当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Application.service方法代码示例

本文整理汇总了TypeScript中@feathersjs/feathers.Application.service方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Application.service方法的具体用法?TypeScript Application.service怎么用?TypeScript Application.service使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在@feathersjs/feathers.Application的用法示例。


在下文中一共展示了Application.service方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: it

    it('promise event dispatching', done => {
      app.channel('testing').join(c1);
      app.channel('othertest').join(c2);

      app.service('test').registerPublisher('created', () =>
        new Promise(resolve =>
          setTimeout(() => resolve(app.channel('testing')), 50)
        )
      );
      app.service('test').registerPublisher('created', () =>
        new Promise(resolve =>
          setTimeout(() => resolve(app.channel('testing', 'othertest')), 100)
        )
      );

      app.once('publish', (_event: string, channel: Channel, hook: HookContext) => {
        assert.deepStrictEqual(hook.result, data);
        assert.deepStrictEqual(channel.connections, [ c1, c2 ]);
        done();
      });

      app.service('test')
        .create(data)
        .catch(done);
    });
开发者ID:feathersjs,项目名称:feathers,代码行数:25,代码来源:dispatch.test.ts

示例2: default

export default (app: Application) => {
  const authentication = new AuthenticationService(app);

  app.set('authentication', {
    entity: 'user',
    service: 'users',
    secret: 'supersecret',
    authStrategies: [ 'local', 'jwt' ],
    local: {
      usernameField: 'email',
      passwordField: 'password'
    }
  });

  authentication.register('jwt', new JWTStrategy());
  authentication.register('local', new LocalStrategy());

  app.use('/authentication', authentication);
  app.use('/users', memory({
    paginate: {
      default: 10,
      max: 20
    }
  }));

  app.service('users').hooks({
    before: {
      create: hashPassword('password')
    },
    after: protect('password')
  });

  app.use('/dummy', {
    find (params) {
      return Promise.resolve(params);
    }
  });

  app.service('dummy').hooks({
    before: authenticate('jwt')
  });

  app.service('users').hooks({
    before (context: HookContext) {
      if (context.id !== undefined && context.id !== null) {
        context.id = parseInt(context.id as string, 10);
      }

      return context;
    }
  });

  return app;
};
开发者ID:feathersjs,项目名称:feathers,代码行数:54,代码来源:fixture.ts

示例3: beforeEach

  beforeEach(async () => {
    app = feathers();

    const authService = new AuthenticationService(app, 'authentication', {
      entity: 'user',
      service: 'users',
      secret: 'supersecret',
      authStrategies: [ 'jwt' ]
    });

    authService.register('jwt', new JWTStrategy());

    app.use('/users', memory());
    app.use('/protected', {
      async get (id, params) {
        return {
          id, params
        };
      }
    });
    app.use('/authentication', authService);

    const service = app.service('authentication');

    app.service('protected').hooks({
      before: {
        all: [ authenticate('jwt') ]
      }
    });

    app.service('users').hooks({
      after: {
        get: [context => {
          if (context.params.provider) {
            context.result.isExternal = true;
          }

          return context;
        }]
      }
    });

    user = await app.service('users').create({
      name: 'David'
    });

    accessToken = await service.createAccessToken({}, {
      subject: `${user.id}`
    });

    payload = await service.verifyAccessToken(accessToken);
  });
开发者ID:feathersjs,项目名称:feathers,代码行数:52,代码来源:jwt.test.ts

示例4: it

    it('errors when subject can not be found', async () => {
      // @ts-ignore
      app.service('users').options.id = 'somethingElse';

      try {
        await app.service('authentication').create({
          strategy: 'first',
          username: 'David'
        });
        assert.fail('Should never get here');
      } catch (error) {
        assert.strictEqual(error.name, 'NotAuthenticated');
        assert.strictEqual(error.message, 'Can not set subject from user.somethingElse');
      }
    });
开发者ID:feathersjs,项目名称:feathers,代码行数:15,代码来源:service.test.ts

示例5: it

  it('does nothing when field is not present', async () => {
    const user = await app.service('users').create({
      email: 'dave@hashpassword.com'
    });

    assert.strictEqual(user.password, undefined);
  });
开发者ID:feathersjs,项目名称:feathers,代码行数:7,代码来源:hash-password.test.ts

示例6: it

    it('returns null when header not set', async () => {
      const req = {} as MockRequest;

      const result = await app.service('authentication').parse(req, res, 'jwt');

      assert.strictEqual(result, null);
    });
开发者ID:feathersjs,项目名称:feathers,代码行数:7,代码来源:jwt.test.ts


注:本文中的@feathersjs/feathers.Application.service方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。