How to use excludeProps method in chai

Best JavaScript code snippet using chai

graphql-client.js

Source:graphql-client.js Github

copy

Full Screen

1'use strict'2import omit from 'lodash/omit'3import isEmpty from 'lodash/isEmpty'4import size from 'lodash/size'5import extend from 'lodash/extend'6import getPropertyAtPath from 'lodash/get'7import { utils as tradleUtils } from '@tradle/engine'8import { GraphQLClient } from 'graphql-request'9import constants from '@tradle/constants'10import utils from '../../utils/utils'11const {12 TYPE,13 SIG,14 ROOT_HASH,15 PREV_HASH,16 CUR_HASH,17} = constants18const { MONEY, ORGANIZATION, MESSAGE, MODEL, FORM, IDENTITY } = constants.TYPES19const PHOTO = 'tradle.Photo'20const COUNTRY = 'tradle.Country'21const PUB_KEY = 'tradle.PubKey'22const APPLICATION = 'tradle.Application'23const APPLICATION_SUBMISSION = 'tradle.ApplicationSubmission'24const BOOKMARKS_FOLDER = 'tradle.BookmarksFolder'25const NETWORK_FAILURE = 'Failed to fetch'26const INVALID_QUERY = 'Syntax Error GraphQL request'27const WRONG_VERSION_ID = 'expected models with versionId: '28const INTERNAL_SERVER_ERROR_MSG = 'Internal Server Error'29const INTERNAL_SERVER_ERROR = 50030const MAX_ATTEMPTS = 331var messageMap = {32 [NETWORK_FAILURE]: 'networkFailure',33 [INVALID_QUERY]: 'invalidQuery',34}35const useApollo = false36var search = {37 initClient(meDriver, url) {38 return this.initClientGraphQLRequest(meDriver, url)39 },40 initClientGraphQLRequest(meDriver, url, headers) {41 // debugger42 let graphqlEndpoint = `${url.replace(/[/]+$/, '')}/graphql`43 if (!graphqlEndpoint)44 return45 this.graphqlEndpoint = graphqlEndpoint46 this.meDriver = meDriver47 // Not needed but just to make it generic48 return new GraphQLClient(graphqlEndpoint, { headers })49 },50 async searchServer(params) {51 let {client, modelName, filterResource, sortProperty, asc, limit,52 endCursor, properties, select, excludeProps, bookmark} = params53 if (filterResource && !Object.keys(filterResource).length)54 filterResource = null55 let table = `rl_${modelName.replace(/\./g, '_')}`56 let model = utils.getModel(modelName)57 let versionId = params.versionId || model._versionId58 let version = versionId ? '($modelsVersionId: String!)' : ''59 let query = `query ${version} {\n${table}\n`60 let props = model.properties61 let inClause = []62 let op = {63 CONTAINS: '',64 EQ: '',65 NEQ: '',66 NULL: '',67 STARTS_WITH: '',68 GT: '',69 GTE: '',70 LT: '',71 LTE: '',72 }73 let exclude = [ROOT_HASH, CUR_HASH, TYPE]74 if (excludeProps)75 exclude.concat(excludeProps)76 if (filterResource) {77 for (let p in filterResource) {78 if (exclude.indexOf(p) !== -1)79 continue80 let val = filterResource[p]81 let neq82 if (p.endsWith('!')) {83 neq = true84 p = p.slice(0, -1)85 }86 if (!props[p] && val) {87 if (p.charAt(0) === '_') {88 if (Array.isArray(val)) {89 let s = `${p}: [`90 val.forEach((r, i) => {91 if (i)92 s += ', '93 s += `"${r}"`94 })95 s += ']'96 inClause.push(s)97 }98 else99 this.addTo(op, neq, `\n ${p}: "${val}",`)100 }101 else if (p.indexOf('.') !== -1 && props[p.split('.')[0]]) {102 p = p.replace('.', '__')103 this.addTo(op, neq, `\n ${p}: "${val}",`)104 }105 continue106 }107 if (!props[p] || props[p].hidden)108 continue109 if (props[p].type === 'string') {110 if (Array.isArray(val)) {111 let s = `${p}: [`112 val.forEach((r, i) => {113 if (i)114 s += ', '115 s += `"${r}"`116 })117 s += ']'118 inClause.push(s)119 continue120 }121 if (!val || !val.trim().length) {122 if (val === null)123 op.NULL += `\n ${p}: true`124 continue125 }126 let len = val.length127 if (val.indexOf('*') === -1)128 this.addTo(op, neq, `\n ${p}: "${val}",`)129 else if (len > 1) {130 if (val.charAt(0) === '*') {131 if (val.charAt(val.length - 1) === '*')132 op.CONTAINS = `\n ${p}: "${val.substring(1, len - 1)}",`133 else134 op.CONTAINS = `\n ${p}: "${val.substring(1)}",`135 }136 else if (val.charAt(len - 1) === '*')137 op.STARTS_WITH = `\n ${p}: "${val.substring(0, len - 1)}",`138 }139 }140 else if (props[p].type === 'boolean') {141 if (val)142 op.EQ += `\n ${p}: ${val},`143 else if (val === null) {144 if (!bookmark)145 op.NULL += `\n ${p}: true`146 }147 else148 op.NEQ += `\n ${p}: true,`149 }150 else if (props[p].type === 'number')151 addEqualsOrGreaterOrLesserNumber(val, op, props[p])152 else if (props[p].type === 'date')153 op.GTE = `\n ${p}: "${typeof val === 'date' && val || new Date(val).getTime()}",`154 else if (props[p].type === 'object') {155 let isEnum = props[p].ref && utils.isEnum(props[p].ref)156 if (Array.isArray(val)) {157 if (!val.length)158 continue159 if (isEnum) {160 if (val.length === 1) {161 this.addTo(op, neq, `\n ${p}__id: "${val[0].id}",`)162 }163 else {164 let s = `${p}__id: [`165 val.forEach((r, i) => {166 if (i)167 s += ', '168 s += `"${r.id}"`169 })170 s += ']'171 inClause.push(s)172 }173 }174 else {175 if (val.length === 1) {176 this.addTo(op, neq, `\n ${p}___permalink: "${utils.getRootHash(val[0])}",`)177 }178 else {179 let s = `${p}___permalink: [`180 val.forEach((r, i) => {181 if (i)182 s += ', '183 s += `"${utils.getRootHash(r)}"`184 })185 s += ']'186 inClause.push(s)187 }188 }189 }190 else {191 if (isEnum) {192 this.addTo(op, neq, `\n ${p}__id: "${val.id}",`)193 }194 else if (props[p].ref === MONEY) {195 let {value, currency} = val196 this.addTo(op, neq, `\n ${p}__currency: "${currency}",`)197 if (val.value)198 addEqualsOrGreaterOrLesserNumber(value, op, props[p])199 }200 else if (val && (typeof val === 'string') && val.indexOf('NULL') !== -1) {201 if (val === 'NULL')202 op.NULL += `\n ${p}: true`203 else204 op.NULL += `\n ${p}: false`205 continue206 }207 else {208 this.addTo(op, neq, `\n ${p}___permalink: "${utils.getRootHash(val)}",`)209 }210 }211 }212 else if (props[p].type === 'array') {213 if (props[p].items.ref) {214 if (!val.length)215 continue216 if (val.length === 1 && val[0].indexOf('NULL') !== -1) {217 if (val[0] === 'NULL')218 op.NULL += `\n ${p}: true`219 else220 op.NULL += `\n ${p}: false`221 continue222 }223 let s = `${p}___permalink: [`224 val.forEach((r, i) => {225 if (i)226 s += ', '227 s += `"${utils.getRootHash(r)}"`228 })229 s += ']'230 inClause.push(s)231 }232 }233 }234 }235 op.IN = inClause ? inClause.join(',') : ''236 let qq = ''237 for (let o in op) {238 let q = op[o]239 if (q.length) {240 qq +=241 `\n ${o}: {242 ${op[o]}\n},`243 }244 }245 query += '('246 if (versionId)247 query += `\nmodelsVersionId: $modelsVersionId\n`248 if (limit) {249 if (endCursor)250 query += `checkpoint: "${endCursor}"\n`251 query += `limit: ${limit}\n`252 }253 if (qq.length)254 query += `filter: { ${qq} },\n`255 if (sortProperty) {256 let sortBy257 let ref = props[sortProperty].ref258 if (ref) {259 if (ref === MONEY)260 sortBy = sortProperty + '__value'261 else262 sortBy = sortProperty + '__title'263 }264 else265 sortBy = sortProperty266 query += `\norderBy: {267 property: ${sortBy},268 desc: ${asc ? false : true}269 }`270 }271 else272 query += `\norderBy: {273 property: _time,274 desc: true275 }`276 query += ')'277 query += `\n{\n`278 query += `pageInfo {\n endCursor\n}\n`279 query += `edges {\n node {\n`280 if (!select) {281 select = this.getSearchProperties({model, properties, isList: true, excludeProps})282 }283 query += `${select.join(' \n')}`284 query += `\n}` // close 'node'285 query += `\n}` // close 'edges'286 query += `\n}` // close properties block287 query += `\n}` // close query288 let error, mapping, retry = true289 for (let attemptsCnt=0; attemptsCnt<MAX_ATTEMPTS && retry; attemptsCnt++) {290 let data = await this.execute({client, query, table, versionId})291 if (data.result) {292 return { result: data.result }293 }294 ({ error='', excludeProps={}, retry=true, mapping={}, versionId='' } = await this.checkError(data, model))295 if (excludeProps.length) {296 params.excludeProps = excludeProps297 params.mapping = mapping298 return await this.searchServer(params)299 }300 if (versionId && versionId !== this.versionId) {301 params.versionId = versionId302 return await this.searchServer(params)303 }304 if (error && error === NETWORK_FAILURE || !retry)305 break306 }307 console.log(error)308 return { error: messageMap[error] || error, retry }309 function addEqualsOrGreaterOrLesserNumber(val, op, prop) {310 let isMoney = prop.ref === MONEY311 let p = prop.name312 if (isMoney)313 p += '__value'314 let ch = val.toString().charAt(0)315 switch (ch) {316 case '>':317 if (val.charAt(1) === '=')318 op.GTE += `\n ${p}: ${val.substring(2)},`319 else320 op.GT += `\n ${p}: ${val.substring(1)},`321 break322 case '<':323 if (val.charAt(1) === '=')324 op.LTE += `\n ${p}: ${val.substring(2)},`325 else326 op.LT += `\n ${p}: ${val.substring(1)},`327 break328 default:329 op.EQ += `\n ${p}: ${val},`330 }331 }332 },333 addTo(op, neq, condition) {334 if (neq)335 op.NEQ += condition336 else337 op.EQ += condition338 },339 async getChat(params) {340 let { author, client, context, filterResource, limit, endCursor, application } = params341 let table = `rl_${MESSAGE.replace(/\./g, '_')}`342 let contextVar = filterResource || context ? '' : '($context: String)'343 let limitP = limit ? `limit: ${limit}` : ''344 let checkpoint = limit && endCursor ? `checkpoint: "${endCursor}"\n` : ''345 // let desc = !direction || direction === 'down' ? true : false346 let desc = true347 // if (endCursor)348 // debugger349 let queryHeader =350 `query ${contextVar} {351 ${table} (352 ${limitP}353 ${checkpoint}354 filter: {355 `356 let queryFooter = `357 }358 orderBy:{359 property: _time360 desc: ${desc}361 }362 )363 {364 pageInfo { endCursor }365 edges {366 node {367 _author368 _recipient369 _inbound370 originalSender371 object372 _time373 context374 }375 }376 }377 }`378 let eq = `379 EQ: {380 `381 // for app view prevent prevent from displaying double wrapped messages382 if (author) // && (!context || application))383 eq += `_counterparty: "${author}"\n`384 let filter = ''385 if (filterResource) {386 for (let p in filterResource) {387 if (typeof filterResource[p] === 'boolean')388 filter += ' ' + p + ': ' + `${filterResource[p]}\n`389 else390 filter += ' ' + p + ': ' + `"${filterResource[p]}"\n`391 }392 }393 eq += filter394 if (context)395 eq += ` context: "${context}"`396 eq += `397 },398 `399 let neq = ''400 if (!context && !filterResource) {401 context = null402 neq = `403 NEQ: {404 context: $context405 _payloadType: "${MESSAGE}"406 }407 `408 }409 if (!neq && application) {410 neq = `411 NEQ: {412 _payloadType: "${MESSAGE}"413 }414 `415 }416 let query = queryHeader + eq + neq + queryFooter417 try {418 let result = await this.execute({client, query, table})419 return result && result.result420 } catch (err) {421 debugger422 }423 },424 async getBookmarkChat(params) {425 let { author, client, context, filterResource, limit, endCursor, application,426 sortProperty, asc } = params427 let table = `rl_${MESSAGE.replace(/\./g, '_')}`428 let contextVar = filterResource || context ? '' : '($context: String)'429 let limitP = `limit: ${limit || 20}`430 let checkpoint = limit && endCursor ? `checkpoint: "${endCursor}"\n` : ''431 // let desc = !direction || direction === 'down' ? true : false432 let orderBy = sortProperty || '_time'433 let desc434 if (orderBy && typeof asc !== 'undefined')435 desc = params.hasOwnProperty('asc') ? asc : true436 else437 desc = true438 let props = utils.getModel(MESSAGE).properties439 // if (endCursor)440 // debugger441 let queryHeader =442 `query ${contextVar} {443 ${table} (444 ${limitP}445 ${checkpoint}446 filter: {447 `448 let queryFooter = `449 }450 orderBy:{451 property: ${orderBy}452 desc: ${desc}453 }454 )455 {456 pageInfo { endCursor }457 edges {458 node {459 _author460 _recipient461 _link462 _permalink463 originalSender464 _payloadType465 _payloadLink466 _time467 context468 }469 }470 }471 }`472 let op = {473 CONTAINS: '',474 EQ: '',475 IN: '',476 NEQ: '',477 NULL: '',478 STARTS_WITH: '',479 GT: '',480 GTE: '',481 LT: '',482 LTE: '',483 }484 // for app view prevent prevent from displaying double wrapped messages485 if (author) // && (!context || application))486 op.EQ += `_counterparty: "${filterResource._counterparty || author}"\n`487 if (filterResource) {488 for (let p in filterResource) {489 if (p === TYPE)490 continue491 let val = filterResource[p]492 if (Array.isArray(val))493 op.IN += `\n ${p}: ["${val.join('\",\"')}"],`494 else if (typeof val === 'string' && props[p].type === 'string') {495 let len = val.length496 if (val.charAt(0) === '*') {497 if (val.charAt(len - 1) === '*')498 op.CONTAINS += `\n ${p}: "${val.substring(1, len - 1)}",`499 else500 op.CONTAINS += `\n ${p}: "${val.substring(1)}",`501 }502 else if (val.charAt(len - 1) === '*')503 op.STARTS_WITH += `\n ${p}: "${val.substring(0, len - 1)}",`504 else505 op.EQ += ' ' + p + ': ' + `"${val}"\n`506 }507 else if (props[p].type === 'date')508 op.GTE = `\n ${p}: "${new Date(val).getTime()}",`509 else if (typeof val === 'boolean')510 op.EQ += ' ' + p + ': ' + `${val}\n`511 else512 op.EQ += ' ' + p + ': ' + `"${val}"\n`513 }514 }515 if (context)516 op.EQ += ` context: "${context}"`517 else //if (filterResource && filterResource.hasOwnProperty('context') && typeof filterResource.context !== 'string') {518 op.NULL += ` context: false `519 if (!context && !filterResource) {520 context = null521 op.NEQ += `522 context: $context523 _payloadType: "${MESSAGE}"524 `525 }526 if (!op.NEQ && application) {527 op.NEQ = ` _payloadType: "${MESSAGE}"`528 }529 let qq = ''530 for (let o in op) {531 let q = op[o]532 if (q.length) {533 qq +=534 `\n ${o}: {535 ${op[o]}\n},`536 }537 }538 let query = queryHeader + qq + queryFooter539 try {540 let result = await this.execute({client, query, table})541 return result && result.result542 } catch (err) {543 debugger544 }545 },546 getSearchProperties(params) {547 let { model, inlined, properties, backlink } = params548 let props = /*backlink ? {[backlink.name]: backlink} :*/ model.properties549 let arr550 if (utils.isInlined(model))551 arr = [] //[TYPE] //, '_link', '_permalink']552 else {553 arr = ['_permalink', '_link', '_p', '_time', '_author', '_org', '_authorTitle', '_time']554 if (model.id !== PUB_KEY && !inlined) {555 let newarr = arr.concat(TYPE, SIG)556 arr = newarr557 }558 if (model.abstract)559 return arr560 arr.push(`_seal {561 txId,562 blockchain,563 network,564 _time565 }`)566 }567 if (properties) {568 let newProps = {}569 properties.forEach((p) => newProps[p] = props[p])570 props = newProps571 }572 return this.addProps({...params, props, model, arr})573 },574 addRef(prop) {575 let ref = prop.type === 'array' ? prop.items.ref : prop.ref576 let p = prop.name577 if (ref === MONEY) {578 return (579 `${p} {580 value581 currency582 }`583 )584 }585 else if (ref === COUNTRY) {// || ref === CURRENCY)586 return (587 `${p} {588 id589 title590 }`591 )592 }593 let m = utils.getModel(ref)594 if (utils.isEnum(m)) {595 if (m.enum)596 return (597 `${p} {598 id599 title600 }`601 )602 else603 return p604 }605 if (m.id === PHOTO) {606 return (607 `${p} {${this.getSearchProperties({model: m})}}`608 )609 }610 return (611 `${p} {612 ${TYPE}613 _permalink614 _link615 _displayName616 }`617 )618 },619 addProps({isList, backlink, props, currentProp, arr, model, excludeProps, mapping, noBacklinks}) {620 if (!arr)621 arr = []622 let isApplication = model && model.id === APPLICATION623 let me = utils.getMe()624 for (let p in props) {625 if (excludeProps && excludeProps.indexOf(p) !== -1)626 continue627 if (p.charAt(0) === '_') {628 if (me.isEmployee) {629 if (p === '_sourceOfData' || p === '_dataLineage')630 arr.push(p)631 }632 continue633 }634 if (p === 'from' || p === 'to' || p.indexOf('_group') !== -1)635 continue636 let prop = props[p]637 if (prop.virtual || prop === currentProp)638 continue639 if (prop.displayAs)640 continue641 let ptype = prop.type642 if (ptype === 'array') {643 // let excludePropsFor = mapping && prop.items.ref && mapping[prop.items.ref]644 // this.addArrayProperty({prop, model, arr, isList, backlink, currentProp, excludeProps: excludePropsFor})645 let excludePropsFor646 if (prop.items.ref === model.id)647 excludePropsFor = excludeProps648 else649 excludePropsFor = mapping && prop.items.ref && mapping[prop.items.ref]650 this.addArrayProperty({prop, model, arr, isList, backlink, currentProp, excludeProps, noBacklinks})651 continue652 }653 if (ptype !== 'object') {654 arr.push(p)655 continue656 }657 let ref = prop.ref658 if (!ref) {659 if (prop.range === 'json')660 arr.push(p)661 continue662 }663 if (ref === ORGANIZATION)664 continue665 if (prop.inlined || utils.getModel(ref).inlined)666 arr.push(this.addInlined({prop}))667 else668 arr.push(this.addRef(prop))669 }670 return arr671 },672 addArrayProperty({prop, model, arr, isList, backlink, currentProp, excludeProps, noBacklinks}) {673 let p = prop.name674 let isApplication = model && model.id === APPLICATION675 // if (p === 'verifications')676 // return677 let isSubmissions678 if (isApplication) {679 if (isList && p !== 'relationshipManagers')680 return681 isSubmissions = p === 'submissions'682 if (!backlink && prop.items.ref === APPLICATION_SUBMISSION && !isSubmissions)683 return684 }685 let isBookmarksFolder = model && model.id === BOOKMARKS_FOLDER686 let iref = prop.items.ref687 if (iref) {688 let isInlined = iref !== MODEL && utils.isInlined(utils.getModel(iref))689 if (prop.items.backlink && !prop.inlined) { // && !utils.getModel(iref).abstract) {690 if (isList && !isApplication && !isBookmarksFolder)691 return692 let props693 if (iref !== model.id) {694 if (noBacklinks) return695 props = this.getSearchProperties({model: utils.getModel(iref), noBacklinks: true})696 }697 // HACK698 else if (isApplication)699 props = arr.concat(['hasFailedChecks', 'hasCheckOverrides'])700 else701 props = arr702 arr.push(`${p}${isSubmissions && '(limit: 100)' || ''} {703 edges {704 node {705 ${props}706 }707 }708 }`)709 }710 else if (prop.inlined || isInlined) {711 if (currentProp && currentProp === prop)712 return713 arr.push(this.addInlined({prop, excludeProps}))714 }715 else716 arr.push(717 `${p} {718 ${TYPE}719 _permalink720 _link721 _displayName722 }`723 )724 }725 else {726 let allProps = this.addProps({isList, props: prop.items.properties, excludeProps})727 if (allProps.length) {728 arr.push(729 `${p} {730 ${allProps.toString().replace(/,/g, '\n')}731 }`732 )733 }734 else735 arr.push(p)736 }737 },738 addInlined({prop, excludeProps}) {739 let ref = prop.type === 'array' ? prop.items.ref : prop.ref740 let p = prop.name741 if (ref === MODEL)742 return `${p}`743 let refM = utils.getModel(ref)744 if (prop.range === 'json')745 return p746 if (refM.abstract)747 return p748 if (/*ref === FORM || */ refM.isInterface || utils.isEnum(refM)) {749 return (750 `${p} {751 id752 title753 }`754 )755 }756 else {757 let allProps = this.getSearchProperties({model: refM, inlined: true, currentProp: prop, noBacklinks: true, excludeProps})758 return (759 `${p} {760 ${allProps.toString().replace(/,/g, '\n')}761 }`762 )763 }764 },765 async getItem({id, client, backlink, noBacklinks, excludeProps, mapping, isChat, isThisVersion}) {766 let [modelName, _permalink, _link] = id.split('_')767 let model = utils.getModel(modelName)768 if (!model)769 return770 let table = `r_${modelName.replace(/\./g, '_')}`771 let query772 if (isChat || isThisVersion)773 query = `query {\n${table} (_link: "${_link}")\n`774 else775 query = `query {\n${table} (_permalink: "${_permalink}")\n`776 if (backlink || noBacklinks) {777 if (!excludeProps)778 excludeProps = []779 let itemsProps = utils.getPropertiesWithAnnotation(model, 'items')780 if (size(itemsProps) > 1) {781 if (noBacklinks)782 itemsProps = Object.keys(itemsProps)783 else784 itemsProps = Object.keys(itemsProps).filter(item => item !== backlink.name)785 excludeProps = excludeProps.concat(itemsProps)786 }787 }788 let arr = this.getSearchProperties({model, backlink, excludeProps, mapping})789 query += `\n{${arr.join(' \n')}\n}\n}`790 try {791 let result = await this.execute({client, query, table})792 if (result.error && !excludeProps) {793 let { excludeProps, error, mapping } = await this.checkError(result, model)794 if (excludeProps)795 return await this.getItem({ id, client, backlink, excludeProps, mapping, isThisVersion })796 }797 return result.result798 }799 catch(err) {800 console.log('graphQL._getItem', err)801 debugger802 }803 },804 async checkError(result, model) {805 let message, graphQLErrors, networkError806 if (useApollo) {807 ({ message, graphQLErrors, networkError } = result.error)808 }809 else {810 debugger811 if (result.error.response) {812 debugger813 // if (result.error.response.error === INTERNAL_SERVER_ERROR)814 // return {error: result.error.response.error, retry: true}815 const { errors, status, error } = result.error.response816 if (status === INTERNAL_SERVER_ERROR || error === INTERNAL_SERVER_ERROR_MSG) {817 if (errors && errors.length === 1) {818 if (errors[0].message.indexOf(WRONG_VERSION_ID) === 0)819 return {error, retry: true, versionId: errors[0].message.split(': ')[1]}820 }821 return {error, retry: true}822 }823 graphQLErrors = result.error.response.errors824 message = INVALID_QUERY825 }826 else {827 graphQLErrors = []828 if (result.error.message === 'Failed to fetch')829 return { error: NETWORK_FAILURE }830 message = result.error.message831 }832 }833 if (graphQLErrors && graphQLErrors.length) {834 let { excludeProps, mapping } = this.getExcludeProps(graphQLErrors, model)835 if (excludeProps.length)836 return { excludeProps, mapping }837 return { error: message, retry: message === NETWORK_FAILURE }838 }839 debugger840 if (networkError && networkError.message === NETWORK_FAILURE)841 return { error: NETWORK_FAILURE }842 if (message.indexOf(INVALID_QUERY) === 0)843 message = INVALID_QUERY844 await utils.submitLog(true)845 return { error: message, retry: false }846 },847 getExcludeProps(graphQLErrors, model) {848 let excludeProps = []849 let mapping = {}850 let str = 'Cannot query field \"'851 let len = str.length852 let props = model.properties853 graphQLErrors.forEach(err => {854 if (err.path) {855 if (err.path === 1)856 return857 let prop858 for (let i=err.path.length - 1; i>=0 && !prop; i--) {859 let p = err.path[i]860 if (props[p])861 prop = p862 }863 if (prop) {864 excludeProps.push(prop)865 return866 }867 }868 let msg = err.message869 let idx = msg.indexOf(str)870 if (idx !== 0)871 return872 idx = msg.indexOf('\"', len)873 let field = msg.substring(len, idx)874 // check if this is the table itself that is not recognized875 if (field.indexOf(`_${model.id.replace('.', '_')}`) === -1) {876 excludeProps.push(field)877 let idx = msg.indexOf(' on type "')878 if (idx === -1)879 return880 let idx2 = msg.indexOf('"', idx + 10)881 if (idx2 === -1)882 return883 let type = msg.slice(idx + 10, idx2).replace(/_/g, '.')884 if (utils.getModel(type)) {885 let props = mapping[type]886 if (!props)887 mapping[type] = []888 mapping[type].push(field)889 }890 }891 })892 return { excludeProps, mapping }893 },894 // TODO: rename _getItem to getItem895 // getItem: (...args) => search._getItem(...args),896 async getObjects(links, client) {897 let table = 'rl_objects'898 let query = `899 query {900 ${table} (901 links: ["${links.join('","')}"]902 )903 {904 objects905 }906 }`907 try {908 let result = await this.execute({client, query, table})909 return result.result && result.result.objects || []910 }911 catch(err) {912 console.log('graphQL._getItem', err)913 return []914 debugger915 }916 },917 async getIdentity({ client, _permalink, _link, pub }) {918 if (_link) return search.getIdentityByLink({ client, link: _link })919 if (_permalink) return search.getIdentityByPermalink({ client, permalink: _permalink })920 if (!pub) throw new Error('querying identities by _permalink is not supported at this time')921 const list = await search.searchServer({922 client,923 filterResource: { pub, importedFrom: null },924 select: ['link', 'permalink'],925 modelName: 'tradle.PubKey',926 noTrigger: true,927 limit: 1928 })929 if (list) {930 const pubKeyMapping = getFirstNode(list.result)931 if (pubKeyMapping) {932 return search.getIdentityByPermalink({ permalink: pubKeyMapping.permalink, client })933 // return search.getIdentityByLink({ link: pubKeyMapping.link, client })934 }935 }936 throw new Error(`identity not found with pub: ${pub}`)937 },938 async getIdentityByPermalink({permalink, client}) {939 let table = 'rl_tradle_Identity'940 let arr = ['_p', '_time', '_author', '_v', '_pv', '_ph', '_time', '_s']941 let pubArr = ['type', 'purpose', 'pub', 'fingerprint', 'curve', 'importedFrom', 'networkName']942 let query = `query {943 ${table} (944 limit:1945 orderBy: {946 property: _time,947 desc: true948 }949 filter:{950 EQ: {951 _permalink: "${permalink}"952 },953 }954 ) {955 edges {956 node {957 ${arr}958 pubkeys {959 ${pubArr}960 }961 }962 }963 }964 }`965 try {966 let data = await this.execute({query, table})967 if (data.result && data.result.edges.length) {968 // let ret = omit(data.result.edges[0].node, ['_permalink'])969 let ret = { ...data.result.edges[0].node }970 for (let p in ret) {971 if (!ret[p])972 delete ret[p]973 }974 if (ret._v)975 ret[ROOT_HASH] = permalink976 ret[TYPE] = IDENTITY977 ret.pubkeys.map(pub => {978 for (let p in pub)979 if (!pub[p]) delete pub[p]980 })981 // debugger982 return ret983 }984 } catch (err) {985 console.log(`unknown identity ${permalink}`, err)986 throw new Error(`identity with permalink: ${permalink}`)987 }988 },989 getIdentityByLink: async ({ link, client }) => {990 const results = await search.getObjects([link], client)991 if (isEmpty(results)) throw new Error(`identity not found with link: ${link}`)992 return results[0]993 },994 async getMasterAuthorKey({pub, importedFrom}) {995 let table = 'rl_tradle_PubKey'996 let query = `query {997 ${table}(998 limit:1999 orderBy: {1000 property: _time,1001 desc: true1002 }1003 filter:{1004 EQ: {1005 pub: "${pub}",1006 importedFrom: "${importedFrom}"1007 },1008 }1009 ) {1010 edges {1011 node {1012 permalink1013 }1014 }1015 }1016 }`1017 let data = await this.execute({query, table})1018 if (data.result && data.result.edges.length)1019 return data.result.edges[0].node.permalink1020 },1021 async execute(params) {1022 if (useApollo)1023 return this.executeApollo(params)1024 var {query, table, versionId} = params1025 let variables = versionId && {modelsVersionId: versionId} || undefined1026 // debugger1027 const rawBody = { query }1028 if (variables) rawBody.variables = variables1029 const body = tradleUtils.stringify(rawBody)1030 let obj = {1031 [TYPE]: 'tradle.GraphQLQuery',1032 body,1033 _time: Date.now()1034 }1035 let { _masterAuthor } = utils.getMe()1036 if (_masterAuthor)1037 extend(obj, {_masterAuthor})1038 const result = await this.meDriver.sign({1039 object: obj1040 })1041 // const result = await this.meDriver.sign({ object })1042 const headers = {1043 'x-tradle-auth': JSON.stringify(omit(result.object, ['body', TYPE]))1044 }1045 let client = new GraphQLClient(this.graphqlEndpoint, { headers })1046 try {1047 let data = await client.rawRequest(query, variables)1048 if (data.data) {1049 // if (data.data[table].objects)1050 // data.data[table].objects = data.data[table].objects.filter(r => r !== null)1051 return {result: data.data[table]}1052 }1053 else1054 return {error: JSON.stringify(data.errors && data.errors || data)}1055 } catch (error) {1056 console.log(error)1057// debugger1058 return { error }1059 }1060 }1061}1062// const neuter = obj => utils.omitVirtual(utils.sanitize(obj))1063const getFirstNode = result => getPropertyAtPath(result, ['edges', '0', 'node'])...

Full Screen

Full Screen

open-export-dialog.js

Source:open-export-dialog.js Github

copy

Full Screen

1import ui from '../util/ui';2import exportUtils from '../util/export';3import sketchUtils from '../util/sketch';4import exportComponents from './export-components';5export default function(context, opts, cb) {6 ui.createSettingsDialog(context, opts, exportComponents, (data) => {7 // Defaults8 data.propertyNamingConvention = data.propertyNamingConvention || 'Numeric';9 data.cssUnit = (data.cssUnit === 'No unit' ? 0 : data.cssUnit);10 // First store the properties we should exclude11 let excludeProps = [];12 if (data['excludeProps']['Color']) {13 excludeProps.push('color');14 }15 if (data['excludeProps']['Line height']) {16 excludeProps.push('lineHeight');17 }18 // Get the text styles from the Sketch document19 let textStyles = sketchUtils.getTextStyles(context);20 textStyles = exportUtils.sortTextStyles(textStyles);21 textStyles = exportUtils.excludeTextStyleProperties(textStyles, excludeProps);22 if (data['merge']) {23 textStyles = exportUtils.removeDoubleTextStyles(textStyles);24 }25 cb(textStyles, data);26 });...

Full Screen

Full Screen

excludeProps.test.js

Source:excludeProps.test.js Github

copy

Full Screen

...4 excludeProps5} = mytoolkit6test('excludeProps', t => {7 const o = { a: 1, b: 2, c: 3, d: 4 }8 t.deepEqual(excludeProps(o, 'a'), { b: 2, c: 3, d: 4 })9 t.deepEqual(excludeProps(o, ['a', 'd']), { b: 2, c: 3 })10 t.deepEqual(excludeProps(o, name => name === 'a'), { b: 2, c: 3, d: 4 })11 t.deepEqual(excludeProps(o, name => name !== 'a'), { a: 1 })12 t.end()...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var chai = require('chai');2var expect = chai.expect;3chai.use(require('chai-exclude'));4var obj1 = { a: 1, b: 2, c: 3 };5var obj2 = { a: 1, b: 2, c: 3 };6var obj3 = { a: 1, b: 2, c: 3, d: 4 };7expect(obj1).excluding('a').to.deep.equal(obj2);8expect(obj1).excluding(['a', 'b']).to.deep.equal(obj3);9expect(obj1).excluding('a', 'b').to.deep.equal(obj3);10expect(obj1).excluding('a', 'b').to.deep.equal(obj2);11var chai = require('chai');12var expect = chai.expect;13chai.use(require('chai-exclude'));14var obj1 = { a: 1, b: 2, c: 3 };15var obj2 = { a: 1, b: 2 };16var obj3 = { a: 1, b: 2, c: 3, d: 4 };17expect(obj1).to.containSubset(obj2);18expect(obj1).to.containSubset(obj3);19expect(obj1).to.not.containSubset(obj3);20expect(obj1).to.not.containSubset(obj2);21var chai = require('chai');22var expect = chai.expect;23chai.use(require('chai-exclude'));24var obj1 = { a: 1, b: 2, c: 3 };25var obj2 = { a: 1, b: 2 };26var obj3 = { a: 1, b: 2, c: 3, d: 4 };27expect(obj1).to.includeSubset(obj2);28expect(obj1).to.includeSubset(obj3);29expect(obj1).to.not.includeSubset(obj3);30expect(obj1).to.not.includeSubset(obj2);31var chai = require('chai');32var expect = chai.expect;33chai.use(require('chai-exclude'));34var obj1 = { a: 1, b: 2, c: 3 };35var obj2 = { a: 1, b: 2 };36var obj3 = { a:

Full Screen

Using AI Code Generation

copy

Full Screen

1var chai = require('chai');2var expect = chai.expect;3var chaiExclude = require('chai-exclude');4chai.use(chaiExclude);5var obj1 = {a: 1, b: 2, c: 3};6var obj2 = {a: 1, b: 2, c: 3, d: 4};7expect(obj1).excluding('b').to.deep.equal(obj2);8expect(obj1).excluding(['b', 'c']).to.deep.equal(obj2);9expect(obj1).excludingEvery('b').to.deep.equal(obj2);10expect(obj1).excludingEvery(['b', 'c']).to.deep.equal(obj2);11var chai = require('chai');12var expect = chai.expect;13var chaiExclude = require('chai-exclude');14chai.use(chaiExclude);15var obj1 = {a: 1, b: 2, c: 3};16var obj2 = {a: 1, b: 2, c: 3, d: 4};17expect(obj1).including('b').to.deep.equal(obj2);18expect(obj1).including(['b', 'c']).to.deep.equal(obj2);19expect(obj1).includingEvery('b').to.deep.equal(obj2);20expect(obj1).includingEvery(['b', 'c']).to.deep.equal(obj2);21var chai = require('chai');22var expect = chai.expect;23var chaiExclude = require('chai-exclude');24chai.use(chaiExclude);25var obj1 = {a: 1, b: 2, c: 3};26var obj2 = {a: 1, b: 2, c: 3, d: 4};27expect(obj1).excluding('b').to.deep.equal(obj2);28expect(obj1).excluding(['b', 'c']).to.deep.equal(obj2);29expect(obj1).excludingEvery('b').to.deep.equal(obj2);30expect(obj1).excludingEvery(['b', 'c']).to.deep.equal(obj2);31var chai = require('chai');32var expect = chai.expect;33var chaiExclude = require('chai-exclude');34chai.use(chaiExclude);35var obj1 = {a: 1, b: 2, c: 3};36var obj2 = {

Full Screen

Using AI Code Generation

copy

Full Screen

1const chai = require('chai');2const expect = chai.expect;3const chaiExclude = require('chai-exclude');4chai.use(chaiExclude);5const chai = require('chai');6const expect = chai.expect;7const chaiExclude = require('chai-exclude');8chai.use(chaiExclude);9const chai = require('chai');10const expect = chai.expect;11const chaiExclude = require('chai-exclude');12chai.use(chaiExclude);13const chai = require('chai');14const expect = chai.expect;15const chaiExclude = require('chai-exclude');16chai.use(chaiExclude);17const chai = require('chai');18const expect = chai.expect;19const chaiExclude = require('chai-exclude');20chai.use(chaiExclude);21const chai = require('chai');22const expect = chai.expect;23const chaiExclude = require('chai-exclude');24chai.use(chaiExclude);25const chai = require('chai');26const expect = chai.expect;27const chaiExclude = require('chai-exclude');28chai.use(chaiExclude);29const chai = require('chai');30const expect = chai.expect;31const chaiExclude = require('chai-exclude');32chai.use(chaiExclude);

Full Screen

Using AI Code Generation

copy

Full Screen

1const chai = require('chai');2const chaiExclude = require('chai-exclude');3chai.use(chaiExclude);4const expect = chai.expect;5const obj1 = {6};7const obj2 = {8};9const obj3 = {10};11expect(obj1).excludingEvery(['a', 'b']).to.deep.equal(obj2);12expect(obj1).excludingEvery(['a', 'b']).to.deep.equal(obj3);13const chai = require('chai');14const chaiExclude = require('chai-exclude');15chai.use(chaiExclude);16const expect = chai.expect;17const obj1 = {18};19const obj2 = {20};21const obj3 = {22};23expect(obj1).excludingEvery(['a', 'b']).to.deep.equal(obj2);24expect(obj1).excludingEvery(['a', 'b']).to.deep.equal(obj3);25const chai = require('chai');26const chaiExclude = require('chai-exclude');27chai.use(chaiExclude);28const expect = chai.expect;29const obj1 = {30};31const obj2 = {32};33const obj3 = {34};35expect(obj1).excludingEvery(['a', 'b']).to.deep.equal(obj2);36expect(obj1).excludingEvery(['a', 'b']).to.deep.equal(obj3);37const chai = require('chai');38const chaiExclude = require('chai-exclude');39chai.use(chaiExclude);40const expect = chai.expect;41const obj1 = {

Full Screen

Using AI Code Generation

copy

Full Screen

1const chai = require('chai');2const { expect } = chai;3const chaiExclude = require('chai-exclude');4chai.use(chaiExclude);5describe('test', () => {6 it('test', () => {7 const obj = {8 };9 const obj2 = {10 };11 expect(obj).excluding('a').to.deep.equal(obj2);12 });13});14const chai = require('chai');15const { expect } = chai;16describe('test', () => {17 it('test', () => {18 const obj = {19 };20 const obj2 = {21 };22 expect(obj).to.deep.equal(obj2);23 });24});25{26 "scripts": {27 },28 "devDependencies": {29 }30}

Full Screen

Using AI Code Generation

copy

Full Screen

1const chai = require('chai');2const expect = chai.expect;3const chaiExclude = require('chai-exclude');4chai.use(chaiExclude);5const { excludeProps } = require('chai-exclude');6const obj1 = { a: 1, b: 2 };7const obj2 = { a: 1, b: 2, c: 3 };8expect(obj1).to.deep.equal(obj2);9expect(obj1).excludingEvery('c').to.deep.equal(obj2);10const chai = require('chai');11const expect = chai.expect;12const chaiExclude = require('chai-exclude');13chai.use(chaiExclude);14const { excludeProps } = require('chai-exclude');15const obj1 = { a: 1, b: 2 };16const obj2 = { a: 1, b: 2, c: 3 };17expect(obj1).to.deep.equal(obj2);18expect(obj1).excludingEvery(['c']).to.deep.equal(obj2);19const chai = require('chai');20const expect = chai.expect;21const chaiExclude = require('chai-exclude');22chai.use(chaiExclude);23const { excludeProps } = require('chai-exclude');24const obj1 = { a: 1, b: 2 };25const obj2 = { a: 1, b: 2, c: 3 };26expect(obj1).to.deep.equal(obj2);27expect(obj1).excludingEvery(['c', 'd']).to.deep.equal(obj2);28const chai = require('chai');29const expect = chai.expect;30const chaiExclude = require('chai-exclude');31chai.use(chaiExclude);32const { excludeProps } = require('chai-exclude');33const obj1 = { a: 1, b: 2 };34const obj2 = { a: 1, b: 2, c: 3 };35expect(obj1).to.deep.equal(obj2);36expect(obj1).excludingEvery(['c', 'd']).to.deep.equal(obj2);37const chai = require('chai');38const expect = chai.expect;39const chaiExclude = require('chai-exclude');

Full Screen

Using AI Code Generation

copy

Full Screen

1const chainable = require('chainable');2const obj = { a: 1, b: 2 };3const result = chainable(obj).excludeProps('a').value();4console.log(result);5const chainable = require('chainable');6const obj = { a: 1, b: 2 };7const result = chainable(obj).includeProps('a').value();8console.log(result);9const chainable = require('chainable');10const obj = { a: 1, b: 2 };11const result = chainable(obj).pick(['a', 'b']).value();12console.log(result);13const chainable = require('chainable');14const obj = { a: 1, b: 2 };15const result = chainable(obj).omit(['a']).value();16console.log(result);17const chainable = require('chainable');18const obj = { a: 1, b: 2 };19const result = chainable(obj).merge({ c: 3 }).value();20console.log(result);21const chainable = require('chainable');22const obj = { a: 1, b: 2 };23const result = chainable(obj).clone().value();24console.log(result);25const chainable = require('chainable');26const obj = { a: 1, b: 2 };27const result = chainable(obj).cloneDeep().value();28console.log(result);29const chainable = require('chainable');30const obj = { a: 1, b: 2 };31const result = chainable(obj).invert().value();32console.log(result);

Full Screen

Using AI Code Generation

copy

Full Screen

1var chai = require('chai');2chai.use(require('chai-exclude'));3var expect = chai.expect;4var assert = chai.assert;5describe('Test Case', function() {6 it('Should pass', function() {7 var obj1 = {8 };9 var obj2 = {10 };11 expect(obj1).excluding('a').to.deep.equal(obj2);12 });13});

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run chai automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful