Skip to content

Commit

Permalink
removed unused function - updated comment to be clearer
Browse files Browse the repository at this point in the history
  • Loading branch information
Ptroger committed Nov 5, 2024
1 parent cca8184 commit c48adef
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ getAccountByAddress(address) := account if {
## !! IMPORTANT !!
## This query finds an account by its ID or address. This works because currently we only support EOA accounts.
## If we support Smart Accounts in the future, this query will likely need to be splitted in two.
## A smartAccount address can exist on multiple chains, so find by address will need to return multiple accounts.
##
## Input: string
## Output: account object with its groups | null
Expand Down
18 changes: 5 additions & 13 deletions packages/policy-engine-shared/src/lib/util/entity.util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EntityVersion, entitiesV1Schema, entitiesV2Schema, getEntitySchema } from '../schema/entity.schema'
import { entitiesV1Schema, entitiesV2Schema, EntityVersion, getEntitySchema } from '../schema/entity.schema'
import {
AccountEntity,
CredentialEntity,
Expand All @@ -7,7 +7,7 @@ import {
UserAccountEntity,
UserEntity
} from '../type/entity.type'
import { Validation, Validator, isV1 } from './validation.types'
import { isV1, Validation, Validator } from './validation.types'
import { V1_VALIDATORS } from './validators.v1'
import { V2_VALIDATORS } from './validators.v2'

Expand All @@ -27,19 +27,11 @@ export const VALIDATORS: {
'2': V2_VALIDATORS
}

export const determineEntityVersion = (entities: Entities): { version: EntityVersion } => {
switch (entities.version) {
case '1':
return { version: '1' }
case '2':
return { version: '2' }
case undefined:
return { version: '1' }
}
}
export const findEntityVersion = (entities: Entities): { version: EntityVersion } =>
!entities.version ? { version: '1' } : { version: entities.version }

export const validate = (entities: Entities): Validation => {
const { version } = determineEntityVersion(entities)
const { version } = findEntityVersion(entities)

const schema = getEntitySchema(version)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EntityVersion, entitiesV1Schema, entitiesV2Schema } from '../schema/entity.schema'
import { EntityVersion, entitiesV1Schema } from '../schema/entity.schema'
import { Entities, EntitiesV } from '../type/entity.type'

export type ValidationIssue = {
Expand All @@ -16,5 +16,3 @@ export type ValidationOption<Version extends EntityVersion> = {

export const isV1 = (entities: Partial<Entities>): entities is Partial<EntitiesV<'1'>> =>
entitiesV1Schema.safeParse(entities).success || 'accountGroups' in entities || 'userGroups' in entities
export const isV2 = (entities: Partial<Entities>): entities is Partial<EntitiesV<'2'>> =>
entitiesV2Schema.safeParse(entities).success || 'groups' in entities

0 comments on commit c48adef

Please sign in to comment.