Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    zetos
    @zetos
    I guess i will try to play a little to see if i figure something out with rx, but if it does not work i will go for a Load balancer
    Hmm a load balancer would solve that too xD
    Józef Flakus
    @JozefFlakus
    The load balancer is an another abstraction layer over the HTTP server so it is out of the framework boundaries :)
    zetos
    @zetos
    Question, how do you answer early an http request with marble and keep going with the stream? I have a request that takes a long time to process, so i would like to just pass through the validator, return a 200 and keep going with the process.
    Géraud Henrion
    @fuunnx
    (I'm not a marble.js user)
    I think that's what messaging if for : you can emit a message/an event and terminate your request without having to wait for the answer. This message would be then handled by another effect handler https://docs.marblejs.com/messaging/core-concepts
    Józef Flakus
    @JozefFlakus
    Exactly, as @fuunnx mentioned, for this specific use case you should handle requests with an event-based manner, eg. via EventBus.
    Thanzex
    @Thanzex
    Hi there! Would you advise using a global set of BehaviourSubjects that stream their values to listeners on websockets?
    Józef Flakus
    @JozefFlakus
    @Thanzex can you explain more what would you like to achieve? Is it a Marble.js related question or general one?
    zetos
    @zetos

    Question, i was looking into the migration guide for the version 2 to 3 but i did not found anything about tests.

    i was doing the tests in the version 2 just like the marblejs/example : https://github.com/marblejs/example/blob/master/src/api/common/effects/notFound.effect.spec.ts

    How do you do this kinds of tests with the version 3?

    zetos
    @zetos

    i guess i found the answer, now you use:

      const server = createServer({ listener });
      const httpTestBed = createHttpServerTestBed(server);

    im just not sure if importing it with import { createHttpServerTestBed } from '@marblejs/core/dist/+internal/testing'; is the right way to do it

    Józef Flakus
    @JozefFlakus
    @zetos You can try to use a brand new and shiny @marblejs/testing module. 🔥
    https://docs.marblejs.com/testing/http-testing
    chua-mbt
    @chua-mbt
    sorry, im completely new to ts/node. come from scala and want to try the more functional side of ts/node. im kind of in this strange position where i barely know all the node-related stuff instead of the reactive and fp stuff. i've been following the instructions for 3.x:
    but when i run the service, the process terminates after binding the endpoints:
    akaii@haro-worker:~/IdeaProjects/mango-boba$ yarn start
    yarn run v1.22.4
    warning package.json: No license field
    $ ts-node ./src/app.ts
    λ - 9768 - 2020-06-28 21:45:37 - http [Context] - Registered: "HttpServerClientToken"
    λ - 9768 - 2020-06-28 21:45:37 - http [Context] - Registered: "LoggerToken"
    λ - 9768 - 2020-06-28 21:45:37 - http [Context] - Registered: "HttpRequestBusToken"
    λ - 9768 - 2020-06-28 21:45:37 - http [Context] - Registered: "HttpServerEventStreamToken"
    λ - 9768 - 2020-06-28 21:45:37 - http [Router] - Effect mapped: / GET
    λ - 9768 - 2020-06-28 21:45:37 - http [Router] - Effect mapped: /(.*) *
    Done in 3.44s.
    not sure what im doing wrong, the docs for 3.X are pretty sparse atm. i've tried 2.X as well, and i can't even get that to build properly.
    might be something very basic about node im missing
    Krzysztof Miemiec
    @krzysztof-miemiec
    @chua-mbt I think there is no main() function call in docs you mentioned. Can you try running main function? Note that createServer returns a Promise, which returns a function returning a Promise, so you have to call await twice await (await server)();.
    chua-mbt
    @chua-mbt
    const main: IO<void> = async () => await (await server)();
    Its there. Scroll down to the third file descrobed in thr doc
    Krzysztof Miemiec
    @krzysztof-miemiec
    @chua-mbt it's just a function definition - you have to execute it to start the server.
    chua-mbt
    @chua-mbt
    yeah, thats what i was missing, thanks. i havent worked with scripting languages in awhile.
    jim108dev
    @jim108dev

    Hello! Has anybody tried angular, socket.io and marble.js?
    I have tried:

    import { Socket } from 'ngx-socket-io'
    
    ...
    export class AdapterHelloComponent {
      constructor(private socket: Socket) {
        this.superviseConnection()
      }
    
      superviseConnection() {
        this.socket.on('connect', () => console.log('online'))
        this.socket.on('disconnect', () => console.log('offline'))
        this.socket.fromEvent<string>('HELLO').subscribe(console.log)
      }
      ping() {
        this.socket.emit('HELLO', 'hello from client')
        console.log('Client emitted hello')
      }

    Marble.js server like in the docs:

    export const hello$: WsEffect = (event$) =>
      event$.pipe(
        matchEvent('HELLO'),
        mapTo({ type: 'HELLO', payload: 'hello from server' })
      )

    Result:
    Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:4001/socket.io/?EIO=3&transport=polling&t=NLqMX41. (Reason: CORS request did not succeed).

    Which means no connection.
    I have tried Nest:

    @WebSocketGateway(4001)
    export class AdapterMessageGateway...
    
      @SubscribeMessage('HELLO')
      async handleGreeting(_client: Socket, value: string): Promise<void> {
        this.logger.log('Nest server:' + value)
        this.serverSocket.emit('HELLO', 'hello from server')
      }

    Works perfectly. Has anybody had the same problem? I only find react examples on github.

    Józef Flakus
    @JozefFlakus
    Marble.js doesn’t support socket.io. Only official RFC 6455 protocol.
    jim108dev
    @jim108dev
    Ok, thanks.
    jim108dev
    @jim108dev

    I have tried http, upgrade to websockets with cookies with the latest version(based on an example which uses version 2):

    Middleware:

    export const authorize$ = (
      config: AuthorizeMiddlewareConfig
    ): HttpMiddlewareEffect => (req$) =>
      req$.pipe(
        flatMap((req) =>
          of(req).pipe(
            map(parseCookies),
            flatMap(verifyToken$(config)),
            flatMap(verifyPayload$),
            tap(assignPayloadToRequest(req)),
            flatMap(() => req$)
          )
        ),
        catchError(() =>
          throwError(new HttpError('Unauthorized', HttpStatus.UNAUTHORIZED))
        )
      )

    webSocketListener:

    const connection$: WsConnectionEffect = (req$) =>
      req$.pipe(
        use(authorize$(jwtConfig)), //<-- Error
        mergeMap((req) =>
          iif(
            () => req.headers.upgrade !== 'websocket',
            throwError(
              new WebSocketConnectionError('Unauthorized', HttpStatus.UNAUTHORIZED)
            ),
            of(req)
          )
        )
      )
    
    export default webSocketListener({
      middlewares: [logger$],
      effects: [...Object.values(messages$)],
      connection$,
    })

    Error:

    Argument of type '(source$: Observable<HttpRequest<unknown, unknown, unknown>>) => Observable<HttpRequest<unknown, unknown, unknown>>' is not assignable to parameter of type 'OperatorFunction<IncomingMessage, HttpRequest<unknown, unknown, unknown>>'.
      Types of parameters 'source$' and 'source' are incompatible.
        Type 'Observable<IncomingMessage>' is not assignable to type 'Observable<HttpRequest<unknown, unknown, unknown>>'.
          Type 'IncomingMessage' is missing the following properties from type 'HttpRequest<unknown, unknown, unknown>': body, params, query, responsets(2345)

    Does somebody know what I do wrong and how to get OperatorFunction<IncomingMessage?

    jim108dev
    @jim108dev
    More precisely: How should jwt-authorization for websockets be done? https://docs.marblejs.com/other/api-reference/websockets/websocketlistener says there is connection$ for WebSocketListenerConfig, but the only fields are middlewares, error$,eventTransformer,output$, effects. createWebSocketServer has connection$ and it's deprecated.
    zetos
    @zetos
    Will the example repo get an update ?
    Joshua
    @JoshuaAmaju
    Hi, new to marble. Went through the docs but couldn't find anything on rendering templates, is it focused on REST APIs only.
    Joshua
    @JoshuaAmaju
    Good day, does context only work for strings?
    Edu Mosqueda
    @bbaaxx

    Good day, does context only work for strings?

    I have just played a little bit with Marble but I believe it is better suited for APIs, WS and MQ processors.
    As for the context, it will take any valid expression, just read the part on the docs about lazy bootstrapping.

    Tam CARRE
    @tam-carre
    hey
    looking at the doc
    import { createServer } from '@marblejs/core';
    import { IO } from 'fp-ts/lib/IO';
    import { listener } from './http.listener';
    
    const server = createServer({
      port: 1337,
      hostname: '127.0.0.1',
      listener,
    });
    
    const main: IO<void> = async () =>
      await (await server)();
    
    main();
    what's the point of the outermost await here?
    couldn't this file be written as
    import { createServer } from '@marblejs/core';
    import { listener } from './http.listener';
    import { call } from 'ramda';
    
    createServer({
      port: 1337,
      hostname: '127.0.0.1',
      listener,
    }).then(call);
    1 reply
    Tam CARRE
    @tam-carre
    i guess its just a stylistic concern of conveying that all of the application's side effects happen inside the main function but
    i still am not sure why the outer await is needed?
    const main: IO<void> = async () => (await server)();
    intuition says this should work fine
    Tam CARRE
    @tam-carre
    what does the dollar sign identifier suffix convey?
    zetos
    @zetos
    what does the dollar sign identifier suffix convey?
    The $ sign is a naming convention for observables
    1 reply
    Giovanni Lituma
    @giovannixdev
    Hello everyone, I just saw Marble.js 4.0 RC was released a few days ago I wonder if someone could point me to information or an article with more information about it.
    Joshua
    @JoshuaAmaju
    Good day, how would you combine a websocket listener with an http listener like you would in an express application?
    Dylan DE SOUSA
    @Gi-jutsu
    Hello everyone, I would like to know if there is already an available implementation to test Microservice ? I'm looking at @marblejs/testing but as far as I know there's only an HttpTestBed
    Thanks :)
    Dylan DE SOUSA
    @Gi-jutsu

    For now I came with this solution

    describe('effects - findUserByCredentialsEffect', () => {
      test('it should emit an Event with Validation error when payload is incomplete', async () => {
        // Mock input event
        const input$ = of({ type: 'FIND_USER_BY_CREDENTIALS' })
    
        // Retrieve the dependencies
        const { context } = await microservice;
        const effectContext = createEffectContext<any, any>({
          ask: lookup(context),
          client: null,
        });
    
        // Call the Effect
        findUserByCredentialsEffect$(input$, effectContext)
          .subscribe({
            next: (event) => {
              expect(event).toEqual({
                type: 'FIND_USER_BY_CREDENTIALS_UNHANDLED_ERROR',
                error: {
                  name: 'EventError',
                  message: 'Validation error',
                  event: { type: 'FIND_USER_BY_CREDENTIALS' },
                  data: [
                    {
                      path: 'payload',
                      expected: '{ email: string, password: string }',
                      got: undefined
                    }
                  ]
                }
              })
            }
          })
      })
    })

    I dont like the fact that I need to explicitly add <any, any> and client: null, to the createEffectContext.
    But with this I'm able to have a nice coverage easily.

    Nick Caballero
    @nickcaballero
    hi, i'm trying to use @marblejs/middleware-io to validate that a string matches a regexp - how do i do that?
    Kevin Abatan
    @carere
    Hello, i got a lot of problem handling errors with marbleJS, Is the project still maintained ?? Is there a way to handle error properly ?? (I tried the doc but it doesn't work, as i explained in the issue that i post on the repo on github)
    Someone can explain me this error ??
    [
      @marblejs/core error:
    
      🚨  An effect returned a response: "{"status":"BAD_REQUEST","headers":{"Content-Type":"application/json; charset=utf-8"},"body":"[Validation Error] read model id does not exist"}" without bound request
    
      ] {
      name: 'CoreError'
    }
    I don't understand the "without bound request"