@langchain/core 1.1.47 → 1.1.49-dev-1781044436312

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.
Files changed (470) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/callbacks/base.cjs +2 -3
  3. package/dist/callbacks/base.cjs.map +1 -1
  4. package/dist/callbacks/base.js +1 -2
  5. package/dist/callbacks/base.js.map +1 -1
  6. package/dist/callbacks/dispatch/index.cjs.map +1 -1
  7. package/dist/callbacks/dispatch/index.js.map +1 -1
  8. package/dist/callbacks/manager.cjs +7 -8
  9. package/dist/callbacks/manager.cjs.map +1 -1
  10. package/dist/callbacks/manager.js +1 -2
  11. package/dist/callbacks/manager.js.map +1 -1
  12. package/dist/example_selectors/conditional.cjs.map +1 -1
  13. package/dist/example_selectors/conditional.js.map +1 -1
  14. package/dist/example_selectors/length_based.cjs.map +1 -1
  15. package/dist/example_selectors/length_based.js.map +1 -1
  16. package/dist/example_selectors/semantic_similarity.cjs.map +1 -1
  17. package/dist/example_selectors/semantic_similarity.js.map +1 -1
  18. package/dist/indexing/base.cjs +3 -4
  19. package/dist/indexing/base.cjs.map +1 -1
  20. package/dist/indexing/base.js +1 -2
  21. package/dist/indexing/base.js.map +1 -1
  22. package/dist/language_models/base.cjs +1 -1
  23. package/dist/language_models/base.cjs.map +1 -1
  24. package/dist/language_models/base.js +1 -1
  25. package/dist/language_models/base.js.map +1 -1
  26. package/dist/language_models/chat_models.cjs.map +1 -1
  27. package/dist/language_models/chat_models.js.map +1 -1
  28. package/dist/language_models/compat.cjs.map +1 -1
  29. package/dist/language_models/compat.js.map +1 -1
  30. package/dist/language_models/llms.cjs.map +1 -1
  31. package/dist/language_models/llms.js.map +1 -1
  32. package/dist/language_models/stream.cjs.map +1 -1
  33. package/dist/language_models/stream.js.map +1 -1
  34. package/dist/load/index.cjs.map +1 -1
  35. package/dist/load/index.js.map +1 -1
  36. package/dist/memory.cjs.map +1 -1
  37. package/dist/memory.js.map +1 -1
  38. package/dist/messages/base.cjs.map +1 -1
  39. package/dist/messages/base.d.cts +9 -0
  40. package/dist/messages/base.d.cts.map +1 -1
  41. package/dist/messages/base.d.ts +9 -0
  42. package/dist/messages/base.d.ts.map +1 -1
  43. package/dist/messages/base.js.map +1 -1
  44. package/dist/messages/block_translators/anthropic.cjs.map +1 -1
  45. package/dist/messages/block_translators/anthropic.js.map +1 -1
  46. package/dist/messages/block_translators/bedrock_converse.cjs.map +1 -1
  47. package/dist/messages/block_translators/bedrock_converse.js.map +1 -1
  48. package/dist/messages/block_translators/google.cjs.map +1 -1
  49. package/dist/messages/block_translators/google.js.map +1 -1
  50. package/dist/messages/block_translators/google_vertexai.cjs.map +1 -1
  51. package/dist/messages/block_translators/google_vertexai.js.map +1 -1
  52. package/dist/messages/block_translators/index.cjs +2 -0
  53. package/dist/messages/block_translators/index.cjs.map +1 -1
  54. package/dist/messages/block_translators/index.js +2 -0
  55. package/dist/messages/block_translators/index.js.map +1 -1
  56. package/dist/messages/block_translators/openai.cjs.map +1 -1
  57. package/dist/messages/block_translators/openai.js.map +1 -1
  58. package/dist/messages/block_translators/openrouter.cjs +101 -0
  59. package/dist/messages/block_translators/openrouter.cjs.map +1 -0
  60. package/dist/messages/block_translators/openrouter.js +101 -0
  61. package/dist/messages/block_translators/openrouter.js.map +1 -0
  62. package/dist/messages/index.d.cts +2 -2
  63. package/dist/messages/index.d.ts +2 -2
  64. package/dist/messages/modifier.cjs +6 -0
  65. package/dist/messages/modifier.cjs.map +1 -1
  66. package/dist/messages/modifier.d.cts +9 -4
  67. package/dist/messages/modifier.d.cts.map +1 -1
  68. package/dist/messages/modifier.d.ts +9 -4
  69. package/dist/messages/modifier.d.ts.map +1 -1
  70. package/dist/messages/modifier.js +6 -0
  71. package/dist/messages/modifier.js.map +1 -1
  72. package/dist/messages/transformers.cjs.map +1 -1
  73. package/dist/messages/transformers.js.map +1 -1
  74. package/dist/messages/utils.cjs +16 -2
  75. package/dist/messages/utils.cjs.map +1 -1
  76. package/dist/messages/utils.d.cts +9 -1
  77. package/dist/messages/utils.d.cts.map +1 -1
  78. package/dist/messages/utils.d.ts +9 -1
  79. package/dist/messages/utils.d.ts.map +1 -1
  80. package/dist/messages/utils.js +16 -2
  81. package/dist/messages/utils.js.map +1 -1
  82. package/dist/output_parsers/openai_functions/json_output_functions_parsers.cjs.map +1 -1
  83. package/dist/output_parsers/openai_functions/json_output_functions_parsers.js.map +1 -1
  84. package/dist/output_parsers/openai_tools/json_output_tools_parsers.cjs.map +1 -1
  85. package/dist/output_parsers/openai_tools/json_output_tools_parsers.js.map +1 -1
  86. package/dist/output_parsers/structured.cjs.map +1 -1
  87. package/dist/output_parsers/structured.js.map +1 -1
  88. package/dist/output_parsers/xml.cjs.map +1 -1
  89. package/dist/output_parsers/xml.js.map +1 -1
  90. package/dist/prompts/base.cjs.map +1 -1
  91. package/dist/prompts/base.js.map +1 -1
  92. package/dist/prompts/chat.cjs.map +1 -1
  93. package/dist/prompts/chat.js.map +1 -1
  94. package/dist/prompts/few_shot.cjs.map +1 -1
  95. package/dist/prompts/few_shot.js.map +1 -1
  96. package/dist/prompts/image.cjs.map +1 -1
  97. package/dist/prompts/image.js.map +1 -1
  98. package/dist/prompts/prompt.cjs +1 -1
  99. package/dist/prompts/prompt.cjs.map +1 -1
  100. package/dist/prompts/prompt.d.cts +1 -1
  101. package/dist/prompts/prompt.d.ts +1 -1
  102. package/dist/prompts/prompt.js +1 -1
  103. package/dist/prompts/prompt.js.map +1 -1
  104. package/dist/prompts/string.cjs.map +1 -1
  105. package/dist/prompts/string.js.map +1 -1
  106. package/dist/prompts/template.cjs.map +1 -1
  107. package/dist/prompts/template.js.map +1 -1
  108. package/dist/retrievers/index.cjs.map +1 -1
  109. package/dist/retrievers/index.js.map +1 -1
  110. package/dist/runnables/base.cjs +2 -3
  111. package/dist/runnables/base.cjs.map +1 -1
  112. package/dist/runnables/base.js +1 -2
  113. package/dist/runnables/base.js.map +1 -1
  114. package/dist/runnables/branch.cjs.map +1 -1
  115. package/dist/runnables/branch.js.map +1 -1
  116. package/dist/runnables/graph.cjs +6 -8
  117. package/dist/runnables/graph.cjs.map +1 -1
  118. package/dist/runnables/graph.js +1 -3
  119. package/dist/runnables/graph.js.map +1 -1
  120. package/dist/runnables/graph_mermaid.cjs.map +1 -1
  121. package/dist/runnables/graph_mermaid.js.map +1 -1
  122. package/dist/runnables/history.cjs.map +1 -1
  123. package/dist/runnables/history.js.map +1 -1
  124. package/dist/runnables/router.cjs.map +1 -1
  125. package/dist/runnables/router.js.map +1 -1
  126. package/dist/runnables/utils.cjs.map +1 -1
  127. package/dist/runnables/utils.js.map +1 -1
  128. package/dist/singletons/async_local_storage/context.cjs.map +1 -1
  129. package/dist/singletons/async_local_storage/context.js.map +1 -1
  130. package/dist/singletons/async_local_storage/index.cjs.map +1 -1
  131. package/dist/singletons/async_local_storage/index.js.map +1 -1
  132. package/dist/testing/fake_model_builder.cjs.map +1 -1
  133. package/dist/testing/fake_model_builder.js.map +1 -1
  134. package/dist/testing/matchers.cjs.map +1 -1
  135. package/dist/testing/matchers.js.map +1 -1
  136. package/dist/tracers/console.cjs.map +1 -1
  137. package/dist/tracers/console.js.map +1 -1
  138. package/dist/tracers/event_stream.cjs.map +1 -1
  139. package/dist/tracers/event_stream.js.map +1 -1
  140. package/dist/tracers/tracer_langchain.cjs.map +1 -1
  141. package/dist/tracers/tracer_langchain.js.map +1 -1
  142. package/dist/utils/callbacks.cjs.map +1 -1
  143. package/dist/utils/callbacks.js.map +1 -1
  144. package/dist/utils/context.cjs.map +1 -1
  145. package/dist/utils/context.js.map +1 -1
  146. package/dist/utils/env.cjs.map +1 -1
  147. package/dist/utils/env.js.map +1 -1
  148. package/dist/utils/fast-json-patch/src/core.cjs.map +1 -1
  149. package/dist/utils/fast-json-patch/src/core.js.map +1 -1
  150. package/dist/utils/json_schema.cjs.map +1 -1
  151. package/dist/utils/json_schema.js.map +1 -1
  152. package/dist/utils/sax-js/sax.cjs.map +1 -1
  153. package/dist/utils/sax-js/sax.js.map +1 -1
  154. package/dist/utils/ssrf.cjs.map +1 -1
  155. package/dist/utils/ssrf.js.map +1 -1
  156. package/dist/utils/stream.d.cts +2 -2
  157. package/dist/utils/stream.d.cts.map +1 -1
  158. package/dist/utils/stream.d.ts +2 -2
  159. package/dist/utils/stream.d.ts.map +1 -1
  160. package/dist/utils/testing/chat_models.cjs.map +1 -1
  161. package/dist/utils/testing/chat_models.js.map +1 -1
  162. package/dist/utils/testing/embeddings.cjs.map +1 -1
  163. package/dist/utils/testing/embeddings.js.map +1 -1
  164. package/dist/utils/testing/vectorstores.cjs.map +1 -1
  165. package/dist/utils/testing/vectorstores.js.map +1 -1
  166. package/dist/utils/types/zod.cjs.map +1 -1
  167. package/dist/utils/types/zod.js.map +1 -1
  168. package/dist/utils/uuid/index.cjs +33 -22
  169. package/dist/utils/uuid/index.cjs.map +1 -1
  170. package/dist/utils/uuid/index.d.cts +25 -12
  171. package/dist/utils/uuid/index.d.cts.map +1 -0
  172. package/dist/utils/uuid/index.d.ts +25 -12
  173. package/dist/utils/uuid/index.d.ts.map +1 -0
  174. package/dist/utils/uuid/index.js +23 -12
  175. package/dist/utils/uuid/index.js.map +1 -1
  176. package/dist/utils/uuid/v35.cjs.map +1 -1
  177. package/dist/utils/uuid/v35.js.map +1 -1
  178. package/dist/utils/zod-to-json-schema/parsers/nativeEnum.cjs.map +1 -1
  179. package/dist/utils/zod-to-json-schema/parsers/nativeEnum.js.map +1 -1
  180. package/dist/utils/zod-to-json-schema/parsers/pipeline.cjs.map +1 -1
  181. package/dist/utils/zod-to-json-schema/parsers/pipeline.js.map +1 -1
  182. package/dist/utils/zod-to-json-schema/parsers/set.cjs.map +1 -1
  183. package/dist/utils/zod-to-json-schema/parsers/set.js.map +1 -1
  184. package/dist/utils/zod-to-json-schema/parsers/string.cjs +26 -0
  185. package/dist/utils/zod-to-json-schema/parsers/string.cjs.map +1 -1
  186. package/dist/utils/zod-to-json-schema/parsers/string.js +26 -0
  187. package/dist/utils/zod-to-json-schema/parsers/string.js.map +1 -1
  188. package/dist/vectorstores.cjs.map +1 -1
  189. package/dist/vectorstores.js.map +1 -1
  190. package/package.json +5 -5
  191. package/agents.cjs +0 -1
  192. package/agents.d.cts +0 -1
  193. package/agents.d.ts +0 -1
  194. package/agents.js +0 -1
  195. package/caches.cjs +0 -1
  196. package/caches.d.cts +0 -1
  197. package/caches.d.ts +0 -1
  198. package/caches.js +0 -1
  199. package/callbacks/base.cjs +0 -1
  200. package/callbacks/base.d.cts +0 -1
  201. package/callbacks/base.d.ts +0 -1
  202. package/callbacks/base.js +0 -1
  203. package/callbacks/dispatch/web.cjs +0 -1
  204. package/callbacks/dispatch/web.d.cts +0 -1
  205. package/callbacks/dispatch/web.d.ts +0 -1
  206. package/callbacks/dispatch/web.js +0 -1
  207. package/callbacks/dispatch.cjs +0 -1
  208. package/callbacks/dispatch.d.cts +0 -1
  209. package/callbacks/dispatch.d.ts +0 -1
  210. package/callbacks/dispatch.js +0 -1
  211. package/callbacks/manager.cjs +0 -1
  212. package/callbacks/manager.d.cts +0 -1
  213. package/callbacks/manager.d.ts +0 -1
  214. package/callbacks/manager.js +0 -1
  215. package/callbacks/promises.cjs +0 -1
  216. package/callbacks/promises.d.cts +0 -1
  217. package/callbacks/promises.d.ts +0 -1
  218. package/callbacks/promises.js +0 -1
  219. package/chat_history.cjs +0 -1
  220. package/chat_history.d.cts +0 -1
  221. package/chat_history.d.ts +0 -1
  222. package/chat_history.js +0 -1
  223. package/context.cjs +0 -1
  224. package/context.d.cts +0 -1
  225. package/context.d.ts +0 -1
  226. package/context.js +0 -1
  227. package/dist/utils/uuid/max.d.cts +0 -5
  228. package/dist/utils/uuid/max.d.cts.map +0 -1
  229. package/dist/utils/uuid/max.d.ts +0 -5
  230. package/dist/utils/uuid/max.d.ts.map +0 -1
  231. package/dist/utils/uuid/nil.d.cts +0 -5
  232. package/dist/utils/uuid/nil.d.cts.map +0 -1
  233. package/dist/utils/uuid/nil.d.ts +0 -5
  234. package/dist/utils/uuid/nil.d.ts.map +0 -1
  235. package/document_loaders/base.cjs +0 -1
  236. package/document_loaders/base.d.cts +0 -1
  237. package/document_loaders/base.d.ts +0 -1
  238. package/document_loaders/base.js +0 -1
  239. package/document_loaders/langsmith.cjs +0 -1
  240. package/document_loaders/langsmith.d.cts +0 -1
  241. package/document_loaders/langsmith.d.ts +0 -1
  242. package/document_loaders/langsmith.js +0 -1
  243. package/documents.cjs +0 -1
  244. package/documents.d.cts +0 -1
  245. package/documents.d.ts +0 -1
  246. package/documents.js +0 -1
  247. package/embeddings.cjs +0 -1
  248. package/embeddings.d.cts +0 -1
  249. package/embeddings.d.ts +0 -1
  250. package/embeddings.js +0 -1
  251. package/errors.cjs +0 -1
  252. package/errors.d.cts +0 -1
  253. package/errors.d.ts +0 -1
  254. package/errors.js +0 -1
  255. package/example_selectors.cjs +0 -1
  256. package/example_selectors.d.cts +0 -1
  257. package/example_selectors.d.ts +0 -1
  258. package/example_selectors.js +0 -1
  259. package/indexing.cjs +0 -1
  260. package/indexing.d.cts +0 -1
  261. package/indexing.d.ts +0 -1
  262. package/indexing.js +0 -1
  263. package/language_models/base.cjs +0 -1
  264. package/language_models/base.d.cts +0 -1
  265. package/language_models/base.d.ts +0 -1
  266. package/language_models/base.js +0 -1
  267. package/language_models/chat_models.cjs +0 -1
  268. package/language_models/chat_models.d.cts +0 -1
  269. package/language_models/chat_models.d.ts +0 -1
  270. package/language_models/chat_models.js +0 -1
  271. package/language_models/compat.cjs +0 -1
  272. package/language_models/compat.d.cts +0 -1
  273. package/language_models/compat.d.ts +0 -1
  274. package/language_models/compat.js +0 -1
  275. package/language_models/event.cjs +0 -1
  276. package/language_models/event.d.cts +0 -1
  277. package/language_models/event.d.ts +0 -1
  278. package/language_models/event.js +0 -1
  279. package/language_models/llms.cjs +0 -1
  280. package/language_models/llms.d.cts +0 -1
  281. package/language_models/llms.d.ts +0 -1
  282. package/language_models/llms.js +0 -1
  283. package/language_models/profile.cjs +0 -1
  284. package/language_models/profile.d.cts +0 -1
  285. package/language_models/profile.d.ts +0 -1
  286. package/language_models/profile.js +0 -1
  287. package/language_models/stream.cjs +0 -1
  288. package/language_models/stream.d.cts +0 -1
  289. package/language_models/stream.d.ts +0 -1
  290. package/language_models/stream.js +0 -1
  291. package/language_models/structured_output.cjs +0 -1
  292. package/language_models/structured_output.d.cts +0 -1
  293. package/language_models/structured_output.d.ts +0 -1
  294. package/language_models/structured_output.js +0 -1
  295. package/load/serializable.cjs +0 -1
  296. package/load/serializable.d.cts +0 -1
  297. package/load/serializable.d.ts +0 -1
  298. package/load/serializable.js +0 -1
  299. package/load.cjs +0 -1
  300. package/load.d.cts +0 -1
  301. package/load.d.ts +0 -1
  302. package/load.js +0 -1
  303. package/memory.cjs +0 -1
  304. package/memory.d.cts +0 -1
  305. package/memory.d.ts +0 -1
  306. package/memory.js +0 -1
  307. package/messages/tool.cjs +0 -1
  308. package/messages/tool.d.cts +0 -1
  309. package/messages/tool.d.ts +0 -1
  310. package/messages/tool.js +0 -1
  311. package/messages.cjs +0 -1
  312. package/messages.d.cts +0 -1
  313. package/messages.d.ts +0 -1
  314. package/messages.js +0 -1
  315. package/output_parsers/openai_functions.cjs +0 -1
  316. package/output_parsers/openai_functions.d.cts +0 -1
  317. package/output_parsers/openai_functions.d.ts +0 -1
  318. package/output_parsers/openai_functions.js +0 -1
  319. package/output_parsers/openai_tools.cjs +0 -1
  320. package/output_parsers/openai_tools.d.cts +0 -1
  321. package/output_parsers/openai_tools.d.ts +0 -1
  322. package/output_parsers/openai_tools.js +0 -1
  323. package/output_parsers.cjs +0 -1
  324. package/output_parsers.d.cts +0 -1
  325. package/output_parsers.d.ts +0 -1
  326. package/output_parsers.js +0 -1
  327. package/outputs.cjs +0 -1
  328. package/outputs.d.cts +0 -1
  329. package/outputs.d.ts +0 -1
  330. package/outputs.js +0 -1
  331. package/prompt_values.cjs +0 -1
  332. package/prompt_values.d.cts +0 -1
  333. package/prompt_values.d.ts +0 -1
  334. package/prompt_values.js +0 -1
  335. package/prompts.cjs +0 -1
  336. package/prompts.d.cts +0 -1
  337. package/prompts.d.ts +0 -1
  338. package/prompts.js +0 -1
  339. package/retrievers/document_compressors.cjs +0 -1
  340. package/retrievers/document_compressors.d.cts +0 -1
  341. package/retrievers/document_compressors.d.ts +0 -1
  342. package/retrievers/document_compressors.js +0 -1
  343. package/retrievers.cjs +0 -1
  344. package/retrievers.d.cts +0 -1
  345. package/retrievers.d.ts +0 -1
  346. package/retrievers.js +0 -1
  347. package/runnables/graph.cjs +0 -1
  348. package/runnables/graph.d.cts +0 -1
  349. package/runnables/graph.d.ts +0 -1
  350. package/runnables/graph.js +0 -1
  351. package/runnables.cjs +0 -1
  352. package/runnables.d.cts +0 -1
  353. package/runnables.d.ts +0 -1
  354. package/runnables.js +0 -1
  355. package/singletons.cjs +0 -1
  356. package/singletons.d.cts +0 -1
  357. package/singletons.d.ts +0 -1
  358. package/singletons.js +0 -1
  359. package/stores.cjs +0 -1
  360. package/stores.d.cts +0 -1
  361. package/stores.d.ts +0 -1
  362. package/stores.js +0 -1
  363. package/structured_query.cjs +0 -1
  364. package/structured_query.d.cts +0 -1
  365. package/structured_query.d.ts +0 -1
  366. package/structured_query.js +0 -1
  367. package/tools.cjs +0 -1
  368. package/tools.d.cts +0 -1
  369. package/tools.d.ts +0 -1
  370. package/tools.js +0 -1
  371. package/tracers/base.cjs +0 -1
  372. package/tracers/base.d.cts +0 -1
  373. package/tracers/base.d.ts +0 -1
  374. package/tracers/base.js +0 -1
  375. package/tracers/console.cjs +0 -1
  376. package/tracers/console.d.cts +0 -1
  377. package/tracers/console.d.ts +0 -1
  378. package/tracers/console.js +0 -1
  379. package/tracers/log_stream.cjs +0 -1
  380. package/tracers/log_stream.d.cts +0 -1
  381. package/tracers/log_stream.d.ts +0 -1
  382. package/tracers/log_stream.js +0 -1
  383. package/tracers/run_collector.cjs +0 -1
  384. package/tracers/run_collector.d.cts +0 -1
  385. package/tracers/run_collector.d.ts +0 -1
  386. package/tracers/run_collector.js +0 -1
  387. package/tracers/tracer_langchain.cjs +0 -1
  388. package/tracers/tracer_langchain.d.cts +0 -1
  389. package/tracers/tracer_langchain.d.ts +0 -1
  390. package/tracers/tracer_langchain.js +0 -1
  391. package/types/stream.cjs +0 -1
  392. package/types/stream.d.cts +0 -1
  393. package/types/stream.d.ts +0 -1
  394. package/types/stream.js +0 -1
  395. package/utils/async_caller.cjs +0 -1
  396. package/utils/async_caller.d.cts +0 -1
  397. package/utils/async_caller.d.ts +0 -1
  398. package/utils/async_caller.js +0 -1
  399. package/utils/chunk_array.cjs +0 -1
  400. package/utils/chunk_array.d.cts +0 -1
  401. package/utils/chunk_array.d.ts +0 -1
  402. package/utils/chunk_array.js +0 -1
  403. package/utils/context.cjs +0 -1
  404. package/utils/context.d.cts +0 -1
  405. package/utils/context.d.ts +0 -1
  406. package/utils/context.js +0 -1
  407. package/utils/env.cjs +0 -1
  408. package/utils/env.d.cts +0 -1
  409. package/utils/env.d.ts +0 -1
  410. package/utils/env.js +0 -1
  411. package/utils/event_source_parse.cjs +0 -1
  412. package/utils/event_source_parse.d.cts +0 -1
  413. package/utils/event_source_parse.d.ts +0 -1
  414. package/utils/event_source_parse.js +0 -1
  415. package/utils/format.cjs +0 -1
  416. package/utils/format.d.cts +0 -1
  417. package/utils/format.d.ts +0 -1
  418. package/utils/format.js +0 -1
  419. package/utils/function_calling.cjs +0 -1
  420. package/utils/function_calling.d.cts +0 -1
  421. package/utils/function_calling.d.ts +0 -1
  422. package/utils/function_calling.js +0 -1
  423. package/utils/hash.cjs +0 -1
  424. package/utils/hash.d.cts +0 -1
  425. package/utils/hash.d.ts +0 -1
  426. package/utils/hash.js +0 -1
  427. package/utils/json_patch.cjs +0 -1
  428. package/utils/json_patch.d.cts +0 -1
  429. package/utils/json_patch.d.ts +0 -1
  430. package/utils/json_patch.js +0 -1
  431. package/utils/json_schema.cjs +0 -1
  432. package/utils/json_schema.d.cts +0 -1
  433. package/utils/json_schema.d.ts +0 -1
  434. package/utils/json_schema.js +0 -1
  435. package/utils/math.cjs +0 -1
  436. package/utils/math.d.cts +0 -1
  437. package/utils/math.d.ts +0 -1
  438. package/utils/math.js +0 -1
  439. package/utils/ssrf.cjs +0 -1
  440. package/utils/ssrf.d.cts +0 -1
  441. package/utils/ssrf.d.ts +0 -1
  442. package/utils/ssrf.js +0 -1
  443. package/utils/standard_schema.cjs +0 -1
  444. package/utils/standard_schema.d.cts +0 -1
  445. package/utils/standard_schema.d.ts +0 -1
  446. package/utils/standard_schema.js +0 -1
  447. package/utils/stream.cjs +0 -1
  448. package/utils/stream.d.cts +0 -1
  449. package/utils/stream.d.ts +0 -1
  450. package/utils/stream.js +0 -1
  451. package/utils/testing.cjs +0 -1
  452. package/utils/testing.d.cts +0 -1
  453. package/utils/testing.d.ts +0 -1
  454. package/utils/testing.js +0 -1
  455. package/utils/tiktoken.cjs +0 -1
  456. package/utils/tiktoken.d.cts +0 -1
  457. package/utils/tiktoken.d.ts +0 -1
  458. package/utils/tiktoken.js +0 -1
  459. package/utils/types.cjs +0 -1
  460. package/utils/types.d.cts +0 -1
  461. package/utils/types.d.ts +0 -1
  462. package/utils/types.js +0 -1
  463. package/utils/uuid.cjs +0 -1
  464. package/utils/uuid.d.cts +0 -1
  465. package/utils/uuid.d.ts +0 -1
  466. package/utils/uuid.js +0 -1
  467. package/vectorstores.cjs +0 -1
  468. package/vectorstores.d.cts +0 -1
  469. package/vectorstores.d.ts +0 -1
  470. package/vectorstores.js +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"context.cjs","names":[],"sources":["../../src/utils/context.ts"],"sourcesContent":["/**\n * A tagged template function for creating formatted strings.\n *\n * This utility provides a clean, template literal-based API for string formatting\n * that can be used for prompts, descriptions, and other text formatting needs.\n *\n * It automatically handles whitespace normalization and indentation, making it\n * ideal for multi-line strings in code.\n *\n * When using this utility, it will:\n * - Strip common leading indentation from all lines\n * - Trim leading/trailing whitespace\n * - Align multi-line interpolated values to match indentation\n * - Support escape sequences: `\\\\n` (newline), `\\\\`` (backtick), `\\\\$` (dollar), `\\\\{` (brace)\n *\n * @example\n * ```typescript\n * import { context } from \"@langchain/core/utils/context\";\n *\n * const role = \"agent\";\n * const prompt = context`\n * You are an ${role}.\n * Your task is to help users.\n * `;\n * // Returns: \"You are an agent.\\nYour task is to help users.\"\n * ```\n *\n * @example\n * ```typescript\n * // Multi-line interpolated values are aligned\n * const items = \"- Item 1\\n- Item 2\\n- Item 3\";\n * const message = context`\n * Shopping list:\n * ${items}\n * End of list.\n * `;\n * // The items will be indented to match \" \" (4 spaces)\n * ```\n */\nexport function context(\n strings: TemplateStringsArray,\n ...values: unknown[]\n): string {\n const raw = strings.raw;\n let result = \"\";\n\n for (let i = 0; i < raw.length; i++) {\n // Handle escaped characters in template literals\n const next = raw[i]\n .replace(/\\\\\\n[ \\t]*/g, \"\") // escaped newlines (line continuation)\n .replace(/\\\\`/g, \"`\") // escaped backticks\n .replace(/\\\\\\$/g, \"$\") // escaped dollar signs\n .replace(/\\\\\\{/g, \"{\"); // escaped braces\n\n result += next;\n\n if (i < values.length) {\n const value = alignValue(values[i], result);\n result += typeof value === \"string\" ? value : JSON.stringify(value);\n }\n }\n\n // Strip common indentation\n result = stripIndent(result);\n\n // Trim leading/trailing whitespace\n result = result.trim();\n\n // Handle escaped \\n at the end (preserve intentional newlines)\n result = result.replace(/\\\\n/g, \"\\n\");\n\n return result;\n}\n\n/**\n * Adjusts the indentation of a multi-line interpolated value to match the current line.\n *\n * @param value - The interpolated value\n * @param precedingText - The text that comes before this value\n * @returns The value with adjusted indentation\n */\nfunction alignValue(value: unknown, precedingText: string): unknown {\n if (typeof value !== \"string\" || !value.includes(\"\\n\")) {\n return value;\n }\n\n const currentLine = precedingText.slice(precedingText.lastIndexOf(\"\\n\") + 1);\n const indentMatch = currentLine.match(/^(\\s+)/);\n\n if (indentMatch) {\n const indent = indentMatch[1];\n return value.replace(/\\n/g, `\\n${indent}`);\n }\n\n return value;\n}\n\n/**\n * Strips common leading indentation from all lines.\n *\n * @param text - The text to process\n * @returns The text with common indentation removed\n */\nfunction stripIndent(text: string): string {\n const lines = text.split(\"\\n\");\n\n // Find minimum indentation (only from lines that have content)\n let minIndent: number | null = null;\n for (const line of lines) {\n const match = line.match(/^(\\s+)\\S+/);\n if (match) {\n const indent = match[1].length;\n if (minIndent === null) {\n minIndent = indent;\n } else {\n minIndent = Math.min(minIndent, indent);\n }\n }\n }\n\n if (minIndent === null) {\n return text;\n }\n\n // Remove the common indentation from all lines\n return lines\n .map((line) =>\n line[0] === \" \" || line[0] === \"\\t\" ? line.slice(minIndent) : line\n )\n .join(\"\\n\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,SAAgB,QACd,SACA,GAAG,QACK;CACR,MAAM,MAAM,QAAQ;CACpB,IAAI,SAAS;AAEb,MAAK,IAAI,IAAI,GAAG,IAAI,IAAI,QAAQ,KAAK;EAEnC,MAAM,OAAO,IAAI,GACd,QAAQ,eAAe,GAAG,CAC1B,QAAQ,QAAQ,IAAI,CACpB,QAAQ,SAAS,IAAI,CACrB,QAAQ,SAAS,IAAI;AAExB,YAAU;AAEV,MAAI,IAAI,OAAO,QAAQ;GACrB,MAAM,QAAQ,WAAW,OAAO,IAAI,OAAO;AAC3C,aAAU,OAAO,UAAU,WAAW,QAAQ,KAAK,UAAU,MAAM;;;AAKvE,UAAS,YAAY,OAAO;AAG5B,UAAS,OAAO,MAAM;AAGtB,UAAS,OAAO,QAAQ,QAAQ,KAAK;AAErC,QAAO;;;;;;;;;AAUT,SAAS,WAAW,OAAgB,eAAgC;AAClE,KAAI,OAAO,UAAU,YAAY,CAAC,MAAM,SAAS,KAAK,CACpD,QAAO;CAIT,MAAM,cADc,cAAc,MAAM,cAAc,YAAY,KAAK,GAAG,EAAE,CAC5C,MAAM,SAAS;AAE/C,KAAI,aAAa;EACf,MAAM,SAAS,YAAY;AAC3B,SAAO,MAAM,QAAQ,OAAO,KAAK,SAAS;;AAG5C,QAAO;;;;;;;;AAST,SAAS,YAAY,MAAsB;CACzC,MAAM,QAAQ,KAAK,MAAM,KAAK;CAG9B,IAAI,YAA2B;AAC/B,MAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,QAAQ,KAAK,MAAM,YAAY;AACrC,MAAI,OAAO;GACT,MAAM,SAAS,MAAM,GAAG;AACxB,OAAI,cAAc,KAChB,aAAY;OAEZ,aAAY,KAAK,IAAI,WAAW,OAAO;;;AAK7C,KAAI,cAAc,KAChB,QAAO;AAIT,QAAO,MACJ,KAAK,SACJ,KAAK,OAAO,OAAO,KAAK,OAAO,MAAO,KAAK,MAAM,UAAU,GAAG,KAC/D,CACA,KAAK,KAAK"}
1
+ {"version":3,"file":"context.cjs","names":[],"sources":["../../src/utils/context.ts"],"sourcesContent":["/**\n * A tagged template function for creating formatted strings.\n *\n * This utility provides a clean, template literal-based API for string formatting\n * that can be used for prompts, descriptions, and other text formatting needs.\n *\n * It automatically handles whitespace normalization and indentation, making it\n * ideal for multi-line strings in code.\n *\n * When using this utility, it will:\n * - Strip common leading indentation from all lines\n * - Trim leading/trailing whitespace\n * - Align multi-line interpolated values to match indentation\n * - Support escape sequences: `\\\\n` (newline), `\\\\`` (backtick), `\\\\$` (dollar), `\\\\{` (brace)\n *\n * @example\n * ```typescript\n * import { context } from \"@langchain/core/utils/context\";\n *\n * const role = \"agent\";\n * const prompt = context`\n * You are an ${role}.\n * Your task is to help users.\n * `;\n * // Returns: \"You are an agent.\\nYour task is to help users.\"\n * ```\n *\n * @example\n * ```typescript\n * // Multi-line interpolated values are aligned\n * const items = \"- Item 1\\n- Item 2\\n- Item 3\";\n * const message = context`\n * Shopping list:\n * ${items}\n * End of list.\n * `;\n * // The items will be indented to match \" \" (4 spaces)\n * ```\n */\nexport function context(\n strings: TemplateStringsArray,\n ...values: unknown[]\n): string {\n const raw = strings.raw;\n let result = \"\";\n\n for (let i = 0; i < raw.length; i++) {\n // Handle escaped characters in template literals\n const next = raw[i]\n .replace(/\\\\\\n[ \\t]*/g, \"\") // escaped newlines (line continuation)\n .replace(/\\\\`/g, \"`\") // escaped backticks\n .replace(/\\\\\\$/g, \"$\") // escaped dollar signs\n .replace(/\\\\\\{/g, \"{\"); // escaped braces\n\n result += next;\n\n if (i < values.length) {\n const value = alignValue(values[i], result);\n result += typeof value === \"string\" ? value : JSON.stringify(value);\n }\n }\n\n // Strip common indentation\n result = stripIndent(result);\n\n // Trim leading/trailing whitespace\n result = result.trim();\n\n // Handle escaped \\n at the end (preserve intentional newlines)\n result = result.replace(/\\\\n/g, \"\\n\");\n\n return result;\n}\n\n/**\n * Adjusts the indentation of a multi-line interpolated value to match the current line.\n *\n * @param value - The interpolated value\n * @param precedingText - The text that comes before this value\n * @returns The value with adjusted indentation\n */\nfunction alignValue(value: unknown, precedingText: string): unknown {\n if (typeof value !== \"string\" || !value.includes(\"\\n\")) {\n return value;\n }\n\n const currentLine = precedingText.slice(precedingText.lastIndexOf(\"\\n\") + 1);\n const indentMatch = currentLine.match(/^(\\s+)/);\n\n if (indentMatch) {\n const indent = indentMatch[1];\n return value.replace(/\\n/g, `\\n${indent}`);\n }\n\n return value;\n}\n\n/**\n * Strips common leading indentation from all lines.\n *\n * @param text - The text to process\n * @returns The text with common indentation removed\n */\nfunction stripIndent(text: string): string {\n const lines = text.split(\"\\n\");\n\n // Find minimum indentation (only from lines that have content)\n let minIndent: number | null = null;\n for (const line of lines) {\n const match = line.match(/^(\\s+)\\S+/);\n if (match) {\n const indent = match[1].length;\n if (minIndent === null) {\n minIndent = indent;\n } else {\n minIndent = Math.min(minIndent, indent);\n }\n }\n }\n\n if (minIndent === null) {\n return text;\n }\n\n // Remove the common indentation from all lines\n return lines\n .map((line) =>\n line[0] === \" \" || line[0] === \"\\t\" ? line.slice(minIndent) : line\n )\n .join(\"\\n\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAu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
- {"version":3,"file":"context.js","names":[],"sources":["../../src/utils/context.ts"],"sourcesContent":["/**\n * A tagged template function for creating formatted strings.\n *\n * This utility provides a clean, template literal-based API for string formatting\n * that can be used for prompts, descriptions, and other text formatting needs.\n *\n * It automatically handles whitespace normalization and indentation, making it\n * ideal for multi-line strings in code.\n *\n * When using this utility, it will:\n * - Strip common leading indentation from all lines\n * - Trim leading/trailing whitespace\n * - Align multi-line interpolated values to match indentation\n * - Support escape sequences: `\\\\n` (newline), `\\\\`` (backtick), `\\\\$` (dollar), `\\\\{` (brace)\n *\n * @example\n * ```typescript\n * import { context } from \"@langchain/core/utils/context\";\n *\n * const role = \"agent\";\n * const prompt = context`\n * You are an ${role}.\n * Your task is to help users.\n * `;\n * // Returns: \"You are an agent.\\nYour task is to help users.\"\n * ```\n *\n * @example\n * ```typescript\n * // Multi-line interpolated values are aligned\n * const items = \"- Item 1\\n- Item 2\\n- Item 3\";\n * const message = context`\n * Shopping list:\n * ${items}\n * End of list.\n * `;\n * // The items will be indented to match \" \" (4 spaces)\n * ```\n */\nexport function context(\n strings: TemplateStringsArray,\n ...values: unknown[]\n): string {\n const raw = strings.raw;\n let result = \"\";\n\n for (let i = 0; i < raw.length; i++) {\n // Handle escaped characters in template literals\n const next = raw[i]\n .replace(/\\\\\\n[ \\t]*/g, \"\") // escaped newlines (line continuation)\n .replace(/\\\\`/g, \"`\") // escaped backticks\n .replace(/\\\\\\$/g, \"$\") // escaped dollar signs\n .replace(/\\\\\\{/g, \"{\"); // escaped braces\n\n result += next;\n\n if (i < values.length) {\n const value = alignValue(values[i], result);\n result += typeof value === \"string\" ? value : JSON.stringify(value);\n }\n }\n\n // Strip common indentation\n result = stripIndent(result);\n\n // Trim leading/trailing whitespace\n result = result.trim();\n\n // Handle escaped \\n at the end (preserve intentional newlines)\n result = result.replace(/\\\\n/g, \"\\n\");\n\n return result;\n}\n\n/**\n * Adjusts the indentation of a multi-line interpolated value to match the current line.\n *\n * @param value - The interpolated value\n * @param precedingText - The text that comes before this value\n * @returns The value with adjusted indentation\n */\nfunction alignValue(value: unknown, precedingText: string): unknown {\n if (typeof value !== \"string\" || !value.includes(\"\\n\")) {\n return value;\n }\n\n const currentLine = precedingText.slice(precedingText.lastIndexOf(\"\\n\") + 1);\n const indentMatch = currentLine.match(/^(\\s+)/);\n\n if (indentMatch) {\n const indent = indentMatch[1];\n return value.replace(/\\n/g, `\\n${indent}`);\n }\n\n return value;\n}\n\n/**\n * Strips common leading indentation from all lines.\n *\n * @param text - The text to process\n * @returns The text with common indentation removed\n */\nfunction stripIndent(text: string): string {\n const lines = text.split(\"\\n\");\n\n // Find minimum indentation (only from lines that have content)\n let minIndent: number | null = null;\n for (const line of lines) {\n const match = line.match(/^(\\s+)\\S+/);\n if (match) {\n const indent = match[1].length;\n if (minIndent === null) {\n minIndent = indent;\n } else {\n minIndent = Math.min(minIndent, indent);\n }\n }\n }\n\n if (minIndent === null) {\n return text;\n }\n\n // Remove the common indentation from all lines\n return lines\n .map((line) =>\n line[0] === \" \" || line[0] === \"\\t\" ? line.slice(minIndent) : line\n )\n .join(\"\\n\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,SAAgB,QACd,SACA,GAAG,QACK;CACR,MAAM,MAAM,QAAQ;CACpB,IAAI,SAAS;AAEb,MAAK,IAAI,IAAI,GAAG,IAAI,IAAI,QAAQ,KAAK;EAEnC,MAAM,OAAO,IAAI,GACd,QAAQ,eAAe,GAAG,CAC1B,QAAQ,QAAQ,IAAI,CACpB,QAAQ,SAAS,IAAI,CACrB,QAAQ,SAAS,IAAI;AAExB,YAAU;AAEV,MAAI,IAAI,OAAO,QAAQ;GACrB,MAAM,QAAQ,WAAW,OAAO,IAAI,OAAO;AAC3C,aAAU,OAAO,UAAU,WAAW,QAAQ,KAAK,UAAU,MAAM;;;AAKvE,UAAS,YAAY,OAAO;AAG5B,UAAS,OAAO,MAAM;AAGtB,UAAS,OAAO,QAAQ,QAAQ,KAAK;AAErC,QAAO;;;;;;;;;AAUT,SAAS,WAAW,OAAgB,eAAgC;AAClE,KAAI,OAAO,UAAU,YAAY,CAAC,MAAM,SAAS,KAAK,CACpD,QAAO;CAIT,MAAM,cADc,cAAc,MAAM,cAAc,YAAY,KAAK,GAAG,EAAE,CAC5C,MAAM,SAAS;AAE/C,KAAI,aAAa;EACf,MAAM,SAAS,YAAY;AAC3B,SAAO,MAAM,QAAQ,OAAO,KAAK,SAAS;;AAG5C,QAAO;;;;;;;;AAST,SAAS,YAAY,MAAsB;CACzC,MAAM,QAAQ,KAAK,MAAM,KAAK;CAG9B,IAAI,YAA2B;AAC/B,MAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,QAAQ,KAAK,MAAM,YAAY;AACrC,MAAI,OAAO;GACT,MAAM,SAAS,MAAM,GAAG;AACxB,OAAI,cAAc,KAChB,aAAY;OAEZ,aAAY,KAAK,IAAI,WAAW,OAAO;;;AAK7C,KAAI,cAAc,KAChB,QAAO;AAIT,QAAO,MACJ,KAAK,SACJ,KAAK,OAAO,OAAO,KAAK,OAAO,MAAO,KAAK,MAAM,UAAU,GAAG,KAC/D,CACA,KAAK,KAAK"}
1
+ {"version":3,"file":"context.js","names":[],"sources":["../../src/utils/context.ts"],"sourcesContent":["/**\n * A tagged template function for creating formatted strings.\n *\n * This utility provides a clean, template literal-based API for string formatting\n * that can be used for prompts, descriptions, and other text formatting needs.\n *\n * It automatically handles whitespace normalization and indentation, making it\n * ideal for multi-line strings in code.\n *\n * When using this utility, it will:\n * - Strip common leading indentation from all lines\n * - Trim leading/trailing whitespace\n * - Align multi-line interpolated values to match indentation\n * - Support escape sequences: `\\\\n` (newline), `\\\\`` (backtick), `\\\\$` (dollar), `\\\\{` (brace)\n *\n * @example\n * ```typescript\n * import { context } from \"@langchain/core/utils/context\";\n *\n * const role = \"agent\";\n * const prompt = context`\n * You are an ${role}.\n * Your task is to help users.\n * `;\n * // Returns: \"You are an agent.\\nYour task is to help users.\"\n * ```\n *\n * @example\n * ```typescript\n * // Multi-line interpolated values are aligned\n * const items = \"- Item 1\\n- Item 2\\n- Item 3\";\n * const message = context`\n * Shopping list:\n * ${items}\n * End of list.\n * `;\n * // The items will be indented to match \" \" (4 spaces)\n * ```\n */\nexport function context(\n strings: TemplateStringsArray,\n ...values: unknown[]\n): string {\n const raw = strings.raw;\n let result = \"\";\n\n for (let i = 0; i < raw.length; i++) {\n // Handle escaped characters in template literals\n const next = raw[i]\n .replace(/\\\\\\n[ \\t]*/g, \"\") // escaped newlines (line continuation)\n .replace(/\\\\`/g, \"`\") // escaped backticks\n .replace(/\\\\\\$/g, \"$\") // escaped dollar signs\n .replace(/\\\\\\{/g, \"{\"); // escaped braces\n\n result += next;\n\n if (i < values.length) {\n const value = alignValue(values[i], result);\n result += typeof value === \"string\" ? value : JSON.stringify(value);\n }\n }\n\n // Strip common indentation\n result = stripIndent(result);\n\n // Trim leading/trailing whitespace\n result = result.trim();\n\n // Handle escaped \\n at the end (preserve intentional newlines)\n result = result.replace(/\\\\n/g, \"\\n\");\n\n return result;\n}\n\n/**\n * Adjusts the indentation of a multi-line interpolated value to match the current line.\n *\n * @param value - The interpolated value\n * @param precedingText - The text that comes before this value\n * @returns The value with adjusted indentation\n */\nfunction alignValue(value: unknown, precedingText: string): unknown {\n if (typeof value !== \"string\" || !value.includes(\"\\n\")) {\n return value;\n }\n\n const currentLine = precedingText.slice(precedingText.lastIndexOf(\"\\n\") + 1);\n const indentMatch = currentLine.match(/^(\\s+)/);\n\n if (indentMatch) {\n const indent = indentMatch[1];\n return value.replace(/\\n/g, `\\n${indent}`);\n }\n\n return value;\n}\n\n/**\n * Strips common leading indentation from all lines.\n *\n * @param text - The text to process\n * @returns The text with common indentation removed\n */\nfunction stripIndent(text: string): string {\n const lines = text.split(\"\\n\");\n\n // Find minimum indentation (only from lines that have content)\n let minIndent: number | null = null;\n for (const line of lines) {\n const match = line.match(/^(\\s+)\\S+/);\n if (match) {\n const indent = match[1].length;\n if (minIndent === null) {\n minIndent = indent;\n } else {\n minIndent = Math.min(minIndent, indent);\n }\n }\n }\n\n if (minIndent === null) {\n return text;\n }\n\n // Remove the common indentation from all lines\n return lines\n .map((line) =>\n line[0] === \" \" || line[0] === \"\\t\" ? line.slice(minIndent) : line\n )\n .join(\"\\n\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,SAAgB,QACd,SACA,GAAG,QACK;CACR,MAAM,MAAM,QAAQ;CACpB,IAAI,SAAS;AAEb,MAAK,IAAI,IAAI,GAAG,IAAI,IAAI,QAAQ,KAAK;EAEnC,MAAM,OAAO,IAAI,GACd,QAAQ,eAAe,GAAG,CAC1B,QAAQ,QAAQ,IAAI,CACpB,QAAQ,SAAS,IAAI,CACrB,QAAQ,SAAS,IAAI;AAExB,YAAU;AAEV,MAAI,IAAI,OAAO,QAAQ;GACrB,MAAM,QAAQ,WAAW,OAAO,IAAI,OAAO;AAC3C,aAAU,OAAO,UAAU,WAAW,QAAQ,KAAK,UAAU,MAAM;;;AAKvE,UAAS,YAAY,OAAO;AAG5B,UAAS,OAAO,MAAM;AAGtB,UAAS,OAAO,QAAQ,QAAQ,KAAK;AAErC,QAAO;;;;;;;;;AAUT,SAAS,WAAW,OAAgB,eAAgC;AAClE,KAAI,OAAO,UAAU,YAAY,CAAC,MAAM,SAAS,KAAK,CACpD,QAAO;CAIT,MAAM,cADc,cAAc,MAAM,cAAc,YAAY,KAAK,GAAG,EAC3C,CAAC,MAAM,SAAS;AAE/C,KAAI,aAAa;EACf,MAAM,SAAS,YAAY;AAC3B,SAAO,MAAM,QAAQ,OAAO,KAAK,SAAS;;AAG5C,QAAO;;;;;;;;AAST,SAAS,YAAY,MAAsB;CACzC,MAAM,QAAQ,KAAK,MAAM,KAAK;CAG9B,IAAI,YAA2B;AAC/B,MAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,QAAQ,KAAK,MAAM,YAAY;AACrC,MAAI,OAAO;GACT,MAAM,SAAS,MAAM,GAAG;AACxB,OAAI,cAAc,KAChB,aAAY;OAEZ,aAAY,KAAK,IAAI,WAAW,OAAO;;;AAK7C,KAAI,cAAc,KAChB,QAAO;AAIT,QAAO,MACJ,KAAK,SACJ,KAAK,OAAO,OAAO,KAAK,OAAO,MAAO,KAAK,MAAM,UAAU,GAAG,KAC/D,CACA,KAAK,KAAK"}
@@ -1 +1 @@
1
- {"version":3,"file":"env.cjs","names":[],"sources":["../../src/utils/env.ts"],"sourcesContent":["// Inlined from https://github.com/flexdinesh/browser-or-node\ndeclare global {\n // @ts-expect-error Conflicts with langsmith's ambient Deno declaration\n const Deno:\n | {\n version: {\n deno: string;\n };\n env: {\n get: (name: string) => string | undefined;\n };\n }\n | undefined;\n}\n\nexport const isBrowser = () =>\n typeof window !== \"undefined\" && typeof window.document !== \"undefined\";\n\nexport const isWebWorker = () =>\n typeof globalThis === \"object\" &&\n globalThis.constructor &&\n globalThis.constructor.name === \"DedicatedWorkerGlobalScope\";\n\nexport const isJsDom = () =>\n (typeof window !== \"undefined\" && window.name === \"nodejs\") ||\n (typeof navigator !== \"undefined\" && navigator.userAgent.includes(\"jsdom\"));\n\n// Supabase Edge Function provides a `Deno` global object\n// without `version` property\nexport const isDeno = () => typeof Deno !== \"undefined\";\n\n// Mark not-as-node if in Supabase Edge Function\nexport const isNode = () =>\n typeof process !== \"undefined\" &&\n typeof process.versions !== \"undefined\" &&\n typeof process.versions.node !== \"undefined\" &&\n !isDeno();\n\nexport const getEnv = () => {\n let env: string;\n if (isBrowser()) {\n env = \"browser\";\n } else if (isNode()) {\n env = \"node\";\n } else if (isWebWorker()) {\n env = \"webworker\";\n } else if (isJsDom()) {\n env = \"jsdom\";\n } else if (isDeno()) {\n env = \"deno\";\n } else {\n env = \"other\";\n }\n\n return env;\n};\n\nexport type RuntimeEnvironment = {\n library: string;\n libraryVersion?: string;\n runtime: string;\n runtimeVersion?: string;\n};\n\nlet runtimeEnvironment: RuntimeEnvironment | undefined;\n\nexport function getRuntimeEnvironment(): RuntimeEnvironment {\n if (runtimeEnvironment === undefined) {\n const env = getEnv();\n\n runtimeEnvironment = {\n library: \"langchain-js\",\n runtime: env,\n };\n }\n return runtimeEnvironment;\n}\n\nexport function getEnvironmentVariable(name: string): string | undefined {\n // Certain Deno setups will throw an error if you try to access environment variables\n // https://github.com/langchain-ai/langchainjs/issues/1412\n try {\n if (typeof process !== \"undefined\") {\n // oxlint-disable-next-line no-process-env\n return process.env?.[name];\n } else if (isDeno()) {\n // @ts-expect-error Langsmith's Deno declaration is missing `env`\n return Deno?.env.get(name);\n } else {\n return undefined;\n }\n } catch {\n return undefined;\n }\n}\n"],"mappings":";;;;;;;;;;;;AAeA,MAAa,kBACX,OAAO,WAAW,eAAe,OAAO,OAAO,aAAa;AAE9D,MAAa,oBACX,OAAO,eAAe,YACtB,WAAW,eACX,WAAW,YAAY,SAAS;AAElC,MAAa,gBACV,OAAO,WAAW,eAAe,OAAO,SAAS,YACjD,OAAO,cAAc,eAAe,UAAU,UAAU,SAAS,QAAQ;AAI5E,MAAa,eAAe,OAAO,SAAS;AAG5C,MAAa,eACX,OAAO,YAAY,eACnB,OAAO,QAAQ,aAAa,eAC5B,OAAO,QAAQ,SAAS,SAAS,eACjC,CAAC,QAAQ;AAEX,MAAa,eAAe;CAC1B,IAAI;AACJ,KAAI,WAAW,CACb,OAAM;UACG,QAAQ,CACjB,OAAM;UACG,aAAa,CACtB,OAAM;UACG,SAAS,CAClB,OAAM;UACG,QAAQ,CACjB,OAAM;KAEN,OAAM;AAGR,QAAO;;AAUT,IAAI;AAEJ,SAAgB,wBAA4C;AAC1D,KAAI,uBAAuB,KAAA,EAGzB,sBAAqB;EACnB,SAAS;EACT,SAJU,QAAQ;EAKnB;AAEH,QAAO;;AAGT,SAAgB,uBAAuB,MAAkC;AAGvE,KAAI;AACF,MAAI,OAAO,YAAY,YAErB,QAAO,QAAQ,MAAM;WACZ,QAAQ,CAEjB,QAAO,MAAM,IAAI,IAAI,KAAK;MAE1B;SAEI;AACN"}
1
+ {"version":3,"file":"env.cjs","names":[],"sources":["../../src/utils/env.ts"],"sourcesContent":["// Inlined from https://github.com/flexdinesh/browser-or-node\ndeclare global {\n // @ts-expect-error Conflicts with langsmith's ambient Deno declaration\n const Deno:\n | {\n version: {\n deno: string;\n };\n env: {\n get: (name: string) => string | undefined;\n };\n }\n | undefined;\n}\n\nexport const isBrowser = () =>\n typeof window !== \"undefined\" && typeof window.document !== \"undefined\";\n\nexport const isWebWorker = () =>\n typeof globalThis === \"object\" &&\n globalThis.constructor &&\n globalThis.constructor.name === \"DedicatedWorkerGlobalScope\";\n\nexport const isJsDom = () =>\n (typeof window !== \"undefined\" && window.name === \"nodejs\") ||\n (typeof navigator !== \"undefined\" && navigator.userAgent.includes(\"jsdom\"));\n\n// Supabase Edge Function provides a `Deno` global object\n// without `version` property\nexport const isDeno = () => typeof Deno !== \"undefined\";\n\n// Mark not-as-node if in Supabase Edge Function\nexport const isNode = () =>\n typeof process !== \"undefined\" &&\n typeof process.versions !== \"undefined\" &&\n typeof process.versions.node !== \"undefined\" &&\n !isDeno();\n\nexport const getEnv = () => {\n let env: string;\n if (isBrowser()) {\n env = \"browser\";\n } else if (isNode()) {\n env = \"node\";\n } else if (isWebWorker()) {\n env = \"webworker\";\n } else if (isJsDom()) {\n env = \"jsdom\";\n } else if (isDeno()) {\n env = \"deno\";\n } else {\n env = \"other\";\n }\n\n return env;\n};\n\nexport type RuntimeEnvironment = {\n library: string;\n libraryVersion?: string;\n runtime: string;\n runtimeVersion?: string;\n};\n\nlet runtimeEnvironment: RuntimeEnvironment | undefined;\n\nexport function getRuntimeEnvironment(): RuntimeEnvironment {\n if (runtimeEnvironment === undefined) {\n const env = getEnv();\n\n runtimeEnvironment = {\n library: \"langchain-js\",\n runtime: env,\n };\n }\n return runtimeEnvironment;\n}\n\nexport function getEnvironmentVariable(name: string): string | undefined {\n // Certain Deno setups will throw an error if you try to access environment variables\n // https://github.com/langchain-ai/langchainjs/issues/1412\n try {\n if (typeof process !== \"undefined\") {\n // oxlint-disable-next-line no-process-env\n return process.env?.[name];\n } else if (isDeno()) {\n // @ts-expect-error Langsmith's Deno declaration is missing `env`\n return Deno?.env.get(name);\n } else {\n return undefined;\n }\n } catch {\n return undefined;\n }\n}\n"],"mappings":";;;;;;;;;;;;AAeA,MAAa,kBACX,OAAO,WAAW,eAAe,OAAO,OAAO,aAAa;AAE9D,MAAa,oBACX,OAAO,eAAe,YACtB,WAAW,eACX,WAAW,YAAY,SAAS;AAElC,MAAa,gBACV,OAAO,WAAW,eAAe,OAAO,SAAS,YACjD,OAAO,cAAc,eAAe,UAAU,UAAU,SAAS,QAAQ;AAI5E,MAAa,eAAe,OAAO,SAAS;AAG5C,MAAa,eACX,OAAO,YAAY,eACnB,OAAO,QAAQ,aAAa,eAC5B,OAAO,QAAQ,SAAS,SAAS,eACjC,CAAC,QAAQ;AAEX,MAAa,eAAe;CAC1B,IAAI;AACJ,KAAI,WAAW,CACb,OAAM;UACG,QAAQ,CACjB,OAAM;UACG,aAAa,CACtB,OAAM;UACG,SAAS,CAClB,OAAM;UACG,QAAQ,CACjB,OAAM;KAEN,OAAM;AAGR,QAAO;;AAUT,IAAI;AAEJ,SAAgB,wBAA4C;AAC1D,KAAI,uBAAuB,KAAA,EAGzB,sBAAqB;EACnB,SAAS;EACT,SAJU,QAIE;EACb;AAEH,QAAO;;AAGT,SAAgB,uBAAuB,MAAkC;AAGvE,KAAI;AACF,MAAI,OAAO,YAAY,YAErB,QAAO,QAAQ,MAAM;WACZ,QAAQ,CAEjB,QAAO,MAAM,IAAI,IAAI,KAAK;MAE1B;SAEI;AACN"}
@@ -1 +1 @@
1
- {"version":3,"file":"env.js","names":[],"sources":["../../src/utils/env.ts"],"sourcesContent":["// Inlined from https://github.com/flexdinesh/browser-or-node\ndeclare global {\n // @ts-expect-error Conflicts with langsmith's ambient Deno declaration\n const Deno:\n | {\n version: {\n deno: string;\n };\n env: {\n get: (name: string) => string | undefined;\n };\n }\n | undefined;\n}\n\nexport const isBrowser = () =>\n typeof window !== \"undefined\" && typeof window.document !== \"undefined\";\n\nexport const isWebWorker = () =>\n typeof globalThis === \"object\" &&\n globalThis.constructor &&\n globalThis.constructor.name === \"DedicatedWorkerGlobalScope\";\n\nexport const isJsDom = () =>\n (typeof window !== \"undefined\" && window.name === \"nodejs\") ||\n (typeof navigator !== \"undefined\" && navigator.userAgent.includes(\"jsdom\"));\n\n// Supabase Edge Function provides a `Deno` global object\n// without `version` property\nexport const isDeno = () => typeof Deno !== \"undefined\";\n\n// Mark not-as-node if in Supabase Edge Function\nexport const isNode = () =>\n typeof process !== \"undefined\" &&\n typeof process.versions !== \"undefined\" &&\n typeof process.versions.node !== \"undefined\" &&\n !isDeno();\n\nexport const getEnv = () => {\n let env: string;\n if (isBrowser()) {\n env = \"browser\";\n } else if (isNode()) {\n env = \"node\";\n } else if (isWebWorker()) {\n env = \"webworker\";\n } else if (isJsDom()) {\n env = \"jsdom\";\n } else if (isDeno()) {\n env = \"deno\";\n } else {\n env = \"other\";\n }\n\n return env;\n};\n\nexport type RuntimeEnvironment = {\n library: string;\n libraryVersion?: string;\n runtime: string;\n runtimeVersion?: string;\n};\n\nlet runtimeEnvironment: RuntimeEnvironment | undefined;\n\nexport function getRuntimeEnvironment(): RuntimeEnvironment {\n if (runtimeEnvironment === undefined) {\n const env = getEnv();\n\n runtimeEnvironment = {\n library: \"langchain-js\",\n runtime: env,\n };\n }\n return runtimeEnvironment;\n}\n\nexport function getEnvironmentVariable(name: string): string | undefined {\n // Certain Deno setups will throw an error if you try to access environment variables\n // https://github.com/langchain-ai/langchainjs/issues/1412\n try {\n if (typeof process !== \"undefined\") {\n // oxlint-disable-next-line no-process-env\n return process.env?.[name];\n } else if (isDeno()) {\n // @ts-expect-error Langsmith's Deno declaration is missing `env`\n return Deno?.env.get(name);\n } else {\n return undefined;\n }\n } catch {\n return undefined;\n }\n}\n"],"mappings":";;;;;;;;;;;;AAeA,MAAa,kBACX,OAAO,WAAW,eAAe,OAAO,OAAO,aAAa;AAE9D,MAAa,oBACX,OAAO,eAAe,YACtB,WAAW,eACX,WAAW,YAAY,SAAS;AAElC,MAAa,gBACV,OAAO,WAAW,eAAe,OAAO,SAAS,YACjD,OAAO,cAAc,eAAe,UAAU,UAAU,SAAS,QAAQ;AAI5E,MAAa,eAAe,OAAO,SAAS;AAG5C,MAAa,eACX,OAAO,YAAY,eACnB,OAAO,QAAQ,aAAa,eAC5B,OAAO,QAAQ,SAAS,SAAS,eACjC,CAAC,QAAQ;AAEX,MAAa,eAAe;CAC1B,IAAI;AACJ,KAAI,WAAW,CACb,OAAM;UACG,QAAQ,CACjB,OAAM;UACG,aAAa,CACtB,OAAM;UACG,SAAS,CAClB,OAAM;UACG,QAAQ,CACjB,OAAM;KAEN,OAAM;AAGR,QAAO;;AAUT,IAAI;AAEJ,SAAgB,wBAA4C;AAC1D,KAAI,uBAAuB,KAAA,EAGzB,sBAAqB;EACnB,SAAS;EACT,SAJU,QAAQ;EAKnB;AAEH,QAAO;;AAGT,SAAgB,uBAAuB,MAAkC;AAGvE,KAAI;AACF,MAAI,OAAO,YAAY,YAErB,QAAO,QAAQ,MAAM;WACZ,QAAQ,CAEjB,QAAO,MAAM,IAAI,IAAI,KAAK;MAE1B;SAEI;AACN"}
1
+ {"version":3,"file":"env.js","names":[],"sources":["../../src/utils/env.ts"],"sourcesContent":["// Inlined from https://github.com/flexdinesh/browser-or-node\ndeclare global {\n // @ts-expect-error Conflicts with langsmith's ambient Deno declaration\n const Deno:\n | {\n version: {\n deno: string;\n };\n env: {\n get: (name: string) => string | undefined;\n };\n }\n | undefined;\n}\n\nexport const isBrowser = () =>\n typeof window !== \"undefined\" && typeof window.document !== \"undefined\";\n\nexport const isWebWorker = () =>\n typeof globalThis === \"object\" &&\n globalThis.constructor &&\n globalThis.constructor.name === \"DedicatedWorkerGlobalScope\";\n\nexport const isJsDom = () =>\n (typeof window !== \"undefined\" && window.name === \"nodejs\") ||\n (typeof navigator !== \"undefined\" && navigator.userAgent.includes(\"jsdom\"));\n\n// Supabase Edge Function provides a `Deno` global object\n// without `version` property\nexport const isDeno = () => typeof Deno !== \"undefined\";\n\n// Mark not-as-node if in Supabase Edge Function\nexport const isNode = () =>\n typeof process !== \"undefined\" &&\n typeof process.versions !== \"undefined\" &&\n typeof process.versions.node !== \"undefined\" &&\n !isDeno();\n\nexport const getEnv = () => {\n let env: string;\n if (isBrowser()) {\n env = \"browser\";\n } else if (isNode()) {\n env = \"node\";\n } else if (isWebWorker()) {\n env = \"webworker\";\n } else if (isJsDom()) {\n env = \"jsdom\";\n } else if (isDeno()) {\n env = \"deno\";\n } else {\n env = \"other\";\n }\n\n return env;\n};\n\nexport type RuntimeEnvironment = {\n library: string;\n libraryVersion?: string;\n runtime: string;\n runtimeVersion?: string;\n};\n\nlet runtimeEnvironment: RuntimeEnvironment | undefined;\n\nexport function getRuntimeEnvironment(): RuntimeEnvironment {\n if (runtimeEnvironment === undefined) {\n const env = getEnv();\n\n runtimeEnvironment = {\n library: \"langchain-js\",\n runtime: env,\n };\n }\n return runtimeEnvironment;\n}\n\nexport function getEnvironmentVariable(name: string): string | undefined {\n // Certain Deno setups will throw an error if you try to access environment variables\n // https://github.com/langchain-ai/langchainjs/issues/1412\n try {\n if (typeof process !== \"undefined\") {\n // oxlint-disable-next-line no-process-env\n return process.env?.[name];\n } else if (isDeno()) {\n // @ts-expect-error Langsmith's Deno declaration is missing `env`\n return Deno?.env.get(name);\n } else {\n return undefined;\n }\n } catch {\n return undefined;\n }\n}\n"],"mappings":";;;;;;;;;;;;AAeA,MAAa,kBACX,OAAO,WAAW,eAAe,OAAO,OAAO,aAAa;AAE9D,MAAa,oBACX,OAAO,eAAe,YACtB,WAAW,eACX,WAAW,YAAY,SAAS;AAElC,MAAa,gBACV,OAAO,WAAW,eAAe,OAAO,SAAS,YACjD,OAAO,cAAc,eAAe,UAAU,UAAU,SAAS,QAAQ;AAI5E,MAAa,eAAe,OAAO,SAAS;AAG5C,MAAa,eACX,OAAO,YAAY,eACnB,OAAO,QAAQ,aAAa,eAC5B,OAAO,QAAQ,SAAS,SAAS,eACjC,CAAC,QAAQ;AAEX,MAAa,eAAe;CAC1B,IAAI;AACJ,KAAI,WAAW,CACb,OAAM;UACG,QAAQ,CACjB,OAAM;UACG,aAAa,CACtB,OAAM;UACG,SAAS,CAClB,OAAM;UACG,QAAQ,CACjB,OAAM;KAEN,OAAM;AAGR,QAAO;;AAUT,IAAI;AAEJ,SAAgB,wBAA4C;AAC1D,KAAI,uBAAuB,KAAA,EAGzB,sBAAqB;EACnB,SAAS;EACT,SAJU,QAIE;EACb;AAEH,QAAO;;AAGT,SAAgB,uBAAuB,MAAkC;AAGvE,KAAI;AACF,MAAI,OAAO,YAAY,YAErB,QAAO,QAAQ,MAAM;WACZ,QAAQ,CAEjB,QAAO,MAAM,IAAI,IAAI,KAAK;MAE1B;SAEI;AACN"}
@@ -1 +1 @@
1
- {"version":3,"file":"core.cjs","names":["PatchError","_deepClone","isInteger","unescapePathComponent","hasUndefined"],"sources":["../../../../src/utils/fast-json-patch/src/core.ts"],"sourcesContent":["// @ts-nocheck\n\n// Inlined because of ESM import issues\n\n/*!\n * https://github.com/Starcounter-Jack/JSON-Patch\n * (c) 2013-2021 Joachim Wester\n * MIT license\n */\ndeclare var require: any;\n\nimport {\n PatchError,\n _deepClone,\n isInteger,\n unescapePathComponent,\n hasUndefined,\n} from \"./helpers.js\";\n\nexport const JsonPatchError = PatchError;\nexport const deepClone = _deepClone;\n\nexport type Operation =\n | AddOperation<any>\n | RemoveOperation\n | ReplaceOperation<any>\n | MoveOperation\n | CopyOperation\n | TestOperation<any>\n | GetOperation<any>;\n\nexport interface Validator<T> {\n (\n operation: Operation,\n index: number,\n document: T,\n existingPathFragment: string\n ): void;\n}\n\nexport interface OperationResult<T> {\n removed?: any;\n test?: boolean;\n newDocument: T;\n}\n\nexport interface BaseOperation {\n path: string;\n}\n\nexport interface AddOperation<T> extends BaseOperation {\n op: \"add\";\n value: T;\n}\n\nexport interface RemoveOperation extends BaseOperation {\n op: \"remove\";\n}\n\nexport interface ReplaceOperation<T> extends BaseOperation {\n op: \"replace\";\n value: T;\n}\n\nexport interface MoveOperation extends BaseOperation {\n op: \"move\";\n from: string;\n}\n\nexport interface CopyOperation extends BaseOperation {\n op: \"copy\";\n from: string;\n}\n\nexport interface TestOperation<T> extends BaseOperation {\n op: \"test\";\n value: T;\n}\n\nexport interface GetOperation<T> extends BaseOperation {\n op: \"_get\";\n value: T;\n}\nexport interface PatchResult<T> extends Array<OperationResult<T>> {\n newDocument: T;\n}\n\n/* We use a Javascript hash to store each\n function. Each hash entry (property) uses\n the operation identifiers specified in rfc6902.\n In this way, we can map each patch operation\n to its dedicated function in efficient way.\n */\n\n/* The operations applicable to an object */\nconst objOps = {\n add: function (obj, key, document) {\n if (key === \"__proto__\" || key === \"constructor\") {\n throw new TypeError(\n \"JSON-Patch: modifying `__proto__` or `constructor` prop is banned for security reasons\"\n );\n }\n obj[key] = this.value;\n return { newDocument: document };\n },\n remove: function (obj, key, document) {\n if (key === \"__proto__\" || key === \"constructor\") {\n throw new TypeError(\n \"JSON-Patch: modifying `__proto__` or `constructor` prop is banned for security reasons\"\n );\n }\n var removed = obj[key];\n delete obj[key];\n return { newDocument: document, removed };\n },\n replace: function (obj, key, document) {\n if (key === \"__proto__\" || key === \"constructor\") {\n throw new TypeError(\n \"JSON-Patch: modifying `__proto__` or `constructor` prop is banned for security reasons\"\n );\n }\n var removed = obj[key];\n obj[key] = this.value;\n return { newDocument: document, removed };\n },\n move: function (obj, key, document) {\n /* in case move target overwrites an existing value,\n return the removed value, this can be taxing performance-wise,\n and is potentially unneeded */\n let removed = getValueByPointer(document, this.path);\n\n if (removed) {\n removed = _deepClone(removed);\n }\n\n const originalValue = applyOperation(document, {\n op: \"remove\",\n path: this.from,\n }).removed;\n\n applyOperation(document, {\n op: \"add\",\n path: this.path,\n value: originalValue,\n });\n\n return { newDocument: document, removed };\n },\n copy: function (obj, key, document) {\n const valueToCopy = getValueByPointer(document, this.from);\n // enforce copy by value so further operations don't affect source (see issue #177)\n applyOperation(document, {\n op: \"add\",\n path: this.path,\n value: _deepClone(valueToCopy),\n });\n return { newDocument: document };\n },\n test: function (obj, key, document) {\n return { newDocument: document, test: _areEquals(obj[key], this.value) };\n },\n _get: function (obj, key, document) {\n this.value = obj[key];\n return { newDocument: document };\n },\n};\n\n/* The operations applicable to an array. Many are the same as for the object */\nvar arrOps = {\n add: function (arr, i, document) {\n if (isInteger(i)) {\n arr.splice(i, 0, this.value);\n } else {\n // array props\n arr[i] = this.value;\n }\n // this may be needed when using '-' in an array\n return { newDocument: document, index: i };\n },\n remove: function (arr, i, document) {\n var removedList = arr.splice(i, 1);\n return { newDocument: document, removed: removedList[0] };\n },\n replace: function (arr, i, document) {\n var removed = arr[i];\n arr[i] = this.value;\n return { newDocument: document, removed };\n },\n move: objOps.move,\n copy: objOps.copy,\n test: objOps.test,\n _get: objOps._get,\n};\n\n/**\n * Retrieves a value from a JSON document by a JSON pointer.\n * Returns the value.\n *\n * @param document The document to get the value from\n * @param pointer an escaped JSON pointer\n * @return The retrieved value\n */\nexport function getValueByPointer(document: any, pointer: string): any {\n if (pointer == \"\") {\n return document;\n }\n var getOriginalDestination = <GetOperation<any>>{ op: \"_get\", path: pointer };\n applyOperation(document, getOriginalDestination);\n return getOriginalDestination.value;\n}\n/**\n * Apply a single JSON Patch Operation on a JSON document.\n * Returns the {newDocument, result} of the operation.\n * It modifies the `document` and `operation` objects - it gets the values by reference.\n * If you would like to avoid touching your values, clone them:\n * `jsonpatch.applyOperation(document, jsonpatch._deepClone(operation))`.\n *\n * @param document The document to patch\n * @param operation The operation to apply\n * @param validateOperation `false` is without validation, `true` to use default jsonpatch's validation, or you can pass a `validateOperation` callback to be used for validation.\n * @param mutateDocument Whether to mutate the original document or clone it before applying\n * @param banPrototypeModifications Whether to ban modifications to `__proto__`, defaults to `true`.\n * @return `{newDocument, result}` after the operation\n */\nexport function applyOperation<T>(\n document: T,\n operation: Operation,\n validateOperation: boolean | Validator<T> = false,\n mutateDocument: boolean = true,\n banPrototypeModifications: boolean = true,\n index: number = 0\n): OperationResult<T> {\n if (validateOperation) {\n if (typeof validateOperation == \"function\") {\n validateOperation(operation, 0, document, operation.path);\n } else {\n validator(operation, 0);\n }\n }\n /* ROOT OPERATIONS */\n if (operation.path === \"\") {\n let returnValue: OperationResult<T> = { newDocument: document };\n if (operation.op === \"add\") {\n returnValue.newDocument = operation.value;\n return returnValue;\n } else if (operation.op === \"replace\") {\n returnValue.newDocument = operation.value;\n returnValue.removed = document; //document we removed\n return returnValue;\n } else if (operation.op === \"move\" || operation.op === \"copy\") {\n // it's a move or copy to root\n returnValue.newDocument = getValueByPointer(document, operation.from); // get the value by json-pointer in `from` field\n if (operation.op === \"move\") {\n // report removed item\n returnValue.removed = document;\n }\n return returnValue;\n } else if (operation.op === \"test\") {\n returnValue.test = _areEquals(document, operation.value);\n if (returnValue.test === false) {\n throw new JsonPatchError(\n \"Test operation failed\",\n \"TEST_OPERATION_FAILED\",\n index,\n operation,\n document\n );\n }\n returnValue.newDocument = document;\n return returnValue;\n } else if (operation.op === \"remove\") {\n // a remove on root\n returnValue.removed = document;\n returnValue.newDocument = null;\n return returnValue;\n } else if (operation.op === \"_get\") {\n operation.value = document;\n return returnValue;\n } else {\n /* bad operation */\n if (validateOperation) {\n throw new JsonPatchError(\n \"Operation `op` property is not one of operations defined in RFC-6902\",\n \"OPERATION_OP_INVALID\",\n index,\n operation,\n document\n );\n } else {\n return returnValue;\n }\n }\n } /* END ROOT OPERATIONS */ else {\n if (!mutateDocument) {\n document = _deepClone(document);\n }\n const path = operation.path || \"\";\n const keys = path.split(\"/\");\n let obj = document;\n let t = 1; //skip empty element - http://jsperf.com/to-shift-or-not-to-shift\n let len = keys.length;\n let existingPathFragment = undefined;\n let key: string | number;\n let validateFunction;\n if (typeof validateOperation == \"function\") {\n validateFunction = validateOperation;\n } else {\n validateFunction = validator;\n }\n while (true) {\n key = keys[t];\n if (key && key.indexOf(\"~\") != -1) {\n key = unescapePathComponent(key);\n }\n\n if (\n banPrototypeModifications &&\n (key == \"__proto__\" ||\n (key == \"prototype\" && t > 0 && keys[t - 1] == \"constructor\"))\n ) {\n throw new TypeError(\n \"JSON-Patch: modifying `__proto__` or `constructor/prototype` prop is banned for security reasons, if this was on purpose, please set `banPrototypeModifications` flag false and pass it to this function. More info in fast-json-patch README\"\n );\n }\n\n if (validateOperation) {\n if (existingPathFragment === undefined) {\n if (obj[key] === undefined) {\n existingPathFragment = keys.slice(0, t).join(\"/\");\n } else if (t == len - 1) {\n existingPathFragment = operation.path;\n }\n if (existingPathFragment !== undefined) {\n validateFunction(operation, 0, document, existingPathFragment);\n }\n }\n }\n t++;\n if (Array.isArray(obj)) {\n if (key === \"-\") {\n key = obj.length;\n } else {\n if (validateOperation && !isInteger(key)) {\n throw new JsonPatchError(\n \"Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index\",\n \"OPERATION_PATH_ILLEGAL_ARRAY_INDEX\",\n index,\n operation,\n document\n );\n } // only parse key when it's an integer for `arr.prop` to work\n else if (isInteger(key)) {\n key = ~~key;\n }\n }\n if (t >= len) {\n if (validateOperation && operation.op === \"add\" && key > obj.length) {\n throw new JsonPatchError(\n \"The specified index MUST NOT be greater than the number of elements in the array\",\n \"OPERATION_VALUE_OUT_OF_BOUNDS\",\n index,\n operation,\n document\n );\n }\n const returnValue = arrOps[operation.op].call(\n operation,\n obj,\n key,\n document\n ); // Apply patch\n if (returnValue.test === false) {\n throw new JsonPatchError(\n \"Test operation failed\",\n \"TEST_OPERATION_FAILED\",\n index,\n operation,\n document\n );\n }\n return returnValue;\n }\n } else {\n if (t >= len) {\n const returnValue = objOps[operation.op].call(\n operation,\n obj,\n key,\n document\n ); // Apply patch\n if (returnValue.test === false) {\n throw new JsonPatchError(\n \"Test operation failed\",\n \"TEST_OPERATION_FAILED\",\n index,\n operation,\n document\n );\n }\n return returnValue;\n }\n }\n obj = obj[key];\n // If we have more keys in the path, but the next value isn't a non-null object,\n // throw an OPERATION_PATH_UNRESOLVABLE error instead of iterating again.\n if (validateOperation && t < len && (!obj || typeof obj !== \"object\")) {\n throw new JsonPatchError(\n \"Cannot perform operation at the desired path\",\n \"OPERATION_PATH_UNRESOLVABLE\",\n index,\n operation,\n document\n );\n }\n }\n }\n}\n\n/**\n * Apply a full JSON Patch array on a JSON document.\n * Returns the {newDocument, result} of the patch.\n * It modifies the `document` object and `patch` - it gets the values by reference.\n * If you would like to avoid touching your values, clone them:\n * `jsonpatch.applyPatch(document, jsonpatch._deepClone(patch))`.\n *\n * @param document The document to patch\n * @param patch The patch to apply\n * @param validateOperation `false` is without validation, `true` to use default jsonpatch's validation, or you can pass a `validateOperation` callback to be used for validation.\n * @param mutateDocument Whether to mutate the original document or clone it before applying\n * @param banPrototypeModifications Whether to ban modifications to `__proto__`, defaults to `true`.\n * @return An array of `{newDocument, result}` after the patch\n */\nexport function applyPatch<T>(\n document: T,\n patch: ReadonlyArray<Operation>,\n validateOperation?: boolean | Validator<T>,\n mutateDocument: boolean = true,\n banPrototypeModifications: boolean = true\n): PatchResult<T> {\n if (validateOperation) {\n if (!Array.isArray(patch)) {\n throw new JsonPatchError(\n \"Patch sequence must be an array\",\n \"SEQUENCE_NOT_AN_ARRAY\"\n );\n }\n }\n if (!mutateDocument) {\n document = _deepClone(document);\n }\n const results = new Array(patch.length) as PatchResult<T>;\n\n for (let i = 0, length = patch.length; i < length; i++) {\n // we don't need to pass mutateDocument argument because if it was true, we already deep cloned the object, we'll just pass `true`\n results[i] = applyOperation(\n document,\n patch[i],\n validateOperation,\n true,\n banPrototypeModifications,\n i\n );\n document = results[i].newDocument; // in case root was replaced\n }\n results.newDocument = document;\n return results;\n}\n\n/**\n * Apply a single JSON Patch Operation on a JSON document.\n * Returns the updated document.\n * Suitable as a reducer.\n *\n * @param document The document to patch\n * @param operation The operation to apply\n * @return The updated document\n */\nexport function applyReducer<T>(\n document: T,\n operation: Operation,\n index: number\n): T {\n const operationResult: OperationResult<T> = applyOperation(\n document,\n operation\n );\n if (operationResult.test === false) {\n // failed test\n throw new JsonPatchError(\n \"Test operation failed\",\n \"TEST_OPERATION_FAILED\",\n index,\n operation,\n document\n );\n }\n return operationResult.newDocument;\n}\n\n/**\n * Validates a single operation. Called from `jsonpatch.validate`. Throws `JsonPatchError` in case of an error.\n * @param {object} operation - operation object (patch)\n * @param {number} index - index of operation in the sequence\n * @param {object} [document] - object where the operation is supposed to be applied\n * @param {string} [existingPathFragment] - comes along with `document`\n */\nexport function validator(\n operation: Operation,\n index: number,\n document?: any,\n existingPathFragment?: string\n): void {\n if (\n typeof operation !== \"object\" ||\n operation === null ||\n Array.isArray(operation)\n ) {\n throw new JsonPatchError(\n \"Operation is not an object\",\n \"OPERATION_NOT_AN_OBJECT\",\n index,\n operation,\n document\n );\n } else if (!objOps[operation.op]) {\n throw new JsonPatchError(\n \"Operation `op` property is not one of operations defined in RFC-6902\",\n \"OPERATION_OP_INVALID\",\n index,\n operation,\n document\n );\n } else if (typeof operation.path !== \"string\") {\n throw new JsonPatchError(\n \"Operation `path` property is not a string\",\n \"OPERATION_PATH_INVALID\",\n index,\n operation,\n document\n );\n } else if (operation.path.indexOf(\"/\") !== 0 && operation.path.length > 0) {\n // paths that aren't empty string should start with \"/\"\n throw new JsonPatchError(\n 'Operation `path` property must start with \"/\"',\n \"OPERATION_PATH_INVALID\",\n index,\n operation,\n document\n );\n } else if (\n (operation.op === \"move\" || operation.op === \"copy\") &&\n typeof operation.from !== \"string\"\n ) {\n throw new JsonPatchError(\n \"Operation `from` property is not present (applicable in `move` and `copy` operations)\",\n \"OPERATION_FROM_REQUIRED\",\n index,\n operation,\n document\n );\n } else if (\n (operation.op === \"add\" ||\n operation.op === \"replace\" ||\n operation.op === \"test\") &&\n operation.value === undefined\n ) {\n throw new JsonPatchError(\n \"Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)\",\n \"OPERATION_VALUE_REQUIRED\",\n index,\n operation,\n document\n );\n } else if (\n (operation.op === \"add\" ||\n operation.op === \"replace\" ||\n operation.op === \"test\") &&\n hasUndefined(operation.value)\n ) {\n throw new JsonPatchError(\n \"Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)\",\n \"OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED\",\n index,\n operation,\n document\n );\n } else if (document) {\n if (operation.op == \"add\") {\n var pathLen = operation.path.split(\"/\").length;\n var existingPathLen = existingPathFragment.split(\"/\").length;\n if (pathLen !== existingPathLen + 1 && pathLen !== existingPathLen) {\n throw new JsonPatchError(\n \"Cannot perform an `add` operation at the desired path\",\n \"OPERATION_PATH_CANNOT_ADD\",\n index,\n operation,\n document\n );\n }\n } else if (\n operation.op === \"replace\" ||\n operation.op === \"remove\" ||\n <any>operation.op === \"_get\"\n ) {\n if (operation.path !== existingPathFragment) {\n throw new JsonPatchError(\n \"Cannot perform the operation at a path that does not exist\",\n \"OPERATION_PATH_UNRESOLVABLE\",\n index,\n operation,\n document\n );\n }\n } else if (operation.op === \"move\" || operation.op === \"copy\") {\n var existingValue: any = {\n op: \"_get\",\n path: operation.from,\n value: undefined,\n };\n var error = validate([existingValue], document);\n if (error && error.name === \"OPERATION_PATH_UNRESOLVABLE\") {\n throw new JsonPatchError(\n \"Cannot perform the operation from a path that does not exist\",\n \"OPERATION_FROM_UNRESOLVABLE\",\n index,\n operation,\n document\n );\n }\n }\n }\n}\n\n/**\n * Validates a sequence of operations. If `document` parameter is provided, the sequence is additionally validated against the object document.\n * If error is encountered, returns a JsonPatchError object\n * @param sequence\n * @param document\n * @returns {JsonPatchError|undefined}\n */\nexport function validate<T>(\n sequence: ReadonlyArray<Operation>,\n document?: T,\n externalValidator?: Validator<T>\n): PatchError {\n try {\n if (!Array.isArray(sequence)) {\n throw new JsonPatchError(\n \"Patch sequence must be an array\",\n \"SEQUENCE_NOT_AN_ARRAY\"\n );\n }\n if (document) {\n //clone document and sequence so that we can safely try applying operations\n applyPatch(\n _deepClone(document),\n _deepClone(sequence),\n externalValidator || true\n );\n } else {\n externalValidator = externalValidator || validator;\n for (var i = 0; i < sequence.length; i++) {\n externalValidator(sequence[i], i, document, undefined);\n }\n }\n } catch (e) {\n if (e instanceof JsonPatchError) {\n return e;\n } else {\n throw e;\n }\n }\n}\n\n// based on https://github.com/epoberezkin/fast-deep-equal\n// MIT License\n\n// Copyright (c) 2017 Evgeny Poberezkin\n\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n\n// The above copyright notice and this permission notice shall be included in all\n// copies or substantial portions of the Software.\n\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n// SOFTWARE.\nexport function _areEquals(a: any, b: any): boolean {\n if (a === b) return true;\n\n if (a && b && typeof a == \"object\" && typeof b == \"object\") {\n var arrA = Array.isArray(a),\n arrB = Array.isArray(b),\n i,\n length,\n key;\n\n if (arrA && arrB) {\n length = a.length;\n if (length != b.length) return false;\n for (i = length; i-- !== 0; ) if (!_areEquals(a[i], b[i])) return false;\n return true;\n }\n\n if (arrA != arrB) return false;\n\n var keys = Object.keys(a);\n length = keys.length;\n\n if (length !== Object.keys(b).length) return false;\n\n for (i = length; i-- !== 0; ) if (!b.hasOwnProperty(keys[i])) return false;\n\n for (i = length; i-- !== 0; ) {\n key = keys[i];\n if (!_areEquals(a[key], b[key])) return false;\n }\n\n return true;\n }\n\n return a !== a && b !== b;\n}\n"],"mappings":";;;;;;;;;;;;;;AAmBA,MAAa,iBAAiBA,gBAAAA;AAC9B,MAAa,YAAYC,gBAAAA;AA2EzB,MAAM,SAAS;CACb,KAAK,SAAU,KAAK,KAAK,UAAU;AACjC,MAAI,QAAQ,eAAe,QAAQ,cACjC,OAAM,IAAI,UACR,yFACD;AAEH,MAAI,OAAO,KAAK;AAChB,SAAO,EAAE,aAAa,UAAU;;CAElC,QAAQ,SAAU,KAAK,KAAK,UAAU;AACpC,MAAI,QAAQ,eAAe,QAAQ,cACjC,OAAM,IAAI,UACR,yFACD;EAEH,IAAI,UAAU,IAAI;AAClB,SAAO,IAAI;AACX,SAAO;GAAE,aAAa;GAAU;GAAS;;CAE3C,SAAS,SAAU,KAAK,KAAK,UAAU;AACrC,MAAI,QAAQ,eAAe,QAAQ,cACjC,OAAM,IAAI,UACR,yFACD;EAEH,IAAI,UAAU,IAAI;AAClB,MAAI,OAAO,KAAK;AAChB,SAAO;GAAE,aAAa;GAAU;GAAS;;CAE3C,MAAM,SAAU,KAAK,KAAK,UAAU;EAIlC,IAAI,UAAU,kBAAkB,UAAU,KAAK,KAAK;AAEpD,MAAI,QACF,WAAUA,gBAAAA,WAAW,QAAQ;EAG/B,MAAM,gBAAgB,eAAe,UAAU;GAC7C,IAAI;GACJ,MAAM,KAAK;GACZ,CAAC,CAAC;AAEH,iBAAe,UAAU;GACvB,IAAI;GACJ,MAAM,KAAK;GACX,OAAO;GACR,CAAC;AAEF,SAAO;GAAE,aAAa;GAAU;GAAS;;CAE3C,MAAM,SAAU,KAAK,KAAK,UAAU;EAClC,MAAM,cAAc,kBAAkB,UAAU,KAAK,KAAK;AAE1D,iBAAe,UAAU;GACvB,IAAI;GACJ,MAAM,KAAK;GACX,OAAOA,gBAAAA,WAAW,YA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ClE,UAAO;;AAGT,MAAI,QAAQ,KAAM,QAAO;EAEzB,IAAI,OAAO,OAAO,KAAK,EAAE;AACzB,WAAS,KAAK;AAEd,MAAI,WAAW,OAAO,KAAK,EAAE,CAAC,OAAQ,QAAO;AAE7C,OAAK,IAAI,QAAQ,QAAQ,GAAK,KAAI,CAAC,EAAE,eAAe,KAAK,GAAG,CAAE,QAAO;AAErE,OAAK,IAAI,QAAQ,QAAQ,IAAK;AAC5B,SAAM,KAAK;AACX,OAAI,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,CAAE,QAAO;;AAG1C,SAAO;;AAGT,QAAO,MAAM,KAAK,MAAM"}
1
+ {"version":3,"file":"core.cjs","names":["PatchError","_deepClone","isInteger","unescapePathComponent","hasUndefined"],"sources":["../../../../src/utils/fast-json-patch/src/core.ts"],"sourcesContent":["// @ts-nocheck\n\n// Inlined because of ESM import issues\n\n/*!\n * https://github.com/Starcounter-Jack/JSON-Patch\n * (c) 2013-2021 Joachim Wester\n * MIT license\n */\ndeclare var require: any;\n\nimport {\n PatchError,\n _deepClone,\n isInteger,\n unescapePathComponent,\n hasUndefined,\n} from \"./helpers.js\";\n\nexport const JsonPatchError = PatchError;\nexport const deepClone = _deepClone;\n\nexport type Operation =\n | AddOperation<any>\n | RemoveOperation\n | ReplaceOperation<any>\n | MoveOperation\n | CopyOperation\n | TestOperation<any>\n | GetOperation<any>;\n\nexport interface Validator<T> {\n (\n operation: Operation,\n index: number,\n document: T,\n existingPathFragment: string\n ): void;\n}\n\nexport interface OperationResult<T> {\n removed?: any;\n test?: boolean;\n newDocument: T;\n}\n\nexport interface BaseOperation {\n path: string;\n}\n\nexport interface AddOperation<T> extends BaseOperation {\n op: \"add\";\n value: T;\n}\n\nexport interface RemoveOperation extends BaseOperation {\n op: \"remove\";\n}\n\nexport interface ReplaceOperation<T> extends BaseOperation {\n op: \"replace\";\n value: T;\n}\n\nexport interface MoveOperation extends BaseOperation {\n op: \"move\";\n from: string;\n}\n\nexport interface CopyOperation extends BaseOperation {\n op: \"copy\";\n from: string;\n}\n\nexport interface TestOperation<T> extends BaseOperation {\n op: \"test\";\n value: T;\n}\n\nexport interface GetOperation<T> extends BaseOperation {\n op: \"_get\";\n value: T;\n}\nexport interface PatchResult<T> extends Array<OperationResult<T>> {\n newDocument: T;\n}\n\n/* We use a Javascript hash to store each\n function. Each hash entry (property) uses\n the operation identifiers specified in rfc6902.\n In this way, we can map each patch operation\n to its dedicated function in efficient way.\n */\n\n/* The operations applicable to an object */\nconst objOps = {\n add: function (obj, key, document) {\n if (key === \"__proto__\" || key === \"constructor\") {\n throw new TypeError(\n \"JSON-Patch: modifying `__proto__` or `constructor` prop is banned for security reasons\"\n );\n }\n obj[key] = this.value;\n return { newDocument: document };\n },\n remove: function (obj, key, document) {\n if (key === \"__proto__\" || key === \"constructor\") {\n throw new TypeError(\n \"JSON-Patch: modifying `__proto__` or `constructor` prop is banned for security reasons\"\n );\n }\n var removed = obj[key];\n delete obj[key];\n return { newDocument: document, removed };\n },\n replace: function (obj, key, document) {\n if (key === \"__proto__\" || key === \"constructor\") {\n throw new TypeError(\n \"JSON-Patch: modifying `__proto__` or `constructor` prop is banned for security reasons\"\n );\n }\n var removed = obj[key];\n obj[key] = this.value;\n return { newDocument: document, removed };\n },\n move: function (obj, key, document) {\n /* in case move target overwrites an existing value,\n return the removed value, this can be taxing performance-wise,\n and is potentially unneeded */\n let removed = getValueByPointer(document, this.path);\n\n if (removed) {\n removed = _deepClone(removed);\n }\n\n const originalValue = applyOperation(document, {\n op: \"remove\",\n path: this.from,\n }).removed;\n\n applyOperation(document, {\n op: \"add\",\n path: this.path,\n value: originalValue,\n });\n\n return { newDocument: document, removed };\n },\n copy: function (obj, key, document) {\n const valueToCopy = getValueByPointer(document, this.from);\n // enforce copy by value so further operations don't affect source (see issue #177)\n applyOperation(document, {\n op: \"add\",\n path: this.path,\n value: _deepClone(valueToCopy),\n });\n return { newDocument: document };\n },\n test: function (obj, key, document) {\n return { newDocument: document, test: _areEquals(obj[key], this.value) };\n },\n _get: function (obj, key, document) {\n this.value = obj[key];\n return { newDocument: document };\n },\n};\n\n/* The operations applicable to an array. Many are the same as for the object */\nvar arrOps = {\n add: function (arr, i, document) {\n if (isInteger(i)) {\n arr.splice(i, 0, this.value);\n } else {\n // array props\n arr[i] = this.value;\n }\n // this may be needed when using '-' in an array\n return { newDocument: document, index: i };\n },\n remove: function (arr, i, document) {\n var removedList = arr.splice(i, 1);\n return { newDocument: document, removed: removedList[0] };\n },\n replace: function (arr, i, document) {\n var removed = arr[i];\n arr[i] = this.value;\n return { newDocument: document, removed };\n },\n move: objOps.move,\n copy: objOps.copy,\n test: objOps.test,\n _get: objOps._get,\n};\n\n/**\n * Retrieves a value from a JSON document by a JSON pointer.\n * Returns the value.\n *\n * @param document The document to get the value from\n * @param pointer an escaped JSON pointer\n * @return The retrieved value\n */\nexport function getValueByPointer(document: any, pointer: string): any {\n if (pointer == \"\") {\n return document;\n }\n var getOriginalDestination = <GetOperation<any>>{ op: \"_get\", path: pointer };\n applyOperation(document, getOriginalDestination);\n return getOriginalDestination.value;\n}\n/**\n * Apply a single JSON Patch Operation on a JSON document.\n * Returns the {newDocument, result} of the operation.\n * It modifies the `document` and `operation` objects - it gets the values by reference.\n * If you would like to avoid touching your values, clone them:\n * `jsonpatch.applyOperation(document, jsonpatch._deepClone(operation))`.\n *\n * @param document The document to patch\n * @param operation The operation to apply\n * @param validateOperation `false` is without validation, `true` to use default jsonpatch's validation, or you can pass a `validateOperation` callback to be used for validation.\n * @param mutateDocument Whether to mutate the original document or clone it before applying\n * @param banPrototypeModifications Whether to ban modifications to `__proto__`, defaults to `true`.\n * @return `{newDocument, result}` after the operation\n */\nexport function applyOperation<T>(\n document: T,\n operation: Operation,\n validateOperation: boolean | Validator<T> = false,\n mutateDocument: boolean = true,\n banPrototypeModifications: boolean = true,\n index: number = 0\n): OperationResult<T> {\n if (validateOperation) {\n if (typeof validateOperation == \"function\") {\n validateOperation(operation, 0, document, operation.path);\n } else {\n validator(operation, 0);\n }\n }\n /* ROOT OPERATIONS */\n if (operation.path === \"\") {\n let returnValue: OperationResult<T> = { newDocument: document };\n if (operation.op === \"add\") {\n returnValue.newDocument = operation.value;\n return returnValue;\n } else if (operation.op === \"replace\") {\n returnValue.newDocument = operation.value;\n returnValue.removed = document; //document we removed\n return returnValue;\n } else if (operation.op === \"move\" || operation.op === \"copy\") {\n // it's a move or copy to root\n returnValue.newDocument = getValueByPointer(document, operation.from); // get the value by json-pointer in `from` field\n if (operation.op === \"move\") {\n // report removed item\n returnValue.removed = document;\n }\n return returnValue;\n } else if (operation.op === \"test\") {\n returnValue.test = _areEquals(document, operation.value);\n if (returnValue.test === false) {\n throw new JsonPatchError(\n \"Test operation failed\",\n \"TEST_OPERATION_FAILED\",\n index,\n operation,\n document\n );\n }\n returnValue.newDocument = document;\n return returnValue;\n } else if (operation.op === \"remove\") {\n // a remove on root\n returnValue.removed = document;\n returnValue.newDocument = null;\n return returnValue;\n } else if (operation.op === \"_get\") {\n operation.value = document;\n return returnValue;\n } else {\n /* bad operation */\n if (validateOperation) {\n throw new JsonPatchError(\n \"Operation `op` property is not one of operations defined in RFC-6902\",\n \"OPERATION_OP_INVALID\",\n index,\n operation,\n document\n );\n } else {\n return returnValue;\n }\n }\n } /* END ROOT OPERATIONS */ else {\n if (!mutateDocument) {\n document = _deepClone(document);\n }\n const path = operation.path || \"\";\n const keys = path.split(\"/\");\n let obj = document;\n let t = 1; //skip empty element - http://jsperf.com/to-shift-or-not-to-shift\n let len = keys.length;\n let existingPathFragment = undefined;\n let key: string | number;\n let validateFunction;\n if (typeof validateOperation == \"function\") {\n validateFunction = validateOperation;\n } else {\n validateFunction = validator;\n }\n while (true) {\n key = keys[t];\n if (key && key.indexOf(\"~\") != -1) {\n key = unescapePathComponent(key);\n }\n\n if (\n banPrototypeModifications &&\n (key == \"__proto__\" ||\n (key == \"prototype\" && t > 0 && keys[t - 1] == \"constructor\"))\n ) {\n throw new TypeError(\n \"JSON-Patch: modifying `__proto__` or `constructor/prototype` prop is banned for security reasons, if this was on purpose, please set `banPrototypeModifications` flag false and pass it to this function. More info in fast-json-patch README\"\n );\n }\n\n if (validateOperation) {\n if (existingPathFragment === undefined) {\n if (obj[key] === undefined) {\n existingPathFragment = keys.slice(0, t).join(\"/\");\n } else if (t == len - 1) {\n existingPathFragment = operation.path;\n }\n if (existingPathFragment !== undefined) {\n validateFunction(operation, 0, document, existingPathFragment);\n }\n }\n }\n t++;\n if (Array.isArray(obj)) {\n if (key === \"-\") {\n key = obj.length;\n } else {\n if (validateOperation && !isInteger(key)) {\n throw new JsonPatchError(\n \"Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index\",\n \"OPERATION_PATH_ILLEGAL_ARRAY_INDEX\",\n index,\n operation,\n document\n );\n } // only parse key when it's an integer for `arr.prop` to work\n else if (isInteger(key)) {\n key = ~~key;\n }\n }\n if (t >= len) {\n if (validateOperation && operation.op === \"add\" && key > obj.length) {\n throw new JsonPatchError(\n \"The specified index MUST NOT be greater than the number of elements in the array\",\n \"OPERATION_VALUE_OUT_OF_BOUNDS\",\n index,\n operation,\n document\n );\n }\n const returnValue = arrOps[operation.op].call(\n operation,\n obj,\n key,\n document\n ); // Apply patch\n if (returnValue.test === false) {\n throw new JsonPatchError(\n \"Test operation failed\",\n \"TEST_OPERATION_FAILED\",\n index,\n operation,\n document\n );\n }\n return returnValue;\n }\n } else {\n if (t >= len) {\n const returnValue = objOps[operation.op].call(\n operation,\n obj,\n key,\n document\n ); // Apply patch\n if (returnValue.test === false) {\n throw new JsonPatchError(\n \"Test operation failed\",\n \"TEST_OPERATION_FAILED\",\n index,\n operation,\n document\n );\n }\n return returnValue;\n }\n }\n obj = obj[key];\n // If we have more keys in the path, but the next value isn't a non-null object,\n // throw an OPERATION_PATH_UNRESOLVABLE error instead of iterating again.\n if (validateOperation && t < len && (!obj || typeof obj !== \"object\")) {\n throw new JsonPatchError(\n \"Cannot perform operation at the desired path\",\n \"OPERATION_PATH_UNRESOLVABLE\",\n index,\n operation,\n document\n );\n }\n }\n }\n}\n\n/**\n * Apply a full JSON Patch array on a JSON document.\n * Returns the {newDocument, result} of the patch.\n * It modifies the `document` object and `patch` - it gets the values by reference.\n * If you would like to avoid touching your values, clone them:\n * `jsonpatch.applyPatch(document, jsonpatch._deepClone(patch))`.\n *\n * @param document The document to patch\n * @param patch The patch to apply\n * @param validateOperation `false` is without validation, `true` to use default jsonpatch's validation, or you can pass a `validateOperation` callback to be used for validation.\n * @param mutateDocument Whether to mutate the original document or clone it before applying\n * @param banPrototypeModifications Whether to ban modifications to `__proto__`, defaults to `true`.\n * @return An array of `{newDocument, result}` after the patch\n */\nexport function applyPatch<T>(\n document: T,\n patch: ReadonlyArray<Operation>,\n validateOperation?: boolean | Validator<T>,\n mutateDocument: boolean = true,\n banPrototypeModifications: boolean = true\n): PatchResult<T> {\n if (validateOperation) {\n if (!Array.isArray(patch)) {\n throw new JsonPatchError(\n \"Patch sequence must be an array\",\n \"SEQUENCE_NOT_AN_ARRAY\"\n );\n }\n }\n if (!mutateDocument) {\n document = _deepClone(document);\n }\n const results = new Array(patch.length) as PatchResult<T>;\n\n for (let i = 0, length = patch.length; i < length; i++) {\n // we don't need to pass mutateDocument argument because if it was true, we already deep cloned the object, we'll just pass `true`\n results[i] = applyOperation(\n document,\n patch[i],\n validateOperation,\n true,\n banPrototypeModifications,\n i\n );\n document = results[i].newDocument; // in case root was replaced\n }\n results.newDocument = document;\n return results;\n}\n\n/**\n * Apply a single JSON Patch Operation on a JSON document.\n * Returns the updated document.\n * Suitable as a reducer.\n *\n * @param document The document to patch\n * @param operation The operation to apply\n * @return The updated document\n */\nexport function applyReducer<T>(\n document: T,\n operation: Operation,\n index: number\n): T {\n const operationResult: OperationResult<T> = applyOperation(\n document,\n operation\n );\n if (operationResult.test === false) {\n // failed test\n throw new JsonPatchError(\n \"Test operation failed\",\n \"TEST_OPERATION_FAILED\",\n index,\n operation,\n document\n );\n }\n return operationResult.newDocument;\n}\n\n/**\n * Validates a single operation. Called from `jsonpatch.validate`. Throws `JsonPatchError` in case of an error.\n * @param {object} operation - operation object (patch)\n * @param {number} index - index of operation in the sequence\n * @param {object} [document] - object where the operation is supposed to be applied\n * @param {string} [existingPathFragment] - comes along with `document`\n */\nexport function validator(\n operation: Operation,\n index: number,\n document?: any,\n existingPathFragment?: string\n): void {\n if (\n typeof operation !== \"object\" ||\n operation === null ||\n Array.isArray(operation)\n ) {\n throw new JsonPatchError(\n \"Operation is not an object\",\n \"OPERATION_NOT_AN_OBJECT\",\n index,\n operation,\n document\n );\n } else if (!objOps[operation.op]) {\n throw new JsonPatchError(\n \"Operation `op` property is not one of operations defined in RFC-6902\",\n \"OPERATION_OP_INVALID\",\n index,\n operation,\n document\n );\n } else if (typeof operation.path !== \"string\") {\n throw new JsonPatchError(\n \"Operation `path` property is not a string\",\n \"OPERATION_PATH_INVALID\",\n index,\n operation,\n document\n );\n } else if (operation.path.indexOf(\"/\") !== 0 && operation.path.length > 0) {\n // paths that aren't empty string should start with \"/\"\n throw new JsonPatchError(\n 'Operation `path` property must start with \"/\"',\n \"OPERATION_PATH_INVALID\",\n index,\n operation,\n document\n );\n } else if (\n (operation.op === \"move\" || operation.op === \"copy\") &&\n typeof operation.from !== \"string\"\n ) {\n throw new JsonPatchError(\n \"Operation `from` property is not present (applicable in `move` and `copy` operations)\",\n \"OPERATION_FROM_REQUIRED\",\n index,\n operation,\n document\n );\n } else if (\n (operation.op === \"add\" ||\n operation.op === \"replace\" ||\n operation.op === \"test\") &&\n operation.value === undefined\n ) {\n throw new JsonPatchError(\n \"Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)\",\n \"OPERATION_VALUE_REQUIRED\",\n index,\n operation,\n document\n );\n } else if (\n (operation.op === \"add\" ||\n operation.op === \"replace\" ||\n operation.op === \"test\") &&\n hasUndefined(operation.value)\n ) {\n throw new JsonPatchError(\n \"Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)\",\n \"OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED\",\n index,\n operation,\n document\n );\n } else if (document) {\n if (operation.op == \"add\") {\n var pathLen = operation.path.split(\"/\").length;\n var existingPathLen = existingPathFragment.split(\"/\").length;\n if (pathLen !== existingPathLen + 1 && pathLen !== existingPathLen) {\n throw new JsonPatchError(\n \"Cannot perform an `add` operation at the desired path\",\n \"OPERATION_PATH_CANNOT_ADD\",\n index,\n operation,\n document\n );\n }\n } else if (\n operation.op === \"replace\" ||\n operation.op === \"remove\" ||\n <any>operation.op === \"_get\"\n ) {\n if (operation.path !== existingPathFragment) {\n throw new JsonPatchError(\n \"Cannot perform the operation at a path that does not exist\",\n \"OPERATION_PATH_UNRESOLVABLE\",\n index,\n operation,\n document\n );\n }\n } else if (operation.op === \"move\" || operation.op === \"copy\") {\n var existingValue: any = {\n op: \"_get\",\n path: operation.from,\n value: undefined,\n };\n var error = validate([existingValue], document);\n if (error && error.name === \"OPERATION_PATH_UNRESOLVABLE\") {\n throw new JsonPatchError(\n \"Cannot perform the operation from a path that does not exist\",\n \"OPERATION_FROM_UNRESOLVABLE\",\n index,\n operation,\n document\n );\n }\n }\n }\n}\n\n/**\n * Validates a sequence of operations. If `document` parameter is provided, the sequence is additionally validated against the object document.\n * If error is encountered, returns a JsonPatchError object\n * @param sequence\n * @param document\n * @returns {JsonPatchError|undefined}\n */\nexport function validate<T>(\n sequence: ReadonlyArray<Operation>,\n document?: T,\n externalValidator?: Validator<T>\n): PatchError {\n try {\n if (!Array.isArray(sequence)) {\n throw new JsonPatchError(\n \"Patch sequence must be an array\",\n \"SEQUENCE_NOT_AN_ARRAY\"\n );\n }\n if (document) {\n //clone document and sequence so that we can safely try applying operations\n applyPatch(\n _deepClone(document),\n _deepClone(sequence),\n externalValidator || true\n );\n } else {\n externalValidator = externalValidator || validator;\n for (var i = 0; i < sequence.length; i++) {\n externalValidator(sequence[i], i, document, undefined);\n }\n }\n } catch (e) {\n if (e instanceof JsonPatchError) {\n return e;\n } else {\n throw e;\n }\n }\n}\n\n// based on https://github.com/epoberezkin/fast-deep-equal\n// MIT License\n\n// Copyright (c) 2017 Evgeny Poberezkin\n\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n\n// The above copyright notice and this permission notice shall be included in all\n// copies or substantial portions of the Software.\n\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n// SOFTWARE.\nexport function _areEquals(a: any, b: any): boolean {\n if (a === b) return true;\n\n if (a && b && typeof a == \"object\" && typeof b == \"object\") {\n var arrA = Array.isArray(a),\n arrB = Array.isArray(b),\n i,\n length,\n key;\n\n if (arrA && arrB) {\n length = a.length;\n if (length != b.length) return false;\n for (i = length; i-- !== 0; ) if (!_areEquals(a[i], b[i])) return false;\n return true;\n }\n\n if (arrA != arrB) return false;\n\n var keys = Object.keys(a);\n length = keys.length;\n\n if (length !== Object.keys(b).length) return false;\n\n for (i = length; i-- !== 0; ) if (!b.hasOwnProperty(keys[i])) return false;\n\n for (i = length; i-- !== 0; ) {\n key = keys[i];\n if (!_areEquals(a[key], b[key])) return false;\n }\n\n return true;\n }\n\n return a !== a && b !== b;\n}\n"],"mappings":";;;;;;;;;;;;;;AAmBA,MAAa,iBAAiBA,gBA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,QAAQ,GAAK,KAAI,CAAC,EAAE,eAAe,KAAK,GAAG,CAAE,QAAO;AAErE,OAAK,IAAI,QAAQ,QAAQ,IAAK;AAC5B,SAAM,KAAK;AACX,OAAI,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,CAAE,QAAO;;AAG1C,SAAO;;AAGT,QAAO,MAAM,KAAK,MAAM"}
@@ -1 +1 @@
1
- {"version":3,"file":"core.js","names":[],"sources":["../../../../src/utils/fast-json-patch/src/core.ts"],"sourcesContent":["// @ts-nocheck\n\n// Inlined because of ESM import issues\n\n/*!\n * https://github.com/Starcounter-Jack/JSON-Patch\n * (c) 2013-2021 Joachim Wester\n * MIT license\n */\ndeclare var require: any;\n\nimport {\n PatchError,\n _deepClone,\n isInteger,\n unescapePathComponent,\n hasUndefined,\n} from \"./helpers.js\";\n\nexport const JsonPatchError = PatchError;\nexport const deepClone = _deepClone;\n\nexport type Operation =\n | AddOperation<any>\n | RemoveOperation\n | ReplaceOperation<any>\n | MoveOperation\n | CopyOperation\n | TestOperation<any>\n | GetOperation<any>;\n\nexport interface Validator<T> {\n (\n operation: Operation,\n index: number,\n document: T,\n existingPathFragment: string\n ): void;\n}\n\nexport interface OperationResult<T> {\n removed?: any;\n test?: boolean;\n newDocument: T;\n}\n\nexport interface BaseOperation {\n path: string;\n}\n\nexport interface AddOperation<T> extends BaseOperation {\n op: \"add\";\n value: T;\n}\n\nexport interface RemoveOperation extends BaseOperation {\n op: \"remove\";\n}\n\nexport interface ReplaceOperation<T> extends BaseOperation {\n op: \"replace\";\n value: T;\n}\n\nexport interface MoveOperation extends BaseOperation {\n op: \"move\";\n from: string;\n}\n\nexport interface CopyOperation extends BaseOperation {\n op: \"copy\";\n from: string;\n}\n\nexport interface TestOperation<T> extends BaseOperation {\n op: \"test\";\n value: T;\n}\n\nexport interface GetOperation<T> extends BaseOperation {\n op: \"_get\";\n value: T;\n}\nexport interface PatchResult<T> extends Array<OperationResult<T>> {\n newDocument: T;\n}\n\n/* We use a Javascript hash to store each\n function. Each hash entry (property) uses\n the operation identifiers specified in rfc6902.\n In this way, we can map each patch operation\n to its dedicated function in efficient way.\n */\n\n/* The operations applicable to an object */\nconst objOps = {\n add: function (obj, key, document) {\n if (key === \"__proto__\" || key === \"constructor\") {\n throw new TypeError(\n \"JSON-Patch: modifying `__proto__` or `constructor` prop is banned for security reasons\"\n );\n }\n obj[key] = this.value;\n return { newDocument: document };\n },\n remove: function (obj, key, document) {\n if (key === \"__proto__\" || key === \"constructor\") {\n throw new TypeError(\n \"JSON-Patch: modifying `__proto__` or `constructor` prop is banned for security reasons\"\n );\n }\n var removed = obj[key];\n delete obj[key];\n return { newDocument: document, removed };\n },\n replace: function (obj, key, document) {\n if (key === \"__proto__\" || key === \"constructor\") {\n throw new TypeError(\n \"JSON-Patch: modifying `__proto__` or `constructor` prop is banned for security reasons\"\n );\n }\n var removed = obj[key];\n obj[key] = this.value;\n return { newDocument: document, removed };\n },\n move: function (obj, key, document) {\n /* in case move target overwrites an existing value,\n return the removed value, this can be taxing performance-wise,\n and is potentially unneeded */\n let removed = getValueByPointer(document, this.path);\n\n if (removed) {\n removed = _deepClone(removed);\n }\n\n const originalValue = applyOperation(document, {\n op: \"remove\",\n path: this.from,\n }).removed;\n\n applyOperation(document, {\n op: \"add\",\n path: this.path,\n value: originalValue,\n });\n\n return { newDocument: document, removed };\n },\n copy: function (obj, key, document) {\n const valueToCopy = getValueByPointer(document, this.from);\n // enforce copy by value so further operations don't affect source (see issue #177)\n applyOperation(document, {\n op: \"add\",\n path: this.path,\n value: _deepClone(valueToCopy),\n });\n return { newDocument: document };\n },\n test: function (obj, key, document) {\n return { newDocument: document, test: _areEquals(obj[key], this.value) };\n },\n _get: function (obj, key, document) {\n this.value = obj[key];\n return { newDocument: document };\n },\n};\n\n/* The operations applicable to an array. Many are the same as for the object */\nvar arrOps = {\n add: function (arr, i, document) {\n if (isInteger(i)) {\n arr.splice(i, 0, this.value);\n } else {\n // array props\n arr[i] = this.value;\n }\n // this may be needed when using '-' in an array\n return { newDocument: document, index: i };\n },\n remove: function (arr, i, document) {\n var removedList = arr.splice(i, 1);\n return { newDocument: document, removed: removedList[0] };\n },\n replace: function (arr, i, document) {\n var removed = arr[i];\n arr[i] = this.value;\n return { newDocument: document, removed };\n },\n move: objOps.move,\n copy: objOps.copy,\n test: objOps.test,\n _get: objOps._get,\n};\n\n/**\n * Retrieves a value from a JSON document by a JSON pointer.\n * Returns the value.\n *\n * @param document The document to get the value from\n * @param pointer an escaped JSON pointer\n * @return The retrieved value\n */\nexport function getValueByPointer(document: any, pointer: string): any {\n if (pointer == \"\") {\n return document;\n }\n var getOriginalDestination = <GetOperation<any>>{ op: \"_get\", path: pointer };\n applyOperation(document, getOriginalDestination);\n return getOriginalDestination.value;\n}\n/**\n * Apply a single JSON Patch Operation on a JSON document.\n * Returns the {newDocument, result} of the operation.\n * It modifies the `document` and `operation` objects - it gets the values by reference.\n * If you would like to avoid touching your values, clone them:\n * `jsonpatch.applyOperation(document, jsonpatch._deepClone(operation))`.\n *\n * @param document The document to patch\n * @param operation The operation to apply\n * @param validateOperation `false` is without validation, `true` to use default jsonpatch's validation, or you can pass a `validateOperation` callback to be used for validation.\n * @param mutateDocument Whether to mutate the original document or clone it before applying\n * @param banPrototypeModifications Whether to ban modifications to `__proto__`, defaults to `true`.\n * @return `{newDocument, result}` after the operation\n */\nexport function applyOperation<T>(\n document: T,\n operation: Operation,\n validateOperation: boolean | Validator<T> = false,\n mutateDocument: boolean = true,\n banPrototypeModifications: boolean = true,\n index: number = 0\n): OperationResult<T> {\n if (validateOperation) {\n if (typeof validateOperation == \"function\") {\n validateOperation(operation, 0, document, operation.path);\n } else {\n validator(operation, 0);\n }\n }\n /* ROOT OPERATIONS */\n if (operation.path === \"\") {\n let returnValue: OperationResult<T> = { newDocument: document };\n if (operation.op === \"add\") {\n returnValue.newDocument = operation.value;\n return returnValue;\n } else if (operation.op === \"replace\") {\n returnValue.newDocument = operation.value;\n returnValue.removed = document; //document we removed\n return returnValue;\n } else if (operation.op === \"move\" || operation.op === \"copy\") {\n // it's a move or copy to root\n returnValue.newDocument = getValueByPointer(document, operation.from); // get the value by json-pointer in `from` field\n if (operation.op === \"move\") {\n // report removed item\n returnValue.removed = document;\n }\n return returnValue;\n } else if (operation.op === \"test\") {\n returnValue.test = _areEquals(document, operation.value);\n if (returnValue.test === false) {\n throw new JsonPatchError(\n \"Test operation failed\",\n \"TEST_OPERATION_FAILED\",\n index,\n operation,\n document\n );\n }\n returnValue.newDocument = document;\n return returnValue;\n } else if (operation.op === \"remove\") {\n // a remove on root\n returnValue.removed = document;\n returnValue.newDocument = null;\n return returnValue;\n } else if (operation.op === \"_get\") {\n operation.value = document;\n return returnValue;\n } else {\n /* bad operation */\n if (validateOperation) {\n throw new JsonPatchError(\n \"Operation `op` property is not one of operations defined in RFC-6902\",\n \"OPERATION_OP_INVALID\",\n index,\n operation,\n document\n );\n } else {\n return returnValue;\n }\n }\n } /* END ROOT OPERATIONS */ else {\n if (!mutateDocument) {\n document = _deepClone(document);\n }\n const path = operation.path || \"\";\n const keys = path.split(\"/\");\n let obj = document;\n let t = 1; //skip empty element - http://jsperf.com/to-shift-or-not-to-shift\n let len = keys.length;\n let existingPathFragment = undefined;\n let key: string | number;\n let validateFunction;\n if (typeof validateOperation == \"function\") {\n validateFunction = validateOperation;\n } else {\n validateFunction = validator;\n }\n while (true) {\n key = keys[t];\n if (key && key.indexOf(\"~\") != -1) {\n key = unescapePathComponent(key);\n }\n\n if (\n banPrototypeModifications &&\n (key == \"__proto__\" ||\n (key == \"prototype\" && t > 0 && keys[t - 1] == \"constructor\"))\n ) {\n throw new TypeError(\n \"JSON-Patch: modifying `__proto__` or `constructor/prototype` prop is banned for security reasons, if this was on purpose, please set `banPrototypeModifications` flag false and pass it to this function. More info in fast-json-patch README\"\n );\n }\n\n if (validateOperation) {\n if (existingPathFragment === undefined) {\n if (obj[key] === undefined) {\n existingPathFragment = keys.slice(0, t).join(\"/\");\n } else if (t == len - 1) {\n existingPathFragment = operation.path;\n }\n if (existingPathFragment !== undefined) {\n validateFunction(operation, 0, document, existingPathFragment);\n }\n }\n }\n t++;\n if (Array.isArray(obj)) {\n if (key === \"-\") {\n key = obj.length;\n } else {\n if (validateOperation && !isInteger(key)) {\n throw new JsonPatchError(\n \"Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index\",\n \"OPERATION_PATH_ILLEGAL_ARRAY_INDEX\",\n index,\n operation,\n document\n );\n } // only parse key when it's an integer for `arr.prop` to work\n else if (isInteger(key)) {\n key = ~~key;\n }\n }\n if (t >= len) {\n if (validateOperation && operation.op === \"add\" && key > obj.length) {\n throw new JsonPatchError(\n \"The specified index MUST NOT be greater than the number of elements in the array\",\n \"OPERATION_VALUE_OUT_OF_BOUNDS\",\n index,\n operation,\n document\n );\n }\n const returnValue = arrOps[operation.op].call(\n operation,\n obj,\n key,\n document\n ); // Apply patch\n if (returnValue.test === false) {\n throw new JsonPatchError(\n \"Test operation failed\",\n \"TEST_OPERATION_FAILED\",\n index,\n operation,\n document\n );\n }\n return returnValue;\n }\n } else {\n if (t >= len) {\n const returnValue = objOps[operation.op].call(\n operation,\n obj,\n key,\n document\n ); // Apply patch\n if (returnValue.test === false) {\n throw new JsonPatchError(\n \"Test operation failed\",\n \"TEST_OPERATION_FAILED\",\n index,\n operation,\n document\n );\n }\n return returnValue;\n }\n }\n obj = obj[key];\n // If we have more keys in the path, but the next value isn't a non-null object,\n // throw an OPERATION_PATH_UNRESOLVABLE error instead of iterating again.\n if (validateOperation && t < len && (!obj || typeof obj !== \"object\")) {\n throw new JsonPatchError(\n \"Cannot perform operation at the desired path\",\n \"OPERATION_PATH_UNRESOLVABLE\",\n index,\n operation,\n document\n );\n }\n }\n }\n}\n\n/**\n * Apply a full JSON Patch array on a JSON document.\n * Returns the {newDocument, result} of the patch.\n * It modifies the `document` object and `patch` - it gets the values by reference.\n * If you would like to avoid touching your values, clone them:\n * `jsonpatch.applyPatch(document, jsonpatch._deepClone(patch))`.\n *\n * @param document The document to patch\n * @param patch The patch to apply\n * @param validateOperation `false` is without validation, `true` to use default jsonpatch's validation, or you can pass a `validateOperation` callback to be used for validation.\n * @param mutateDocument Whether to mutate the original document or clone it before applying\n * @param banPrototypeModifications Whether to ban modifications to `__proto__`, defaults to `true`.\n * @return An array of `{newDocument, result}` after the patch\n */\nexport function applyPatch<T>(\n document: T,\n patch: ReadonlyArray<Operation>,\n validateOperation?: boolean | Validator<T>,\n mutateDocument: boolean = true,\n banPrototypeModifications: boolean = true\n): PatchResult<T> {\n if (validateOperation) {\n if (!Array.isArray(patch)) {\n throw new JsonPatchError(\n \"Patch sequence must be an array\",\n \"SEQUENCE_NOT_AN_ARRAY\"\n );\n }\n }\n if (!mutateDocument) {\n document = _deepClone(document);\n }\n const results = new Array(patch.length) as PatchResult<T>;\n\n for (let i = 0, length = patch.length; i < length; i++) {\n // we don't need to pass mutateDocument argument because if it was true, we already deep cloned the object, we'll just pass `true`\n results[i] = applyOperation(\n document,\n patch[i],\n validateOperation,\n true,\n banPrototypeModifications,\n i\n );\n document = results[i].newDocument; // in case root was replaced\n }\n results.newDocument = document;\n return results;\n}\n\n/**\n * Apply a single JSON Patch Operation on a JSON document.\n * Returns the updated document.\n * Suitable as a reducer.\n *\n * @param document The document to patch\n * @param operation The operation to apply\n * @return The updated document\n */\nexport function applyReducer<T>(\n document: T,\n operation: Operation,\n index: number\n): T {\n const operationResult: OperationResult<T> = applyOperation(\n document,\n operation\n );\n if (operationResult.test === false) {\n // failed test\n throw new JsonPatchError(\n \"Test operation failed\",\n \"TEST_OPERATION_FAILED\",\n index,\n operation,\n document\n );\n }\n return operationResult.newDocument;\n}\n\n/**\n * Validates a single operation. Called from `jsonpatch.validate`. Throws `JsonPatchError` in case of an error.\n * @param {object} operation - operation object (patch)\n * @param {number} index - index of operation in the sequence\n * @param {object} [document] - object where the operation is supposed to be applied\n * @param {string} [existingPathFragment] - comes along with `document`\n */\nexport function validator(\n operation: Operation,\n index: number,\n document?: any,\n existingPathFragment?: string\n): void {\n if (\n typeof operation !== \"object\" ||\n operation === null ||\n Array.isArray(operation)\n ) {\n throw new JsonPatchError(\n \"Operation is not an object\",\n \"OPERATION_NOT_AN_OBJECT\",\n index,\n operation,\n document\n );\n } else if (!objOps[operation.op]) {\n throw new JsonPatchError(\n \"Operation `op` property is not one of operations defined in RFC-6902\",\n \"OPERATION_OP_INVALID\",\n index,\n operation,\n document\n );\n } else if (typeof operation.path !== \"string\") {\n throw new JsonPatchError(\n \"Operation `path` property is not a string\",\n \"OPERATION_PATH_INVALID\",\n index,\n operation,\n document\n );\n } else if (operation.path.indexOf(\"/\") !== 0 && operation.path.length > 0) {\n // paths that aren't empty string should start with \"/\"\n throw new JsonPatchError(\n 'Operation `path` property must start with \"/\"',\n \"OPERATION_PATH_INVALID\",\n index,\n operation,\n document\n );\n } else if (\n (operation.op === \"move\" || operation.op === \"copy\") &&\n typeof operation.from !== \"string\"\n ) {\n throw new JsonPatchError(\n \"Operation `from` property is not present (applicable in `move` and `copy` operations)\",\n \"OPERATION_FROM_REQUIRED\",\n index,\n operation,\n document\n );\n } else if (\n (operation.op === \"add\" ||\n operation.op === \"replace\" ||\n operation.op === \"test\") &&\n operation.value === undefined\n ) {\n throw new JsonPatchError(\n \"Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)\",\n \"OPERATION_VALUE_REQUIRED\",\n index,\n operation,\n document\n );\n } else if (\n (operation.op === \"add\" ||\n operation.op === \"replace\" ||\n operation.op === \"test\") &&\n hasUndefined(operation.value)\n ) {\n throw new JsonPatchError(\n \"Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)\",\n \"OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED\",\n index,\n operation,\n document\n );\n } else if (document) {\n if (operation.op == \"add\") {\n var pathLen = operation.path.split(\"/\").length;\n var existingPathLen = existingPathFragment.split(\"/\").length;\n if (pathLen !== existingPathLen + 1 && pathLen !== existingPathLen) {\n throw new JsonPatchError(\n \"Cannot perform an `add` operation at the desired path\",\n \"OPERATION_PATH_CANNOT_ADD\",\n index,\n operation,\n document\n );\n }\n } else if (\n operation.op === \"replace\" ||\n operation.op === \"remove\" ||\n <any>operation.op === \"_get\"\n ) {\n if (operation.path !== existingPathFragment) {\n throw new JsonPatchError(\n \"Cannot perform the operation at a path that does not exist\",\n \"OPERATION_PATH_UNRESOLVABLE\",\n index,\n operation,\n document\n );\n }\n } else if (operation.op === \"move\" || operation.op === \"copy\") {\n var existingValue: any = {\n op: \"_get\",\n path: operation.from,\n value: undefined,\n };\n var error = validate([existingValue], document);\n if (error && error.name === \"OPERATION_PATH_UNRESOLVABLE\") {\n throw new JsonPatchError(\n \"Cannot perform the operation from a path that does not exist\",\n \"OPERATION_FROM_UNRESOLVABLE\",\n index,\n operation,\n document\n );\n }\n }\n }\n}\n\n/**\n * Validates a sequence of operations. If `document` parameter is provided, the sequence is additionally validated against the object document.\n * If error is encountered, returns a JsonPatchError object\n * @param sequence\n * @param document\n * @returns {JsonPatchError|undefined}\n */\nexport function validate<T>(\n sequence: ReadonlyArray<Operation>,\n document?: T,\n externalValidator?: Validator<T>\n): PatchError {\n try {\n if (!Array.isArray(sequence)) {\n throw new JsonPatchError(\n \"Patch sequence must be an array\",\n \"SEQUENCE_NOT_AN_ARRAY\"\n );\n }\n if (document) {\n //clone document and sequence so that we can safely try applying operations\n applyPatch(\n _deepClone(document),\n _deepClone(sequence),\n externalValidator || true\n );\n } else {\n externalValidator = externalValidator || validator;\n for (var i = 0; i < sequence.length; i++) {\n externalValidator(sequence[i], i, document, undefined);\n }\n }\n } catch (e) {\n if (e instanceof JsonPatchError) {\n return e;\n } else {\n throw e;\n }\n }\n}\n\n// based on https://github.com/epoberezkin/fast-deep-equal\n// MIT License\n\n// Copyright (c) 2017 Evgeny Poberezkin\n\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n\n// The above copyright notice and this permission notice shall be included in all\n// copies or substantial portions of the Software.\n\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n// SOFTWARE.\nexport function _areEquals(a: any, b: any): boolean {\n if (a === b) return true;\n\n if (a && b && typeof a == \"object\" && typeof b == \"object\") {\n var arrA = Array.isArray(a),\n arrB = Array.isArray(b),\n i,\n length,\n key;\n\n if (arrA && arrB) {\n length = a.length;\n if (length != b.length) return false;\n for (i = length; i-- !== 0; ) if (!_areEquals(a[i], b[i])) return false;\n return true;\n }\n\n if (arrA != arrB) return false;\n\n var keys = Object.keys(a);\n length = keys.length;\n\n if (length !== Object.keys(b).length) return false;\n\n for (i = length; i-- !== 0; ) if (!b.hasOwnProperty(keys[i])) return false;\n\n for (i = length; i-- !== 0; ) {\n key = keys[i];\n if (!_areEquals(a[key], b[key])) return false;\n }\n\n return true;\n }\n\n return a !== a && b !== b;\n}\n"],"mappings":";;;;;;;;;;;;;;AAmBA,MAAa,iBAAiB;AAC9B,MAAa,YAAY;AA2EzB,MAAM,SAAS;CACb,KAAK,SAAU,KAAK,KAAK,UAAU;AACjC,MAAI,QAAQ,eAAe,QAAQ,cACjC,OAAM,IAAI,UACR,yFACD;AAEH,MAAI,OAAO,KAAK;AAChB,SAAO,EAAE,aAAa,UAAU;;CAElC,QAAQ,SAAU,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AI;AACF,MAAI,CAAC,MAAM,QAAQ,SAAS,CAC1B,OAAM,IAAI,eACR,mCACA,wBACD;AAEH,MAAI,SAEF,YACE,WAAW,SAAS,EACpB,WAAW,SAAS,EACpB,qBAAqB,KACtB;OACI;AACL,uBAAoB,qBAAqB;AACzC,QAAK,IAAI,IAAI,GAAG,IAAI,SAAS,QAAQ,IACnC,mBAAkB,SAAS,IAAI,GAAG,UAAU,KAAA,EAAU;;UAGnD,GAAG;AACV,MAAI,aAAa,eACf,QAAO;MAEP,OAAM;;;AA2BZ,SAAgB,WAAW,GAAQ,GAAiB;AAClD,KAAI,MAAM,EAAG,QAAO;AAEpB,KAAI,KAAK,KAAK,OAAO,KAAK,YAAY,OAAO,KAAK,UAAU;EAC1D,IAAI,OAAO,MAAM,QAAQ,EAAE,EACzB,OAAO,MAAM,QAAQ,EAAE,EACvB,GACA,QACA;AAEF,MAAI,QAAQ,MAAM;AAChB,YAAS,EAAE;AACX,OAAI,UAAU,EAAE,OAAQ,QAAO;AAC/B,QAAK,IAAI,QAAQ,QAAQ,GAAK,KAAI,CAAC,WAAW,EAAE,IAAI,EAAE,GAAG,CAAE,QAAO;AAClE,UAAO;;AAGT,MAAI,QAAQ,KAAM,QAAO;EAEzB,IAAI,OAAO,OAAO,KAAK,EAAE;AACzB,WAAS,KAAK;AAEd,MAAI,WAAW,OAAO,KAAK,EAAE,CAAC,OAAQ,QAAO;AAE7C,OAAK,IAAI,QAAQ,QAAQ,GAAK,KAAI,CAAC,EAAE,eAAe,KAAK,GAAG,CAAE,QAAO;AAErE,OAAK,IAAI,QAAQ,QAAQ,IAAK;AAC5B,SAAM,KAAK;AACX,OAAI,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,CAAE,QAAO;;AAG1C,SAAO;;AAGT,QAAO,MAAM,KAAK,MAAM"}
1
+ {"version":3,"file":"core.js","names":[],"sources":["../../../../src/utils/fast-json-patch/src/core.ts"],"sourcesContent":["// @ts-nocheck\n\n// Inlined because of ESM import issues\n\n/*!\n * https://github.com/Starcounter-Jack/JSON-Patch\n * (c) 2013-2021 Joachim Wester\n * MIT license\n */\ndeclare var require: any;\n\nimport {\n PatchError,\n _deepClone,\n isInteger,\n unescapePathComponent,\n hasUndefined,\n} from \"./helpers.js\";\n\nexport const JsonPatchError = PatchError;\nexport const deepClone = _deepClone;\n\nexport type Operation =\n | AddOperation<any>\n | RemoveOperation\n | ReplaceOperation<any>\n | MoveOperation\n | CopyOperation\n | TestOperation<any>\n | GetOperation<any>;\n\nexport interface Validator<T> {\n (\n operation: Operation,\n index: number,\n document: T,\n existingPathFragment: string\n ): void;\n}\n\nexport interface OperationResult<T> {\n removed?: any;\n test?: boolean;\n newDocument: T;\n}\n\nexport interface BaseOperation {\n path: string;\n}\n\nexport interface AddOperation<T> extends BaseOperation {\n op: \"add\";\n value: T;\n}\n\nexport interface RemoveOperation extends BaseOperation {\n op: \"remove\";\n}\n\nexport interface ReplaceOperation<T> extends BaseOperation {\n op: \"replace\";\n value: T;\n}\n\nexport interface MoveOperation extends BaseOperation {\n op: \"move\";\n from: string;\n}\n\nexport interface CopyOperation extends BaseOperation {\n op: \"copy\";\n from: string;\n}\n\nexport interface TestOperation<T> extends BaseOperation {\n op: \"test\";\n value: T;\n}\n\nexport interface GetOperation<T> extends BaseOperation {\n op: \"_get\";\n value: T;\n}\nexport interface PatchResult<T> extends Array<OperationResult<T>> {\n newDocument: T;\n}\n\n/* We use a Javascript hash to store each\n function. Each hash entry (property) uses\n the operation identifiers specified in rfc6902.\n In this way, we can map each patch operation\n to its dedicated function in efficient way.\n */\n\n/* The operations applicable to an object */\nconst objOps = {\n add: function (obj, key, document) {\n if (key === \"__proto__\" || key === \"constructor\") {\n throw new TypeError(\n \"JSON-Patch: modifying `__proto__` or `constructor` prop is banned for security reasons\"\n );\n }\n obj[key] = this.value;\n return { newDocument: document };\n },\n remove: function (obj, key, document) {\n if (key === \"__proto__\" || key === \"constructor\") {\n throw new TypeError(\n \"JSON-Patch: modifying `__proto__` or `constructor` prop is banned for security reasons\"\n );\n }\n var removed = obj[key];\n delete obj[key];\n return { newDocument: document, removed };\n },\n replace: function (obj, key, document) {\n if (key === \"__proto__\" || key === \"constructor\") {\n throw new TypeError(\n \"JSON-Patch: modifying `__proto__` or `constructor` prop is banned for security reasons\"\n );\n }\n var removed = obj[key];\n obj[key] = this.value;\n return { newDocument: document, removed };\n },\n move: function (obj, key, document) {\n /* in case move target overwrites an existing value,\n return the removed value, this can be taxing performance-wise,\n and is potentially unneeded */\n let removed = getValueByPointer(document, this.path);\n\n if (removed) {\n removed = _deepClone(removed);\n }\n\n const originalValue = applyOperation(document, {\n op: \"remove\",\n path: this.from,\n }).removed;\n\n applyOperation(document, {\n op: \"add\",\n path: this.path,\n value: originalValue,\n });\n\n return { newDocument: document, removed };\n },\n copy: function (obj, key, document) {\n const valueToCopy = getValueByPointer(document, this.from);\n // enforce copy by value so further operations don't affect source (see issue #177)\n applyOperation(document, {\n op: \"add\",\n path: this.path,\n value: _deepClone(valueToCopy),\n });\n return { newDocument: document };\n },\n test: function (obj, key, document) {\n return { newDocument: document, test: _areEquals(obj[key], this.value) };\n },\n _get: function (obj, key, document) {\n this.value = obj[key];\n return { newDocument: document };\n },\n};\n\n/* The operations applicable to an array. Many are the same as for the object */\nvar arrOps = {\n add: function (arr, i, document) {\n if (isInteger(i)) {\n arr.splice(i, 0, this.value);\n } else {\n // array props\n arr[i] = this.value;\n }\n // this may be needed when using '-' in an array\n return { newDocument: document, index: i };\n },\n remove: function (arr, i, document) {\n var removedList = arr.splice(i, 1);\n return { newDocument: document, removed: removedList[0] };\n },\n replace: function (arr, i, document) {\n var removed = arr[i];\n arr[i] = this.value;\n return { newDocument: document, removed };\n },\n move: objOps.move,\n copy: objOps.copy,\n test: objOps.test,\n _get: objOps._get,\n};\n\n/**\n * Retrieves a value from a JSON document by a JSON pointer.\n * Returns the value.\n *\n * @param document The document to get the value from\n * @param pointer an escaped JSON pointer\n * @return The retrieved value\n */\nexport function getValueByPointer(document: any, pointer: string): any {\n if (pointer == \"\") {\n return document;\n }\n var getOriginalDestination = <GetOperation<any>>{ op: \"_get\", path: pointer };\n applyOperation(document, getOriginalDestination);\n return getOriginalDestination.value;\n}\n/**\n * Apply a single JSON Patch Operation on a JSON document.\n * Returns the {newDocument, result} of the operation.\n * It modifies the `document` and `operation` objects - it gets the values by reference.\n * If you would like to avoid touching your values, clone them:\n * `jsonpatch.applyOperation(document, jsonpatch._deepClone(operation))`.\n *\n * @param document The document to patch\n * @param operation The operation to apply\n * @param validateOperation `false` is without validation, `true` to use default jsonpatch's validation, or you can pass a `validateOperation` callback to be used for validation.\n * @param mutateDocument Whether to mutate the original document or clone it before applying\n * @param banPrototypeModifications Whether to ban modifications to `__proto__`, defaults to `true`.\n * @return `{newDocument, result}` after the operation\n */\nexport function applyOperation<T>(\n document: T,\n operation: Operation,\n validateOperation: boolean | Validator<T> = false,\n mutateDocument: boolean = true,\n banPrototypeModifications: boolean = true,\n index: number = 0\n): OperationResult<T> {\n if (validateOperation) {\n if (typeof validateOperation == \"function\") {\n validateOperation(operation, 0, document, operation.path);\n } else {\n validator(operation, 0);\n }\n }\n /* ROOT OPERATIONS */\n if (operation.path === \"\") {\n let returnValue: OperationResult<T> = { newDocument: document };\n if (operation.op === \"add\") {\n returnValue.newDocument = operation.value;\n return returnValue;\n } else if (operation.op === \"replace\") {\n returnValue.newDocument = operation.value;\n returnValue.removed = document; //document we removed\n return returnValue;\n } else if (operation.op === \"move\" || operation.op === \"copy\") {\n // it's a move or copy to root\n returnValue.newDocument = getValueByPointer(document, operation.from); // get the value by json-pointer in `from` field\n if (operation.op === \"move\") {\n // report removed item\n returnValue.removed = document;\n }\n return returnValue;\n } else if (operation.op === \"test\") {\n returnValue.test = _areEquals(document, operation.value);\n if (returnValue.test === false) {\n throw new JsonPatchError(\n \"Test operation failed\",\n \"TEST_OPERATION_FAILED\",\n index,\n operation,\n document\n );\n }\n returnValue.newDocument = document;\n return returnValue;\n } else if (operation.op === \"remove\") {\n // a remove on root\n returnValue.removed = document;\n returnValue.newDocument = null;\n return returnValue;\n } else if (operation.op === \"_get\") {\n operation.value = document;\n return returnValue;\n } else {\n /* bad operation */\n if (validateOperation) {\n throw new JsonPatchError(\n \"Operation `op` property is not one of operations defined in RFC-6902\",\n \"OPERATION_OP_INVALID\",\n index,\n operation,\n document\n );\n } else {\n return returnValue;\n }\n }\n } /* END ROOT OPERATIONS */ else {\n if (!mutateDocument) {\n document = _deepClone(document);\n }\n const path = operation.path || \"\";\n const keys = path.split(\"/\");\n let obj = document;\n let t = 1; //skip empty element - http://jsperf.com/to-shift-or-not-to-shift\n let len = keys.length;\n let existingPathFragment = undefined;\n let key: string | number;\n let validateFunction;\n if (typeof validateOperation == \"function\") {\n validateFunction = validateOperation;\n } else {\n validateFunction = validator;\n }\n while (true) {\n key = keys[t];\n if (key && key.indexOf(\"~\") != -1) {\n key = unescapePathComponent(key);\n }\n\n if (\n banPrototypeModifications &&\n (key == \"__proto__\" ||\n (key == \"prototype\" && t > 0 && keys[t - 1] == \"constructor\"))\n ) {\n throw new TypeError(\n \"JSON-Patch: modifying `__proto__` or `constructor/prototype` prop is banned for security reasons, if this was on purpose, please set `banPrototypeModifications` flag false and pass it to this function. More info in fast-json-patch README\"\n );\n }\n\n if (validateOperation) {\n if (existingPathFragment === undefined) {\n if (obj[key] === undefined) {\n existingPathFragment = keys.slice(0, t).join(\"/\");\n } else if (t == len - 1) {\n existingPathFragment = operation.path;\n }\n if (existingPathFragment !== undefined) {\n validateFunction(operation, 0, document, existingPathFragment);\n }\n }\n }\n t++;\n if (Array.isArray(obj)) {\n if (key === \"-\") {\n key = obj.length;\n } else {\n if (validateOperation && !isInteger(key)) {\n throw new JsonPatchError(\n \"Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index\",\n \"OPERATION_PATH_ILLEGAL_ARRAY_INDEX\",\n index,\n operation,\n document\n );\n } // only parse key when it's an integer for `arr.prop` to work\n else if (isInteger(key)) {\n key = ~~key;\n }\n }\n if (t >= len) {\n if (validateOperation && operation.op === \"add\" && key > obj.length) {\n throw new JsonPatchError(\n \"The specified index MUST NOT be greater than the number of elements in the array\",\n \"OPERATION_VALUE_OUT_OF_BOUNDS\",\n index,\n operation,\n document\n );\n }\n const returnValue = arrOps[operation.op].call(\n operation,\n obj,\n key,\n document\n ); // Apply patch\n if (returnValue.test === false) {\n throw new JsonPatchError(\n \"Test operation failed\",\n \"TEST_OPERATION_FAILED\",\n index,\n operation,\n document\n );\n }\n return returnValue;\n }\n } else {\n if (t >= len) {\n const returnValue = objOps[operation.op].call(\n operation,\n obj,\n key,\n document\n ); // Apply patch\n if (returnValue.test === false) {\n throw new JsonPatchError(\n \"Test operation failed\",\n \"TEST_OPERATION_FAILED\",\n index,\n operation,\n document\n );\n }\n return returnValue;\n }\n }\n obj = obj[key];\n // If we have more keys in the path, but the next value isn't a non-null object,\n // throw an OPERATION_PATH_UNRESOLVABLE error instead of iterating again.\n if (validateOperation && t < len && (!obj || typeof obj !== \"object\")) {\n throw new JsonPatchError(\n \"Cannot perform operation at the desired path\",\n \"OPERATION_PATH_UNRESOLVABLE\",\n index,\n operation,\n document\n );\n }\n }\n }\n}\n\n/**\n * Apply a full JSON Patch array on a JSON document.\n * Returns the {newDocument, result} of the patch.\n * It modifies the `document` object and `patch` - it gets the values by reference.\n * If you would like to avoid touching your values, clone them:\n * `jsonpatch.applyPatch(document, jsonpatch._deepClone(patch))`.\n *\n * @param document The document to patch\n * @param patch The patch to apply\n * @param validateOperation `false` is without validation, `true` to use default jsonpatch's validation, or you can pass a `validateOperation` callback to be used for validation.\n * @param mutateDocument Whether to mutate the original document or clone it before applying\n * @param banPrototypeModifications Whether to ban modifications to `__proto__`, defaults to `true`.\n * @return An array of `{newDocument, result}` after the patch\n */\nexport function applyPatch<T>(\n document: T,\n patch: ReadonlyArray<Operation>,\n validateOperation?: boolean | Validator<T>,\n mutateDocument: boolean = true,\n banPrototypeModifications: boolean = true\n): PatchResult<T> {\n if (validateOperation) {\n if (!Array.isArray(patch)) {\n throw new JsonPatchError(\n \"Patch sequence must be an array\",\n \"SEQUENCE_NOT_AN_ARRAY\"\n );\n }\n }\n if (!mutateDocument) {\n document = _deepClone(document);\n }\n const results = new Array(patch.length) as PatchResult<T>;\n\n for (let i = 0, length = patch.length; i < length; i++) {\n // we don't need to pass mutateDocument argument because if it was true, we already deep cloned the object, we'll just pass `true`\n results[i] = applyOperation(\n document,\n patch[i],\n validateOperation,\n true,\n banPrototypeModifications,\n i\n );\n document = results[i].newDocument; // in case root was replaced\n }\n results.newDocument = document;\n return results;\n}\n\n/**\n * Apply a single JSON Patch Operation on a JSON document.\n * Returns the updated document.\n * Suitable as a reducer.\n *\n * @param document The document to patch\n * @param operation The operation to apply\n * @return The updated document\n */\nexport function applyReducer<T>(\n document: T,\n operation: Operation,\n index: number\n): T {\n const operationResult: OperationResult<T> = applyOperation(\n document,\n operation\n );\n if (operationResult.test === false) {\n // failed test\n throw new JsonPatchError(\n \"Test operation failed\",\n \"TEST_OPERATION_FAILED\",\n index,\n operation,\n document\n );\n }\n return operationResult.newDocument;\n}\n\n/**\n * Validates a single operation. Called from `jsonpatch.validate`. Throws `JsonPatchError` in case of an error.\n * @param {object} operation - operation object (patch)\n * @param {number} index - index of operation in the sequence\n * @param {object} [document] - object where the operation is supposed to be applied\n * @param {string} [existingPathFragment] - comes along with `document`\n */\nexport function validator(\n operation: Operation,\n index: number,\n document?: any,\n existingPathFragment?: string\n): void {\n if (\n typeof operation !== \"object\" ||\n operation === null ||\n Array.isArray(operation)\n ) {\n throw new JsonPatchError(\n \"Operation is not an object\",\n \"OPERATION_NOT_AN_OBJECT\",\n index,\n operation,\n document\n );\n } else if (!objOps[operation.op]) {\n throw new JsonPatchError(\n \"Operation `op` property is not one of operations defined in RFC-6902\",\n \"OPERATION_OP_INVALID\",\n index,\n operation,\n document\n );\n } else if (typeof operation.path !== \"string\") {\n throw new JsonPatchError(\n \"Operation `path` property is not a string\",\n \"OPERATION_PATH_INVALID\",\n index,\n operation,\n document\n );\n } else if (operation.path.indexOf(\"/\") !== 0 && operation.path.length > 0) {\n // paths that aren't empty string should start with \"/\"\n throw new JsonPatchError(\n 'Operation `path` property must start with \"/\"',\n \"OPERATION_PATH_INVALID\",\n index,\n operation,\n document\n );\n } else if (\n (operation.op === \"move\" || operation.op === \"copy\") &&\n typeof operation.from !== \"string\"\n ) {\n throw new JsonPatchError(\n \"Operation `from` property is not present (applicable in `move` and `copy` operations)\",\n \"OPERATION_FROM_REQUIRED\",\n index,\n operation,\n document\n );\n } else if (\n (operation.op === \"add\" ||\n operation.op === \"replace\" ||\n operation.op === \"test\") &&\n operation.value === undefined\n ) {\n throw new JsonPatchError(\n \"Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)\",\n \"OPERATION_VALUE_REQUIRED\",\n index,\n operation,\n document\n );\n } else if (\n (operation.op === \"add\" ||\n operation.op === \"replace\" ||\n operation.op === \"test\") &&\n hasUndefined(operation.value)\n ) {\n throw new JsonPatchError(\n \"Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)\",\n \"OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED\",\n index,\n operation,\n document\n );\n } else if (document) {\n if (operation.op == \"add\") {\n var pathLen = operation.path.split(\"/\").length;\n var existingPathLen = existingPathFragment.split(\"/\").length;\n if (pathLen !== existingPathLen + 1 && pathLen !== existingPathLen) {\n throw new JsonPatchError(\n \"Cannot perform an `add` operation at the desired path\",\n \"OPERATION_PATH_CANNOT_ADD\",\n index,\n operation,\n document\n );\n }\n } else if (\n operation.op === \"replace\" ||\n operation.op === \"remove\" ||\n <any>operation.op === \"_get\"\n ) {\n if (operation.path !== existingPathFragment) {\n throw new JsonPatchError(\n \"Cannot perform the operation at a path that does not exist\",\n \"OPERATION_PATH_UNRESOLVABLE\",\n index,\n operation,\n document\n );\n }\n } else if (operation.op === \"move\" || operation.op === \"copy\") {\n var existingValue: any = {\n op: \"_get\",\n path: operation.from,\n value: undefined,\n };\n var error = validate([existingValue], document);\n if (error && error.name === \"OPERATION_PATH_UNRESOLVABLE\") {\n throw new JsonPatchError(\n \"Cannot perform the operation from a path that does not exist\",\n \"OPERATION_FROM_UNRESOLVABLE\",\n index,\n operation,\n document\n );\n }\n }\n }\n}\n\n/**\n * Validates a sequence of operations. If `document` parameter is provided, the sequence is additionally validated against the object document.\n * If error is encountered, returns a JsonPatchError object\n * @param sequence\n * @param document\n * @returns {JsonPatchError|undefined}\n */\nexport function validate<T>(\n sequence: ReadonlyArray<Operation>,\n document?: T,\n externalValidator?: Validator<T>\n): PatchError {\n try {\n if (!Array.isArray(sequence)) {\n throw new JsonPatchError(\n \"Patch sequence must be an array\",\n \"SEQUENCE_NOT_AN_ARRAY\"\n );\n }\n if (document) {\n //clone document and sequence so that we can safely try applying operations\n applyPatch(\n _deepClone(document),\n _deepClone(sequence),\n externalValidator || true\n );\n } else {\n externalValidator = externalValidator || validator;\n for (var i = 0; i < sequence.length; i++) {\n externalValidator(sequence[i], i, document, undefined);\n }\n }\n } catch (e) {\n if (e instanceof JsonPatchError) {\n return e;\n } else {\n throw e;\n }\n }\n}\n\n// based on https://github.com/epoberezkin/fast-deep-equal\n// MIT License\n\n// Copyright (c) 2017 Evgeny Poberezkin\n\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n\n// The above copyright notice and this permission notice shall be included in all\n// copies or substantial portions of the Software.\n\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n// SOFTWARE.\nexport function _areEquals(a: any, b: any): boolean {\n if (a === b) return true;\n\n if (a && b && typeof a == \"object\" && typeof b == \"object\") {\n var arrA = Array.isArray(a),\n arrB = Array.isArray(b),\n i,\n length,\n key;\n\n if (arrA && arrB) {\n length = a.length;\n if (length != b.length) return false;\n for (i = length; i-- !== 0; ) if (!_areEquals(a[i], b[i])) return false;\n return true;\n }\n\n if (arrA != arrB) return false;\n\n var keys = Object.keys(a);\n length = keys.length;\n\n if (length !== Object.keys(b).length) return false;\n\n for (i = length; i-- !== 0; ) if (!b.hasOwnProperty(keys[i])) return false;\n\n for (i = length; i-- !== 0; ) {\n key = keys[i];\n if (!_areEquals(a[key], b[key])) return false;\n }\n\n return true;\n }\n\n return a !== a && b !== b;\n}\n"],"mappings":";;;;;;;;;;;;;;AAmBA,MAAa,iBAAiB;AAC9B,MAAa,YAAY;AA2EzB,MAAM,SAAS;CACb,KAAK,SAAU,KAAK,KAAK,UAAU;AACjC,MAAI,QAAQ,eAAe,QAAQ,cACjC,OAAM,IAAI,UACR,yFACD;AAEH,MAAI,OAAO,KAAK;AAChB,SAAO,EAAE,aAAa,UAAU;;CAElC,QAAQ,SAAU,KAAK,KAAK,UAAU;AACpC,MAAI,QAAQ,eAAe,QAAQ,cACjC,OAAM,IAAI,UACR,yFACD;EAEH,IAAI,UAAU,IAAI;AAClB,SAAO,IAAI;AACX,SAAO;GAAE,aAAa;GAAU;GAAS;;CAE3C,SAAS,SAAU,KAAK,KAAK,UAAU;AACrC,MAAI,QAAQ,eAAe,QAAQ,cACjC,OAAM,IAAI,UACR,yFACD;EAEH,IAAI,UAAU,IAAI;AAClB,MAAI,OAAO,KAAK;AAChB,SAAO;GAAE,aAAa;GAAU;GAAS;;CAE3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AAgB,WAAW,GAAQ,GAAiB;AAClD,KAAI,MAAM,EAAG,QAAO;AAEpB,KAAI,KAAK,KAAK,OAAO,KAAK,YAAY,OAAO,KAAK,UAAU;EAC1D,IAAI,OAAO,MAAM,QAAQ,EAAE,EACzB,OAAO,MAAM,QAAQ,EAAE,EACvB,GACA,QACA;AAEF,MAAI,QAAQ,MAAM;AAChB,YAAS,EAAE;AACX,OAAI,UAAU,EAAE,OAAQ,QAAO;AAC/B,QAAK,IAAI,QAAQ,QAAQ,GAAK,KAAI,CAAC,WAAW,EAAE,IAAI,EAAE,GAAG,CAAE,QAAO;AAClE,UAAO;;AAGT,MAAI,QAAQ,KAAM,QAAO;EAEzB,IAAI,OAAO,OAAO,KAAK,EAAE;AACzB,WAAS,KAAK;AAEd,MAAI,WAAW,OAAO,KAAK,EAAE,CAAC,OAAQ,QAAO;AAE7C,OAAK,IAAI,QAAQ,QAAQ,GAAK,KAAI,CAAC,EAAE,eAAe,KAAK,GAAG,CAAE,QAAO;AAErE,OAAK,IAAI,QAAQ,QAAQ,IAAK;AAC5B,SAAM,KAAK;AACX,OAAI,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,CAAE,QAAO;;AAG1C,SAAO;;AAGT,QAAO,MAAM,KAAK,MAAM"}
@@ -1 +1 @@
1
- {"version":3,"file":"json_schema.cjs","names":["isStandardJsonSchema","isZodSchemaV4","interopZodTransformInputSchema","isZodObjectV4","interopZodObjectStrict","isZodSchemaV3","zodToJsonSchema"],"sources":["../../src/utils/json_schema.ts"],"sourcesContent":["import { toJSONSchema, type $ZodType } from \"zod/v4/core\";\nimport { dereference, type Schema } from \"@cfworker/json-schema\";\nimport {\n isZodSchemaV3,\n isZodSchemaV4,\n InteropZodType,\n interopZodObjectStrict,\n isZodObjectV4,\n interopZodTransformInputSchema,\n} from \"./types/zod.js\";\nimport {\n type JsonSchema7Type as JSONSchema,\n zodToJsonSchema,\n} from \"./zod-to-json-schema/index.js\";\nimport { StandardJSONSchemaV1 } from \"@standard-schema/spec\";\nimport { isStandardJsonSchema } from \"./standard_schema.js\";\n\nexport { deepCompareStrict, Validator } from \"@cfworker/json-schema\";\n\nexport type ToJSONSchemaParams = NonNullable<\n Parameters<typeof toJSONSchema>[1]\n>;\n\n/**\n * WeakMap cache for Zod/Standard-Schema → JSON Schema conversions.\n *\n * Keyed on the schema object reference. Since Zod schemas are immutable and\n * the same `tool.schema` reference is passed on every LLM call, this\n * eliminates redundant serializations. For example, an agent with 6 tools\n * doing 15 steps across 3 parallel subagents would otherwise run 270\n * identical conversions per invocation.\n *\n * Only used when no custom `params` are passed (the common case for tool\n * binding). WeakMap ensures cached entries are GC'd when the schema goes\n * out of scope.\n *\n * @internal\n */\nconst _jsonSchemaCache = new WeakMap<object, JSONSchema>();\n\n/**\n * Converts a Standard JSON schema, Zod schema or JSON schema to a JSON schema.\n * Results are cached by schema reference when no custom params are passed.\n * @param schema - The schema to convert.\n * @param params - The parameters to pass to the toJSONSchema function.\n * @returns The converted schema.\n */\nexport function toJsonSchema(\n schema: StandardJSONSchemaV1 | InteropZodType | JSONSchema,\n params?: ToJSONSchemaParams\n): JSONSchema {\n // Cache when no custom params are passed (the default for tool binding).\n // Params can change the output (e.g., different target draft), so we\n // bypass the cache when they're provided.\n const canCache = !params && schema != null && typeof schema === \"object\";\n\n if (canCache) {\n const cached = _jsonSchemaCache.get(schema);\n if (cached) return cached;\n }\n\n let result: JSONSchema;\n\n if (isStandardJsonSchema(schema) && !isZodSchemaV4(schema)) {\n result = schema[\"~standard\"].jsonSchema.input({\n target: \"draft-07\",\n }) as JSONSchema;\n } else if (isZodSchemaV4(schema)) {\n const inputSchema = interopZodTransformInputSchema(schema, true);\n if (isZodObjectV4(inputSchema)) {\n const strictSchema = interopZodObjectStrict(inputSchema, true);\n result = toJSONSchema(strictSchema as unknown as $ZodType, params);\n } else {\n result = toJSONSchema(schema as unknown as $ZodType, params);\n }\n } else if (isZodSchemaV3(schema)) {\n result = zodToJsonSchema(schema as never);\n } else {\n result = schema as JSONSchema;\n }\n\n if (canCache && result != null && typeof result === \"object\") {\n _jsonSchemaCache.set(schema, result);\n }\n\n return result;\n}\n\n/**\n * Validates if a JSON schema validates only strings. May return false negatives in some edge cases\n * (like recursive or unresolvable refs).\n *\n * @param schema - The schema to validate.\n * @returns `true` if the schema validates only strings, `false` otherwise.\n */\nexport function validatesOnlyStrings(schema: unknown): boolean {\n // Null, undefined, or empty schema\n if (\n !schema ||\n typeof schema !== \"object\" ||\n Object.keys(schema).length === 0 ||\n Array.isArray(schema)\n ) {\n return false; // Validates anything, not just strings\n }\n\n // Explicit type constraint\n if (\"type\" in schema) {\n if (typeof schema.type === \"string\") {\n return schema.type === \"string\";\n }\n\n if (Array.isArray(schema.type)) {\n // not sure why someone would do `\"type\": [\"string\"]` or especially `\"type\": [\"string\",\n // \"string\", \"string\", ...]` but we're not here to judge\n return schema.type.every((t) => t === \"string\");\n }\n return false; // Invalid or non-string type\n }\n\n // Enum with only string values\n if (\"enum\" in schema) {\n return (\n Array.isArray(schema.enum) &&\n schema.enum.length > 0 &&\n schema.enum.every((val) => typeof val === \"string\")\n );\n }\n\n // String constant\n if (\"const\" in schema) {\n return typeof schema.const === \"string\";\n }\n\n // Schema combinations\n if (\"allOf\" in schema && Array.isArray(schema.allOf)) {\n // If any subschema validates only strings, then the overall schema validates only strings\n return schema.allOf.some((subschema) => validatesOnlyStrings(subschema));\n }\n\n if (\n (\"anyOf\" in schema && Array.isArray(schema.anyOf)) ||\n (\"oneOf\" in schema && Array.isArray(schema.oneOf))\n ) {\n const subschemas = (\n \"anyOf\" in schema ? schema.anyOf : schema.oneOf\n ) as unknown[];\n\n // All subschemas must validate only strings\n return (\n subschemas.length > 0 &&\n subschemas.every((subschema) => validatesOnlyStrings(subschema))\n );\n }\n\n // We're not going to try on this one, it's too complex - we just assume if it has a \"not\" key and hasn't matched one of the above checks, it's not a string schema.\n if (\"not\" in schema) {\n return false; // The not case can validate non-strings\n }\n\n if (\"$ref\" in schema && typeof schema.$ref === \"string\") {\n const ref = schema.$ref as string;\n const resolved = dereference(schema as Schema);\n if (resolved[ref]) {\n return validatesOnlyStrings(resolved[ref]);\n }\n return false;\n }\n\n // ignore recursive refs and other cases where type is omitted for now\n // ignore other cases for now where type is omitted\n\n return false;\n}\n\n// Re-export of the types used throughout langchain for json schema serialization.\n// The plan is to eventually nix zod-to-json-schema altogether in place for\n// zod v4 / a more standardized way of serializing validated inputs, so its re-exported\n// here to remove the dependency on zod-to-json-schema in downstream packages until\n// a determination is made.\n\nexport {\n type JsonSchema7Type,\n type JsonSchema7Type as JSONSchema,\n type JsonSchema7ArrayType,\n type JsonSchema7ObjectType,\n type JsonSchema7StringType,\n type JsonSchema7NumberType,\n type JsonSchema7NullableType,\n} from \"./zod-to-json-schema/index.js\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,MAAM,mCAAmB,IAAI,SAA6B;;;;;;;;AAS1D,SAAgB,aACd,QACA,QACY;CAIZ,MAAM,WAAW,CAAC,UAAU,UAAU,QAAQ,OAAO,WAAW;AAEhE,KAAI,UAAU;EACZ,MAAM,SAAS,iBAAiB,IAAI,OAAO;AAC3C,MAAI,OAAQ,QAAO;;CAGrB,IAAI;AAEJ,KAAIA,8BAAAA,qBAAqB,OAAO,IAAI,CAACC,YAAAA,cAAc,OAAO,CACxD,UAAS,OAAO,aAAa,WAAW,MAAM,EAC5C,QAAQ,YACT,CAAC;UACOA,YAAAA,cAAc,OAAO,EAAE;EAChC,MAAM,cAAcC,YAAAA,+BAA+B,QAAQ,KAAK;AAChE,MAAIC,YAAAA,cAAc,YAAY,CAE5B,WAAA,GAAA,YAAA,cADqBC,YAAAA,uBAAuB,aAAa,KAAK,EACH,OAAO;MAElE,WAAA,GAAA,YAAA,cAAsB,QAA+B,OAAO;YAErDC,YAAAA,cAAc,OAAO,CAC9B,UAASC,wBAAAA,gBAAgB,OAAgB;KAEzC,UAAS;AAGX,KAAI,YAAY,UAAU,QAAQ,OAAO,WAAW,SAClD,kBAAiB,IAAI,QAAQ,OAAO;AAGtC,QAAO;;;;;;;;;AAUT,SAAgB,qBAAqB,QAA0B;AAE7D,KACE,CAAC,UACD,OAAO,WAAW,YAClB,OAAO,KAAK,OAAO,CAAC,WAAW,KAC/B,MAAM,QAAQ,OAAO,CAErB,QAAO;AAIT,KAAI,UAAU,QAAQ;AACpB,MAAI,OAAO,OAAO,SAAS,SACzB,QAAO,OAAO,SAAS;AAGzB,MAAI,MAAM,QAAQ,OAAO,KAAK,CAG5B,QAAO,OAAO,KAAK,OAAO,MAAM,MAAM,SAAS;AAEjD,SAAO;;AAIT,KAAI,UAAU,OACZ,QACE,MAAM,QAAQ,OAAO,KAAK,IAC1B,OAAO,KAAK,SAAS,KACrB,OAAO,KAAK,OAAO,QAAQ,OAAO,QAAQ,SAAS;AAKvD,KAAI,WAAW,OACb,QAAO,OAAO,OAAO,UAAU;AAIjC,KAAI,WAAW,UAAU,MAAM,QAAQ,OAAO,MAAM,CAElD,QAAO,OAAO,MAAM,MAAM,cAAc,qBAAqB,UAAU,CAAC;AAG1E,KACG,WAAW,UAAU,MAAM,QAAQ,OAAO,MAAM,IAChD,WAAW,UAAU,MAAM,QAAQ,OAAO,MAAM,EACjD;EACA,MAAM,aACJ,WAAW,SAAS,OAAO,QAAQ,OAAO;AAI5C,SACE,WAAW,SAAS,KACpB,WAAW,OAAO,cAAc,qBAAqB,UAAU,CAAC;;AAKpE,KAAI,SAAS,OACX,QAAO;AAGT,KAAI,UAAU,UAAU,OAAO,OAAO,SAAS,UAAU;EACvD,MAAM,MAAM,OAAO;EACnB,MAAM,YAAA,GAAA,sBAAA,aAAuB,OAAiB;AAC9C,MAAI,SAAS,KACX,QAAO,qBAAqB,SAAS,KAAK;AAE5C,SAAO;;AAMT,QAAO"}
1
+ {"version":3,"file":"json_schema.cjs","names":["isStandardJsonSchema","isZodSchemaV4","interopZodTransformInputSchema","isZodObjectV4","interopZodObjectStrict","isZodSchemaV3","zodToJsonSchema"],"sources":["../../src/utils/json_schema.ts"],"sourcesContent":["import { toJSONSchema, type $ZodType } from \"zod/v4/core\";\nimport { dereference, type Schema } from \"@cfworker/json-schema\";\nimport {\n isZodSchemaV3,\n isZodSchemaV4,\n InteropZodType,\n interopZodObjectStrict,\n isZodObjectV4,\n interopZodTransformInputSchema,\n} from \"./types/zod.js\";\nimport {\n type JsonSchema7Type as JSONSchema,\n zodToJsonSchema,\n} from \"./zod-to-json-schema/index.js\";\nimport { StandardJSONSchemaV1 } from \"@standard-schema/spec\";\nimport { isStandardJsonSchema } from \"./standard_schema.js\";\n\nexport { deepCompareStrict, Validator } from \"@cfworker/json-schema\";\n\nexport type ToJSONSchemaParams = NonNullable<\n Parameters<typeof toJSONSchema>[1]\n>;\n\n/**\n * WeakMap cache for Zod/Standard-Schema → JSON Schema conversions.\n *\n * Keyed on the schema object reference. Since Zod schemas are immutable and\n * the same `tool.schema` reference is passed on every LLM call, this\n * eliminates redundant serializations. For example, an agent with 6 tools\n * doing 15 steps across 3 parallel subagents would otherwise run 270\n * identical conversions per invocation.\n *\n * Only used when no custom `params` are passed (the common case for tool\n * binding). WeakMap ensures cached entries are GC'd when the schema goes\n * out of scope.\n *\n * @internal\n */\nconst _jsonSchemaCache = new WeakMap<object, JSONSchema>();\n\n/**\n * Converts a Standard JSON schema, Zod schema or JSON schema to a JSON schema.\n * Results are cached by schema reference when no custom params are passed.\n * @param schema - The schema to convert.\n * @param params - The parameters to pass to the toJSONSchema function.\n * @returns The converted schema.\n */\nexport function toJsonSchema(\n schema: StandardJSONSchemaV1 | InteropZodType | JSONSchema,\n params?: ToJSONSchemaParams\n): JSONSchema {\n // Cache when no custom params are passed (the default for tool binding).\n // Params can change the output (e.g., different target draft), so we\n // bypass the cache when they're provided.\n const canCache = !params && schema != null && typeof schema === \"object\";\n\n if (canCache) {\n const cached = _jsonSchemaCache.get(schema);\n if (cached) return cached;\n }\n\n let result: JSONSchema;\n\n if (isStandardJsonSchema(schema) && !isZodSchemaV4(schema)) {\n result = schema[\"~standard\"].jsonSchema.input({\n target: \"draft-07\",\n }) as JSONSchema;\n } else if (isZodSchemaV4(schema)) {\n const inputSchema = interopZodTransformInputSchema(schema, true);\n if (isZodObjectV4(inputSchema)) {\n const strictSchema = interopZodObjectStrict(inputSchema, true);\n result = toJSONSchema(strictSchema as unknown as $ZodType, params);\n } else {\n result = toJSONSchema(schema as unknown as $ZodType, params);\n }\n } else if (isZodSchemaV3(schema)) {\n result = zodToJsonSchema(schema as never);\n } else {\n result = schema as JSONSchema;\n }\n\n if (canCache && result != null && typeof result === \"object\") {\n _jsonSchemaCache.set(schema, result);\n }\n\n return result;\n}\n\n/**\n * Validates if a JSON schema validates only strings. May return false negatives in some edge cases\n * (like recursive or unresolvable refs).\n *\n * @param schema - The schema to validate.\n * @returns `true` if the schema validates only strings, `false` otherwise.\n */\nexport function validatesOnlyStrings(schema: unknown): boolean {\n // Null, undefined, or empty schema\n if (\n !schema ||\n typeof schema !== \"object\" ||\n Object.keys(schema).length === 0 ||\n Array.isArray(schema)\n ) {\n return false; // Validates anything, not just strings\n }\n\n // Explicit type constraint\n if (\"type\" in schema) {\n if (typeof schema.type === \"string\") {\n return schema.type === \"string\";\n }\n\n if (Array.isArray(schema.type)) {\n // not sure why someone would do `\"type\": [\"string\"]` or especially `\"type\": [\"string\",\n // \"string\", \"string\", ...]` but we're not here to judge\n return schema.type.every((t) => t === \"string\");\n }\n return false; // Invalid or non-string type\n }\n\n // Enum with only string values\n if (\"enum\" in schema) {\n return (\n Array.isArray(schema.enum) &&\n schema.enum.length > 0 &&\n schema.enum.every((val) => typeof val === \"string\")\n );\n }\n\n // String constant\n if (\"const\" in schema) {\n return typeof schema.const === \"string\";\n }\n\n // Schema combinations\n if (\"allOf\" in schema && Array.isArray(schema.allOf)) {\n // If any subschema validates only strings, then the overall schema validates only strings\n return schema.allOf.some((subschema) => validatesOnlyStrings(subschema));\n }\n\n if (\n (\"anyOf\" in schema && Array.isArray(schema.anyOf)) ||\n (\"oneOf\" in schema && Array.isArray(schema.oneOf))\n ) {\n const subschemas = (\n \"anyOf\" in schema ? schema.anyOf : schema.oneOf\n ) as unknown[];\n\n // All subschemas must validate only strings\n return (\n subschemas.length > 0 &&\n subschemas.every((subschema) => validatesOnlyStrings(subschema))\n );\n }\n\n // We're not going to try on this one, it's too complex - we just assume if it has a \"not\" key and hasn't matched one of the above checks, it's not a string schema.\n if (\"not\" in schema) {\n return false; // The not case can validate non-strings\n }\n\n if (\"$ref\" in schema && typeof schema.$ref === \"string\") {\n const ref = schema.$ref as string;\n const resolved = dereference(schema as Schema);\n if (resolved[ref]) {\n return validatesOnlyStrings(resolved[ref]);\n }\n return false;\n }\n\n // ignore recursive refs and other cases where type is omitted for now\n // ignore other cases for now where type is omitted\n\n return false;\n}\n\n// Re-export of the types used throughout langchain for json schema serialization.\n// The plan is to eventually nix zod-to-json-schema altogether in place for\n// zod v4 / a more standardized way of serializing validated inputs, so its re-exported\n// here to remove the dependency on zod-to-json-schema in downstream packages until\n// a determination is made.\n\nexport {\n type JsonSchema7Type,\n type JsonSchema7Type as JSONSchema,\n type JsonSchema7ArrayType,\n type JsonSchema7ObjectType,\n type JsonSchema7StringType,\n type JsonSchema7NumberType,\n type JsonSchema7NullableType,\n} from \"./zod-to-json-schema/index.js\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,MAAM,mCAAmB,IAAI,SAA6B;;;;;;;;AAS1D,SAAgB,aACd,QACA,QACY;CAIZ,MAAM,WAAW,CAAC,UAAU,UAAU,QAAQ,OAAO,WAAW;AAEhE,KAAI,UAAU;EACZ,MAAM,SAAS,iBAAiB,IAAI,OAAO;AAC3C,MAAI,OAAQ,QAAO;;CAGrB,IAAI;AAEJ,KAAIA,8BAAAA,qBAAqB,OAAO,IAAI,CAACC,YAAAA,cAAc,OAAO,CACxD,UAAS,OAAO,aAAa,WAAW,MAAM,EAC5C,QAAQ,YACT,CAAC;UACOA,YAAAA,cAAc,OAAO,EA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AGT,KAAI,UAAU,UAAU,OAAO,OAAO,SAAS,UAAU;EACvD,MAAM,MAAM,OAAO;EACnB,MAAM,YAAA,GAAA,sBAAA,aAAuB,OAAiB;AAC9C,MAAI,SAAS,KACX,QAAO,qBAAqB,SAAS,KAAK;AAE5C,SAAO;;AAMT,QAAO"}
@@ -1 +1 @@
1
- {"version":3,"file":"json_schema.js","names":[],"sources":["../../src/utils/json_schema.ts"],"sourcesContent":["import { toJSONSchema, type $ZodType } from \"zod/v4/core\";\nimport { dereference, type Schema } from \"@cfworker/json-schema\";\nimport {\n isZodSchemaV3,\n isZodSchemaV4,\n InteropZodType,\n interopZodObjectStrict,\n isZodObjectV4,\n interopZodTransformInputSchema,\n} from \"./types/zod.js\";\nimport {\n type JsonSchema7Type as JSONSchema,\n zodToJsonSchema,\n} from \"./zod-to-json-schema/index.js\";\nimport { StandardJSONSchemaV1 } from \"@standard-schema/spec\";\nimport { isStandardJsonSchema } from \"./standard_schema.js\";\n\nexport { deepCompareStrict, Validator } from \"@cfworker/json-schema\";\n\nexport type ToJSONSchemaParams = NonNullable<\n Parameters<typeof toJSONSchema>[1]\n>;\n\n/**\n * WeakMap cache for Zod/Standard-Schema → JSON Schema conversions.\n *\n * Keyed on the schema object reference. Since Zod schemas are immutable and\n * the same `tool.schema` reference is passed on every LLM call, this\n * eliminates redundant serializations. For example, an agent with 6 tools\n * doing 15 steps across 3 parallel subagents would otherwise run 270\n * identical conversions per invocation.\n *\n * Only used when no custom `params` are passed (the common case for tool\n * binding). WeakMap ensures cached entries are GC'd when the schema goes\n * out of scope.\n *\n * @internal\n */\nconst _jsonSchemaCache = new WeakMap<object, JSONSchema>();\n\n/**\n * Converts a Standard JSON schema, Zod schema or JSON schema to a JSON schema.\n * Results are cached by schema reference when no custom params are passed.\n * @param schema - The schema to convert.\n * @param params - The parameters to pass to the toJSONSchema function.\n * @returns The converted schema.\n */\nexport function toJsonSchema(\n schema: StandardJSONSchemaV1 | InteropZodType | JSONSchema,\n params?: ToJSONSchemaParams\n): JSONSchema {\n // Cache when no custom params are passed (the default for tool binding).\n // Params can change the output (e.g., different target draft), so we\n // bypass the cache when they're provided.\n const canCache = !params && schema != null && typeof schema === \"object\";\n\n if (canCache) {\n const cached = _jsonSchemaCache.get(schema);\n if (cached) return cached;\n }\n\n let result: JSONSchema;\n\n if (isStandardJsonSchema(schema) && !isZodSchemaV4(schema)) {\n result = schema[\"~standard\"].jsonSchema.input({\n target: \"draft-07\",\n }) as JSONSchema;\n } else if (isZodSchemaV4(schema)) {\n const inputSchema = interopZodTransformInputSchema(schema, true);\n if (isZodObjectV4(inputSchema)) {\n const strictSchema = interopZodObjectStrict(inputSchema, true);\n result = toJSONSchema(strictSchema as unknown as $ZodType, params);\n } else {\n result = toJSONSchema(schema as unknown as $ZodType, params);\n }\n } else if (isZodSchemaV3(schema)) {\n result = zodToJsonSchema(schema as never);\n } else {\n result = schema as JSONSchema;\n }\n\n if (canCache && result != null && typeof result === \"object\") {\n _jsonSchemaCache.set(schema, result);\n }\n\n return result;\n}\n\n/**\n * Validates if a JSON schema validates only strings. May return false negatives in some edge cases\n * (like recursive or unresolvable refs).\n *\n * @param schema - The schema to validate.\n * @returns `true` if the schema validates only strings, `false` otherwise.\n */\nexport function validatesOnlyStrings(schema: unknown): boolean {\n // Null, undefined, or empty schema\n if (\n !schema ||\n typeof schema !== \"object\" ||\n Object.keys(schema).length === 0 ||\n Array.isArray(schema)\n ) {\n return false; // Validates anything, not just strings\n }\n\n // Explicit type constraint\n if (\"type\" in schema) {\n if (typeof schema.type === \"string\") {\n return schema.type === \"string\";\n }\n\n if (Array.isArray(schema.type)) {\n // not sure why someone would do `\"type\": [\"string\"]` or especially `\"type\": [\"string\",\n // \"string\", \"string\", ...]` but we're not here to judge\n return schema.type.every((t) => t === \"string\");\n }\n return false; // Invalid or non-string type\n }\n\n // Enum with only string values\n if (\"enum\" in schema) {\n return (\n Array.isArray(schema.enum) &&\n schema.enum.length > 0 &&\n schema.enum.every((val) => typeof val === \"string\")\n );\n }\n\n // String constant\n if (\"const\" in schema) {\n return typeof schema.const === \"string\";\n }\n\n // Schema combinations\n if (\"allOf\" in schema && Array.isArray(schema.allOf)) {\n // If any subschema validates only strings, then the overall schema validates only strings\n return schema.allOf.some((subschema) => validatesOnlyStrings(subschema));\n }\n\n if (\n (\"anyOf\" in schema && Array.isArray(schema.anyOf)) ||\n (\"oneOf\" in schema && Array.isArray(schema.oneOf))\n ) {\n const subschemas = (\n \"anyOf\" in schema ? schema.anyOf : schema.oneOf\n ) as unknown[];\n\n // All subschemas must validate only strings\n return (\n subschemas.length > 0 &&\n subschemas.every((subschema) => validatesOnlyStrings(subschema))\n );\n }\n\n // We're not going to try on this one, it's too complex - we just assume if it has a \"not\" key and hasn't matched one of the above checks, it's not a string schema.\n if (\"not\" in schema) {\n return false; // The not case can validate non-strings\n }\n\n if (\"$ref\" in schema && typeof schema.$ref === \"string\") {\n const ref = schema.$ref as string;\n const resolved = dereference(schema as Schema);\n if (resolved[ref]) {\n return validatesOnlyStrings(resolved[ref]);\n }\n return false;\n }\n\n // ignore recursive refs and other cases where type is omitted for now\n // ignore other cases for now where type is omitted\n\n return false;\n}\n\n// Re-export of the types used throughout langchain for json schema serialization.\n// The plan is to eventually nix zod-to-json-schema altogether in place for\n// zod v4 / a more standardized way of serializing validated inputs, so its re-exported\n// here to remove the dependency on zod-to-json-schema in downstream packages until\n// a determination is made.\n\nexport {\n type JsonSchema7Type,\n type JsonSchema7Type as JSONSchema,\n type JsonSchema7ArrayType,\n type JsonSchema7ObjectType,\n type JsonSchema7StringType,\n type JsonSchema7NumberType,\n type JsonSchema7NullableType,\n} from \"./zod-to-json-schema/index.js\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,MAAM,mCAAmB,IAAI,SAA6B;;;;;;;;AAS1D,SAAgB,aACd,QACA,QACY;CAIZ,MAAM,WAAW,CAAC,UAAU,UAAU,QAAQ,OAAO,WAAW;AAEhE,KAAI,UAAU;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M,aACJ,WAAW,SAAS,OAAO,QAAQ,OAAO;AAI5C,SACE,WAAW,SAAS,KACpB,WAAW,OAAO,cAAc,qBAAqB,UAAU,CAAC;;AAKpE,KAAI,SAAS,OACX,QAAO;AAGT,KAAI,UAAU,UAAU,OAAO,OAAO,SAAS,UAAU;EACvD,MAAM,MAAM,OAAO;EACnB,MAAM,WAAW,YAAY,OAAiB;AAC9C,MAAI,SAAS,KACX,QAAO,qBAAqB,SAAS,KAAK;AAE5C,SAAO;;AAMT,QAAO"}
1
+ {"version":3,"file":"json_schema.js","names":[],"sources":["../../src/utils/json_schema.ts"],"sourcesContent":["import { toJSONSchema, type $ZodType } from \"zod/v4/core\";\nimport { dereference, type Schema } from \"@cfworker/json-schema\";\nimport {\n isZodSchemaV3,\n isZodSchemaV4,\n InteropZodType,\n interopZodObjectStrict,\n isZodObjectV4,\n interopZodTransformInputSchema,\n} from \"./types/zod.js\";\nimport {\n type JsonSchema7Type as JSONSchema,\n zodToJsonSchema,\n} from \"./zod-to-json-schema/index.js\";\nimport { StandardJSONSchemaV1 } from \"@standard-schema/spec\";\nimport { isStandardJsonSchema } from \"./standard_schema.js\";\n\nexport { deepCompareStrict, Validator } from \"@cfworker/json-schema\";\n\nexport type ToJSONSchemaParams = NonNullable<\n Parameters<typeof toJSONSchema>[1]\n>;\n\n/**\n * WeakMap cache for Zod/Standard-Schema → JSON Schema conversions.\n *\n * Keyed on the schema object reference. Since Zod schemas are immutable and\n * the same `tool.schema` reference is passed on every LLM call, this\n * eliminates redundant serializations. For example, an agent with 6 tools\n * doing 15 steps across 3 parallel subagents would otherwise run 270\n * identical conversions per invocation.\n *\n * Only used when no custom `params` are passed (the common case for tool\n * binding). WeakMap ensures cached entries are GC'd when the schema goes\n * out of scope.\n *\n * @internal\n */\nconst _jsonSchemaCache = new WeakMap<object, JSONSchema>();\n\n/**\n * Converts a Standard JSON schema, Zod schema or JSON schema to a JSON schema.\n * Results are cached by schema reference when no custom params are passed.\n * @param schema - The schema to convert.\n * @param params - The parameters to pass to the toJSONSchema function.\n * @returns The converted schema.\n */\nexport function toJsonSchema(\n schema: StandardJSONSchemaV1 | InteropZodType | JSONSchema,\n params?: ToJSONSchemaParams\n): JSONSchema {\n // Cache when no custom params are passed (the default for tool binding).\n // Params can change the output (e.g., different target draft), so we\n // bypass the cache when they're provided.\n const canCache = !params && schema != null && typeof schema === \"object\";\n\n if (canCache) {\n const cached = _jsonSchemaCache.get(schema);\n if (cached) return cached;\n }\n\n let result: JSONSchema;\n\n if (isStandardJsonSchema(schema) && !isZodSchemaV4(schema)) {\n result = schema[\"~standard\"].jsonSchema.input({\n target: \"draft-07\",\n }) as JSONSchema;\n } else if (isZodSchemaV4(schema)) {\n const inputSchema = interopZodTransformInputSchema(schema, true);\n if (isZodObjectV4(inputSchema)) {\n const strictSchema = interopZodObjectStrict(inputSchema, true);\n result = toJSONSchema(strictSchema as unknown as $ZodType, params);\n } else {\n result = toJSONSchema(schema as unknown as $ZodType, params);\n }\n } else if (isZodSchemaV3(schema)) {\n result = zodToJsonSchema(schema as never);\n } else {\n result = schema as JSONSchema;\n }\n\n if (canCache && result != null && typeof result === \"object\") {\n _jsonSchemaCache.set(schema, result);\n }\n\n return result;\n}\n\n/**\n * Validates if a JSON schema validates only strings. May return false negatives in some edge cases\n * (like recursive or unresolvable refs).\n *\n * @param schema - The schema to validate.\n * @returns `true` if the schema validates only strings, `false` otherwise.\n */\nexport function validatesOnlyStrings(schema: unknown): boolean {\n // Null, undefined, or empty schema\n if (\n !schema ||\n typeof schema !== \"object\" ||\n Object.keys(schema).length === 0 ||\n Array.isArray(schema)\n ) {\n return false; // Validates anything, not just strings\n }\n\n // Explicit type constraint\n if (\"type\" in schema) {\n if (typeof schema.type === \"string\") {\n return schema.type === \"string\";\n }\n\n if (Array.isArray(schema.type)) {\n // not sure why someone would do `\"type\": [\"string\"]` or especially `\"type\": [\"string\",\n // \"string\", \"string\", ...]` but we're not here to judge\n return schema.type.every((t) => t === \"string\");\n }\n return false; // Invalid or non-string type\n }\n\n // Enum with only string values\n if (\"enum\" in schema) {\n return (\n Array.isArray(schema.enum) &&\n schema.enum.length > 0 &&\n schema.enum.every((val) => typeof val === \"string\")\n );\n }\n\n // String constant\n if (\"const\" in schema) {\n return typeof schema.const === \"string\";\n }\n\n // Schema combinations\n if (\"allOf\" in schema && Array.isArray(schema.allOf)) {\n // If any subschema validates only strings, then the overall schema validates only strings\n return schema.allOf.some((subschema) => validatesOnlyStrings(subschema));\n }\n\n if (\n (\"anyOf\" in schema && Array.isArray(schema.anyOf)) ||\n (\"oneOf\" in schema && Array.isArray(schema.oneOf))\n ) {\n const subschemas = (\n \"anyOf\" in schema ? schema.anyOf : schema.oneOf\n ) as unknown[];\n\n // All subschemas must validate only strings\n return (\n subschemas.length > 0 &&\n subschemas.every((subschema) => validatesOnlyStrings(subschema))\n );\n }\n\n // We're not going to try on this one, it's too complex - we just assume if it has a \"not\" key and hasn't matched one of the above checks, it's not a string schema.\n if (\"not\" in schema) {\n return false; // The not case can validate non-strings\n }\n\n if (\"$ref\" in schema && typeof schema.$ref === \"string\") {\n const ref = schema.$ref as string;\n const resolved = dereference(schema as Schema);\n if (resolved[ref]) {\n return validatesOnlyStrings(resolved[ref]);\n }\n return false;\n }\n\n // ignore recursive refs and other cases where type is omitted for now\n // ignore other cases for now where type is omitted\n\n return false;\n}\n\n// Re-export of the types used throughout langchain for json schema serialization.\n// The plan is to eventually nix zod-to-json-schema altogether in place for\n// zod v4 / a more standardized way of serializing validated inputs, so its re-exported\n// here to remove the dependency on zod-to-json-schema in downstream packages until\n// a determination is made.\n\nexport {\n type JsonSchema7Type,\n type JsonSchema7Type as JSONSchema,\n type JsonSchema7ArrayType,\n type JsonSchema7ObjectType,\n type JsonSchema7StringType,\n type JsonSchema7NumberType,\n type JsonSchema7NullableType,\n} from \"./zod-to-json-schema/index.js\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,MAAM,mCAAmB,IAAI,SAA6B;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