Skip to content

Commit

Permalink
meta: improve Utils.defaults typing and fix test (#15264)
Browse files Browse the repository at this point in the history
* meta: update dependency chai to v4.3.7

* meta: improve Utils.defaults typing and fix test

* meta: update to PropertyKey

* meta: update getComplexKeys return

* meta: update yarn after conflict solving

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
  • Loading branch information
WikiRik and renovate[bot] committed Nov 15, 2022
1 parent 6575a94 commit 79696f3
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 45 deletions.
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -62,7 +62,7 @@
"devDependencies": {
"@ephys/eslint-config-typescript": "17.0.0",
"@rushstack/eslint-patch": "1.2.0",
"@types/chai": "4.3.3",
"@types/chai": "4.3.4",
"@types/chai-as-promised": "7.1.5",
"@types/chai-datetime": "0.0.37",
"@types/ibm_db": "2.0.11",
Expand All @@ -76,7 +76,7 @@
"@types/snowflake-sdk": "1.6.9",
"@types/tedious": "4.0.9",
"@types/uuid": "8.3.4",
"chai": "4.3.6",
"chai": "4.3.7",
"chai-as-promised": "7.1.1",
"chai-datetime": "1.8.0",
"cls-hooked": "4.2.2",
Expand Down
11 changes: 4 additions & 7 deletions src/utils/format.ts
Expand Up @@ -95,20 +95,17 @@ export function mapOptionFieldNames<M extends Model>(
return out;
}

export function mapWhereFieldNames(where: Record<string | symbol, any>, Model: ModelStatic<Model>): object {
export function mapWhereFieldNames(where: Record<PropertyKey, any>, Model: ModelStatic<Model>): object {
if (!where) {
return where;
}

const newWhere: Record<string | symbol, any> = Object.create(null);
// TODO [2022-09-01]: note on 'as any[]': TypeScript < 4.4 does not support using Symbol for keys.
// Cast can be removed in sept. 2022 when we drop support for < 4.4
const newWhere: Record<PropertyKey, any> = Object.create(null);
// TODO: note on 'as any[]'; removing the cast causes the following error on attributeNameOrOperator "TS2538: Type 'symbol' cannot be used as an index type."
for (const attributeNameOrOperator of getComplexKeys(where) as any[]) {
const rawAttribute: ModelAttributeColumnOptions | undefined = Model.rawAttributes[attributeNameOrOperator];

// TODO [2022-09-01]: note on 'any': TypeScript < 4.4 does not support using Symbol for keys.
// Cast can changed back to 'symbol | string' in sept. 2022 when we drop support for < 4.4
const columnNameOrOperator: any = rawAttribute?.field ?? attributeNameOrOperator;
const columnNameOrOperator: PropertyKey = rawAttribute?.field ?? attributeNameOrOperator;

if (
isPlainObject(where[attributeNameOrOperator])
Expand Down
10 changes: 4 additions & 6 deletions src/utils/object.ts
Expand Up @@ -174,19 +174,17 @@ type Flatten<T extends object> = object extends T ? object : {
* @private
*/
export function defaults(
objectIn: { [key: string]: any }, // TODO [2022-09-01]: key should be string | symbol once we drop support for TS 4.4
...sources: Array<{ [key: string]: any }> // TODO [2022-09-01]: key should be string | symbol once we drop support for TS 4.4
objectIn: { [key: PropertyKey]: any },
...sources: Array<{ [key: PropertyKey]: any }>
): object {
for (const source of sources) {
if (!source) {
continue;
}

// TODO [2022-09-01]: note on 'as any[]': TypeScript < 4.4 does not support using Symbol for keys.
// Cast can be removed in sept. 2022 when we drop support for < 4.4
for (const key of getComplexKeys(source) as any[]) {
for (const key of getComplexKeys(source)) {
const value = objectIn[key];
const objectPrototype: { [key: string]: any } = Object.prototype; // TODO [2022-09-01]: key should be string | symbol once we drop support for TS 4.4
const objectPrototype: { [key: PropertyKey]: any } = Object.prototype;

if (
value === undefined
Expand Down
8 changes: 4 additions & 4 deletions test/unit/utils.test.js
Expand Up @@ -71,14 +71,14 @@ describe(Support.getTestDialectTeaser('Utils'), () => {

it('defaults symbol keys', () => {
expect(Utils.defaults(
{ a: 1, [Symbol.for('c')]: 3 },
{ a: 1, [Symbol.for('eq')]: 3 },
{ b: 2 },
{ [Symbol.for('c')]: 4, [Symbol.for('d')]: 4 },
{ [Symbol.for('eq')]: 4, [Symbol.for('ne')]: 4 },
)).to.eql({
a: 1,
b: 2,
[Symbol.for('c')]: 3,
[Symbol.for('d')]: 4,
[Symbol.for('eq')]: 3,
[Symbol.for('ne')]: 4,
});
});
});
Expand Down
32 changes: 6 additions & 26 deletions yarn.lock
Expand Up @@ -1110,15 +1110,15 @@
"@types/chai" "*"

"@types/chai@*":
version "4.3.4"
resolved "https://registry.yarnpkg.com/@types/chai/-/chai-4.3.4.tgz#e913e8175db8307d78b4e8fa690408ba6b65dee4"
integrity sha512-KnRanxnpfpjUTqTCXslZSEdLfXExwgNxYPdiO2WGUj8+HDjFi8R3k5RVKPeSCzLjCcshCAtVO2QBbVuAV4kTnw==

"@types/chai@4.3.3":
version "4.3.3"
resolved "https://registry.yarnpkg.com/@types/chai/-/chai-4.3.3.tgz#3c90752792660c4b562ad73b3fbd68bf3bc7ae07"
integrity sha512-hC7OMnszpxhZPduX+m+nrx+uFoLkWOMiR4oa/AZF3MuSETYTZmFfJAHqZEM8MVlvfG7BEUcgvtwoCTxBp6hm3g==

"@types/chai@4.3.4":
version "4.3.4"
resolved "https://registry.yarnpkg.com/@types/chai/-/chai-4.3.4.tgz#e913e8175db8307d78b4e8fa690408ba6b65dee4"
integrity sha512-KnRanxnpfpjUTqTCXslZSEdLfXExwgNxYPdiO2WGUj8+HDjFi8R3k5RVKPeSCzLjCcshCAtVO2QBbVuAV4kTnw==

"@types/debug@^4.1.7":
version "4.1.7"
resolved "https://registry.yarnpkg.com/@types/debug/-/debug-4.1.7.tgz#7cc0ea761509124709b8b2d1090d8f6c17aadb82"
Expand Down Expand Up @@ -2075,20 +2075,7 @@ chai-datetime@1.8.0:
dependencies:
chai ">1.9.0"

chai@4.3.6:
version "4.3.6"
resolved "https://registry.yarnpkg.com/chai/-/chai-4.3.6.tgz#ffe4ba2d9fa9d6680cc0b370adae709ec9011e9c"
integrity sha512-bbcp3YfHCUzMOvKqsztczerVgBKSsEijCySNlHHbX3VG1nskvqjz5Rfso1gGwD6w6oOV3eI60pKuMOV5MV7p3Q==
dependencies:
assertion-error "^1.1.0"
check-error "^1.0.2"
deep-eql "^3.0.1"
get-func-name "^2.0.0"
loupe "^2.3.1"
pathval "^1.1.1"
type-detect "^4.0.5"

chai@>1.9.0:
chai@4.3.7, chai@>1.9.0:
version "4.3.7"
resolved "https://registry.yarnpkg.com/chai/-/chai-4.3.7.tgz#ec63f6df01829088e8bf55fca839bcd464a8ec51"
integrity sha512-HLnAzZ2iupm25PlN0xFreAlBA5zaBSv3og0DdeGA4Ar6h6rJ3A0rolRUKJhSF2V10GZKDgWF/VmAEsNWjCRB+A==
Expand Down Expand Up @@ -2635,13 +2622,6 @@ decamelize@^4.0.0:
resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-4.0.0.tgz#aa472d7bf660eb15f3494efd531cab7f2a709837"
integrity sha512-9iE1PgSik9HeIIw2JO94IidnE3eBoQrFJ3w7sFuzSX4DpmZ3v5sZpUiV5Swcf6mQEF+Y0ru8Neo+p+nyh2J+hQ==

deep-eql@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/deep-eql/-/deep-eql-3.0.1.tgz#dfc9404400ad1c8fe023e7da1df1c147c4b444df"
integrity sha512-+QeIQyN5ZuO+3Uk5DYh6/1eKO0m0YmJFGNmFHGACpf1ClL1nmlV/p4gNgbl2pJGxgXb4faqo6UE+M5ACEMyVcw==
dependencies:
type-detect "^4.0.0"

deep-eql@^4.1.2:
version "4.1.2"
resolved "https://registry.yarnpkg.com/deep-eql/-/deep-eql-4.1.2.tgz#270ceb902f87724077e6f6449aed81463f42fc1c"
Expand Down

0 comments on commit 79696f3

Please sign in to comment.