Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update typescript to 5.2.2 #270

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
module.exports = {
parser: "@typescript-eslint/parser",
plugins: ["prettier", "typescript"],
plugins: ["prettier", "@typescript-eslint"],
extends: ["eslint:recommended"],
rules: {
"no-unused-vars": "off",
"typescript/no-unused-vars": ["error"],
"prefer-arrow-callback": ["error"],
},
};
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: ['12', '14', '16']
node-version: ["16", "18"]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'
cache: "yarn"
- name: Display version of Node.js, npm, Yarn
run: |
node -v
Expand All @@ -38,15 +38,15 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: ['12', '14', '16']
node-version: ["16", "18"]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'
cache: "yarn"
- name: Display version of Node.js, npm, Yarn
run: |
node -v
Expand All @@ -70,15 +70,15 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: ['12', '14', '16']
node-version: ["16", "18"]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'
cache: "yarn"
- run: ls modules/*/package.json | xargs -n1 md5sum > deps.txt
- name: Display version of Node.js, npm, Yarn
run: |
Expand Down
8 changes: 4 additions & 4 deletions modules/format/src/common/bound-document-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export type BoundDocumentPathOfDepth8<
> = `${K1}${DocumentPathSegment<K2>}${DocumentPathSegment<K3>}${DocumentPathSegment<K4>}${DocumentPathSegment<K5>}${DocumentPathSegment<K6>}${DocumentPathSegment<K7>}${DocumentPathSegment<K8>}`;

export type BoundDocumentPath<
T,
T extends Object,
K1,
K2,
K3,
Expand Down Expand Up @@ -163,7 +163,7 @@ export type BoundDocumentPath<
: BoundDocumentPathOfDepth1<T, K1>
: string;

export interface BoundDocumentPathCreator<T> {
export interface BoundDocumentPathCreator<T extends Object> {
<K1 extends Extract<keyof T, Attribute>>(k1: K1): BoundDocumentPathOfDepth1<
T,
K1
Expand Down Expand Up @@ -322,14 +322,14 @@ export interface BoundDocumentPathCreator<T> {
): BoundDocumentPathOfDepth8<T, K1, K2, K3, K4, K5, K6, K7, K8>;
}

export function $path<T>(): BoundDocumentPathCreator<T> {
export function $path<T extends Object>(): BoundDocumentPathCreator<T> {
// @ts-ignore surpress for typing.
return createDocumentPath;
}

// prettier-ignore
export type NestedValue<
T,
T extends Object,
K1,
K2,
K3,
Expand Down
4 changes: 2 additions & 2 deletions modules/format/src/updating/bind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ const updateOperationCreatorAndDocumentPathCreatorAndRetargetFunctionAndMergeFun
}
);

export function $bind<T>(): {
[OP in UpdateOperator]: UpdateOperationCreator<OP, T>
export function $bind<T extends Object>(): {
[OP in UpdateOperator]: UpdateOperationCreator<OP, T>;
} & {
$docPath: BoundDocumentPathCreator<T>;
$merge: BoundMergeOperations<T>;
Expand Down
7 changes: 5 additions & 2 deletions modules/format/src/updating/bound-create-update-operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const updateOpearationCreator = {

Object.freeze(updateOpearationCreator);

export function $op<T>(): {
export function $op<T extends Object>(): {
[OP in UpdateOperator]: UpdateOperationCreator<OP, T>;
} {
// @ts-ignore surpress for typing.
Expand Down Expand Up @@ -121,7 +121,10 @@ type ValueOf<OP extends UpdateOperator, V> = BoundUpdateOperandItemValue<

type Attribute = number | string;

export interface UpdateOperationCreator<OP extends UpdateOperator, T> {
export interface UpdateOperationCreator<
OP extends UpdateOperator,
T extends Object
> {
<K1 extends Extract<keyof T, Attribute>>(
docPath: BoundDocumentPathOfDepth1<T, K1>,
value: ValueOf<OP, T[K1]>
Expand Down
4 changes: 2 additions & 2 deletions modules/format/src/updating/bound-retarget-operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import {

import { retargetOperation } from "./retarget-operation";

export function $retarget<T>(): BoundRetarget<T> {
export function $retarget<T extends Object>(): BoundRetarget<T> {
// @ts-ignore surpress for typing.
return retargetOperation;
}

export interface BoundRetarget<T> {
export interface BoundRetarget<T extends Object> {
<
U extends NestedValue<T, K1, K2, K3, K4, K5, K6, K7, K8>,
K1,
Expand Down
29 changes: 25 additions & 4 deletions modules/format/src/updating/merge-update-operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,13 @@ function mergePullOperand<OP extends "$pull">(
if (k in ret) {
const query1 = ret[k];
const query2 = v;
if ("$eq" in query1 && "$eq" in query2) {

if (
typeof query1 === "object" &&
typeof query2 === "object" &&
"$eq" in query1 &&
"$eq" in query2
) {
// merges $eq query operators
const value1 = query1["$eq"];
const value2 = query2["$eq"];
Expand All @@ -151,15 +157,25 @@ function mergePullOperand<OP extends "$pull">(
} else {
ret[k] = { $in: [value1, value2] };
}
} else if ("$in" in query1 && "$in" in query2) {
} else if (
typeof query1 === "object" &&
typeof query2 === "object" &&
"$in" in query1 &&
"$in" in query2
) {
// merges $in query operators
const values1 = query1["$in"] as any[];
const values2 = query2["$in"] as any[];
const diffValues2 = values2.filter((v2) =>
values1.every((v1) => !deepEqual(v1, v2))
);
ret[k] = { $in: values1.concat(diffValues2) };
} else if ("$in" in query1 && "$eq" in query2) {
} else if (
typeof query1 === "object" &&
typeof query2 === "object" &&
"$in" in query1 &&
"$eq" in query2
) {
// merges $in and $eq query operators
const values = query1["$in"] as any[];
const value = query2["$eq"];
Expand All @@ -168,7 +184,12 @@ function mergePullOperand<OP extends "$pull">(
} else {
ret[k] = { $in: [...values, value] };
}
} else if ("$eq" in query1 && "$in" in query2) {
} else if (
typeof query1 === "object" &&
typeof query2 === "object" &&
"$eq" in query1 &&
"$in" in query2
) {
// merges $eq and $in query operators
const values = query2["$in"] as any[];
const value = query1["$eq"];
Expand Down
10 changes: 5 additions & 5 deletions modules/format/src/updating/update-operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ type RegularUpdateValueMap = {
$currentDate: true | { $type: "timestamp" | "date" };
$bit: { and?: number; or?: number; xor?: number };
$unset: "";
$restore: "" | ({ new (plain: Object): Object }); // strictFunctionTypes should be false.
$restore: "" | { new (plain: Object): Object }; // strictFunctionTypes should be false.
$rename: string;
$append: Object;
};
Expand All @@ -185,7 +185,7 @@ type BroaderUpdateValueMap = {
$push: any;
$currentDate: true | { $type: string };
$unset: string;
$restore: string | ({ new (plain: Object): Object });
$restore: string | { new (plain: Object): Object };
};

/**
Expand All @@ -210,7 +210,7 @@ export type UpdateValue<
* }
*/
type RegularUpdateOperationMap = {
[K in keyof RegularUpdateValueMap]: RegularUpdateOperand<K>
[K in keyof RegularUpdateValueMap]: RegularUpdateOperand<K>;
};

/**
Expand All @@ -223,7 +223,7 @@ type RegularUpdateOperationMap = {
* }
*/
type UpdateOperationMap = {
[K in keyof RegularUpdateValueMap]: UpdateOperand<K>
[K in keyof RegularUpdateValueMap]: UpdateOperand<K>;
};

/**
Expand Down Expand Up @@ -306,7 +306,7 @@ export type UpdateOperationOrSetOperand =
| UpdateOperand<"$set">;

type NonFunctionPropNames<T> = {
[K in keyof T]: T[K] extends Function ? never : K
[K in keyof T]: T[K] extends Function ? never : K;
}[keyof T];

type NonFunctionProps<T> = Pick<T, NonFunctionPropNames<T>>;
Expand Down
24 changes: 12 additions & 12 deletions modules/retriever/src/retriever.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function checkCondition(value: any, condition: QueryCondition): boolean {
* 2. `QueryCondition` (e.g. `{ $eq: "foo" }` )
* 3. `JSONValue` (number|string|boolean|Array)
*/
export function classifyByComplexFindOperation<T>(
export function classifyByComplexFindOperation<T extends Object>(
values: T[],
cond: ComplexFindOperation
): Classified<T> {
Expand Down Expand Up @@ -121,14 +121,14 @@ class Retriever {
return this.classifySimpleFindOperation(values, where);
}

private static classifySimpleFindOperation<T>(
private static classifySimpleFindOperation<T extends Object>(
values: T[],
where: SimpleFindOperation
): Classified<T> {
const documentPaths = Object.keys(where);
return values.reduce(
(classified, value) => {
const isOk = documentPaths.every(documentPath => {
const isOk = documentPaths.every((documentPath) => {
const queryCondition = where[documentPath];
const nestedValue = getNestedValue(value, documentPath);
return this.checkCondition(
Expand All @@ -148,7 +148,7 @@ class Retriever {
*/
static checkCondition(leftOperand: any, condition: QueryCondition): boolean {
const operators = Object.keys(condition);
return operators.every(operator => {
return operators.every((operator) => {
switch (operator) {
case "$eq":
case "$gt":
Expand Down Expand Up @@ -196,8 +196,8 @@ class Retriever {
);
case "$all":
if (!Array.isArray(leftOperand)) return false;
return condition.$all!.every(val =>
leftOperand.some(elem => deepEqual(elem, val))
return condition.$all!.every((val) =>
leftOperand.some((elem) => deepEqual(elem, val))
);

case "$elemMatch":
Expand Down Expand Up @@ -244,7 +244,7 @@ class Retriever {
return COMPARE_FUNC[operator](target, condValues);
}

const isIn = condValues.some(condValue =>
const isIn = condValues.some((condValue) =>
this.compare("$eq", target, condValue)
);
return operator === "$in" ? isIn : !isIn;
Expand All @@ -260,24 +260,24 @@ class Retriever {
if (Array.isArray(target) && !Array.isArray(condValue)) {
if (operator === "$ne") {
compareFunc = COMPARE_FUNC["$eq"];
return !target.some(val => compareFunc(val, condValue));
return !target.some((val) => compareFunc(val, condValue));
}
return target.some(val => compareFunc(val, condValue));
return target.some((val) => compareFunc(val, condValue));
}

return compareFunc(target, condValue);
}
}

const COMPARE_FUNC: {
[K in ComparisonQueryOperator]: (val1: any, val2: any) => boolean
[K in ComparisonQueryOperator]: (val1: any, val2: any) => boolean;
} = {
$eq: deepEqual,
$gt: (t, c) => t > c,
$gte: (t, c) => t >= c,
$in: (t, c: any[]) => c.some(v => deepEqual(t, v)),
$in: (t, c: any[]) => c.some((v) => deepEqual(t, v)),
$lt: (t, c) => t < c,
$lte: (t, c) => t <= c,
$ne: (t, c) => !deepEqual(t, c),
$nin: (t, c: any[]) => !c.some(v => deepEqual(t, v)),
$nin: (t, c: any[]) => !c.some((v) => deepEqual(t, v)),
};
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@
"devDependencies": {
"@types/mocha": "8.2.2",
"@types/node": "14.14.20",
"@typescript-eslint/parser": "^4.12.0",
"@typescript-eslint/parser": "^6.5.0",
"@typescript-eslint/eslint-plugin": "^6.5.0",
"coveralls": "3.1.0",
"eslint": "^7.17.0",
"eslint-plugin-prettier": "3.3.1",
"eslint-plugin-typescript": "0.14.0",
"eslint": "^8.48.0",
"eslint-plugin-prettier": "5.0.0",
"lcov-result-merger": "3.1.0",
"lerna": "3.20.2",
"mocha": "8.2.1",
"nyc": "15.1.0",
"prettier": "2.2.1",
"rimraf": "3.0.2",
"ts-node": "9.1.1",
"typescript": "4.3.4"
"typescript": "~5.2.2"
}
}
Loading