import Resource from '../src' import { DefaultClient } from '../src/client' import RelatedManager from '../src/related' import { normalizerFactory, NumberNormalizer, NestedResourceStringNormalizer, StringNormalizer } from '../src/helpers/normalization' class CustomRelatedManager extends RelatedManager { batchSize = 20 } class CustomClient extends DefaultClient { get() { console.log('GET', arguments[0], arguments[1] || {}) // @ts-ignore return DefaultClient.prototype.get.apply(this, arguments) } patch() { console.log('PATCH', arguments[0], arguments[1] || {}) // @ts-ignore return DefaultClient.prototype.patch.apply(this, arguments) } } class BaseResource extends Resource { static client = new CustomClient('http://localhost:8099') static RelatedManagerClass = CustomRelatedManager } class UserResource extends BaseResource { static endpoint = '/users' static validation = { phone(value: any, instance: UserResource, ValidationError: any) { let regExp = /^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$/im if (!regExp.test(value)) { throw new ValidationError('phone') } }, } } class TodoResource extends BaseResource { static endpoint = '/todos' static related = { user: UserResource, } } class PostResource extends BaseResource { static endpoint = '/posts' static related = { user: UserResource, } } class GroupResource extends BaseResource { static endpoint = '/groups' static related() { return { users: UserResource, owner: { to: UserResource, nested: true }, todos: { to: TodoResource, nested: true, }, } } } class CommentResource extends BaseResource { static endpoint = '/comments' static related = { post: PostResource } } class CommentMeta extends BaseResource { static endpoint = '/commentmeta' static related = { comment: CommentResource } } class CommentOtherMeta extends BaseResource { static endpoint = '/commentothermeta' static related = { meta: CommentMeta } } ;(async function() { let resource = await CommentResource.detail(1) //console.log(UserResource.cache) //console.log(group.managers.owner) //console.log(await resource.resolveAttribute('meta.comment.post.user.name')) console.log(resource.changes) })()