Skip to content

Commit 10c95f3

Browse files
committed
change OperationQueueItem to interface
1 parent 9673631 commit 10c95f3

File tree

4 files changed

+41
-46
lines changed

4 files changed

+41
-46
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
},
8585
{
8686
"path": "./build/releases/OneSignalSDK.page.es6.js",
87-
"limit": "47.886 kB",
87+
"limit": "47.8 kB",
8888
"gzip": true
8989
},
9090
{

src/core/operationRepo/OperationRepo.test.ts

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
OP_REPO_POST_CREATE_DELAY,
2020
} from './constants';
2121
import { NewRecordsState } from './NewRecordsState';
22-
import { OperationQueueItem, OperationRepo } from './OperationRepo';
22+
import { OperationRepo } from './OperationRepo';
2323

2424
vi.spyOn(Log, '_error').mockImplementation((msg) => {
2525
if (typeof msg === 'string' && msg.includes('Operation execution failed'))
@@ -224,43 +224,49 @@ describe('OperationRepo', () => {
224224
const singleOp = new Operation('1', GroupComparisonType.NONE);
225225
const groupedOps = getGroupedOp();
226226

227-
let op = new OperationQueueItem({
227+
let op = {
228228
operation: singleOp,
229229
bucket: 0,
230-
});
230+
retries: 0,
231+
};
231232

232233
// single operation should be returned as is
233234
expect(opRepo._getGroupableOperations(op)).toEqual([op]);
234235

235236
// can group operations by same create comparison key
236-
op = new OperationQueueItem({
237+
op = {
237238
operation: groupedOps[0],
238239
bucket: 0,
239-
});
240-
let op2 = new OperationQueueItem({
240+
retries: 0,
241+
};
242+
let op2 = {
241243
operation: groupedOps[1],
242244
bucket: 0,
243-
});
245+
retries: 0,
246+
};
244247
opRepo._enqueue(op2.operation);
245248
expect(opRepo._getGroupableOperations(op)).toEqual([op, op2]);
246249

247250
// can group operations by same modify comparison key
248-
op = new OperationQueueItem({
251+
op = {
249252
operation: new Operation('1', GroupComparisonType.ALTER, '', 'abc'),
250253
bucket: 0,
251-
});
252-
op2 = new OperationQueueItem({
254+
retries: 0,
255+
};
256+
op2 = {
253257
operation: new Operation('2', GroupComparisonType.ALTER, '', 'abc'),
254258
bucket: 0,
255-
});
259+
retries: 0,
260+
};
256261
opRepo._enqueue(op2.operation);
257262
expect(opRepo._getGroupableOperations(op)).toEqual([op, op2]);
258263

259264
// throws for no comparison keys
260-
op = new OperationQueueItem({
265+
op = {
261266
operation: new Operation('1', GroupComparisonType.CREATE),
262267
bucket: 0,
263-
});
268+
retries: 0,
269+
};
264270
opRepo._enqueue(op2.operation);
265271
expect(() => opRepo._getGroupableOperations(op)).toThrow(
266272
'Both comparison keys cannot be blank!',
@@ -271,10 +277,11 @@ describe('OperationRepo', () => {
271277
const records = opRepo._records;
272278
records.set(blockedId, Date.now());
273279

274-
op = new OperationQueueItem({
280+
op = {
275281
operation: new Operation('1', GroupComparisonType.CREATE, 'def'),
276282
bucket: 0,
277-
});
283+
retries: 0,
284+
};
278285
op2.operation._setProperty('onesignalId', blockedId);
279286

280287
opRepo._enqueue(op2.operation);

src/core/operationRepo/OperationRepo.ts

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,11 @@ const removeOpFromDB = (op: Operation) => {
2222

2323
// Implements logic similar to Android SDK's OperationRepo & OperationQueueItem
2424
// Reference: https://github.com/OneSignal/OneSignal-Android-SDK/blob/5.1.31/OneSignalSDK/onesignal/core/src/main/java/com/onesignal/core/internal/operations/impl/OperationRepo.kt
25-
export class OperationQueueItem {
26-
public operation: Operation;
27-
public bucket: number;
28-
public retries: number;
29-
public resolver?: (value: boolean) => void;
30-
31-
constructor(props: {
32-
operation: Operation;
33-
bucket: number;
34-
retries?: number;
35-
resolver?: (value: boolean) => void;
36-
}) {
37-
this.operation = props.operation;
38-
this.bucket = props.bucket;
39-
this.retries = props.retries ?? 0;
40-
this.resolver = props.resolver;
41-
}
42-
43-
toString(): string {
44-
return `bucket:${this.bucket}, retries:${this.retries}, operation:${this.operation}\n`;
45-
}
25+
export interface OperationQueueItem {
26+
operation: Operation;
27+
bucket: number;
28+
retries: number;
29+
resolver?: (value: boolean) => void;
4630
}
4731

4832
// OperationRepo Class
@@ -103,10 +87,11 @@ export class OperationRepo implements IOperationRepo, IStartableService {
10387
Log._debug(`OperationRepo.enqueue(operation: ${operation})`);
10488

10589
this._internalEnqueue(
106-
new OperationQueueItem({
90+
{
10791
operation,
10892
bucket: this._enqueueIntoBucket,
109-
}),
93+
retries: 0,
94+
},
11095
true,
11196
);
11297
}
@@ -116,11 +101,12 @@ export class OperationRepo implements IOperationRepo, IStartableService {
116101

117102
await new Promise<void>((resolve, reject) => {
118103
this._internalEnqueue(
119-
new OperationQueueItem({
104+
{
120105
operation,
121106
bucket: this._enqueueIntoBucket,
107+
retries: 0,
122108
resolver: (value) => (value ? resolve() : reject()),
123-
}),
109+
},
124110
true,
125111
);
126112
});
@@ -258,10 +244,11 @@ export class OperationRepo implements IOperationRepo, IStartableService {
258244
// Handle additional operations from the response
259245
if (response.operations) {
260246
for (const op of [...response.operations].reverse()) {
261-
const queueItem = new OperationQueueItem({
247+
const queueItem = {
262248
operation: op,
263249
bucket: 0,
264-
});
250+
retries: 0,
251+
};
265252
this._queue.unshift(queueItem);
266253
this._operationModelStore.addAt(0, queueItem.operation);
267254
}
@@ -364,10 +351,11 @@ export class OperationRepo implements IOperationRepo, IStartableService {
364351

365352
for (const operation of operations) {
366353
this._internalEnqueue(
367-
new OperationQueueItem({
354+
{
368355
operation,
369356
bucket: this._enqueueIntoBucket,
370-
}),
357+
retries: 0,
358+
},
371359
false,
372360
0,
373361
);

src/onesignal/OneSignal.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import {
4242
updateIdentityModel,
4343
} from '__test__/support/helpers/setup';
4444
import { MockServiceWorker } from '__test__/support/mocks/MockServiceWorker';
45-
import { OperationQueueItem } from 'src/core/operationRepo/OperationRepo';
45+
import type { OperationQueueItem } from 'src/core/operationRepo/OperationRepo';
4646
import { type ICreateUserSubscription } from 'src/core/types/api';
4747
import { ModelChangeTags } from 'src/core/types/models';
4848
import { db } from 'src/shared/database/client';

0 commit comments

Comments
 (0)