Skip to content

Commit

Permalink
update util names
Browse files Browse the repository at this point in the history
  • Loading branch information
david-mcafee committed Dec 29, 2021
1 parent dfea917 commit eec3d0d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 18 deletions.
7 changes: 2 additions & 5 deletions packages/datastore/src/sync/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { CONTROL_MSG, SubscriptionProcessor } from './processors/subscription';
import { SyncProcessor } from './processors/sync';
import {
createMutationInstanceFromModelOperation,
getIdOrPkValueStringFromModel,
getIdentifierValue,
predicateToGraphQLCondition,
TransformerMutationType,
} from './utils';
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions packages/datastore/src/sync/merger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
Expand Down
9 changes: 3 additions & 6 deletions packages/datastore/src/sync/outbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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<MutationEvent>(
mutationEventModelDefinition,
Expand Down
10 changes: 5 additions & 5 deletions packages/datastore/src/sync/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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];
}

0 comments on commit eec3d0d

Please sign in to comment.