@fabriktor/client 0.0.48 → 0.0.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  import { type InUser, type OperationResult, type PLUsersContactList, type PLUsersForgotPassword, type PLUsersResolveUsername, type PLUsersSignInLink, type PLUsersVerifyEmail, type UpsertResult, type User } from "@fabriktor/schema";
2
2
  import type { TokenProvider } from "../core/auth.js";
3
- import type { OperationResultOf } from "../core/crud.js";
3
+ import type { DeleteOneOptionsCRUD, FindOneOptionsCRUD, OperationResultOf, QueryOptionsCRUD, ReplaceOneOptionsCRUD, SearchManyOptionsCRUD, SearchResultOf } from "../core/crud.js";
4
4
  import type { HTTPDoer } from "../core/http.js";
5
5
  import type { CompletePayload } from "../core/type.js";
6
6
  export type BootstrapOptions = {
@@ -11,14 +11,16 @@ export type ForgotPasswordOptions = CompletePayload<PLUsersForgotPassword>;
11
11
  export type SendSignInLinkOptions = CompletePayload<PLUsersSignInLink>;
12
12
  export type SendEmailVerificationOptions = CompletePayload<PLUsersVerifyEmail>;
13
13
  export type MatchOptions = CompletePayload<PLUsersContactList>;
14
- export type SearchOptions = {
15
- q: string;
16
- limit?: number;
17
- };
18
14
  export type GetByUIDOptions = {
19
15
  uid: string;
20
16
  };
17
+ export type SearchManyUsersOptions = SearchManyOptionsCRUD & GetByUIDOptions;
21
18
  export interface UsersOperator {
19
+ queryUsers(opts?: QueryOptionsCRUD): Promise<OperationResultOf<User[]>>;
20
+ findOneUser(opts: FindOneOptionsCRUD): Promise<OperationResultOf<User>>;
21
+ replaceOneUser(opts: ReplaceOneOptionsCRUD<InUser>): Promise<OperationResult>;
22
+ deleteOneUser(opts: DeleteOneOptionsCRUD): Promise<OperationResult>;
23
+ searchManyUsers(opts: SearchManyUsersOptions): Promise<OperationResultOf<SearchResultOf<User>>>;
22
24
  bootstrap(opts: BootstrapOptions): Promise<OperationResultOf<UpsertResult>>;
23
25
  sync(): Promise<OperationResult>;
24
26
  sendEmailVerification(opts: SendEmailVerificationOptions): Promise<void>;
@@ -26,7 +28,6 @@ export interface UsersOperator {
26
28
  sendSignInLink(opts: SendSignInLinkOptions): Promise<void>;
27
29
  resolveUsername(opts: ResolveUsernameOptions): Promise<OperationResultOf<string>>;
28
30
  match(opts: MatchOptions): Promise<OperationResultOf<User[]>>;
29
- search(opts: SearchOptions): Promise<OperationResultOf<User[]>>;
30
31
  getByUID(opts: GetByUIDOptions): Promise<OperationResultOf<User[]>>;
31
32
  }
32
33
  export type UsersClientOptions = {
@@ -35,10 +36,16 @@ export type UsersClientOptions = {
35
36
  get_token?: TokenProvider;
36
37
  };
37
38
  export declare class UsersClient implements UsersOperator {
39
+ private users;
38
40
  private http;
39
41
  private base_url;
40
42
  private get_token?;
41
43
  constructor(opts: UsersClientOptions);
44
+ queryUsers(opts?: QueryOptionsCRUD): Promise<OperationResultOf<User[]>>;
45
+ findOneUser(opts: FindOneOptionsCRUD): Promise<OperationResultOf<User>>;
46
+ replaceOneUser(opts: ReplaceOneOptionsCRUD<InUser>): Promise<OperationResult>;
47
+ deleteOneUser(opts: DeleteOneOptionsCRUD): Promise<OperationResult>;
48
+ searchManyUsers(opts: SearchManyUsersOptions): Promise<OperationResultOf<SearchResultOf<User>>>;
42
49
  bootstrap(opts: BootstrapOptions): Promise<OperationResultOf<UpsertResult>>;
43
50
  sync(): Promise<OperationResult>;
44
51
  sendEmailVerification(opts: SendEmailVerificationOptions): Promise<void>;
@@ -46,7 +53,6 @@ export declare class UsersClient implements UsersOperator {
46
53
  sendSignInLink(opts: SendSignInLinkOptions): Promise<void>;
47
54
  resolveUsername(opts: ResolveUsernameOptions): Promise<OperationResultOf<string>>;
48
55
  match(opts: MatchOptions): Promise<OperationResultOf<User[]>>;
49
- search(opts: SearchOptions): Promise<OperationResultOf<User[]>>;
50
56
  getByUID(opts: GetByUIDOptions): Promise<OperationResultOf<User[]>>;
51
57
  }
52
58
  export declare function newUsersClient(opts: UsersClientOptions): UsersClient;
@@ -3,19 +3,50 @@
3
3
  // Licensed under the Apache License, Version 2.0 (the "License"); you may
4
4
  // not use this file except in compliance with the License. You may obtain
5
5
  // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- import { ColUsersUsers, HTTPMethodGet, HTTPMethodPost, PathSearch, PathUsersBootstrap, PathUsersForgotPassword, PathUsersMatch, PathUsersResolveUsername, PathUsersSendEmailVerification, PathUsersSendSignInLink, PathUsersSync, SvcUsers, } from "@fabriktor/schema";
6
+ import { ColUsersUsers, HTTPMethodPost, PathUsersBootstrap, PathUsersForgotPassword, PathUsersMatch, PathUsersResolveUsername, PathUsersSendEmailVerification, PathUsersSendSignInLink, PathUsersSync, SvcUsers, } from "@fabriktor/schema";
7
7
  import { requiredToken } from "../core/auth.js";
8
- import { queryParam, withQuery } from "../core/col.js";
8
+ import { queryParam } from "../core/col.js";
9
+ import { newCRUDClient } from "../core/crud.js";
9
10
  import { buildPath } from "../core/path.js";
10
11
  export class UsersClient {
12
+ users;
11
13
  http;
12
14
  base_url;
13
15
  get_token;
14
16
  constructor(opts) {
17
+ this.users = newCRUDClient({
18
+ http: opts.http,
19
+ base_url: opts.base_url,
20
+ svc: SvcUsers,
21
+ col: ColUsersUsers,
22
+ get_token: opts.get_token,
23
+ });
15
24
  this.http = opts.http;
16
25
  this.base_url = opts.base_url;
17
26
  this.get_token = opts.get_token;
18
27
  }
28
+ async queryUsers(opts) {
29
+ return await this.users.query(opts);
30
+ }
31
+ async findOneUser(opts) {
32
+ return await this.users.findOne(opts);
33
+ }
34
+ async replaceOneUser(opts) {
35
+ return await this.users.replaceOne(opts);
36
+ }
37
+ async deleteOneUser(opts) {
38
+ return await this.users.deleteOne(opts);
39
+ }
40
+ async searchManyUsers(opts) {
41
+ const { uid, query, ...searchOpts } = opts;
42
+ return await this.users.searchMany({
43
+ ...searchOpts,
44
+ query: {
45
+ ...(query ?? {}),
46
+ ...userUIDQuery(uid),
47
+ },
48
+ });
49
+ }
19
50
  async bootstrap(opts) {
20
51
  const token = await requiredToken(this.get_token);
21
52
  return await this.http.do({
@@ -79,40 +110,15 @@ export class UsersClient {
79
110
  body: opts,
80
111
  });
81
112
  }
82
- async search(opts) {
83
- const token = await requiredToken(this.get_token);
84
- return await this.http.do({
85
- base_url: this.base_url,
86
- path: userPath(PathSearch),
87
- method: HTTPMethodPost,
88
- token,
89
- body: {
90
- q: opts.q,
91
- limit: opts.limit,
92
- },
93
- });
94
- }
95
113
  async getByUID(opts) {
96
- const token = await requiredToken(this.get_token);
97
- return await this.http.do({
98
- base_url: this.base_url,
99
- path: withQuery(collectionPath(), {
100
- query: queryParam("uid", opts.uid),
101
- }),
102
- method: HTTPMethodGet,
103
- token,
114
+ return await this.queryUsers({
115
+ query: userUIDQuery(opts.uid),
104
116
  });
105
117
  }
106
118
  }
107
119
  export function newUsersClient(opts) {
108
120
  return new UsersClient(opts);
109
121
  }
110
- function collectionPath() {
111
- return buildPath({
112
- svc: SvcUsers,
113
- col: ColUsersUsers,
114
- });
115
- }
116
122
  function userPath(action) {
117
123
  return buildPath({
118
124
  svc: SvcUsers,
@@ -120,3 +126,6 @@ function userPath(action) {
120
126
  action,
121
127
  });
122
128
  }
129
+ function userUIDQuery(uid) {
130
+ return queryParam("uid", uid);
131
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fabriktor/client",
3
- "version": "0.0.48",
3
+ "version": "0.0.50",
4
4
  "description": "![Fabriktor Logo](./img/fabriktor-character.gif)",
5
5
  "type": "module",
6
6
  "exports": {