@lumibase/sdk 2.0.0 → 2.2.1
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/dist/index.cjs +964 -32
- package/dist/index.d.cts +644 -10
- package/dist/index.d.ts +644 -10
- package/dist/index.js +954 -32
- package/package.json +5 -2
package/dist/index.cjs
CHANGED
|
@@ -24,8 +24,12 @@ __export(index_exports, {
|
|
|
24
24
|
AudienceClient: () => AudienceClient,
|
|
25
25
|
DECISION_ERROR_CODES: () => DECISION_ERROR_CODES,
|
|
26
26
|
DEFAULT_IMPORT_SOURCE: () => DEFAULT_IMPORT_SOURCE,
|
|
27
|
+
DEFAULT_ZOD_IMPORT: () => DEFAULT_ZOD_IMPORT,
|
|
28
|
+
FILES_INTERFACE: () => FILES_INTERFACE,
|
|
29
|
+
FILE_INTERFACE: () => FILE_INTERFACE,
|
|
27
30
|
LumiError: () => LumiError,
|
|
28
31
|
RealtimeClient: () => RealtimeClient,
|
|
32
|
+
TRANSLATABLE_INTERFACE: () => TRANSLATABLE_INTERFACE,
|
|
29
33
|
ackCdcSubscription: () => ackCdcSubscription,
|
|
30
34
|
checkCdcPipelineHealth: () => checkCdcPipelineHealth,
|
|
31
35
|
createAgentArtifact: () => createAgentArtifact,
|
|
@@ -46,8 +50,12 @@ __export(index_exports, {
|
|
|
46
50
|
evaluateAgentArtifact: () => evaluateAgentArtifact,
|
|
47
51
|
exportAccessManifest: () => exportAccessManifest,
|
|
48
52
|
extractSeo: () => extractSeo,
|
|
53
|
+
filterManifest: () => filterManifest,
|
|
49
54
|
generateAgentApp: () => generateAgentApp,
|
|
55
|
+
generateGraphQLSdl: () => generateGraphQLSdl,
|
|
56
|
+
generateOpenApi: () => generateOpenApi,
|
|
50
57
|
generateTypes: () => generateTypes,
|
|
58
|
+
generateZod: () => generateZod,
|
|
51
59
|
getEffectivePreset: () => getEffectivePreset,
|
|
52
60
|
getReview: () => getReview,
|
|
53
61
|
getReviewProfile: () => getReviewProfile,
|
|
@@ -76,7 +84,9 @@ __export(index_exports, {
|
|
|
76
84
|
readCdcSubscription: () => readCdcSubscription,
|
|
77
85
|
readItem: () => readItem,
|
|
78
86
|
readItems: () => readItems,
|
|
87
|
+
realtimeHolders: () => realtimeHolders,
|
|
79
88
|
replayCdcSubscription: () => replayCdcSubscription,
|
|
89
|
+
retainRealtime: () => retainRealtime,
|
|
80
90
|
retryAgentRun: () => retryAgentRun,
|
|
81
91
|
reviewContentHash: () => reviewContentHash,
|
|
82
92
|
reviewDraft: () => reviewDraft,
|
|
@@ -187,16 +197,35 @@ function createLumiClient(opts) {
|
|
|
187
197
|
}
|
|
188
198
|
return refreshInFlight;
|
|
189
199
|
}
|
|
190
|
-
|
|
200
|
+
function buildHeaders(init) {
|
|
191
201
|
const headers = new Headers(init.headers);
|
|
192
202
|
for (const [key, value] of Object.entries(opts.headers ?? {})) {
|
|
193
203
|
headers.set(key, value);
|
|
194
204
|
}
|
|
195
205
|
headers.set("authorization", `Bearer ${currentToken}`);
|
|
196
206
|
headers.set("x-lumi-site", opts.siteId);
|
|
197
|
-
|
|
207
|
+
const isForm = typeof FormData !== "undefined" && init.body instanceof FormData;
|
|
208
|
+
if (!headers.has("content-type") && init.body && !isForm) {
|
|
198
209
|
headers.set("content-type", "application/json");
|
|
199
210
|
}
|
|
211
|
+
return headers;
|
|
212
|
+
}
|
|
213
|
+
async function rawFetch(path, init = {}, retried = false) {
|
|
214
|
+
const res = await fetcher(`${base}${path}`, { ...init, headers: buildHeaders(init) });
|
|
215
|
+
if (res.ok) return res;
|
|
216
|
+
if (res.status === 401 && !retried && currentRefreshToken && await attemptRefresh()) {
|
|
217
|
+
return rawFetch(path, init, true);
|
|
218
|
+
}
|
|
219
|
+
if (res.status === 401 && opts.onUnauthorized) {
|
|
220
|
+
try {
|
|
221
|
+
opts.onUnauthorized();
|
|
222
|
+
} catch {
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
throw new LumiError(res.status, toErrorBody(res.status, parseResponseBody(await res.text())), res.headers);
|
|
226
|
+
}
|
|
227
|
+
async function rawRequest(path, init = {}, retried = false) {
|
|
228
|
+
const headers = buildHeaders(init);
|
|
200
229
|
const res = await fetcher(`${base}${path}`, { ...init, headers });
|
|
201
230
|
const text = await res.text();
|
|
202
231
|
const body = parseResponseBody(text);
|
|
@@ -224,6 +253,7 @@ function createLumiClient(opts) {
|
|
|
224
253
|
siteId: opts.siteId,
|
|
225
254
|
fetcher,
|
|
226
255
|
rawRequest,
|
|
256
|
+
rawFetch: (path, init) => rawFetch(path, init),
|
|
227
257
|
async request(command) {
|
|
228
258
|
return command(this);
|
|
229
259
|
},
|
|
@@ -414,6 +444,29 @@ var AudienceClient = class {
|
|
|
414
444
|
}
|
|
415
445
|
};
|
|
416
446
|
|
|
447
|
+
// src/realtime/retain.ts
|
|
448
|
+
var holders = /* @__PURE__ */ new WeakMap();
|
|
449
|
+
function realtimeHolders(client) {
|
|
450
|
+
return holders.get(client) ?? 0;
|
|
451
|
+
}
|
|
452
|
+
function retainRealtime(client) {
|
|
453
|
+
const count = realtimeHolders(client);
|
|
454
|
+
holders.set(client, count + 1);
|
|
455
|
+
if (count === 0) client.connect();
|
|
456
|
+
let released = false;
|
|
457
|
+
return () => {
|
|
458
|
+
if (released) return;
|
|
459
|
+
released = true;
|
|
460
|
+
const next = realtimeHolders(client) - 1;
|
|
461
|
+
if (next <= 0) {
|
|
462
|
+
holders.delete(client);
|
|
463
|
+
client.disconnect();
|
|
464
|
+
} else {
|
|
465
|
+
holders.set(client, next);
|
|
466
|
+
}
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
|
|
417
470
|
// src/realtime/index.ts
|
|
418
471
|
var RealtimeClient = class {
|
|
419
472
|
constructor(opts) {
|
|
@@ -616,6 +669,10 @@ var RealtimeClient = class {
|
|
|
616
669
|
};
|
|
617
670
|
|
|
618
671
|
// src/rest/legacy.ts
|
|
672
|
+
function ifMatchInit(options) {
|
|
673
|
+
if (options?.ifMatch === void 0) return {};
|
|
674
|
+
return { headers: { "if-match": `"${options.ifMatch}"` } };
|
|
675
|
+
}
|
|
619
676
|
function withQuery(path, params = {}) {
|
|
620
677
|
const qs = new URLSearchParams();
|
|
621
678
|
for (const [key, value] of Object.entries(params)) {
|
|
@@ -724,7 +781,31 @@ function legacyRest() {
|
|
|
724
781
|
deleteField: fields.delete,
|
|
725
782
|
listRelations: relations.list,
|
|
726
783
|
createRelation: relations.create,
|
|
727
|
-
deleteRelation: relations.delete
|
|
784
|
+
deleteRelation: relations.delete,
|
|
785
|
+
/**
|
|
786
|
+
* Collection form layout (#750): tabs / groups / dividers + conditions.
|
|
787
|
+
* Typed loosely so the SDK stays decoupled from contracts; parse with
|
|
788
|
+
* `parseFormLayout` from `@lumibase/contracts/form-layout`.
|
|
789
|
+
*/
|
|
790
|
+
getFormLayout: (name) => client.rawRequest(
|
|
791
|
+
`/api/v1/collections/${name}/form-layout`
|
|
792
|
+
),
|
|
793
|
+
setFormLayout: (name, layout) => client.rawRequest(
|
|
794
|
+
`/api/v1/collections/${name}/form-layout`,
|
|
795
|
+
{ method: "PUT", body: JSON.stringify({ layout }) }
|
|
796
|
+
),
|
|
797
|
+
/**
|
|
798
|
+
* Expression index advice for filtering on a JSON path (#729). `cast`
|
|
799
|
+
* defaults to the declared type of a top-level field; nested paths
|
|
800
|
+
* must name it. Read-only: the DDL is returned, never executed.
|
|
801
|
+
*/
|
|
802
|
+
indexAdvice: (name, path, cast) => {
|
|
803
|
+
const params = new URLSearchParams({ path });
|
|
804
|
+
if (cast) params.set("cast", cast);
|
|
805
|
+
return client.rawRequest(
|
|
806
|
+
`/api/v1/collections/${encodeURIComponent(name)}/index-advice?${params.toString()}`
|
|
807
|
+
);
|
|
808
|
+
}
|
|
728
809
|
};
|
|
729
810
|
function items(name) {
|
|
730
811
|
function buildQuery(params) {
|
|
@@ -737,6 +818,8 @@ function legacyRest() {
|
|
|
737
818
|
if (params.offset !== void 0)
|
|
738
819
|
qs.set("offset", String(params.offset));
|
|
739
820
|
if (params.status) qs.set("status", params.status);
|
|
821
|
+
if (params.publicationState) qs.set("publicationState", params.publicationState);
|
|
822
|
+
if (params.modifiedSincePublish) qs.set("modifiedSincePublish", "true");
|
|
740
823
|
const s = qs.toString();
|
|
741
824
|
return s ? `?${s}` : "";
|
|
742
825
|
}
|
|
@@ -755,19 +838,90 @@ function legacyRest() {
|
|
|
755
838
|
method: "POST",
|
|
756
839
|
body: JSON.stringify(input)
|
|
757
840
|
}),
|
|
758
|
-
patch: (id, input) => client.rawRequest(`${base}/${id}`, {
|
|
841
|
+
patch: (id, input, options) => client.rawRequest(`${base}/${id}`, {
|
|
759
842
|
method: "PATCH",
|
|
760
|
-
body: JSON.stringify(input)
|
|
843
|
+
body: JSON.stringify(input),
|
|
844
|
+
...ifMatchInit(options)
|
|
761
845
|
}),
|
|
762
|
-
replace: (id, input) => client.rawRequest(`${base}/${id}`, {
|
|
846
|
+
replace: (id, input, options) => client.rawRequest(`${base}/${id}`, {
|
|
763
847
|
method: "PUT",
|
|
848
|
+
...ifMatchInit(options),
|
|
764
849
|
body: JSON.stringify(input)
|
|
765
850
|
}),
|
|
766
851
|
delete: (id) => client.rawRequest(`${base}/${id}`, { method: "DELETE" }),
|
|
852
|
+
/**
|
|
853
|
+
* Stream the collection as CSV or JSON (#727). Resolves with the
|
|
854
|
+
* unread `Response`: pipe `res.body` to a file, or `await res.text()`.
|
|
855
|
+
* Uses the caller's read permission; filters use the list syntax.
|
|
856
|
+
*/
|
|
857
|
+
export: (params = {}) => {
|
|
858
|
+
const qs = new URLSearchParams();
|
|
859
|
+
if (params.format) qs.set("format", params.format);
|
|
860
|
+
if (params.fields?.length) qs.set("fields", params.fields.join(","));
|
|
861
|
+
if (params.locales?.length) qs.set("locales", params.locales.join(","));
|
|
862
|
+
if (params.relations) qs.set("relations", params.relations);
|
|
863
|
+
if (params.filter) qs.set("filter", JSON.stringify(params.filter));
|
|
864
|
+
if (params.sort?.length) qs.set("sort", params.sort.join(","));
|
|
865
|
+
if (params.status) qs.set("status", params.status);
|
|
866
|
+
const s = qs.toString();
|
|
867
|
+
return client.rawFetch(`${base}/export${s ? `?${s}` : ""}`);
|
|
868
|
+
},
|
|
767
869
|
bulk: (op, payload) => client.rawRequest(`${base}/bulk`, {
|
|
768
870
|
method: "POST",
|
|
769
871
|
body: JSON.stringify({ op, items: payload })
|
|
770
872
|
}),
|
|
873
|
+
/**
|
|
874
|
+
* Save-as-copy (#689): a draft copy with unique fields suffixed
|
|
875
|
+
* (`-copy`, `-copy-2`, …). Goes through the normal create path.
|
|
876
|
+
*/
|
|
877
|
+
duplicate: (id, options = {}) => client.rawRequest(`${base}/${encodeURIComponent(id)}/duplicate`, {
|
|
878
|
+
method: "POST",
|
|
879
|
+
body: JSON.stringify(options)
|
|
880
|
+
}),
|
|
881
|
+
/**
|
|
882
|
+
* Manual ordering (#690) on a `meta.manualSort` collection: place `id`
|
|
883
|
+
* right after `after` (null = first) or right before `before`.
|
|
884
|
+
*/
|
|
885
|
+
reorder: (id, target) => client.rawRequest(`${base}/${encodeURIComponent(id)}/reorder`, {
|
|
886
|
+
method: "POST",
|
|
887
|
+
body: JSON.stringify(target)
|
|
888
|
+
}),
|
|
889
|
+
/**
|
|
890
|
+
* Patch without recording a revision (#693) — for autosave and
|
|
891
|
+
* machine writes. Agent-authored writes keep their revision anyway.
|
|
892
|
+
*/
|
|
893
|
+
patchWithoutRevision: (id, input) => client.rawRequest(`${base}/${id}?saveRevision=false`, {
|
|
894
|
+
method: "PATCH",
|
|
895
|
+
body: JSON.stringify(input)
|
|
896
|
+
}),
|
|
897
|
+
/**
|
|
898
|
+
* Hierarchical collections (#749) on a `meta.tree.enabled` collection.
|
|
899
|
+
* Reads apply the caller's row rules; the anchor must be readable.
|
|
900
|
+
*/
|
|
901
|
+
tree: {
|
|
902
|
+
children: (parent, params) => {
|
|
903
|
+
const q = buildQuery(params);
|
|
904
|
+
const sep = q ? "&" : "?";
|
|
905
|
+
return client.rawRequest(
|
|
906
|
+
`${base}${q}${sep}tree=children&parent=${encodeURIComponent(parent ?? "null")}`
|
|
907
|
+
);
|
|
908
|
+
},
|
|
909
|
+
subtree: (parent, params) => {
|
|
910
|
+
const q = buildQuery(params);
|
|
911
|
+
const sep = q ? "&" : "?";
|
|
912
|
+
return client.rawRequest(
|
|
913
|
+
`${base}${q}${sep}tree=subtree&parent=${encodeURIComponent(parent ?? "null")}`
|
|
914
|
+
);
|
|
915
|
+
},
|
|
916
|
+
ancestors: (node) => client.rawRequest(
|
|
917
|
+
`${base}?tree=ancestors&node=${encodeURIComponent(node)}`
|
|
918
|
+
),
|
|
919
|
+
/** Move an item and its subtree; `position` is its 0-based index among the new siblings. */
|
|
920
|
+
move: (id, input) => client.rawRequest(`${base}/${id}/move`, {
|
|
921
|
+
method: "POST",
|
|
922
|
+
body: JSON.stringify(input)
|
|
923
|
+
})
|
|
924
|
+
},
|
|
771
925
|
listRevisions: (id) => client.rawRequest(`${base}/${id}/revisions`),
|
|
772
926
|
revertRevision: (id, revisionId) => client.rawRequest(`${base}/${id}/revert/${revisionId}`, {
|
|
773
927
|
method: "POST"
|
|
@@ -1024,10 +1178,66 @@ function legacyRest() {
|
|
|
1024
1178
|
method: "PATCH",
|
|
1025
1179
|
body: JSON.stringify(patch)
|
|
1026
1180
|
}),
|
|
1027
|
-
delete: (id) => client.rawRequest(`/api/v1/files/folders/${id}`, { method: "DELETE" })
|
|
1181
|
+
delete: (id) => client.rawRequest(`/api/v1/files/folders/${id}`, { method: "DELETE" }),
|
|
1182
|
+
/** Nested folder tree with id paths (`/a/b/`) and name paths (#701). */
|
|
1183
|
+
tree: () => client.rawRequest("/api/v1/files/folders/tree")
|
|
1028
1184
|
};
|
|
1029
1185
|
const files = {
|
|
1030
|
-
|
|
1186
|
+
/**
|
|
1187
|
+
* List / filter the library. Without a query: the first 1000 files,
|
|
1188
|
+
* newest first. `meta` carries `{ total, limit, offset }`.
|
|
1189
|
+
*/
|
|
1190
|
+
list: (query) => {
|
|
1191
|
+
const q = new URLSearchParams();
|
|
1192
|
+
if (query?.folder !== void 0) q.set("folder", query.folder);
|
|
1193
|
+
if (query?.subfolders) q.set("subfolders", "true");
|
|
1194
|
+
if (query?.search) q.set("search", query.search);
|
|
1195
|
+
if (query?.mime?.length) q.set("mime", query.mime.join(","));
|
|
1196
|
+
if (query?.ids?.length) q.set("ids", query.ids.join(","));
|
|
1197
|
+
if (query?.limit !== void 0) q.set("limit", String(query.limit));
|
|
1198
|
+
if (query?.offset !== void 0) q.set("offset", String(query.offset));
|
|
1199
|
+
const qs = q.toString();
|
|
1200
|
+
return client.rawRequest(`/api/v1/files${qs ? `?${qs}` : ""}`);
|
|
1201
|
+
},
|
|
1202
|
+
get: (id) => client.rawRequest(`/api/v1/files/${encodeURIComponent(id)}`),
|
|
1203
|
+
/**
|
|
1204
|
+
* Replace the bytes behind a file in place (#703): same id, key, folder
|
|
1205
|
+
* and references; `version` bumps. Pass `expectedVersion` to refuse
|
|
1206
|
+
* (409) when someone replaced it since you loaded it.
|
|
1207
|
+
*/
|
|
1208
|
+
replaceContent: (id, body, opts) => {
|
|
1209
|
+
const q = opts.filename ? `?filename=${encodeURIComponent(opts.filename)}` : "";
|
|
1210
|
+
const headers = { "content-type": opts.mime };
|
|
1211
|
+
if (opts.expectedVersion !== void 0) headers["if-match"] = `"v${opts.expectedVersion}"`;
|
|
1212
|
+
return client.rawRequest(`/api/v1/files/${encodeURIComponent(id)}/content${q}`, {
|
|
1213
|
+
method: "PUT",
|
|
1214
|
+
body,
|
|
1215
|
+
headers
|
|
1216
|
+
});
|
|
1217
|
+
},
|
|
1218
|
+
/** URL that serves the current bytes; pass `version` for an immutable, cacheable URL. */
|
|
1219
|
+
contentUrl: (id, version) => `${client.url.replace(/\/$/, "")}/api/v1/files/${encodeURIComponent(id)}/content${version !== void 0 ? `?v=${version}` : ""}`,
|
|
1220
|
+
versions: (id) => client.rawRequest(`/api/v1/files/${encodeURIComponent(id)}/versions`),
|
|
1221
|
+
restoreVersion: (id, versionId) => client.rawRequest(
|
|
1222
|
+
`/api/v1/files/${encodeURIComponent(id)}/versions/${encodeURIComponent(versionId)}/restore`,
|
|
1223
|
+
{ method: "POST" }
|
|
1224
|
+
),
|
|
1225
|
+
/** Items and pages that reference the file (#706). */
|
|
1226
|
+
usage: (id) => client.rawRequest(`/api/v1/files/${encodeURIComponent(id)}/usage`),
|
|
1227
|
+
/** Files with the same content hash (lowercase hex SHA-256). */
|
|
1228
|
+
duplicates: (hash) => client.rawRequest(`/api/v1/files/duplicates?hash=${encodeURIComponent(hash)}`),
|
|
1229
|
+
/** Bulk move and/or merge editorial metadata (alt, title, caption, credit, tags). */
|
|
1230
|
+
bulk: (input) => client.rawRequest("/api/v1/files/bulk", {
|
|
1231
|
+
method: "POST",
|
|
1232
|
+
body: JSON.stringify(input)
|
|
1233
|
+
}),
|
|
1234
|
+
settings: {
|
|
1235
|
+
get: () => client.rawRequest("/api/v1/files/settings"),
|
|
1236
|
+
update: (patch) => client.rawRequest("/api/v1/files/settings", {
|
|
1237
|
+
method: "PUT",
|
|
1238
|
+
body: JSON.stringify(patch)
|
|
1239
|
+
})
|
|
1240
|
+
},
|
|
1031
1241
|
create: (input) => client.rawRequest("/api/v1/files", {
|
|
1032
1242
|
method: "POST",
|
|
1033
1243
|
body: JSON.stringify(input)
|
|
@@ -1036,7 +1246,12 @@ function legacyRest() {
|
|
|
1036
1246
|
method: "PATCH",
|
|
1037
1247
|
body: JSON.stringify(patch)
|
|
1038
1248
|
}),
|
|
1039
|
-
|
|
1249
|
+
/**
|
|
1250
|
+
* Safe delete (#706): a referenced file answers 409 `FILE_IN_USE` with the
|
|
1251
|
+
* references in `errors[0].details.usage`; repeat with `{ confirm: true }`
|
|
1252
|
+
* to delete anyway (unless the site's policy is `block`).
|
|
1253
|
+
*/
|
|
1254
|
+
delete: (id, opts) => client.rawRequest(`/api/v1/files/${id}${opts?.confirm ? "?confirm=true" : ""}`, { method: "DELETE" }),
|
|
1040
1255
|
getPresignedUrl: (filename) => client.rawRequest("/api/v1/files/presigned-url", {
|
|
1041
1256
|
method: "POST",
|
|
1042
1257
|
body: JSON.stringify({ filename })
|
|
@@ -1167,6 +1382,23 @@ function legacyRest() {
|
|
|
1167
1382
|
target: { type: "api_key", id }
|
|
1168
1383
|
})
|
|
1169
1384
|
};
|
|
1385
|
+
const preview = {
|
|
1386
|
+
mintToken: (input) => client.rawRequest("/api/v1/preview/token", {
|
|
1387
|
+
method: "POST",
|
|
1388
|
+
body: JSON.stringify(input)
|
|
1389
|
+
}),
|
|
1390
|
+
listTokens: () => client.rawRequest("/api/v1/preview/tokens"),
|
|
1391
|
+
revokeToken: (id) => client.rawRequest(`/api/v1/preview/tokens/${encodeURIComponent(id)}/revoke`, {
|
|
1392
|
+
method: "POST"
|
|
1393
|
+
}),
|
|
1394
|
+
/** Rotation: revoke every live preview token of the site (site admin). */
|
|
1395
|
+
revokeAll: () => client.rawRequest("/api/v1/preview/tokens/revoke-all", { method: "POST" }),
|
|
1396
|
+
getSettings: () => client.rawRequest("/api/v1/preview/settings"),
|
|
1397
|
+
updateSettings: (input) => client.rawRequest("/api/v1/preview/settings", {
|
|
1398
|
+
method: "PUT",
|
|
1399
|
+
body: JSON.stringify(input)
|
|
1400
|
+
})
|
|
1401
|
+
};
|
|
1170
1402
|
const shares = {
|
|
1171
1403
|
create: (input) => client.rawRequest("/api/v1/shares", {
|
|
1172
1404
|
method: "POST",
|
|
@@ -1195,10 +1427,44 @@ function legacyRest() {
|
|
|
1195
1427
|
body: JSON.stringify(patch)
|
|
1196
1428
|
}),
|
|
1197
1429
|
delete: (id) => client.rawRequest(`/api/v1/deployments/targets/${id}`, { method: "DELETE" }),
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1430
|
+
/**
|
|
1431
|
+
* Resolves with the deployment (201), or — when the target belongs to
|
|
1432
|
+
* an approval-gated environment (#743) — with a `pending_approval`
|
|
1433
|
+
* outcome (202).
|
|
1434
|
+
*/
|
|
1435
|
+
deploy: (id, input = {}) => client.rawRequest(
|
|
1436
|
+
`/api/v1/deployments/targets/${id}/deploy`,
|
|
1437
|
+
{
|
|
1438
|
+
method: "POST",
|
|
1439
|
+
body: JSON.stringify(input)
|
|
1440
|
+
}
|
|
1441
|
+
)
|
|
1442
|
+
},
|
|
1443
|
+
// Environments, promotion and deploy approvals (#743).
|
|
1444
|
+
access: () => client.rawRequest("/api/v1/deployments/access"),
|
|
1445
|
+
environments: {
|
|
1446
|
+
list: () => client.rawRequest("/api/v1/deployments/environments"),
|
|
1447
|
+
update: (environments) => client.rawRequest("/api/v1/deployments/environments", {
|
|
1448
|
+
method: "PUT",
|
|
1449
|
+
body: JSON.stringify({ environments })
|
|
1450
|
+
}),
|
|
1451
|
+
deploy: (key, input = {}) => client.rawRequest(
|
|
1452
|
+
`/api/v1/deployments/environments/${encodeURIComponent(key)}/deploy`,
|
|
1453
|
+
{ method: "POST", body: JSON.stringify(input) }
|
|
1454
|
+
),
|
|
1455
|
+
promote: (key, input = {}) => client.rawRequest(
|
|
1456
|
+
`/api/v1/deployments/environments/${encodeURIComponent(key)}/promote`,
|
|
1457
|
+
{ method: "POST", body: JSON.stringify(input) }
|
|
1458
|
+
)
|
|
1459
|
+
},
|
|
1460
|
+
approvals: {
|
|
1461
|
+
list: (status = "pending") => client.rawRequest(
|
|
1462
|
+
`/api/v1/deployments/approvals?status=${encodeURIComponent(status)}`
|
|
1463
|
+
),
|
|
1464
|
+
decide: (id, input) => client.rawRequest(
|
|
1465
|
+
`/api/v1/deployments/approvals/${encodeURIComponent(id)}/decide`,
|
|
1466
|
+
{ method: "POST", body: JSON.stringify(input) }
|
|
1467
|
+
)
|
|
1202
1468
|
},
|
|
1203
1469
|
list: (params) => {
|
|
1204
1470
|
const qs = new URLSearchParams();
|
|
@@ -1211,14 +1477,46 @@ function legacyRest() {
|
|
|
1211
1477
|
logs: (id) => client.rawRequest(`/api/v1/deployments/${id}/logs`),
|
|
1212
1478
|
refresh: (id) => client.rawRequest(`/api/v1/deployments/${id}/refresh`, { method: "POST" })
|
|
1213
1479
|
};
|
|
1480
|
+
const imports = {
|
|
1481
|
+
/**
|
|
1482
|
+
* Upload a CSV or JSON export file and queue it. Resolves with the job
|
|
1483
|
+
* (`202`); poll `get(id)` until `status` is terminal.
|
|
1484
|
+
*/
|
|
1485
|
+
create: (collection, file, opts = {}) => {
|
|
1486
|
+
const qs = new URLSearchParams({ collection });
|
|
1487
|
+
if (opts.format) qs.set("format", opts.format);
|
|
1488
|
+
if (opts.mode) qs.set("mode", opts.mode);
|
|
1489
|
+
const form = new FormData();
|
|
1490
|
+
const blob = typeof file === "string" ? new Blob([file], { type: "application/octet-stream" }) : file;
|
|
1491
|
+
form.append("file", blob, opts.filename ?? `${collection}.${opts.format ?? "csv"}`);
|
|
1492
|
+
return client.rawRequest(`/api/v1/imports?${qs.toString()}`, { method: "POST", body: form });
|
|
1493
|
+
},
|
|
1494
|
+
list: (params = {}) => {
|
|
1495
|
+
const qs = new URLSearchParams();
|
|
1496
|
+
if (params.collection) qs.set("collection", params.collection);
|
|
1497
|
+
if (params.status) qs.set("status", params.status);
|
|
1498
|
+
if (params.limit !== void 0) qs.set("limit", String(params.limit));
|
|
1499
|
+
const s = qs.toString();
|
|
1500
|
+
return client.rawRequest(`/api/v1/imports${s ? `?${s}` : ""}`);
|
|
1501
|
+
},
|
|
1502
|
+
get: (id) => client.rawRequest(`/api/v1/imports/${encodeURIComponent(id)}`),
|
|
1503
|
+
errors: (id) => client.rawRequest(
|
|
1504
|
+
`/api/v1/imports/${encodeURIComponent(id)}/errors`
|
|
1505
|
+
),
|
|
1506
|
+
/** The error report as a CSV download (`row,id,message`). */
|
|
1507
|
+
errorsCsv: (id) => client.rawFetch(`/api/v1/imports/${encodeURIComponent(id)}/errors?format=csv`),
|
|
1508
|
+
cancel: (id) => client.rawRequest(`/api/v1/imports/${encodeURIComponent(id)}/cancel`, { method: "POST" })
|
|
1509
|
+
};
|
|
1214
1510
|
return {
|
|
1215
1511
|
schema,
|
|
1216
1512
|
items,
|
|
1513
|
+
imports,
|
|
1217
1514
|
roles,
|
|
1218
1515
|
policies,
|
|
1219
1516
|
access,
|
|
1220
1517
|
apiKeys,
|
|
1221
1518
|
shares,
|
|
1519
|
+
preview,
|
|
1222
1520
|
me,
|
|
1223
1521
|
permissions,
|
|
1224
1522
|
presets,
|
|
@@ -1514,7 +1812,7 @@ function readItem(collection, id, fields) {
|
|
|
1514
1812
|
const res = await client.rawRequest(
|
|
1515
1813
|
`/api/v1/items/${collection}/${id}${fields?.length ? `?fields=${fields.join(",")}` : ""}`
|
|
1516
1814
|
);
|
|
1517
|
-
return res;
|
|
1815
|
+
return res.data;
|
|
1518
1816
|
};
|
|
1519
1817
|
}
|
|
1520
1818
|
function exportAccessManifest() {
|
|
@@ -1896,6 +2194,583 @@ function graphql(endpoint = "/api/v1/graphql") {
|
|
|
1896
2194
|
};
|
|
1897
2195
|
}
|
|
1898
2196
|
|
|
2197
|
+
// src/typegen/shared.ts
|
|
2198
|
+
var TRANSLATABLE_INTERFACE = "translatable-text";
|
|
2199
|
+
var FILE_INTERFACE = "file";
|
|
2200
|
+
var FILES_INTERFACE = "files";
|
|
2201
|
+
function fieldShape(field) {
|
|
2202
|
+
if (field.kind === "m2o") return { kind: "m2o" };
|
|
2203
|
+
if (field.kind === "o2m" || field.kind === "m2m") {
|
|
2204
|
+
return { kind: "to-many", target: field.target || "unknown" };
|
|
2205
|
+
}
|
|
2206
|
+
if (field.kind === "m2a") return { kind: "m2a" };
|
|
2207
|
+
if (field.interface === TRANSLATABLE_INTERFACE) return { kind: "localized" };
|
|
2208
|
+
if (field.interface === FILES_INTERFACE || field.type === "files") return { kind: "files" };
|
|
2209
|
+
if (field.interface === FILE_INTERFACE) return { kind: "file" };
|
|
2210
|
+
if (field.enum && field.enum.length > 0) return { kind: "enum", values: field.enum };
|
|
2211
|
+
if (field.primaryKey) return { kind: "primary-key" };
|
|
2212
|
+
return { kind: "scalar" };
|
|
2213
|
+
}
|
|
2214
|
+
function isOptional(field) {
|
|
2215
|
+
return !field.required;
|
|
2216
|
+
}
|
|
2217
|
+
function isNullable(field) {
|
|
2218
|
+
return !field.required || field.nullable;
|
|
2219
|
+
}
|
|
2220
|
+
function hasIntegerPrimaryKey(collection) {
|
|
2221
|
+
return collection?.primaryKeyType === "integer" || collection?.primaryKeyType === "bigInteger";
|
|
2222
|
+
}
|
|
2223
|
+
function relationsOf(collection) {
|
|
2224
|
+
return collection.relations ?? [];
|
|
2225
|
+
}
|
|
2226
|
+
function capitalize(str) {
|
|
2227
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
2228
|
+
}
|
|
2229
|
+
var IDENTIFIER = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
|
|
2230
|
+
function propertyKey(name) {
|
|
2231
|
+
return IDENTIFIER.test(name) ? name : JSON.stringify(name);
|
|
2232
|
+
}
|
|
2233
|
+
function filterManifest(manifest, filters) {
|
|
2234
|
+
const { include, exclude } = filters;
|
|
2235
|
+
if (!include?.length && !exclude?.length) return manifest;
|
|
2236
|
+
return {
|
|
2237
|
+
...manifest,
|
|
2238
|
+
collections: manifest.collections.filter(
|
|
2239
|
+
(collection) => (!include?.length || include.includes(collection.name)) && !(exclude?.length && exclude.includes(collection.name))
|
|
2240
|
+
)
|
|
2241
|
+
};
|
|
2242
|
+
}
|
|
2243
|
+
|
|
2244
|
+
// src/typegen/richtext.ts
|
|
2245
|
+
var RICHTEXT_TS_DECLARATIONS = `export type RichTextMark = 'bold' | 'italic' | 'underline' | 'strike' | 'code' | 'superscript' | 'subscript';
|
|
2246
|
+
|
|
2247
|
+
export interface RichTextRef {
|
|
2248
|
+
kind: 'item' | 'file';
|
|
2249
|
+
collection?: string;
|
|
2250
|
+
id: string;
|
|
2251
|
+
}
|
|
2252
|
+
|
|
2253
|
+
export type RichTextInline =
|
|
2254
|
+
| { type: 'text'; text: string; marks?: RichTextMark[] }
|
|
2255
|
+
| { type: 'link'; href: string; content: RichTextInline[] }
|
|
2256
|
+
| { type: 'ref'; ref: RichTextRef; content: RichTextInline[] }
|
|
2257
|
+
| { type: 'embed'; ref: RichTextRef; alt?: string }
|
|
2258
|
+
| { type: 'break' }
|
|
2259
|
+
| { type: 'footnote'; label: string };
|
|
2260
|
+
|
|
2261
|
+
export interface RichTextTableRow {
|
|
2262
|
+
header?: boolean;
|
|
2263
|
+
cells: RichTextBlock[][];
|
|
2264
|
+
}
|
|
2265
|
+
|
|
2266
|
+
export type RichTextBlock =
|
|
2267
|
+
| { type: 'paragraph'; content: RichTextInline[] }
|
|
2268
|
+
| { type: 'heading'; level: 1 | 2 | 3 | 4 | 5 | 6; content: RichTextInline[] }
|
|
2269
|
+
| { type: 'quote'; content: RichTextBlock[] }
|
|
2270
|
+
| { type: 'list'; ordered: boolean; start?: number; items: RichTextBlock[][] }
|
|
2271
|
+
| { type: 'code'; language?: string; text: string }
|
|
2272
|
+
| { type: 'rule' }
|
|
2273
|
+
| { type: 'embed'; ref: RichTextRef; alt?: string }
|
|
2274
|
+
| { type: 'table'; rows: RichTextTableRow[]; caption?: string; headerColumn?: boolean; align?: Array<'left' | 'center' | 'right' | null> }
|
|
2275
|
+
| { type: 'footnote'; label: string; content: RichTextBlock[] }
|
|
2276
|
+
| { type: 'custom'; name: string; data: Record<string, unknown> };
|
|
2277
|
+
|
|
2278
|
+
export interface RichTextDocument {
|
|
2279
|
+
type: 'doc';
|
|
2280
|
+
version: 1;
|
|
2281
|
+
content: RichTextBlock[];
|
|
2282
|
+
}`;
|
|
2283
|
+
var RICHTEXT_ZOD = "z.object({ type: z.literal('doc'), version: z.literal(1), content: z.array(z.record(z.string(), z.unknown())) })";
|
|
2284
|
+
|
|
2285
|
+
// src/typegen/zod.ts
|
|
2286
|
+
var DEFAULT_ZOD_IMPORT = "zod";
|
|
2287
|
+
function generateZod(manifest, options = {}) {
|
|
2288
|
+
const importSource = options.importSource ?? DEFAULT_ZOD_IMPORT;
|
|
2289
|
+
const byName = new Map(manifest.collections.map((collection) => [collection.name, collection]));
|
|
2290
|
+
const blocks = manifest.collections.map((collection) => {
|
|
2291
|
+
const name = capitalize(collection.name);
|
|
2292
|
+
const props = collection.fields.map((field) => ` ${propertyKey(field.name)}: ${fieldValidator(field, collection, byName)},`).join("\n");
|
|
2293
|
+
return [
|
|
2294
|
+
`export const ${name}Schema = z.object({`,
|
|
2295
|
+
props,
|
|
2296
|
+
"});",
|
|
2297
|
+
`export type ${name} = z.infer<typeof ${name}Schema>;`
|
|
2298
|
+
].filter((line) => line !== "").join("\n");
|
|
2299
|
+
});
|
|
2300
|
+
const map = [
|
|
2301
|
+
"export const LumibaseSchemas = {",
|
|
2302
|
+
...manifest.collections.map(
|
|
2303
|
+
(collection) => ` ${propertyKey(collection.name)}: ${capitalize(collection.name)}Schema,`
|
|
2304
|
+
),
|
|
2305
|
+
"} as const;"
|
|
2306
|
+
].join("\n");
|
|
2307
|
+
return [`import { z } from ${JSON.stringify(importSource)};`, ...blocks, map].join("\n\n");
|
|
2308
|
+
}
|
|
2309
|
+
function fieldValidator(field, collection, byName) {
|
|
2310
|
+
const shape = fieldShape(field);
|
|
2311
|
+
let schema;
|
|
2312
|
+
switch (shape.kind) {
|
|
2313
|
+
case "to-many": {
|
|
2314
|
+
const target = byName.get(shape.target);
|
|
2315
|
+
const id = target ? primaryKeyValidator(target) : "z.union([z.string(), z.number()])";
|
|
2316
|
+
return withOptional(field, `z.array(z.union([${id}, z.record(z.string(), z.unknown())]))`);
|
|
2317
|
+
}
|
|
2318
|
+
case "m2a":
|
|
2319
|
+
return withOptional(
|
|
2320
|
+
field,
|
|
2321
|
+
"z.array(z.object({ collection: z.string(), item: z.unknown() }))"
|
|
2322
|
+
);
|
|
2323
|
+
case "localized":
|
|
2324
|
+
schema = "z.record(z.string(), z.string())";
|
|
2325
|
+
break;
|
|
2326
|
+
case "file":
|
|
2327
|
+
schema = "z.string()";
|
|
2328
|
+
break;
|
|
2329
|
+
case "files":
|
|
2330
|
+
schema = "z.array(z.string())";
|
|
2331
|
+
break;
|
|
2332
|
+
case "enum":
|
|
2333
|
+
return wrap(field, `z.enum(${JSON.stringify(shape.values)})`);
|
|
2334
|
+
case "primary-key":
|
|
2335
|
+
return wrap(field, primaryKeyValidator(collection));
|
|
2336
|
+
case "m2o":
|
|
2337
|
+
return wrap(field, scalarValidator(field.type));
|
|
2338
|
+
case "scalar":
|
|
2339
|
+
schema = scalarValidator(field.type);
|
|
2340
|
+
break;
|
|
2341
|
+
}
|
|
2342
|
+
if (field.encrypted) schema = `z.union([${schema}, z.literal('***')])`;
|
|
2343
|
+
return wrap(field, schema);
|
|
2344
|
+
}
|
|
2345
|
+
function primaryKeyValidator(collection) {
|
|
2346
|
+
const type = collection.primaryKeyType ?? "nanoid";
|
|
2347
|
+
return type === "integer" || type === "bigInteger" ? "z.number().int()" : "z.string()";
|
|
2348
|
+
}
|
|
2349
|
+
function scalarValidator(type) {
|
|
2350
|
+
switch (type) {
|
|
2351
|
+
case "string":
|
|
2352
|
+
case "text":
|
|
2353
|
+
case "hash":
|
|
2354
|
+
case "csv":
|
|
2355
|
+
case "uuid":
|
|
2356
|
+
case "date":
|
|
2357
|
+
case "datetime":
|
|
2358
|
+
case "dateTime":
|
|
2359
|
+
case "time":
|
|
2360
|
+
case "timestamp":
|
|
2361
|
+
return "z.string()";
|
|
2362
|
+
case "integer":
|
|
2363
|
+
return "z.number().int()";
|
|
2364
|
+
case "bigInteger":
|
|
2365
|
+
case "decimal":
|
|
2366
|
+
case "float":
|
|
2367
|
+
return "z.number()";
|
|
2368
|
+
case "boolean":
|
|
2369
|
+
return "z.boolean()";
|
|
2370
|
+
case "geometry":
|
|
2371
|
+
return "z.record(z.string(), z.unknown())";
|
|
2372
|
+
case "richtext":
|
|
2373
|
+
return RICHTEXT_ZOD;
|
|
2374
|
+
default:
|
|
2375
|
+
return "z.unknown()";
|
|
2376
|
+
}
|
|
2377
|
+
}
|
|
2378
|
+
function wrap(field, schema) {
|
|
2379
|
+
return withOptional(field, isNullable(field) ? `${schema}.nullable()` : schema);
|
|
2380
|
+
}
|
|
2381
|
+
function withOptional(field, schema) {
|
|
2382
|
+
return isOptional(field) ? `${schema}.optional()` : schema;
|
|
2383
|
+
}
|
|
2384
|
+
|
|
2385
|
+
// src/typegen/graphql-sdl.ts
|
|
2386
|
+
function generateGraphQLSdl(manifest) {
|
|
2387
|
+
const collections = manifest.collections.filter((collection) => GRAPHQL_NAME.test(collection.name));
|
|
2388
|
+
const typeNames = new Map(collections.map((collection) => [collection.name, pascalCase(collection.name)]));
|
|
2389
|
+
const blocks = ["scalar JSON", "scalar DateTime"];
|
|
2390
|
+
for (const collection of collections) {
|
|
2391
|
+
blocks.push(objectType(typeNames.get(collection.name), itemFields(collection, typeNames)));
|
|
2392
|
+
}
|
|
2393
|
+
if (collections.some((c) => c.fields.some((f) => !f.system && f.type === "richtext" && !RESERVED.has(f.name) && GRAPHQL_NAME.test(f.name)))) {
|
|
2394
|
+
blocks.push(objectType("RichText", ["json: JSON", "html: String", "markdown: String", "text: String"]));
|
|
2395
|
+
}
|
|
2396
|
+
const query = ["_collections: [String!]!"];
|
|
2397
|
+
const mutation = [];
|
|
2398
|
+
const subscription = [];
|
|
2399
|
+
for (const collection of collections) {
|
|
2400
|
+
const name = collection.name;
|
|
2401
|
+
const type = typeNames.get(name);
|
|
2402
|
+
query.push(
|
|
2403
|
+
`${name}(filter: JSON, sort: [String!], limit: Int, offset: Int, status: String, publicationState: PublicationState, modifiedSincePublish: Boolean): [${type}!]!`,
|
|
2404
|
+
`${name}_by_id(id: ID!, publicationState: PublicationState): ${type}`
|
|
2405
|
+
);
|
|
2406
|
+
mutation.push(
|
|
2407
|
+
`create_${name}(data: JSON!, status: String, sort: Int): ${type}!`,
|
|
2408
|
+
`update_${name}(id: ID!, data: JSON, status: String, sort: Int): ${type}!`,
|
|
2409
|
+
`delete_${name}(id: ID!): Boolean!`
|
|
2410
|
+
);
|
|
2411
|
+
subscription.push(`${name}_events: ItemEvent!`);
|
|
2412
|
+
}
|
|
2413
|
+
blocks.push(objectType("Query", query));
|
|
2414
|
+
if (collections.length > 0) blocks.push("enum PublicationState {\n live\n preview\n all\n}");
|
|
2415
|
+
if (mutation.length > 0) blocks.push(objectType("Mutation", mutation));
|
|
2416
|
+
if (subscription.length > 0) {
|
|
2417
|
+
blocks.push(objectType("Subscription", subscription));
|
|
2418
|
+
blocks.push(
|
|
2419
|
+
objectType("ItemEvent", [
|
|
2420
|
+
"collection: String!",
|
|
2421
|
+
"action: String!",
|
|
2422
|
+
"itemId: ID!",
|
|
2423
|
+
"item: JSON"
|
|
2424
|
+
])
|
|
2425
|
+
);
|
|
2426
|
+
}
|
|
2427
|
+
return `${blocks.join("\n\n")}
|
|
2428
|
+
`;
|
|
2429
|
+
}
|
|
2430
|
+
var STRUCTURAL = [
|
|
2431
|
+
["id", "ID!"],
|
|
2432
|
+
["status", "String"],
|
|
2433
|
+
["sort", "Int"],
|
|
2434
|
+
["createdAt", "DateTime"],
|
|
2435
|
+
["updatedAt", "DateTime"],
|
|
2436
|
+
["userCreated", "String"],
|
|
2437
|
+
["userUpdated", "String"],
|
|
2438
|
+
["_data", "JSON"],
|
|
2439
|
+
// Publication state (#687), underscored so a content field keeps its name.
|
|
2440
|
+
["_firstPublishedAt", "DateTime"],
|
|
2441
|
+
["_publishedAt", "DateTime"],
|
|
2442
|
+
["_hasUnpublishedChanges", "Boolean"]
|
|
2443
|
+
];
|
|
2444
|
+
var RESERVED = /* @__PURE__ */ new Set([
|
|
2445
|
+
"id",
|
|
2446
|
+
"status",
|
|
2447
|
+
"sort",
|
|
2448
|
+
"createdAt",
|
|
2449
|
+
"updatedAt",
|
|
2450
|
+
"userCreated",
|
|
2451
|
+
"userUpdated",
|
|
2452
|
+
"created_at",
|
|
2453
|
+
"updated_at",
|
|
2454
|
+
"user_created",
|
|
2455
|
+
"user_updated",
|
|
2456
|
+
"_data",
|
|
2457
|
+
"_firstPublishedAt",
|
|
2458
|
+
"_publishedAt",
|
|
2459
|
+
"_hasUnpublishedChanges"
|
|
2460
|
+
]);
|
|
2461
|
+
var GRAPHQL_NAME = /^[_A-Za-z][_0-9A-Za-z]*$/;
|
|
2462
|
+
function itemFields(collection, typeNames) {
|
|
2463
|
+
const fields = new Map(STRUCTURAL);
|
|
2464
|
+
for (const field of collection.fields) {
|
|
2465
|
+
if (field.system || RESERVED.has(field.name) || !GRAPHQL_NAME.test(field.name)) continue;
|
|
2466
|
+
fields.set(field.name, scalarFor(field.type));
|
|
2467
|
+
}
|
|
2468
|
+
for (const relation of relationsOf(collection)) {
|
|
2469
|
+
const nested = relationField(collection, relation, typeNames);
|
|
2470
|
+
if (!nested || !GRAPHQL_NAME.test(nested.name) || fields.has(nested.name)) continue;
|
|
2471
|
+
fields.set(nested.name, nested.args ? `${nested.args}: ${nested.type}` : nested.type);
|
|
2472
|
+
}
|
|
2473
|
+
return [...fields].map(([name, type]) => type.startsWith("(") ? `${name}${type}` : `${name}: ${type}`);
|
|
2474
|
+
}
|
|
2475
|
+
function relationField(collection, relation, typeNames) {
|
|
2476
|
+
const many = relation.manyCollection ?? (relation.kind === "m2o" ? collection.name : relation.target);
|
|
2477
|
+
const one = relation.oneCollection ?? (relation.kind === "m2o" ? relation.target : collection.name);
|
|
2478
|
+
const stored = relation.relationType ?? (many === collection.name ? relation.kind : void 0);
|
|
2479
|
+
if (stored === "m2o" && many === collection.name) {
|
|
2480
|
+
const target = typeNames.get(one);
|
|
2481
|
+
return target ? { name: relation.alias ?? m2oAlias(relation, one), type: target } : null;
|
|
2482
|
+
}
|
|
2483
|
+
if (stored === "o2m" && one === collection.name) {
|
|
2484
|
+
const target = typeNames.get(many);
|
|
2485
|
+
return target ? { name: relation.alias ?? many, args: "(limit: Int, offset: Int)", type: `[${target}!]!` } : null;
|
|
2486
|
+
}
|
|
2487
|
+
return null;
|
|
2488
|
+
}
|
|
2489
|
+
function m2oAlias(relation, oneCollection) {
|
|
2490
|
+
const manyField = relation.manyField ?? relation.field;
|
|
2491
|
+
return manyField.endsWith("_id") ? manyField.slice(0, -3) : oneCollection;
|
|
2492
|
+
}
|
|
2493
|
+
function scalarFor(type) {
|
|
2494
|
+
switch (type) {
|
|
2495
|
+
case "boolean":
|
|
2496
|
+
return "Boolean";
|
|
2497
|
+
case "integer":
|
|
2498
|
+
return "Int";
|
|
2499
|
+
case "float":
|
|
2500
|
+
case "decimal":
|
|
2501
|
+
return "Float";
|
|
2502
|
+
case "bigInteger":
|
|
2503
|
+
return "String";
|
|
2504
|
+
// `datetime` is the canonical FieldType spelling; `dateTime` is legacy (#865).
|
|
2505
|
+
case "datetime":
|
|
2506
|
+
case "dateTime":
|
|
2507
|
+
case "date":
|
|
2508
|
+
case "time":
|
|
2509
|
+
case "timestamp":
|
|
2510
|
+
return "DateTime";
|
|
2511
|
+
case "richtext":
|
|
2512
|
+
return "RichText";
|
|
2513
|
+
case "json":
|
|
2514
|
+
case "csv":
|
|
2515
|
+
case "geometry":
|
|
2516
|
+
case "files":
|
|
2517
|
+
case "m2o":
|
|
2518
|
+
case "o2m":
|
|
2519
|
+
case "m2m":
|
|
2520
|
+
case "m2a":
|
|
2521
|
+
return "JSON";
|
|
2522
|
+
default:
|
|
2523
|
+
return "String";
|
|
2524
|
+
}
|
|
2525
|
+
}
|
|
2526
|
+
function pascalCase(name) {
|
|
2527
|
+
return name.split("_").filter(Boolean).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
|
|
2528
|
+
}
|
|
2529
|
+
function objectType(name, fields) {
|
|
2530
|
+
return `type ${name} {
|
|
2531
|
+
${fields.map((field) => ` ${field}`).join("\n")}
|
|
2532
|
+
}`;
|
|
2533
|
+
}
|
|
2534
|
+
|
|
2535
|
+
// src/typegen/openapi.ts
|
|
2536
|
+
function generateOpenApi(manifest, options = {}) {
|
|
2537
|
+
const byName = new Map(manifest.collections.map((collection) => [collection.name, collection]));
|
|
2538
|
+
const bases = /* @__PURE__ */ new Map();
|
|
2539
|
+
const taken = /* @__PURE__ */ new Set();
|
|
2540
|
+
for (const collection of manifest.collections) {
|
|
2541
|
+
const raw = collection.name.replace(/[^a-zA-Z0-9._-]/g, "_");
|
|
2542
|
+
let base = raw;
|
|
2543
|
+
for (let n = 2; taken.has(base); n += 1) base = `${raw}_${n}`;
|
|
2544
|
+
taken.add(base);
|
|
2545
|
+
bases.set(collection.name, base);
|
|
2546
|
+
}
|
|
2547
|
+
const ctx = {
|
|
2548
|
+
primaryKeySchema: (name) => hasIntegerPrimaryKey(byName.get(name)) ? { type: "integer" } : { type: "string" },
|
|
2549
|
+
projectionRef: (name) => {
|
|
2550
|
+
const base = bases.get(name);
|
|
2551
|
+
return base ? `#/components/schemas/${base}.Projection` : null;
|
|
2552
|
+
}
|
|
2553
|
+
};
|
|
2554
|
+
const schemas = {
|
|
2555
|
+
ErrorObject: {
|
|
2556
|
+
type: "object",
|
|
2557
|
+
properties: { code: { type: "string" }, message: { type: "string" } },
|
|
2558
|
+
required: ["code"]
|
|
2559
|
+
},
|
|
2560
|
+
ErrorResponse: {
|
|
2561
|
+
type: "object",
|
|
2562
|
+
properties: { errors: { type: "array", items: { $ref: "#/components/schemas/ErrorObject" } } },
|
|
2563
|
+
required: ["errors"]
|
|
2564
|
+
},
|
|
2565
|
+
PaginationMeta: {
|
|
2566
|
+
type: "object",
|
|
2567
|
+
properties: {
|
|
2568
|
+
total: { type: "integer", minimum: 0, description: "Omitted when the request passed `meta=none`." },
|
|
2569
|
+
limit: { type: "integer", minimum: 1, maximum: 200 },
|
|
2570
|
+
offset: { type: "integer", minimum: 0 }
|
|
2571
|
+
},
|
|
2572
|
+
required: ["limit", "offset"]
|
|
2573
|
+
}
|
|
2574
|
+
};
|
|
2575
|
+
for (const collection of manifest.collections) {
|
|
2576
|
+
addCollectionSchemas(schemas, collection, bases.get(collection.name), ctx);
|
|
2577
|
+
}
|
|
2578
|
+
return {
|
|
2579
|
+
openapi: "3.1.0",
|
|
2580
|
+
info: {
|
|
2581
|
+
title: options.title ?? "LumiBase content schemas",
|
|
2582
|
+
version: options.version ?? `manifest-v${manifest.version}`,
|
|
2583
|
+
description: "Component schemas generated by `lumibase types` from the typegen manifest. For paths and a per-caller view, use the live document at /api/v1/openapi.json."
|
|
2584
|
+
},
|
|
2585
|
+
components: { schemas }
|
|
2586
|
+
};
|
|
2587
|
+
}
|
|
2588
|
+
var timestamp = { type: "string", format: "date-time" };
|
|
2589
|
+
var nullableTimestamp = { type: ["string", "null"], format: "date-time" };
|
|
2590
|
+
var nullableString = { type: ["string", "null"] };
|
|
2591
|
+
var expandedObject = {
|
|
2592
|
+
type: "object",
|
|
2593
|
+
description: "Expanded record (requested with `fields=<name>.*`)."
|
|
2594
|
+
};
|
|
2595
|
+
var fileId = { type: "string", description: "File id (`/api/v1/files/{id}`)." };
|
|
2596
|
+
var FIELD_TYPE_JSON_SCHEMA = {
|
|
2597
|
+
string: { type: "string" },
|
|
2598
|
+
text: { type: "string" },
|
|
2599
|
+
hash: { type: "string" },
|
|
2600
|
+
csv: { type: "string" },
|
|
2601
|
+
integer: { type: "integer" },
|
|
2602
|
+
bigInteger: { type: "integer", format: "int64" },
|
|
2603
|
+
decimal: { type: "number" },
|
|
2604
|
+
float: { type: "number" },
|
|
2605
|
+
boolean: { type: "boolean" },
|
|
2606
|
+
json: {},
|
|
2607
|
+
uuid: { type: "string", format: "uuid" },
|
|
2608
|
+
date: { type: "string", format: "date" },
|
|
2609
|
+
datetime: { type: "string", format: "date-time" },
|
|
2610
|
+
dateTime: { type: "string", format: "date-time" },
|
|
2611
|
+
time: { type: "string", format: "time" },
|
|
2612
|
+
timestamp: { type: "string", format: "date-time" },
|
|
2613
|
+
geometry: { type: "object", additionalProperties: true, description: "GeoJSON geometry object." },
|
|
2614
|
+
richtext: {
|
|
2615
|
+
type: "object",
|
|
2616
|
+
required: ["type", "version", "content"],
|
|
2617
|
+
properties: {
|
|
2618
|
+
type: { type: "string", enum: ["doc"] },
|
|
2619
|
+
version: { type: "integer", enum: [1] },
|
|
2620
|
+
content: { type: "array", items: { type: "object", additionalProperties: true } }
|
|
2621
|
+
},
|
|
2622
|
+
description: "Portable rich-text document (see the RichTextDocument type)."
|
|
2623
|
+
}
|
|
2624
|
+
};
|
|
2625
|
+
function withNull(schema) {
|
|
2626
|
+
if (Object.keys(schema).length === 0) return schema;
|
|
2627
|
+
const type = schema["type"];
|
|
2628
|
+
if (typeof type === "string" && !("enum" in schema)) return { ...schema, type: [type, "null"] };
|
|
2629
|
+
if (typeof type === "string" && Array.isArray(schema["enum"])) {
|
|
2630
|
+
return { ...schema, type: [type, "null"], enum: [...schema["enum"], null] };
|
|
2631
|
+
}
|
|
2632
|
+
return { anyOf: [schema, { type: "null" }] };
|
|
2633
|
+
}
|
|
2634
|
+
function referenceOrId(target, ctx, shape) {
|
|
2635
|
+
const id = ctx.primaryKeySchema(target);
|
|
2636
|
+
if (shape !== "projection") return id;
|
|
2637
|
+
const ref = ctx.projectionRef(target);
|
|
2638
|
+
return ref ? { anyOf: [id, { $ref: ref }] } : { anyOf: [id, expandedObject] };
|
|
2639
|
+
}
|
|
2640
|
+
function fieldSchema(field, collection, ctx, shape) {
|
|
2641
|
+
const relation = relationsOf(collection).find((candidate) => candidate.field === field.name);
|
|
2642
|
+
const kind = fieldShape(field);
|
|
2643
|
+
let schema;
|
|
2644
|
+
if (field.kind === "m2o" && field.target) {
|
|
2645
|
+
schema = referenceOrId(field.target, ctx, shape);
|
|
2646
|
+
} else if (kind.kind === "to-many" || relation && (relation.kind === "o2m" || relation.kind === "m2m")) {
|
|
2647
|
+
const target = kind.kind === "to-many" ? kind.target : relation?.target;
|
|
2648
|
+
schema = { type: "array", items: referenceOrId(target, ctx, shape) };
|
|
2649
|
+
} else if (kind.kind === "m2a" || relation?.kind === "m2a") {
|
|
2650
|
+
schema = {
|
|
2651
|
+
type: "array",
|
|
2652
|
+
items: {
|
|
2653
|
+
type: "object",
|
|
2654
|
+
properties: { collection: { type: "string" }, item: {} },
|
|
2655
|
+
required: ["collection", "item"]
|
|
2656
|
+
}
|
|
2657
|
+
};
|
|
2658
|
+
} else if (kind.kind === "localized") {
|
|
2659
|
+
schema = {
|
|
2660
|
+
type: "object",
|
|
2661
|
+
description: 'Per-locale values keyed by locale code (e.g. `{ "en": "\u2026", "vi": "\u2026" }`).',
|
|
2662
|
+
additionalProperties: { type: "string" }
|
|
2663
|
+
};
|
|
2664
|
+
} else if (kind.kind === "file") {
|
|
2665
|
+
schema = shape === "projection" ? { anyOf: [fileId, expandedObject] } : fileId;
|
|
2666
|
+
} else if (kind.kind === "files") {
|
|
2667
|
+
schema = { type: "array", items: shape === "projection" ? { anyOf: [fileId, expandedObject] } : fileId };
|
|
2668
|
+
} else if (field.type === "alias") {
|
|
2669
|
+
return null;
|
|
2670
|
+
} else if (kind.kind === "enum") {
|
|
2671
|
+
schema = { type: "string", enum: [...new Set(kind.values)] };
|
|
2672
|
+
} else {
|
|
2673
|
+
schema = { ...FIELD_TYPE_JSON_SCHEMA[field.type] ?? {} };
|
|
2674
|
+
}
|
|
2675
|
+
if (field.encrypted && shape !== "input") {
|
|
2676
|
+
schema = { anyOf: [schema, { const: "***", description: "Masked: caller lacks `read_decrypted`." }] };
|
|
2677
|
+
}
|
|
2678
|
+
if (isNullable(field)) schema = withNull(schema);
|
|
2679
|
+
if (field.readonly && shape !== "input") schema = { ...schema, readOnly: true };
|
|
2680
|
+
return schema;
|
|
2681
|
+
}
|
|
2682
|
+
function addCollectionSchemas(schemas, collection, base, ctx) {
|
|
2683
|
+
const userFields = collection.fields.filter((field) => !field.system);
|
|
2684
|
+
const ref = (suffix) => ({ $ref: `#/components/schemas/${base}.${suffix}` });
|
|
2685
|
+
const fieldProps = {};
|
|
2686
|
+
const projectionProps = {
|
|
2687
|
+
id: { ...ctx.primaryKeySchema(collection.name), readOnly: true },
|
|
2688
|
+
status: { type: "string" },
|
|
2689
|
+
sort: { type: "integer" },
|
|
2690
|
+
user_created: nullableString,
|
|
2691
|
+
user_updated: nullableString,
|
|
2692
|
+
created_at: timestamp,
|
|
2693
|
+
updated_at: timestamp
|
|
2694
|
+
};
|
|
2695
|
+
const required = [];
|
|
2696
|
+
for (const field of userFields) {
|
|
2697
|
+
const item = fieldSchema(field, collection, ctx, "item");
|
|
2698
|
+
const projection = fieldSchema(field, collection, ctx, "projection");
|
|
2699
|
+
if (item) {
|
|
2700
|
+
fieldProps[field.name] = item;
|
|
2701
|
+
if (field.required) required.push(field.name);
|
|
2702
|
+
}
|
|
2703
|
+
if (projection) projectionProps[field.name] = projection;
|
|
2704
|
+
}
|
|
2705
|
+
schemas[`${base}.Fields`] = {
|
|
2706
|
+
type: "object",
|
|
2707
|
+
description: `User fields of \`${collection.name}\`.`,
|
|
2708
|
+
properties: fieldProps,
|
|
2709
|
+
...required.length > 0 ? { required } : {}
|
|
2710
|
+
};
|
|
2711
|
+
schemas[`${base}.Item`] = {
|
|
2712
|
+
type: "object",
|
|
2713
|
+
properties: {
|
|
2714
|
+
id: { ...ctx.primaryKeySchema(collection.name), readOnly: true },
|
|
2715
|
+
status: { type: "string", description: "`draft`, `published`, `archived`, or a custom workflow value." },
|
|
2716
|
+
sort: { type: "integer" },
|
|
2717
|
+
data: ref("Fields"),
|
|
2718
|
+
publishAt: nullableTimestamp,
|
|
2719
|
+
unpublishAt: nullableTimestamp,
|
|
2720
|
+
userCreated: nullableString,
|
|
2721
|
+
userUpdated: nullableString,
|
|
2722
|
+
createdAt: { ...timestamp, readOnly: true },
|
|
2723
|
+
updatedAt: { ...timestamp, readOnly: true }
|
|
2724
|
+
},
|
|
2725
|
+
required: ["id", "status", "data"]
|
|
2726
|
+
};
|
|
2727
|
+
schemas[`${base}.Projection`] = {
|
|
2728
|
+
type: "object",
|
|
2729
|
+
description: "Flat shape returned when the request passes `fields=`; only requested keys are present.",
|
|
2730
|
+
properties: projectionProps
|
|
2731
|
+
};
|
|
2732
|
+
const inputSchema = (withRequired) => {
|
|
2733
|
+
const props = {};
|
|
2734
|
+
const req = [];
|
|
2735
|
+
for (const field of userFields) {
|
|
2736
|
+
if (field.readonly || field.generated) continue;
|
|
2737
|
+
const schema = fieldSchema(field, collection, ctx, "input");
|
|
2738
|
+
if (!schema) continue;
|
|
2739
|
+
props[field.name] = schema;
|
|
2740
|
+
if (withRequired && field.required) req.push(field.name);
|
|
2741
|
+
}
|
|
2742
|
+
return {
|
|
2743
|
+
type: "object",
|
|
2744
|
+
properties: {
|
|
2745
|
+
data: { type: "object", properties: props, ...req.length > 0 ? { required: req } : {} },
|
|
2746
|
+
status: { type: "string" },
|
|
2747
|
+
sort: { type: "integer" },
|
|
2748
|
+
publishAt: nullableTimestamp,
|
|
2749
|
+
unpublishAt: nullableTimestamp
|
|
2750
|
+
},
|
|
2751
|
+
...withRequired ? { required: ["data"] } : {}
|
|
2752
|
+
};
|
|
2753
|
+
};
|
|
2754
|
+
schemas[`${base}.CreateInput`] = inputSchema(true);
|
|
2755
|
+
schemas[`${base}.UpdateInput`] = inputSchema(false);
|
|
2756
|
+
const itemOrProjection = { anyOf: [ref("Item"), ref("Projection")] };
|
|
2757
|
+
schemas[`${base}.Response`] = {
|
|
2758
|
+
type: "object",
|
|
2759
|
+
description: "Single-item envelope.",
|
|
2760
|
+
properties: { data: itemOrProjection },
|
|
2761
|
+
required: ["data"]
|
|
2762
|
+
};
|
|
2763
|
+
schemas[`${base}.ListResponse`] = {
|
|
2764
|
+
type: "object",
|
|
2765
|
+
description: "A page of items.",
|
|
2766
|
+
properties: {
|
|
2767
|
+
data: { type: "array", items: itemOrProjection },
|
|
2768
|
+
meta: { $ref: "#/components/schemas/PaginationMeta" }
|
|
2769
|
+
},
|
|
2770
|
+
required: ["data"]
|
|
2771
|
+
};
|
|
2772
|
+
}
|
|
2773
|
+
|
|
1899
2774
|
// src/typegen/index.ts
|
|
1900
2775
|
var DEFAULT_IMPORT_SOURCE = "@lumibase/sdk";
|
|
1901
2776
|
function generateTypes(manifest, options = {}) {
|
|
@@ -1906,71 +2781,112 @@ function generateTypes(manifest, options = {}) {
|
|
|
1906
2781
|
return generatePerCollection(manifest, branded, importSource);
|
|
1907
2782
|
}
|
|
1908
2783
|
function generateSingleFile(manifest, branded, importSource) {
|
|
2784
|
+
const known = new Set(manifest.collections.map((c) => c.name));
|
|
1909
2785
|
const imports = [
|
|
1910
2786
|
`import type { ID, Locale } from '${importSource}';`,
|
|
1911
2787
|
branded ? `import type { Brand } from '${importSource}';` : ""
|
|
1912
2788
|
].filter(Boolean).join("\n");
|
|
1913
2789
|
const collectionInterfaces = manifest.collections.map((coll) => {
|
|
1914
|
-
const base = generateCollectionInterface(coll, branded);
|
|
2790
|
+
const base = generateCollectionInterface(coll, branded, known);
|
|
1915
2791
|
const expanded = generateExpandedType(coll);
|
|
1916
2792
|
return [base, expanded].filter(Boolean).join("\n\n");
|
|
1917
2793
|
}).join("\n\n");
|
|
2794
|
+
const blockTypes = generateBlockTypes(manifest, branded, known);
|
|
2795
|
+
const richText = manifest.collections.some((c) => c.fields.some((f) => f.type === "richtext")) ? RICHTEXT_TS_DECLARATIONS : "";
|
|
1918
2796
|
const collectionsMap = `export interface LumibaseCollections {
|
|
1919
|
-
${manifest.collections.map((c) => ` ${c.name}: ${
|
|
2797
|
+
${manifest.collections.map((c) => ` ${c.name}: ${capitalize2(c.name)};`).join("\n")}
|
|
1920
2798
|
}`;
|
|
1921
2799
|
const schemaType = "export type LumibaseSchema = LumibaseCollections;";
|
|
2800
|
+
const body = [richText, collectionInterfaces, blockTypes, collectionsMap, schemaType].filter(Boolean).join("\n\n");
|
|
1922
2801
|
return `${imports}
|
|
1923
2802
|
|
|
1924
|
-
${
|
|
1925
|
-
|
|
1926
|
-
${collectionsMap}
|
|
1927
|
-
|
|
1928
|
-
${schemaType}`;
|
|
2803
|
+
${body}`;
|
|
1929
2804
|
}
|
|
1930
2805
|
function generatePerCollection(manifest, branded, importSource) {
|
|
1931
2806
|
return generateSingleFile(manifest, branded, importSource);
|
|
1932
2807
|
}
|
|
1933
|
-
function generateCollectionInterface(coll, branded) {
|
|
2808
|
+
function generateCollectionInterface(coll, branded, known) {
|
|
1934
2809
|
const fields = coll.fields.map((f) => {
|
|
1935
|
-
const tsType = mapFieldTypeToTs(f, coll, branded);
|
|
2810
|
+
const tsType = mapFieldTypeToTs(f, coll, branded, known);
|
|
1936
2811
|
const optional = f.required ? "" : "?";
|
|
1937
2812
|
const readonly = f.readonly || f.generated ? "readonly " : "";
|
|
1938
2813
|
return ` ${readonly}${f.name}${optional}: ${tsType};`;
|
|
1939
2814
|
}).join("\n");
|
|
1940
|
-
return `export interface ${
|
|
2815
|
+
return `export interface ${capitalize2(coll.name)} {
|
|
1941
2816
|
${fields}
|
|
1942
2817
|
}`;
|
|
1943
2818
|
}
|
|
1944
2819
|
function generateExpandedType(coll) {
|
|
1945
2820
|
const relations = coll.relations ?? [];
|
|
1946
2821
|
if (relations.length === 0) {
|
|
1947
|
-
return `export type ${
|
|
2822
|
+
return `export type ${capitalize2(coll.name)}Expanded = ${capitalize2(coll.name)};`;
|
|
1948
2823
|
}
|
|
1949
2824
|
const omittedKeys = relations.map((relation) => quoteProperty(relation.field)).join(" | ");
|
|
1950
2825
|
const fields = relations.map((relation) => ` ${relation.field}?: ${expandedRelationType(relation)};`).join("\n");
|
|
1951
|
-
return `export type ${
|
|
2826
|
+
return `export type ${capitalize2(coll.name)}Expanded = Omit<${capitalize2(coll.name)}, ${omittedKeys}> & {
|
|
1952
2827
|
${fields}
|
|
1953
2828
|
};`;
|
|
1954
2829
|
}
|
|
1955
2830
|
function expandedRelationType(relation) {
|
|
1956
2831
|
if (relation.kind === "m2o") {
|
|
1957
|
-
return `${
|
|
2832
|
+
return `${capitalize2(relation.target)} | ${capitalize2(relation.target)}Expanded | null`;
|
|
1958
2833
|
}
|
|
1959
2834
|
if (relation.kind === "o2m" || relation.kind === "m2m") {
|
|
1960
|
-
return `Array<${
|
|
2835
|
+
return `Array<${capitalize2(relation.target)} | ${capitalize2(relation.target)}Expanded>`;
|
|
1961
2836
|
}
|
|
1962
2837
|
return `Array<{ collection: string; item: unknown }>`;
|
|
1963
2838
|
}
|
|
1964
|
-
function
|
|
2839
|
+
function generateBlockTypes(manifest, branded, known) {
|
|
2840
|
+
const byName = new Map(manifest.collections.map((c) => [c.name, c]));
|
|
2841
|
+
const referenced = /* @__PURE__ */ new Set();
|
|
2842
|
+
for (const coll of manifest.collections) {
|
|
2843
|
+
for (const f of coll.fields) {
|
|
2844
|
+
if (f.type === "blocks") for (const t of f.allowedBlocks ?? []) referenced.add(t);
|
|
2845
|
+
}
|
|
2846
|
+
}
|
|
2847
|
+
return [...referenced].filter((name) => byName.has(name)).sort().map((name) => {
|
|
2848
|
+
const coll = byName.get(name);
|
|
2849
|
+
const dataFields = coll.fields.filter((f) => !f.system && !f.primaryKey).map((f) => {
|
|
2850
|
+
const optional = f.required ? "" : "?";
|
|
2851
|
+
return ` ${f.name}${optional}: ${mapFieldTypeToTs(f, coll, branded, known)};`;
|
|
2852
|
+
}).join("\n");
|
|
2853
|
+
const t = capitalize2(name);
|
|
2854
|
+
return `export interface ${t}BlockData {
|
|
2855
|
+
${dataFields}
|
|
2856
|
+
}
|
|
2857
|
+
|
|
2858
|
+
export interface ${t}Block {
|
|
2859
|
+
id: string;
|
|
2860
|
+
type: ${JSON.stringify(name)};
|
|
2861
|
+
data: ${t}BlockData;
|
|
2862
|
+
}`;
|
|
2863
|
+
}).join("\n\n");
|
|
2864
|
+
}
|
|
2865
|
+
function blocksUnionType(field, isKnown) {
|
|
2866
|
+
const members = (field.allowedBlocks ?? []).map(
|
|
2867
|
+
(name) => isKnown(name) ? `${capitalize2(name)}Block` : `{ id: string; type: ${JSON.stringify(name)}; data: Record<string, unknown> }`
|
|
2868
|
+
);
|
|
2869
|
+
if (members.length === 0) return "Array<{ id: string; type: string; data: Record<string, unknown> }>";
|
|
2870
|
+
return `Array<${members.join(" | ")}>`;
|
|
2871
|
+
}
|
|
2872
|
+
function mapFieldTypeToTs(field, coll, branded, known = /* @__PURE__ */ new Set()) {
|
|
2873
|
+
if (field.type === "blocks") {
|
|
2874
|
+
return nullable(field, blocksUnionType(field, (name) => known.has(name)));
|
|
2875
|
+
}
|
|
1965
2876
|
if (field.kind === "m2o") {
|
|
1966
2877
|
return nullable(field, mapScalarFieldType(field, branded));
|
|
1967
2878
|
}
|
|
1968
2879
|
if (field.kind === "o2m" || field.kind === "m2m") {
|
|
1969
|
-
return `${
|
|
2880
|
+
return `${capitalize2(field.target || "unknown")}[]`;
|
|
1970
2881
|
}
|
|
1971
2882
|
if (field.kind === "m2a") {
|
|
1972
2883
|
return `Array<{ collection: string; item: unknown }>`;
|
|
1973
2884
|
}
|
|
2885
|
+
const shape = fieldShape(field);
|
|
2886
|
+
if (shape.kind === "localized" || shape.kind === "file" || shape.kind === "files") {
|
|
2887
|
+
const wire = shape.kind === "localized" ? "Partial<Record<Locale, string>>" : shape.kind === "file" ? "string" : "string[]";
|
|
2888
|
+
return nullable(field, field.encrypted ? `${wire} | '***'` : wire);
|
|
2889
|
+
}
|
|
1974
2890
|
if (field.enum && field.enum.length > 0) {
|
|
1975
2891
|
return nullable(field, field.enum.map((v) => JSON.stringify(v)).join(" | "));
|
|
1976
2892
|
}
|
|
@@ -1983,7 +2899,9 @@ function mapFieldTypeToTs(field, coll, branded) {
|
|
|
1983
2899
|
const tsType = mapScalarFieldType(field, branded);
|
|
1984
2900
|
return nullable(field, field.encrypted ? `${tsType} | '***'` : tsType);
|
|
1985
2901
|
}
|
|
2902
|
+
var ZONED_DATETIME_TS = "{ instant: string; tz: string; offset: string }";
|
|
1986
2903
|
function mapScalarFieldType(field, branded) {
|
|
2904
|
+
if (field.timezone) return ZONED_DATETIME_TS;
|
|
1987
2905
|
const typeMap = {
|
|
1988
2906
|
string: "string",
|
|
1989
2907
|
text: "string",
|
|
@@ -1992,14 +2910,18 @@ function mapScalarFieldType(field, branded) {
|
|
|
1992
2910
|
integer: "number",
|
|
1993
2911
|
bigInteger: "number",
|
|
1994
2912
|
decimal: "number",
|
|
2913
|
+
float: "number",
|
|
1995
2914
|
boolean: "boolean",
|
|
1996
2915
|
json: "unknown",
|
|
1997
2916
|
uuid: mapPrimaryKeyType("uuid", branded, field.branded),
|
|
1998
2917
|
date: "string",
|
|
1999
2918
|
datetime: "string",
|
|
2919
|
+
dateTime: "string",
|
|
2000
2920
|
time: "string",
|
|
2001
2921
|
timestamp: "string",
|
|
2002
|
-
geometry: "GeoJSON.Geometry"
|
|
2922
|
+
geometry: "GeoJSON.Geometry",
|
|
2923
|
+
geopoint: "{ lat: number; lng: number }",
|
|
2924
|
+
richtext: "RichTextDocument"
|
|
2003
2925
|
};
|
|
2004
2926
|
return typeMap[field.type] || "unknown";
|
|
2005
2927
|
}
|
|
@@ -2014,7 +2936,7 @@ function mapPrimaryKeyType(primaryKeyType, branded, brand) {
|
|
|
2014
2936
|
if (branded) return `Brand<'${brand || "ID"}', string>`;
|
|
2015
2937
|
return "ID";
|
|
2016
2938
|
}
|
|
2017
|
-
function
|
|
2939
|
+
function capitalize2(str) {
|
|
2018
2940
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
2019
2941
|
}
|
|
2020
2942
|
function quoteProperty(name) {
|
|
@@ -2048,8 +2970,12 @@ function jsonLdScript(item) {
|
|
|
2048
2970
|
AudienceClient,
|
|
2049
2971
|
DECISION_ERROR_CODES,
|
|
2050
2972
|
DEFAULT_IMPORT_SOURCE,
|
|
2973
|
+
DEFAULT_ZOD_IMPORT,
|
|
2974
|
+
FILES_INTERFACE,
|
|
2975
|
+
FILE_INTERFACE,
|
|
2051
2976
|
LumiError,
|
|
2052
2977
|
RealtimeClient,
|
|
2978
|
+
TRANSLATABLE_INTERFACE,
|
|
2053
2979
|
ackCdcSubscription,
|
|
2054
2980
|
checkCdcPipelineHealth,
|
|
2055
2981
|
createAgentArtifact,
|
|
@@ -2070,8 +2996,12 @@ function jsonLdScript(item) {
|
|
|
2070
2996
|
evaluateAgentArtifact,
|
|
2071
2997
|
exportAccessManifest,
|
|
2072
2998
|
extractSeo,
|
|
2999
|
+
filterManifest,
|
|
2073
3000
|
generateAgentApp,
|
|
3001
|
+
generateGraphQLSdl,
|
|
3002
|
+
generateOpenApi,
|
|
2074
3003
|
generateTypes,
|
|
3004
|
+
generateZod,
|
|
2075
3005
|
getEffectivePreset,
|
|
2076
3006
|
getReview,
|
|
2077
3007
|
getReviewProfile,
|
|
@@ -2100,7 +3030,9 @@ function jsonLdScript(item) {
|
|
|
2100
3030
|
readCdcSubscription,
|
|
2101
3031
|
readItem,
|
|
2102
3032
|
readItems,
|
|
3033
|
+
realtimeHolders,
|
|
2103
3034
|
replayCdcSubscription,
|
|
3035
|
+
retainRealtime,
|
|
2104
3036
|
retryAgentRun,
|
|
2105
3037
|
reviewContentHash,
|
|
2106
3038
|
reviewDraft,
|