How to use the @marblejs/core.createContextToken function in @marblejs/core

To help you get started, we’ve selected a few @marblejs/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github marblejs / marble / packages / messaging / src / server / messaging.server.tokens.ts View on Github external
import { createContextToken } from '@marblejs/core';
import { Subject } from 'rxjs';
import { TransportLayer } from '../transport/transport.interface';
import { AllServerEvents } from './messaging.server.events';
import { Logger } from './messaging.server.logger';

export const TransportLayerToken = createContextToken();
export const ServerEventsToken = createContextToken>();
export const LoggerToken = createContextToken();
github marblejs / marble / packages / @integration / src / websockets / http.server.ts View on Github external
bindEagerlyTo,
  createContextToken,
  createServer,
  matchEvent,
  ServerEvent,
  httpListener,
  HttpServerEffect,
  useContext,
} from '@marblejs/core';
import { mapToServer, MarbleWebSocketServer } from '@marblejs/websockets';
import { logger$ } from '@marblejs/middleware-logger';
import { merge } from 'rxjs';
import { tap, map } from 'rxjs/operators';
import { websocketsServer } from './websockets.server';

export const WsServerToken = createContextToken('MarbleWebSocketServer');

const root$ = r.pipe(
  r.matchPath('/'),
  r.matchType('GET'),
  r.useEffect((req$, { ask }) => {
    const wsServer = useContext(WsServerToken)(ask);

    return req$.pipe(
      tap(() => wsServer.sendBroadcastResponse({ type: 'ROOT', payload: 'Hello' })),
      map(body => ({ body })),
    );
  }));

const upgrade$: HttpServerEffect = (event$, { ask }) =>
  event$.pipe(
    matchEvent(ServerEvent.upgrade),
github marblejs / marble / packages / messaging / src / server / messaging.server.tokens.ts View on Github external
import { createContextToken } from '@marblejs/core';
import { Subject } from 'rxjs';
import { TransportLayer } from '../transport/transport.interface';
import { AllServerEvents } from './messaging.server.events';
import { Logger } from './messaging.server.logger';

export const TransportLayerToken = createContextToken();
export const ServerEventsToken = createContextToken>();
export const LoggerToken = createContextToken();
github marblejs / marble / packages / @integration / src / messaging / client.ts View on Github external
matchEvent,
  ServerEvent,
  httpListener,
  HttpServerEffect,
  use,
  useContext,
} from '@marblejs/core';
import { merge, forkJoin } from 'rxjs';
import { tap, map, mergeMap, mapTo } from 'rxjs/operators';
import { requestValidator$, t } from '@marblejs/middleware-io';

const port = process.env.PORT
  ? Number(process.env.PORT)
  : undefined;

const ClientToken = createContextToken('MessagingClient');

const client = messagingClient({
  transport: Transport.AMQP,
  options: {
    host: 'amqp://localhost:5672',
    queue: 'test_queue',
    queueOptions: { durable: false },
  },
});

const rootValiadtor$ = requestValidator$({
  params: t.type({
    number: t.string,
  }),
});
github marblejs / marble / packages / messaging / src / server / messaging.server.tokens.ts View on Github external
import { createContextToken } from '@marblejs/core';
import { Subject } from 'rxjs';
import { TransportLayer } from '../transport/transport.interface';
import { AllServerEvents } from './messaging.server.events';
import { Logger } from './messaging.server.logger';

export const TransportLayerToken = createContextToken();
export const ServerEventsToken = createContextToken>();
export const LoggerToken = createContextToken();
github marblejs / marble / packages / @integration / src / tokens.ts View on Github external
import { createContextToken } from '@marblejs/core';
import { MarbleWebSocketServer } from '@marblejs/websockets';

export const WsServerToken = createContextToken();