Skip to content

Commit

Permalink
feat: Deprecate createChildContainer method (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
ch1ller0 authored Feb 24, 2024
1 parent 2d0f2c4 commit 588ce64
Show file tree
Hide file tree
Showing 25 changed files with 2,770 additions and 10,586 deletions.
6 changes: 6 additions & 0 deletions .changeset/blue-toes-obey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@fridgefm/inverter": patch
"@fridgefm/examples": patch
---

feat: Deprecate `createChildContainer` method
4 changes: 3 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extends": [
"airbnb-typescript/base",
"plugin:@typescript-eslint/strict",
"plugin:prettier/recommended"
],
"plugins": ["import", "prettier"],
Expand All @@ -26,6 +26,8 @@
}],
"import/extensions": 0,
"@typescript-eslint/no-explicit-any": 2,
"@typescript-eslint/no-namespace": 0,
"@typescript-eslint/no-invalid-void-type": 0,
"@typescript-eslint/consistent-type-imports": 2,
"no-underscore-dangle": 0,
"no-console": 2,
Expand Down
14 changes: 14 additions & 0 deletions apps/examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## Examples

In order to test the package run the following
```bash
# inside packages/inverter/ directory
npm run dev
```
and
```bash
# inside apps/examples/ directory
npm run dev ./src/calc-app
# OR
npm run dev ./src/chat-app
```
10 changes: 5 additions & 5 deletions apps/examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
"description": "Examples",
"private": true,
"scripts": {
"dev": "ts-node-dev --respawn --transpile-only src/chat-app",
"dev": "tsx watch",
"test:typecheck": "tsc -p tsconfig.json --noEmit"
},
"dependencies": {
"@fridgefm/inverter": "0.2.5",
"@fridgefm/inverter-test": "0.2.5",
"pino": "^8.7.0",
"pino-pretty": "^10.0.0",
"ts-node-dev": "^2.0.0",
"ws": "^8.11.0"
"pino": "^8.19.0",
"pino-pretty": "^10.3.1",
"tsx": "^4.7.1",
"ws": "^8.16.0"
}
}
2 changes: 1 addition & 1 deletion apps/examples/src/calc-app/calc-root.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const RootModule = createModule({
const result = handler(command, numericValues);
write(result);
} catch (e) {
// @ts-ignore
// @ts-expect-error trust me
write(e.message);
}
recurseAsk();
Expand Down
20 changes: 8 additions & 12 deletions apps/examples/src/chat-app/server.module.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import { WebSocketServer, type WebSocket } from 'ws';
import {
createModule,
createToken,
injectable,
createChildContainer,
internalTokens,
type Token,
} from '@fridgefm/inverter';
import { createModule, createToken, injectable, createContainer, internalTokens, type Token } from '@fridgefm/inverter';
import { LoggerModule, NetworkModule } from '../shared';
import { ChatModule } from './chat.module';
import { ClientModule } from './client.module';
Expand Down Expand Up @@ -64,7 +57,7 @@ export const ServerModule = createModule({
if (parsed.type === 'message') {
const formatted = chatStore.pushMessages(parsed.items, id);
newSession.pushOther({ type: 'message', items: formatted });
scopedLogger.info(formatted[0]!.chatMessage);
scopedLogger.info(formatted[0]?.chatMessage);
return;
}
});
Expand All @@ -89,9 +82,12 @@ export const ServerModule = createModule({
const server = new WebSocketServer({ port, host });

server.on('connection', (ws) => {
return createChildContainer(baseContainer, {
providers: [injectable({ provide: SCOPED_WS, useValue: ws })],
}).get(SESSION_ROOT);
return createContainer(
{
providers: [injectable({ provide: SCOPED_WS, useValue: ws })],
},
baseContainer,
).get(SESSION_ROOT);
});

server.on('listening', () => {
Expand Down
1 change: 0 additions & 1 deletion apps/examples/src/shared/__tests__/example-shared.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ describe('integration:shared', () => {
en0: [{ address: '192.168.178.1', family: 'IPv4' }],
utun2: [{ address: 'fe80::ce81:b1c:bd2c:69e', family: 'IPv6' }],
};
// @ts-ignore
jest.spyOn(os, 'networkInterfaces').mockReturnValue(networkMocks);

it('ok', async () => {
Expand Down
1 change: 1 addition & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ const config: Config = {
clearMocks: true,
};

// eslint-disable-next-line import/no-default-export
export default config;
Loading

0 comments on commit 588ce64

Please sign in to comment.