import { deepDiffOn, deepMergeOn } from '@mappedin/mvf-core/locale'; import type { ManifestCollection, ParsedMVF, ParsedMVFLocalePack } from './types/bundle.js'; import type { PartialExcept } from '@mappedin/mvf-core/locale'; export { deepDiffOn, deepMergeOn }; /** * Cleans up the manifest and removes unnecessary folder_struct entries. Used in createLocalePack. * Speficially, it removes folder_struct entries that are not present in the locale pack. * * @param manifest - The original manifest collection. * @param localePack - The partial MVF locale pack. * @returns A ParsedMVFLocalePack with the correct manifest */ export declare function cleanUpManifest(manifest: ManifestCollection, localePack: PartialExcept): ParsedMVFLocalePack; /** * Merges a partial locale pack into a full ParsedMVF object. * * This function uses a deep merge strategy to combine the full ParsedMVF with a partial * locale pack, preserving the original structure while updating or adding new content * from the locale pack. * * It has special handling for arrays containing "identifiable objects" (ie, an object with an * 'id' or 'key' property somewhere in it's structure, like a Feature with 'properties.id' or 'properties.key'). In those cases, * the merge will only update the objects that have a corresponding 'id' or 'key' in the locale pack, by merging * in only the properties that are present in the locale pack. * * This allows a locale pack to contain updates to only some objects in an array, without having to * update every object in the array. * * Also, this function does NOT have detailed understanding of MVF's structure, outside of the manifest, * which should make it robust to changes / additions to MVF in the future. * * Key features: * 1. Clones the original parsed MVF * 2. Deep merges objects and arrays, with special handling for arrays containing objects with 'id' or 'key' properties somewhere. * 3. Adds new properties from the locale pack that don't exist in the full ParsedMVF. * 4. Keeps the original folder_struct from the full ParsedMVF. * * @param full - The complete ParsedMVF object to merge into. * @param partial - The partial ParsedMVFLocalePack containing localized updates. * @returns A new ParsedMVF object that is the result of merging the partial locale pack into the full ParsedMVF. * * * @example * // Basic merge with enterprise extension * // It work with any collection, but this extension is simple to create and read test data for. * const full: ParsedMVF = { * 'enterprise': { * locations: [ * { * id: 'el_store1', * name: 'Clothing Store', * externalId: 'CS001', * type: 'store', * sortOrder: 1, * description: 'A great clothing store', * polygons: [{ map: 'map1', id: 'space1' }], * nodes: [{ map: 'map1', id: 'node1' }] * } * ], * categories: [] * } * }; * * const partial: ParsedMVFLocalePack = { * 'enterprise.json': { * locations: [ * { * id: 'el_store1', * name: 'Magasin de Vêtements', * description: 'Un excellent magasin de vêtements' * } * ] * } * }; * * const result = mergeLocalePack(full, partial); * // Result: * // { * // 'enterprise.json': { * // locations: [ * // { * // id: 'el_store1', * // name: 'Magasin de Vêtements', * // externalId: 'CS001', * // type: 'store', * // sortOrder: 1, * // description: 'Un excellent magasin de vêtements', * // polygons: [{ map: 'map1', id: 'space1' }], * // nodes: [{ map: 'map1', id: 'node1' }] * // } * // ], * // categories: [] * // } * // } * * @example * // Merge with nested arrays containing identifiable objects, showing partial updates * const full: ParsedMVF = { * 'enterprise.json': { * locations: [ * { * id: 'el_store1', * name: 'Store 1', * externalId: 'S1', * type: 'store', * sortOrder: 1, * description: 'A great store', * polygons: [{ map: 'map1', id: 'space1' }], * nodes: [{ map: 'map1', id: 'node1' }] * }, * { * id: 'el_store2', * name: 'Store 2', * externalId: 'S2', * type: 'store', * sortOrder: 2, * description: 'Another great store', * polygons: [{ map: 'map1', id: 'space2' }], * nodes: [{ map: 'map1', id: 'node2' }] * } * ] * } * }; * * const partial: ParsedMVFLocalePack = { * 'enterprise.json': { * locations: [ * { * id: 'el_store1', * name: 'Magasin 1', * description: 'Un excellent magasin' * } * // Note: el_store2 is not included because it hasn't changed * ] * } * }; * * const result = mergeLocalePack(full, partial); * // Result: * // { * // 'enterprise.json': { * // locations: [ * // { * // id: 'el_store1', * // name: 'Magasin 1', * // externalId: 'S1', * // type: 'store', * // sortOrder: 1, * // description: 'Un excellent magasin', * // polygons: [{ map: 'map1', id: 'space1' }], * // nodes: [{ map: 'map1', id: 'node1' }] * // }, * // { * // id: 'el_store2', * // name: 'Store 2', * // externalId: 'S2', * // type: 'store', * // sortOrder: 2, * // description: 'Another great store', * // polygons: [{ map: 'map1', id: 'space2' }], * // nodes: [{ map: 'map1', id: 'node2' }] * // } * // ] * // } * // } * * Note: The merging process always preserves the 'id' field and the structure of the * 'manifest.geojson' file, ensuring the integrity of the MVF structure while allowing * for localized content updates. */ export declare function mergeLocalePack(full: ParsedMVF, partial: ParsedMVFLocalePack): ParsedMVF; /** * Creates a partial locale pack by comparing two full ParsedMVF objects. * * This function generates a ParsedMVFLocalePack by identifying the differences * between a base ParsedMVF and a localized ParsedMVF. It's particularly useful * for extracting localized content changes from a fully localized MVF. * * Key features: * 1. Compares the base and localized ParsedMVF objects deeply. * 2. Includes only the properties and nested objects that differ in the locale pack. * 3. Handles arrays of objects with identifier keys, including only changed items. * 4. Preserves the structure of changed elements while omitting unchanged ones. * 5. Cleans up the manifest to include only relevant folder structure entries. * * @param base - The original ParsedMVF object to compare against. * @param locale - The localized ParsedMVF object containing changes. * @returns A ParsedMVFLocalePack containing only the differences between base and locale. * * @example * // Basic creation of a locale pack with enterprise extension * const base: ParsedMVF = { * 'enterprise.json': { * venue: { * name: 'Shopping Mall', * slug: 'shopping-mall', * externalId: 'SM001', * defaultLanguage: { name: 'English', code: 'en' }, * languages: [{ name: 'English', code: 'en' }, { name: 'French', code: 'fr' }] * }, * locations: [ * { * id: 'el_store1', * name: 'Clothing Store', * externalId: 'CS001', * type: 'store', * sortOrder: 1, * description: 'A great clothing store', * polygons: [{ map: 'map1', id: 'space1' }], * nodes: [{ map: 'map1', id: 'node1' }] * } * ], * categories: [] * } * }; * * const locale: ParsedMVF = { * 'enterprise.json': { * venue: { * name: 'Centre Commercial', * slug: 'shopping-mall', * externalId: 'SM001', * defaultLanguage: { name: 'English', code: 'en' }, * languages: [{ name: 'English', code: 'en' }, { name: 'French', code: 'fr' }] * }, * locations: [ * { * id: 'el_store1', * name: 'Magasin de Vêtements', * externalId: 'CS001', * type: 'store', * sortOrder: 1, * description: 'Un excellent magasin de vêtements', * polygons: [{ map: 'map1', id: 'space1' }], * nodes: [{ map: 'map1', id: 'node1' }] * } * ], * categories: [] * } * }; * * const result = createLocalePack(base, locale); * // Result: * // { * // 'enterprise.json': { * // venue: { * // name: 'Centre Commercial' * // }, * // locations: [ * // { * // id: 'el_store1', * // name: 'Magasin de Vêtements', * // description: 'Un excellent magasin de vêtements' * // } * // ] * // } * // } * * @example * // Creating a locale pack with partial changes in nested arrays * const base: ParsedMVF = { * 'enterprise.json': { * locations: [ * { * id: 'el_store1', * name: 'Store 1', * externalId: 'S1', * type: 'store', * sortOrder: 1, * description: 'A great store', * polygons: [{ map: 'map1', id: 'space1' }], * nodes: [{ map: 'map1', id: 'node1' }] * }, * { * id: 'el_store2', * name: 'Store 2', * externalId: 'S2', * type: 'store', * sortOrder: 2, * description: 'Another great store', * polygons: [{ map: 'map1', id: 'space2' }], * nodes: [{ map: 'map1', id: 'node2' }] * } * ] * } * }; * * const locale: ParsedMVF = { * 'enterprise.json': { * locations: [ * { * id: 'el_store1', * name: 'Magasin 1', * externalId: 'S1', * type: 'store', * sortOrder: 1, * description: 'Un excellent magasin', * polygons: [{ map: 'map1', id: 'space1' }], * nodes: [{ map: 'map1', id: 'node1' }] * }, * { * id: 'el_store2', * name: 'Store 2', * externalId: 'S2', * type: 'store', * sortOrder: 2, * description: 'Another great store', * polygons: [{ map: 'map1', id: 'space2' }], * nodes: [{ map: 'map1', id: 'node2' }] * } * ] * } * }; * * const result = createLocalePack(base, locale); * // Result: * // { * // 'enterprise.json': { * // locations: [ * // { * // id: 'el_store1', * // name: 'Magasin 1', * // description: 'Un excellent magasin' * // } * // // Note: el_store2 is not included because it hasn't changed * // ] * // } * // } * * Note: The resulting locale pack includes only the changed properties and * maintains the structure necessary for these changes. The manifest is also * cleaned up to include only relevant folder structure entries. */ export declare function createLocalePack(base: ParsedMVF, locale: ParsedMVF): ParsedMVFLocalePack; //# sourceMappingURL=locale.d.ts.map