persisting.js
function toStorableUnusableRecordState(unusableRecordState, unusableRecord, context) {
  if (!unusableRecordState) {
    context.warn(`Skipping save of state for unusable record, since it has no state - record (${JSON.stringify(unusableRecord)})`);
    return undefined;
  }

  // Convert the record's state into a safely storable object to get a clean, simplified version of its state
  const state = dynamoDBUtils.toStorableObject(unusableRecordState);

  // If state has no record identifier then have no way to identify the unusable record ... so attach a safely storable
  // copy of its original user record or record (if any) (without its legacy state, if any) for later matching!
  if (!hasUnusableRecordIdentifier(unusableRecordState)) {
    unusableRecord = unusableRecord || unusableRecordState.unusableRecord;

    if (unusableRecord) {
      // Make a storable copy of the unusable record & attach it to the storable state
      state.unusableRecord = dynamoDBUtils.toStorableObject(unusableRecord);
      // Remove the unusable record copy's LEGACY state (if any) to get back to the original unusable record
      tracking.deleteLegacyState(unusableRecord, context);
    }
    if (unusableRecordState.userRecord) {
      // Make a storable copy of the unusable record's user record & attach it to the storable state
      state.userRecord = dynamoDBUtils.toStorableObject(unusableRecordState.userRecord);
      // Remove the unusable record's user record copy's LEGACY state (if any) to get back to the original user record
      tracking.deleteLegacyState(state.userRecord, context);
    }
    else if (unusableRecordState.record) {
      // Make a storable copy of the unusable record's record & attach it to the storable state
      state.record = dynamoDBUtils.toStorableObject(unusableRecordState.record);
      // remove the unusable record's record copy's LEGACY state (if any) to get back to the original record
      tracking.deleteLegacyState(state.record, context);
    }
  }
  return state;
}
function toStorableUnusableRecordState(unusableRecordState, unusableRecord, context) {
  if (!unusableRecordState) {
    context.warn(`Skipping save of state for unusable record, since it has no state - record (${JSON.stringify(unusableRecord)})`);
    return undefined;
  }

  // Convert the record's state into a safely storable object to get a clean, simplified version of its state
  const state = dynamoDBUtils.toStorableObject(unusableRecordState);

  // If state has no record identifier then have no way to identify the unusable record ... so attach a safely storable
  // copy of its original user record or record (if any) (without its legacy state, if any) for later matching!
  if (!hasUnusableRecordIdentifier(unusableRecordState)) {
    unusableRecord = unusableRecord || unusableRecordState.unusableRecord;

    if (unusableRecord) {
      // Make a storable copy of the unusable record & attach it to the storable state
      state.unusableRecord = dynamoDBUtils.toStorableObject(unusableRecord);
      // Remove the unusable record copy's LEGACY state (if any) to get back to the original unusable record
      tracking.deleteLegacyState(unusableRecord, context);
    }
    if (unusableRecordState.userRecord) {
      // Make a storable copy of the unusable record's user record & attach it to the storable state
      state.userRecord = dynamoDBUtils.toStorableObject(unusableRecordState.userRecord);
      // Remove the unusable record's user record copy's LEGACY state (if any) to get back to the original user record
      tracking.deleteLegacyState(state.userRecord, context);
    }
    else if (unusableRecordState.record) {
      // Make a storable copy of the unusable record's record & attach it to the storable state
      state.record = dynamoDBUtils.toStorableObject(unusableRecordState.record);
      // remove the unusable record's record copy's LEGACY state (if any) to get back to the original record
      tracking.deleteLegacyState(state.record, context);
    }
  }
  return state;
}
function toStorableUnusableRecordState ( unusableRecordState , unusableRecord , context ) { if ( ! unusableRecordState ) { context . warn ( ` ${ JSON . stringify ( unusableRecord ) } ` ) ; return undefined ; } // Convert the record's state into a safely storable object to get a clean, simplified version of its state const state = dynamoDBUtils . toStorableObject ( unusableRecordState ) ; // If state has no record identifier then have no way to identify the unusable record ... so attach a safely storable // copy of its original user record or record (if any) (without its legacy state, if any) for later matching! if ( ! hasUnusableRecordIdentifier ( unusableRecordState ) ) { unusableRecord = unusableRecord || unusableRecordState . unusableRecord ; if ( unusableRecord ) { // Make a storable copy of the unusable record & attach it to the storable state state . unusableRecord = dynamoDBUtils . toStorableObject ( unusableRecord ) ; // Remove the unusable record copy's LEGACY state (if any) to get back to the original unusable record tracking . deleteLegacyState ( unusableRecord , context ) ; } if ( unusableRecordState . userRecord ) { // Make a storable copy of the unusable record's user record & attach it to the storable state state . userRecord = dynamoDBUtils . toStorableObject ( unusableRecordState . userRecord ) ; // Remove the unusable record's user record copy's LEGACY state (if any) to get back to the original user record tracking . deleteLegacyState ( state . userRecord , context ) ; } else if ( unusableRecordState . record ) { // Make a storable copy of the unusable record's record & attach it to the storable state state . record = dynamoDBUtils . toStorableObject ( unusableRecordState . record ) ; // remove the unusable record's record copy's LEGACY state (if any) to get back to the original record tracking . deleteLegacyState ( state . record , context ) ; } } return state ; }
Converts the given unusable record state into a storable version of itself.
@param {UnusableRecordState} unusableRecordState
@param {UnusableRecord|undefined} unusableRecord
@param {StreamProcessing} context
@return {UnusableRecordStateItem|undefined}
Converts the given unusable record state into a storable version of itself .