diff --git a/.gitignore b/.gitignore index 488b755..f2b2b84 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,4 @@ node_modules dist -test.* \ No newline at end of file +test.* diff --git a/src/clients/bucket/lib/methodChaining.ts b/src/clients/bucket/lib/methodChaining.ts index 96e2858..3b4cf4f 100644 --- a/src/clients/bucket/lib/methodChaining.ts +++ b/src/clients/bucket/lib/methodChaining.ts @@ -8,18 +8,50 @@ export default class MethodChaining { } props(props: string | Array) { - let propStr = props; - if (Array.isArray(propStr)) { - propStr = propStr - .filter((prop) => typeof prop === 'string') + let propStr: string; + + if (typeof props === 'string') { + propStr = + props.startsWith('{') && props.endsWith('}') + ? this.parseGraphQLProps(props.slice(1, -1)) + : props; + } else if (Array.isArray(props)) { + propStr = props + .filter((prop): prop is string => typeof prop === 'string') .map((prop) => prop.trim()) - .filter((prop) => !!prop) - .toString(); + .filter(Boolean) + .join(','); + } else { + throw new Error('Invalid props type'); } - this.endpoint += `&props=${propStr}`; + this.endpoint += `&props=${encodeURIComponent(propStr)}`; return this; } + private parseGraphQLProps(propsString: string): string { + const lines = propsString + .split('\n') + .map((line) => line.trim()) + .filter(Boolean); + const result: string[] = []; + const currentPath: string[] = []; + + for (const line of lines) { + if (line.includes('{')) { + const [key] = line.split('{'); + if (key !== undefined) { + currentPath.push(key.trim()); + } + } else if (line === '}') { + currentPath.pop(); + } else { + result.push([...currentPath, line].join('.')); + } + } + + return result.join(','); + } + sort(sort: string) { this.endpoint += `&sort=${sort}`; return this; diff --git a/src/clients/bucket/media/index.ts b/src/clients/bucket/media/index.ts index 5f58d19..0c3f721 100644 --- a/src/clients/bucket/media/index.ts +++ b/src/clients/bucket/media/index.ts @@ -48,9 +48,6 @@ export const mediaChainMethods = ( if (params.metadata) { data.append('metadata', JSON.stringify(params.metadata)); } - if (params.alt_text) { - data.append('alt_text', params.alt_text); - } if (params.trigger_webhook) { data.append('trigger_webhook', params.trigger_webhook.toString()); } diff --git a/src/types/media.types.ts b/src/types/media.types.ts index d1bf32e..c50f7fc 100644 --- a/src/types/media.types.ts +++ b/src/types/media.types.ts @@ -3,7 +3,6 @@ import { GenericObject } from './generic.types'; export type InsertMediaType = { media: any; folder?: string; - alt_text?: string; metadata?: GenericObject; trigger_webhook?: boolean; };