How to use the sp2.createDocumentPath function in sp2

To help you get started, we’ve selected a few sp2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github phenyl / phenyl / modules / redux / src / local-state-updater.ts View on Github external
pushCommand: PushCommand,
    localCommits: Array
  ): GeneralUpdateOperation {
    const { entityName, id, operations, versionId } = pushCommand;
    const entityInfo = LocalStateFinder.getEntityInfo(state, {
      id,
      entityName
    });
    const newOrigin = update(entityInfo.origin, ...operations, ...localCommits); // assert(localCommits.length === 0 || entityInfo.commits[0] === localCommits[0])

    const newCommits = entityInfo.commits.slice(localCommits.length);
    const newHead =
      newCommits.length > 0 ? update(newOrigin, ...newCommits) : null;
    return {
      $set: {
        [createDocumentPath("entities", entityName, id)]: {
          origin: newOrigin,
          versionId,
          commits: newCommits,
          head: newHead
        }
      }
    };
  }
  /**
github phenyl / phenyl / modules / redux / src / local-state-updater.ts View on Github external
id
      })
    ) {
      throw new Error(
        `LocalStateUpdater.commit(). No entity found. entityName: "${entityName}", id: "${id}".`
      );
    }

    const entity = LocalStateFinder.getHeadEntity(state, {
      id,
      entityName
    });
    const newEntity = update(entity, operation);
    return {
      $push: {
        [createDocumentPath("entities", entityName, id, "commits")]: operation
      },
      $set: {
        [createDocumentPath("entities", entityName, id, "head")]: newEntity
      }
    };
  }
  /**
github phenyl / phenyl / modules / redux / src / local-state-finder.ts View on Github external
static getEntityInfo>(
    state: LocalStateOf,
    query: IdQuery
  ): LocalEntityInfo {
    const { entityName, id } = query;
    if (state.entities[entityName] == null)
      throw new Error(
        `LocalStateFinder#getEntityInfo(). No entityName found: "${entityName}".`
      );
    const entityInfo = getNestedValue(
      state,
      createDocumentPath("entities", entityName, id)
    );
    if (entityInfo == null)
      throw new Error(
        `LocalStateFinder#getEntityInfo(). No id found in entityName: "${entityName}". id: "${id}".`
      );
    return entityInfo;
  }
}
github phenyl / phenyl / modules / redux / src / local-state-updater.ts View on Github external
static online(): GeneralUpdateOperation {
    return {
      $set: {
        [createDocumentPath("network", "isOnline")]: true
      }
    };
  }
  /**
github phenyl / phenyl / modules / redux / src / local-state-updater.ts View on Github external
if (entityInfo.versionId !== prevVersionId) {
      return {};
    }

    const newOrigin = update(entityInfo.origin);
    const newHead = update(newOrigin, ...entityInfo.commits);
    return {
      $set: {
        [createDocumentPath("entities", entityName, id, "origin")]: newOrigin,
        [createDocumentPath(
          "entities",
          entityName,
          id,
          "versionId"
        )]: versionId,
        [createDocumentPath("entities", entityName, id, "head")]: newHead
      }
    };
  }
  /**
github phenyl / phenyl / modules / redux / src / local-state-updater.ts View on Github external
static follow>(
    state: LocalStateOf,
    entityName: EN,
    entity: Entity,
    versionId: Id | undefined | null
  ): GeneralUpdateOperation {
    return {
      $set: {
        [createDocumentPath("entities", entityName, entity.id)]: {
          origin: entity,
          versionId,
          commits: [],
          head: null
        }
      }
    };
  }
  /**
github phenyl / phenyl / modules / redux / src / local-state-updater.ts View on Github external
static unfollow>(
    state: LocalStateOf,
    entityName: EN,
    id: Id
  ): GeneralUpdateOperation {
    return {
      $unset: {
        [createDocumentPath("entities", entityName, id)]: ""
      }
    };
  }
  /**
github phenyl / phenyl / modules / redux / src / local-state-updater.ts View on Github external
pushCommand: PushCommand
  ): GeneralUpdateOperation {
    const { entityName, id, versionId, operations } = pushCommand;
    const entityInfo = LocalStateFinder.getEntityInfo(state, {
      id,
      entityName
    });
    const newOrigin = update(entityInfo.origin, ...operations);
    const newHead =
      entityInfo.commits.length > 0
        ? update(newOrigin, ...entityInfo.commits)
        : null;
    return {
      $set: {
        [createDocumentPath("entities", entityName, id, "origin")]: newOrigin,
        [createDocumentPath(
          "entities",
          entityName,
          id,
          "versionId"
        )]: versionId,
        [createDocumentPath("entities", entityName, id, "head")]: newHead
      }
    };
  }
  /**