How to use the sp2.getNestedValue 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 / standards / src / encrypt-password-in-request-data.ts View on Github external
export function encryptPasswordInRequestData(
  reqData: GeneralUserEntityRequestData,
  passwordPropName: DocumentPath,
  encrypt: EncryptFunction
): GeneralUserEntityRequestData {
  switch (reqData.method) {
    case "insertOne":
    case "insertAndGet": {
      const { payload } = reqData;
      const { value } = payload;
      const password = getNestedValue(value, passwordPropName);

      if (password) {
        const { $set, $docPath } = $bind();
        const valueWithEncryptedPass = update(
          value,
          // @ts-ignore password always exists
          $set($docPath(passwordPropName), encrypt(password))
        );
        const { $set: $OtherSet, $docPath: $otherDocPath } = $bind<
          typeof reqData
        >();
        return update(
          reqData,
          $OtherSet($otherDocPath("payload", "value"), valueWithEncryptedPass)
        );
      } else {
github phenyl / phenyl / modules / standards / src / encrypt-password-in-request-data.ts View on Github external
const valuesWithEncryptedPass = values.map(value => {
        const password = getNestedValue(value, passwordPropName);

        if (password) {
          const { $set, $docPath } = $bind();
          return update(
            value,
            // @ts-ignore password always exists
            $set($docPath(passwordPropName), encrypt(password))
          );
        } else {
          return value;
        }
      });
      const { $set, $docPath } = $bind();
github phenyl / phenyl / modules / standards / src / encrypt-password-in-request-data.ts View on Github external
Object.keys(operation).forEach((key: any) => {
        // @ts-ignore: Partial has no index signature.
        const password = getNestedValue(operation[key], passwordPropName);

        if (password) {
          const { $set, $docPath } = $bind();
          operationWithEncryptedPass = update(
            operationWithEncryptedPass,
            $set($docPath(key, passwordPropName), encrypt(password))
          );
        }
      });
github phenyl / phenyl / modules / redux / src / local-state-finder.ts View on Github external
static getHeadEntity>(
    state: LocalStateOf,
    query: IdQuery
  ): Entity {
    const { entityName, id } = query;
    if (state.entities[entityName] == null)
      throw new Error(
        `LocalStateFinder#getHeadEntity(). No entityName found: "${entityName}".`
      );
    const entityInfo = getNestedValue(
      state,
      createDocumentPath("entities", entityName, id)
    );
    if (entityInfo == null)
      throw new Error(
        `LocalStateFinder#getHeadEntity(). No id found in entityName: "${entityName}". id: "${id}".`
      ); // If no head, meaning origin is the head (= commits.length === 0)

    return entityInfo.head ? entityInfo.head : entityInfo.origin;
  }
  /**
github phenyl / phenyl / modules / redux / src / local-state-finder.ts View on Github external
static hasEntity>(
    state: LocalStateOf,
    query: IdQuery
  ): boolean {
    const { entityName, id } = query;
    if (!state.entities[entityName]) return false;
    const entityInfo = getNestedValue(
      state,
      createDocumentPath("entities", entityName, id)
    );
    return entityInfo != null;
  }
  /**
github phenyl / phenyl / modules / standards / src / foreign-query-wrapper.ts View on Github external
async getForeignEntity>(
    entity: E,
    foreign: ForeignQueryParams
  ): Promise {
    const { documentPath, entityName } = foreign;

    try {
      const foreignId = getNestedValue(entity, documentPath);
      const result = await this.entityClient.get({ id: foreignId, entityName });
      return result.entity;
    } catch (e) {
      e.message = `Error while getting entities "${entityName}" by foreign keys "${documentPath}".\n${
        e.message
      }`;
      throw e;
    }
  }
}
github phenyl / phenyl / modules / standards / src / foreign-query-wrapper.ts View on Github external
const foreignIds = entities.map(entity =>
        getNestedValue(entity, documentPath)
      );
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;
  }
}