@btst/stack 2.1.0 → 2.3.0
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/api/index.cjs +9 -1
- package/dist/api/index.d.cts +4 -4
- package/dist/api/index.d.mts +4 -4
- package/dist/api/index.d.ts +4 -4
- package/dist/api/index.mjs +9 -1
- package/dist/client/index.d.cts +2 -2
- package/dist/client/index.d.mts +2 -2
- package/dist/client/index.d.ts +2 -2
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/packages/stack/src/plugins/ai-chat/api/getters.cjs +42 -0
- package/dist/packages/stack/src/plugins/ai-chat/api/getters.mjs +39 -0
- package/dist/packages/stack/src/plugins/ai-chat/api/plugin.cjs +5 -0
- package/dist/packages/stack/src/plugins/ai-chat/api/plugin.mjs +5 -0
- package/dist/packages/stack/src/plugins/blog/api/getters.cjs +131 -0
- package/dist/packages/stack/src/plugins/blog/api/getters.mjs +127 -0
- package/dist/packages/stack/src/plugins/blog/api/plugin.cjs +60 -107
- package/dist/packages/stack/src/plugins/blog/api/plugin.mjs +60 -107
- package/dist/packages/stack/src/plugins/blog/api/query-key-defs.cjs +18 -0
- package/dist/packages/stack/src/plugins/blog/api/query-key-defs.mjs +15 -0
- package/dist/packages/stack/src/plugins/blog/api/serializers.cjs +21 -0
- package/dist/packages/stack/src/plugins/blog/api/serializers.mjs +18 -0
- package/dist/packages/stack/src/plugins/blog/client/plugin.cjs +16 -1
- package/dist/packages/stack/src/plugins/blog/client/plugin.mjs +17 -2
- package/dist/packages/stack/src/plugins/cms/api/getters.cjs +156 -0
- package/dist/packages/stack/src/plugins/cms/api/getters.mjs +147 -0
- package/dist/packages/stack/src/plugins/cms/api/plugin.cjs +624 -617
- package/dist/packages/stack/src/plugins/cms/api/plugin.mjs +623 -616
- package/dist/packages/stack/src/plugins/cms/api/query-key-defs.cjs +29 -0
- package/dist/packages/stack/src/plugins/cms/api/query-key-defs.mjs +26 -0
- package/dist/packages/stack/src/plugins/cms/client/components/pages/content-editor-page.internal.cjs +1 -1
- package/dist/packages/stack/src/plugins/cms/client/components/pages/content-editor-page.internal.mjs +1 -1
- package/dist/packages/stack/src/plugins/cms/client/hooks/cms-hooks.cjs +6 -3
- package/dist/packages/stack/src/plugins/cms/client/hooks/cms-hooks.mjs +6 -3
- package/dist/packages/stack/src/plugins/cms/client/plugin.cjs +15 -0
- package/dist/packages/stack/src/plugins/cms/client/plugin.mjs +16 -1
- package/dist/packages/stack/src/plugins/form-builder/api/getters.cjs +120 -0
- package/dist/packages/stack/src/plugins/form-builder/api/getters.mjs +112 -0
- package/dist/packages/stack/src/plugins/form-builder/api/plugin.cjs +75 -86
- package/dist/packages/stack/src/plugins/form-builder/api/plugin.mjs +71 -82
- package/dist/packages/stack/src/plugins/form-builder/api/query-key-defs.cjs +37 -0
- package/dist/packages/stack/src/plugins/form-builder/api/query-key-defs.mjs +33 -0
- package/dist/packages/stack/src/plugins/form-builder/client/components/pages/submissions-page.internal.cjs +1 -1
- package/dist/packages/stack/src/plugins/form-builder/client/components/pages/submissions-page.internal.mjs +1 -1
- package/dist/packages/stack/src/plugins/form-builder/client/plugin.cjs +15 -0
- package/dist/packages/stack/src/plugins/form-builder/client/plugin.mjs +16 -1
- package/dist/packages/stack/src/plugins/kanban/api/getters.cjs +84 -0
- package/dist/packages/stack/src/plugins/kanban/api/getters.mjs +81 -0
- package/dist/packages/stack/src/plugins/kanban/api/plugin.cjs +37 -123
- package/dist/packages/stack/src/plugins/kanban/api/plugin.mjs +37 -123
- package/dist/packages/stack/src/plugins/kanban/api/query-key-defs.cjs +26 -0
- package/dist/packages/stack/src/plugins/kanban/api/query-key-defs.mjs +23 -0
- package/dist/packages/stack/src/plugins/kanban/api/serializers.cjs +30 -0
- package/dist/packages/stack/src/plugins/kanban/api/serializers.mjs +26 -0
- package/dist/packages/stack/src/plugins/kanban/client/plugin.cjs +11 -1
- package/dist/packages/stack/src/plugins/kanban/client/plugin.mjs +12 -2
- package/dist/packages/stack/src/plugins/utils.cjs +6 -0
- package/dist/packages/stack/src/plugins/utils.mjs +6 -1
- package/dist/plugins/ai-chat/api/index.cjs +3 -0
- package/dist/plugins/ai-chat/api/index.d.cts +27 -4
- package/dist/plugins/ai-chat/api/index.d.mts +27 -4
- package/dist/plugins/ai-chat/api/index.d.ts +27 -4
- package/dist/plugins/ai-chat/api/index.mjs +1 -0
- package/dist/plugins/ai-chat/client/hooks/index.d.cts +2 -2
- package/dist/plugins/ai-chat/client/hooks/index.d.mts +2 -2
- package/dist/plugins/ai-chat/client/hooks/index.d.ts +2 -2
- package/dist/plugins/ai-chat/query-keys.d.cts +9 -284
- package/dist/plugins/ai-chat/query-keys.d.mts +9 -284
- package/dist/plugins/ai-chat/query-keys.d.ts +9 -284
- package/dist/plugins/api/index.d.cts +4 -3
- package/dist/plugins/api/index.d.mts +4 -3
- package/dist/plugins/api/index.d.ts +4 -3
- package/dist/plugins/blog/api/index.cjs +9 -0
- package/dist/plugins/blog/api/index.d.cts +20 -4
- package/dist/plugins/blog/api/index.d.mts +20 -4
- package/dist/plugins/blog/api/index.d.ts +20 -4
- package/dist/plugins/blog/api/index.mjs +3 -0
- package/dist/plugins/blog/client/hooks/index.d.cts +5 -5
- package/dist/plugins/blog/client/hooks/index.d.mts +5 -5
- package/dist/plugins/blog/client/hooks/index.d.ts +5 -5
- package/dist/plugins/blog/client/index.d.cts +1 -1
- package/dist/plugins/blog/client/index.d.mts +1 -1
- package/dist/plugins/blog/client/index.d.ts +1 -1
- package/dist/plugins/blog/query-keys.cjs +13 -9
- package/dist/plugins/blog/query-keys.d.cts +8 -333
- package/dist/plugins/blog/query-keys.d.mts +8 -333
- package/dist/plugins/blog/query-keys.d.ts +8 -333
- package/dist/plugins/blog/query-keys.mjs +13 -9
- package/dist/plugins/client/index.cjs +1 -0
- package/dist/plugins/client/index.d.cts +10 -3
- package/dist/plugins/client/index.d.mts +10 -3
- package/dist/plugins/client/index.d.ts +10 -3
- package/dist/plugins/client/index.mjs +1 -1
- package/dist/plugins/cms/api/index.cjs +10 -0
- package/dist/plugins/cms/api/index.d.cts +7 -163
- package/dist/plugins/cms/api/index.d.mts +7 -163
- package/dist/plugins/cms/api/index.d.ts +7 -163
- package/dist/plugins/cms/api/index.mjs +2 -0
- package/dist/plugins/cms/client/hooks/index.d.cts +1 -1
- package/dist/plugins/cms/client/hooks/index.d.mts +1 -1
- package/dist/plugins/cms/client/hooks/index.d.ts +1 -1
- package/dist/plugins/cms/query-keys.cjs +2 -1
- package/dist/plugins/cms/query-keys.d.cts +6 -9
- package/dist/plugins/cms/query-keys.d.mts +6 -9
- package/dist/plugins/cms/query-keys.d.ts +6 -9
- package/dist/plugins/cms/query-keys.mjs +2 -1
- package/dist/plugins/form-builder/api/index.cjs +10 -0
- package/dist/plugins/form-builder/api/index.d.cts +7 -141
- package/dist/plugins/form-builder/api/index.d.mts +7 -141
- package/dist/plugins/form-builder/api/index.d.ts +7 -141
- package/dist/plugins/form-builder/api/index.mjs +2 -0
- package/dist/plugins/form-builder/client/components/index.d.cts +1 -1
- package/dist/plugins/form-builder/client/components/index.d.mts +1 -1
- package/dist/plugins/form-builder/client/components/index.d.ts +1 -1
- package/dist/plugins/form-builder/client/hooks/index.d.cts +1 -1
- package/dist/plugins/form-builder/client/hooks/index.d.mts +1 -1
- package/dist/plugins/form-builder/client/hooks/index.d.ts +1 -1
- package/dist/plugins/form-builder/query-keys.cjs +3 -2
- package/dist/plugins/form-builder/query-keys.d.cts +7 -6
- package/dist/plugins/form-builder/query-keys.d.mts +7 -6
- package/dist/plugins/form-builder/query-keys.d.ts +7 -6
- package/dist/plugins/form-builder/query-keys.mjs +3 -2
- package/dist/plugins/kanban/api/index.cjs +9 -0
- package/dist/plugins/kanban/api/index.d.cts +17 -395
- package/dist/plugins/kanban/api/index.d.mts +17 -395
- package/dist/plugins/kanban/api/index.d.ts +17 -395
- package/dist/plugins/kanban/api/index.mjs +3 -0
- package/dist/plugins/kanban/client/components/index.d.cts +1 -1
- package/dist/plugins/kanban/client/components/index.d.mts +1 -1
- package/dist/plugins/kanban/client/components/index.d.ts +1 -1
- package/dist/plugins/kanban/client/hooks/index.d.cts +1 -1
- package/dist/plugins/kanban/client/hooks/index.d.mts +1 -1
- package/dist/plugins/kanban/client/hooks/index.d.ts +1 -1
- package/dist/plugins/kanban/client/index.d.cts +1 -1
- package/dist/plugins/kanban/client/index.d.mts +1 -1
- package/dist/plugins/kanban/client/index.d.ts +1 -1
- package/dist/plugins/kanban/query-keys.cjs +6 -12
- package/dist/plugins/kanban/query-keys.d.cts +5 -16
- package/dist/plugins/kanban/query-keys.d.mts +5 -16
- package/dist/plugins/kanban/query-keys.d.ts +5 -16
- package/dist/plugins/kanban/query-keys.mjs +6 -12
- package/dist/plugins/open-api/api/index.d.cts +2 -2
- package/dist/plugins/open-api/api/index.d.mts +2 -2
- package/dist/plugins/open-api/api/index.d.ts +2 -2
- package/dist/plugins/route-docs/client/index.d.cts +1 -1
- package/dist/plugins/route-docs/client/index.d.mts +1 -1
- package/dist/plugins/route-docs/client/index.d.ts +1 -1
- package/dist/plugins/ui-builder/index.d.cts +1 -1
- package/dist/plugins/ui-builder/index.d.mts +1 -1
- package/dist/plugins/ui-builder/index.d.ts +1 -1
- package/dist/shared/{stack.BoA0xkJv.d.cts → stack.7n9Y_u7N.d.cts} +33 -7
- package/dist/shared/{stack.BoA0xkJv.d.mts → stack.7n9Y_u7N.d.mts} +33 -7
- package/dist/shared/{stack.BoA0xkJv.d.ts → stack.7n9Y_u7N.d.ts} +33 -7
- package/dist/shared/stack.B1EeBt1b.d.ts +297 -0
- package/dist/shared/stack.BIXEI6v_.d.mts +419 -0
- package/dist/shared/stack.BKfolAyK.d.ts +419 -0
- package/dist/shared/stack.BeSm90va.d.ts +289 -0
- package/dist/shared/stack.BpolpQpf.d.cts +445 -0
- package/dist/shared/stack.C5dtIncc.d.mts +293 -0
- package/dist/shared/stack.CIP6QS9l.d.ts +293 -0
- package/dist/shared/stack.CMh_EdxW.d.cts +289 -0
- package/dist/shared/stack.CP68pFEH.d.mts +297 -0
- package/dist/shared/{stack.BsXokfNh.d.mts → stack.CVDTkMoO.d.cts} +8 -2
- package/dist/shared/{stack.BsXokfNh.d.ts → stack.CVDTkMoO.d.mts} +8 -2
- package/dist/shared/{stack.BsXokfNh.d.cts → stack.CVDTkMoO.d.ts} +8 -2
- package/dist/shared/{stack.DKDMI-QO.d.mts → stack.DJaKVY7v.d.cts} +7 -1
- package/dist/shared/{stack.DKDMI-QO.d.ts → stack.DJaKVY7v.d.mts} +7 -1
- package/dist/shared/{stack.DKDMI-QO.d.cts → stack.DJaKVY7v.d.ts} +7 -1
- package/dist/shared/{stack.DzH_wcvr.d.mts → stack.DdI5W6MB.d.cts} +9 -3
- package/dist/shared/{stack.DzH_wcvr.d.ts → stack.DdI5W6MB.d.mts} +9 -3
- package/dist/shared/{stack.DzH_wcvr.d.cts → stack.DdI5W6MB.d.ts} +9 -3
- package/dist/shared/stack.Dg09R0oB.d.mts +289 -0
- package/dist/shared/stack.Dw0Ly2TM.d.cts +293 -0
- package/dist/shared/stack.IdtKDRka.d.cts +297 -0
- package/dist/shared/stack.TIBF2AOx.d.ts +445 -0
- package/dist/shared/stack.rTy7-wQU.d.mts +445 -0
- package/dist/shared/stack.snB1EDP7.d.cts +419 -0
- package/package.json +3 -3
- package/src/__tests__/stack-api.test.ts +118 -0
- package/src/api/index.ts +15 -1
- package/src/plugins/ai-chat/__tests__/getters.test.ts +109 -0
- package/src/plugins/ai-chat/api/getters.ts +71 -0
- package/src/plugins/ai-chat/api/index.ts +1 -0
- package/src/plugins/ai-chat/api/plugin.ts +8 -0
- package/src/plugins/api/index.ts +3 -1
- package/src/plugins/blog/__tests__/getters.test.ts +540 -0
- package/src/plugins/blog/api/getters.ts +243 -0
- package/src/plugins/blog/api/index.ts +9 -0
- package/src/plugins/blog/api/plugin.ts +98 -141
- package/src/plugins/blog/api/query-key-defs.ts +46 -0
- package/src/plugins/blog/api/serializers.ts +27 -0
- package/src/plugins/blog/client/plugin.tsx +21 -1
- package/src/plugins/blog/query-keys.ts +21 -20
- package/src/plugins/client/index.ts +1 -1
- package/src/plugins/cms/__tests__/getters.test.ts +206 -0
- package/src/plugins/cms/api/getters.ts +268 -0
- package/src/plugins/cms/api/index.ts +15 -1
- package/src/plugins/cms/api/plugin.ts +151 -150
- package/src/plugins/cms/api/query-key-defs.ts +53 -0
- package/src/plugins/cms/api/serializers.ts +12 -0
- package/src/plugins/cms/client/components/pages/content-editor-page.internal.tsx +1 -1
- package/src/plugins/cms/client/hooks/cms-hooks.tsx +3 -0
- package/src/plugins/cms/client/plugin.tsx +19 -0
- package/src/plugins/cms/query-keys.ts +2 -1
- package/src/plugins/cms/types.ts +1 -1
- package/src/plugins/form-builder/__tests__/getters.test.ts +159 -0
- package/src/plugins/form-builder/api/getters.ts +226 -0
- package/src/plugins/form-builder/api/index.ts +15 -1
- package/src/plugins/form-builder/api/plugin.ts +107 -109
- package/src/plugins/form-builder/api/query-key-defs.ts +79 -0
- package/src/plugins/form-builder/api/serializers.ts +12 -0
- package/src/plugins/form-builder/client/components/pages/submissions-page.internal.tsx +1 -1
- package/src/plugins/form-builder/client/plugin.tsx +19 -0
- package/src/plugins/form-builder/query-keys.ts +6 -2
- package/src/plugins/form-builder/types.ts +2 -2
- package/src/plugins/kanban/__tests__/getters.test.ts +172 -0
- package/src/plugins/kanban/api/getters.ts +149 -0
- package/src/plugins/kanban/api/index.ts +4 -0
- package/src/plugins/kanban/api/plugin.ts +65 -146
- package/src/plugins/kanban/api/query-key-defs.ts +54 -0
- package/src/plugins/kanban/api/serializers.ts +49 -0
- package/src/plugins/kanban/client/plugin.tsx +15 -1
- package/src/plugins/kanban/query-keys.ts +10 -14
- package/src/plugins/utils.ts +19 -0
- package/src/types.ts +44 -5
- package/dist/shared/{stack.CbuN2zVV.d.cts → stack.CBON0dWL.d.cts} +7 -7
- package/dist/shared/{stack.CbuN2zVV.d.mts → stack.CBON0dWL.d.mts} +7 -7
- package/dist/shared/{stack.CbuN2zVV.d.ts → stack.CBON0dWL.d.ts} +7 -7
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function serializeContentType(ct) {
|
|
4
|
+
const needsMigration = !ct.autoFormVersion || ct.autoFormVersion < 2;
|
|
5
|
+
const migratedJsonSchema = needsMigration ? migrateToUnifiedSchema(ct.jsonSchema, ct.fieldConfig) : ct.jsonSchema;
|
|
6
|
+
return {
|
|
7
|
+
id: ct.id,
|
|
8
|
+
name: ct.name,
|
|
9
|
+
slug: ct.slug,
|
|
10
|
+
description: ct.description,
|
|
11
|
+
jsonSchema: migratedJsonSchema,
|
|
12
|
+
createdAt: ct.createdAt.toISOString(),
|
|
13
|
+
updatedAt: ct.updatedAt.toISOString()
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function migrateToUnifiedSchema(jsonSchemaStr, fieldConfigStr) {
|
|
17
|
+
if (!fieldConfigStr) return jsonSchemaStr;
|
|
18
|
+
try {
|
|
19
|
+
const jsonSchema = JSON.parse(jsonSchemaStr);
|
|
20
|
+
const fieldConfig = JSON.parse(fieldConfigStr);
|
|
21
|
+
if (!jsonSchema.properties || typeof fieldConfig !== "object") {
|
|
22
|
+
return jsonSchemaStr;
|
|
23
|
+
}
|
|
24
|
+
for (const [key, config] of Object.entries(fieldConfig)) {
|
|
25
|
+
if (jsonSchema.properties[key] && typeof config === "object" && config !== null && "fieldType" in config) {
|
|
26
|
+
jsonSchema.properties[key].fieldType = config.fieldType;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return JSON.stringify(jsonSchema);
|
|
30
|
+
} catch {
|
|
31
|
+
return jsonSchemaStr;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function serializeContentItem(item) {
|
|
35
|
+
return {
|
|
36
|
+
...item,
|
|
37
|
+
createdAt: item.createdAt.toISOString(),
|
|
38
|
+
updatedAt: item.updatedAt.toISOString()
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function serializeContentItemWithType(item) {
|
|
42
|
+
const parsedData = JSON.parse(item.data);
|
|
43
|
+
return {
|
|
44
|
+
...serializeContentItem(item),
|
|
45
|
+
parsedData,
|
|
46
|
+
contentType: item.contentType ? serializeContentType(item.contentType) : void 0
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
async function getAllContentTypes(adapter) {
|
|
50
|
+
const contentTypes = await adapter.findMany({
|
|
51
|
+
model: "contentType",
|
|
52
|
+
sortBy: { field: "name", direction: "asc" }
|
|
53
|
+
});
|
|
54
|
+
return contentTypes.map(serializeContentType);
|
|
55
|
+
}
|
|
56
|
+
async function getAllContentItems(adapter, contentTypeSlug, params) {
|
|
57
|
+
const contentType = await adapter.findOne({
|
|
58
|
+
model: "contentType",
|
|
59
|
+
where: [
|
|
60
|
+
{
|
|
61
|
+
field: "slug",
|
|
62
|
+
value: contentTypeSlug,
|
|
63
|
+
operator: "eq"
|
|
64
|
+
}
|
|
65
|
+
]
|
|
66
|
+
});
|
|
67
|
+
if (!contentType) {
|
|
68
|
+
return {
|
|
69
|
+
items: [],
|
|
70
|
+
total: 0,
|
|
71
|
+
limit: params?.limit,
|
|
72
|
+
offset: params?.offset
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
const whereConditions = [
|
|
76
|
+
{
|
|
77
|
+
field: "contentTypeId",
|
|
78
|
+
value: contentType.id,
|
|
79
|
+
operator: "eq"
|
|
80
|
+
}
|
|
81
|
+
];
|
|
82
|
+
if (params?.slug) {
|
|
83
|
+
whereConditions.push({
|
|
84
|
+
field: "slug",
|
|
85
|
+
value: params.slug,
|
|
86
|
+
operator: "eq"
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
const total = await adapter.count({
|
|
90
|
+
model: "contentItem",
|
|
91
|
+
where: whereConditions
|
|
92
|
+
});
|
|
93
|
+
const items = await adapter.findMany({
|
|
94
|
+
model: "contentItem",
|
|
95
|
+
where: whereConditions,
|
|
96
|
+
limit: params?.limit,
|
|
97
|
+
offset: params?.offset,
|
|
98
|
+
sortBy: { field: "createdAt", direction: "desc" },
|
|
99
|
+
join: { contentType: true }
|
|
100
|
+
});
|
|
101
|
+
return {
|
|
102
|
+
items: items.map(serializeContentItemWithType),
|
|
103
|
+
total,
|
|
104
|
+
limit: params?.limit,
|
|
105
|
+
offset: params?.offset
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
async function getContentItemById(adapter, id) {
|
|
109
|
+
const item = await adapter.findOne({
|
|
110
|
+
model: "contentItem",
|
|
111
|
+
where: [{ field: "id", value: id, operator: "eq" }],
|
|
112
|
+
join: { contentType: true }
|
|
113
|
+
});
|
|
114
|
+
if (!item) return null;
|
|
115
|
+
return serializeContentItemWithType(item);
|
|
116
|
+
}
|
|
117
|
+
async function getContentItemBySlug(adapter, contentTypeSlug, slug) {
|
|
118
|
+
const contentType = await adapter.findOne({
|
|
119
|
+
model: "contentType",
|
|
120
|
+
where: [
|
|
121
|
+
{
|
|
122
|
+
field: "slug",
|
|
123
|
+
value: contentTypeSlug,
|
|
124
|
+
operator: "eq"
|
|
125
|
+
}
|
|
126
|
+
]
|
|
127
|
+
});
|
|
128
|
+
if (!contentType) {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
const item = await adapter.findOne({
|
|
132
|
+
model: "contentItem",
|
|
133
|
+
where: [
|
|
134
|
+
{
|
|
135
|
+
field: "contentTypeId",
|
|
136
|
+
value: contentType.id,
|
|
137
|
+
operator: "eq"
|
|
138
|
+
},
|
|
139
|
+
{ field: "slug", value: slug, operator: "eq" }
|
|
140
|
+
],
|
|
141
|
+
join: { contentType: true }
|
|
142
|
+
});
|
|
143
|
+
if (!item) {
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
return serializeContentItemWithType(item);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
exports.getAllContentItems = getAllContentItems;
|
|
150
|
+
exports.getAllContentTypes = getAllContentTypes;
|
|
151
|
+
exports.getContentItemById = getContentItemById;
|
|
152
|
+
exports.getContentItemBySlug = getContentItemBySlug;
|
|
153
|
+
exports.migrateToUnifiedSchema = migrateToUnifiedSchema;
|
|
154
|
+
exports.serializeContentItem = serializeContentItem;
|
|
155
|
+
exports.serializeContentItemWithType = serializeContentItemWithType;
|
|
156
|
+
exports.serializeContentType = serializeContentType;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
function serializeContentType(ct) {
|
|
2
|
+
const needsMigration = !ct.autoFormVersion || ct.autoFormVersion < 2;
|
|
3
|
+
const migratedJsonSchema = needsMigration ? migrateToUnifiedSchema(ct.jsonSchema, ct.fieldConfig) : ct.jsonSchema;
|
|
4
|
+
return {
|
|
5
|
+
id: ct.id,
|
|
6
|
+
name: ct.name,
|
|
7
|
+
slug: ct.slug,
|
|
8
|
+
description: ct.description,
|
|
9
|
+
jsonSchema: migratedJsonSchema,
|
|
10
|
+
createdAt: ct.createdAt.toISOString(),
|
|
11
|
+
updatedAt: ct.updatedAt.toISOString()
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function migrateToUnifiedSchema(jsonSchemaStr, fieldConfigStr) {
|
|
15
|
+
if (!fieldConfigStr) return jsonSchemaStr;
|
|
16
|
+
try {
|
|
17
|
+
const jsonSchema = JSON.parse(jsonSchemaStr);
|
|
18
|
+
const fieldConfig = JSON.parse(fieldConfigStr);
|
|
19
|
+
if (!jsonSchema.properties || typeof fieldConfig !== "object") {
|
|
20
|
+
return jsonSchemaStr;
|
|
21
|
+
}
|
|
22
|
+
for (const [key, config] of Object.entries(fieldConfig)) {
|
|
23
|
+
if (jsonSchema.properties[key] && typeof config === "object" && config !== null && "fieldType" in config) {
|
|
24
|
+
jsonSchema.properties[key].fieldType = config.fieldType;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return JSON.stringify(jsonSchema);
|
|
28
|
+
} catch {
|
|
29
|
+
return jsonSchemaStr;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function serializeContentItem(item) {
|
|
33
|
+
return {
|
|
34
|
+
...item,
|
|
35
|
+
createdAt: item.createdAt.toISOString(),
|
|
36
|
+
updatedAt: item.updatedAt.toISOString()
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function serializeContentItemWithType(item) {
|
|
40
|
+
const parsedData = JSON.parse(item.data);
|
|
41
|
+
return {
|
|
42
|
+
...serializeContentItem(item),
|
|
43
|
+
parsedData,
|
|
44
|
+
contentType: item.contentType ? serializeContentType(item.contentType) : void 0
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
async function getAllContentTypes(adapter) {
|
|
48
|
+
const contentTypes = await adapter.findMany({
|
|
49
|
+
model: "contentType",
|
|
50
|
+
sortBy: { field: "name", direction: "asc" }
|
|
51
|
+
});
|
|
52
|
+
return contentTypes.map(serializeContentType);
|
|
53
|
+
}
|
|
54
|
+
async function getAllContentItems(adapter, contentTypeSlug, params) {
|
|
55
|
+
const contentType = await adapter.findOne({
|
|
56
|
+
model: "contentType",
|
|
57
|
+
where: [
|
|
58
|
+
{
|
|
59
|
+
field: "slug",
|
|
60
|
+
value: contentTypeSlug,
|
|
61
|
+
operator: "eq"
|
|
62
|
+
}
|
|
63
|
+
]
|
|
64
|
+
});
|
|
65
|
+
if (!contentType) {
|
|
66
|
+
return {
|
|
67
|
+
items: [],
|
|
68
|
+
total: 0,
|
|
69
|
+
limit: params?.limit,
|
|
70
|
+
offset: params?.offset
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
const whereConditions = [
|
|
74
|
+
{
|
|
75
|
+
field: "contentTypeId",
|
|
76
|
+
value: contentType.id,
|
|
77
|
+
operator: "eq"
|
|
78
|
+
}
|
|
79
|
+
];
|
|
80
|
+
if (params?.slug) {
|
|
81
|
+
whereConditions.push({
|
|
82
|
+
field: "slug",
|
|
83
|
+
value: params.slug,
|
|
84
|
+
operator: "eq"
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
const total = await adapter.count({
|
|
88
|
+
model: "contentItem",
|
|
89
|
+
where: whereConditions
|
|
90
|
+
});
|
|
91
|
+
const items = await adapter.findMany({
|
|
92
|
+
model: "contentItem",
|
|
93
|
+
where: whereConditions,
|
|
94
|
+
limit: params?.limit,
|
|
95
|
+
offset: params?.offset,
|
|
96
|
+
sortBy: { field: "createdAt", direction: "desc" },
|
|
97
|
+
join: { contentType: true }
|
|
98
|
+
});
|
|
99
|
+
return {
|
|
100
|
+
items: items.map(serializeContentItemWithType),
|
|
101
|
+
total,
|
|
102
|
+
limit: params?.limit,
|
|
103
|
+
offset: params?.offset
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
async function getContentItemById(adapter, id) {
|
|
107
|
+
const item = await adapter.findOne({
|
|
108
|
+
model: "contentItem",
|
|
109
|
+
where: [{ field: "id", value: id, operator: "eq" }],
|
|
110
|
+
join: { contentType: true }
|
|
111
|
+
});
|
|
112
|
+
if (!item) return null;
|
|
113
|
+
return serializeContentItemWithType(item);
|
|
114
|
+
}
|
|
115
|
+
async function getContentItemBySlug(adapter, contentTypeSlug, slug) {
|
|
116
|
+
const contentType = await adapter.findOne({
|
|
117
|
+
model: "contentType",
|
|
118
|
+
where: [
|
|
119
|
+
{
|
|
120
|
+
field: "slug",
|
|
121
|
+
value: contentTypeSlug,
|
|
122
|
+
operator: "eq"
|
|
123
|
+
}
|
|
124
|
+
]
|
|
125
|
+
});
|
|
126
|
+
if (!contentType) {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
const item = await adapter.findOne({
|
|
130
|
+
model: "contentItem",
|
|
131
|
+
where: [
|
|
132
|
+
{
|
|
133
|
+
field: "contentTypeId",
|
|
134
|
+
value: contentType.id,
|
|
135
|
+
operator: "eq"
|
|
136
|
+
},
|
|
137
|
+
{ field: "slug", value: slug, operator: "eq" }
|
|
138
|
+
],
|
|
139
|
+
join: { contentType: true }
|
|
140
|
+
});
|
|
141
|
+
if (!item) {
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
return serializeContentItemWithType(item);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export { getAllContentItems, getAllContentTypes, getContentItemById, getContentItemBySlug, migrateToUnifiedSchema, serializeContentItem, serializeContentItemWithType, serializeContentType };
|