{"version":3,"sources":["../../src/internal/event.ts"],"sourcesContent":["// Copyright © Aptos Foundation\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * This file contains the underlying implementations for exposed API surface in\n * the {@link api/event}. By moving the methods out into a separate file,\n * other namespaces and processes can access these methods without depending on the entire\n * event namespace and without having a dependency cycle error.\n */\n\nimport { AptosConfig } from \"../api/aptosConfig\";\nimport { AccountAddress, AccountAddressInput } from \"../core\";\nimport { AnyNumber, GetEventsResponse, PaginationArgs, MoveStructId, OrderByArg, WhereArg } from \"../types\";\nimport { GetEventsQuery } from \"../types/generated/operations\";\nimport { GetEvents } from \"../types/generated/queries\";\nimport { EventsBoolExp, InputMaybe } from \"../types/generated/types\";\nimport { queryIndexer } from \"./general\";\n\nconst MAX_EVENT_TYPE_LENGTH = 300;\nconst checkEventTypeLength = (eventType?: InputMaybe<string>) => {\n  if (eventType && eventType.length > MAX_EVENT_TYPE_LENGTH) {\n    throw new Error(`Event type length exceeds the maximum length of ${MAX_EVENT_TYPE_LENGTH}`);\n  }\n};\n\nexport async function getModuleEventsByEventType(args: {\n  aptosConfig: AptosConfig;\n  eventType: MoveStructId;\n  options?: PaginationArgs & OrderByArg<GetEventsResponse[0]>;\n}): Promise<GetEventsResponse> {\n  const { aptosConfig, eventType, options } = args;\n\n  const whereCondition: EventsBoolExp = {\n    account_address: { _eq: \"0x0000000000000000000000000000000000000000000000000000000000000000\" },\n    creation_number: { _eq: \"0\" },\n    sequence_number: { _eq: \"0\" },\n    indexed_type: { _eq: eventType },\n  };\n\n  const customOptions = {\n    where: whereCondition,\n    pagination: options,\n    orderBy: options?.orderBy,\n  };\n\n  return getEvents({ aptosConfig, options: customOptions });\n}\n\nexport async function getAccountEventsByCreationNumber(args: {\n  aptosConfig: AptosConfig;\n  accountAddress: AccountAddressInput;\n  creationNumber: AnyNumber;\n  options?: PaginationArgs & OrderByArg<GetEventsResponse[0]>;\n}): Promise<GetEventsResponse> {\n  const { accountAddress, aptosConfig, creationNumber, options } = args;\n  const address = AccountAddress.from(accountAddress);\n\n  const whereCondition: EventsBoolExp = {\n    account_address: { _eq: address.toStringLong() },\n    creation_number: { _eq: creationNumber },\n  };\n\n  const customOptions = {\n    where: whereCondition,\n    pagination: options,\n    orderBy: options?.orderBy,\n  };\n\n  return getEvents({ aptosConfig, options: customOptions });\n}\n\nexport async function getAccountEventsByEventType(args: {\n  aptosConfig: AptosConfig;\n  accountAddress: AccountAddressInput;\n  eventType: MoveStructId;\n  options?: PaginationArgs & OrderByArg<GetEventsResponse[0]>;\n}): Promise<GetEventsResponse> {\n  const { accountAddress, aptosConfig, eventType, options } = args;\n  const address = AccountAddress.from(accountAddress).toStringLong();\n\n  const whereCondition: EventsBoolExp = {\n    account_address: { _eq: address },\n    indexed_type: { _eq: eventType },\n  };\n\n  const customOptions = {\n    where: whereCondition,\n    pagination: options,\n    orderBy: options?.orderBy,\n  };\n\n  return getEvents({ aptosConfig, options: customOptions });\n}\n\nexport async function getEvents(args: {\n  aptosConfig: AptosConfig;\n  options?: PaginationArgs & OrderByArg<GetEventsResponse[0]> & WhereArg<EventsBoolExp>;\n}): Promise<GetEventsResponse> {\n  const { aptosConfig, options } = args;\n  // eslint-disable-next-line no-underscore-dangle\n  checkEventTypeLength(options?.where?.indexed_type?._eq);\n\n  const graphqlQuery = {\n    query: GetEvents,\n    variables: {\n      where_condition: options?.where,\n      offset: options?.offset,\n      limit: options?.limit,\n      order_by: options?.orderBy,\n    },\n  };\n\n  const data = await queryIndexer<GetEventsQuery>({\n    aptosConfig,\n    query: graphqlQuery,\n    originMethod: \"getEvents\",\n  });\n\n  return data.events;\n}\n"],"mappings":"2HAkBA,IAAMA,EAAwB,IACxBC,EAAwBC,GAAmC,CAC/D,GAAIA,GAAaA,EAAU,OAASF,EAClC,MAAM,IAAI,MAAM,mDAAmDA,CAAqB,EAAE,CAE9F,EAEA,eAAsBG,EAA2BC,EAIlB,CAC7B,GAAM,CAAE,YAAAC,EAAa,UAAAH,EAAW,QAAAI,CAAQ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EAQA,OANa,MAAMU,EAA6B,CAC9C,YAAAX,EACA,MAAOS,EACP,aAAc,WAChB,CAAC,GAEW,MACd","names":["MAX_EVENT_TYPE_LENGTH","checkEventTypeLength","eventType","getModuleEventsByEventType","args","aptosConfig","options","customOptions","getEvents","getAccountEventsByCreationNumber","accountAddress","creationNumber","AccountAddress","getAccountEventsByEventType","graphqlQuery","GetEvents","queryIndexer"]}