Skip to content

Commit 03455ec

Browse files
committed
feat: sync with 4.4.5
1 parent 128b620 commit 03455ec

File tree

7 files changed

+221
-94
lines changed

7 files changed

+221
-94
lines changed

packages/cbjs/src/authenticators.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export interface IPasswordAuthenticator {
2828
username: string;
2929

3030
/**
31-
* The password to autehnticate with.
31+
* The password to authenticate with.
3232
*/
3333
password: string;
3434

packages/cbjs/src/cluster.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
import { promisify } from 'node:util';
17+
import { inspect, promisify } from 'util';
1818

1919
import { BucketName, CouchbaseClusterTypes, DefaultClusterTypes } from '@cbjsdev/shared';
2020

@@ -389,6 +389,23 @@ export class Cluster<in out T extends CouchbaseClusterTypes = DefaultClusterType
389389
return this._resolveTimeout;
390390
}
391391

392+
/**
393+
* @internal
394+
*/
395+
[inspect.custom](): Record<string, any> {
396+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
397+
const { _auth, ...rest } = this;
398+
return { ...rest, _auth: '***hidden***' };
399+
}
400+
/**
401+
* @internal
402+
*/
403+
toJSON(): Record<string, any> {
404+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
405+
const { _auth, ...rest } = this;
406+
return { ...rest, _auth: '***hidden***' };
407+
}
408+
392409
/**
393410
@internal
394411
@deprecated Use the static sdk-level {@link connect} method instead.
@@ -859,6 +876,10 @@ export class Cluster<in out T extends CouchbaseClusterTypes = DefaultClusterType
859876
}
860877
}
861878

879+
async waitForBuckets() {
880+
await Promise.allSettled(this._openBuckets.values());
881+
}
882+
862883
/**
863884
* @throws AuthenticationFailureError
864885
* @private

packages/cbjs/src/utilities.ts

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ export { type Cas, CouchbaseCas };
3636
export type NodeCallback<T> = (...args: [null, T] | [Error, null]) => void;
3737
export type VoidNodeCallback = (err: Error | null) => void;
3838

39-
class UserCallbackError extends Error {}
40-
4139
/**
4240
* @internal
4341
*/
@@ -63,21 +61,10 @@ export class PromiseHelper {
6361
const prom = logicFn();
6462

6563
if (callback) {
66-
prom
67-
.then((res) => {
68-
try {
69-
callback(null, res);
70-
} catch (err) {
71-
throw new UserCallbackError('', { cause: err });
72-
}
73-
})
74-
.catch((err) => {
75-
if (err instanceof UserCallbackError) {
76-
throw err.cause;
77-
}
78-
79-
callback(err, null);
80-
});
64+
prom.then(
65+
(res) => callback(null, res),
66+
(err: Error) => callback(err, null)
67+
);
8168
}
8269

8370
return prom;
@@ -92,11 +79,11 @@ export class PromiseHelper {
9279
): Promise<void>;
9380
static wrap<T>(
9481
logicFn: (callback: NodeCallback<NonVoid<T>>) => void,
95-
callback?: NodeCallback<NonVoid<T>> | null
82+
callback?: NodeCallback<NonVoid<NoInfer<T>>> | null
9683
): Promise<T>;
9784
static wrap<T>(
9885
logicFn: (callback: (err: Error | null, res?: T | null) => void) => void,
99-
callback?: ((err: Error | null, res: T | null) => T) | null
86+
callback?: ((err: Error | null, res: NoInfer<T> | null) => T) | null
10087
): Promise<T> {
10188
const prom = new Promise<T>((resolve, reject) => {
10289
logicFn((err, res) => {
@@ -110,21 +97,10 @@ export class PromiseHelper {
11097
});
11198

11299
if (callback) {
113-
prom
114-
.then((res) => {
115-
try {
116-
callback(null, res);
117-
} catch (err) {
118-
throw new UserCallbackError('', { cause: err });
119-
}
120-
})
121-
.catch((err) => {
122-
if (err instanceof UserCallbackError) {
123-
throw err.cause;
124-
}
125-
126-
callback(err, null);
127-
});
100+
prom.then(
101+
(res) => callback(null, res),
102+
(err: Error) => callback(err, null)
103+
);
128104
}
129105

130106
return prom;

tests/cbjs/tests/cluster.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,4 +206,14 @@ describe.shuffle('cluster', { timeout: 10_000, repeats: 5 }, async () => {
206206
expect(cluster.searchTimeout).toEqual(60000);
207207
expect(cluster.viewTimeout).toEqual(60000);
208208
});
209+
210+
test('should not expose auth info in cluster', async ({
211+
expect,
212+
serverTestContext,
213+
}) => {
214+
const clusterStr = JSON.stringify(serverTestContext.cluster);
215+
const cluster = JSON.parse(clusterStr);
216+
217+
expect(cluster).toHaveProperty('_auth', '***hidden***');
218+
});
209219
});

tests/cbjs/tests/kv.lookupInAllReplicas.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ describe
6969
]);
7070

7171
expect(result).toBeInstanceOf(Array);
72+
expect(result[0]).toBeInstanceOf(LookupInReplicaResult);
7273
expect(result[0].content).toHaveLength(4);
7374

7475
expect(result[0].content[0].error).toBeNull();

tests/cbjs/tests/kv.lookupInAnyReplica.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ describe
7070
]);
7171

7272
expect(res.content).toBeInstanceOf(Array);
73+
expect(res).toBeInstanceOf(LookupInReplicaResult);
7374
expect(res.content).toHaveLength(4);
7475

7576
expect(res.content[0].error).toBeNull();

0 commit comments

Comments
 (0)