diff --git a/packages/datastore/src/sync/index.ts b/packages/datastore/src/sync/index.ts index 633f6b16250..9cbc1555b46 100644 --- a/packages/datastore/src/sync/index.ts +++ b/packages/datastore/src/sync/index.ts @@ -32,7 +32,7 @@ import { CONTROL_MSG, SubscriptionProcessor } from './processors/subscription'; import { SyncProcessor } from './processors/sync'; import { createMutationInstanceFromModelOperation, - getIdOrPkValueStringFromModel, + getIdentifierValue, predicateToGraphQLCondition, TransformerMutationType, } from './utils'; @@ -532,10 +532,7 @@ export class SyncEngine { const oneByOne: ModelInstanceMetadata[] = []; const page = items.filter(item => { - const itemId = getIdOrPkValueStringFromModel( - modelDefinition, - item - ); + const itemId = getIdentifierValue(modelDefinition, item); if (!idsInOutbox.has(itemId)) { return true; diff --git a/packages/datastore/src/sync/merger.ts b/packages/datastore/src/sync/merger.ts index cfc22bb401a..337e7bf5a80 100644 --- a/packages/datastore/src/sync/merger.ts +++ b/packages/datastore/src/sync/merger.ts @@ -7,7 +7,7 @@ import { } from '../types'; import { MutationEventOutbox } from './outbox'; import { SchemaModel } from '../types'; -import { getIdOrPkValueStringFromModel } from './utils'; +import { getIdentifierValue } from './utils'; class ModelMerger { constructor( private readonly outbox: MutationEventOutbox, @@ -46,7 +46,7 @@ class ModelMerger { for (const item of items) { // merge items by model id. Latest record for a given id remains. - const modelId = getIdOrPkValueStringFromModel(modelDefinition, item); + const modelId = getIdentifierValue(modelDefinition, item); itemsMap.set(modelId, item); } diff --git a/packages/datastore/src/sync/outbox.ts b/packages/datastore/src/sync/outbox.ts index 52231ace933..93e07dab10d 100644 --- a/packages/datastore/src/sync/outbox.ts +++ b/packages/datastore/src/sync/outbox.ts @@ -14,10 +14,7 @@ import { QueryOne, } from '../types'; import { USER, SYNC, valuesEqual, isModelConstructor } from '../util'; -import { - getIdOrPkValueStringFromModel, - TransformerMutationType, -} from './utils'; +import { getIdentifierValue, TransformerMutationType } from './utils'; // TODO: Persist deleted ids class MutationEventOutbox { @@ -138,7 +135,7 @@ class MutationEventOutbox { const userModelDefinition = this.schema.namespaces['user'].models[model.constructor.name]; - const modelId = getIdOrPkValueStringFromModel(userModelDefinition, model); + const modelId = getIdentifierValue(userModelDefinition, model); const mutationEvents = await storage.query( this.MutationEvent, @@ -204,7 +201,7 @@ class MutationEventOutbox { const userModelDefinition = this.schema.namespaces['user'].models[head.model]; - const recordId = getIdOrPkValueStringFromModel(userModelDefinition, record); + const recordId = getIdentifierValue(userModelDefinition, record); const predicate = ModelPredicateCreator.createFromExisting( mutationEventModelDefinition, diff --git a/packages/datastore/src/sync/utils.ts b/packages/datastore/src/sync/utils.ts index 91b78725e7d..95b56ce4594 100644 --- a/packages/datastore/src/sync/utils.ts +++ b/packages/datastore/src/sync/utils.ts @@ -414,7 +414,7 @@ export function createMutationInstanceFromModelOperation< return v; }; - const modelId = getIdOrPkValueStringFromModel(modelDefinition, element); + const modelId = getIdentifierValue(modelDefinition, element); // TODO: create util to identify custom PK - for now, using hardcoded 'customId` const mutationEvent = modelInstanceCreator(MutationEventConstructor, { @@ -617,7 +617,7 @@ export async function getTokenForCustomAuth( } // Util that takes a modelDefinition and model and returns either the id or the custom primary key(s) -export function getIdOrPkFromModel( +export function getIdentifierKey( modelDefinition: SchemaModel, model: ModelInstanceMetadata | PersistentModel ): string { @@ -635,7 +635,7 @@ export function getIdOrPkFromModel( } // Util that takes a modelDefinition and model and returns either the id value(s) or the custom primary key value(s) -export function getIdOrPkValueStringFromModel( +export function getIdentifierValue( modelDefinition: SchemaModel, model: ModelInstanceMetadata | PersistentModel ): string { @@ -658,8 +658,8 @@ export function getIdOrPkKeyValuePairFromModel( modelDefinition: SchemaModel, model: ModelInstanceMetadata | PersistentModel ): String[] { - const key = getIdOrPkFromModel(modelDefinition, model); - const value = getIdOrPkValueStringFromModel(modelDefinition, model); + const key = getIdentifierKey(modelDefinition, model); + const value = getIdentifierValue(modelDefinition, model); return [key, value]; }