@fabriktor/fx 0.0.108 → 0.0.110

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,4 +1,4 @@
1
- import type { ChatOperator, UsersOperator, WSCloseHandler, WSConnection, WSErrorHandler, WSMessageHandler } from "@fabriktor/client";
1
+ import { type ChatOperator, type UsersOperator, type WSCloseHandler, type WSConnection, type WSErrorHandler, type WSMessageHandler } from "@fabriktor/client";
2
2
  import { type Chat, type ChatRoom, type ChatRoomMember, type User } from "@fabriktor/schema";
3
3
  import { type RequiredSearchOptions, type SearchOptions, type SearchPage, type SearchPaginationOptions } from "../core/search.js";
4
4
  import { ChatSendQueue, type ChatSendQueueOptions } from "./send-queue.js";
@@ -26,7 +26,7 @@ type SearchChatsScope = {
26
26
  chat_room_id?: string;
27
27
  owner_id: string;
28
28
  };
29
- export type SearchChatsOptions = SearchChatsScope & RequiredSearchOptions;
29
+ export type SearchChatsOptions = SearchChatsScope & RequiredSearchOptions & Pick<SearchOptions, "signal">;
30
30
  export type SearchChatsPage = SearchPage<Chat>;
31
31
  export type LatestChatsOptions = SearchPaginationOptions & {
32
32
  chat_room_id: string;
@@ -3,7 +3,8 @@
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 { IDKey, } from "@fabriktor/schema";
6
+ import { queryParam, queryParams, } from "@fabriktor/client";
7
+ import { IDKey, OwnerIDKey, } from "@fabriktor/schema";
7
8
  import { errRequired, errResolveFailed, errValidation } from "../core/err.js";
8
9
  import { requiredOperationID } from "../core/id.js";
9
10
  import { normalizeSearchPage, normalizeSearchPerPage, normalizeSearchQuery, runSearch, } from "../core/search.js";
@@ -69,13 +70,14 @@ export class ChatFX {
69
70
  }
70
71
  return await runSearch({
71
72
  search: (searchOpts) => this.chat.searchManyChats(searchOpts),
72
- query: {
73
+ query: queryParams({
73
74
  chat_room_id: opts.chat_room_id,
74
- owner_id: opts.owner_id,
75
- },
75
+ [OwnerIDKey]: opts.owner_id,
76
+ }),
76
77
  q,
77
78
  page: opts.page,
78
79
  per_page: opts.per_page,
80
+ signal: opts.signal,
79
81
  });
80
82
  }
81
83
  newLatestChatsCursor(opts) {
@@ -89,9 +91,7 @@ export class ChatFX {
89
91
  async latestChats(opts) {
90
92
  const raw = await runSearch({
91
93
  search: (searchOpts) => this.chat.searchManyChats(searchOpts),
92
- query: {
93
- chat_room_id: opts.chat_room_id,
94
- },
94
+ query: queryParam("chat_room_id", opts.chat_room_id),
95
95
  page: opts.page,
96
96
  per_page: opts.per_page,
97
97
  });
@@ -113,19 +113,16 @@ export class ChatFX {
113
113
  async searchChatRoomMembers(opts) {
114
114
  return await runSearch({
115
115
  search: (searchOpts) => this.chat.searchManyChatRoomMembers(searchOpts),
116
- query: {
117
- chat_room_id: opts.chat_room_id,
118
- },
116
+ query: queryParam("chat_room_id", opts.chat_room_id),
119
117
  q: opts.q,
120
118
  page: opts.page,
121
119
  per_page: opts.per_page,
120
+ signal: opts.signal,
122
121
  });
123
122
  }
124
123
  async chatRoomMembers(opts) {
125
124
  const out = await this.chat.queryChatRoomMembers({
126
- query: {
127
- chat_room_id: opts.chat_room_id,
128
- },
125
+ query: queryParam("chat_room_id", opts.chat_room_id),
129
126
  });
130
127
  return out.value ?? [];
131
128
  }
@@ -135,17 +132,13 @@ export class ChatFX {
135
132
  return [];
136
133
  }
137
134
  const out = await this.chat.queryChatRooms({
138
- query: {
139
- [IDKey]: ids,
140
- },
135
+ query: queryParam(IDKey, ids),
141
136
  });
142
137
  return out.value ?? [];
143
138
  }
144
139
  async myChatRoomMembers(opts) {
145
140
  const out = await this.chat.queryChatRoomMembers({
146
- query: {
147
- owner_id: opts.owner_id,
148
- },
141
+ query: queryParam(OwnerIDKey, opts.owner_id),
149
142
  });
150
143
  return out.value ?? [];
151
144
  }
@@ -1,4 +1,4 @@
1
- import type { ContactsOperator, UsersOperator } from "@fabriktor/client";
1
+ import { type ContactsOperator, type UsersOperator } from "@fabriktor/client";
2
2
  import { Friend, Hired, Manager, Na, OldHire, type Contact, type ID, type OperationResult, type User } from "@fabriktor/schema";
3
3
  type ContactInsertOptions = Parameters<ContactsOperator["insertOneContact"]>[0];
4
4
  type ContactReplaceOptions = Parameters<ContactsOperator["replaceOneContact"]>[0];
@@ -3,6 +3,7 @@
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 { queryParam, } from "@fabriktor/client";
6
7
  import { Friend, Hired, IDKey, Na, OldHire, UserTypeEmployee, UserTypeEmployer, } from "@fabriktor/schema";
7
8
  import { errRequired, errResolveFailed, errValidation } from "../core/err.js";
8
9
  import { requiredOperationID } from "../core/id.js";
@@ -250,7 +251,7 @@ export class ContactsFX {
250
251
  }
251
252
  const pages = await Promise.all(chunks(values, employmentUserBatchSize).map((chunk) => runSearch({
252
253
  per_page: chunk.length,
253
- query: { [IDKey]: chunk },
254
+ query: queryParam(IDKey, chunk),
254
255
  search: (searchOpts) => this.users.searchManyUsers({
255
256
  ...searchOpts,
256
257
  uid,
@@ -24,6 +24,7 @@ export declare class SearchController<T extends SearchResultWithID, Options exte
24
24
  replace(selection: Options): Promise<boolean>;
25
25
  loadMore(): Promise<boolean>;
26
26
  retry(): Promise<boolean>;
27
+ updateResult(value: T): void;
27
28
  private load;
28
29
  private emptyState;
29
30
  private publish;
@@ -41,6 +41,16 @@ export class SearchController {
41
41
  async retry() {
42
42
  return await this.load(this.next_page > normalizeSearchPage());
43
43
  }
44
+ // Update a displayed record without changing membership or backend position.
45
+ // Use query replacement when a mutation can affect either of those.
46
+ updateResult(value) {
47
+ if (!this.current.results.some((result) => result.id === value.id))
48
+ return;
49
+ this.publish({
50
+ ...this.current,
51
+ results: this.current.results.map((result) => result.id === value.id ? value : result),
52
+ });
53
+ }
44
54
  async load(append) {
45
55
  if (!this.selection || this.current.loading || this.current.loading_more) {
46
56
  return false;
@@ -26,21 +26,15 @@ export type ArchiveLocationOptions = {
26
26
  owner_id: string;
27
27
  location: Location;
28
28
  };
29
- export type SearchLocationsOptions = OwnerSearchOptions & {
30
- is_archived?: boolean;
31
- };
32
- export type SearchAccessibleLocationsOptions = SearchOptions & {
33
- is_archived?: boolean;
34
- };
35
- export type SearchJobProgramsOptions = OwnerSearchOptions & {
36
- location_id?: string;
37
- };
38
- export type SearchJobsOptions = OwnerSearchOptions & {
39
- location_id?: string;
40
- };
41
- export type SearchAccessibleJobsOptions = SearchOptions & {
42
- location_id?: string;
43
- };
29
+ type LocationSearchFields = Partial<Pick<Location, "is_archived">>;
30
+ type JobSearchFields = Partial<Pick<Job, "location_id" | "status">>;
31
+ export type SearchLocationsOptions = OwnerSearchOptions & LocationSearchFields;
32
+ export type SearchAccessibleLocationsOptions = SearchOptions & LocationSearchFields;
33
+ export type SearchJobProgramsOptions = OwnerSearchOptions & Partial<Pick<JobProgram, "finished">> & {
34
+ location_id?: JobProgram["job_location_id"];
35
+ };
36
+ export type SearchJobsOptions = OwnerSearchOptions & JobSearchFields;
37
+ export type SearchAccessibleJobsOptions = SearchOptions & JobSearchFields;
44
38
  export type SearchLocationsPage = SearchPage<Location>;
45
39
  export type SearchJobProgramsPage = SearchPage<JobProgram>;
46
40
  export type SearchJobsPage = SearchPage<Job>;
@@ -168,12 +168,13 @@ export class JobsFX {
168
168
  };
169
169
  }
170
170
  async searchJobPrograms(opts) {
171
- const { location_id, ...searchOpts } = opts;
171
+ const { location_id, finished, ...searchOpts } = opts;
172
172
  return await runOwnerSearch({
173
173
  ...searchOpts,
174
- query: location_id === undefined
175
- ? undefined
176
- : queryParams({ job_location_id: location_id }),
174
+ query: queryParams({
175
+ job_location_id: resolvedID(location_id),
176
+ finished,
177
+ }),
177
178
  search: (searchOpts) => this.jobs.searchManyJobPrograms(searchOpts),
178
179
  });
179
180
  }
@@ -219,20 +220,18 @@ export class JobsFX {
219
220
  return await this.findJob(id);
220
221
  }
221
222
  async searchJobs(opts) {
222
- const { location_id, ...searchOpts } = opts;
223
- const id = resolvedID(location_id);
223
+ const { location_id, status, ...searchOpts } = opts;
224
224
  return await runOwnerSearch({
225
225
  ...searchOpts,
226
- query: id === undefined ? undefined : queryParams({ location_id: id }),
226
+ query: jobSearchQuery({ location_id, status }),
227
227
  search: (opts) => this.jobs.searchManyJobs(opts),
228
228
  });
229
229
  }
230
230
  async searchAccessibleJobs(opts = {}) {
231
- const { location_id, ...searchOpts } = opts;
232
- const id = resolvedID(location_id);
231
+ const { location_id, status, ...searchOpts } = opts;
233
232
  return await runSearch({
234
233
  ...searchOpts,
235
- query: id === undefined ? undefined : queryParams({ location_id: id }),
234
+ query: jobSearchQuery({ location_id, status }),
236
235
  search: (opts) => this.jobs.searchMineJobs(opts),
237
236
  });
238
237
  }
@@ -440,6 +439,12 @@ export class JobsFX {
440
439
  return job;
441
440
  }
442
441
  }
442
+ function jobSearchQuery(fields) {
443
+ return queryParams({
444
+ location_id: resolvedID(fields.location_id),
445
+ status: fields.status,
446
+ });
447
+ }
443
448
  function jobMembershipInput(opts) {
444
449
  const id = requiredID(opts.job.id, "job", msgJobIDRequired);
445
450
  const location_id = locationID(opts.location, opts.job.location_id, "job", msgJobLocationMismatch);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fabriktor/fx",
3
- "version": "0.0.108",
3
+ "version": "0.0.110",
4
4
  "description": "![Fabriktor Logo](./img/fabriktor-character.gif)",
5
5
  "type": "module",
6
6
  "exports": {
@@ -17,7 +17,7 @@
17
17
  "typescript": "^6.0.3"
18
18
  },
19
19
  "dependencies": {
20
- "@fabriktor/client": "0.0.83",
20
+ "@fabriktor/client": "0.0.85",
21
21
  "@fabriktor/fx": "0.0.94",
22
22
  "@fabriktor/schema": "0.0.63"
23
23
  }