Skip to content

Commit

Permalink
chore(linting): add and run scripts to format TS files in each package
Browse files Browse the repository at this point in the history
AFFECTS PACKAGES:
@esri/hub-annotations
@esri/hub-auth
@esri/hub-common
@esri/hub-content
@esri/hub-downloads
@esri/hub-events
@esri/hub-initiatives
@esri/hub-members
@esri/hub-search
@esri/hub-sites
@esri/hub-surveys
@esri/hub-teams
@esri/hub-types

format TS files in the following packages:
- hub-content
- hub-common
- hub-downloads
- hub-saerch
- hub-sites
- hub-surveys
  • Loading branch information
tomwayson committed Aug 12, 2020
1 parent f4e6cf2 commit c50eff3
Show file tree
Hide file tree
Showing 115 changed files with 4,029 additions and 3,102 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@
"docs:dev:sass": "node-sass --watch --recursive --output docs/build/hub.js/css --source-map true --source-map-contents docs/src/sass",
"docs:dev:js": "cpx \"docs/src/**/{api-search,nav-toggle}.js\" docs/build/hub.js -w",
"docs:srihash": "node docs/generate-srihashes.js",
"format": "lerna run format",
"format:check": "lerna run format:check",
"lint": "tslint --project tsconfig.json",
"y:publish": "lerna run y:publish",
"y:push": "lerna run y:push",
Expand Down
4 changes: 3 additions & 1 deletion packages/annotations/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
"build:node": "tsc --module commonjs --outDir ./dist/node",
"dev:esm": "tsc -w --module es2015 --outDir ./dist/esm --declaration",
"dev:umd": "rollup -w -c ../../umd-base-profile.js",
"dev:node": "tsc -w --module commonjs --outDir ./dist/node"
"dev:node": "tsc -w --module commonjs --outDir ./dist/node",
"format": "prettier --write ./{src,test}/**/*.ts",
"format:check": "prettier --check ./{src,test}/**/*.ts"
},
"publishConfig": {
"access": "public"
Expand Down
4 changes: 3 additions & 1 deletion packages/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
"build:node": "tsc --module commonjs --outDir ./dist/node",
"dev:esm": "tsc -w --module es2015 --outDir ./dist/esm --declaration",
"dev:umd": "rollup -w -c ../../umd-base-profile.js",
"dev:node": "tsc -w --module commonjs --outDir ./dist/node"
"dev:node": "tsc -w --module commonjs --outDir ./dist/node",
"format": "prettier --write ./{src,test}/**/*.ts",
"format:check": "prettier --check ./{src,test}/**/*.ts"
},
"publishConfig": {
"access": "public"
Expand Down
2 changes: 2 additions & 0 deletions packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
"dev:esm": "tsc -w --module es2015 --outDir ./dist/esm --declaration",
"dev:umd": "rollup -w -c ../../umd-base-profile.js",
"dev:node": "tsc -w --module commonjs --outDir ./dist/node",
"format": "prettier --write ./{src,test}/**/*.ts",
"format:check": "prettier --check ./{src,test}/**/*.ts",
"y:publish": "yalc publish",
"y:push": "yalc push"
},
Expand Down
22 changes: 12 additions & 10 deletions packages/common/src/items/does-item-exist-with-title.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import { searchItems } from '@esri/arcgis-rest-portal';
import { IAuthenticationManager } from '@esri/arcgis-rest-request';
import { searchItems } from "@esri/arcgis-rest-portal";
import { IAuthenticationManager } from "@esri/arcgis-rest-request";

/**
* Check if a site/page exists with a specific name
*/
export function doesItemExistWithTitle (
*/
export function doesItemExistWithTitle(
itemTitle: string,
options: Record<string,string>,
authMgr: IAuthenticationManager,
options: Record<string, string>,
authMgr: IAuthenticationManager
) {
// if options have multiple properties, put them into one string separated with 'AND'
let optionsQuery = Object.keys(options).map(key => {
return `${key}:"${options[key]}"`;
}).join(' AND ');
let opts = {
const optionsQuery = Object.keys(options)
.map(key => {
return `${key}:"${options[key]}"`;
})
.join(" AND ");
const opts = {
q: `title:"${itemTitle}" AND ${optionsQuery}`,
authentication: authMgr
};
Expand Down
30 changes: 15 additions & 15 deletions packages/common/src/items/get-unique-item-title.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { doesItemExistWithTitle } from "./does-item-exist-with-title";
import { IAuthenticationManager } from '@esri/arcgis-rest-request';
import { IAuthenticationManager } from "@esri/arcgis-rest-request";

/**
* Given a title, construct a site/page title that is unique
Expand All @@ -12,9 +12,9 @@ import { IAuthenticationManager } from '@esri/arcgis-rest-request';
* @param {number} step Number to increment. Defaults to 0
*/

export function getUniqueItemTitle (
export function getUniqueItemTitle(
title: string,
options: Record<string,string>,
options: Record<string, string>,
authMgr: IAuthenticationManager,
step = 0
): Promise<string> {
Expand All @@ -25,15 +25,15 @@ export function getUniqueItemTitle (
}

return doesItemExistWithTitle(combinedName, options, authMgr)
.then(result => {
if (result) {
step++;
return getUniqueItemTitle(title, options, authMgr, step);
} else {
return combinedName;
}
})
.catch(e => {
throw Error(`Error in getUniqueItemTitle ${e}`);
});
}
.then(result => {
if (result) {
step++;
return getUniqueItemTitle(title, options, authMgr, step);
} else {
return combinedName;
}
})
.catch(e => {
throw Error(`Error in getUniqueItemTitle ${e}`);
});
}
2 changes: 1 addition & 1 deletion packages/common/src/items/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ export * from "./share-item-to-groups";
export * from "./unprotect-model";
export * from "./unshare-item-from-groups";
export * from "./does-item-exist-with-title";
export * from "./get-unique-item-title";
export * from "./get-unique-item-title";
3 changes: 1 addition & 2 deletions packages/common/src/objects/deep-string-replace.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

import { _deepMapValues, _isString, _isRegExp } from "./_deep-map-values";
import { _deepMapValues, _isString, _isRegExp } from "./_deep-map-values";

/**
* Iterate over an object graph, and for all string properties, search for a string,
Expand Down
10 changes: 3 additions & 7 deletions packages/common/src/objects/merge-objects.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getProp } from './get-prop';
import { deepSet } from './deep-set';
import { getProp } from "./get-prop";
import { deepSet } from "./deep-set";

/**
* Apply a specified set properties from a source object to a target object
Expand All @@ -8,11 +8,7 @@ import { deepSet } from './deep-set';
* @param {Object} target The target object
* @param {Array} allowList Array of property paths (if not provided, source returned)
*/
export function mergeObjects(
source: any,
target: any,
allowList?: string[]
) {
export function mergeObjects(source: any, target: any, allowList?: string[]) {
if (Array.isArray(allowList) && allowList.length) {
// we iterate the allowList, applying changes to the target from source
allowList.forEach(prop => {
Expand Down
3 changes: 1 addition & 2 deletions packages/common/src/urls/get-hub-api-url-from-portal.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IPortal } from "@esri/arcgis-rest-portal";
import { getHubUrlFromPortal } from './get-hub-url-from-portal';
import { getHubUrlFromPortal } from "./get-hub-url-from-portal";

/**
* Return the Portal url based on the portal self
Expand All @@ -8,4 +8,3 @@ import { getHubUrlFromPortal } from './get-hub-url-from-portal';
export function getHubApiUrlFromPortal(portal: IPortal): string {
return `${getHubUrlFromPortal(portal)}/api/v3`;
}

8 changes: 4 additions & 4 deletions packages/common/src/urls/get-hub-url-from-portal.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { IPortal } from "@esri/arcgis-rest-portal";
import { _getHubUrlFromPortalHostname } from './_get-hub-url-from-portal-hostname';
import { _getHubUrlFromPortalHostname } from "./_get-hub-url-from-portal-hostname";

/**
* Return the Hub Url based on the portal self
* @param portal
* @param portal
*/
export function getHubUrlFromPortal (portal: IPortal) : string {
export function getHubUrlFromPortal(portal: IPortal): string {
if (portal.isPortal) {
throw new Error(`Hub Url is not available in ArcGIS Enterprise`);
} else {
return _getHubUrlFromPortalHostname(portal.portalHostname);
}
}
}
36 changes: 14 additions & 22 deletions packages/common/src/utils/batch.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
IBatch,
IBatchTransform
} from "../types";
import { IBatch, IBatchTransform } from "../types";

/**
* Helper to split a large number of calls into
Expand All @@ -11,22 +8,19 @@ import {
* @param {number} [batchSize=5] The number of concurrent calls to fn, defaults to 5
* @returns {Promise<IBatch[]>}
*/
export function batch (
export function batch(
values: IBatch,
fn: IBatchTransform,
batchSize: number = 5
): Promise<any> {
const toBatches = (
batches: IBatch[],
value: any
): IBatch[] => {
let batch = batches[batches.length - 1];
if (!batch || batch.length === batchSize) {
batch = [];
batches.push(batch);
const toBatches = (_batches: IBatch[], value: any): IBatch[] => {
let _batch = _batches[_batches.length - 1];
if (!_batch || _batch.length === batchSize) {
_batch = [];
_batches.push(_batch);
}
batch.push(value);
return batches;
_batch.push(value);
return _batches;
};

const toSerialBatchChain = (
Expand All @@ -35,8 +29,9 @@ export function batch (
): Promise<any> => {
const executeBatch = (prevResults: any[]) => {
const batchResults = batchOfValues.map(id => fn(id));
return Promise.all(batchResults)
.then(results => prevResults.concat(results));
return Promise.all(batchResults).then(results =>
prevResults.concat(results)
);
};
return promise.then(executeBatch);
};
Expand All @@ -46,8 +41,5 @@ export function batch (

// batches are processed serially, however
// all calls within a batch are concurrent
return batches.reduce(
toSerialBatchChain,
Promise.resolve([])
);
};
return batches.reduce(toSerialBatchChain, Promise.resolve([]));
}
6 changes: 2 additions & 4 deletions packages/common/src/utils/is-update-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import { IGroup } from "@esri/arcgis-rest-types";
* Determines if a given IGroup is an update group
* @param {IGroup} group The group to evaluate
*/
export function isUpdateGroup (
group: IGroup
): boolean {
export function isUpdateGroup(group: IGroup): boolean {
return group.capabilities.includes("updateitemcontrol");
};
}
62 changes: 31 additions & 31 deletions packages/common/src/utils/logger.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* tslint:disable no-console */

/**
* Enum for Logger Levels
Expand All @@ -8,8 +9,8 @@ export enum Level {
info,
warn,
error,
off,
}
off
}

/**
* ```js
Expand Down Expand Up @@ -37,73 +38,72 @@ export enum Level {
* ```
*/
export class Logger {

private static logLevel = Level.off;

private static isLevelPermitted(level: Level) {
return this.logLevel <= level;
}

/**
* Sets the global log level
* @param {Level} level
*/
* Sets the global log level
* @param {Level} level
*/
public static setLogLevel(level: Level) {
this.logLevel = level;
}

/**
* Logs to debug if level is enabled
* @param {string} message
* @param {...*} objects additional objects to log (optional rest parameter)
*/
* Logs to debug if level is enabled
* @param {string} message
* @param {...*} objects additional objects to log (optional rest parameter)
*/
public static log(message: string, ...objects: any[]) {
if (this.isLevelPermitted(Level.debug)) {
console.log(message, ...objects);
}
}

/**
* Logs to debug if level is enabled
* @param {string} message
* @param {...*} objects additional objects to log (optional rest parameter)
*/
* Logs to debug if level is enabled
* @param {string} message
* @param {...*} objects additional objects to log (optional rest parameter)
*/
public static debug(message: string, ...objects: any[]) {
if (this.isLevelPermitted(Level.debug)) {
console.debug(message, ...objects);
}
}

/**
* Logs to info if level is enabled
* @param {string} message
* @param {...*} objects additional objects to log (optional rest parameter)
*/
* Logs to info if level is enabled
* @param {string} message
* @param {...*} objects additional objects to log (optional rest parameter)
*/
public static info(message: string, ...objects: any[]) {
if (this.isLevelPermitted(Level.info)) {
console.info(message, ...objects);
}
}

/**
* Logs to warn if level is enabled
* @param {string} message
* @param {...*} objects additional objects to log (optional rest parameter)
*/
* Logs to warn if level is enabled
* @param {string} message
* @param {...*} objects additional objects to log (optional rest parameter)
*/
public static warn(message: string, ...objects: any[]) {
if (this.isLevelPermitted(Level.warn)) {
console.warn(message, ...objects);
}
}

/**
* Logs to error if level is enabled
* @param {string} message
* @param {...*} objects additional objects to log (optional rest parameter)
*/
* Logs to error if level is enabled
* @param {string} message
* @param {...*} objects additional objects to log (optional rest parameter)
*/
public static error(message: string, ...objects: any[]) {
if (this.isLevelPermitted(Level.error)) {
console.error(message, ...objects);
}
}
}

private static isLevelPermitted(level: Level) {
return this.logLevel <= level;
}
}
Loading

0 comments on commit c50eff3

Please sign in to comment.