Best JavaScript code snippet using appium-base-driver
plain-client.js
Source:plain-client.js
1function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }2function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }3function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }4import { ALPHA_FEATURE_WORKFLOWS } from '../adapters/REST/endpoints/workflow-definition';5import { omitAndDeleteField as _omitAndDeleteField } from '../methods/content-type';6import { wrap } from './wrappers/wrap';7/**8 * @private9 */10export var createPlainClient = function createPlainClient(makeRequest, defaults, alphaFeatures) {11 var wrapParams = {12 makeRequest: makeRequest,13 defaults: defaults14 };15 return _objectSpread({16 raw: {17 getDefaultParams: function getDefaultParams() {18 return defaults;19 },20 get: function get(url, config) {21 return makeRequest({22 entityType: 'Http',23 action: 'get',24 params: {25 url: url,26 config: config27 }28 });29 },30 patch: function patch(url, payload, config) {31 return makeRequest({32 entityType: 'Http',33 action: 'patch',34 params: {35 url: url,36 config: config37 },38 payload: payload39 });40 },41 post: function post(url, payload, config) {42 return makeRequest({43 entityType: 'Http',44 action: 'post',45 params: {46 url: url,47 config: config48 },49 payload: payload50 });51 },52 put: function put(url, payload, config) {53 return makeRequest({54 entityType: 'Http',55 action: 'put',56 params: {57 url: url,58 config: config59 },60 payload: payload61 });62 },63 "delete": function _delete(url, config) {64 return makeRequest({65 entityType: 'Http',66 action: 'delete',67 params: {68 url: url,69 config: config70 }71 });72 },73 http: function http(url, config) {74 return makeRequest({75 entityType: 'Http',76 action: 'request',77 params: {78 url: url,79 config: config80 }81 });82 }83 },84 appAction: {85 get: wrap(wrapParams, 'AppAction', 'get'),86 getMany: wrap(wrapParams, 'AppAction', 'getMany'),87 "delete": wrap(wrapParams, 'AppAction', 'delete'),88 create: wrap(wrapParams, 'AppAction', 'create'),89 update: wrap(wrapParams, 'AppAction', 'update')90 },91 appActionCall: {92 create: wrap(wrapParams, 'AppActionCall', 'create')93 },94 appBundle: {95 get: wrap(wrapParams, 'AppBundle', 'get'),96 getMany: wrap(wrapParams, 'AppBundle', 'getMany'),97 "delete": wrap(wrapParams, 'AppBundle', 'delete'),98 create: wrap(wrapParams, 'AppBundle', 'create')99 },100 appDetails: {101 upsert: wrap(wrapParams, 'AppDetails', 'upsert'),102 get: wrap(wrapParams, 'AppDetails', 'get'),103 "delete": wrap(wrapParams, 'AppDetails', 'delete')104 },105 appSignedRequest: {106 create: wrap(wrapParams, 'AppSignedRequest', 'create')107 },108 appSigningSecret: {109 upsert: wrap(wrapParams, 'AppSigningSecret', 'upsert'),110 get: wrap(wrapParams, 'AppSigningSecret', 'get'),111 "delete": wrap(wrapParams, 'AppSigningSecret', 'delete')112 },113 editorInterface: {114 get: wrap(wrapParams, 'EditorInterface', 'get'),115 getMany: wrap(wrapParams, 'EditorInterface', 'getMany'),116 update: wrap(wrapParams, 'EditorInterface', 'update')117 },118 space: {119 get: wrap(wrapParams, 'Space', 'get'),120 getMany: wrap(wrapParams, 'Space', 'getMany'),121 update: wrap(wrapParams, 'Space', 'update'),122 "delete": wrap(wrapParams, 'Space', 'delete'),123 create: wrap(wrapParams, 'Space', 'create')124 },125 environment: {126 get: wrap(wrapParams, 'Environment', 'get'),127 getMany: wrap(wrapParams, 'Environment', 'getMany'),128 create: wrap(wrapParams, 'Environment', 'create'),129 createWithId: wrap(wrapParams, 'Environment', 'createWithId'),130 update: wrap(wrapParams, 'Environment', 'update'),131 "delete": wrap(wrapParams, 'Environment', 'delete')132 },133 environmentAlias: {134 get: wrap(wrapParams, 'EnvironmentAlias', 'get'),135 getMany: wrap(wrapParams, 'EnvironmentAlias', 'getMany'),136 createWithId: wrap(wrapParams, 'EnvironmentAlias', 'createWithId'),137 update: wrap(wrapParams, 'EnvironmentAlias', 'update'),138 "delete": wrap(wrapParams, 'EnvironmentAlias', 'delete')139 },140 bulkAction: {141 get: wrap(wrapParams, 'BulkAction', 'get'),142 publish: wrap(wrapParams, 'BulkAction', 'publish'),143 unpublish: wrap(wrapParams, 'BulkAction', 'unpublish'),144 validate: wrap(wrapParams, 'BulkAction', 'validate')145 },146 comment: {147 get: wrap(wrapParams, 'Comment', 'get'),148 getAll: wrap(wrapParams, 'Comment', 'getAll'),149 create: wrap(wrapParams, 'Comment', 'create'),150 update: wrap(wrapParams, 'Comment', 'update'),151 "delete": wrap(wrapParams, 'Comment', 'delete')152 },153 contentType: {154 get: wrap(wrapParams, 'ContentType', 'get'),155 getMany: wrap(wrapParams, 'ContentType', 'getMany'),156 update: wrap(wrapParams, 'ContentType', 'update'),157 "delete": wrap(wrapParams, 'ContentType', 'delete'),158 publish: wrap(wrapParams, 'ContentType', 'publish'),159 unpublish: wrap(wrapParams, 'ContentType', 'unpublish'),160 create: wrap(wrapParams, 'ContentType', 'create'),161 createWithId: wrap(wrapParams, 'ContentType', 'createWithId'),162 omitAndDeleteField: function omitAndDeleteField(params, contentType, fieldId) {163 return _omitAndDeleteField(makeRequest, _objectSpread(_objectSpread({}, _objectSpread(_objectSpread({}, defaults), params)), {}, {164 fieldId: fieldId165 }), contentType);166 }167 },168 user: {169 getManyForSpace: wrap(wrapParams, 'User', 'getManyForSpace'),170 getForSpace: wrap(wrapParams, 'User', 'getForSpace'),171 getCurrent: wrap(wrapParams, 'User', 'getCurrent'),172 getForOrganization: wrap(wrapParams, 'User', 'getForOrganization'),173 getManyForOrganization: wrap(wrapParams, 'User', 'getManyForOrganization')174 },175 task: {176 get: wrap(wrapParams, 'Task', 'get'),177 getAll: wrap(wrapParams, 'Task', 'getAll'),178 create: wrap(wrapParams, 'Task', 'create'),179 update: wrap(wrapParams, 'Task', 'update'),180 "delete": wrap(wrapParams, 'Task', 'delete')181 },182 entry: {183 getMany: wrap(wrapParams, 'Entry', 'getMany'),184 get: wrap(wrapParams, 'Entry', 'get'),185 update: wrap(wrapParams, 'Entry', 'update'),186 patch: wrap(wrapParams, 'Entry', 'patch'),187 "delete": wrap(wrapParams, 'Entry', 'delete'),188 publish: wrap(wrapParams, 'Entry', 'publish'),189 unpublish: wrap(wrapParams, 'Entry', 'unpublish'),190 archive: wrap(wrapParams, 'Entry', 'archive'),191 unarchive: wrap(wrapParams, 'Entry', 'unarchive'),192 create: wrap(wrapParams, 'Entry', 'create'),193 createWithId: wrap(wrapParams, 'Entry', 'createWithId'),194 references: wrap(wrapParams, 'Entry', 'references')195 },196 asset: {197 getMany: wrap(wrapParams, 'Asset', 'getMany'),198 get: wrap(wrapParams, 'Asset', 'get'),199 update: wrap(wrapParams, 'Asset', 'update'),200 "delete": wrap(wrapParams, 'Asset', 'delete'),201 publish: wrap(wrapParams, 'Asset', 'publish'),202 unpublish: wrap(wrapParams, 'Asset', 'unpublish'),203 archive: wrap(wrapParams, 'Asset', 'archive'),204 unarchive: wrap(wrapParams, 'Asset', 'unarchive'),205 create: wrap(wrapParams, 'Asset', 'create'),206 createWithId: wrap(wrapParams, 'Asset', 'createWithId'),207 createFromFiles: wrap(wrapParams, 'Asset', 'createFromFiles'),208 processForAllLocales: function processForAllLocales(params, asset, options) {209 return makeRequest({210 entityType: 'Asset',211 action: 'processForAllLocales',212 params: _objectSpread(_objectSpread({}, _objectSpread(_objectSpread({}, defaults), params)), {}, {213 options: options,214 asset: asset215 })216 });217 },218 processForLocale: function processForLocale(params, asset, locale, options) {219 return makeRequest({220 entityType: 'Asset',221 action: 'processForLocale',222 params: _objectSpread(_objectSpread({}, _objectSpread(_objectSpread({}, defaults), params)), {}, {223 locale: locale,224 asset: asset,225 options: options226 })227 });228 }229 },230 appUpload: {231 get: wrap(wrapParams, 'AppUpload', 'get'),232 "delete": wrap(wrapParams, 'AppUpload', 'delete'),233 create: wrap(wrapParams, 'AppUpload', 'create')234 },235 assetKey: {236 create: wrap(wrapParams, 'AssetKey', 'create')237 },238 upload: {239 get: wrap(wrapParams, 'Upload', 'get'),240 create: wrap(wrapParams, 'Upload', 'create'),241 "delete": wrap(wrapParams, 'Upload', 'delete')242 },243 locale: {244 get: wrap(wrapParams, 'Locale', 'get'),245 getMany: wrap(wrapParams, 'Locale', 'getMany'),246 "delete": wrap(wrapParams, 'Locale', 'delete'),247 update: wrap(wrapParams, 'Locale', 'update'),248 create: wrap(wrapParams, 'Locale', 'create')249 },250 personalAccessToken: {251 get: wrap(wrapParams, 'PersonalAccessToken', 'get'),252 getMany: wrap(wrapParams, 'PersonalAccessToken', 'getMany'),253 create: function create(data, headers) {254 return makeRequest({255 entityType: 'PersonalAccessToken',256 action: 'create',257 params: {},258 headers: headers,259 payload: data260 });261 },262 revoke: wrap(wrapParams, 'PersonalAccessToken', 'revoke')263 },264 usage: {265 getManyForSpace: wrap(wrapParams, 'Usage', 'getManyForSpace'),266 getManyForOrganization: wrap(wrapParams, 'Usage', 'getManyForOrganization')267 },268 release: {269 get: wrap(wrapParams, 'Release', 'get'),270 query: wrap(wrapParams, 'Release', 'query'),271 create: wrap(wrapParams, 'Release', 'create'),272 update: wrap(wrapParams, 'Release', 'update'),273 "delete": wrap(wrapParams, 'Release', 'delete'),274 publish: wrap(wrapParams, 'Release', 'publish'),275 unpublish: wrap(wrapParams, 'Release', 'unpublish'),276 validate: wrap(wrapParams, 'Release', 'validate')277 },278 releaseAction: {279 get: wrap(wrapParams, 'ReleaseAction', 'get'),280 queryForRelease: wrap(wrapParams, 'ReleaseAction', 'queryForRelease')281 },282 role: {283 get: wrap(wrapParams, 'Role', 'get'),284 getMany: wrap(wrapParams, 'Role', 'getMany'),285 create: wrap(wrapParams, 'Role', 'create'),286 createWithId: wrap(wrapParams, 'Role', 'createWithId'),287 update: wrap(wrapParams, 'Role', 'update'),288 "delete": wrap(wrapParams, 'Role', 'delete')289 },290 scheduledActions: {291 get: wrap(wrapParams, 'ScheduledAction', 'get'),292 getMany: wrap(wrapParams, 'ScheduledAction', 'getMany'),293 create: wrap(wrapParams, 'ScheduledAction', 'create'),294 "delete": wrap(wrapParams, 'ScheduledAction', 'delete'),295 update: wrap(wrapParams, 'ScheduledAction', 'update')296 },297 previewApiKey: {298 get: wrap(wrapParams, 'PreviewApiKey', 'get'),299 getMany: wrap(wrapParams, 'PreviewApiKey', 'getMany')300 },301 apiKey: {302 get: wrap(wrapParams, 'ApiKey', 'get'),303 getMany: wrap(wrapParams, 'ApiKey', 'getMany'),304 create: wrap(wrapParams, 'ApiKey', 'create'),305 createWithId: wrap(wrapParams, 'ApiKey', 'createWithId'),306 update: wrap(wrapParams, 'ApiKey', 'update'),307 "delete": wrap(wrapParams, 'ApiKey', 'delete')308 },309 appDefinition: {310 get: wrap(wrapParams, 'AppDefinition', 'get'),311 getMany: wrap(wrapParams, 'AppDefinition', 'getMany'),312 create: wrap(wrapParams, 'AppDefinition', 'create'),313 update: wrap(wrapParams, 'AppDefinition', 'update'),314 "delete": wrap(wrapParams, 'AppDefinition', 'delete')315 },316 appInstallation: {317 get: wrap(wrapParams, 'AppInstallation', 'get'),318 getMany: wrap(wrapParams, 'AppInstallation', 'getMany'),319 upsert: wrap(wrapParams, 'AppInstallation', 'upsert'),320 "delete": wrap(wrapParams, 'AppInstallation', 'delete')321 },322 extension: {323 get: wrap(wrapParams, 'Extension', 'get'),324 getMany: wrap(wrapParams, 'Extension', 'getMany'),325 create: wrap(wrapParams, 'Extension', 'create'),326 createWithId: wrap(wrapParams, 'Extension', 'createWithId'),327 update: wrap(wrapParams, 'Extension', 'update'),328 "delete": wrap(wrapParams, 'Extension', 'delete')329 },330 webhook: {331 get: wrap(wrapParams, 'Webhook', 'get'),332 getMany: wrap(wrapParams, 'Webhook', 'getMany'),333 getHealthStatus: wrap(wrapParams, 'Webhook', 'getHealthStatus'),334 getCallDetails: wrap(wrapParams, 'Webhook', 'getCallDetails'),335 getManyCallDetails: wrap(wrapParams, 'Webhook', 'getManyCallDetails'),336 create: wrap(wrapParams, 'Webhook', 'create'),337 update: wrap(wrapParams, 'Webhook', 'update'),338 "delete": wrap(wrapParams, 'Webhook', 'delete')339 },340 snapshot: {341 getManyForEntry: wrap(wrapParams, 'Snapshot', 'getManyForEntry'),342 getForEntry: wrap(wrapParams, 'Snapshot', 'getForEntry'),343 getManyForContentType: wrap(wrapParams, 'Snapshot', 'getManyForContentType'),344 getForContentType: wrap(wrapParams, 'Snapshot', 'getForContentType')345 },346 tag: {347 get: wrap(wrapParams, 'Tag', 'get'),348 getMany: wrap(wrapParams, 'Tag', 'getMany'),349 createWithId: wrap(wrapParams, 'Tag', 'createWithId'),350 update: wrap(wrapParams, 'Tag', 'update'),351 "delete": wrap(wrapParams, 'Tag', 'delete')352 },353 organization: {354 getAll: wrap(wrapParams, 'Organization', 'getMany'),355 get: wrap(wrapParams, 'Organization', 'get')356 },357 organizationInvitation: {358 get: wrap(wrapParams, 'OrganizationInvitation', 'get'),359 create: wrap(wrapParams, 'OrganizationInvitation', 'create')360 },361 organizationMembership: {362 get: wrap(wrapParams, 'OrganizationMembership', 'get'),363 getMany: wrap(wrapParams, 'OrganizationMembership', 'getMany'),364 update: wrap(wrapParams, 'OrganizationMembership', 'update'),365 "delete": wrap(wrapParams, 'OrganizationMembership', 'delete')366 },367 spaceMember: {368 get: wrap(wrapParams, 'SpaceMember', 'get'),369 getMany: wrap(wrapParams, 'SpaceMember', 'getMany')370 },371 spaceMembership: {372 get: wrap(wrapParams, 'SpaceMembership', 'get'),373 getMany: wrap(wrapParams, 'SpaceMembership', 'getMany'),374 getForOrganization: wrap(wrapParams, 'SpaceMembership', 'getForOrganization'),375 getManyForOrganization: wrap(wrapParams, 'SpaceMembership', 'getManyForOrganization'),376 create: wrap(wrapParams, 'SpaceMembership', 'create'),377 createWithId: wrap(wrapParams, 'SpaceMembership', 'createWithId'),378 update: wrap(wrapParams, 'SpaceMembership', 'update'),379 "delete": wrap(wrapParams, 'SpaceMembership', 'delete')380 },381 team: {382 get: wrap(wrapParams, 'Team', 'get'),383 getMany: wrap(wrapParams, 'Team', 'getMany'),384 getManyForSpace: wrap(wrapParams, 'Team', 'getManyForSpace'),385 create: wrap(wrapParams, 'Team', 'create'),386 update: wrap(wrapParams, 'Team', 'update'),387 "delete": wrap(wrapParams, 'Team', 'delete')388 },389 teamMembership: {390 get: wrap(wrapParams, 'TeamMembership', 'get'),391 getManyForOrganization: wrap(wrapParams, 'TeamMembership', 'getManyForOrganization'),392 getManyForTeam: wrap(wrapParams, 'TeamMembership', 'getManyForTeam'),393 create: wrap(wrapParams, 'TeamMembership', 'create'),394 update: wrap(wrapParams, 'TeamMembership', 'update'),395 "delete": wrap(wrapParams, 'TeamMembership', 'delete')396 },397 teamSpaceMembership: {398 get: wrap(wrapParams, 'TeamSpaceMembership', 'get'),399 getMany: wrap(wrapParams, 'TeamSpaceMembership', 'getMany'),400 getForOrganization: wrap(wrapParams, 'TeamSpaceMembership', 'getForOrganization'),401 getManyForOrganization: wrap(wrapParams, 'TeamSpaceMembership', 'getManyForOrganization'),402 create: wrap(wrapParams, 'TeamSpaceMembership', 'create'),403 update: wrap(wrapParams, 'TeamSpaceMembership', 'update'),404 "delete": wrap(wrapParams, 'TeamSpaceMembership', 'delete')405 }406 }, addAlphaFeatures(makeRequest, defaults, alphaFeatures));407};408var addAlphaFeatures = function addAlphaFeatures(makeRequest, defaults, alphaFeatures) {409 var wrapParams = {410 makeRequest: makeRequest,411 defaults: defaults412 };413 var alphaInterface = {};414 if (alphaFeatures !== null && alphaFeatures !== void 0 && alphaFeatures.includes(ALPHA_FEATURE_WORKFLOWS)) {415 alphaInterface.workflowDefinition = {416 get: wrap(wrapParams, 'WorkflowDefinition', 'get'),417 getMany: wrap(wrapParams, 'WorkflowDefinition', 'getMany'),418 create: wrap(wrapParams, 'WorkflowDefinition', 'create'),419 update: wrap(wrapParams, 'WorkflowDefinition', 'update'),420 "delete": wrap(wrapParams, 'WorkflowDefinition', 'delete')421 };422 alphaInterface.workflow = {423 getMany: wrap(wrapParams, 'Workflow', 'getMany'),424 create: wrap(wrapParams, 'Workflow', 'create'),425 update: wrap(wrapParams, 'Workflow', 'update'),426 "delete": wrap(wrapParams, 'Workflow', 'delete'),427 complete: wrap(wrapParams, 'Workflow', 'complete')428 };429 alphaInterface.workflowsChangelog = {430 getMany: wrap(wrapParams, 'WorkflowsChangelog', 'getMany')431 };432 }433 return alphaInterface;...
index.js
Source:index.js
...71 * @type {import('.').default}72 */73const createDefaultImplementation = ({ strapi, db, eventHub, entityValidator }) => ({74 uploadFiles,75 async wrapParams(options = {}) {76 return options;77 },78 async emitEvent(uid, event, entity) {79 const model = strapi.getModel(uid);80 const sanitizedEntity = await sanitize.sanitizers.defaultSanitizeOutput(model, entity);81 eventHub.emit(event, {82 model: model.modelName,83 entry: sanitizedEntity,84 });85 },86 async findMany(uid, opts) {87 const { kind } = strapi.getModel(uid);88 const wrappedParams = await this.wrapParams(opts, { uid, action: 'findMany' });89 const query = transformParamsToQuery(uid, wrappedParams);90 if (kind === 'singleType') {91 return db.query(uid).findOne(query);92 }93 return db.query(uid).findMany(query);94 },95 async findPage(uid, opts) {96 const wrappedParams = await this.wrapParams(opts, { uid, action: 'findPage' });97 const query = transformParamsToQuery(uid, wrappedParams);98 return db.query(uid).findPage(query);99 },100 // TODO: streamline the logic based on the populate option101 async findWithRelationCounts(uid, opts) {102 const wrappedParams = await this.wrapParams(opts, { uid, action: 'findWithRelationCounts' });103 const query = transformParamsToQuery(uid, wrappedParams);104 const { results, pagination } = await db.query(uid).findPage(query);105 return {106 results,107 pagination,108 };109 },110 async findOne(uid, entityId, opts) {111 const wrappedParams = await this.wrapParams(opts, { uid, action: 'findOne' });112 const query = transformParamsToQuery(uid, pickSelectionParams(wrappedParams));113 return db.query(uid).findOne({ ...query, where: { id: entityId } });114 },115 async count(uid, opts) {116 const wrappedParams = await this.wrapParams(opts, { uid, action: 'count' });117 const query = transformParamsToQuery(uid, wrappedParams);118 return db.query(uid).count(query);119 },120 async create(uid, opts) {121 const wrappedParams = await this.wrapParams(opts, { uid, action: 'create' });122 const { data, files } = wrappedParams;123 const model = strapi.getModel(uid);124 const isDraft = contentTypesUtils.isDraft(data, model);125 const validData = await entityValidator.validateEntityCreation(model, data, { isDraft });126 // select / populate127 const query = transformParamsToQuery(uid, pickSelectionParams(wrappedParams));128 // TODO: wrap into transaction129 const componentData = await createComponents(uid, validData);130 let entity = await db.query(uid).create({131 ...query,132 data: creationPipeline(Object.assign(omitComponentData(model, validData), componentData), {133 contentType: model,134 }),135 });136 // TODO: upload the files then set the links in the entity like with compo to avoid making too many queries137 // FIXME: upload in components138 if (files && Object.keys(files).length > 0) {139 await this.uploadFiles(uid, entity, files);140 entity = await this.findOne(uid, entity.id, wrappedParams);141 }142 await this.emitEvent(uid, ENTRY_CREATE, entity);143 return entity;144 },145 async update(uid, entityId, opts) {146 const wrappedParams = await this.wrapParams(opts, { uid, action: 'update' });147 const { data, files } = wrappedParams;148 const model = strapi.getModel(uid);149 const entityToUpdate = await db.query(uid).findOne({ where: { id: entityId } });150 if (!entityToUpdate) {151 return null;152 }153 const isDraft = contentTypesUtils.isDraft(entityToUpdate, model);154 const validData = await entityValidator.validateEntityUpdate(155 model,156 data,157 {158 isDraft,159 },160 entityToUpdate161 );162 const query = transformParamsToQuery(uid, pickSelectionParams(wrappedParams));163 // TODO: wrap in transaction164 const componentData = await updateComponents(uid, entityToUpdate, validData);165 let entity = await db.query(uid).update({166 ...query,167 where: { id: entityId },168 data: updatePipeline(Object.assign(omitComponentData(model, validData), componentData), {169 contentType: model,170 }),171 });172 // TODO: upload the files then set the links in the entity like with compo to avoid making too many queries173 // FIXME: upload in components174 if (files && Object.keys(files).length > 0) {175 await this.uploadFiles(uid, entity, files);176 entity = await this.findOne(uid, entity.id, wrappedParams);177 }178 await this.emitEvent(uid, ENTRY_UPDATE, entity);179 return entity;180 },181 async delete(uid, entityId, opts) {182 const wrappedParams = await this.wrapParams(opts, { uid, action: 'delete' });183 // select / populate184 const query = transformParamsToQuery(uid, pickSelectionParams(wrappedParams));185 const entityToDelete = await db.query(uid).findOne({186 ...query,187 where: { id: entityId },188 });189 if (!entityToDelete) {190 return null;191 }192 await deleteComponents(uid, entityToDelete);193 await db.query(uid).delete({ where: { id: entityToDelete.id } });194 await this.emitEvent(uid, ENTRY_DELETE, entityToDelete);195 return entityToDelete;196 },197 // FIXME: used only for the CM to be removed198 async deleteMany(uid, opts) {199 const wrappedParams = await this.wrapParams(opts, { uid, action: 'delete' });200 // select / populate201 const query = transformParamsToQuery(uid, wrappedParams);202 return db.query(uid).deleteMany(query);203 },204 load(uid, entity, field, params = {}) {205 const { attributes } = strapi.getModel(uid);206 const attribute = attributes[field];207 const loadParams = {};208 switch (attribute.type) {209 case 'relation': {210 Object.assign(loadParams, transformParamsToQuery(attribute.target, params));211 break;212 }213 case 'component': {...
entity-service-decorator.test.js
Source:entity-service-decorator.test.js
...62 wrapParams: jest.fn(() => Promise.resolve('li')),63 };64 const service = decorator(defaultService);65 const input = { populate: ['test'] };66 await service.wrapParams(input, { uid: 'test-model' });67 expect(defaultService.wrapParams).toHaveBeenCalledWith(input, { uid: 'test-model' });68 });69 test('Does not wrap options if model is not localized', async () => {70 const defaultService = {71 wrapParams: jest.fn(opts => Promise.resolve(opts)),72 };73 const service = decorator(defaultService);74 const input = { populate: ['test'] };75 const output = await service.wrapParams(input, { uid: 'non-localized-model' });76 expect(output).toStrictEqual(input);77 });78 test('does not change non params options', async () => {79 const defaultService = {80 wrapParams: jest.fn(opts => Promise.resolve(opts)),81 };82 const service = decorator(defaultService);83 const input = { populate: ['test'] };84 const output = await service.wrapParams(input, { uid: 'test-model' });85 expect(output.populate).toStrictEqual(input.populate);86 });87 test('Adds locale param', async () => {88 const defaultService = {89 wrapParams: jest.fn(opts => Promise.resolve(opts)),90 };91 const service = decorator(defaultService);92 const input = { populate: ['test'] };93 const output = await service.wrapParams(input, { uid: 'test-model' });94 expect(output).toMatchObject({ filters: { $and: [{ locale: 'en' }] } });95 });96 const testData = [97 ['findOne', { filters: { id: 1 } }],98 ['update', { filters: { id: 1 } }],99 ['delete', { filters: { id: 1 } }],100 ['delete', { filters: { id: { $in: [1] } } }],101 ['findOne', { filters: [{ id: 1 }] }],102 ['update', { filters: [{ id: 1 }] }],103 ['delete', { filters: [{ id: 1 }] }],104 ['delete', { filters: [{ id: { $in: [1] } }] }],105 ];106 test.each(testData)(107 "Doesn't add locale param when the params contain id or id_in - %s",108 async (action, params) => {109 const defaultService = {110 wrapParams: jest.fn(opts => Promise.resolve(opts)),111 };112 const service = decorator(defaultService);113 const input = Object.assign({ populate: ['test'], ...params });114 const output = await service.wrapParams(input, { uid: 'test-model', action });115 expect(output).toEqual({ populate: ['test'], ...params });116 }117 );118 test('Replaces locale param', async () => {119 const defaultService = {120 wrapParams: jest.fn(opts => Promise.resolve(opts)),121 };122 const service = decorator(defaultService);123 const input = {124 locale: 'fr',125 populate: ['test'],126 };127 const output = await service.wrapParams(input, { uid: 'test-model' });128 expect(output).toMatchObject({ filters: { $and: [{ locale: 'fr' }] } });129 });130 });131 describe('create', () => {132 test('Calls original create', async () => {133 const entry = {134 id: 1,135 };136 const defaultService = {137 create: jest.fn(() => Promise.resolve(entry)),138 };139 const service = decorator(defaultService);140 const input = { data: { title: 'title ' } };141 await service.create('test-model', input);...
debt.js
Source:debt.js
...3var config = require('../helpers/config.js').service;4var Cache = require('../helpers/redisCache.js');5var wrapParams = require('../helpers/wrapParams.js');6module.exports.roundNoRefund = function(data, callback) {7 data.sign = wrapParams(data);8 return http({9 url: `${config.service_domain}/web/debt/roundNoRefund`,10 data: data || {},11 timeout: 30000,12 method: 'POST'13 })14};15module.exports.removeSuspectedRepeat = function(data, callback) {16 data.sign = wrapParams(data);17 return http({18 url: `${config.service_domain}/web/debt/removeSuspectedRepeat`,19 data: data || {},20 method: 'POST'21 })22};23module.exports.saveDetail = function(data, callback) {24 data.sign = wrapParams(data);25 return http({26 url: `${config.service_domain}/web/debt/saveDetail`,27 data: data || {},28 method: 'POST'29 })30};31module.exports.uploadHistory = function(data, callback) {32 data.sign = wrapParams(data);33 return http({34 url: `${config.service_domain}/web/debt/uploadHistory`,35 data: data || {},36 method: 'POST'37 })38};39module.exports.statusModifyList = function(data, callback) {40 data.sign = wrapParams(data);41 return http({42 url: `${config.service_domain}/web/debt/status-modify-list`,43 data: data || {},44 method: 'POST'45 })46};47module.exports.getDetail = function(data) {48 data.sign = wrapParams(data);49 return http({50 url: `${config.service_domain}/web/debt/detail`,51 data: data || {},52 method: 'POST'53 })54};55module.exports.getEnterpriseList = function(data) {56 data.sign = wrapParams(data);57 return http({58 url: `${config.service_domain}/web/enterprise/list`,59 data: data || {},60 method: 'POST'61 })62};63module.exports.getList = function(data) {64 data.sign = wrapParams(data);65 return http({66 url: `${config.service_domain}/web/debt/list`,67 data: data || {},68 method: 'POST'69 })70};71module.exports.getCloseReasons = function(data) {72 data = data || {};73 data.sign = wrapParams(data);74 return http({75 url: `${config.service_domain}/web/debt/close-reasons`,76 data: data || {},77 timeout: 30000,78 method: 'POST'79 })80};81module.exports.getCollRecodByPage = function(data) {82 data = data || {};83 data.sign = wrapParams(data);84 return http({85 url: `${config.service_domain}/web/debt/getCollRecodByPage`,86 data: data || {},87 method: 'POST'88 })89};90module.exports.close = function(data, callback) {91 data.sign = wrapParams(data);92 return http({93 url: `${config.service_domain}/web/debt/close`,94 data: data || {},95 timeout: 30000,96 method: 'POST'97 })98};99module.exports.sendToRrc = function(data, callback) {100 data.sign = wrapParams(data);101 return http({102 url: `${config.service_domain}/web/debt/send-to-rrc`,103 data: data || {},104 method: 'POST'105 })106};107module.exports.collectRecordExport = function(data, callback) {108 data.sign = wrapParams(data);109 return http({110 url: `${config.service_domain}/web/debt/collectRecordExport`,111 data: data || {},112 method: 'POST'113 })114};115module.exports.exception = function(data, callback) {116 data.sign = wrapParams(data);117 return http({118 url: `${config.service_domain}/web/debt/exception`,119 data: data || {},120 method: 'POST'121 })122};123module.exports.unexception = function(data, callback) {124 data.sign = wrapParams(data);125 return http({126 url: `${config.service_domain}/web/debt/unexception`,127 data: data || {},128 method: 'POST'129 })130};131module.exports.refundConfirm = function(data, callback) {132 data.sign = wrapParams(data);133 return http({134 url: `${config.service_domain}/web/debt/refund-confirm`,135 data: data || {},136 method: 'POST'137 })138};139module.exports.refund = function(data, callback) {140 data.sign = wrapParams(data);141 return http({142 url: `${config.service_domain}/web/debt/refund`,143 data: data || {},144 method: 'POST'145 })146};147module.exports.extendEntrustDate = function(data, callback) {148 data.sign = wrapParams(data);149 return http({150 url: `${config.service_domain}/web/debt/extend-entrust-date`,151 data: data || {},152 method: 'POST'153 })154};155module.exports.refundPause = function(data, callback) {156 data.sign = wrapParams(data);157 158 return http({159 url: `${config.service_domain}/web/debt/refund-pause`,160 data: data || {},161 method: 'POST'162 })163};164module.exports.upload = function(data, callback) {165 data.sign = wrapParams(data, 'uploadFile');166 var params = {};167 /**168 * request formData æ件æµå段å¿
é¡»æ¾äºè°±å¾å段å169 * å¦åå¯è½ä¸¢å¤±æ®éå段å¼170 **/171 Object.keys(data).forEach(function (item) {172 if (item !== "uploadFile") {173 params[item] = data[item];174 }175 });176 params['uploadFile'] = data['uploadFile'];177 http({178 url: `${config.service_domain}/web/debt/upload`,179 data: params || {},180 method: 'POST',181 timeout: 3 * 1000 * 60 // 3åé182 }).then(function(ret) {183 callback(ret);184 });185};186var request = require('request');187var path = require('path');188var fs = require('fs');189function httpRequest(params) {190 var options = {191 json: true,192 timeout: 3000193 };194 options.method = params.method || 'GET';195 options.url = params.url;196 options.formData = params.data;197 options.headers = {198 'content-type': 'application/x-www-form-urlencoded'199 }200 return request(options);201}202module.exports.download = function(data) {203 data.sign = wrapParams(data);204 return httpRequest({205 url: `${config.service_domain}/web/enterprise/download`,206 data: data || {},207 method: 'POST'208 })...
call.js
Source:call.js
1'use strict';2/*!3 * Snakeskin4 * https://github.com/SnakeskinTpl/Snakeskin5 *6 * Released under the MIT license7 * https://github.com/SnakeskinTpl/Snakeskin/blob/master/LICENSE8 */9import Snakeskin from '../core';10import { ws } from '../helpers/string';11Snakeskin.addDirective(12 'call',13 {14 block: true,15 deferInit: true,16 filters: {global: [['undef']]},17 group: ['call', 'microTemplate', 'output'],18 notEmpty: true,19 shorthands: {'+=': 'call ', '/+': 'end call'},20 trim: true21 },22 function (command) {23 if (command.slice(-1) === '/') {24 this.startInlineDir(null, {short: true});25 this.append(this.wrap(this.out(command.slice(0, -1))));26 return;27 }28 this.startDir(null, {29 chunks: 1,30 command31 });32 this.append(ws`33 ${this.declVars(34 ws`35 __CALL_CACHE__ = __RESULT__,36 __CALL_TMP__ = [],37 __CALL_POS__ = 038 `,39 {sys: true}40 )}41 __RESULT__ = ${this.getResultDecl()};42 `);43 },44 function () {45 this.text = true;46 const47 p = this.structure.params;48 if (p.strongSpace) {49 this.strongSpace.pop();50 }51 if (p.short) {52 return;53 }54 const55 tmp = this.getVar('__CALL_TMP__'),56 pos = this.getVar('__CALL_POS__');57 this.append(ws`58 if (__LENGTH__(__RESULT__)) {59 ${pos}++;60 ${tmp}.push(Unsafe(${this.getReturnResultDecl()}));61 }62 `);63 let64 i = p.chunks,65 j = 0;66 let67 wrapParams = '';68 while (i--) {69 if (wrapParams) {70 wrapParams += ',';71 }72 wrapParams += `${tmp}[${j++}]`;73 }74 let str;75 const command = p.command.replace(/([^\s]\s*)(?=\)$)/, (str, $0) => {76 if (str[0] !== '(') {77 wrapParams = `,${wrapParams}`;78 }79 return $0 + wrapParams;80 });81 const82 name = this.getFnName(command);83 if (name === '&') {84 const85 block = this.hasBlock(this.getGroup('block'), true);86 if (block) {87 str = block.params.fn + this.out(command.replace(name, ''), {unsafe: true});88 } else {89 return this.error(`invalid "${this.name}" declaration`);90 }91 } else {92 if (j === 1) {93 str = ws`94 ${pos} ? ${this.out(command)} : ${this.out(p.command)}95 `;96 } else {97 str = this.out(command);98 }99 }100 this.append(ws`101 __RESULT__ = ${this.getVar('__CALL_CACHE__')};102 ${this.wrap(str)}103 `);104 }...
company.js
Source:company.js
2var http = require('../helpers/http.js');3var config = require('../helpers/config.js').service;4var wrapParams = require('../helpers/wrapParams.js');5module.exports.overdueRewardInfo = function(data, callback) {6 data.sign = wrapParams(data);7 return http({8 url: `${config.service_domain}/web/enterprise/overdueRewardInfo`,9 data: data,10 method: 'POST'11 })12};13module.exports.getCompanyList = function(data, callback) {14 data.sign = wrapParams(data);15 return http({16 url: `${config.service_domain}/web/enterprise/debt-list`,17 data: data,18 method: 'POST'19 })20};21module.exports.companyDetail = function(data, callback) {22 data.sign = wrapParams(data);23 return http({24 url: `${config.service_domain}/web/enterprise/detail`,25 data: data,26 method: 'POST'27 })28};29module.exports.companyModify = function(data, callback) {30 data.sign = wrapParams(data);31 return http({32 url: `${config.service_domain}/web/enterprise/modify`,33 data: data,34 method: 'POST'35 })36};37module.exports.companyAdd = function(data, callback) {38 data.sign = wrapParams(data);39 return http({40 url: `${config.service_domain}/web/enterprise/add`,41 data: data,42 method: 'POST'43 })...
use-async.js
Source:use-async.js
1import { ref, reactive, watch,unref } from "@vue/composition-api";2export default function useAsync(promiseFnc, params) {3 const wrapPromiseFn = ref(promiseFnc);4 const wrapParams = ref(params);5 const state = reactive({6 isLoading: false,7 error: null,8 result: null,9 retry_attempts: 0,10 retry: () => {11 state.retry_attempts++;12 const origPromiseFn = unref(wrapPromiseFn);13 wrapPromiseFn.value = async (params) => origPromiseFn(params);14 },15 });16 const watched = [wrapPromiseFn, wrapParams];17 watch(18 watched,19 async ([promiseFnc, wrapParams]) => {20 state.isLoading = true;21 state.error = null;22 try {23 console.log(wrapParams)24 const data = await promiseFnc(wrapParams);25 state.result = data;26 } catch (error) {27 console.log(error)28 state.error = error;29 } finally {30 state.isLoading = false;31 }32 },33 { immediate: true }34 );35 return state;...
platform.js
Source:platform.js
1var http = require('../helpers/http.js');2var config = require('../helpers/config.js').service;3var wrapParams = require('../helpers/wrapParams.js');4module.exports.bonusTaxQuery = function(data, callback) {5 data.sign = wrapParams(data);6 return http({7 url: `${config.service_domain}/web/bonusTax/query`,8 data: data,9 method: 'POST'10 })11};12module.exports.bonusTaxModify = function(data, callback) {13 data.sign = wrapParams(data);14 return http({15 url: `${config.service_domain}/web/bonusTax/modify`,16 data: data,17 method: 'POST'18 })...
Using AI Code Generation
1var BaseDriver = require('appium-base-driver');2var baseDriver = new BaseDriver();3var desiredCaps = {4};5var caps = baseDriver.wrapParams(desiredCaps);6console.log(caps);7{ platformName: 'iOS',8 app: 'path/to/app' }9var BaseDriver = require('appium-base-driver');10var baseDriver = new BaseDriver();11var desiredCaps = {12};13var caps = baseDriver.wrapParams(desiredCaps);14var driver = new BaseDriver(caps);15driver.createSession();16var BaseDriver = require('appium-base-driver');17var baseDriver = new BaseDriver();18var desiredCaps = {19};20var caps = baseDriver.wrapParams(desiredCaps);21var driver = new BaseDriver(caps);22driver.createSession();23driver.startSession();24var BaseDriver = require('
Using AI Code Generation
1var BaseDriver = require('appium-base-driver').BaseDriver;2var wrapParams = BaseDriver.wrapParams;3var driver = new BaseDriver();4var wrapped = wrapParams(driver, function (a, b, c, d) {5 return a + b + c + d;6});7var BaseDriver = require('appium-base-driver').BaseDriver;8var wrapCommand = BaseDriver.wrapCommand;9var driver = new BaseDriver();10var wrapped = wrapCommand(driver, 'findElOrEls', function (origFindElOrEls) {11 return async function (strategy, selector, mult, context) {12 console.log('About to find element!');13 var el = await origFindElOrEls.call(this, strategy, selector, mult, context);14 console.log('Found element!');15 return el;16 };17});18await wrapped.findElOrEls('id', 'foo', false, null);19var BaseDriver = require('appium-base-driver').BaseDriver;20var unwrapElement = BaseDriver.unwrapElement;21var driver = new BaseDriver();22var el = await driver.findElement('id', 'foo');23var unwrapped = unwrapElement(el);24var BaseDriver = require('appium-base-driver').BaseDriver;25var unwrapElement = BaseDriver.unwrapElement;26var driver = new BaseDriver();27var el = await driver.findElement('id', 'foo');28var unwrapped = unwrapElement(el);
Using AI Code Generation
1const wd = require('wd');2const { AppiumBaseDriver, errors } = require('appium-base-driver');3const { wrapParams } = AppiumBaseDriver;4let driver = null;5async function main() {6 driver = wd.promiseChainRemote('localhost', 4723);7 driver.on('status', console.log);8 driver.on('command', console.log);9 driver.on('http', console.log);10 try {11 await driver.init(wrapParams({
Using AI Code Generation
1const BaseDriver = require('appium-base-driver');2const wrapParams = BaseDriver.prototype.wrapParams;3const params = wrapParams({4});5console.log(params);6const AndroidDriver = require('appium-android-driver');7const wrapParams = AndroidDriver.prototype.wrapParams;8const params = wrapParams({9});10console.log(params);11const IOSDriver = require('appium-ios-driver');12const wrapParams = IOSDriver.prototype.wrapParams;13const params = wrapParams({14});15console.log(params);16const WindowsDriver = require('appium-windows-driver');17const wrapParams = WindowsDriver.prototype.wrapParams;18const params = wrapParams({19});20console.log(params);21const MacDriver = require('appium-mac-driver');22const wrapParams = MacDriver.prototype.wrapParams;23const params = wrapParams({24});25console.log(params);26const SelendroidDriver = require('appium-selendroid-driver');27const wrapParams = SelendroidDriver.prototype.wrapParams;28const params = wrapParams({29});30console.log(params);
Using AI Code Generation
1const AppiumBaseDriver = require('appium-base-driver');2const test = async function () {3 const testParams = {4 };5 const result = await AppiumBaseDriver.wrapParams(testParams);6 console.log(result);7};8test();9{ platformVersion: '1.0',10 app: 'test.apk' }11const AppiumBaseDriver = require('appium-base-driver');12const test = async function () {13 const testParams = {14 };15 const result = await AppiumBaseDriver.wrapParams(testParams);16 console.log(result);17};18test();19{ platformVersion: '1.0',20 app: 'test.apk' }21const AppiumBaseDriver = require('appium-base-driver');22const test = async function () {23 const testParams = {24 };
Using AI Code Generation
1var wrapParams = function (params) {2 params = params || {};3 var newParams = {};4 return newParams;5};6var wrapParams = function (params) {7 params = params || {};8 var newParams = {};9 return newParams;10};11var wrapParams = function (params) {12 params = params || {};13 var newParams = {};14 return newParams;15};16var wrapParams = function (params) {17 params = params || {};18 var newParams = {};19 return newParams;20};21var wrapParams = function (params) {22 params = params || {};23 var newParams = {};24 return newParams;25};
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!