{"version":3,"file":"loadJSON.mjs","names":[],"sources":["../../src/loadJSON.ts"],"sourcesContent":["import {\n  createFileAdapter,\n  createSyncPlugin,\n  type SplitKeysMode,\n} from '@intlayer/engine/syncPluginKit';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { DictionaryFormat } from '@intlayer/types/dictionary';\nimport type { FilePathPattern } from '@intlayer/types/filePathPattern';\nimport type { Plugin } from '@intlayer/types/plugin';\nimport { jsonCodec, readJSONEntry } from './jsonCodec';\n\nexport type LoadJSONPluginOptions = {\n  /**\n   * The source of the plugin.\n   * Is a function to build the source from the key and locale.\n   *\n   * @example\n   * ```ts\n   * loadJSON({\n   *   source: ({ key }) => `blog/${'**'}/${key}.i18n.json`,\n   * })\n   * ```\n   */\n  source: FilePathPattern;\n\n  /**\n   * Locale\n   *\n   * If not provided, the plugin will consider the default locale.\n   *\n   * @example\n   * ```ts\n   * loadJSON({\n   *   source: ({ key }) => `blog/${'**'}/${key}.i18n.json`,\n   *   locale: Locales.ENGLISH,\n   * })\n   * ```\n   */\n  locale?: Locale;\n\n  /**\n   * Because Intlayer transform the JSON files into Dictionary, we need to identify the plugin in the dictionary.\n   * Used to identify the plugin in the dictionary.\n   *\n   * In the case you have multiple plugins, you can use this to identify the plugin in the dictionary.\n   *\n   * @example\n   * ```ts\n   * const config = {\n   *   plugins: [\n   *     loadJSON({\n   *       source: ({ key }) => `./resources/${key}.json`,\n   *       location: 'plugin-i18next',\n   *     }),\n   *     loadJSON({\n   *       source: ({ key }) => `./messages/${key}.json`,\n   *       location: 'plugin-next-intl',\n   *     }),\n   *   ]\n   * }\n   * ```\n   */\n  location?: string;\n\n  /**\n   * The priority of the dictionaries created by the plugin.\n   *\n   * In the case of conflicts with remote dictionaries, or .content files, the dictionary with the highest priority will override the other dictionaries.\n   *\n   * Default is -1. (.content file priority is 0)\n   *\n   */\n  priority?: number;\n\n  /**\n   * The format of the dictionary content.\n   *\n   * @example\n   * ```ts\n   * loadJSON({\n   *   format: 'icu',\n   * })\n   * ```\n   */\n  format?: DictionaryFormat;\n\n  /**\n   * Whether each top-level key of the JSON file should become its own\n   * dictionary (keyed by that top-level key) instead of a single dictionary\n   * holding the whole file.\n   *\n   * This matches the namespace model of libraries such as `next-intl` /\n   * `react-intl`, where a single `messages/{locale}.json` file groups several\n   * namespaces by its first-level keys.\n   *\n   * When omitted, it is auto-detected: the file is split when the `source`\n   * pattern has no `{{key}}` segment, and kept as a single dictionary otherwise.\n   */\n  splitKeys?: SplitKeysMode;\n};\n\n/**\n * Read-only JSON ingestion plugin: loads JSON message files as dictionaries\n * without ever writing back to them.\n */\nexport const loadJSON = (options: LoadJSONPluginOptions): Plugin =>\n  createSyncPlugin({\n    name: 'load-json',\n    adapter: createFileAdapter({\n      source: options.source,\n      codec: jsonCodec,\n      readEntry: readJSONEntry,\n      discovery: 'inclusive',\n    }),\n    direction: 'pull',\n    location: options.location ?? 'plugin',\n    priority: options.priority ?? 0,\n    format: options.format,\n    splitKeys: options.splitKeys,\n    localeOverride: options.locale,\n  });\n"],"mappings":";;;;;;;;AAyGA,MAAa,YAAY,YACvB,iBAAiB;CACf,MAAM;CACN,SAAS,kBAAkB;EACzB,QAAQ,QAAQ;EAChB,OAAO;EACP,WAAW;EACX,WAAW;CACb,CAAC;CACD,WAAW;CACX,UAAU,QAAQ,YAAY;CAC9B,UAAU,QAAQ,YAAY;CAC9B,QAAQ,QAAQ;CAChB,WAAW,QAAQ;CACnB,gBAAgB,QAAQ;AAC1B,CAAC"}