Skip to content

Commit 8c33430

Browse files
committed
fix(deploy): applyCouchbaseClusterChanges accepts AnyCluster
1 parent 0fb79d2 commit 8c33430

File tree

4 files changed

+40
-24
lines changed

4 files changed

+40
-24
lines changed

packages/cbjs/src/clusterTypes/clusterTypes.spec-d.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ import {
2424

2525
import { Bucket } from '../bucket.js';
2626
import { Collection } from '../collection.js';
27+
import { connect } from '../couchbase.js';
2728
import { Scope } from '../scope.js';
2829
import {
30+
AnyCluster,
2931
ClusterBucket,
3032
ClusterCollection,
3133
ClusterScope,
@@ -93,6 +95,17 @@ describe('IsDefaultClusterTypes', () => {
9395
});
9496
});
9597

98+
describe('AnyCluster', () => {
99+
it('should accept any cluster object with cluster types', async () => {
100+
function doSomething(cluster: AnyCluster): void {
101+
// something
102+
}
103+
104+
const cluster = await connect<UserClusterTypes>('...');
105+
doSomething(cluster);
106+
});
107+
});
108+
96109
describe('ClusterBucket', () => {
97110
it('should be extended by a Bucket that is within the described keyspace', () => {
98111
type UserBucket = Bucket<UserClusterTypes, 'BucketOne'>;

packages/cbjs/src/clusterTypes/clusterTypes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import {
3838
} from '@cbjsdev/shared';
3939

4040
import { Bucket } from '../bucket.js';
41+
import { Cluster } from '../cluster.js';
4142
import type { Collection } from '../collection.js';
4243
import type { Scope } from '../scope.js';
4344

@@ -122,6 +123,7 @@ export type CollectionOptions<Instance> =
122123
never
123124
;
124125

126+
export type AnyCluster = Cluster<any>;
125127
export type AnyBucket = Bucket<any, any>;
126128
export type AnyScope = Scope<any, any, any>;
127129
export type AnyCollection = Collection<any, any, any, any>;

packages/cbjs/src/clusterTypes/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export type {
2121
AnyCollection,
2222
AnyScope,
2323
AnyBucket,
24+
AnyCluster,
2425
ClusterCollection,
2526
ClusterScope,
2627
ClusterBucket,

packages/deploy/src/clusterChanges/applyCouchbaseClusterChanges.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { retry } from 'ts-retry-promise';
22

3-
import { Cluster, keyspacePath } from '@cbjsdev/cbjs';
3+
import { AnyCluster, Cluster, keyspacePath } from '@cbjsdev/cbjs';
44
import {
55
CouchbaseHttpApiConfig,
66
createQueryIndex,
@@ -14,7 +14,7 @@ import {
1414
waitForUser,
1515
whoami,
1616
} from '@cbjsdev/http-client';
17-
import { hasOwn, waitFor } from '@cbjsdev/shared';
17+
import { waitFor } from '@cbjsdev/shared';
1818

1919
import {
2020
CouchbaseClusterChange,
@@ -56,7 +56,7 @@ function getTimePrefix() {
5656
}
5757

5858
export async function applyCouchbaseClusterChanges(
59-
cluster: Cluster,
59+
cluster: AnyCluster,
6060
apiConfig: CouchbaseHttpApiConfig,
6161
changes: CouchbaseClusterChange[],
6262
options?: ChangeOptions
@@ -67,7 +67,7 @@ export async function applyCouchbaseClusterChanges(
6767
const operations: Record<
6868
CouchbaseClusterChange['type'],
6969
(
70-
cluster: Cluster,
70+
cluster: AnyCluster,
7171
apiConfig: CouchbaseHttpApiConfig,
7272
change: never,
7373
opts: { timeout?: number }
@@ -109,7 +109,7 @@ export async function applyCouchbaseClusterChanges(
109109
}
110110

111111
async function applyCreateBucket(
112-
cluster: Cluster,
112+
cluster: AnyCluster,
113113
apiConfig: CouchbaseHttpApiConfig,
114114
change: CouchbaseClusterChangeCreateBucket,
115115
opts: ChangeOptions
@@ -130,7 +130,7 @@ async function applyCreateBucket(
130130
}
131131

132132
async function applyDropBucket(
133-
cluster: Cluster,
133+
cluster: AnyCluster,
134134
apiConfig: CouchbaseHttpApiConfig,
135135
change: CouchbaseClusterChangeDropBucket,
136136
opts: ChangeOptions
@@ -152,7 +152,7 @@ async function applyDropBucket(
152152
}
153153

154154
async function applyUpdateBucket(
155-
cluster: Cluster,
155+
cluster: AnyCluster,
156156
apiConfig: CouchbaseHttpApiConfig,
157157
change: CouchbaseClusterChangeUpdateBucket,
158158
opts: ChangeOptions
@@ -178,7 +178,7 @@ async function applyUpdateBucket(
178178
}
179179

180180
async function applyRecreateBucket(
181-
cluster: Cluster,
181+
cluster: AnyCluster,
182182
apiConfig: CouchbaseHttpApiConfig,
183183
change: CouchbaseClusterChangeRecreateBucket,
184184
opts: ChangeOptions
@@ -207,7 +207,7 @@ async function applyRecreateBucket(
207207
}
208208

209209
async function applyCreateScope(
210-
cluster: Cluster,
210+
cluster: AnyCluster,
211211
apiConfig: CouchbaseHttpApiConfig,
212212
change: CouchbaseClusterChangeCreateScope,
213213
opts: ChangeOptions
@@ -230,7 +230,7 @@ async function applyCreateScope(
230230
}
231231

232232
async function applyDropScope(
233-
cluster: Cluster,
233+
cluster: AnyCluster,
234234
apiConfig: CouchbaseHttpApiConfig,
235235
change: CouchbaseClusterChangeDropScope,
236236
opts: ChangeOptions
@@ -256,7 +256,7 @@ async function applyDropScope(
256256
}
257257

258258
async function applyCreateCollection(
259-
cluster: Cluster,
259+
cluster: AnyCluster,
260260
apiConfig: CouchbaseHttpApiConfig,
261261
change: CouchbaseClusterChangeCreateCollection,
262262
opts: ChangeOptions
@@ -288,7 +288,7 @@ async function applyCreateCollection(
288288
}
289289

290290
async function applyDropCollection(
291-
cluster: Cluster,
291+
cluster: AnyCluster,
292292
apiConfig: CouchbaseHttpApiConfig,
293293
change: CouchbaseClusterChangeDropCollection,
294294
opts: ChangeOptions
@@ -320,7 +320,7 @@ async function applyDropCollection(
320320
}
321321

322322
async function applyUpdateCollection(
323-
cluster: Cluster,
323+
cluster: AnyCluster,
324324
apiConfig: CouchbaseHttpApiConfig,
325325
change: CouchbaseClusterChangeUpdateCollection,
326326
opts: ChangeOptions
@@ -351,7 +351,7 @@ async function applyUpdateCollection(
351351
}
352352

353353
async function applyCreateIndex(
354-
cluster: Cluster,
354+
cluster: AnyCluster,
355355
apiConfig: CouchbaseHttpApiConfig,
356356
change: CouchbaseClusterChangeCreateIndex,
357357
opts: ChangeOptions
@@ -402,7 +402,7 @@ async function applyCreateIndex(
402402
}
403403

404404
async function applyDropIndex(
405-
cluster: Cluster,
405+
cluster: AnyCluster,
406406
apiConfig: CouchbaseHttpApiConfig,
407407
change: CouchbaseClusterChangeDropIndex,
408408
opts: ChangeOptions
@@ -450,7 +450,7 @@ async function applyDropIndex(
450450
}
451451

452452
async function applyUpdateIndex(
453-
cluster: Cluster,
453+
cluster: AnyCluster,
454454
apiConfig: CouchbaseHttpApiConfig,
455455
change: CouchbaseClusterChangeUpdateIndex,
456456
opts: ChangeOptions
@@ -488,7 +488,7 @@ async function applyUpdateIndex(
488488
}
489489

490490
async function applyRecreateIndex(
491-
cluster: Cluster,
491+
cluster: AnyCluster,
492492
apiConfig: CouchbaseHttpApiConfig,
493493
change: CouchbaseClusterChangeRecreateIndex,
494494
opts: ChangeOptions
@@ -508,7 +508,7 @@ async function applyRecreateIndex(
508508
}
509509

510510
async function applyCreateUser(
511-
cluster: Cluster,
511+
cluster: AnyCluster,
512512
apiConfig: CouchbaseHttpApiConfig,
513513
change: CouchbaseClusterChangeCreateUser,
514514
opts: ChangeOptions
@@ -524,7 +524,7 @@ async function applyCreateUser(
524524
}
525525

526526
async function applyUpdateUser(
527-
cluster: Cluster,
527+
cluster: AnyCluster,
528528
apiConfig: CouchbaseHttpApiConfig,
529529
change: CouchbaseClusterChangeUpdateUser,
530530
opts: ChangeOptions
@@ -562,7 +562,7 @@ async function applyUpdateUser(
562562
}
563563

564564
async function applyUpdateUserPassword(
565-
cluster: Cluster,
565+
cluster: AnyCluster,
566566
apiConfig: CouchbaseHttpApiConfig,
567567
change: CouchbaseClusterChangeUpdateUserPassword,
568568
opts: ChangeOptions
@@ -594,7 +594,7 @@ async function applyUpdateUserPassword(
594594
}
595595

596596
async function applyRecreateUser(
597-
cluster: Cluster,
597+
cluster: AnyCluster,
598598
apiConfig: CouchbaseHttpApiConfig,
599599
change: CouchbaseClusterChangeRecreateUser,
600600
opts: ChangeOptions
@@ -613,7 +613,7 @@ async function applyRecreateUser(
613613
}
614614

615615
async function applyDropUser(
616-
cluster: Cluster,
616+
cluster: AnyCluster,
617617
apiConfig: CouchbaseHttpApiConfig,
618618
change: CouchbaseClusterChangeDropUser,
619619
opts: ChangeOptions
@@ -632,7 +632,7 @@ async function applyDropUser(
632632
}
633633

634634
async function applyUpsertSearchIndex(
635-
cluster: Cluster,
635+
cluster: AnyCluster,
636636
apiConfig: CouchbaseHttpApiConfig,
637637
change:
638638
| CouchbaseClusterChangeCreateSearchIndex
@@ -686,7 +686,7 @@ async function applyUpsertSearchIndex(
686686
}
687687

688688
async function applyDropSearchIndex(
689-
cluster: Cluster,
689+
cluster: AnyCluster,
690690
apiConfig: CouchbaseHttpApiConfig,
691691
change: CouchbaseClusterChangeDropSearchIndex,
692692
opts: ChangeOptions

0 commit comments

Comments
 (0)