content-serialization 0.0.0 → 2.0.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.
@@ -156,6 +156,8 @@ function recursiveSanitize(data, attributes, componentSchemas) {
156
156
  if (compSchema) {
157
157
  currentAttributes = compSchema.attributes;
158
158
  sanitized.__component = data.__component;
159
+ } else {
160
+ strapi.log.warn(`[Content Serialization] Component schema not found for: ${data.__component}`);
159
161
  }
160
162
  }
161
163
  keys.forEach((key) => {
@@ -164,19 +166,25 @@ function recursiveSanitize(data, attributes, componentSchemas) {
164
166
  const value = data[key];
165
167
  const attr = currentAttributes ? currentAttributes[key] : null;
166
168
  if (!attr) {
169
+ if (value && typeof value === "object") {
170
+ strapi.log.warn(`[Content Serialization] Attribute not found for key: ${key}. Keeping value as-is (potential error source).`);
171
+ }
167
172
  sanitized[key] = value;
168
173
  return;
169
174
  }
170
175
  if (attr.type === "relation" || attr.type === "media") {
171
176
  if (Array.isArray(value)) {
172
- sanitized[key] = value.map((v) => v?.documentId || v?.id).filter((v) => v);
177
+ sanitized[key] = value.map((v) => v?.id || v?.documentId).filter((v) => v);
173
178
  } else if (value && typeof value === "object") {
174
- sanitized[key] = value.documentId || value.id;
179
+ sanitized[key] = value.id || value.documentId;
175
180
  } else {
176
181
  sanitized[key] = value;
177
182
  }
178
183
  } else if (attr.type === "component") {
179
184
  const compSchema = componentSchemas[attr.component];
185
+ if (!compSchema) {
186
+ strapi.log.warn(`[Content Serialization] Schema not found for component attribute: ${key} (uid: ${attr.component})`);
187
+ }
180
188
  const compAttributes = compSchema ? compSchema.attributes : {};
181
189
  sanitized[key] = recursiveSanitize(value, compAttributes, componentSchemas);
182
190
  } else if (attr.type === "dynamiczone") {
@@ -212,6 +220,29 @@ function getComponentSchemas() {
212
220
  });
213
221
  return schemas;
214
222
  }
223
+ function getDeepPopulate(uid, depth = 5) {
224
+ if (depth <= 0) return true;
225
+ const model = strapi.contentTypes[uid] || strapi.components[uid];
226
+ const populate = {};
227
+ Object.keys(model.attributes).forEach((key) => {
228
+ const attr = model.attributes[key];
229
+ if (attr.type === "component") {
230
+ populate[key] = { populate: getDeepPopulate(attr.component, depth - 1) };
231
+ } else if (attr.type === "dynamiczone") {
232
+ const dzPopulate = { on: {} };
233
+ attr.components.forEach((compUid) => {
234
+ dzPopulate.on[compUid] = { populate: getDeepPopulate(compUid, depth - 1) };
235
+ });
236
+ populate[key] = dzPopulate;
237
+ } else if (attr.type === "media") {
238
+ populate[key] = true;
239
+ } else if (attr.type === "relation") {
240
+ populate[key] = { count: true };
241
+ populate[key] = true;
242
+ }
243
+ });
244
+ return populate;
245
+ }
215
246
  const serialization = ({ strapi: strapi2 }) => ({
216
247
  async pull() {
217
248
  ensureDir(SERIALIZATION_DIR);
@@ -250,14 +281,15 @@ const serialization = ({ strapi: strapi2 }) => ({
250
281
  }
251
282
  processedFiles.add(filename);
252
283
  };
284
+ const populate = getDeepPopulate(uid);
253
285
  const items = await strapi2.documents(uid).findMany({
254
- populate: "*",
286
+ populate,
255
287
  publicationState: "preview",
256
288
  limit: 1e4
257
289
  });
258
290
  const itemArray = Array.isArray(items) ? items : [items];
259
291
  if (contentType.kind === "singleType") {
260
- const item = await strapi2.documents(uid).findFirst({ populate: "*" });
292
+ const item = await strapi2.documents(uid).findFirst({ populate: getDeepPopulate(uid) });
261
293
  if (item) {
262
294
  processItem(item, `${singularName}.yml`);
263
295
  }
@@ -150,6 +150,8 @@ function recursiveSanitize(data, attributes, componentSchemas) {
150
150
  if (compSchema) {
151
151
  currentAttributes = compSchema.attributes;
152
152
  sanitized.__component = data.__component;
153
+ } else {
154
+ strapi.log.warn(`[Content Serialization] Component schema not found for: ${data.__component}`);
153
155
  }
154
156
  }
155
157
  keys.forEach((key) => {
@@ -158,19 +160,25 @@ function recursiveSanitize(data, attributes, componentSchemas) {
158
160
  const value = data[key];
159
161
  const attr = currentAttributes ? currentAttributes[key] : null;
160
162
  if (!attr) {
163
+ if (value && typeof value === "object") {
164
+ strapi.log.warn(`[Content Serialization] Attribute not found for key: ${key}. Keeping value as-is (potential error source).`);
165
+ }
161
166
  sanitized[key] = value;
162
167
  return;
163
168
  }
164
169
  if (attr.type === "relation" || attr.type === "media") {
165
170
  if (Array.isArray(value)) {
166
- sanitized[key] = value.map((v) => v?.documentId || v?.id).filter((v) => v);
171
+ sanitized[key] = value.map((v) => v?.id || v?.documentId).filter((v) => v);
167
172
  } else if (value && typeof value === "object") {
168
- sanitized[key] = value.documentId || value.id;
173
+ sanitized[key] = value.id || value.documentId;
169
174
  } else {
170
175
  sanitized[key] = value;
171
176
  }
172
177
  } else if (attr.type === "component") {
173
178
  const compSchema = componentSchemas[attr.component];
179
+ if (!compSchema) {
180
+ strapi.log.warn(`[Content Serialization] Schema not found for component attribute: ${key} (uid: ${attr.component})`);
181
+ }
174
182
  const compAttributes = compSchema ? compSchema.attributes : {};
175
183
  sanitized[key] = recursiveSanitize(value, compAttributes, componentSchemas);
176
184
  } else if (attr.type === "dynamiczone") {
@@ -206,6 +214,29 @@ function getComponentSchemas() {
206
214
  });
207
215
  return schemas;
208
216
  }
217
+ function getDeepPopulate(uid, depth = 5) {
218
+ if (depth <= 0) return true;
219
+ const model = strapi.contentTypes[uid] || strapi.components[uid];
220
+ const populate = {};
221
+ Object.keys(model.attributes).forEach((key) => {
222
+ const attr = model.attributes[key];
223
+ if (attr.type === "component") {
224
+ populate[key] = { populate: getDeepPopulate(attr.component, depth - 1) };
225
+ } else if (attr.type === "dynamiczone") {
226
+ const dzPopulate = { on: {} };
227
+ attr.components.forEach((compUid) => {
228
+ dzPopulate.on[compUid] = { populate: getDeepPopulate(compUid, depth - 1) };
229
+ });
230
+ populate[key] = dzPopulate;
231
+ } else if (attr.type === "media") {
232
+ populate[key] = true;
233
+ } else if (attr.type === "relation") {
234
+ populate[key] = { count: true };
235
+ populate[key] = true;
236
+ }
237
+ });
238
+ return populate;
239
+ }
209
240
  const serialization = ({ strapi: strapi2 }) => ({
210
241
  async pull() {
211
242
  ensureDir(SERIALIZATION_DIR);
@@ -244,14 +275,15 @@ const serialization = ({ strapi: strapi2 }) => ({
244
275
  }
245
276
  processedFiles.add(filename);
246
277
  };
278
+ const populate = getDeepPopulate(uid);
247
279
  const items = await strapi2.documents(uid).findMany({
248
- populate: "*",
280
+ populate,
249
281
  publicationState: "preview",
250
282
  limit: 1e4
251
283
  });
252
284
  const itemArray = Array.isArray(items) ? items : [items];
253
285
  if (contentType.kind === "singleType") {
254
- const item = await strapi2.documents(uid).findFirst({ populate: "*" });
286
+ const item = await strapi2.documents(uid).findFirst({ populate: getDeepPopulate(uid) });
255
287
  if (item) {
256
288
  processItem(item, `${singularName}.yml`);
257
289
  }
package/package.json CHANGED
@@ -1,71 +1,71 @@
1
- {
2
- "version": "0.0.0",
3
- "keywords": [],
4
- "type": "commonjs",
5
- "exports": {
6
- "./package.json": "./package.json",
7
- "./strapi-admin": {
8
- "types": "./dist/admin/src/index.d.ts",
9
- "source": "./admin/src/index.ts",
10
- "import": "./dist/admin/index.mjs",
11
- "require": "./dist/admin/index.js",
12
- "default": "./dist/admin/index.js"
13
- },
14
- "./strapi-server": {
15
- "types": "./dist/server/src/index.d.ts",
16
- "source": "./server/src/index.ts",
17
- "import": "./dist/server/index.mjs",
18
- "require": "./dist/server/index.js",
19
- "default": "./dist/server/index.js"
20
- }
21
- },
22
- "files": [
23
- "dist"
24
- ],
25
- "scripts": {
26
- "build": "strapi-plugin build",
27
- "watch": "strapi-plugin watch",
28
- "watch:link": "strapi-plugin watch:link",
29
- "verify": "strapi-plugin verify",
30
- "test:ts:front": "run -T tsc -p admin/tsconfig.json",
31
- "test:ts:back": "run -T tsc -p server/tsconfig.json"
32
- },
33
- "dependencies": {
34
- "@strapi/design-system": "^2.0.0-rc.30",
35
- "@strapi/icons": "^2.0.0-rc.30",
36
- "@types/js-yaml": "^4.0.9",
37
- "js-yaml": "^4.1.1",
38
- "react-intl": "^8.0.10"
39
- },
40
- "devDependencies": {
41
- "@strapi/sdk-plugin": "^5.4.0",
42
- "@strapi/strapi": "^5.33.1",
43
- "@strapi/typescript-utils": "^5.33.1",
44
- "@types/react": "^19.2.7",
45
- "@types/react-dom": "^19.2.3",
46
- "prettier": "^3.7.4",
47
- "react": "^18.3.1",
48
- "react-dom": "^18.3.1",
49
- "react-router-dom": "^6.30.2",
50
- "styled-components": "^6.1.19",
51
- "typescript": "^5.9.3"
52
- },
53
- "peerDependencies": {
54
- "@strapi/sdk-plugin": "^5.4.0",
55
- "@strapi/strapi": "^5.33.1",
56
- "react": "^18.3.1",
57
- "react-dom": "^18.3.1",
58
- "react-router-dom": "^6.30.2",
59
- "styled-components": "^6.1.19"
60
- },
61
- "strapi": {
62
- "kind": "plugin",
63
- "name": "content-serialization",
64
- "displayName": "Content CLI",
65
- "description": ""
66
- },
67
- "name": "content-serialization",
68
- "description": "",
69
- "license": "MIT",
70
- "author": "Jaydeep <jaydeepkotak10@gmail.com>"
71
- }
1
+ {
2
+ "version": "2.0.0",
3
+ "keywords": [],
4
+ "type": "commonjs",
5
+ "exports": {
6
+ "./package.json": "./package.json",
7
+ "./strapi-admin": {
8
+ "types": "./dist/admin/src/index.d.ts",
9
+ "source": "./admin/src/index.ts",
10
+ "import": "./dist/admin/index.mjs",
11
+ "require": "./dist/admin/index.js",
12
+ "default": "./dist/admin/index.js"
13
+ },
14
+ "./strapi-server": {
15
+ "types": "./dist/server/src/index.d.ts",
16
+ "source": "./server/src/index.ts",
17
+ "import": "./dist/server/index.mjs",
18
+ "require": "./dist/server/index.js",
19
+ "default": "./dist/server/index.js"
20
+ }
21
+ },
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "scripts": {
26
+ "build": "strapi-plugin build",
27
+ "watch": "strapi-plugin watch",
28
+ "watch:link": "strapi-plugin watch:link",
29
+ "verify": "strapi-plugin verify",
30
+ "test:ts:front": "run -T tsc -p admin/tsconfig.json",
31
+ "test:ts:back": "run -T tsc -p server/tsconfig.json"
32
+ },
33
+ "dependencies": {
34
+ "@strapi/design-system": "^2.0.0-rc.30",
35
+ "@strapi/icons": "^2.0.0-rc.30",
36
+ "@types/js-yaml": "^4.0.9",
37
+ "js-yaml": "^4.1.1",
38
+ "react-intl": "^8.0.10"
39
+ },
40
+ "devDependencies": {
41
+ "@strapi/sdk-plugin": "^5.4.0",
42
+ "@strapi/strapi": "^5.33.1",
43
+ "@strapi/typescript-utils": "^5.33.1",
44
+ "@types/react": "^19.2.7",
45
+ "@types/react-dom": "^19.2.3",
46
+ "prettier": "^3.7.4",
47
+ "react": "^18.3.1",
48
+ "react-dom": "^18.3.1",
49
+ "react-router-dom": "^6.30.2",
50
+ "styled-components": "^6.1.19",
51
+ "typescript": "^5.9.3"
52
+ },
53
+ "peerDependencies": {
54
+ "@strapi/sdk-plugin": "^5.4.0",
55
+ "@strapi/strapi": "^5.33.1",
56
+ "react": "^18.3.1",
57
+ "react-dom": "^18.3.1",
58
+ "react-router-dom": "^6.30.2",
59
+ "styled-components": "^6.1.19"
60
+ },
61
+ "strapi": {
62
+ "kind": "plugin",
63
+ "name": "content-serialization",
64
+ "displayName": "Content CLI",
65
+ "description": ""
66
+ },
67
+ "name": "content-serialization",
68
+ "description": "",
69
+ "license": "MIT",
70
+ "author": "Jaydeep <jaydeepkotak10@gmail.com>"
71
+ }