fix(backend): migrate code to use the commons workspace

Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
Tilman Vatteroth 2022-12-04 22:43:12 +01:00
parent c489aacea0
commit 298b6bc205
13 changed files with 37 additions and 42 deletions

View file

@ -72,14 +72,11 @@ jobs:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
if: needs.changes.outputs.changed == 'true' if: needs.changes.outputs.changed == 'true'
- name: Use Node.js ${{ matrix.node-version }} - name: Setup node
if: needs.changes.outputs.changed == 'true' if: needs.changes.outputs.changed == 'true'
uses: actions/setup-node@v3 uses: ./.github/actions/setup-node
with: with:
node-version: ${{ matrix.node-version }} NODE_VERSION: ${{ env.NODE_VERSION }}
- run: yarn install --immutable
if: needs.changes.outputs.changed == 'true'
- run: yarn run build - run: yarn run build
if: needs.changes.outputs.changed == 'true' if: needs.changes.outputs.changed == 'true'
@ -93,14 +90,11 @@ jobs:
with: with:
fetch-depth: 0 fetch-depth: 0
- name: Use Node.js ${{ env.NODEJS_VERSION }} - name: Setup node
if: needs.changes.outputs.changed == 'true' if: needs.changes.outputs.changed == 'true'
uses: actions/setup-node@v3 uses: ./.github/actions/setup-node
with: with:
node-version: ${{ env.NODEJS_VERSION }} NODE_VERSION: ${{ env.NODE_VERSION }}
- run: yarn install --immutable
if: needs.changes.outputs.changed == 'true'
- run: yarn run test:cov - run: yarn run test:cov
if: needs.changes.outputs.changed == 'true' if: needs.changes.outputs.changed == 'true'

View file

@ -26,20 +26,27 @@ USER node
WORKDIR /usr/src/app WORKDIR /usr/src/app
COPY --chown=node .yarn/plugins .yarn/plugins COPY --chown=node .yarn/plugins .yarn/plugins
COPY --chown=node .yarn/patches .yarn/patches
COPY --chown=node .yarn/releases .yarn/releases COPY --chown=node .yarn/releases .yarn/releases
COPY --chown=node .yarnrc.yml .yarnrc.yml COPY --chown=node .yarnrc.yml .yarnrc.yml
COPY --chown=node package.json package.json COPY --chown=node package.json package.json
COPY --chown=node yarn.lock yarn.lock COPY --chown=node yarn.lock yarn.lock
COPY --chown=node backend/package.json backend/ COPY --chown=node backend/package.json backend/
COPY --chown=node commons/package.json commons/
COPY --chown=node frontend/package.json frontend/ COPY --chown=node frontend/package.json frontend/
# Install dependencies first to not invalidate the cache on every source change # Install dependencies first to not invalidate the cache on every source change
RUN --mount=type=cache,sharing=locked,uid=1000,gid=1000,target=/tmp/.yarn \ RUN --mount=type=cache,sharing=locked,uid=1000,gid=1000,target=/tmp/.yarn \
yarn install --immutable && yarn workspaces focus @hedgedoc/backend yarn install --immutable && yarn workspaces focus @hedgedoc/backend
COPY --chown=node commons/ commons/
COPY --chown=node backend/nest-cli.json backend/tsconfig.json backend/tsconfig.build.json backend/ COPY --chown=node backend/nest-cli.json backend/tsconfig.json backend/tsconfig.build.json backend/
COPY --chown=node backend/src backend/src COPY --chown=node backend/src backend/src
WORKDIR /usr/src/app/commons
RUN yarn build
## Stage 2a: Dev config files and tests ## Stage 2a: Dev config files and tests
FROM code-with-deps as development FROM code-with-deps as development
USER node USER node

View file

@ -25,7 +25,7 @@
}, },
"dependencies": { "dependencies": {
"@azure/storage-blob": "12.12.0", "@azure/storage-blob": "12.12.0",
"@hedgedoc/realtime": "0.3.0", "@hedgedoc/commons": "workspace:commons",
"@mrdrogdrog/optional": "1.0.0", "@mrdrogdrog/optional": "1.0.0",
"@nestjs/common": "9.2.1", "@nestjs/common": "9.2.1",
"@nestjs/config": "2.2.0", "@nestjs/config": "2.2.0",

View file

@ -6,7 +6,7 @@
import { import {
encodeDocumentDeletedMessage, encodeDocumentDeletedMessage,
encodeMetadataUpdatedMessage, encodeMetadataUpdatedMessage,
} from '@hedgedoc/realtime'; } from '@hedgedoc/commons';
import { Mock } from 'ts-mockery'; import { Mock } from 'ts-mockery';
import { Note } from '../../notes/note.entity'; import { Note } from '../../notes/note.entity';

View file

@ -6,10 +6,9 @@
import { import {
encodeDocumentDeletedMessage, encodeDocumentDeletedMessage,
encodeMetadataUpdatedMessage, encodeMetadataUpdatedMessage,
} from '@hedgedoc/realtime'; } from '@hedgedoc/commons';
import { Logger } from '@nestjs/common'; import { Logger } from '@nestjs/common';
import { EventEmitter } from 'events'; import { EventEmitter2 } from 'eventemitter2';
import TypedEventEmitter, { EventMap } from 'typed-emitter';
import { Awareness } from 'y-protocols/awareness'; import { Awareness } from 'y-protocols/awareness';
import { Note } from '../../notes/note.entity'; import { Note } from '../../notes/note.entity';
@ -17,18 +16,10 @@ import { WebsocketAwareness } from './websocket-awareness';
import { WebsocketConnection } from './websocket-connection'; import { WebsocketConnection } from './websocket-connection';
import { WebsocketDoc } from './websocket-doc'; import { WebsocketDoc } from './websocket-doc';
export type RealtimeNoteEvents = {
beforeDestroy: () => void;
destroy: () => void;
};
type TypedEventEmitterConstructor<T extends EventMap> =
new () => TypedEventEmitter<T>;
/** /**
* Represents a note currently being edited by a number of clients. * Represents a note currently being edited by a number of clients.
*/ */
export class RealtimeNote extends (EventEmitter as TypedEventEmitterConstructor<RealtimeNoteEvents>) { export class RealtimeNote extends EventEmitter2 {
protected logger: Logger; protected logger: Logger;
private readonly websocketDoc: WebsocketDoc; private readonly websocketDoc: WebsocketDoc;
private readonly websocketAwareness: WebsocketAwareness; private readonly websocketAwareness: WebsocketAwareness;

View file

@ -3,18 +3,17 @@
* *
* SPDX-License-Identifier: AGPL-3.0-only * SPDX-License-Identifier: AGPL-3.0-only
*/ */
import { EventEmitter } from 'events'; import { EventEmitter2 } from 'eventemitter2';
import { Mock } from 'ts-mockery'; import { Mock } from 'ts-mockery';
import TypedEmitter from 'typed-emitter';
import { Note } from '../../../notes/note.entity'; import { Note } from '../../../notes/note.entity';
import { RealtimeNote, RealtimeNoteEvents } from '../realtime-note'; import { RealtimeNote } from '../realtime-note';
import { WebsocketAwareness } from '../websocket-awareness'; import { WebsocketAwareness } from '../websocket-awareness';
import { WebsocketDoc } from '../websocket-doc'; import { WebsocketDoc } from '../websocket-doc';
import { mockAwareness } from './mock-awareness'; import { mockAwareness } from './mock-awareness';
import { mockWebsocketDoc } from './mock-websocket-doc'; import { mockWebsocketDoc } from './mock-websocket-doc';
class MockRealtimeNote extends (EventEmitter as new () => TypedEmitter<RealtimeNoteEvents>) { class MockRealtimeNote extends EventEmitter2 {
constructor( constructor(
private note: Note, private note: Note,
private doc: WebsocketDoc, private doc: WebsocketDoc,

View file

@ -3,13 +3,11 @@
* *
* SPDX-License-Identifier: AGPL-3.0-only * SPDX-License-Identifier: AGPL-3.0-only
*/ */
import { WebsocketTransporter } from '@hedgedoc/realtime'; import { WebsocketTransporter } from '@hedgedoc/commons';
import { MessageTransporterEvents } from '@hedgedoc/realtime/dist/mjs/y-doc-message-transporter'; import { EventEmitter2 } from 'eventemitter2';
import { EventEmitter } from 'events';
import { Mock } from 'ts-mockery'; import { Mock } from 'ts-mockery';
import TypedEmitter from 'typed-emitter';
class MockMessageTransporter extends (EventEmitter as new () => TypedEmitter<MessageTransporterEvents>) { class MockMessageTransporter extends EventEmitter2 {
setupWebsocket(): void { setupWebsocket(): void {
//intentionally left blank //intentionally left blank
} }

View file

@ -3,7 +3,7 @@
* *
* SPDX-License-Identifier: AGPL-3.0-only * SPDX-License-Identifier: AGPL-3.0-only
*/ */
import * as hedgedocRealtimeModule from '@hedgedoc/realtime'; import * as hedgedocRealtimeModule from '@hedgedoc/commons';
import { Mock } from 'ts-mockery'; import { Mock } from 'ts-mockery';
import { RealtimeNote } from './realtime-note'; import { RealtimeNote } from './realtime-note';
@ -12,6 +12,8 @@ import { ClientIdUpdate, WebsocketAwareness } from './websocket-awareness';
import { WebsocketConnection } from './websocket-connection'; import { WebsocketConnection } from './websocket-connection';
import { WebsocketDoc } from './websocket-doc'; import { WebsocketDoc } from './websocket-doc';
jest.mock('@hedgedoc/commons');
describe('websocket-awareness', () => { describe('websocket-awareness', () => {
it('distributes content updates to other synced clients', () => { it('distributes content updates to other synced clients', () => {
const mockEncodedUpdate = new Uint8Array([0, 1, 2, 3]); const mockEncodedUpdate = new Uint8Array([0, 1, 2, 3]);

View file

@ -3,7 +3,7 @@
* *
* SPDX-License-Identifier: AGPL-3.0-only * SPDX-License-Identifier: AGPL-3.0-only
*/ */
import { encodeAwarenessUpdateMessage } from '@hedgedoc/realtime'; import { encodeAwarenessUpdateMessage } from '@hedgedoc/commons';
import { Awareness } from 'y-protocols/awareness'; import { Awareness } from 'y-protocols/awareness';
import { RealtimeNote } from './realtime-note'; import { RealtimeNote } from './realtime-note';

View file

@ -3,8 +3,8 @@
* *
* SPDX-License-Identifier: AGPL-3.0-only * SPDX-License-Identifier: AGPL-3.0-only
*/ */
import * as hedgedocRealtimeModule from '@hedgedoc/realtime'; import * as hedgedocRealtimeModule from '@hedgedoc/commons';
import { WebsocketTransporter } from '@hedgedoc/realtime'; import { WebsocketTransporter } from '@hedgedoc/commons';
import { Mock } from 'ts-mockery'; import { Mock } from 'ts-mockery';
import WebSocket from 'ws'; import WebSocket from 'ws';
import * as yProtocolsAwarenessModule from 'y-protocols/awareness'; import * as yProtocolsAwarenessModule from 'y-protocols/awareness';
@ -25,6 +25,8 @@ import { WebsocketDoc } from './websocket-doc';
import SpyInstance = jest.SpyInstance; import SpyInstance = jest.SpyInstance;
jest.mock('@hedgedoc/commons');
describe('websocket connection', () => { describe('websocket connection', () => {
let mockedDoc: WebsocketDoc; let mockedDoc: WebsocketDoc;
let mockedAwareness: WebsocketAwareness; let mockedAwareness: WebsocketAwareness;

View file

@ -3,7 +3,7 @@
* *
* SPDX-License-Identifier: AGPL-3.0-only * SPDX-License-Identifier: AGPL-3.0-only
*/ */
import { WebsocketTransporter } from '@hedgedoc/realtime'; import { WebsocketTransporter } from '@hedgedoc/commons';
import { Logger } from '@nestjs/common'; import { Logger } from '@nestjs/common';
import WebSocket from 'ws'; import WebSocket from 'ws';
import { Awareness, removeAwarenessStates } from 'y-protocols/awareness'; import { Awareness, removeAwarenessStates } from 'y-protocols/awareness';

View file

@ -3,7 +3,7 @@
* *
* SPDX-License-Identifier: AGPL-3.0-only * SPDX-License-Identifier: AGPL-3.0-only
*/ */
import * as hedgedocRealtimeModule from '@hedgedoc/realtime'; import * as hedgedocRealtimeModule from '@hedgedoc/commons';
import { Mock } from 'ts-mockery'; import { Mock } from 'ts-mockery';
import { RealtimeNote } from './realtime-note'; import { RealtimeNote } from './realtime-note';
@ -11,6 +11,8 @@ import { mockConnection } from './test-utils/mock-connection';
import { WebsocketConnection } from './websocket-connection'; import { WebsocketConnection } from './websocket-connection';
import { WebsocketDoc } from './websocket-doc'; import { WebsocketDoc } from './websocket-doc';
jest.mock('@hedgedoc/commons');
describe('websocket-doc', () => { describe('websocket-doc', () => {
it('saves the initial content', () => { it('saves the initial content', () => {
const textContent = 'textContent'; const textContent = 'textContent';

View file

@ -3,7 +3,7 @@
* *
* SPDX-License-Identifier: AGPL-3.0-only * SPDX-License-Identifier: AGPL-3.0-only
*/ */
import { encodeDocumentUpdateMessage } from '@hedgedoc/realtime'; import { encodeDocumentUpdateMessage } from '@hedgedoc/commons';
import { Doc } from 'yjs'; import { Doc } from 'yjs';
import { RealtimeNote } from './realtime-note'; import { RealtimeNote } from './realtime-note';