fsanyoto commited on
Commit
77e5524
·
verified ·
1 Parent(s): ecd617f

Deploy AIOS web (React glide grid + FastAPI slice)

Browse files
RELEASES.json CHANGED
@@ -1,4 +1,4 @@
1
  {
2
- "current": "97257dacca6",
3
  "releases": []
4
  }
 
1
  {
2
+ "current": "092e56b2ead",
3
  "releases": []
4
  }
VERSION CHANGED
@@ -1 +1 @@
1
- 97257dacca6
 
1
+ 092e56b2ead
api/routes_external.py CHANGED
@@ -2934,11 +2934,17 @@ def _query_database_page(session: Session, database: str, payload: dict):
2934
  "database": database, "fields": selected_keys, "filters": scoped.get("filters"),
2935
  "sorts": sorts, "aggregates": aggregates, "limit": limit,
2936
  })
2937
- # Bind a cursor to the live permission projection as well as the source revision. A field or
2938
- # row-scope revocation changes this hash on the next call, so an old page cannot skip into a
2939
- # newly narrowed result set. Only the digest enters the cursor; no record id or value does.
 
 
 
 
 
 
2940
  snapshot_digest = _json_digest({
2941
- "source_version": scoped.get("source_version"),
2942
  "visible_fields": [field["key"] for field in visible_fields
2943
  if isinstance(field, dict) and field.get("key") in visible_keys],
2944
  "permitted_pids": [row.get("pid") for row in rows],
 
2934
  "database": database, "fields": selected_keys, "filters": scoped.get("filters"),
2935
  "sorts": sorts, "aggregates": aggregates, "limit": limit,
2936
  })
2937
+ snapshot_source = scoped.get("source_version")
2938
+ if scoped.get("source_kind") == "runtime_cache":
2939
+ # Bind authorized content and linked permissions because pool timestamps differ by worker.
2940
+ snapshot_source = {
2941
+ "records": rows,
2942
+ "link_scope": (snapshot_source.get("link_scope")
2943
+ if isinstance(snapshot_source, dict) else None),
2944
+ }
2945
+ # Only the digest enters the cursor, including every visible field and permitted row.
2946
  snapshot_digest = _json_digest({
2947
+ "source_version": snapshot_source,
2948
  "visible_fields": [field["key"] for field in visible_fields
2949
  if isinstance(field, dict) and field.get("key") in visible_keys],
2950
  "permitted_pids": [row.get("pid") for row in rows],
web/public/AIOS_DEPLOY_RECEIPT CHANGED
@@ -1 +1 @@
1
- 28f494a1bff26c1441ab680e4e8d4b823c63741879de814769878c4e69caf407
 
1
+ 8425f95624766de59c627c48dd69bf18f4aca378441cad9b12949bd6e7e710ce
web/src/apps/catalog/useCatalogData.ts CHANGED
@@ -195,28 +195,73 @@ export function useCatalogData(database: string, scope: CatalogReadScope, search
195
 
196
  export interface CatalogRecords { fields: Field[]; rows: Row[] }
197
 
198
- /** Read every page of one query. The document is read once and one limit holds for the whole walk. */
199
  export async function loadCatalogRecords(database: string, scope: CatalogReadScope, signal: AbortSignal,
200
  query: Pick<CatalogPageRequest, "search" | "searchFields"> = {},
201
  onPage?: (data: CatalogRecords) => void): Promise<CatalogRecords> {
202
  const properties = await documentProperties(await typedOpenApi(signal), database);
203
- const cursors: (string | null)[] = [null];
204
- let limit = RECORDS_PAGE_SIZE;
205
- let data: CatalogRecords = { fields: [], rows: [] };
206
- for (;;) {
207
- const page = await loadCatalogData(database, scope, signal,
208
- { ...query, cursor: cursors[cursors.length - 1], limit, priorCursors: [...cursors] }, properties);
209
- limit = page.limit;
210
- data = { fields: page.fields, rows: [...data.rows, ...page.rows] };
211
- onPage?.(data);
212
- if (!page.nextCursor) return data;
213
- cursors.push(page.nextCursor);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
214
  }
215
  }
216
 
217
  type RecordsState = CatalogRecords & { key: string; loading: boolean; error: string };
218
 
219
- /** Hold every record of the query. Rows grow per page and loading stays true until the last page. */
220
  export function useCatalogRecords(database: string, scope: CatalogReadScope, searchFields: string[] = []) {
221
  const [search, setSearch] = useState("");
222
  const scopeJson = JSON.stringify(scope);
@@ -228,20 +273,22 @@ export function useCatalogRecords(database: string, scope: CatalogReadScope, sea
228
 
229
  useEffect(() => {
230
  const controller = new AbortController();
231
- setState((live) => ({ fields: live.fields, rows: [], key, loading: true, error: "" }));
 
232
  void loadCatalogRecords(database, JSON.parse(scopeJson) as CatalogReadScope, controller.signal,
233
  { search, searchFields: JSON.parse(searchJson) }, (data) => {
234
- if (!controller.signal.aborted) setState({ ...data, key, loading: true, error: "" });
 
235
  }).then((data) => {
236
  if (!controller.signal.aborted) setState({ ...data, key, loading: false, error: "" });
237
- }).catch((error: unknown) => {
238
- if (!controller.signal.aborted) setState((live) => ({ fields: live.fields, rows: [], key, loading: false,
239
- error: error instanceof Error ? error.message : "The App could not be loaded." }));
240
  });
241
  return () => controller.abort();
242
  }, [database, scopeJson, searchJson, search, key, attempt]);
243
 
244
- const live = state.key === key ? state : { fields: state.fields, rows: [] as Row[], key, loading: true, error: "" };
245
  return { fields: live.fields, rows: live.rows, loading: live.loading, error: live.error, retry, search, setSearch };
246
  }
247
 
 
195
 
196
  export interface CatalogRecords { fields: Field[]; rows: Row[] }
197
 
198
+ /** Read every page with one document and one negotiated limit across at most two stale restarts. */
199
  export async function loadCatalogRecords(database: string, scope: CatalogReadScope, signal: AbortSignal,
200
  query: Pick<CatalogPageRequest, "search" | "searchFields"> = {},
201
  onPage?: (data: CatalogRecords) => void): Promise<CatalogRecords> {
202
  const properties = await documentProperties(await typedOpenApi(signal), database);
203
+ signal.throwIfAborted();
204
+ const filters = typedFilters(scope);
205
+ const search = query.search?.trim();
206
+ const searchNodes = search ? [...new Set(query.searchFields)].filter(Boolean).map((colId) =>
207
+ ({ colId, op: "contains", value: search })) : [];
208
+ if (search && !searchNodes.length) throw new Error("Choose a search field.");
209
+ const body: QueryRequest = {
210
+ limit: RECORDS_PAGE_SIZE,
211
+ filters: searchNodes.length ? { conj: "and", nodes: [
212
+ ...(filters ? [{ conj: filters.conj, children: filters.nodes }] : []),
213
+ { conj: "or", children: searchNodes },
214
+ ] } as QueryRequest["filters"] : filters,
215
+ sorts: scope.sorts.map((sort) => ({ field: sort.colId, direction: sort.dir })),
216
+ };
217
+ let limit: number | null = null;
218
+ for (let restarts = 0; ; restarts += 1) {
219
+ const cursors: (string | null)[] = [null];
220
+ let data: CatalogRecords = { fields: [], rows: [] };
221
+ try {
222
+ for (;;) {
223
+ signal.throwIfAborted();
224
+ const cursor = cursors[cursors.length - 1];
225
+ let response: QueryResponse;
226
+ if (limit === null) {
227
+ const first = await firstPage(database, body, signal);
228
+ response = first.response;
229
+ limit = first.limit;
230
+ } else {
231
+ response = await typedQuery(database, { ...body, cursor, limit }, signal);
232
+ }
233
+ signal.throwIfAborted();
234
+ if (response.database !== database || !Array.isArray(response.records) || !Array.isArray(response.fields) ||
235
+ response.page?.returned !== response.records.length || response.records.length > limit ||
236
+ typeof response.page.has_more !== "boolean") {
237
+ throw new Error("The App page could not be confirmed.");
238
+ }
239
+ const nextCursor = response.page.has_more ? response.page.next_cursor : null;
240
+ if (response.page.has_more && (typeof nextCursor !== "string" || !nextCursor || cursors.includes(nextCursor) ||
241
+ !response.page.returned)) {
242
+ throw new Error("The App cursor did not advance. Retry the request.");
243
+ }
244
+ const fields = response.fields.filter((field) => Object.hasOwn(properties, field.key)).map<Field>((field) => ({
245
+ ...field, label: field.label ?? field.key, type: field.type as Field["type"],
246
+ source: field.source === "odoo" ? "odoo" : "overlay",
247
+ }));
248
+ const rows = response.records.map((record) => projectRow(record, properties));
249
+ data = { fields, rows: [...data.rows, ...rows] };
250
+ onPage?.(data);
251
+ signal.throwIfAborted();
252
+ if (!nextCursor) return data;
253
+ cursors.push(nextCursor);
254
+ }
255
+ } catch (error) {
256
+ signal.throwIfAborted();
257
+ if (!(error instanceof TypedRefusal) || error.code !== "query_cursor_stale" || restarts >= 2) throw error;
258
+ }
259
  }
260
  }
261
 
262
  type RecordsState = CatalogRecords & { key: string; loading: boolean; error: string };
263
 
264
+ /** Retain rows for the current query while a new walk loads or fails. */
265
  export function useCatalogRecords(database: string, scope: CatalogReadScope, searchFields: string[] = []) {
266
  const [search, setSearch] = useState("");
267
  const scopeJson = JSON.stringify(scope);
 
273
 
274
  useEffect(() => {
275
  const controller = new AbortController();
276
+ setState((live) => ({ fields: live.key === key ? live.fields : [], rows: live.key === key ? live.rows : [],
277
+ key, loading: true, error: "" }));
278
  void loadCatalogRecords(database, JSON.parse(scopeJson) as CatalogReadScope, controller.signal,
279
  { search, searchFields: JSON.parse(searchJson) }, (data) => {
280
+ if (!controller.signal.aborted) setState((live) => live.key === key && live.rows.length > data.rows.length
281
+ ? live : { ...data, key, loading: true, error: "" });
282
  }).then((data) => {
283
  if (!controller.signal.aborted) setState({ ...data, key, loading: false, error: "" });
284
+ }).catch(() => {
285
+ if (!controller.signal.aborted) setState((live) => ({ ...live, key, loading: false,
286
+ error: "Could not load records" }));
287
  });
288
  return () => controller.abort();
289
  }, [database, scopeJson, searchJson, search, key, attempt]);
290
 
291
+ const live = state.key === key ? state : { fields: [], rows: [] as Row[], key, loading: true, error: "" };
292
  return { fields: live.fields, rows: live.rows, loading: live.loading, error: live.error, retry, search, setSearch };
293
  }
294