diff --git a/packages/server/assets/acc/typedefs/accSyncItems.graphql b/packages/server/assets/acc/typedefs/accSyncItems.graphql index 6badc59a4..35c2bb9ae 100644 --- a/packages/server/assets/acc/typedefs/accSyncItems.graphql +++ b/packages/server/assets/acc/typedefs/accSyncItems.graphql @@ -1,6 +1,6 @@ extend type Project { accSyncItems(cursor: String, limit: Int): AccSyncItemCollection! - accSyncItem(lineageUrn: String!): AccSyncItem! + accSyncItem(id: String!): AccSyncItem! } type AccSyncItemCollection { @@ -40,12 +40,12 @@ enum AccSyncItemStatus { input DeleteAccSyncItemInput { projectId: ID! - accFileLineageUrn: ID! + id: ID! } input UpdateAccSyncItemInput { projectId: ID! - accFileLineageUrn: ID! + id: ID! status: AccSyncItemStatus! } diff --git a/packages/server/modules/acc/domain/operations.ts b/packages/server/modules/acc/domain/operations.ts index 47707f7c5..b72aa5956 100644 --- a/packages/server/modules/acc/domain/operations.ts +++ b/packages/server/modules/acc/domain/operations.ts @@ -12,6 +12,8 @@ export type GetAccSyncItemByUrn = (args: { lineageUrn: string }) => Promise +export type GetAccSyncItemById = (args: { id: string }) => Promise + export type ListAccSyncItems = (args: { projectId: string filter?: { diff --git a/packages/server/modules/acc/domain/types.ts b/packages/server/modules/acc/domain/types.ts index da42079e5..15da55876 100644 --- a/packages/server/modules/acc/domain/types.ts +++ b/packages/server/modules/acc/domain/types.ts @@ -14,7 +14,7 @@ export type AccSyncItem = { accFileExtension: string accFileVersionIndex: number accFileVersionUrn: string - accFileViewName: string + accFileViewName?: string | null accWebhookId?: string status: AccSyncItemStatus authorId: string diff --git a/packages/server/modules/acc/graph/resolvers/accSyncItems.ts b/packages/server/modules/acc/graph/resolvers/accSyncItems.ts index a6c1378d6..856b3ac1c 100644 --- a/packages/server/modules/acc/graph/resolvers/accSyncItems.ts +++ b/packages/server/modules/acc/graph/resolvers/accSyncItems.ts @@ -1,7 +1,7 @@ import { countAccSyncItemsFactory, deleteAccSyncItemByUrnFactory, - getAccSyncItemByUrnFactory, + getAccSyncItemByIdFactory, listAccSyncItemsFactory, updateAccSyncItemStatusFactory, upsertAccSyncItemFactory @@ -79,7 +79,6 @@ const resolvers: Resolvers = { const projectDb = await getProjectDbClient({ projectId: input.projectId }) return await createAccSyncItemFactory({ - getAccSyncItemByUrn: getAccSyncItemByUrnFactory({ db }), upsertAccSyncItem: upsertAccSyncItemFactory({ db }), createAutomation: createAutomationFactory({ createAuthCode: createStoredAuthCodeFactory({ redis: getGenericRedis() }), @@ -137,7 +136,7 @@ const resolvers: Resolvers = { }) return await updateAccSyncItemFactory({ - getAccSyncItemByUrn: getAccSyncItemByUrnFactory({ db }), + getAccSyncItemById: getAccSyncItemByIdFactory({ db }), upsertAccSyncItem: upsertAccSyncItemFactory({ db }) })({ syncItem: input @@ -186,7 +185,7 @@ const resolvers: Resolvers = { }) }, async accSyncItem(parent, args, ctx) { - const { lineageUrn } = args + const { id } = args throwIfResourceAccessNotAllowed({ resourceId: parent.id, @@ -195,8 +194,8 @@ const resolvers: Resolvers = { }) return await getAccSyncItemFactory({ - getAccSyncItemByUrn: getAccSyncItemByUrnFactory({ db }) - })({ lineageUrn }) + getAccSyncItemById: getAccSyncItemByIdFactory({ db }) + })({ id }) } }, Subscription: { diff --git a/packages/server/modules/acc/repositories/accSyncItems.ts b/packages/server/modules/acc/repositories/accSyncItems.ts index e43b04ba6..b6e98d6fc 100644 --- a/packages/server/modules/acc/repositories/accSyncItems.ts +++ b/packages/server/modules/acc/repositories/accSyncItems.ts @@ -2,6 +2,7 @@ import { AccSyncItems } from '@/modules/acc/dbSchema' import type { CountAccSyncItems, DeleteAccSyncItemByUrn, + GetAccSyncItemById, GetAccSyncItemByUrn, ListAccSyncItems, QueryAllAccSyncItems, @@ -18,6 +19,18 @@ const tables = { accSyncItems: (db: Knex) => db(AccSyncItems.name) } +export const getAccSyncItemByIdFactory = + (deps: { db: Knex }): GetAccSyncItemById => + async ({ id }) => { + return ( + (await tables + .accSyncItems(deps.db) + .select('*') + .where(AccSyncItems.col.id, id) + .first()) ?? null + ) + } + export const getAccSyncItemByUrnFactory = (deps: { db: Knex }): GetAccSyncItemByUrn => async ({ lineageUrn }) => { diff --git a/packages/server/modules/acc/services/management.ts b/packages/server/modules/acc/services/management.ts index e27ff6fb4..68004753a 100644 --- a/packages/server/modules/acc/services/management.ts +++ b/packages/server/modules/acc/services/management.ts @@ -9,12 +9,12 @@ import { isReadyForImport } from '@/modules/acc/domain/logic' import type { CountAccSyncItems, DeleteAccSyncItemByUrn, - GetAccSyncItemByUrn, + GetAccSyncItemById, ListAccSyncItems, UpsertAccSyncItem } from '@/modules/acc/domain/operations' import type { AccSyncItem } from '@/modules/acc/domain/types' -import { DuplicateSyncItemError, SyncItemNotFoundError } from '@/modules/acc/errors/acc' +import { SyncItemNotFoundError } from '@/modules/acc/errors/acc' import type { TriggerSyncItemAutomation } from '@/modules/acc/services/automate' import type { CreateAutomation, @@ -49,7 +49,6 @@ export type CreateAccSyncItem = (params: { export const createAccSyncItemFactory = (deps: { - getAccSyncItemByUrn: GetAccSyncItemByUrn upsertAccSyncItem: UpsertAccSyncItem createAutomation: CreateAutomation createAutomationRevision: CreateAutomationRevision @@ -57,14 +56,6 @@ export const createAccSyncItemFactory = eventEmit: EventBusEmit }): CreateAccSyncItem => async ({ syncItem, creatorUserId }) => { - const existingSyncItem = await deps.getAccSyncItemByUrn({ - lineageUrn: syncItem.accFileLineageUrn - }) - - if (!!existingSyncItem) { - throw new DuplicateSyncItemError(syncItem.accFileLineageUrn) - } - const webhookId = await tryRegisterAccWebhook({ // For local development, you may set your public tailscale url as your local server's canonical origin callbackUrl: `${getServerOrigin()}/api/v1/acc/webhook/callback`, @@ -145,12 +136,12 @@ export const createAccSyncItemFactory = return await deps.triggerSyncItemAutomation({ id: newSyncItem.id }) } -export type GetAccSyncItem = (params: { lineageUrn: string }) => Promise +export type GetAccSyncItem = (params: { id: string }) => Promise export const getAccSyncItemFactory = - (deps: { getAccSyncItemByUrn: GetAccSyncItemByUrn }): GetAccSyncItem => - async ({ lineageUrn }) => { - const syncItem = await deps.getAccSyncItemByUrn({ lineageUrn }) + (deps: { getAccSyncItemById: GetAccSyncItemById }): GetAccSyncItem => + async ({ id }) => { + const syncItem = await deps.getAccSyncItemById({ id }) if (!syncItem) { throw new SyncItemNotFoundError() @@ -200,17 +191,17 @@ export const getPaginatedAccSyncItemsFactory = } export type UpdateAccSyncItem = (params: { - syncItem: Pick + syncItem: Pick }) => Promise export const updateAccSyncItemFactory = (deps: { - getAccSyncItemByUrn: GetAccSyncItemByUrn + getAccSyncItemById: GetAccSyncItemById upsertAccSyncItem: UpsertAccSyncItem }): UpdateAccSyncItem => async ({ syncItem }) => { - const existingSyncItem = await deps.getAccSyncItemByUrn({ - lineageUrn: syncItem.accFileLineageUrn + const existingSyncItem = await deps.getAccSyncItemById({ + id: syncItem.id }) if (!existingSyncItem) { diff --git a/packages/server/modules/core/graph/generated/graphql.ts b/packages/server/modules/core/graph/generated/graphql.ts index 1cb1b1bb5..7fe647aef 100644 --- a/packages/server/modules/core/graph/generated/graphql.ts +++ b/packages/server/modules/core/graph/generated/graphql.ts @@ -49,7 +49,7 @@ export type AccSyncItem = { accFileName: Scalars['String']['output']; accFileVersionIndex: Scalars['Int']['output']; accFileVersionUrn: Scalars['String']['output']; - accFileViewName: Scalars['String']['output']; + accFileViewName?: Maybe; accHubId: Scalars['String']['output']; accProjectId: Scalars['String']['output']; accRegion: Scalars['String']['output']; @@ -989,7 +989,7 @@ export type CreateAccSyncItemInput = { accFileName: Scalars['String']['input']; accFileVersionIndex: Scalars['Int']['input']; accFileVersionUrn: Scalars['String']['input']; - accFileViewName: Scalars['String']['input']; + accFileViewName?: InputMaybe; accHubId: Scalars['String']['input']; accProjectId: Scalars['String']['input']; accRegion: Scalars['String']['input']; @@ -1080,7 +1080,7 @@ export type CurrencyBasedPrices = { }; export type DeleteAccSyncItemInput = { - accFileLineageUrn: Scalars['ID']['input']; + id: Scalars['ID']['input']; projectId: Scalars['ID']['input']; }; @@ -4143,7 +4143,7 @@ export type TriggeredAutomationsStatus = { }; export type UpdateAccSyncItemInput = { - accFileLineageUrn: Scalars['ID']['input']; + id: Scalars['ID']['input']; projectId: Scalars['ID']['input']; status: AccSyncItemStatus; }; @@ -6310,7 +6310,7 @@ export type AccSyncItemResolvers; accFileVersionIndex?: Resolver; accFileVersionUrn?: Resolver; - accFileViewName?: Resolver; + accFileViewName?: Resolver, ParentType, ContextType>; accHubId?: Resolver; accProjectId?: Resolver; accRegion?: Resolver;