import { Quaternion, Vector3 } from 'three' import { matches, Validator } from 'ts-matches' import { EntityUUID } from '@xrengine/common/src/interfaces/EntityUUID' import { NetworkId } from '@xrengine/common/src/interfaces/NetworkId' import { PeerID } from '@xrengine/common/src/interfaces/PeerID' import { UserId } from '@xrengine/common/src/interfaces/UserId' import { Entity } from '../../ecs/classes/Entity' export * from 'ts-matches' const matchesVec3Shape = matches.shape({ x: matches.number, y: matches.number, z: matches.number }) const matchesQuatShape = matches.some( matches.shape({ _x: matches.number, _y: matches.number, _z: matches.number, _w: matches.number }), matches.shape({ x: matches.number, y: matches.number, z: matches.number, w: matches.number }) ) const matchesVector3 = matches.guard((v): v is Vector3 => matchesVec3Shape.test(v)) const matchesQuaternion = matches.guard((v): v is Quaternion => matchesQuatShape.test(v)) const matchesUserId = matches.string as Validator const matchesPeerID = matches.string as Validator const matchesNetworkId = matches.number as Validator const matchesEntity = matches.number as Validator const matchesEntityUUID = matches.string as Validator const matchesActionFromUser = (userId: UserId) => { return matches.shape({ $from: matches.literal(userId) }) } export type MatchesWithDefault = { matches: Validator; defaultValue: () => A } const matchesWithDefault = (matches: Validator, defaultValue: () => A): MatchesWithDefault => { return { matches, defaultValue } } export { matchesUserId, matchesPeerID, matchesNetworkId, matchesEntity, matchesEntityUUID, matchesVector3, matchesQuaternion, matchesActionFromUser, matchesWithDefault }