Skip to content

Commit

Permalink
Merge pull request nasa-gcn#2530 from lpsinger/unmarshallTrigger
Browse files Browse the repository at this point in the history
Refactor duplicate function unmarshallTrigger
  • Loading branch information
dakota002 authored Aug 8, 2024
2 parents 4a6e287 + 75d9c85 commit d1414df
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
12 changes: 2 additions & 10 deletions app/table-streams/circulars/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,13 @@
* SPDX-License-Identifier: Apache-2.0
*/
import { tables } from '@architect/functions'
import type { AttributeValue } from '@aws-sdk/client-dynamodb'
import { paginateQuery, paginateScan } from '@aws-sdk/lib-dynamodb'
import type { DynamoDBDocument } from '@aws-sdk/lib-dynamodb'
import { unmarshall } from '@aws-sdk/util-dynamodb'
import { search as getSearchClient } from '@nasa-gcn/architect-functions-search'
import { errors } from '@opensearch-project/opensearch'
import type {
DynamoDBRecord,
AttributeValue as LambdaTriggerAttributeValue,
} from 'aws-lambda'
import type { DynamoDBRecord } from 'aws-lambda'

import { unmarshallTrigger } from '../utils'
import { sendEmailBulk } from '~/lib/email.server'
import { origin } from '~/lib/env.server'
import { send as sendKafka } from '~/lib/kafka.server'
Expand All @@ -29,10 +25,6 @@ import { $id as circularsJsonSchemaId } from '@nasa-gcn/schema/gcn/circulars.sch
const index = 'circulars'
const fromName = 'GCN Circulars'

function unmarshallTrigger(item?: Record<string, LambdaTriggerAttributeValue>) {
return unmarshall(item as Record<string, AttributeValue>)
}

async function removeIndex(id: number) {
const client = await getSearchClient()
try {
Expand Down
12 changes: 2 additions & 10 deletions app/table-streams/synonyms/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,16 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
import type { AttributeValue } from '@aws-sdk/client-dynamodb'
import { unmarshall } from '@aws-sdk/util-dynamodb'
import { search as getSearchClient } from '@nasa-gcn/architect-functions-search'
import { errors } from '@opensearch-project/opensearch'
import type {
DynamoDBRecord,
AttributeValue as LambdaTriggerAttributeValue,
} from 'aws-lambda'
import type { DynamoDBRecord } from 'aws-lambda'

import { unmarshallTrigger } from '../utils'
import { createTriggerHandler } from '~/lib/lambdaTrigger.server'
import type { Synonym } from '~/routes/synonyms/synonyms.lib'

const index = 'synonyms'

function unmarshallTrigger(item?: Record<string, LambdaTriggerAttributeValue>) {
return unmarshall(item as Record<string, AttributeValue>)
}

async function removeIndex(id: string) {
const client = await getSearchClient()
try {
Expand Down
16 changes: 16 additions & 0 deletions app/table-streams/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*!
* Copyright © 2023 United States Government as represented by the
* Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/
import type { AttributeValue } from '@aws-sdk/client-dynamodb'
import { unmarshall } from '@aws-sdk/util-dynamodb'
import type { AttributeValue as LambdaTriggerAttributeValue } from 'aws-lambda'

export function unmarshallTrigger(
item?: Record<string, LambdaTriggerAttributeValue>
) {
return unmarshall(item as Record<string, AttributeValue>)
}

0 comments on commit d1414df

Please sign in to comment.