@omnixdp/typegen 0.3.2 → 0.3.3

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.
@@ -86,7 +86,7 @@ async function fetchBoSchema(apiBase, app, token, spaceRef) {
86
86
  return { space, dataTypes };
87
87
  }
88
88
  async function resolveSpace(apiBase, app, token, spaceRef) {
89
- const spaces = await apiGet(apiBase, app, token, "spaces", { limit: "500" });
89
+ const spaces = await apiGetList(apiBase, app, token, "spaces", { limit: "100" });
90
90
  const wanted = spaceRef.trim();
91
91
  const match = spaces.find((space) => space.id === wanted || space.slug === wanted || space.name === wanted);
92
92
  if (!match?.id || !match.name || !match.slug) {
@@ -95,7 +95,7 @@ async function resolveSpace(apiBase, app, token, spaceRef) {
95
95
  return { id: match.id, name: match.name, slug: match.slug };
96
96
  }
97
97
  async function fetchModels(apiBase, app, token, resource, spaceId) {
98
- const rows = await apiGet(apiBase, app, token, resource, { spaceId, limit: "500", includeArchived: "1" });
98
+ const rows = await apiGetList(apiBase, app, token, resource, { spaceId, limit: "100", includeArchived: "1" });
99
99
  return rows
100
100
  .filter((row) => Boolean(row.id && row.name && row.apiIdentifier))
101
101
  .map((row) => ({
@@ -105,7 +105,20 @@ async function fetchModels(apiBase, app, token, resource, spaceId) {
105
105
  fields: normalizeFields(row.fields ?? [])
106
106
  }));
107
107
  }
108
- async function apiGet(apiBase, app, token, resource, query) {
108
+ async function apiGetList(apiBase, app, token, resource, query) {
109
+ const rows = [];
110
+ let page = 1;
111
+ while (true) {
112
+ const result = await apiGetEnvelope(apiBase, app, token, resource, { ...query, page: String(page) });
113
+ rows.push(...result.data);
114
+ const pagination = readPagination(result.meta);
115
+ if (!pagination || result.data.length === 0 || rows.length >= pagination.total) {
116
+ return rows;
117
+ }
118
+ page = pagination.page + 1;
119
+ }
120
+ }
121
+ async function apiGetEnvelope(apiBase, app, token, resource, query) {
109
122
  const url = new URL(`${apiBase}/${app}/${resource}`);
110
123
  for (const [key, value] of Object.entries(query)) {
111
124
  url.searchParams.set(key, value);
@@ -121,7 +134,15 @@ async function apiGet(apiBase, app, token, resource, query) {
121
134
  const message = body && "error" in body ? body.error?.message : undefined;
122
135
  throw new Error(`Failed to fetch ${app}/${resource}: ${message ?? response.statusText}`);
123
136
  }
124
- return body.data;
137
+ return { data: body.data, meta: body.meta };
138
+ }
139
+ function readPagination(meta) {
140
+ const pagination = meta?.pagination;
141
+ const page = typeof pagination?.page === "number" && Number.isFinite(pagination.page) ? Math.trunc(pagination.page) : null;
142
+ const total = typeof pagination?.total === "number" && Number.isFinite(pagination.total) ? Math.trunc(pagination.total) : null;
143
+ if (page === null || total === null)
144
+ return null;
145
+ return { page, total };
125
146
  }
126
147
  function normalizeFields(fields) {
127
148
  return fields
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnixdp/typegen",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "description": "TypeScript type generator for Omni xDP SDK response models.",
5
5
  "license": "MIT",
6
6
  "repository": {