Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
Change-type: patch
  • Loading branch information
Page- committed Mar 4, 2024
1 parent 4379709 commit 4e982da
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 37 deletions.
7 changes: 2 additions & 5 deletions .lintstagedrc
@@ -1,8 +1,5 @@
{
"*.coffee": [
"balena-lint"
],
"*.ts": [
"balena-lint --typescript --fix"
],
"balena-lint -t tsconfig.dev.json --fix"
]
}
24 changes: 12 additions & 12 deletions package.json
Expand Up @@ -15,7 +15,7 @@
"npm": ">=6.0.0"
},
"scripts": {
"lint": "balena-lint --typescript src test",
"lint": "balena-lint -t tsconfig.dev.json src test",
"pretest": "npm run build",
"test": "mocha",
"posttest": "npm run lint",
Expand All @@ -26,25 +26,25 @@
"build": "npm run build-es2015 && npm run build-es2018 && npm run build-types",
"prepublish": "require-npm4-to-publish",
"prepack": "npm run build",
"prettify": "balena-lint --typescript --fix src test"
"prettify": "balena-lint -t tsconfig.dev.json --fix src test"
},
"license": "MIT",
"dependencies": {
"@balena/es-version": "^1.0.1"
"@balena/es-version": "^1.0.3"
},
"devDependencies": {
"@balena/lint": "^5.4.2",
"@types/chai": "^4.3.4",
"@types/lodash": "^4.14.191",
"@types/mocha": "^10.0.1",
"chai": "^4.3.6",
"@balena/lint": "^7.3.0",
"@types/chai": "^4.3.12",
"@types/lodash": "^4.14.202",
"@types/mocha": "^10.0.6",
"chai": "^4.4.1",
"husky": "^4.3.8",
"lint-staged": "^12.3.7",
"lint-staged": "^15.2.2",
"lodash": "^4.17.21",
"mocha": "^9.2.2",
"mocha": "^10.3.0",
"require-npm4-to-publish": "^1.0.0",
"ts-node": "^10.9.1",
"typescript": "^4.9.3"
"ts-node": "^10.9.2",
"typescript": "^5.3.3"
},
"husky": {
"hooks": {
Expand Down
50 changes: 32 additions & 18 deletions src/index.ts
Expand Up @@ -76,8 +76,7 @@ const isBoolean = (v: any): v is boolean => v === true || v === false;
const isDate = (v: any): v is Date =>
Object.prototype.toString.call(v) === '[object Date]';

const isObject = (v: any): v is AnyObject =>
typeof v != null && typeof v === 'object';
const isObject = (v: any): v is AnyObject => v != null && typeof v === 'object';

const isValidOption = (
key: string,
Expand Down Expand Up @@ -127,7 +126,10 @@ class Poll<T extends PromiseResultTypes> {

private requestFn: null | (() => Promise<T>);

constructor(requestFn: () => Promise<T>, private intervalTime = 10000) {
constructor(
requestFn: () => Promise<T>,
private intervalTime = 10000,
) {
this.requestFn = requestFn;
this.start();
}
Expand Down Expand Up @@ -196,7 +198,7 @@ class Poll<T extends PromiseResultTypes> {

public start(): void {
this.stopped = false;
this.runRequest();
void this.runRequest();
}

public stop(): void {
Expand Down Expand Up @@ -470,7 +472,7 @@ const handleFilterOperator = (
operator,
parentKey,
);
case '$duration':
case '$duration': {
const durationValue = filter as DurationValue;
if (!isObject(durationValue)) {
throw new Error(`Expected type for ${operator}, got: ${typeof filter}`);
Expand Down Expand Up @@ -499,6 +501,7 @@ const handleFilterOperator = (
durationString = `-${durationString}`;
}
return addParentKey(`duration'${durationString}'`, parentKey);
}
// break
case '$raw': {
filter = filter as FilterType<typeof operator>;
Expand Down Expand Up @@ -554,7 +557,8 @@ const handleFilterOperator = (
parentKey != null &&
isObject(filter) &&
// Handles the `$filter: $op: [ {a: {$count: {'...'}}}, value]`` case.
(Object.keys(filter).length === 0 || filter.hasOwnProperty('$filter'))
(Object.keys(filter).length === 0 ||
Object.prototype.hasOwnProperty.call(filter, '$filter'))
) {
keys = parentKey.slice(0, parentKey.length - 1);
keys.push(
Expand Down Expand Up @@ -750,7 +754,10 @@ const buildOrderBy = (orderby: OrderBy): string => {
dir = dirOrOptions;
} else {
const keys = Object.keys(dirOrOptions);
if (!dirOrOptions.hasOwnProperty('$count') || keys.length > 1) {
if (
!Object.prototype.hasOwnProperty.call(dirOrOptions, '$count') ||
keys.length > 1
) {
throw new Error(
`When using '${
ODataOptionCodeExampleMap['$orderby']
Expand Down Expand Up @@ -800,14 +807,15 @@ const buildOption = (
compiledValue = buildOrderBy(value as OrderBy);
break;
case '$top':
case '$skip':
case '$skip': {
const num = value;
if (!NumberIsFinite(num)) {
throw new Error(`'${option}' option has to be a number`);
}
compiledValue = '' + num;
break;
case '$select':
}
case '$select': {
const select = value;
if (isString(select)) {
compiledValue = join(select);
Expand All @@ -822,6 +830,7 @@ const buildOption = (
);
}
break;
}
default:
// Escape parameter aliases as primitives
if (option[0] === '@') {
Expand Down Expand Up @@ -851,7 +860,7 @@ const handleOptions = (
options: ODataOptions,
parentKey: string,
): string => {
if (options.hasOwnProperty('$count')) {
if (Object.prototype.hasOwnProperty.call(options, '$count')) {
const keys = Object.keys(options);
if (keys.length > 1) {
throw new Error(
Expand All @@ -866,7 +875,8 @@ const handleOptions = (
// Check whether there is anything else other than $filter in the $count
// and error b/c it's invalid.
if (
Object.keys(options).length > (options.hasOwnProperty('$filter') ? 1 : 0)
Object.keys(options).length >
(Object.prototype.hasOwnProperty.call(options, '$filter') ? 1 : 0)
) {
// TODO: Remove the optionOperation check in the next major,
// so that it throws for all operators.
Expand Down Expand Up @@ -1091,6 +1101,7 @@ export abstract class PinejsClientCore<PinejsClient> {
retryDefaultParameters.canRetry ??
this.canRetryDefaultHandler;

// eslint-disable-next-line no-constant-condition -- we handle retry logic/delaying within the loop
while (true) {
try {
return await fnCall();
Expand Down Expand Up @@ -1153,8 +1164,8 @@ export abstract class PinejsClientCore<PinejsClient> {
cloneBackendParams = { ...cloneBackendParams, ...backendParams };
}
return new (this.constructor as new (
params: Params,
backendParams: AnyObject,
$params: Params,
$backendParams: AnyObject,
) => PinejsClient)(cloneParams, cloneBackendParams);
}

Expand Down Expand Up @@ -1482,7 +1493,10 @@ export abstract class PinejsClientCore<PinejsClient> {
let url = escapeResource(params.resource);
let { options } = params;

if (options?.hasOwnProperty('$count')) {
if (
options != null &&
Object.prototype.hasOwnProperty.call(options, '$count')
) {
const keys = Object.keys(options);
if (keys.length > 1) {
throw new Error(
Expand All @@ -1495,7 +1509,7 @@ export abstract class PinejsClientCore<PinejsClient> {
options = options.$count as ODataOptionsWithoutCount;
}

if (params.hasOwnProperty('id')) {
if (Object.prototype.hasOwnProperty.call(params, 'id')) {
const { id } = params;
if (id == null) {
throw new Error('If the id property is set it must be non-null');
Expand Down Expand Up @@ -1614,7 +1628,7 @@ export abstract class PinejsClientCore<PinejsClient> {
url: string;
body?: AnyObject;
} & AnyObject,
): Promise<{}>;
): Promise<NonNullable<unknown>>;
}

export type PromiseResultTypes = number | AnyObject | AnyObject[] | undefined;
Expand Down Expand Up @@ -1737,7 +1751,7 @@ export interface FilterObj extends Dictionary<Filter | Lambda | undefined> {
$cast?: FilterFunctionValue;
}

export interface FilterArray extends Array<Filter> {}
export type FilterArray = Filter[];
export type FilterBaseType = string | number | null | boolean | Date;
export type RawFilter =
| string
Expand All @@ -1752,7 +1766,7 @@ export interface Lambda {
}
export type Filter = FilterObj | FilterArray | FilterBaseType;

export interface ResourceExpand extends Dictionary<ODataOptions> {}
export type ResourceExpand = Dictionary<ODataOptions>;

export type Expand = string | ResourceExpand | Array<string | ResourceExpand>;

Expand Down
4 changes: 2 additions & 2 deletions test/filter.ts
Expand Up @@ -861,8 +861,8 @@ const testLambda = function (operator: string) {
$expr?:
| { b: { c: string } }
| { b: { c: string } }
| { $eq: {} }
| { $eq: {} };
| { $eq: object }
| { $eq: object };
}) => ({
[operator]: partialFilter,
});
Expand Down
7 changes: 7 additions & 0 deletions tsconfig.dev.json
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"include": [
"src/*",
"test/*"
]
}

0 comments on commit 4e982da

Please sign in to comment.