{"version":3,"file":"connection-D544oqVW.mjs","names":["createState"],"sources":["../../document-models/connection/v1/gen/controller.ts","../../document-models/connection/v1/gen/ph-factories.ts","../../document-models/connection/v1/hooks.ts"],"sourcesContent":["/**\n * WARNING: DO NOT EDIT\n * This file is auto-generated and updated by codegen\n */\nimport { PHDocumentController } from \"document-model\";\nimport { Connection } from \"../module.js\";\nimport type { ConnectionAction, ConnectionPHState } from \"./types.js\";\n\nexport const ConnectionController = PHDocumentController.forDocumentModel<\n  ConnectionPHState,\n  ConnectionAction\n>(Connection);\n","/**\n * WARNING: DO NOT EDIT\n * This file is auto-generated and updated by codegen\n * Factory methods for creating ConnectionDocument instances\n */\nimport type { PHAuthState, PHBaseState, PHDocumentState } from \"document-model\";\nimport { createBaseState, defaultBaseState } from \"document-model\";\nimport type {\n  ConnectionDocument,\n  ConnectionGlobalState,\n  ConnectionLocalState,\n  ConnectionPHState,\n} from \"./types.js\";\nimport { utils } from \"./utils.js\";\n\nexport function defaultGlobalState(): ConnectionGlobalState {\n  return {\n    name: \"\",\n    connectorId: \"\",\n    authType: \"NONE\",\n    config: {},\n    secretRefs: [],\n    status: \"UNCONFIGURED\",\n    lastCheckedAt: null,\n    lastError: null,\n    accountLabel: null,\n  };\n}\n\nexport function defaultLocalState(): ConnectionLocalState {\n  return {};\n}\n\nexport function defaultPHState(): ConnectionPHState {\n  return {\n    ...defaultBaseState(),\n    global: defaultGlobalState(),\n    local: defaultLocalState(),\n  };\n}\n\nexport function createGlobalState(\n  state?: Partial<ConnectionGlobalState>,\n): ConnectionGlobalState {\n  return {\n    ...defaultGlobalState(),\n    ...(state || {}),\n  };\n}\n\nexport function createLocalState(\n  state?: Partial<ConnectionLocalState>,\n): ConnectionLocalState {\n  return {\n    ...defaultLocalState(),\n    ...(state || {}),\n  } as ConnectionLocalState;\n}\n\nexport function createState(\n  baseState?: Partial<PHBaseState>,\n  globalState?: Partial<ConnectionGlobalState>,\n  localState?: Partial<ConnectionLocalState>,\n): ConnectionPHState {\n  return {\n    ...createBaseState(baseState?.auth, baseState?.document),\n    global: createGlobalState(globalState),\n    local: createLocalState(localState),\n  };\n}\n\n/**\n * Creates a ConnectionDocument with custom global and local state\n * This properly handles the PHBaseState requirements while allowing\n * document-specific state to be set.\n */\nexport function createConnectionDocument(\n  state?: Partial<{\n    auth?: Partial<PHAuthState>;\n    document?: Partial<PHDocumentState>;\n    global?: Partial<ConnectionGlobalState>;\n    local?: Partial<ConnectionLocalState>;\n  }>,\n): ConnectionDocument {\n  const document = utils.createDocument(\n    createState(\n      createBaseState(state?.auth, { version: 1, ...state?.document }),\n      state?.global,\n      state?.local,\n    ),\n  );\n\n  return document;\n}\n","/**\n * WARNING: DO NOT EDIT\n * This file is auto-generated and updated by codegen\n */\nimport type { DocumentDispatch } from \"@powerhousedao/reactor-browser\";\nimport {\n  useDocumentById,\n  useDocumentsInSelectedDrive,\n  useDocumentsInSelectedFolder,\n  useSelectedDocument,\n} from \"@powerhousedao/reactor-browser\";\nimport type {\n  ConnectionAction,\n  ConnectionDocument,\n} from \"document-models/connection/v1\";\nimport {\n  assertIsConnectionDocument,\n  isConnectionDocument,\n} from \"./gen/document-schema.js\";\n\n/** Hook to get a Connection document by its id */\nexport function useConnectionDocumentById(\n  documentId: string | null | undefined,\n):\n  | [ConnectionDocument, DocumentDispatch<ConnectionAction>]\n  | [undefined, undefined] {\n  const [document, dispatch] = useDocumentById(documentId);\n  if (!isConnectionDocument(document)) return [undefined, undefined];\n  return [document, dispatch];\n}\n\n/** Hook to get the selected Connection document */\nexport function useSelectedConnectionDocument(): [\n  ConnectionDocument,\n  DocumentDispatch<ConnectionAction>,\n] {\n  const [document, dispatch] = useSelectedDocument();\n\n  assertIsConnectionDocument(document);\n  return [document, dispatch] as const;\n}\n\n/** Hook to get all Connection documents in the selected drive */\nexport function useConnectionDocumentsInSelectedDrive() {\n  const documentsInSelectedDrive = useDocumentsInSelectedDrive();\n  return documentsInSelectedDrive?.filter(isConnectionDocument);\n}\n\n/** Hook to get all Connection documents in the selected folder */\nexport function useConnectionDocumentsInSelectedFolder() {\n  const documentsInSelectedFolder = useDocumentsInSelectedFolder();\n  return documentsInSelectedFolder?.filter(isConnectionDocument);\n}\n"],"mappings":";;;;;;;;AAQA,MAAa,uBAAuB,qBAAqB,iBAGvD,UAAU;;;ACIZ,SAAgB,qBAA4C;CAC1D,OAAO;EACL,MAAM;EACN,aAAa;EACb,UAAU;EACV,QAAQ,CAAC;EACT,YAAY,CAAC;EACb,QAAQ;EACR,eAAe;EACf,WAAW;EACX,cAAc;CAChB;AACF;AAEA,SAAgB,oBAA0C;CACxD,OAAO,CAAC;AACV;AAEA,SAAgB,iBAAoC;CAClD,OAAO;EACL,GAAG,iBAAiB;EACpB,QAAQ,mBAAmB;EAC3B,OAAO,kBAAkB;CAC3B;AACF;AAEA,SAAgB,kBACd,OACuB;CACvB,OAAO;EACL,GAAG,mBAAmB;EACtB,GAAI,SAAS,CAAC;CAChB;AACF;AAEA,SAAgB,iBACd,OACsB;CACtB,OAAO;EACL,GAAG,kBAAkB;EACrB,GAAI,SAAS,CAAC;CAChB;AACF;AAEA,SAAgBA,cACd,WACA,aACA,YACmB;CACnB,OAAO;EACL,GAAG,gBAAgB,WAAW,MAAM,WAAW,QAAQ;EACvD,QAAQ,kBAAkB,WAAW;EACrC,OAAO,iBAAiB,UAAU;CACpC;AACF;;;;;;AAOA,SAAgB,yBACd,OAMoB;CASpB,OARiB,MAAM,eACrBA,cACE,gBAAgB,OAAO,MAAM;EAAE,SAAS;EAAG,GAAG,OAAO;CAAS,CAAC,GAC/D,OAAO,QACP,OAAO,KACT,CAGY;AAChB;;;;ACxEA,SAAgB,0BACd,YAGyB;CACzB,MAAM,CAAC,UAAU,YAAY,gBAAgB,UAAU;CACvD,IAAI,CAAC,qBAAqB,QAAQ,GAAG,OAAO,CAAC,KAAA,GAAW,KAAA,CAAS;CACjE,OAAO,CAAC,UAAU,QAAQ;AAC5B;;AAGA,SAAgB,gCAGd;CACA,MAAM,CAAC,UAAU,YAAY,oBAAoB;CAEjD,2BAA2B,QAAQ;CACnC,OAAO,CAAC,UAAU,QAAQ;AAC5B;;AAGA,SAAgB,wCAAwC;CAEtD,OADiC,4BACH,CAAC,EAAE,OAAO,oBAAoB;AAC9D;;AAGA,SAAgB,yCAAyC;CAEvD,OADkC,6BACH,CAAC,EAAE,OAAO,oBAAoB;AAC/D"}