Skip to content

Commit f5f0d5d

Browse files
authored
Prepare v8.1.1 release (#91)
* Downgrade TypeScript to v4.0 * Bump version
1 parent e2cec20 commit f5f0d5d

17 files changed

+170
-54
lines changed

.eslintignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ dist/
44
lib/
55
node_modules/
66
src/Semver.ts
7-
src/Sha1.ts
7+
src/Sha1.ts
8+
src/lib.*.d.ts

package-lock.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "configcat-common",
3-
"version": "8.1.0",
3+
"version": "8.1.1",
44
"description": "ConfigCat is a configuration as a service that lets you manage your features and configurations without actually deploying new code.",
55
"main": "lib/index.js",
66
"types": "lib/index.d.ts",
@@ -48,7 +48,7 @@
4848
"nyc": "^15.1.0",
4949
"source-map-support": "^0.5.21",
5050
"ts-node": "^10.9.1",
51-
"typescript": "^4.9.4"
51+
"typescript": "^4.0.2"
5252
},
5353
"repository": {
5454
"type": "git",

src/ConfigCatClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export interface IConfigCatClient extends IProvidesHooks {
110110
/**
111111
* Returns `true` when the client is configured not to initiate HTTP requests, otherwise `false`.
112112
*/
113-
get isOffline(): boolean;
113+
readonly isOffline: boolean;
114114

115115
/**
116116
* Configures the client to allow HTTP requests.

src/ConfigFetcher.ts

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,21 @@ export class FetchError<TCause extends keyof FetchErrorCauses = keyof FetchError
4545
args: FetchErrorCauses[TCause];
4646

4747
constructor(public cause: TCause, ...args: FetchErrorCauses[TCause]) {
48-
let message: string | undefined;
49-
switch (cause) {
50-
case "abort":
51-
message = "Request was aborted.";
52-
break;
53-
case "timeout":
54-
const [timeoutMs] = args as FetchErrorCauses["timeout"];
55-
message = `Request timed out. Timeout value: ${timeoutMs}ms`;
56-
break;
57-
case "failure":
58-
const [err] = args as FetchErrorCauses["failure"];
59-
message = "Request failed due to a network or protocol error.";
60-
if (err) {
61-
message += " " + (err instanceof Error ? err.message : err + "");
62-
}
63-
break;
64-
}
65-
super(message);
48+
super(((cause: TCause, args: FetchErrorCauses[TCause]): string | undefined => {
49+
switch (cause) {
50+
case "abort":
51+
return "Request was aborted.";
52+
case "timeout":
53+
const [timeoutMs] = args as FetchErrorCauses["timeout"];
54+
return `Request timed out. Timeout value: ${timeoutMs}ms`;
55+
case "failure":
56+
const [err] = args as FetchErrorCauses["failure"];
57+
const message = "Request failed due to a network or protocol error.";
58+
return err
59+
? message + " " + (err instanceof Error ? err.message : err + "")
60+
: message;
61+
}
62+
})(cause, args));
6663

6764
// NOTE: due to a known issue in the TS compiler, instanceof is broken when subclassing Error and targeting ES5 or earlier
6865
// (see https://github.com/microsoft/TypeScript/issues/13965).

src/ConfigServiceBase.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export interface IConfigService {
3939

4040
refreshConfigAsync(): Promise<[RefreshResult, ProjectConfig]>;
4141

42-
get isOffline(): boolean;
42+
readonly isOffline: boolean;
4343

4444
setOnline(): void;
4545

src/DefaultEventEmitter.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,16 @@ export class DefaultEventEmitter implements IEventEmitter {
2121
throw new TypeError("Listener must be a function");
2222
}
2323

24-
const listeners = this.events[eventName];
24+
// TODO: remove `as string` when updating to TypeScript 4.4 or newer (https://stackoverflow.com/a/64943542/8656352)
25+
const listeners = this.events[eventName as string];
2526
const listener: Listener = { fn, once };
2627

2728
if (!listeners) {
28-
this.events[eventName] = listener;
29+
this.events[eventName as string] = listener;
2930
this.eventCount++;
3031
}
3132
else if (isSingle(listeners)) {
32-
this.events[eventName] = [listeners, listener];
33+
this.events[eventName as string] = [listeners, listener];
3334
}
3435
else {
3536
listeners.push(listener);
@@ -39,7 +40,7 @@ export class DefaultEventEmitter implements IEventEmitter {
3940
}
4041

4142
private removeListenerCore<TState>(eventName: string | symbol, state: TState, isMatch: (listener: Listener, state: TState) => boolean) {
42-
const listeners = this.events[eventName];
43+
const listeners = this.events[eventName as string];
4344

4445
if (!listeners) {
4546
return this;
@@ -53,7 +54,7 @@ export class DefaultEventEmitter implements IEventEmitter {
5354
this.removeEvent(eventName);
5455
}
5556
else if (listeners.length === 1) {
56-
this.events[eventName] = listeners[0];
57+
this.events[eventName as string] = listeners[0];
5758
}
5859
break;
5960
}
@@ -71,7 +72,7 @@ export class DefaultEventEmitter implements IEventEmitter {
7172
this.events = {};
7273
}
7374
else {
74-
delete this.events[eventName];
75+
delete this.events[eventName as string];
7576
}
7677
}
7778

@@ -100,15 +101,15 @@ export class DefaultEventEmitter implements IEventEmitter {
100101
this.events = {};
101102
this.eventCount = 0;
102103
}
103-
else if (this.events[eventName]) {
104+
else if (this.events[eventName as string]) {
104105
this.removeEvent(eventName);
105106
}
106107

107108
return this;
108109
}
109110

110111
listeners(eventName: string | symbol): Function[] {
111-
const listeners = this.events[eventName];
112+
const listeners = this.events[eventName as string];
112113

113114
if (!listeners) {
114115
return [];
@@ -126,7 +127,7 @@ export class DefaultEventEmitter implements IEventEmitter {
126127
}
127128

128129
listenerCount(eventName: string | symbol): number {
129-
const listeners = this.events[eventName];
130+
const listeners = this.events[eventName as string];
130131

131132
if (!listeners) {
132133
return 0;
@@ -161,7 +162,7 @@ export class DefaultEventEmitter implements IEventEmitter {
161162
}
162163

163164
emit(eventName: string | symbol, arg0?: any, arg1?: any, arg2?: any, arg3?: any, ...moreArgs: any[]): boolean {
164-
let listeners = this.events[eventName];
165+
let listeners = this.events[eventName as string];
165166

166167
if (!listeners) {
167168
return false;

src/Polyfills.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ export function ObjectEntriesPolyfill<T>(o: { [s: string]: T } | ArrayLike<T>):
3434
}
3535

3636
// eslint-disable-next-line @typescript-eslint/naming-convention
37-
export function ObjectFromEntriesPolyfill<T>(entries: Iterable<readonly [PropertyKey, T]>): { [k: PropertyKey]: T } {
38-
const result: { [k: PropertyKey]: T } = {};
37+
export function ObjectFromEntriesPolyfill<T>(entries: Iterable<readonly [PropertyKey, T]>): { [k: string]: T } {
38+
// TODO: change `k: string` to `k: PropertyKey` in the following line and remove `as string` below
39+
// when updating to TypeScript 4.4 or newer (https://stackoverflow.com/a/64943542/8656352)
40+
const result: { [k: string]: T } = {};
3941
if (Array.isArray(entries)) {
4042
for (const [key, value] of entries) {
4143
result[key] = value;
@@ -46,7 +48,7 @@ export function ObjectFromEntriesPolyfill<T>(entries: Iterable<readonly [Propert
4648
let element: readonly [PropertyKey, T], done: boolean | undefined;
4749
while (({ value: element, done } = iterator.next(), !done)) {
4850
const [key, value] = element;
49-
result[key] = value;
51+
result[key as string] = value;
5052
}
5153
}
5254
else {

src/lib.es2021.promise.d.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*! *****************************************************************************
2+
Copyright (c) Microsoft Corporation. All rights reserved.
3+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4+
this file except in compliance with the License. You may obtain a copy of the
5+
License at http://www.apache.org/licenses/LICENSE-2.0
6+
7+
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8+
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
9+
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
10+
MERCHANTABLITY OR NON-INFRINGEMENT.
11+
12+
See the Apache Version 2.0 License for specific language governing permissions
13+
and limitations under the License.
14+
***************************************************************************** */
15+
16+
17+
18+
/// <reference no-default-lib="true"/>
19+
20+
21+
interface AggregateError extends Error {
22+
errors: any[]
23+
}
24+
25+
interface AggregateErrorConstructor {
26+
new(errors: Iterable<any>, message?: string): AggregateError;
27+
(errors: Iterable<any>, message?: string): AggregateError;
28+
readonly prototype: AggregateError;
29+
}
30+
31+
declare var AggregateError: AggregateErrorConstructor;

src/lib.es2021.weakref.d.ts

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*! *****************************************************************************
2+
Copyright (c) Microsoft Corporation. All rights reserved.
3+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4+
this file except in compliance with the License. You may obtain a copy of the
5+
License at http://www.apache.org/licenses/LICENSE-2.0
6+
7+
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8+
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
9+
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
10+
MERCHANTABLITY OR NON-INFRINGEMENT.
11+
12+
See the Apache Version 2.0 License for specific language governing permissions
13+
and limitations under the License.
14+
***************************************************************************** */
15+
16+
17+
18+
/// <reference no-default-lib="true"/>
19+
20+
21+
interface WeakRef<T extends object> {
22+
readonly [Symbol.toStringTag]: "WeakRef";
23+
24+
/**
25+
* Returns the WeakRef instance's target object, or undefined if the target object has been
26+
* reclaimed.
27+
*/
28+
deref(): T | undefined;
29+
}
30+
31+
interface WeakRefConstructor {
32+
readonly prototype: WeakRef<any>;
33+
34+
/**
35+
* Creates a WeakRef instance for the given target object.
36+
* @param target The target object for the WeakRef instance.
37+
*/
38+
new<T extends object>(target: T): WeakRef<T>;
39+
}
40+
41+
declare var WeakRef: WeakRefConstructor;
42+
43+
interface FinalizationRegistry<T> {
44+
readonly [Symbol.toStringTag]: "FinalizationRegistry";
45+
46+
/**
47+
* Registers an object with the registry.
48+
* @param target The target object to register.
49+
* @param heldValue The value to pass to the finalizer for this object. This cannot be the
50+
* target object.
51+
* @param unregisterToken The token to pass to the unregister method to unregister the target
52+
* object. If provided (and not undefined), this must be an object. If not provided, the target
53+
* cannot be unregistered.
54+
*/
55+
register(target: object, heldValue: T, unregisterToken?: object): void;
56+
57+
/**
58+
* Unregisters an object from the registry.
59+
* @param unregisterToken The token that was used as the unregisterToken argument when calling
60+
* register to register the target object.
61+
*/
62+
unregister(unregisterToken: object): void;
63+
}
64+
65+
interface FinalizationRegistryConstructor {
66+
readonly prototype: FinalizationRegistry<any>;
67+
68+
/**
69+
* Creates a finalization registry with an associated cleanup callback
70+
* @param cleanupCallback The callback to call after an object in the registry has been reclaimed.
71+
*/
72+
new<T>(cleanupCallback: (heldValue: T) => void): FinalizationRegistry<T>;
73+
}
74+
75+
declare var FinalizationRegistry: FinalizationRegistryConstructor;

0 commit comments

Comments
 (0)