@payloadcms/figma 0.0.1-alpha.1 → 0.0.1-alpha.11
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/control-plane.d.ts.map +1 -1
- package/dist/api/control-plane.js +11 -16
- package/dist/api/control-plane.js.map +1 -1
- package/dist/api/figma-api.js +3 -3
- package/dist/api/figma-api.js.map +1 -1
- package/dist/auth/jwt-validator.js.map +1 -1
- package/dist/auth/oauth-flow.d.ts.map +1 -1
- package/dist/auth/oauth-flow.js +3 -6
- package/dist/auth/oauth-flow.js.map +1 -1
- package/dist/auth/project-token.d.ts.map +1 -1
- package/dist/auth/project-token.js +1 -4
- package/dist/auth/project-token.js.map +1 -1
- package/dist/auth/refresh.d.ts.map +1 -1
- package/dist/auth/refresh.js +19 -28
- package/dist/auth/refresh.js.map +1 -1
- package/dist/auth/types.d.ts +1 -1
- package/dist/auth/types.d.ts.map +1 -1
- package/dist/auth/types.js.map +1 -1
- package/dist/cli.js +1 -3
- package/dist/cli.js.map +1 -1
- package/dist/commands/deploy.d.ts.map +1 -1
- package/dist/commands/deploy.js +17 -10
- package/dist/commands/deploy.js.map +1 -1
- package/dist/commands/init.d.ts +4 -0
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +21 -85
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/list-tokens.d.ts +1 -1
- package/dist/commands/list-tokens.d.ts.map +1 -1
- package/dist/commands/list-tokens.js +6 -5
- package/dist/commands/list-tokens.js.map +1 -1
- package/dist/commands/login.d.ts +2 -11
- package/dist/commands/login.d.ts.map +1 -1
- package/dist/commands/login.js +4 -7
- package/dist/commands/login.js.map +1 -1
- package/dist/commands/logout.d.ts +1 -1
- package/dist/commands/logout.js +1 -1
- package/dist/commands/logout.js.map +1 -1
- package/dist/db-adapter.d.ts +17 -0
- package/dist/db-adapter.d.ts.map +1 -0
- package/dist/db-adapter.js +757 -0
- package/dist/db-adapter.js.map +1 -0
- package/dist/endpoints/health.d.ts +3 -0
- package/dist/endpoints/health.d.ts.map +1 -0
- package/dist/endpoints/health.js +11 -0
- package/dist/endpoints/health.js.map +1 -0
- package/dist/exports/client.d.ts +3 -0
- package/dist/exports/client.d.ts.map +1 -0
- package/dist/exports/client.js +4 -0
- package/dist/exports/client.js.map +1 -0
- package/dist/oauth/components/LoginButton/index.d.ts +9 -0
- package/dist/oauth/components/LoginButton/index.d.ts.map +1 -0
- package/dist/oauth/components/LoginButton/index.js +52 -0
- package/dist/oauth/components/LoginButton/index.js.map +1 -0
- package/dist/oauth/components/LoginButton/index.scss +10 -0
- package/dist/oauth/components/LogoutButton/index.d.ts +7 -0
- package/dist/oauth/components/LogoutButton/index.d.ts.map +1 -0
- package/dist/oauth/components/LogoutButton/index.js +67 -0
- package/dist/oauth/components/LogoutButton/index.js.map +1 -0
- package/dist/oauth/components/LogoutButton/index.scss +10 -0
- package/dist/oauth/defaults.d.ts +10 -0
- package/dist/oauth/defaults.d.ts.map +1 -0
- package/dist/oauth/defaults.js +91 -0
- package/dist/oauth/defaults.js.map +1 -0
- package/dist/oauth/endpoints/getLoginEndpoint.d.ts +13 -0
- package/dist/oauth/endpoints/getLoginEndpoint.d.ts.map +1 -0
- package/dist/oauth/endpoints/getLoginEndpoint.js +237 -0
- package/dist/oauth/endpoints/getLoginEndpoint.js.map +1 -0
- package/dist/oauth/endpoints/getLogoutEndpoint.d.ts +12 -0
- package/dist/oauth/endpoints/getLogoutEndpoint.d.ts.map +1 -0
- package/dist/oauth/endpoints/getLogoutEndpoint.js +99 -0
- package/dist/oauth/endpoints/getLogoutEndpoint.js.map +1 -0
- package/dist/oauth/endpoints/getMetaEndpoint.d.ts +13 -0
- package/dist/oauth/endpoints/getMetaEndpoint.d.ts.map +1 -0
- package/dist/oauth/endpoints/getMetaEndpoint.js +25 -0
- package/dist/oauth/endpoints/getMetaEndpoint.js.map +1 -0
- package/dist/oauth/endpoints/getRedirectToLoginEndpoint.d.ts +13 -0
- package/dist/oauth/endpoints/getRedirectToLoginEndpoint.d.ts.map +1 -0
- package/dist/oauth/endpoints/getRedirectToLoginEndpoint.js +21 -0
- package/dist/oauth/endpoints/getRedirectToLoginEndpoint.js.map +1 -0
- package/dist/oauth/exports/client.d.ts +3 -0
- package/dist/oauth/exports/client.d.ts.map +1 -0
- package/dist/oauth/exports/client.js +4 -0
- package/dist/oauth/exports/client.js.map +1 -0
- package/dist/oauth/hooks/afterLogout.d.ts +8 -0
- package/dist/oauth/hooks/afterLogout.d.ts.map +1 -0
- package/dist/oauth/hooks/afterLogout.js +27 -0
- package/dist/oauth/hooks/afterLogout.js.map +1 -0
- package/dist/oauth/hooks/me.d.ts +5 -0
- package/dist/oauth/hooks/me.d.ts.map +1 -0
- package/dist/oauth/hooks/me.js +55 -0
- package/dist/oauth/hooks/me.js.map +1 -0
- package/dist/oauth/hooks/refresh.d.ts +8 -0
- package/dist/oauth/hooks/refresh.d.ts.map +1 -0
- package/dist/oauth/hooks/refresh.js +91 -0
- package/dist/oauth/hooks/refresh.js.map +1 -0
- package/dist/oauth/index.d.ts +4 -0
- package/dist/oauth/index.d.ts.map +1 -0
- package/dist/oauth/index.js +222 -0
- package/dist/oauth/index.js.map +1 -0
- package/dist/oauth/strategy/index.d.ts +54 -0
- package/dist/oauth/strategy/index.d.ts.map +1 -0
- package/dist/oauth/strategy/index.js +280 -0
- package/dist/oauth/strategy/index.js.map +1 -0
- package/dist/oauth/types.d.ts +192 -0
- package/dist/oauth/types.d.ts.map +1 -0
- package/dist/oauth/types.js +3 -0
- package/dist/oauth/types.js.map +1 -0
- package/dist/oauth/utilities/clearCookie.d.ts +9 -0
- package/dist/oauth/utilities/clearCookie.d.ts.map +1 -0
- package/dist/oauth/utilities/clearCookie.js +21 -0
- package/dist/oauth/utilities/clearCookie.js.map +1 -0
- package/dist/oauth/utilities/createCookieOptions.d.ts +10 -0
- package/dist/oauth/utilities/createCookieOptions.d.ts.map +1 -0
- package/dist/oauth/utilities/createCookieOptions.js +42 -0
- package/dist/oauth/utilities/createCookieOptions.js.map +1 -0
- package/dist/oauth/utilities/createDebugLogger.d.ts +4 -0
- package/dist/oauth/utilities/createDebugLogger.d.ts.map +1 -0
- package/dist/oauth/utilities/createDebugLogger.js +16 -0
- package/dist/oauth/utilities/createDebugLogger.js.map +1 -0
- package/dist/oauth/utilities/extractOrigin.d.ts +2 -0
- package/dist/oauth/utilities/extractOrigin.d.ts.map +1 -0
- package/dist/oauth/utilities/extractOrigin.js +12 -0
- package/dist/oauth/utilities/extractOrigin.js.map +1 -0
- package/dist/oauth/utilities/getAdminCollectionSlug.d.ts +3 -0
- package/dist/oauth/utilities/getAdminCollectionSlug.d.ts.map +1 -0
- package/dist/oauth/utilities/getAdminCollectionSlug.js +18 -0
- package/dist/oauth/utilities/getAdminCollectionSlug.js.map +1 -0
- package/dist/oauth/utilities/getAdminPath.d.ts +8 -0
- package/dist/oauth/utilities/getAdminPath.d.ts.map +1 -0
- package/dist/oauth/utilities/getAdminPath.js +9 -0
- package/dist/oauth/utilities/getAdminPath.js.map +1 -0
- package/dist/oauth/utilities/getAuthorizeURL.d.ts +17 -0
- package/dist/oauth/utilities/getAuthorizeURL.d.ts.map +1 -0
- package/dist/oauth/utilities/getAuthorizeURL.js +45 -0
- package/dist/oauth/utilities/getAuthorizeURL.js.map +1 -0
- package/dist/oauth/utilities/getCookieExpiration.d.ts +4 -0
- package/dist/oauth/utilities/getCookieExpiration.d.ts.map +1 -0
- package/dist/oauth/utilities/getCookieExpiration.js +11 -0
- package/dist/oauth/utilities/getCookieExpiration.js.map +1 -0
- package/dist/oauth/utilities/getSecondsFromTokenExp.d.ts +2 -0
- package/dist/oauth/utilities/getSecondsFromTokenExp.d.ts.map +1 -0
- package/dist/oauth/utilities/getSecondsFromTokenExp.js +7 -0
- package/dist/oauth/utilities/getSecondsFromTokenExp.js.map +1 -0
- package/dist/oauth/utilities/getTokenExp.d.ts +6 -0
- package/dist/oauth/utilities/getTokenExp.d.ts.map +1 -0
- package/dist/oauth/utilities/getTokenExp.js +20 -0
- package/dist/oauth/utilities/getTokenExp.js.map +1 -0
- package/dist/oauth/utilities/getUsernameField.d.ts +9 -0
- package/dist/oauth/utilities/getUsernameField.d.ts.map +1 -0
- package/dist/oauth/utilities/getUsernameField.js +20 -0
- package/dist/oauth/utilities/getUsernameField.js.map +1 -0
- package/dist/oauth/utilities/hasUserTokenPropsChanged.d.ts +8 -0
- package/dist/oauth/utilities/hasUserTokenPropsChanged.d.ts.map +1 -0
- package/dist/oauth/utilities/hasUserTokenPropsChanged.js +25 -0
- package/dist/oauth/utilities/hasUserTokenPropsChanged.js.map +1 -0
- package/dist/oauth/utilities/mergeHeaders.d.ts +2 -0
- package/dist/oauth/utilities/mergeHeaders.d.ts.map +1 -0
- package/dist/oauth/utilities/mergeHeaders.js +37 -0
- package/dist/oauth/utilities/mergeHeaders.js.map +1 -0
- package/dist/oauth/utilities/refreshTokens.d.ts +16 -0
- package/dist/oauth/utilities/refreshTokens.d.ts.map +1 -0
- package/dist/oauth/utilities/refreshTokens.js +67 -0
- package/dist/oauth/utilities/refreshTokens.js.map +1 -0
- package/dist/plugin/build-config.d.ts +7 -1
- package/dist/plugin/build-config.d.ts.map +1 -1
- package/dist/plugin/build-config.js +53 -3
- package/dist/plugin/build-config.js.map +1 -1
- package/dist/types/config.d.ts +0 -11
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/config.js +1 -1
- package/dist/types/config.js.map +1 -1
- package/dist/utils/config.d.ts +0 -22
- package/dist/utils/config.d.ts.map +1 -1
- package/dist/utils/config.js +0 -46
- package/dist/utils/config.js.map +1 -1
- package/dist/utils/messages.js +11 -11
- package/dist/utils/messages.js.map +1 -1
- package/dist/utils/payload-config-ast.d.ts +17 -1
- package/dist/utils/payload-config-ast.d.ts.map +1 -1
- package/dist/utils/payload-config-ast.js +166 -14
- package/dist/utils/payload-config-ast.js.map +1 -1
- package/dist/utils/payload-config-modifier.d.ts +2 -1
- package/dist/utils/payload-config-modifier.d.ts.map +1 -1
- package/dist/utils/payload-config-modifier.js +50 -79
- package/dist/utils/payload-config-modifier.js.map +1 -1
- package/dist/utils/payload-package-check.d.ts.map +1 -1
- package/dist/utils/payload-package-check.js +14 -33
- package/dist/utils/payload-package-check.js.map +1 -1
- package/dist/utils/project.d.ts +1 -1
- package/dist/utils/project.d.ts.map +1 -1
- package/dist/utils/project.js +3 -5
- package/dist/utils/project.js.map +1 -1
- package/dist/utils/s3-upload.d.ts.map +1 -1
- package/dist/utils/s3-upload.js +3 -8
- package/dist/utils/s3-upload.js.map +1 -1
- package/dist/utils/token-display.d.ts.map +1 -1
- package/dist/utils/token-display.js +3 -2
- package/dist/utils/token-display.js.map +1 -1
- package/package.json +9 -3
- package/dist/api/control-plane.spec.d.ts +0 -2
- package/dist/api/control-plane.spec.d.ts.map +0 -1
- package/dist/api/control-plane.spec.js +0 -296
- package/dist/api/control-plane.spec.js.map +0 -1
- package/dist/api/figma-api.spec.d.ts +0 -14
- package/dist/api/figma-api.spec.d.ts.map +0 -1
- package/dist/api/figma-api.spec.js +0 -201
- package/dist/api/figma-api.spec.js.map +0 -1
- package/dist/auth/__tests__/fixtures.d.ts +0 -26
- package/dist/auth/__tests__/fixtures.d.ts.map +0 -1
- package/dist/auth/__tests__/fixtures.js +0 -67
- package/dist/auth/__tests__/fixtures.js.map +0 -1
- package/dist/auth/__tests__/mocks.d.ts +0 -33
- package/dist/auth/__tests__/mocks.d.ts.map +0 -1
- package/dist/auth/__tests__/mocks.js +0 -63
- package/dist/auth/__tests__/mocks.js.map +0 -1
- package/dist/auth/callback-server.spec.d.ts +0 -2
- package/dist/auth/callback-server.spec.d.ts.map +0 -1
- package/dist/auth/callback-server.spec.js +0 -85
- package/dist/auth/callback-server.spec.js.map +0 -1
- package/dist/auth/crypto-utils.spec.d.ts +0 -2
- package/dist/auth/crypto-utils.spec.d.ts.map +0 -1
- package/dist/auth/crypto-utils.spec.js +0 -36
- package/dist/auth/crypto-utils.spec.js.map +0 -1
- package/dist/auth/jwt-validator.spec.d.ts +0 -10
- package/dist/auth/jwt-validator.spec.d.ts.map +0 -1
- package/dist/auth/jwt-validator.spec.js +0 -236
- package/dist/auth/jwt-validator.spec.js.map +0 -1
- package/dist/auth/oauth-flow.spec.d.ts +0 -2
- package/dist/auth/oauth-flow.spec.d.ts.map +0 -1
- package/dist/auth/oauth-flow.spec.js +0 -134
- package/dist/auth/oauth-flow.spec.js.map +0 -1
- package/dist/auth/pkce.spec.d.ts +0 -2
- package/dist/auth/pkce.spec.d.ts.map +0 -1
- package/dist/auth/pkce.spec.js +0 -32
- package/dist/auth/pkce.spec.js.map +0 -1
- package/dist/auth/project-token.spec.d.ts +0 -2
- package/dist/auth/project-token.spec.d.ts.map +0 -1
- package/dist/auth/project-token.spec.js +0 -332
- package/dist/auth/project-token.spec.js.map +0 -1
- package/dist/auth/refresh.spec.d.ts +0 -2
- package/dist/auth/refresh.spec.d.ts.map +0 -1
- package/dist/auth/refresh.spec.js +0 -105
- package/dist/auth/refresh.spec.js.map +0 -1
- package/dist/auth/token-store.spec.d.ts +0 -2
- package/dist/auth/token-store.spec.d.ts.map +0 -1
- package/dist/auth/token-store.spec.js +0 -276
- package/dist/auth/token-store.spec.js.map +0 -1
- package/dist/commands/__tests__/test-utils.d.ts +0 -28
- package/dist/commands/__tests__/test-utils.d.ts.map +0 -1
- package/dist/commands/__tests__/test-utils.js +0 -34
- package/dist/commands/__tests__/test-utils.js.map +0 -1
- package/dist/commands/deploy.spec.d.ts +0 -2
- package/dist/commands/deploy.spec.d.ts.map +0 -1
- package/dist/commands/deploy.spec.js +0 -18
- package/dist/commands/deploy.spec.js.map +0 -1
- package/dist/commands/init.spec.d.ts +0 -2
- package/dist/commands/init.spec.d.ts.map +0 -1
- package/dist/commands/init.spec.js +0 -283
- package/dist/commands/init.spec.js.map +0 -1
- package/dist/plugin/build-config.spec.d.ts +0 -2
- package/dist/plugin/build-config.spec.d.ts.map +0 -1
- package/dist/plugin/build-config.spec.js +0 -72
- package/dist/plugin/build-config.spec.js.map +0 -1
- package/dist/utils/asset-collection.spec.d.ts +0 -2
- package/dist/utils/asset-collection.spec.d.ts.map +0 -1
- package/dist/utils/asset-collection.spec.js +0 -155
- package/dist/utils/asset-collection.spec.js.map +0 -1
- package/dist/utils/build-detection.spec.d.ts +0 -2
- package/dist/utils/build-detection.spec.d.ts.map +0 -1
- package/dist/utils/build-detection.spec.js +0 -110
- package/dist/utils/build-detection.spec.js.map +0 -1
- package/dist/utils/config.spec.d.ts +0 -2
- package/dist/utils/config.spec.d.ts.map +0 -1
- package/dist/utils/config.spec.js +0 -167
- package/dist/utils/config.spec.js.map +0 -1
- package/dist/utils/download-template.spec.d.ts +0 -2
- package/dist/utils/download-template.spec.d.ts.map +0 -1
- package/dist/utils/download-template.spec.js +0 -76
- package/dist/utils/download-template.spec.js.map +0 -1
- package/dist/utils/env-management.spec.d.ts +0 -2
- package/dist/utils/env-management.spec.d.ts.map +0 -1
- package/dist/utils/env-management.spec.js +0 -123
- package/dist/utils/env-management.spec.js.map +0 -1
- package/dist/utils/git.spec.d.ts +0 -2
- package/dist/utils/git.spec.d.ts.map +0 -1
- package/dist/utils/git.spec.js +0 -99
- package/dist/utils/git.spec.js.map +0 -1
- package/dist/utils/lambda-config.spec.d.ts +0 -2
- package/dist/utils/lambda-config.spec.d.ts.map +0 -1
- package/dist/utils/lambda-config.spec.js +0 -141
- package/dist/utils/lambda-config.spec.js.map +0 -1
- package/dist/utils/payload-config-ast.spec.d.ts +0 -2
- package/dist/utils/payload-config-ast.spec.d.ts.map +0 -1
- package/dist/utils/payload-config-ast.spec.js +0 -303
- package/dist/utils/payload-config-ast.spec.js.map +0 -1
- package/dist/utils/payload-config-modifier.int.spec.d.ts +0 -2
- package/dist/utils/payload-config-modifier.int.spec.d.ts.map +0 -1
- package/dist/utils/payload-config-modifier.int.spec.js +0 -116
- package/dist/utils/payload-config-modifier.int.spec.js.map +0 -1
- package/dist/utils/payload-config-modifier.spec.d.ts +0 -2
- package/dist/utils/payload-config-modifier.spec.d.ts.map +0 -1
- package/dist/utils/payload-config-modifier.spec.js +0 -162
- package/dist/utils/payload-config-modifier.spec.js.map +0 -1
- package/dist/utils/payload-package-check.spec.d.ts +0 -2
- package/dist/utils/payload-package-check.spec.d.ts.map +0 -1
- package/dist/utils/payload-package-check.spec.js +0 -148
- package/dist/utils/payload-package-check.spec.js.map +0 -1
- package/dist/utils/project.spec.d.ts +0 -2
- package/dist/utils/project.spec.d.ts.map +0 -1
- package/dist/utils/project.spec.js +0 -222
- package/dist/utils/project.spec.js.map +0 -1
- package/dist/utils/s3-upload.spec.d.ts +0 -2
- package/dist/utils/s3-upload.spec.d.ts.map +0 -1
- package/dist/utils/s3-upload.spec.js +0 -140
- package/dist/utils/s3-upload.spec.js.map +0 -1
|
@@ -0,0 +1,757 @@
|
|
|
1
|
+
import { randomUUID } from 'crypto';
|
|
2
|
+
import { createDatabaseAdapter } from 'payload';
|
|
3
|
+
const slugIsGlobal = (slug)=>slug.startsWith('_global-');
|
|
4
|
+
const getGlobalSlug = (slug)=>`_global-${slug}`;
|
|
5
|
+
// Transform Payload Where format to Content API WhereClause format
|
|
6
|
+
function transformWhereClause(where) {
|
|
7
|
+
if (!where) {
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
10
|
+
// Handle and/or logical operators
|
|
11
|
+
if (where.and) {
|
|
12
|
+
return {
|
|
13
|
+
and: where.and.map(transformWhereClause).filter(Boolean)
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
if (where.or) {
|
|
17
|
+
return {
|
|
18
|
+
or: where.or.map(transformWhereClause).filter(Boolean)
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
// Transform field conditions
|
|
22
|
+
const transformedClauses = [];
|
|
23
|
+
for (const [field, condition] of Object.entries(where)){
|
|
24
|
+
if (field === 'and' || field === 'or') {
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
if (Array.isArray(condition)) {
|
|
28
|
+
// Handle nested and/or arrays
|
|
29
|
+
transformedClauses.push({
|
|
30
|
+
[field]: condition.map(transformWhereClause).filter(Boolean)
|
|
31
|
+
});
|
|
32
|
+
} else if (typeof condition === 'object' && condition !== null) {
|
|
33
|
+
// Handle field operators like { equals: 'value' }, { greater_than: 10 }
|
|
34
|
+
for (const [operator, value] of Object.entries(condition)){
|
|
35
|
+
transformedClauses.push({
|
|
36
|
+
operator: operator,
|
|
37
|
+
path: field,
|
|
38
|
+
value
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
} else {
|
|
42
|
+
// Handle direct field values like { status: 'published' }
|
|
43
|
+
transformedClauses.push({
|
|
44
|
+
operator: 'equals',
|
|
45
|
+
path: field,
|
|
46
|
+
value: condition
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (transformedClauses.length === 1) {
|
|
51
|
+
return transformedClauses[0];
|
|
52
|
+
} else if (transformedClauses.length > 1) {
|
|
53
|
+
return {
|
|
54
|
+
and: transformedClauses
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
const formatDocument = (doc)=>{
|
|
60
|
+
if (!doc) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
const { id, data, ...meta } = doc;
|
|
64
|
+
return {
|
|
65
|
+
id,
|
|
66
|
+
_meta: meta,
|
|
67
|
+
...data
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
async function init() {
|
|
71
|
+
console.log('🔍 [DB_CONTENT_API] init() called');
|
|
72
|
+
console.log('🔍 [DB_CONTENT_API] this:', this);
|
|
73
|
+
console.log('🔍 [DB_CONTENT_API] payload collections:', this.payload.config.collections.map((c)=>c.slug));
|
|
74
|
+
// Create collections in content API
|
|
75
|
+
for (const collection of this.payload.config.collections){
|
|
76
|
+
try {
|
|
77
|
+
console.log(`🔧 [DB_CONTENT_API] Creating collection: ${collection.slug}`);
|
|
78
|
+
const response = await this.request('/api/v0/collections', {
|
|
79
|
+
contentSystemId: this.contentSystemId,
|
|
80
|
+
key: collection.slug
|
|
81
|
+
});
|
|
82
|
+
if (response.error) {
|
|
83
|
+
console.error(`[DB_CONTENT_API] create collection ${collection.slug} failure`, response.error);
|
|
84
|
+
} else {
|
|
85
|
+
console.log(`✅ [DB_CONTENT_API] Created collection: ${collection.slug}`);
|
|
86
|
+
}
|
|
87
|
+
} catch (error) {
|
|
88
|
+
console.warn(`⚠️ [DB_CONTENT_API] Failed to create collection ${collection.slug}:`, error);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
// Create globals as collections (with _global- prefix)
|
|
92
|
+
for (const global of this.payload.config.globals){
|
|
93
|
+
try {
|
|
94
|
+
const globalKey = getGlobalSlug(global.slug);
|
|
95
|
+
console.log(`🔧 [DB_CONTENT_API] Creating global collection: ${globalKey}`);
|
|
96
|
+
const response = await this.request('/api/v0/collections', {
|
|
97
|
+
contentSystemId: this.contentSystemId,
|
|
98
|
+
key: globalKey
|
|
99
|
+
});
|
|
100
|
+
if (response.error) {
|
|
101
|
+
console.error(`[DB_CONTENT_API] create global collection ${globalKey} failure`, response.error);
|
|
102
|
+
} else {
|
|
103
|
+
console.log(`✅ [DB_CONTENT_API] Created global collection: ${globalKey}`);
|
|
104
|
+
}
|
|
105
|
+
} catch (error) {
|
|
106
|
+
console.warn(`⚠️ [DB_CONTENT_API] Failed to create global collection ${global.slug}:`, error);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
console.log('🔍 [DB_CONTENT_API] payload globals:', this.payload.config.globals.map((g)=>g.slug));
|
|
110
|
+
}
|
|
111
|
+
const find = async function find({ collection, limit, page = 1, req, sort, where, ...args }) {
|
|
112
|
+
console.log('🔍 [DB_CONTENT_API] find() called with:', collection, JSON.stringify(transformWhereClause(where), null, 2), {
|
|
113
|
+
limit,
|
|
114
|
+
page,
|
|
115
|
+
sort,
|
|
116
|
+
...args
|
|
117
|
+
});
|
|
118
|
+
try {
|
|
119
|
+
const response = await this.request('/api/v0/documents:find', {
|
|
120
|
+
collectionKey: collection,
|
|
121
|
+
contentSystemId: this.contentSystemId,
|
|
122
|
+
limit,
|
|
123
|
+
offset: (page - 1) * (limit || 10),
|
|
124
|
+
sort: sort ? [
|
|
125
|
+
sort
|
|
126
|
+
].flat().map((s)=>({
|
|
127
|
+
direction: Object.values(s)[0] === -1 ? 'dsc' : 'asc',
|
|
128
|
+
path: Object.keys(s)[0]
|
|
129
|
+
})) : undefined,
|
|
130
|
+
where: transformWhereClause(where)
|
|
131
|
+
});
|
|
132
|
+
if (response.error) {
|
|
133
|
+
console.error('[DB_CONTENT_API] find() failure', response.error?.message || response.error);
|
|
134
|
+
}
|
|
135
|
+
const docs = response.result?.data || [];
|
|
136
|
+
const pagination = response.result?.pagination;
|
|
137
|
+
const totalDocs = pagination?.total || docs.length;
|
|
138
|
+
const actualLimit = limit || 10;
|
|
139
|
+
const totalPages = Math.ceil(totalDocs / actualLimit);
|
|
140
|
+
const hasNextPage = page < totalPages;
|
|
141
|
+
const result = {
|
|
142
|
+
docs: docs.map(formatDocument),
|
|
143
|
+
hasNextPage,
|
|
144
|
+
hasPrevPage: page > 1,
|
|
145
|
+
limit: actualLimit,
|
|
146
|
+
nextPage: hasNextPage ? page + 1 : null,
|
|
147
|
+
page,
|
|
148
|
+
pagingCounter: 1,
|
|
149
|
+
prevPage: page > 1 ? page - 1 : null,
|
|
150
|
+
totalDocs,
|
|
151
|
+
totalPages
|
|
152
|
+
};
|
|
153
|
+
console.log('[DB_CONTENT_API] find() result:', result);
|
|
154
|
+
return result;
|
|
155
|
+
} catch (error) {
|
|
156
|
+
console.error(`❌ [DB_CONTENT_API] Error in find():`, error);
|
|
157
|
+
const docs = [];
|
|
158
|
+
const hasNextPage = false;
|
|
159
|
+
const totalPages = 1;
|
|
160
|
+
return {
|
|
161
|
+
docs,
|
|
162
|
+
hasNextPage,
|
|
163
|
+
hasPrevPage: page > 1,
|
|
164
|
+
limit: limit || docs.length,
|
|
165
|
+
nextPage: hasNextPage ? page + 1 : null,
|
|
166
|
+
page,
|
|
167
|
+
pagingCounter: 1,
|
|
168
|
+
prevPage: page > 1 ? page - 1 : null,
|
|
169
|
+
totalDocs: docs.length,
|
|
170
|
+
totalPages
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
const findVersions = async function findVersions({ collection, limit, page = 1, req, where, ...args }) {
|
|
175
|
+
console.log('🔍 [DB_CONTENT_API] findVersions() called with:', {
|
|
176
|
+
collection,
|
|
177
|
+
limit,
|
|
178
|
+
page,
|
|
179
|
+
where,
|
|
180
|
+
...args
|
|
181
|
+
});
|
|
182
|
+
const docs = [];
|
|
183
|
+
const hasNextPage = false;
|
|
184
|
+
const result = {
|
|
185
|
+
docs,
|
|
186
|
+
hasNextPage,
|
|
187
|
+
hasPrevPage: page > 1,
|
|
188
|
+
limit: limit || docs.length,
|
|
189
|
+
nextPage: hasNextPage ? page + 1 : null,
|
|
190
|
+
page,
|
|
191
|
+
pagingCounter: 1,
|
|
192
|
+
prevPage: page > 1 ? page - 1 : null,
|
|
193
|
+
totalDocs: docs.length,
|
|
194
|
+
totalPages: limit && docs.length ? Math.ceil(docs.length / limit) : 1
|
|
195
|
+
};
|
|
196
|
+
console.log('[DB_CONTENT_API] findVersions() result:', result);
|
|
197
|
+
return result;
|
|
198
|
+
};
|
|
199
|
+
const queryDrafts = async function queryDrafts({ collection, limit, page = 1, req, where, ...args }) {
|
|
200
|
+
console.log('🔍 [DB_CONTENT_API] queryDrafts() called with:', {
|
|
201
|
+
collection,
|
|
202
|
+
limit,
|
|
203
|
+
page,
|
|
204
|
+
where,
|
|
205
|
+
...args
|
|
206
|
+
});
|
|
207
|
+
const docs = [];
|
|
208
|
+
const hasNextPage = false;
|
|
209
|
+
const result = {
|
|
210
|
+
docs,
|
|
211
|
+
hasNextPage,
|
|
212
|
+
hasPrevPage: page > 1,
|
|
213
|
+
limit: limit || docs.length,
|
|
214
|
+
nextPage: hasNextPage ? page + 1 : null,
|
|
215
|
+
page,
|
|
216
|
+
pagingCounter: 1,
|
|
217
|
+
prevPage: page > 1 ? page - 1 : null,
|
|
218
|
+
totalDocs: docs.length,
|
|
219
|
+
totalPages: limit && docs.length ? Math.ceil(docs.length / limit) : 1
|
|
220
|
+
};
|
|
221
|
+
console.log('[DB_CONTENT_API] queryDrafts() result:', result);
|
|
222
|
+
return result;
|
|
223
|
+
};
|
|
224
|
+
const createVersion = async function createVersion({ collectionSlug, req, versionData, ...args }) {
|
|
225
|
+
console.log('🔍 [DB_CONTENT_API] createVersion() called with:', {
|
|
226
|
+
collectionSlug,
|
|
227
|
+
versionData,
|
|
228
|
+
...args
|
|
229
|
+
});
|
|
230
|
+
const result = {};
|
|
231
|
+
console.log('[DB_CONTENT_API] createVersion() result:', result);
|
|
232
|
+
return result;
|
|
233
|
+
};
|
|
234
|
+
const updateVersion = async function updateVersion({ id, collection, req, versionData, where, ...args }) {
|
|
235
|
+
console.log('🔍 [DB_CONTENT_API] updateVersion() called with:', {
|
|
236
|
+
id,
|
|
237
|
+
collection,
|
|
238
|
+
versionData,
|
|
239
|
+
...args
|
|
240
|
+
});
|
|
241
|
+
const result = {};
|
|
242
|
+
console.log('[DB_CONTENT_API] updateVersion() result:', result);
|
|
243
|
+
return result;
|
|
244
|
+
};
|
|
245
|
+
const deleteVersions = async function deleteVersions({ collection, req, where, ...args }) {
|
|
246
|
+
console.log('🔍 [DB_CONTENT_API] deleteVersions() called with:', {
|
|
247
|
+
collection,
|
|
248
|
+
where,
|
|
249
|
+
...args
|
|
250
|
+
});
|
|
251
|
+
const versionsToDelete = [];
|
|
252
|
+
const versionCollection = 'versions';
|
|
253
|
+
console.log(`🗑️ [DB_CONTENT_API] Deleted ${versionsToDelete.length} versions from ${versionCollection}`);
|
|
254
|
+
// return versionsToDelete.length
|
|
255
|
+
};
|
|
256
|
+
const findOne = async function findOne({ collection, req, where, ...args }) {
|
|
257
|
+
console.log('🔍 [DB_CONTENT_API] findOne() called with:', collection, JSON.stringify(transformWhereClause(where), null, 2), args, req?.body);
|
|
258
|
+
try {
|
|
259
|
+
const response = await this.request('/api/v0/documents:find', {
|
|
260
|
+
collectionKey: collection,
|
|
261
|
+
contentSystemId: this.contentSystemId,
|
|
262
|
+
limit: 1,
|
|
263
|
+
offset: 0,
|
|
264
|
+
where: transformWhereClause(where)
|
|
265
|
+
});
|
|
266
|
+
if (response.error) {
|
|
267
|
+
console.error('[DB_CONTENT_API] findOne() failure', response.error?.message || response.error);
|
|
268
|
+
}
|
|
269
|
+
const docs = response.result?.data || [];
|
|
270
|
+
const result = docs.length > 0 ? docs[0] : null;
|
|
271
|
+
console.log('[DB_CONTENT_API] findOne() result:', result);
|
|
272
|
+
return formatDocument(result);
|
|
273
|
+
} catch (error) {
|
|
274
|
+
console.error(`❌ [DB_CONTENT_API] Error in findOne():`, error);
|
|
275
|
+
return null;
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
const updateMany = async function updateMany({ collection, data, req, where, ...args }) {
|
|
279
|
+
console.log('🔍 [DB_CONTENT_API] updateMany() called with:', {
|
|
280
|
+
collection,
|
|
281
|
+
data,
|
|
282
|
+
where,
|
|
283
|
+
...args
|
|
284
|
+
});
|
|
285
|
+
try {
|
|
286
|
+
const response = await this.request('/api/v0/documents:update', {
|
|
287
|
+
collectionKey: collection,
|
|
288
|
+
contentSystemId: this.contentSystemId,
|
|
289
|
+
createOnMissing: false,
|
|
290
|
+
data,
|
|
291
|
+
where: transformWhereClause(where)
|
|
292
|
+
});
|
|
293
|
+
if (response.error) {
|
|
294
|
+
console.error('[DB_CONTENT_API] updateMany() failure', response.error?.message || response.error);
|
|
295
|
+
}
|
|
296
|
+
// Return array of updated documents if available, otherwise return placeholder
|
|
297
|
+
const result = response.result?.data || [];
|
|
298
|
+
console.log('[DB_CONTENT_API] updateMany() result:', result);
|
|
299
|
+
return result;
|
|
300
|
+
} catch (error) {
|
|
301
|
+
console.error(`❌ [DB_CONTENT_API] Error in updateMany():`, error);
|
|
302
|
+
return [];
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
const updateOne = async function updateOne({ id, collection, data, req, where = {}, ...args }) {
|
|
306
|
+
console.log('🔍 [DB_CONTENT_API] updateOne() called with:', {
|
|
307
|
+
id,
|
|
308
|
+
collection,
|
|
309
|
+
data,
|
|
310
|
+
where,
|
|
311
|
+
...args
|
|
312
|
+
});
|
|
313
|
+
try {
|
|
314
|
+
const whereClause = id ? {
|
|
315
|
+
operator: 'equals',
|
|
316
|
+
path: 'id',
|
|
317
|
+
value: id
|
|
318
|
+
} : transformWhereClause(where);
|
|
319
|
+
const response = await this.request('/api/v0/documents:update', {
|
|
320
|
+
collectionKey: collection,
|
|
321
|
+
contentSystemId: this.contentSystemId,
|
|
322
|
+
createOnMissing: false,
|
|
323
|
+
data,
|
|
324
|
+
returning: {
|
|
325
|
+
exclude: []
|
|
326
|
+
},
|
|
327
|
+
where: whereClause
|
|
328
|
+
});
|
|
329
|
+
if (response.error) {
|
|
330
|
+
console.error('[DB_CONTENT_API] updateOne() failure', response.error?.message || response.error);
|
|
331
|
+
}
|
|
332
|
+
const result = response.result?.data || {
|
|
333
|
+
id,
|
|
334
|
+
...data
|
|
335
|
+
};
|
|
336
|
+
console.log('[DB_CONTENT_API] updateOne() result:', result);
|
|
337
|
+
return result;
|
|
338
|
+
} catch (error) {
|
|
339
|
+
console.error(`❌ [DB_CONTENT_API] Error in updateOne():`, error);
|
|
340
|
+
return {
|
|
341
|
+
id,
|
|
342
|
+
...data
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
const deleteMany = async function deleteMany({ collection, req, where, ...args }) {
|
|
347
|
+
console.log('🔍 [DB_CONTENT_API] deleteMany() called with:', {
|
|
348
|
+
collection,
|
|
349
|
+
where,
|
|
350
|
+
...args
|
|
351
|
+
});
|
|
352
|
+
try {
|
|
353
|
+
const response = await this.request('/api/v0/documents:delete', {
|
|
354
|
+
collectionKey: collection,
|
|
355
|
+
contentSystemId: this.contentSystemId,
|
|
356
|
+
returning: false,
|
|
357
|
+
where: transformWhereClause(where)
|
|
358
|
+
});
|
|
359
|
+
if (response.error) {
|
|
360
|
+
console.error('[DB_CONTENT_API] deleteMany() failure', response.error?.message || response.error);
|
|
361
|
+
}
|
|
362
|
+
const deletedCount = response.result?.count || 0;
|
|
363
|
+
console.log(`🗑️ [DB_CONTENT_API] Deleted ${deletedCount} documents from ${collection}`);
|
|
364
|
+
} catch (error) {
|
|
365
|
+
console.error(`❌ [DB_CONTENT_API] Error in deleteMany():`, error);
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
const deleteOne = async function deleteOne({ collection, req, where, ...args }) {
|
|
369
|
+
console.log('🔍 [DB_CONTENT_API] deleteOne() called with:', {
|
|
370
|
+
collection,
|
|
371
|
+
where,
|
|
372
|
+
...args
|
|
373
|
+
});
|
|
374
|
+
try {
|
|
375
|
+
const response = await this.request('/api/v0/documents:delete', {
|
|
376
|
+
collectionKey: collection,
|
|
377
|
+
contentSystemId: this.contentSystemId,
|
|
378
|
+
returning: {
|
|
379
|
+
exclude: []
|
|
380
|
+
},
|
|
381
|
+
where: transformWhereClause(where)
|
|
382
|
+
});
|
|
383
|
+
if (response.error) {
|
|
384
|
+
console.error('[DB_CONTENT_API] deleteOne() failure', response.error?.message || response.error);
|
|
385
|
+
}
|
|
386
|
+
const deletedDocs = response.result?.data || [];
|
|
387
|
+
const docId = deletedDocs.length > 0 ? deletedDocs[0].id : 'unknown';
|
|
388
|
+
const result = deletedDocs.length > 0 ? deletedDocs[0] : {};
|
|
389
|
+
console.log(`🗑️ [DB_CONTENT_API] Deleted document ${docId} from ${collection}`);
|
|
390
|
+
console.log('[DB_CONTENT_API] deleteOne() result:', result);
|
|
391
|
+
return result;
|
|
392
|
+
} catch (error) {
|
|
393
|
+
console.error(`❌ [DB_CONTENT_API] Error in deleteOne():`, error);
|
|
394
|
+
return {};
|
|
395
|
+
}
|
|
396
|
+
};
|
|
397
|
+
const create = async function create({ collection, data, req, ...args }) {
|
|
398
|
+
console.log('🔍 [DB_CONTENT_API] create() called with:', {
|
|
399
|
+
collection,
|
|
400
|
+
data,
|
|
401
|
+
...args
|
|
402
|
+
});
|
|
403
|
+
try {
|
|
404
|
+
const randomKey = randomUUID();
|
|
405
|
+
const response = await this.request('/api/v0/documents:create', {
|
|
406
|
+
collectionKey: collection,
|
|
407
|
+
contentSystemId: this.contentSystemId,
|
|
408
|
+
data,
|
|
409
|
+
key: data.key || data.id || `doc-${randomKey}`
|
|
410
|
+
});
|
|
411
|
+
if (response.error) {
|
|
412
|
+
console.error('[DB_CONTENT_API] create() failure', response.error?.message || response.error);
|
|
413
|
+
}
|
|
414
|
+
const result = response.result?.data || response.result || {
|
|
415
|
+
id: `doc-${randomKey}`,
|
|
416
|
+
...data
|
|
417
|
+
};
|
|
418
|
+
console.log('[DB_CONTENT_API] create() result:', result);
|
|
419
|
+
return result;
|
|
420
|
+
} catch (error) {
|
|
421
|
+
console.error(`❌ [DB_CONTENT_API] Error in create():`, error);
|
|
422
|
+
return {
|
|
423
|
+
id: `doc-${randomUUID()}`,
|
|
424
|
+
...data
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
const count = async function count({ collection, req, where = {}, ...args }) {
|
|
429
|
+
console.log('🔍 [DB_CONTENT_API] count() called with:', {
|
|
430
|
+
collection,
|
|
431
|
+
where,
|
|
432
|
+
...args
|
|
433
|
+
});
|
|
434
|
+
try {
|
|
435
|
+
const response = await this.request('/api/v0/documents:count', {
|
|
436
|
+
collectionKey: collection,
|
|
437
|
+
contentSystemId: this.contentSystemId,
|
|
438
|
+
where: transformWhereClause(where)
|
|
439
|
+
});
|
|
440
|
+
if (response.error) {
|
|
441
|
+
console.error('[DB_CONTENT_API] count() failure', response.error?.message || response.error);
|
|
442
|
+
}
|
|
443
|
+
const result = {
|
|
444
|
+
totalDocs: response.result?.count || 0
|
|
445
|
+
};
|
|
446
|
+
console.log('[DB_CONTENT_API] count() result:', result);
|
|
447
|
+
return result;
|
|
448
|
+
} catch (error) {
|
|
449
|
+
console.error(`❌ [DB_CONTENT_API] Error in count():`, error);
|
|
450
|
+
return {
|
|
451
|
+
totalDocs: 0
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
};
|
|
455
|
+
const countVersions = async function countVersions({ collection, req, where, ...args }) {
|
|
456
|
+
console.log('🔍 [DB_CONTENT_API] countVersions() called with:', {
|
|
457
|
+
collection,
|
|
458
|
+
where,
|
|
459
|
+
...args
|
|
460
|
+
});
|
|
461
|
+
const result = {
|
|
462
|
+
totalDocs: 0
|
|
463
|
+
};
|
|
464
|
+
console.log('[DB_CONTENT_API] countVersions() result:', result);
|
|
465
|
+
return result;
|
|
466
|
+
};
|
|
467
|
+
const upsert = async function upsert({ collection, data, req, where, ...args }) {
|
|
468
|
+
console.log('🔍 [DB_CONTENT_API] upsert() called with:', {
|
|
469
|
+
collection,
|
|
470
|
+
data,
|
|
471
|
+
where,
|
|
472
|
+
...args
|
|
473
|
+
});
|
|
474
|
+
try {
|
|
475
|
+
// Try to update first
|
|
476
|
+
const updateResponse = await this.request('/api/v0/documents:update', {
|
|
477
|
+
collectionKey: collection,
|
|
478
|
+
contentSystemId: this.contentSystemId,
|
|
479
|
+
createOnMissing: {
|
|
480
|
+
documentKey: `upsert-${Date.now()}`
|
|
481
|
+
},
|
|
482
|
+
data,
|
|
483
|
+
returning: {
|
|
484
|
+
exclude: []
|
|
485
|
+
},
|
|
486
|
+
where: transformWhereClause(where)
|
|
487
|
+
});
|
|
488
|
+
if (!updateResponse.success) {
|
|
489
|
+
console.log('[DB_CONTENT_API] upsert() failure', updateResponse.error);
|
|
490
|
+
}
|
|
491
|
+
const result = updateResponse.result?.data || {
|
|
492
|
+
...data
|
|
493
|
+
};
|
|
494
|
+
console.log('[DB_CONTENT_API] upsert() result:', result);
|
|
495
|
+
return result;
|
|
496
|
+
} catch (error) {
|
|
497
|
+
console.error(`❌ [DB_CONTENT_API] Error in upsert():`, error);
|
|
498
|
+
return {
|
|
499
|
+
...data
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
};
|
|
503
|
+
const createGlobal = async function createGlobal({ slug, data, req, ...args }) {
|
|
504
|
+
console.log('🔍 [DB_CONTENT_API] createGlobal() called with:', {
|
|
505
|
+
slug,
|
|
506
|
+
data,
|
|
507
|
+
...args
|
|
508
|
+
});
|
|
509
|
+
try {
|
|
510
|
+
const globalKey = getGlobalSlug(slug);
|
|
511
|
+
const response = await this.request('/api/v0/documents:create', {
|
|
512
|
+
collectionKey: globalKey,
|
|
513
|
+
contentSystemId: this.contentSystemId,
|
|
514
|
+
data,
|
|
515
|
+
key: `global-${slug}`
|
|
516
|
+
});
|
|
517
|
+
if (response.error) {
|
|
518
|
+
console.error('[DB_CONTENT_API] createGlobal() failure', response.error?.message || response.error);
|
|
519
|
+
}
|
|
520
|
+
const result = response.result?.data || response.result || {
|
|
521
|
+
id: `global-${slug}`,
|
|
522
|
+
...data
|
|
523
|
+
};
|
|
524
|
+
console.log('[DB_CONTENT_API] createGlobal() result:', result);
|
|
525
|
+
return result;
|
|
526
|
+
} catch (error) {
|
|
527
|
+
console.error(`❌ [DB_CONTENT_API] Error in createGlobal():`, error);
|
|
528
|
+
return {
|
|
529
|
+
id: `global-${slug}`,
|
|
530
|
+
...data
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
};
|
|
534
|
+
const findGlobal = async function findGlobal({ slug, req, ...args }) {
|
|
535
|
+
console.log('🔍 [DB_CONTENT_API] findGlobal() called with:', {
|
|
536
|
+
slug,
|
|
537
|
+
...args
|
|
538
|
+
});
|
|
539
|
+
try {
|
|
540
|
+
const globalKey = getGlobalSlug(slug);
|
|
541
|
+
const response = await this.request('/api/v0/documents:find', {
|
|
542
|
+
collectionKey: globalKey,
|
|
543
|
+
contentSystemId: this.contentSystemId,
|
|
544
|
+
limit: 1,
|
|
545
|
+
offset: 0
|
|
546
|
+
});
|
|
547
|
+
if (response.error) {
|
|
548
|
+
console.error('[DB_CONTENT_API] findGlobal() failure', response.error?.message || response.error);
|
|
549
|
+
}
|
|
550
|
+
const docs = response.result?.data || [];
|
|
551
|
+
const result = docs.length > 0 ? docs[0] : null;
|
|
552
|
+
console.log('[DB_CONTENT_API] findGlobal() result:', result);
|
|
553
|
+
return formatDocument(result);
|
|
554
|
+
} catch (error) {
|
|
555
|
+
console.error(`❌ [DB_CONTENT_API] Error in findGlobal():`, error);
|
|
556
|
+
return null;
|
|
557
|
+
}
|
|
558
|
+
};
|
|
559
|
+
const findDistinct = async function findDistinct({ collection, field, limit, page = 1, req, where, ...args }) {
|
|
560
|
+
console.log('🔍 [DB_CONTENT_API] findDistinct() called with:', {
|
|
561
|
+
collection,
|
|
562
|
+
field,
|
|
563
|
+
limit,
|
|
564
|
+
page,
|
|
565
|
+
where,
|
|
566
|
+
...args
|
|
567
|
+
});
|
|
568
|
+
const distinctValues = [];
|
|
569
|
+
const paginatedValues = [];
|
|
570
|
+
const endIndex = 0;
|
|
571
|
+
const totalDocs = 0;
|
|
572
|
+
console.log(`📊 [DB_CONTENT_API] findDistinct result: ${distinctValues.length} distinct values for ${field}`);
|
|
573
|
+
return {
|
|
574
|
+
hasNextPage: limit ? endIndex < totalDocs : false,
|
|
575
|
+
hasPrevPage: page > 1,
|
|
576
|
+
limit: limit || totalDocs,
|
|
577
|
+
nextPage: limit && endIndex < totalDocs ? page + 1 : null,
|
|
578
|
+
page,
|
|
579
|
+
pagingCounter: 1,
|
|
580
|
+
prevPage: page > 1 ? page - 1 : null,
|
|
581
|
+
totalDocs,
|
|
582
|
+
totalPages: limit ? Math.ceil(totalDocs / limit) : 1,
|
|
583
|
+
values: paginatedValues
|
|
584
|
+
};
|
|
585
|
+
};
|
|
586
|
+
const updateGlobal = async function updateGlobal({ slug, data, req, ...args }) {
|
|
587
|
+
console.log('🔍 [DB_CONTENT_API] updateGlobal() called with:', {
|
|
588
|
+
slug,
|
|
589
|
+
data,
|
|
590
|
+
...args
|
|
591
|
+
});
|
|
592
|
+
try {
|
|
593
|
+
const globalKey = getGlobalSlug(slug);
|
|
594
|
+
const response = await this.request('/api/v0/documents:update', {
|
|
595
|
+
collectionKey: globalKey,
|
|
596
|
+
contentSystemId: this.contentSystemId,
|
|
597
|
+
createOnMissing: {
|
|
598
|
+
documentKey: `global-${slug}`
|
|
599
|
+
},
|
|
600
|
+
data,
|
|
601
|
+
returning: {
|
|
602
|
+
exclude: []
|
|
603
|
+
},
|
|
604
|
+
where: {
|
|
605
|
+
operator: 'equals',
|
|
606
|
+
path: 'key',
|
|
607
|
+
value: `global-${slug}`
|
|
608
|
+
}
|
|
609
|
+
});
|
|
610
|
+
if (response.error) {
|
|
611
|
+
console.error('[DB_CONTENT_API] updateGlobal() failure', response.error?.message || response.error);
|
|
612
|
+
}
|
|
613
|
+
const result = response.result?.data || {
|
|
614
|
+
id: `global-${slug}`,
|
|
615
|
+
...data
|
|
616
|
+
};
|
|
617
|
+
console.log('[DB_CONTENT_API] updateGlobal() result:', result);
|
|
618
|
+
return result;
|
|
619
|
+
} catch (error) {
|
|
620
|
+
console.error(`❌ [DB_CONTENT_API] Error in updateGlobal():`, error);
|
|
621
|
+
return {
|
|
622
|
+
id: `global-${slug}`,
|
|
623
|
+
...data
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
};
|
|
627
|
+
const findGlobalVersions = async function findGlobalVersions({ limit, page = 1, req, where, ...args }) {
|
|
628
|
+
console.log('🔍 [DB_CONTENT_API] findGlobalVersions() called with:', {
|
|
629
|
+
limit,
|
|
630
|
+
page,
|
|
631
|
+
where,
|
|
632
|
+
...args
|
|
633
|
+
});
|
|
634
|
+
const docs = [];
|
|
635
|
+
const hasNextPage = false;
|
|
636
|
+
const result = {
|
|
637
|
+
docs,
|
|
638
|
+
hasNextPage,
|
|
639
|
+
hasPrevPage: page > 1,
|
|
640
|
+
limit: limit || docs.length,
|
|
641
|
+
nextPage: hasNextPage ? page + 1 : null,
|
|
642
|
+
page,
|
|
643
|
+
pagingCounter: 1,
|
|
644
|
+
prevPage: page > 1 ? page - 1 : null,
|
|
645
|
+
totalDocs: docs.length,
|
|
646
|
+
totalPages: limit && docs.length ? Math.ceil(docs.length / limit) : 1
|
|
647
|
+
};
|
|
648
|
+
console.log('[DB_CONTENT_API] findGlobalVersions() result:', result);
|
|
649
|
+
return result;
|
|
650
|
+
};
|
|
651
|
+
const createGlobalVersion = async function createGlobalVersion({ req, versionData, ...args }) {
|
|
652
|
+
console.log('🔍 [DB_CONTENT_API] createGlobalVersion() called with:', {
|
|
653
|
+
versionData,
|
|
654
|
+
...args
|
|
655
|
+
});
|
|
656
|
+
const result = {};
|
|
657
|
+
console.log('[DB_CONTENT_API] createGlobalVersion() result:', result);
|
|
658
|
+
return result;
|
|
659
|
+
};
|
|
660
|
+
const updateGlobalVersion = async function updateGlobalVersion({ id, req, versionData, ...args }) {
|
|
661
|
+
console.log('🔍 [DB_CONTENT_API] updateGlobalVersion() called with:', {
|
|
662
|
+
id,
|
|
663
|
+
versionData,
|
|
664
|
+
...args
|
|
665
|
+
});
|
|
666
|
+
const result = {};
|
|
667
|
+
console.log('[DB_CONTENT_API] updateGlobalVersion() result:', result);
|
|
668
|
+
return result;
|
|
669
|
+
};
|
|
670
|
+
const countGlobalVersions = async function countGlobalVersions({ req, where, ...args }) {
|
|
671
|
+
console.log('🔍 [DB_CONTENT_API] countGlobalVersions() called with:', {
|
|
672
|
+
where,
|
|
673
|
+
...args
|
|
674
|
+
});
|
|
675
|
+
const totalDocs = 0;
|
|
676
|
+
const globalVersionsSlug = 'global-versions';
|
|
677
|
+
console.log(`📊 [DB_CONTENT_API] countGlobalVersions result: ${totalDocs} versions in ${globalVersionsSlug}`);
|
|
678
|
+
const result = {
|
|
679
|
+
totalDocs
|
|
680
|
+
};
|
|
681
|
+
console.log('[DB_CONTENT_API] countGlobalVersions() result:', result);
|
|
682
|
+
return result;
|
|
683
|
+
};
|
|
684
|
+
const request = async function(path, body = {}) {
|
|
685
|
+
console.log('🔍 [DB_CONTENT_API] request() called with:', {
|
|
686
|
+
body,
|
|
687
|
+
path
|
|
688
|
+
});
|
|
689
|
+
const res = await fetch(`${this.contentApiUrl}${path}`, {
|
|
690
|
+
body: JSON.stringify({
|
|
691
|
+
contentSystemId: this.contentSystemId,
|
|
692
|
+
...body
|
|
693
|
+
}),
|
|
694
|
+
headers: {
|
|
695
|
+
Authorization: `Bearer ${this.projectToken}`,
|
|
696
|
+
'Content-Type': 'application/json',
|
|
697
|
+
'X-Api-Key': this.contentApiKey
|
|
698
|
+
},
|
|
699
|
+
method: 'POST'
|
|
700
|
+
});
|
|
701
|
+
return res.json();
|
|
702
|
+
};
|
|
703
|
+
const beginTransaction = async function(options) {
|
|
704
|
+
console.log('🔍 [DB_CONTENT_API] beginTransaction() called', options);
|
|
705
|
+
return null;
|
|
706
|
+
};
|
|
707
|
+
const commitTransaction = async function(id) {
|
|
708
|
+
console.log('🔍 [DB_CONTENT_API] commitTransaction() called', id);
|
|
709
|
+
};
|
|
710
|
+
export const contentAPIAdapter = (opts)=>{
|
|
711
|
+
return {
|
|
712
|
+
name: 'content_api',
|
|
713
|
+
defaultIDType: 'text',
|
|
714
|
+
init: ({ payload })=>{
|
|
715
|
+
return createDatabaseAdapter({
|
|
716
|
+
name: 'content_api',
|
|
717
|
+
beginTransaction,
|
|
718
|
+
commitTransaction,
|
|
719
|
+
contentApiKey: opts.contentApiKey,
|
|
720
|
+
contentApiUrl: opts.contentApiUrl,
|
|
721
|
+
contentSystemId: opts.contentSystemId,
|
|
722
|
+
count,
|
|
723
|
+
countGlobalVersions,
|
|
724
|
+
countVersions,
|
|
725
|
+
create,
|
|
726
|
+
createGlobal,
|
|
727
|
+
createGlobalVersion,
|
|
728
|
+
createVersion,
|
|
729
|
+
defaultIDType: 'text',
|
|
730
|
+
deleteMany,
|
|
731
|
+
deleteOne,
|
|
732
|
+
deleteVersions,
|
|
733
|
+
find,
|
|
734
|
+
findDistinct,
|
|
735
|
+
findGlobal,
|
|
736
|
+
findGlobalVersions,
|
|
737
|
+
findOne,
|
|
738
|
+
findVersions,
|
|
739
|
+
init,
|
|
740
|
+
packageName: '@payloadcms/db-content-api',
|
|
741
|
+
payload,
|
|
742
|
+
projectToken: opts.projectToken,
|
|
743
|
+
queryDrafts,
|
|
744
|
+
request,
|
|
745
|
+
rollbackTransaction: async ()=>{},
|
|
746
|
+
updateGlobal,
|
|
747
|
+
updateGlobalVersion,
|
|
748
|
+
updateMany,
|
|
749
|
+
updateOne,
|
|
750
|
+
updateVersion,
|
|
751
|
+
upsert
|
|
752
|
+
});
|
|
753
|
+
}
|
|
754
|
+
};
|
|
755
|
+
};
|
|
756
|
+
|
|
757
|
+
//# sourceMappingURL=db-adapter.js.map
|