Beispiel #1
0
            .chain((t) => {
                if (t === null) {
                    return Future.reject('Session is not initialized');
                }

                return Model.updateOne(t).map(t => t[dataKey]);
            })
Beispiel #2
0
    return function parseUrlencodedBody(req, res) {
        if (!req.hasbody || req.bodyRead || !req.is(opts.type)) {
            return Pipeline.next(req, res);
        }

        let charset = req.charset;
        // debug('charset', charset);
        if (!R.isNil(charset) && charset !== 'utf-8') {
            return Future.reject(
                createHttpError(415, `unsupported charset "${charset}"`)
            );
        }

        return readBody(req, res, parse(req, res), R.merge(opts, {charset}))
            .chain(parse(req, res))
            .chain((body) => {
                debug('read body');
                req.bodyRead = true;
                return Pipeline.next(
                    req.update({body}),
                    res
                );
            })
        ;
    };
Beispiel #3
0
    return function(coll) {
        if (!checkCollection(coll)) return Future.reject("invalid collection");

        let args = Array.from(arguments).slice(1);
        return Future((reject, resolve) => {
            db[coll][action].apply(db[coll], args.concat((err, result) => err ? reject(err) : resolve(result)));
        });
    }
Beispiel #4
0
            const id = uuidv4();

            if (service.name) {
                // If there is a service name conflict, we will, by default, return an error.
                // However, there are situations where you may want to replace an existing
                // service with a new one.  As such, we allow the service to be overridden
                // if the force flag is set to true.
                if (service.name && this.serviceNames.has(service.name)) {
                    if (force) {
                        return this['service:deregister']({id: service.name, force: true}, source)
                            .chain(() => {
                                return this['service:register'](data, source);
                            })
                        ;
                    } else {
                        return Future.reject(new ServiceNameConflictError(`Duplicate service name ${service.name} found.`, service.name));
                    }
                }

                this.serviceNames.set(service.name, id);
            }

            this.services.set(id, service);

            service.id = id;

            // Set the services outbox so it can communicate with other services through
            // the kernel.
            const outbox = this.createOutbox();
            service._outbox = outbox;
module.exports = x => S.maybe(F.reject(x), F.of);
Beispiel #6
0
    file(req, path, options = {}) {
        const stream = send(req, path, options);
        return this.stream(stream);
    },

    format(req, data, formatters) {
        const types = Object.keys(formatters);
        const type = types.length ? req.acceptType(types) : formatters.default;

        if (type) {
            // TODO: vary
            return formatters[type](req, this, data);
        }

        return Future.reject(createHttpError(406, 'Not Acceptable'));
    },

    cookie(name, value, options = {}) {
        const {
            secret = null,
            encode = encodeURIComponent,
        } = options;

        if (R.is(Number, options.maxAge)) {
            if (!R.is(Date, options.expires)) {
                options = R.dissoc(
                    'maxAge',
                    R.assoc('expires', new Date(Date.now() + options.maxAge), options)
                );
            } else {