Skip to content

Commit

Permalink
Use idempotent actions wherever possible, bump dependency to fix serv…
Browse files Browse the repository at this point in the history
…er crash, fix issue with popups not dismissing correctly when running locally in strict mode
  • Loading branch information
davidje13 committed Sep 4, 2024
1 parent 88a6203 commit 3b524c6
Show file tree
Hide file tree
Showing 20 changed files with 219 additions and 252 deletions.
20 changes: 11 additions & 9 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
"express": "4.x",
"express-static-gzip": "2.x",
"ioredis": "5.x",
"json-immutability-helper": "3.1.x",
"json-immutability-helper": "4.0.x",
"jwt-simple": "0.5.x",
"mongodb": "6.x",
"pg": "8.x",
"pwd-hasher": "2.x",
"shared-reducer-backend": "3.x",
"shared-reducer": "4.x",
"tslib": "2.6.x",
"websocket-express": "3.x",
"ws": "8.x"
Expand Down
5 changes: 5 additions & 0 deletions backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ async function refreshApp(
}
} catch (e) {
logError('Failed to start server', e);
// process.exit may lose stream data which has been buffered in NodeJS - wait for it all to be flushed before exiting
await Promise.all([
new Promise((resolve) => process.stdout.write('', resolve)),
new Promise((resolve) => process.stderr.write('', resolve)),
]);
process.exit(1);
}
}
Expand Down
6 changes: 2 additions & 4 deletions backend/src/routers/ApiRetrosRouter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { WebSocketExpress, Router, type JWTPayload } from 'websocket-express';
import sharedReducerBackend from 'shared-reducer-backend';
import { websocketHandler } from 'shared-reducer/backend';
import { ApiRetroArchivesRouter } from './ApiRetroArchivesRouter';
import { type UserAuthService } from '../services/UserAuthService';
import { type RetroAuthService } from '../services/RetroAuthService';
Expand Down Expand Up @@ -33,9 +33,7 @@ export class ApiRetrosRouter extends Router {
(token): JWTPayload | null => userAuthService.readAndVerifyToken(token),
);

const wsHandler = sharedReducerBackend.websocketHandler(
retroService.retroBroadcaster,
);
const wsHandler = websocketHandler(retroService.retroBroadcaster);

this.get('/', userAuthMiddleware, async (_, res) => {
const userId = WebSocketExpress.getAuthData(res).sub!;
Expand Down
2 changes: 1 addition & 1 deletion backend/src/services/RetroService.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { randomBytes } from 'node:crypto';
import { MemoryDb } from '../import-wrappers/collection-storage-wrap';
import { type Spec } from 'json-immutability-helper';
import { type ChangeInfo, type Subscription } from 'shared-reducer-backend';
import { type ChangeInfo, type Subscription } from 'shared-reducer/backend';
import { makeRetroItem, type Retro } from '../shared/api-entities';
import { RetroService } from './RetroService';

Expand Down
18 changes: 12 additions & 6 deletions backend/src/services/RetroService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ import {
encryptByRecordWithMasterKey,
migrate,
} from '../import-wrappers/collection-storage-wrap';
import srb, { type Permission } from 'shared-reducer-backend';
import {
Broadcaster,
CollectionStorageModel,
ReadOnly,
ReadWriteStruct,
type Permission,
} from 'shared-reducer/backend';
import { type Retro, type RetroSummary } from '../shared/api-entities';
import { extractRetro } from '../helpers/jsonParsers';

Expand All @@ -30,7 +36,7 @@ function dbErrorMessage(e: any): string {
}

export class RetroService {
public readonly retroBroadcaster: srb.Broadcaster<Retro, Spec<Retro>>;
public readonly retroBroadcaster: Broadcaster<Retro, Spec<Retro>>;

private readonly retroCollection: Collection<Retro>;

Expand All @@ -54,7 +60,7 @@ export class RetroService {
),
);

const model = new srb.CollectionStorageModel(
const model = new CollectionStorageModel(
this.retroCollection,
'id',
(x) => {
Expand All @@ -66,16 +72,16 @@ export class RetroService {
(e) => new Error(dbErrorMessage(e)),
);

this.retroBroadcaster = srb.Broadcaster.for<Retro>(model)
this.retroBroadcaster = Broadcaster.for<Retro>(model)
.withReducer<Spec<Retro>>(context.with(listCommands))
.build();
}

public getPermissions(allowWrite: boolean): Permission<Retro, Spec<Retro>> {
if (allowWrite) {
return new srb.ReadWriteStruct(['id', 'ownerId']);
return new ReadWriteStruct(['id', 'ownerId']);
}
return srb.ReadOnly;
return ReadOnly;
}

public async getRetroIdForSlug(slug: string): Promise<string | null> {
Expand Down
8 changes: 4 additions & 4 deletions e2e/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"@tsconfig/strictest": "2.x",
"@types/node": "20.x",
"@types/selenium-webdriver": "4.x",
"chromedriver": "127.x",
"chromedriver": "128.x",
"geckodriver": "4.4.x",
"lean-test": "2.x",
"prettier": "3.3.2",
Expand Down
20 changes: 11 additions & 9 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
"dependencies": {
"@openfonts/open-sans_all": "1.x",
"classnames": "2.x",
"json-immutability-helper": "3.1.x",
"json-immutability-helper": "4.0.x",
"lean-qr": "2.x",
"react": "18.x",
"react-dom": "18.x",
"react-hook-awaited": "1.x",
"react-hook-final-countdown": "2.x",
"react-modal": "3.x",
"rxjs": "7.x",
"shared-reducer-frontend": "3.x",
"shared-reducer": "4.x",
"wouter": "2.10.1"
},
"devDependencies": {
Expand Down
15 changes: 11 additions & 4 deletions frontend/src/actions/autoFacilitate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ interface CategoryStats {
remaining: number;
}

function getCategories(items: RetroItem[]) {
function getCategories(
items: RetroItem[],
isRemaining: (i: RetroItem) => boolean,
) {
const categories = new Set(items.map((item) => item.category));

const result = new Map<string, CategoryStats>();
Expand All @@ -14,7 +17,7 @@ function getCategories(items: RetroItem[]) {

result.set(category, {
total: all.length,
remaining: all.filter((item) => item.doneTime === 0).length,
remaining: all.filter(isRemaining).length,
});
}

Expand All @@ -39,14 +42,18 @@ function itemPriority(a: RetroItem, b: RetroItem): number {
export function autoFacilitate(
items: RetroItem[],
categoryPreferences: string[],
currentItemID: string | null,
): RetroItem | undefined {
const remainingItems = items.filter((item) => item.doneTime === 0);
const isRemaining = (item: RetroItem) =>
item.doneTime === 0 && item.id !== currentItemID;

const remainingItems = items.filter(isRemaining);

if (remainingItems.length === 0) {
return undefined;
}

const categories = getCategories(items);
const categories = getCategories(items, isRemaining);

if (remainingItems.length > 1) {
// reserve a preferred item for last
Expand Down
Loading

0 comments on commit 3b524c6

Please sign in to comment.