@omnixdp/typegen 0.3.1 → 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.
- package/README.md +1 -1
- package/dist/fetch-schema.js +25 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -27,7 +27,7 @@ npx omnixdp-typegen \
|
|
|
27
27
|
|
|
28
28
|
Space arguments can be a space id, slug, or exact name. Typegen loads `.env` and `.env.local` before evaluating config files, then exchanges client credentials for short-lived access tokens. Existing `--management-token`, `--business-objects-token`, and `--ratings-and-reviews-token` flags remain supported when you already have bearer tokens. Regenerate the output after changing content types, taxonomy types, data types, or global fields in the admin.
|
|
29
29
|
|
|
30
|
-
Generated CMS taxonomy response aliases use the delivery SDK's typed taxonomy tree shape: term `slug` and `url`
|
|
30
|
+
Generated CMS taxonomy response aliases use the delivery SDK's typed taxonomy tree shape: term `slug` and `url` are part of nested node `data` when those taxonomy fields are exposed through the Delivery API.
|
|
31
31
|
|
|
32
32
|
## Check in CI
|
|
33
33
|
|
package/dist/fetch-schema.js
CHANGED
|
@@ -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
|
|
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
|
|
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
|
|
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
|