diff --git a/packages/objectloader2/src/core/objectLoader2Factory.ts b/packages/objectloader2/src/core/objectLoader2Factory.ts index 0e0d887ca..8dc845a27 100644 --- a/packages/objectloader2/src/core/objectLoader2Factory.ts +++ b/packages/objectloader2/src/core/objectLoader2Factory.ts @@ -1,5 +1,5 @@ import { CustomLogger, getFeatureFlag, ObjectLoader2Flags } from '../types/functions.js' -import { Base } from '../types/types.js' +import { Base, ObjectAttributeMask } from '../types/types.js' import { ObjectLoader2 } from './objectLoader2.js' import { IndexedDatabase } from './stages/indexedDatabase.js' import { MemoryDatabase } from './stages/memory/memoryDatabase.js' @@ -40,6 +40,7 @@ export class ObjectLoader2Factory { token?: string headers?: Headers options?: ObjectLoader2FactoryOptions + attributeMask: ObjectAttributeMask }): ObjectLoader2 { const log = ObjectLoader2Factory.getLogger(params.options?.logger) let database @@ -67,6 +68,7 @@ export class ObjectLoader2Factory { objectId: params.objectId, token: params.token, headers: params.headers, + attributeMask: params.attributeMask, logger: log || ((): void => {}) }), database, diff --git a/packages/objectloader2/src/core/stages/serverDownloader.ts b/packages/objectloader2/src/core/stages/serverDownloader.ts index b7216f3cc..b1b38f01b 100644 --- a/packages/objectloader2/src/core/stages/serverDownloader.ts +++ b/packages/objectloader2/src/core/stages/serverDownloader.ts @@ -2,7 +2,7 @@ import BatchingQueue from '../../queues/batchingQueue.js' import Queue from '../../queues/queue.js' import { ObjectLoaderRuntimeError } from '../../types/errors.js' import { CustomLogger, Fetcher, indexOf, isBase, take } from '../../types/functions.js' -import { Item } from '../../types/types.js' +import { Item, ObjectAttributeMask } from '../../types/types.js' import { Downloader } from '../interfaces.js' export interface ServerDownloaderOptions { @@ -13,6 +13,7 @@ export interface ServerDownloaderOptions { headers?: Headers logger: CustomLogger fetch?: Fetcher + attributeMask: ObjectAttributeMask } const MAX_SAFARI_DECODE_BYTES = 2 * 1024 * 1024 * 1024 - 1024 * 1024 // 2GB minus a margin @@ -118,11 +119,12 @@ Chrome's behavior: Chrome generally handles larger data sizes without this speci const start = performance.now() this.#logger(`Downloading batch of ${batch.length} items...`) + const attributeMask = this.#options.attributeMask const keys = new Set(batch) const response = await this.#fetch(url, { method: 'POST', headers: { ...headers, 'Content-Type': 'application/json' }, - body: JSON.stringify({ objectIds: batch }) + body: JSON.stringify({ objectIds: batch, attributeMask }) }) this.#validateResponse(response) diff --git a/packages/objectloader2/src/types/types.ts b/packages/objectloader2/src/types/types.ts index a482b89f0..2b26ab29a 100644 --- a/packages/objectloader2/src/types/types.ts +++ b/packages/objectloader2/src/types/types.ts @@ -19,3 +19,5 @@ export interface Reference { export interface DataChunk extends Base { data?: Base[] } + +export type ObjectAttributeMask = { include: string[] } | { exclude: string[] }