How to use groupOperationNames method in wpt

Best JavaScript code snippet using wpt

ExposeRelations.ts

Source:ExposeRelations.ts Github

copy

Full Screen

1// @ts-nocheck2import { Model, RelationMapping } from 'objection'3import { Field, Info, Arg, InputObjectType, InputField } from '@capaj/typegql'4import getFieldNames from 'graphql-list-fields'5import hasProtochainProperty from './hasProtochainProperty'6import { GraphQLInt, GraphQLString } from 'graphql'7import { capitalize } from 'lodash'8@InputObjectType()9export class FilterDescriptor {10 @InputField({11 type: GraphQLString,12 isNullable: false13 })14 name: string15 @InputField({16 type: GraphQLString,17 isNullable: true18 })19 value?: string20}21@InputObjectType()22export class OrderDescriptor {23 @InputField({24 type: GraphQLString,25 isNullable: false26 })27 name: string28 @InputField({29 type: GraphQLString,30 isNullable: true31 })32 sort?: 'asc' | 'desc'33}34/**35 * Beware, there is some meta magic going on in this file36 */37const applyFilters = (38 modelClass: any,39 query: any,40 filters: FilterDescriptor[]41): void => {42 filters.forEach(({ name, value }) => {43 if (modelClass.namedFilters[name]) {44 modelClass.namedFilters[name](query, value)45 } else {46 throw new Error(47 `Named filter ${name} does not exist on ${modelClass.name}`48 )49 }50 })51}52const applyOrder = (query: any, order: OrderDescriptor[]): void =>53 order.forEach(({ name, sort }) => {54 const direction = sort || 'asc'55 query.orderBy(name, direction)56 })57/**58 * used on a class, it iterates all the relationMappings and exposes them as typegql fields,59 * these fields are actually named with a "RelationResolve" suffix to not get in the way of60 * working with relations on the backend61 *62 * by default all relations are exposed. If you want to opt out, just use `exposeAsTypegqlField: false` on your objection relation mapping63 */64export function ObjectionRelationsAsTypegqlFields(options?): ClassDecorator {65 // tslint:disable-next-line66 return (target: Function) => {67 const { prototype } = target68 if (prototype instanceof Model) {69 // @ts-ignore70 Object.entries(target.relationMappings).forEach(71 ([relationName, objectionRelation]) => {72 // @ts-ignore73 if (objectionRelation.exposeAsTypegqlField === false) {74 return75 }76 // @ts-ignore77 const { relation } = objectionRelation78 const relationToMany =79 relation === Model.ManyToManyRelation ||80 relation === Model.HasManyRelation81 const fieldName = `${relationName}RelationResolver`82 const exportFieldName = `export${capitalize(relationName)}`83 if (relationToMany) {84 prototype[fieldName] = async function(85 info,86 filter?: string,87 filters?: FilterDescriptor[],88 order?: OrderDescriptor[],89 offset?: number,90 limit?: number91 ) {92 if (this[relationName]) {93 return this[relationName]94 }95 // @ts-ignore96 const modelClass = require(objectionRelation.modelClass).default97 let query98 if (options && options.selectRequestedFields) {99 const requestedFields = getFieldNames(info).filter(field => {100 return (101 !field.includes('.') && // fields from deeper levels102 !hasProtochainProperty(modelClass, field) // resolver methods103 )104 })105 const idColumns = Array.isArray(modelClass.idColumn)106 ? modelClass.idColumn107 : [modelClass.idColumn]108 idColumns.forEach(column => {109 if (!requestedFields.includes(column)) {110 requestedFields.push(column)111 }112 })113 query = this.$relatedQuery(relationName).select(requestedFields)114 } else {115 query = this.$relatedQuery(relationName)116 }117 if (filter) {118 if (modelClass.namedFilters[filter]) {119 modelClass.namedFilters[filter](query)120 } else {121 throw new Error(122 `Named filter ${filter} does not exist on ${123 modelClass.name124 }`125 )126 }127 }128 if (filters) {129 applyFilters(modelClass, query, filters)130 }131 if (order) {132 applyOrder(query, order)133 }134 if (limit) {135 query.limit(limit)136 }137 if (offset) {138 query.offset(offset)139 }140 return query141 }142 Info(prototype, fieldName, 0)143 Arg({144 isNullable: true,145 description: 'Deprecated in favour of `filters` param',146 type: String147 })(prototype, fieldName, 1)148 Arg({149 isNullable: true,150 type: [FilterDescriptor]151 })(prototype, fieldName, 2)152 Arg({153 isNullable: true,154 type: [OrderDescriptor]155 })(prototype, fieldName, 3)156 Arg({157 isNullable: true,158 type: GraphQLInt159 })(prototype, fieldName, 4)160 Arg({161 isNullable: true,162 type: GraphQLInt163 })(prototype, fieldName, 5)164 } else {165 prototype[fieldName] = async function(info) {166 if (this[relationName]) {167 return this[relationName]168 }169 // @ts-ignore170 const modelClass = require(objectionRelation.modelClass).default171 let query172 if (options && options.selectRequestedFields) {173 const requestedFields = getFieldNames(info).filter(field => {174 return (175 !field.includes('.') && // fields from deeper levels176 !hasProtochainProperty(modelClass, field) // resolver methods177 )178 })179 const idColumns = Array.isArray(modelClass.idColumn)180 ? modelClass.idColumn181 : [modelClass.idColumn]182 idColumns.forEach(column => {183 if (!requestedFields.includes(column)) {184 requestedFields.push(column)185 }186 })187 query = this.$relatedQuery(relationName).select(requestedFields)188 } else {189 query = this.$relatedQuery(relationName)190 }191 return query192 }193 Info(prototype, fieldName, 0)194 }195 const type = () => {196 // @ts-ignore197 const modelClass = require(objectionRelation.modelClass).default198 if (!modelClass) {199 throw new Error(200 `could not load a default export from ${201 // @ts-ignore202 objectionRelation.modelClass203 }, make sure objection model is exported as default and that the path is correct`204 )205 }206 if (relationToMany) {207 return [modelClass]208 }209 return modelClass210 }211 const isNullable = true212 // if (relation === Model.BelongsToOneRelation) {213 // isNullable = false214 // }215 const decoratorFunction = Field({216 type,217 name: relationName,218 // @ts-ignore219 description: objectionRelation.description,220 isNullable221 })222 decoratorFunction(prototype, fieldName)223 if (relationToMany) {224 const fieldNameCount = `${relationName}Count`225 prototype[fieldNameCount] = async function(226 filter?: string,227 filters?: FilterDescriptor[]228 ) {229 // @ts-ignore230 const modelClass = require(objectionRelation.modelClass).default231 let groupBy232 if (relation === Model.ManyToManyRelation) {233 // @ts-ignore234 groupBy = objectionRelation.join.through.from235 } else {236 // @ts-ignore237 groupBy = objectionRelation.join.to238 }239 const query = this.$relatedQuery(relationName).groupBy(groupBy)240 if (filter) {241 if (modelClass.namedFilters[filter]) {242 modelClass.namedFilters[filter](query)243 } else {244 throw new Error(245 `Named filter ${filter} does not exist on ${246 modelClass.name247 }`248 )249 }250 }251 if (filters) {252 applyFilters(modelClass, query, filters)253 }254 let result255 // Dirty hack to see if filters required extra groupings256 const groupOperationNames = ['groupBy', 'groupByRaw']257 const groupingsCount = query._operations.filter(({ name }) =>258 groupOperationNames.includes(name)259 ).length260 if (groupingsCount > 1) {261 ;[result] = (await query262 .clearSelect()263 .select(Model.raw('COUNT(*) OVER() AS count'))264 .limit(1)) as any[]265 } else {266 result = ((await query.count('*').first()) as any) as {267 count: number268 }269 }270 return (result && result['count(*)']) || 0271 }272 const decoratorFunctionCount = Field({273 type: GraphQLInt,274 name: `${relationName}Count`275 })276 decoratorFunctionCount(prototype, fieldNameCount)277 Arg({278 isNullable: true,279 description: 'Deprecated in favour of `filters` param',280 type: String281 })(prototype, fieldNameCount, 0)282 Arg({283 isNullable: true,284 type: [FilterDescriptor]285 })(prototype, fieldNameCount, 1)286 }287 }288 )289 } else {290 console.warn(target)291 throw new TypeError('target is not objection model')292 }293 }...

Full Screen

Full Screen

interface.js

Source:interface.js Github

copy

Full Screen

...3 * @param {import("../validator.js").Definitions} defs4 * @param {import("../productions/container.js").Container} i5 */6export function* checkInterfaceMemberDuplication(defs, i) {7 const opNames = groupOperationNames(i);8 const partials = defs.partials.get(i.name) || [];9 const mixins = defs.mixinMap.get(i.name) || [];10 for (const ext of [...partials, ...mixins]) {11 const additions = getOperations(ext);12 const statics = additions.filter((a) => a.special === "static");13 const nonstatics = additions.filter((a) => a.special !== "static");14 yield* checkAdditions(statics, opNames.statics, ext, i);15 yield* checkAdditions(nonstatics, opNames.nonstatics, ext, i);16 statics.forEach((op) => opNames.statics.add(op.name));17 nonstatics.forEach((op) => opNames.nonstatics.add(op.name));18 }19 /**20 * @param {import("../productions/operation.js").Operation[]} additions21 * @param {Set<string>} existings22 * @param {import("../productions/container.js").Container} ext23 * @param {import("../productions/container.js").Container} base24 */25 function* checkAdditions(additions, existings, ext, base) {26 for (const addition of additions) {27 const { name } = addition;28 if (name && existings.has(name)) {29 const isStatic = addition.special === "static" ? "static " : "";30 const message = `The ${isStatic}operation "${name}" has already been defined for the base interface "${base.name}" either in itself or in a mixin`;31 yield validationError(32 addition.tokens.name,33 ext,34 "no-cross-overload",35 message36 );37 }38 }39 }40 /**41 * @param {import("../productions/container.js").Container} i42 * @returns {import("../productions/operation.js").Operation[]}43 */44 function getOperations(i) {45 return i.members.filter(({ type }) => type === "operation");46 }47 /**48 * @param {import("../productions/container.js").Container} i49 */50 function groupOperationNames(i) {51 const ops = getOperations(i);52 return {53 statics: new Set(54 ops.filter((op) => op.special === "static").map((op) => op.name)55 ),56 nonstatics: new Set(57 ops.filter((op) => op.special !== "static").map((op) => op.name)58 ),59 };60 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wptClient = wpt('API_KEY');3wptClient.groupOperationNames(function(err, data) {4 if (err) {5 return console.error(err);6 }7 console.log(data);8});9 - `data.medianMetric` **[String][3]** Metric to use for median run (default: "loadTime")10 - `data.median` **[Boolean][5]** Include the median run (default: true)11 - `data.run` **[Number][6]** Return a specific run number (1-based)

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptool = require('wptool');2var fs = require('fs');3var path = require('path');4var Promise = require('bluebird');5var _ = require('underscore');6var wptool = require('wptool');7var config = require('../config');8var wpt = new wptool(config.wptool);9var test = function() {10 var wpt = new wptool(config.wptool);11 var testOptions = {12 };13 var results = wpt.runTest(testUrl, testOptions);14 return results;15};16var test2 = function() {17 var wpt = new wptool(config.wptool);18 var testOptions = {19 };20 var results = wpt.runTest(testUrl, testOptions);21 return results;22};23var test3 = function() {24 var wpt = new wptool(config.wptool);25 var testOptions = {26 };27 var results = wpt.runTest(testUrl, testOptions);28 return results;29};30Promise.join(test(), test2(), test3(), function(one, two, three) {31 var group = wpt.groupOperationNames(one.data.median.firstView, two.data.median.firstView, three.data.median.firstView);32 console.log(group);33});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var api = new wpt('API_KEY');3var options = {4}5 console.log(data);6});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var page = wptools.page('Albert Einstein');3page.groupOperationNames(function(err,resp){4 if(err){5 console.log(err);6 }7 else{8 console.log(resp);9 }10});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var fs = require('fs');3var csv = require('fast-csv');4var async = require('async');5var stream = fs.createReadStream("wikipedia.csv");6var csvStream = csv()7 .on("data", function(data){8 var page = wptools.page(data[0]);9 page.get(function(err, resp) {10 if (err) {11 console.log(err);12 }13 else {14 var group = resp.groupOperationNames();15 console.log(group);16 fs.appendFile('groupOperationNames.txt', group + '\n', function (err) {17 if (err) throw err;18 });19 }20 });21 })22 .on("end", function(){23 console.log("done");24 });25stream.pipe(csvStream);

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 wpt 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