yanki 1.2.10 → 2.0.0

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 (297) hide show
  1. package/dist/bin/cli.js +58 -9
  2. package/dist/lib/index.d.ts +144 -1566
  3. package/dist/lib/index.js +50 -1
  4. package/package.json +33 -28
  5. package/readme.md +4 -4
  6. package/dist/abap-Dg923wIy.js +0 -1
  7. package/dist/actionscript-3-BBttMYlr.js +0 -1
  8. package/dist/ada-CTi7YQtL.js +0 -1
  9. package/dist/andromeeda-BK6gTiwT.js +0 -1
  10. package/dist/angular-html-rCdPnZ8w.js +0 -1
  11. package/dist/angular-ts-DYCYVCHu.js +0 -1
  12. package/dist/apache-PcO-DBxQ.js +0 -1
  13. package/dist/apex-CnCu5_gb.js +0 -1
  14. package/dist/apl-B743j01p.js +0 -1
  15. package/dist/applescript-BWh8DkcF.js +0 -1
  16. package/dist/ara-C1--7J61.js +0 -1
  17. package/dist/asciidoc-CkWYjVYI.js +0 -1
  18. package/dist/asm-CTFRnVOM.js +0 -1
  19. package/dist/astro-DHbdk5O0.js +0 -1
  20. package/dist/aurora-x-C0VKFdlO.js +0 -1
  21. package/dist/awk-CrWgQKhV.js +0 -1
  22. package/dist/ayu-dark-De7IQEfS.js +0 -1
  23. package/dist/ballerina-a0yOSyc5.js +0 -1
  24. package/dist/bat-B0cHNp6s.js +0 -1
  25. package/dist/beancount-dPJi_gci.js +0 -1
  26. package/dist/berry-CVKoklHx.js +0 -1
  27. package/dist/bibtex-DRcCXNgM.js +0 -1
  28. package/dist/bicep-jWz-hQ8I.js +0 -1
  29. package/dist/blade-h41ErOi-.js +0 -1
  30. package/dist/bsl-C7rNYC9b.js +0 -1
  31. package/dist/c-BG-tZi7o.js +0 -1
  32. package/dist/c3-2rTjmrCP.js +0 -1
  33. package/dist/cadence-BuaeHeSu.js +0 -1
  34. package/dist/cairo-BHkUC1B6.js +0 -1
  35. package/dist/catppuccin-frappe-D3lHSMns.js +0 -1
  36. package/dist/catppuccin-latte-DoBaWTGn.js +0 -1
  37. package/dist/catppuccin-macchiato-BkAuvdZC.js +0 -1
  38. package/dist/catppuccin-mocha-D9fcC0iT.js +0 -1
  39. package/dist/clarity-CC_0IFDj.js +0 -1
  40. package/dist/clojure-KnfDkB_V.js +0 -1
  41. package/dist/cmake-bh2MLnkv.js +0 -1
  42. package/dist/cobol-WHXSr_Wd.js +0 -1
  43. package/dist/codeowners-CtwIM3TN.js +0 -1
  44. package/dist/codeql-D164juXQ.js +0 -1
  45. package/dist/coffee-BWKAfs2s.js +0 -1
  46. package/dist/common-lisp-DXc9XcIM.js +0 -1
  47. package/dist/coq-BCSFDxg0.js +0 -1
  48. package/dist/cpp-CTmscSNZ.js +0 -1
  49. package/dist/crystal-BFJuErkW.js +0 -1
  50. package/dist/csharp-BztKY7sB.js +0 -1
  51. package/dist/css-PZBBrkI0.js +0 -1
  52. package/dist/csv-D5aBhKLr.js +0 -1
  53. package/dist/cue-WCin6O4e.js +0 -1
  54. package/dist/cypher-DYQk2G82.js +0 -1
  55. package/dist/d-DVc-yF-l.js +0 -1
  56. package/dist/dark-plus-DLU5INA3.js +0 -1
  57. package/dist/dart-YLd5yyRs.js +0 -1
  58. package/dist/dax-oldcCaJg.js +0 -1
  59. package/dist/desktop-DZfyBMgF.js +0 -1
  60. package/dist/diff-jW5kmiru.js +0 -1
  61. package/dist/docker-DG9neUKd.js +0 -1
  62. package/dist/dotenv-Bea-FkXq.js +0 -1
  63. package/dist/dracula-XcYHBZy6.js +0 -1
  64. package/dist/dracula-soft-BPeX9gxW.js +0 -1
  65. package/dist/dream-maker-DAHQwpwp.js +0 -1
  66. package/dist/edge-BvW7BRWT.js +0 -1
  67. package/dist/elixir-C40XQAD9.js +0 -1
  68. package/dist/elm-DzXNHNQT.js +0 -1
  69. package/dist/emacs-lisp-BdGsgvrR.js +0 -1
  70. package/dist/erb-Dis5VyyW.js +0 -1
  71. package/dist/erlang-Jhp2iHYS.js +0 -1
  72. package/dist/everforest-dark-WOub3wle.js +0 -1
  73. package/dist/everforest-light-DCUg8VH8.js +0 -1
  74. package/dist/fennel-BH6gVCng.js +0 -1
  75. package/dist/fish-BxskpYPN.js +0 -1
  76. package/dist/fluent-Bwo2XpEt.js +0 -1
  77. package/dist/fortran-fixed-form-DoFUIhSC.js +0 -1
  78. package/dist/fortran-free-form-DB5N_DgY.js +0 -1
  79. package/dist/fsharp-DHaf8n3s.js +0 -1
  80. package/dist/gdresource-D9Lk-biZ.js +0 -1
  81. package/dist/gdscript-AcTSlgpe.js +0 -1
  82. package/dist/gdshader-G7X6ysY3.js +0 -1
  83. package/dist/genie-DSsjfZMX.js +0 -1
  84. package/dist/gherkin-Cbsyuvab.js +0 -1
  85. package/dist/git-commit-CesLaiSz.js +0 -1
  86. package/dist/git-rebase-B9wKr8Mu.js +0 -1
  87. package/dist/github-dark-BQV5ugrc.js +0 -1
  88. package/dist/github-dark-default-DLWDM7FH.js +0 -1
  89. package/dist/github-dark-dimmed-D1FmiR_p.js +0 -1
  90. package/dist/github-dark-high-contrast-BilLoi0o.js +0 -1
  91. package/dist/github-light-Rcb2q3L5.js +0 -1
  92. package/dist/github-light-default-CQ75esMw.js +0 -1
  93. package/dist/github-light-high-contrast-CRF1wyLy.js +0 -1
  94. package/dist/gleam-BeBqoPwE.js +0 -1
  95. package/dist/glimmer-js-3dwOmeU7.js +0 -1
  96. package/dist/glimmer-ts-CGrdEN9y.js +0 -1
  97. package/dist/glsl-CJ5UNUz7.js +0 -1
  98. package/dist/gn-Dxr0sSUf.js +0 -1
  99. package/dist/gnuplot-CtW3R_Hz.js +0 -1
  100. package/dist/go-CPYJReqS.js +0 -1
  101. package/dist/graphql-BXLvmlOo.js +0 -1
  102. package/dist/groovy-DFxE31Qs.js +0 -1
  103. package/dist/gruvbox-dark-hard-C37G1gbc.js +0 -1
  104. package/dist/gruvbox-dark-medium-C3G9m3TV.js +0 -1
  105. package/dist/gruvbox-dark-soft-eZmcmZ9I.js +0 -1
  106. package/dist/gruvbox-light-hard-BYj-vz_3.js +0 -1
  107. package/dist/gruvbox-light-medium-BdQlDiiF.js +0 -1
  108. package/dist/gruvbox-light-soft-BGNwjiRh.js +0 -1
  109. package/dist/hack-BVNIISZD.js +0 -1
  110. package/dist/haml-CNL2qJ9f.js +0 -1
  111. package/dist/handlebars-X5srullM.js +0 -1
  112. package/dist/haskell-CeCR1-Hh.js +0 -1
  113. package/dist/haxe-DVIybFAS.js +0 -1
  114. package/dist/hcl-B6OePqme.js +0 -1
  115. package/dist/hjson-D2jn7IRw.js +0 -1
  116. package/dist/hlsl-MKeth5V9.js +0 -1
  117. package/dist/houston-RHIKkNfR.js +0 -1
  118. package/dist/html-B4bznzA2.js +0 -1
  119. package/dist/html-derivative-CD1Z7kSG.js +0 -1
  120. package/dist/http-Bb0P8zvE.js +0 -1
  121. package/dist/hurl-DdMgw5nt.js +0 -1
  122. package/dist/hxml-BdTS9Zj7.js +0 -1
  123. package/dist/hy-BZMqGtQj.js +0 -1
  124. package/dist/imba-D-Pk5S0X.js +0 -1
  125. package/dist/index-CQlZV-e4.js +0 -2
  126. package/dist/ini-Dix3pTmg.js +0 -1
  127. package/dist/java-BTDmaRNO.js +0 -1
  128. package/dist/javascript-WyGyM1wV.js +0 -1
  129. package/dist/jinja-Cibv3n81.js +0 -1
  130. package/dist/jison-CZOoZOej.js +0 -1
  131. package/dist/json-B8JryHcM.js +0 -1
  132. package/dist/json5-Cdatmj9n.js +0 -1
  133. package/dist/jsonc-CvUCa1o5.js +0 -1
  134. package/dist/jsonl-9I_GBd5L.js +0 -1
  135. package/dist/jsonnet-XoenQ2oc.js +0 -1
  136. package/dist/jssm-CWE2S0Z5.js +0 -1
  137. package/dist/jsx-8cLv2Six.js +0 -1
  138. package/dist/julia-DIzTBDVk.js +0 -1
  139. package/dist/kanagawa-dragon-BOvIHJVT.js +0 -1
  140. package/dist/kanagawa-lotus-Bwcd7Bvx.js +0 -1
  141. package/dist/kanagawa-wave-0SAlpf0s.js +0 -1
  142. package/dist/kdl-CMbyIXjQ.js +0 -1
  143. package/dist/kotlin-BQy537ds.js +0 -1
  144. package/dist/kusto-B_y0uMaZ.js +0 -1
  145. package/dist/laserwave-si7wuSrt.js +0 -1
  146. package/dist/latex-BXZuhSz0.js +0 -1
  147. package/dist/lean-7hWDN_w4.js +0 -1
  148. package/dist/less-CaoNcwlE.js +0 -1
  149. package/dist/light-plus-g_Fi9vkG.js +0 -1
  150. package/dist/liquid-e5bbsXXe.js +0 -1
  151. package/dist/llvm-CiYQeg8E.js +0 -1
  152. package/dist/log-CcaF_xNv.js +0 -1
  153. package/dist/logo-D9WQLoKQ.js +0 -1
  154. package/dist/lua-DRivoEBK.js +0 -1
  155. package/dist/luau-BTSFCcFb.js +0 -1
  156. package/dist/make-DXVx14cr.js +0 -1
  157. package/dist/markdown-DX-TNHnc.js +0 -1
  158. package/dist/marko-CFpKsLoh.js +0 -1
  159. package/dist/material-theme-CIJ3cGaW.js +0 -1
  160. package/dist/material-theme-darker-BWg3m1GB.js +0 -1
  161. package/dist/material-theme-lighter-DR8HWMN7.js +0 -1
  162. package/dist/material-theme-ocean-CZf9pk28.js +0 -1
  163. package/dist/material-theme-palenight-BF01YeZy.js +0 -1
  164. package/dist/matlab-DzreyMvm.js +0 -1
  165. package/dist/mdc-BX9nsEef.js +0 -1
  166. package/dist/mdx-C2fqO2XY.js +0 -1
  167. package/dist/mermaid-Cwy4Up_p.js +0 -1
  168. package/dist/min-dark-DhfaepVE.js +0 -1
  169. package/dist/min-light-6xx0uMgm.js +0 -1
  170. package/dist/mipsasm-yE_Aqo9y.js +0 -1
  171. package/dist/mojo-Bk-6ipf4.js +0 -1
  172. package/dist/monokai-BodnsaDQ.js +0 -1
  173. package/dist/moonbit-C7bLf9Bh.js +0 -1
  174. package/dist/move-BvvU7WAr.js +0 -1
  175. package/dist/narrat-DXUZ_ZkW.js +0 -1
  176. package/dist/nextflow-MPHPbw14.js +0 -1
  177. package/dist/nginx-DE9vInot.js +0 -1
  178. package/dist/night-owl-EdP2Hztp.js +0 -1
  179. package/dist/nim-CvfVE-Jm.js +0 -1
  180. package/dist/nix-Ckjrpg0r.js +0 -1
  181. package/dist/nord-BAu0wM6c.js +0 -1
  182. package/dist/nushell-8dnicoUR.js +0 -1
  183. package/dist/objective-c-BoaBTdtz.js +0 -1
  184. package/dist/objective-cpp-DstR8hNy.js +0 -1
  185. package/dist/ocaml-DTbn2Hv7.js +0 -1
  186. package/dist/one-dark-pro-utPxbBbJ.js +0 -1
  187. package/dist/one-light-s-s--efq.js +0 -1
  188. package/dist/openscad-CXHpNBsb.js +0 -1
  189. package/dist/pascal-Sr-XLSE6.js +0 -1
  190. package/dist/perl-Dl-vCdjY.js +0 -1
  191. package/dist/php-B5RY5YQV.js +0 -1
  192. package/dist/pkl-CRusufhw.js +0 -1
  193. package/dist/plastic-CXnNNlFZ.js +0 -1
  194. package/dist/plsql-Dbm3tV2N.js +0 -1
  195. package/dist/po-LG0lFwH4.js +0 -1
  196. package/dist/poimandres-BrOVMvuE.js +0 -1
  197. package/dist/polar-DjOs3GWb.js +0 -1
  198. package/dist/postcss-GRRkWn2F.js +0 -1
  199. package/dist/powerquery-DHf-dtTS.js +0 -1
  200. package/dist/powershell-CubgGmZX.js +0 -1
  201. package/dist/prisma-Dgf8IN_C.js +0 -1
  202. package/dist/prolog-9JcfiY6I.js +0 -1
  203. package/dist/proto-dqx_Sj2i.js +0 -1
  204. package/dist/pug-jKFt5v09.js +0 -1
  205. package/dist/puppet-B4ctDsrh.js +0 -1
  206. package/dist/purescript-B-mlhevv.js +0 -1
  207. package/dist/python-B6Ihcp-E.js +0 -1
  208. package/dist/qml-CXQr5hi3.js +0 -1
  209. package/dist/qmldir-DXd9s5XC.js +0 -1
  210. package/dist/qss-B7NnhfIi.js +0 -1
  211. package/dist/r-1ts4xG1r.js +0 -1
  212. package/dist/racket-CrxT4k8p.js +0 -1
  213. package/dist/raku-B9ngR1rt.js +0 -1
  214. package/dist/razor-xda6wMq7.js +0 -1
  215. package/dist/red-DR6ZwibK.js +0 -1
  216. package/dist/reg-Cvyu2Gnx.js +0 -1
  217. package/dist/regexp-DK-WlHNu.js +0 -1
  218. package/dist/rel-CYd0g8C5.js +0 -1
  219. package/dist/riscv-C5dpdlr7.js +0 -1
  220. package/dist/rose-pine-Cd1NG3HO.js +0 -1
  221. package/dist/rose-pine-dawn-eauBvPfk.js +0 -1
  222. package/dist/rose-pine-moon-B3tSb9zr.js +0 -1
  223. package/dist/rosmsg-ZkSIzPhc.js +0 -1
  224. package/dist/rst-DBtDFrr6.js +0 -1
  225. package/dist/ruby-B8qtJuKf.js +0 -1
  226. package/dist/rust-CxuBE0J8.js +0 -1
  227. package/dist/sas-9Dvcn_Se.js +0 -1
  228. package/dist/sass-bfEVHPJ8.js +0 -1
  229. package/dist/scala-Dtw19ca_.js +0 -1
  230. package/dist/scheme-OJppFQF3.js +0 -1
  231. package/dist/scss-CFlr0x0u.js +0 -1
  232. package/dist/sdbl-Bd9eE8IL.js +0 -1
  233. package/dist/shaderlab-CJHdEwFw.js +0 -1
  234. package/dist/shellscript-DgJyDXW6.js +0 -1
  235. package/dist/shellsession-BqFY_Jl7.js +0 -1
  236. package/dist/slack-dark-CWRQmTmo.js +0 -1
  237. package/dist/slack-ochin-DO_ok7XK.js +0 -1
  238. package/dist/smalltalk-B9IHbYt7.js +0 -1
  239. package/dist/snazzy-light-B5llO_gK.js +0 -1
  240. package/dist/solarized-dark-G9yBjKj_.js +0 -1
  241. package/dist/solarized-light-DeSzljQz.js +0 -1
  242. package/dist/solidity-B3CjIuAd.js +0 -1
  243. package/dist/soy-BnGnvCkT.js +0 -1
  244. package/dist/sparql-Ckj_9Rg5.js +0 -1
  245. package/dist/splunk-h-bNAnbk.js +0 -1
  246. package/dist/sql-BbONfI8K.js +0 -1
  247. package/dist/ssh-config-CywOjoXH.js +0 -1
  248. package/dist/stata-eYSq_k6x.js +0 -1
  249. package/dist/stylus-CIg617SB.js +0 -1
  250. package/dist/svelte-Bq7yX3Ip.js +0 -1
  251. package/dist/swift-D8uC5CNv.js +0 -1
  252. package/dist/sync-files-obgDr5HY.js +0 -962
  253. package/dist/synthwave-84-DRVv-_m_.js +0 -1
  254. package/dist/system-verilog-Qdm_1g2q.js +0 -1
  255. package/dist/systemd-DMp0udv_.js +0 -1
  256. package/dist/talonscript-eRuyeYHl.js +0 -1
  257. package/dist/tasl-B9CVvjfG.js +0 -1
  258. package/dist/tcl-Bq9dbVAF.js +0 -1
  259. package/dist/templ-BA8-YsSp.js +0 -1
  260. package/dist/terraform-CAp711iT.js +0 -1
  261. package/dist/tex-Dpq9weyt.js +0 -1
  262. package/dist/tokyo-night-BvwC8l2v.js +0 -1
  263. package/dist/toml-Ms459DBw.js +0 -1
  264. package/dist/ts-tags-D-LANnn2.js +0 -1
  265. package/dist/tsv-BFtm7NXx.js +0 -1
  266. package/dist/tsx-D6116Ycy.js +0 -1
  267. package/dist/turtle-DpRhbQZY.js +0 -1
  268. package/dist/twig-bKeTGJCh.js +0 -1
  269. package/dist/typescript-BqvgUolh.js +0 -1
  270. package/dist/typespec-DhK7u29_.js +0 -1
  271. package/dist/typst-Dfd71gQj.js +0 -1
  272. package/dist/v-BH76v7br.js +0 -1
  273. package/dist/vala-z59IxkFd.js +0 -1
  274. package/dist/vb-4AxSLKIU.js +0 -1
  275. package/dist/verilog-LfQUkHDc.js +0 -1
  276. package/dist/vesper--t9w6MWz.js +0 -1
  277. package/dist/vhdl-DJCsFYgn.js +0 -1
  278. package/dist/viml-pbKHW3Ia.js +0 -1
  279. package/dist/vitesse-black-B_BYPdvp.js +0 -1
  280. package/dist/vitesse-dark-DOSOf2Sz.js +0 -1
  281. package/dist/vitesse-light-gUX51GpB.js +0 -1
  282. package/dist/vue-FQ0hgXO-.js +0 -1
  283. package/dist/vue-html-DH1-x0xc.js +0 -1
  284. package/dist/vue-vine-DeUyrIQS.js +0 -1
  285. package/dist/vyper-DpazWNpx.js +0 -1
  286. package/dist/wasm-CFi-k9--.js +0 -1
  287. package/dist/wasm-CiQ5tcoN.js +0 -1
  288. package/dist/wenyan-DoPRjnAP.js +0 -1
  289. package/dist/wgsl-CxjTZs-b.js +0 -1
  290. package/dist/wikitext-Bx2qct8O.js +0 -1
  291. package/dist/wit-DDW3hD69.js +0 -1
  292. package/dist/wolfram-pu21K997.js +0 -1
  293. package/dist/xml-BhAxjPaW.js +0 -1
  294. package/dist/xsl-6n2rlM5j.js +0 -1
  295. package/dist/yaml-Bopit2L3.js +0 -1
  296. package/dist/zenscript-BIAKq-aR.js +0 -1
  297. package/dist/zig-bSFrHQ7n.js +0 -1
@@ -1,1548 +1,122 @@
1
- /**
2
- Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
3
-
4
- @category Type
5
- */
6
- type Primitive =
7
- | null
8
- | undefined
9
- | string
10
- | number
11
- | boolean
12
- | symbol
13
- | bigint;
14
-
15
- /**
16
- Returns a boolean for whether the given type is `any`.
17
-
18
- @link https://stackoverflow.com/a/49928360/1490091
19
-
20
- Useful in type utilities, such as disallowing `any`s to be passed to a function.
21
-
22
- @example
23
- ```
24
- import type {IsAny} from 'type-fest';
25
-
26
- const typedObject = {a: 1, b: 2} as const;
27
- const anyObject: any = {a: 1, b: 2};
28
-
29
- function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(object: O, key: K) {
30
- return object[key];
31
- }
32
-
33
- const typedA = get(typedObject, 'a');
34
- //=> 1
35
-
36
- const anyA = get(anyObject, 'a');
37
- //=> any
38
- ```
39
-
40
- @category Type Guard
41
- @category Utilities
42
- */
43
- type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;
44
-
45
- /**
46
- Returns a boolean for whether the given key is an optional key of type.
47
-
48
- This is useful when writing utility types or schema validators that need to differentiate `optional` keys.
49
-
50
- @example
51
- ```
52
- import type {IsOptionalKeyOf} from 'type-fest';
53
-
54
- type User = {
55
- name: string;
56
- surname: string;
57
-
58
- luckyNumber?: number;
59
- };
60
-
61
- type Admin = {
62
- name: string;
63
- surname?: string;
64
- };
65
-
66
- type T1 = IsOptionalKeyOf<User, 'luckyNumber'>;
67
- //=> true
68
-
69
- type T2 = IsOptionalKeyOf<User, 'name'>;
70
- //=> false
71
-
72
- type T3 = IsOptionalKeyOf<User, 'name' | 'luckyNumber'>;
73
- //=> boolean
74
-
75
- type T4 = IsOptionalKeyOf<User | Admin, 'name'>;
76
- //=> false
77
-
78
- type T5 = IsOptionalKeyOf<User | Admin, 'surname'>;
79
- //=> boolean
80
- ```
81
-
82
- @category Type Guard
83
- @category Utilities
84
- */
85
- type IsOptionalKeyOf<Type extends object, Key extends keyof Type> =
86
- IsAny<Type | Key> extends true ? never
87
- : Key extends keyof Type
88
- ? Type extends Record<Key, Type[Key]>
89
- ? false
90
- : true
91
- : false;
92
-
93
- /**
94
- Extract all optional keys from the given type.
95
-
96
- This is useful when you want to create a new type that contains different type values for the optional keys only.
97
-
98
- @example
99
- ```
100
- import type {OptionalKeysOf, Except} from 'type-fest';
101
-
102
- type User = {
103
- name: string;
104
- surname: string;
105
-
106
- luckyNumber?: number;
107
- };
108
-
109
- const REMOVE_FIELD = Symbol('remove field symbol');
110
- type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
111
- [Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
112
- };
113
-
114
- const update1: UpdateOperation<User> = {
115
- name: 'Alice',
116
- };
117
-
118
- const update2: UpdateOperation<User> = {
119
- name: 'Bob',
120
- luckyNumber: REMOVE_FIELD,
121
- };
122
- ```
123
-
124
- @category Utilities
125
- */
126
- type OptionalKeysOf<Type extends object> =
127
- Type extends unknown // For distributing `Type`
128
- ? (keyof {[Key in keyof Type as
129
- IsOptionalKeyOf<Type, Key> extends false
130
- ? never
131
- : Key
132
- ]: never
133
- }) & keyof Type // Intersect with `keyof Type` to ensure result of `OptionalKeysOf<Type>` is always assignable to `keyof Type`
134
- : never; // Should never happen
135
-
136
- /**
137
- Extract all required keys from the given type.
138
-
139
- This is useful when you want to create a new type that contains different type values for the required keys only or use the list of keys for validation purposes, etc...
140
-
141
- @example
142
- ```
143
- import type {RequiredKeysOf} from 'type-fest';
144
-
145
- declare function createValidation<
146
- Entity extends object,
147
- Key extends RequiredKeysOf<Entity> = RequiredKeysOf<Entity>,
148
- >(field: Key, validator: (value: Entity[Key]) => boolean): (entity: Entity) => boolean;
149
-
150
- type User = {
151
- name: string;
152
- surname: string;
153
- luckyNumber?: number;
154
- };
155
-
156
- const validator1 = createValidation<User>('name', value => value.length < 25);
157
- const validator2 = createValidation<User>('surname', value => value.length < 25);
158
-
159
- // @ts-expect-error
160
- const validator3 = createValidation<User>('luckyNumber', value => value > 0);
161
- // Error: Argument of type '"luckyNumber"' is not assignable to parameter of type '"name" | "surname"'.
162
- ```
163
-
164
- @category Utilities
165
- */
166
- type RequiredKeysOf<Type extends object> =
167
- Type extends unknown // For distributing `Type`
168
- ? Exclude<keyof Type, OptionalKeysOf<Type>>
169
- : never; // Should never happen
170
-
171
- /**
172
- Returns a boolean for whether the given type is `never`.
173
-
174
- @link https://github.com/microsoft/TypeScript/issues/31751#issuecomment-498526919
175
- @link https://stackoverflow.com/a/53984913/10292952
176
- @link https://www.zhenghao.io/posts/ts-never
177
-
178
- Useful in type utilities, such as checking if something does not occur.
179
-
180
- @example
181
- ```
182
- import type {IsNever, And} from 'type-fest';
183
-
184
- type A = IsNever<never>;
185
- //=> true
186
-
187
- type B = IsNever<any>;
188
- //=> false
189
-
190
- type C = IsNever<unknown>;
191
- //=> false
192
-
193
- type D = IsNever<never[]>;
194
- //=> false
195
-
196
- type E = IsNever<object>;
197
- //=> false
198
-
199
- type F = IsNever<string>;
200
- //=> false
201
- ```
202
-
203
- @example
204
- ```
205
- import type {IsNever} from 'type-fest';
206
-
207
- type IsTrue<T> = T extends true ? true : false;
208
-
209
- // When a distributive conditional is instantiated with `never`, the entire conditional results in `never`.
210
- type A = IsTrue<never>;
211
- //=> never
212
-
213
- // If you don't want that behaviour, you can explicitly add an `IsNever` check before the distributive conditional.
214
- type IsTrueFixed<T> =
215
- IsNever<T> extends true ? false : T extends true ? true : false;
216
-
217
- type B = IsTrueFixed<never>;
218
- //=> false
219
- ```
220
-
221
- @category Type Guard
222
- @category Utilities
223
- */
224
- type IsNever<T> = [T] extends [never] ? true : false;
225
-
226
- /**
227
- An if-else-like type that resolves depending on whether the given `boolean` type is `true` or `false`.
228
-
229
- Use-cases:
230
- - You can use this in combination with `Is*` types to create an if-else-like experience. For example, `If<IsAny<any>, 'is any', 'not any'>`.
231
-
232
- Note:
233
- - Returns a union of if branch and else branch if the given type is `boolean` or `any`. For example, `If<boolean, 'Y', 'N'>` will return `'Y' | 'N'`.
234
- - Returns the else branch if the given type is `never`. For example, `If<never, 'Y', 'N'>` will return `'N'`.
235
-
236
- @example
237
- ```
238
- import type {If} from 'type-fest';
239
-
240
- type A = If<true, 'yes', 'no'>;
241
- //=> 'yes'
242
-
243
- type B = If<false, 'yes', 'no'>;
244
- //=> 'no'
245
-
246
- type C = If<boolean, 'yes', 'no'>;
247
- //=> 'yes' | 'no'
248
-
249
- type D = If<any, 'yes', 'no'>;
250
- //=> 'yes' | 'no'
251
-
252
- type E = If<never, 'yes', 'no'>;
253
- //=> 'no'
254
- ```
255
-
256
- @example
257
- ```
258
- import type {If, IsAny, IsNever} from 'type-fest';
259
-
260
- type A = If<IsAny<unknown>, 'is any', 'not any'>;
261
- //=> 'not any'
262
-
263
- type B = If<IsNever<never>, 'is never', 'not never'>;
264
- //=> 'is never'
265
- ```
266
-
267
- @example
268
- ```
269
- import type {If, IsEqual} from 'type-fest';
270
-
271
- type IfEqual<T, U, IfBranch, ElseBranch> = If<IsEqual<T, U>, IfBranch, ElseBranch>;
272
-
273
- type A = IfEqual<string, string, 'equal', 'not equal'>;
274
- //=> 'equal'
275
-
276
- type B = IfEqual<string, number, 'equal', 'not equal'>;
277
- //=> 'not equal'
278
- ```
279
-
280
- Note: Sometimes using the `If` type can make an implementation non–tail-recursive, which can impact performance. In such cases, it’s better to use a conditional directly. Refer to the following example:
281
-
282
- @example
283
- ```
284
- import type {If, IsEqual, StringRepeat} from 'type-fest';
285
-
286
- type HundredZeroes = StringRepeat<'0', 100>;
287
-
288
- // The following implementation is not tail recursive
289
- type Includes<S extends string, Char extends string> =
290
- S extends `${infer First}${infer Rest}`
291
- ? If<IsEqual<First, Char>,
292
- 'found',
293
- Includes<Rest, Char>>
294
- : 'not found';
295
-
296
- // Hence, instantiations with long strings will fail
297
- // @ts-expect-error
298
- type Fails = Includes<HundredZeroes, '1'>;
299
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
300
- // Error: Type instantiation is excessively deep and possibly infinite.
301
-
302
- // However, if we use a simple conditional instead of `If`, the implementation becomes tail-recursive
303
- type IncludesWithoutIf<S extends string, Char extends string> =
304
- S extends `${infer First}${infer Rest}`
305
- ? IsEqual<First, Char> extends true
306
- ? 'found'
307
- : IncludesWithoutIf<Rest, Char>
308
- : 'not found';
309
-
310
- // Now, instantiations with long strings will work
311
- type Works = IncludesWithoutIf<HundredZeroes, '1'>;
312
- //=> 'not found'
313
- ```
314
-
315
- @category Type Guard
316
- @category Utilities
317
- */
318
- type If<Type extends boolean, IfBranch, ElseBranch> =
319
- IsNever<Type> extends true
320
- ? ElseBranch
321
- : Type extends true
322
- ? IfBranch
323
- : ElseBranch;
324
-
325
- /**
326
- Matches any primitive, `void`, `Date`, or `RegExp` value.
327
- */
328
- type BuiltIns = Primitive | void | Date | RegExp;
329
-
330
- /**
331
- Test if the given function has multiple call signatures.
332
-
333
- Needed to handle the case of a single call signature with properties.
334
-
335
- Multiple call signatures cannot currently be supported due to a TypeScript limitation.
336
- @see https://github.com/microsoft/TypeScript/issues/29732
337
- */
338
- type HasMultipleCallSignatures<T extends (...arguments_: any[]) => unknown> =
339
- T extends {(...arguments_: infer A): unknown; (...arguments_: infer B): unknown}
340
- ? B extends A
341
- ? A extends B
342
- ? false
343
- : true
344
- : true
345
- : false;
346
-
347
- /**
348
- Useful to flatten the type output to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability.
349
-
350
- @example
351
- ```
352
- import type {Simplify} from 'type-fest';
353
-
354
- type PositionProps = {
355
- top: number;
356
- left: number;
357
- };
358
-
359
- type SizeProps = {
360
- width: number;
361
- height: number;
362
- };
363
-
364
- // In your editor, hovering over `Props` will show a flattened object with all the properties.
365
- type Props = Simplify<PositionProps & SizeProps>;
366
- ```
367
-
368
- Sometimes it is desired to pass a value as a function argument that has a different type. At first inspection it may seem assignable, and then you discover it is not because the `value`'s type definition was defined as an interface. In the following example, `fn` requires an argument of type `Record<string, unknown>`. If the value is defined as a literal, then it is assignable. And if the `value` is defined as type using the `Simplify` utility the value is assignable. But if the `value` is defined as an interface, it is not assignable because the interface is not sealed and elsewhere a non-string property could be added to the interface.
369
-
370
- If the type definition must be an interface (perhaps it was defined in a third-party npm package), then the `value` can be defined as `const value: Simplify<SomeInterface> = ...`. Then `value` will be assignable to the `fn` argument. Or the `value` can be cast as `Simplify<SomeInterface>` if you can't re-declare the `value`.
371
-
372
- @example
373
- ```
374
- import type {Simplify} from 'type-fest';
375
-
376
- interface SomeInterface {
377
- foo: number;
378
- bar?: string;
379
- baz: number | undefined;
380
- }
381
-
382
- type SomeType = {
383
- foo: number;
384
- bar?: string;
385
- baz: number | undefined;
386
- };
387
-
388
- const literal = {foo: 123, bar: 'hello', baz: 456};
389
- const someType: SomeType = literal;
390
- const someInterface: SomeInterface = literal;
391
-
392
- declare function fn(object: Record<string, unknown>): void;
393
-
394
- fn(literal); // Good: literal object type is sealed
395
- fn(someType); // Good: type is sealed
396
- // @ts-expect-error
397
- fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
398
- fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
399
- ```
400
-
401
- @link https://github.com/microsoft/TypeScript/issues/15300
402
- @see {@link SimplifyDeep}
403
- @category Object
404
- */
405
- type Simplify<T> = {[KeyType in keyof T]: T[KeyType]} & {};
406
-
407
- /**
408
- Omit any index signatures from the given object type, leaving only explicitly defined properties.
409
-
410
- This is the counterpart of `PickIndexSignature`.
411
-
412
- Use-cases:
413
- - Remove overly permissive signatures from third-party types.
414
-
415
- This type was taken from this [StackOverflow answer](https://stackoverflow.com/a/68261113/420747).
416
-
417
- It relies on the fact that an empty object (`{}`) is assignable to an object with just an index signature, like `Record<string, unknown>`, but not to an object with explicitly defined keys, like `Record<'foo' | 'bar', unknown>`.
418
-
419
- (The actual value type, `unknown`, is irrelevant and could be any type. Only the key type matters.)
420
-
421
- ```
422
- const indexed: Record<string, unknown> = {}; // Allowed
423
-
424
- // @ts-expect-error
425
- const keyed: Record<'foo', unknown> = {}; // Error
426
- // TS2739: Type '{}' is missing the following properties from type 'Record<"foo" | "bar", unknown>': foo, bar
427
- ```
428
-
429
- Instead of causing a type error like the above, you can also use a [conditional type](https://www.typescriptlang.org/docs/handbook/2/conditional-types.html) to test whether a type is assignable to another:
430
-
431
- ```
432
- type Indexed = {} extends Record<string, unknown>
433
- ? '✅ `{}` is assignable to `Record<string, unknown>`'
434
- : '❌ `{}` is NOT assignable to `Record<string, unknown>`';
435
-
436
- type IndexedResult = Indexed;
437
- //=> '✅ `{}` is assignable to `Record<string, unknown>`'
438
-
439
- type Keyed = {} extends Record<'foo' | 'bar', unknown>
440
- ? '✅ `{}` is assignable to `Record<\'foo\' | \'bar\', unknown>`'
441
- : '❌ `{}` is NOT assignable to `Record<\'foo\' | \'bar\', unknown>`';
442
-
443
- type KeyedResult = Keyed;
444
- //=> '❌ `{}` is NOT assignable to `Record<\'foo\' | \'bar\', unknown>`'
445
- ```
446
-
447
- Using a [mapped type](https://www.typescriptlang.org/docs/handbook/2/mapped-types.html#further-exploration), you can then check for each `KeyType` of `ObjectType`...
448
-
449
- ```
450
- type OmitIndexSignature<ObjectType> = {
451
- [KeyType in keyof ObjectType // Map each key of `ObjectType`...
452
- ]: ObjectType[KeyType]; // ...to its original value, i.e. `OmitIndexSignature<Foo> == Foo`.
453
- };
454
- ```
455
-
456
- ...whether an empty object (`{}`) would be assignable to an object with that `KeyType` (`Record<KeyType, unknown>`)...
457
-
458
- ```
459
- type OmitIndexSignature<ObjectType> = {
460
- [KeyType in keyof ObjectType
461
- // Is `{}` assignable to `Record<KeyType, unknown>`?
462
- as {} extends Record<KeyType, unknown>
463
- ? never // ✅ `{}` is assignable to `Record<KeyType, unknown>`
464
- : KeyType // ❌ `{}` is NOT assignable to `Record<KeyType, unknown>`
465
- ]: ObjectType[KeyType];
466
- };
467
- ```
468
-
469
- If `{}` is assignable, it means that `KeyType` is an index signature and we want to remove it. If it is not assignable, `KeyType` is a "real" key and we want to keep it.
470
-
471
- @example
472
- ```
473
- import type {OmitIndexSignature} from 'type-fest';
474
-
475
- type Example = {
476
- // These index signatures will be removed.
477
- [x: string]: any;
478
- [x: number]: any;
479
- [x: symbol]: any;
480
- [x: `head-${string}`]: string;
481
- [x: `${string}-tail`]: string;
482
- [x: `head-${string}-tail`]: string;
483
- [x: `${bigint}`]: string;
484
- [x: `embedded-${number}`]: string;
485
-
486
- // These explicitly defined keys will remain.
487
- foo: 'bar';
488
- qux?: 'baz';
489
- };
490
-
491
- type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
492
- //=> {foo: 'bar'; qux?: 'baz'}
493
- ```
494
-
495
- @see {@link PickIndexSignature}
496
- @category Object
497
- */
498
- type OmitIndexSignature<ObjectType> = {
499
- [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown>
500
- ? never
501
- : KeyType]: ObjectType[KeyType];
502
- };
503
-
504
- /**
505
- Pick only index signatures from the given object type, leaving out all explicitly defined properties.
506
-
507
- This is the counterpart of `OmitIndexSignature`.
508
-
509
- @example
510
- ```
511
- import type {PickIndexSignature} from 'type-fest';
512
-
513
- declare const symbolKey: unique symbol;
514
-
515
- type Example = {
516
- // These index signatures will remain.
517
- [x: string]: unknown;
518
- [x: number]: unknown;
519
- [x: symbol]: unknown;
520
- [x: `head-${string}`]: string;
521
- [x: `${string}-tail`]: string;
522
- [x: `head-${string}-tail`]: string;
523
- [x: `${bigint}`]: string;
524
- [x: `embedded-${number}`]: string;
525
-
526
- // These explicitly defined keys will be removed.
527
- ['kebab-case-key']: string;
528
- [symbolKey]: string;
529
- foo: 'bar';
530
- qux?: 'baz';
531
- };
532
-
533
- type ExampleIndexSignature = PickIndexSignature<Example>;
534
- // {
535
- // [x: string]: unknown;
536
- // [x: number]: unknown;
537
- // [x: symbol]: unknown;
538
- // [x: `head-${string}`]: string;
539
- // [x: `${string}-tail`]: string;
540
- // [x: `head-${string}-tail`]: string;
541
- // [x: `${bigint}`]: string;
542
- // [x: `embedded-${number}`]: string;
543
- // }
544
- ```
545
-
546
- @see {@link OmitIndexSignature}
547
- @category Object
548
- */
549
- type PickIndexSignature<ObjectType> = {
550
- [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown>
551
- ? KeyType
552
- : never]: ObjectType[KeyType];
553
- };
554
-
555
- // Merges two objects without worrying about index signatures.
556
- type SimpleMerge<Destination, Source> = {
557
- [Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key];
558
- } & Source;
559
-
560
- /**
561
- Merge two types into a new type. Keys of the second type overrides keys of the first type.
562
-
563
- @example
564
- ```
565
- import type {Merge} from 'type-fest';
566
-
567
- type Foo = {
568
- [x: string]: unknown;
569
- [x: number]: unknown;
570
- foo: string;
571
- bar: symbol;
572
- };
573
-
574
- type Bar = {
575
- [x: number]: number;
576
- [x: symbol]: unknown;
577
- bar: Date;
578
- baz: boolean;
579
- };
580
-
581
- export type FooBar = Merge<Foo, Bar>;
582
- //=> {
583
- // [x: string]: unknown;
584
- // [x: number]: number;
585
- // [x: symbol]: unknown;
586
- // foo: string;
587
- // bar: Date;
588
- // baz: boolean;
589
- // }
590
- ```
591
-
592
- Note: If you want a merge type that more accurately reflects the runtime behavior of object spread or `Object.assign`, refer to the {@link ObjectMerge} type.
1
+ import { YankiConnectOptions, YankiFetchAdapter, YankiParamsForAction } from "yanki-connect";
2
+ import { PartialDeep, Simplify } from "type-fest";
593
3
 
594
- @see {@link ObjectMerge}
595
- @category Object
596
- */
597
- type Merge<Destination, Source> =
598
- Simplify<
599
- SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>>
600
- & SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>
601
- >;
602
-
603
- /**
604
- Merges user specified options with default options.
605
-
606
- @example
607
- ```
608
- type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
609
- type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
610
- type SpecifiedOptions = {leavesOnly: true};
611
-
612
- type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
613
- //=> {maxRecursionDepth: 10; leavesOnly: true}
614
- ```
615
-
616
- @example
617
- ```
618
- // Complains if default values are not provided for optional options
619
-
620
- type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
621
- type DefaultPathsOptions = {maxRecursionDepth: 10};
622
- type SpecifiedOptions = {};
623
-
624
- type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
625
- // ~~~~~~~~~~~~~~~~~~~
626
- // Property 'leavesOnly' is missing in type 'DefaultPathsOptions' but required in type '{ maxRecursionDepth: number; leavesOnly: boolean; }'.
627
- ```
628
-
629
- @example
630
- ```
631
- // Complains if an option's default type does not conform to the expected type
632
-
633
- type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
634
- type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: 'no'};
635
- type SpecifiedOptions = {};
636
-
637
- type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
638
- // ~~~~~~~~~~~~~~~~~~~
639
- // Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
640
- ```
641
-
642
- @example
643
- ```
644
- // Complains if an option's specified type does not conform to the expected type
645
-
646
- type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
647
- type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
648
- type SpecifiedOptions = {leavesOnly: 'yes'};
649
-
650
- type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
651
- // ~~~~~~~~~~~~~~~~
652
- // Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
653
- ```
654
- */
655
- type ApplyDefaultOptions<
656
- Options extends object,
657
- Defaults extends Simplify<Omit<Required<Options>, RequiredKeysOf<Options>> & Partial<Record<RequiredKeysOf<Options>, never>>>,
658
- SpecifiedOptions extends Options,
659
- > =
660
- If<IsAny<SpecifiedOptions>, Defaults,
661
- If<IsNever<SpecifiedOptions>, Defaults,
662
- Simplify<Merge<Defaults, {
663
- [Key in keyof SpecifiedOptions
664
- as Key extends OptionalKeysOf<Options> ? undefined extends SpecifiedOptions[Key] ? never : Key : Key
665
- ]: SpecifiedOptions[Key]
666
- }> & Required<Options>>>>;
667
-
668
- /**
669
- @see {@link PartialDeep}
670
- */
671
- type PartialDeepOptions = {
672
- /**
673
- Whether to affect the individual elements of arrays and tuples.
674
-
675
- @default false
676
- */
677
- readonly recurseIntoArrays?: boolean;
678
-
679
- /**
680
- Allows `undefined` values in non-tuple arrays.
681
-
682
- - When set to `true`, elements of non-tuple arrays can be `undefined`.
683
- - When set to `false`, only explicitly defined elements are allowed in non-tuple arrays, ensuring stricter type checking.
684
-
685
- @default false
686
-
687
- @example
688
- You can allow `undefined` values in non-tuple arrays by passing `{recurseIntoArrays: true; allowUndefinedInNonTupleArrays: true}` as the second type argument:
689
-
690
- ```
691
- import type {PartialDeep} from 'type-fest';
692
-
693
- type Settings = {
694
- languages: string[];
695
- };
696
-
697
- declare const partialSettings: PartialDeep<Settings, {recurseIntoArrays: true; allowUndefinedInNonTupleArrays: true}>;
698
-
699
- partialSettings.languages = [undefined]; // OK
700
- ```
701
- */
702
- readonly allowUndefinedInNonTupleArrays?: boolean;
703
- };
704
-
705
- type DefaultPartialDeepOptions = {
706
- recurseIntoArrays: false;
707
- allowUndefinedInNonTupleArrays: false;
708
- };
709
-
710
- /**
711
- Create a type from another type with all keys and nested keys set to optional.
712
-
713
- Use-cases:
714
- - Merging a default settings/config object with another object, the second object would be a deep partial of the default object.
715
- - Mocking and testing complex entities, where populating an entire object with its keys would be redundant in terms of the mock or test.
716
-
717
- @example
718
- ```
719
- import type {PartialDeep} from 'type-fest';
720
-
721
- let settings = {
722
- textEditor: {
723
- fontSize: 14,
724
- fontColor: '#000000',
725
- fontWeight: 400,
726
- },
727
- autocomplete: false,
728
- autosave: true,
729
- };
730
-
731
- const applySavedSettings = (savedSettings: PartialDeep<typeof settings>) => (
732
- {...settings, ...savedSettings, textEditor: {...settings.textEditor, ...savedSettings.textEditor}}
733
- );
734
-
735
- settings = applySavedSettings({textEditor: {fontWeight: 500}});
736
- ```
737
-
738
- By default, this does not affect elements in array and tuple types. You can change this by passing `{recurseIntoArrays: true}` as the second type argument:
739
-
740
- ```
741
- import type {PartialDeep} from 'type-fest';
742
-
743
- type Shape = {
744
- dimensions: [number, number];
745
- };
746
-
747
- const partialShape: PartialDeep<Shape, {recurseIntoArrays: true}> = {
748
- dimensions: [], // OK
749
- };
750
-
751
- partialShape.dimensions = [15]; // OK
752
- ```
753
-
754
- @see {@link PartialDeepOptions}
755
-
756
- @category Object
757
- @category Array
758
- @category Set
759
- @category Map
760
- */
761
- type PartialDeep<T, Options extends PartialDeepOptions = {}> =
762
- _PartialDeep<T, ApplyDefaultOptions<PartialDeepOptions, DefaultPartialDeepOptions, Options>>;
763
-
764
- type _PartialDeep<T, Options extends Required<PartialDeepOptions>> = T extends BuiltIns | ((new (...arguments_: any[]) => unknown))
765
- ? T
766
- : T extends Map<infer KeyType, infer ValueType>
767
- ? PartialMapDeep<KeyType, ValueType, Options>
768
- : T extends Set<infer ItemType>
769
- ? PartialSetDeep<ItemType, Options>
770
- : T extends ReadonlyMap<infer KeyType, infer ValueType>
771
- ? PartialReadonlyMapDeep<KeyType, ValueType, Options>
772
- : T extends ReadonlySet<infer ItemType>
773
- ? PartialReadonlySetDeep<ItemType, Options>
774
- : T extends (...arguments_: any[]) => unknown
775
- ? IsNever<keyof T> extends true
776
- ? T // For functions with no properties
777
- : HasMultipleCallSignatures<T> extends true
778
- ? T
779
- : ((...arguments_: Parameters<T>) => ReturnType<T>) & PartialObjectDeep<T, Options>
780
- : T extends object
781
- ? T extends ReadonlyArray<infer ItemType> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
782
- ? Options['recurseIntoArrays'] extends true
783
- ? ItemType[] extends T // Test for arrays (non-tuples) specifically
784
- ? readonly ItemType[] extends T // Differentiate readonly and mutable arrays
785
- ? ReadonlyArray<_PartialDeep<Options['allowUndefinedInNonTupleArrays'] extends false ? ItemType : ItemType | undefined, Options>>
786
- : Array<_PartialDeep<Options['allowUndefinedInNonTupleArrays'] extends false ? ItemType : ItemType | undefined, Options>>
787
- : PartialObjectDeep<T, Options> // Tuples behave properly
788
- : T // If they don't opt into array testing, just use the original type
789
- : PartialObjectDeep<T, Options>
790
- : unknown;
791
-
792
- /**
793
- Same as `PartialDeep`, but accepts only `Map`s and as inputs. Internal helper for `PartialDeep`.
794
- */
795
- type PartialMapDeep<KeyType, ValueType, Options extends Required<PartialDeepOptions>> = {} & Map<_PartialDeep<KeyType, Options>, _PartialDeep<ValueType, Options>>;
796
-
797
- /**
798
- Same as `PartialDeep`, but accepts only `Set`s as inputs. Internal helper for `PartialDeep`.
799
- */
800
- type PartialSetDeep<T, Options extends Required<PartialDeepOptions>> = {} & Set<_PartialDeep<T, Options>>;
801
-
802
- /**
803
- Same as `PartialDeep`, but accepts only `ReadonlyMap`s as inputs. Internal helper for `PartialDeep`.
804
- */
805
- type PartialReadonlyMapDeep<KeyType, ValueType, Options extends Required<PartialDeepOptions>> = {} & ReadonlyMap<_PartialDeep<KeyType, Options>, _PartialDeep<ValueType, Options>>;
806
-
807
- /**
808
- Same as `PartialDeep`, but accepts only `ReadonlySet`s as inputs. Internal helper for `PartialDeep`.
809
- */
810
- type PartialReadonlySetDeep<T, Options extends Required<PartialDeepOptions>> = {} & ReadonlySet<_PartialDeep<T, Options>>;
811
-
812
- /**
813
- Same as `PartialDeep`, but accepts only `object`s as inputs. Internal helper for `PartialDeep`.
814
- */
815
- type PartialObjectDeep<ObjectType extends object, Options extends Required<PartialDeepOptions>> = {
816
- [KeyType in keyof ObjectType]?: _PartialDeep<ObjectType[KeyType], Options>
817
- };
818
-
819
- //#region src/types/deck.d.ts
820
- type DeckStats = {
821
- deck_id: number;
822
- learn_count: number;
823
- name: string;
824
- new_count: number;
825
- review_count: number;
826
- total_in_deck: number;
827
- };
828
- type DeckConfig = {
829
- autoplay: boolean;
830
- dyn: 1 | false;
831
- id: number;
832
- lapse: {
833
- delays: number[];
834
- leechAction: number;
835
- leechFails: number;
836
- minInt: number;
837
- mult: number;
838
- };
839
- maxTaken: number;
840
- mod: number;
841
- name: string;
842
- new: {
843
- bury: boolean;
844
- delays: number[];
845
- initialFactor: number;
846
- ints: number[];
847
- order: number;
848
- perDay: number;
849
- separate: boolean;
850
- };
851
- replayq: boolean;
852
- rev: {
853
- bury: boolean;
854
- ease4: number;
855
- fuzz: number;
856
- ivlFct: number;
857
- maxIvl: number;
858
- minSpace: number;
859
- perDay: number;
860
- };
861
- timer: number;
862
- usn: number;
863
- };
864
- type DeckRequests = Request<'changeDeck', 6, {
865
- cards: number[];
866
- deck: string;
867
- }> | Request<'cloneDeckConfigId', 6, {
868
- cloneFrom: number;
869
- name: string;
870
- }, false | number> | Request<'createDeck', 6, {
871
- deck: string;
872
- }, number> | Request<'deckNames', 6, never, string[]> | Request<'deckNamesAndIds', 6, never, Record<string, number>> | Request<'deleteDecks', 6, {
873
- cardsToo: true;
874
- decks: string[];
875
- }> | Request<'getDeckConfig', 6, {
876
- deck: string;
877
- }, DeckConfig> | Request<'getDecks', 6, Record<'cards', number[]>, Record<string, number[]>> | Request<'getDeckStats', 6, {
878
- decks: string[];
879
- }, Record<string, DeckStats>> | Request<'removeDeckConfigId', 6, {
880
- configId: number;
881
- }, boolean> | Request<'saveDeckConfig', 6, {
882
- config: DeckConfig;
883
- }, boolean> | Request<'setDeckConfigId', 6, {
884
- configId: number;
885
- decks: string[];
886
- }, boolean>;
887
- //#endregion
888
- //#region src/types/note.d.ts
889
- type NoteModel = 'Basic' | 'Basic (and reversed card)' | 'Basic (type in the answer)' | 'Cloze' | (string & {});
890
- type NoteMedia = {
891
- data?: string;
892
- fields?: string[];
893
- filename: string;
894
- path?: string;
895
- skipHash?: string;
896
- url?: string;
897
- };
898
- type Note = {
899
- audio?: NoteMedia[];
900
- deckName: string;
901
- fields: Record<string, string>;
902
- modelName: NoteModel;
903
- picture?: NoteMedia[];
904
- tags?: string[];
905
- video?: NoteMedia[];
906
- };
907
- type NoteWithCreationOptions = Note & {
908
- options?: {
909
- allowDuplicate?: boolean;
910
- duplicateScope?: 'deck' | (string & {});
911
- duplicateScopeOptions?: {
912
- checkAllModels?: boolean;
913
- checkChildren?: boolean;
914
- deckName?: null | string;
915
- };
916
- };
917
- };
918
- type NoteRequests = Request<'addNote', 6, {
919
- note: NoteWithCreationOptions;
920
- }, null | number> | Request<'addNotes', 6, {
921
- notes: NoteWithCreationOptions[];
922
- }, Array<null | string> | null> | Request<'addTags', 6, {
923
- notes: number[];
924
- tags: string;
925
- }> | Request<'canAddNotes', 6, {
926
- notes: NoteWithCreationOptions[];
927
- }, boolean[]> | Request<'canAddNotesWithErrorDetail', 6, {
928
- notes: NoteWithCreationOptions[];
929
- }, Array<{
930
- canAdd: false;
931
- error: string;
932
- } | {
933
- canAdd: true;
934
- }>> | Request<'clearUnusedTags', 6, never, string[]> | Request<'deleteNotes', 6, {
935
- notes: number[];
936
- }> | Request<'findNotes', 6, {
937
- query: string;
938
- }, number[]> | Request<'getNoteTags', 6, {
939
- note: number;
940
- }, string[]> | Request<'getTags', 6, never, string[]> | Request<'notesInfo', 6, {
941
- notes: number[];
942
- }, Array<{
943
- cards: number[];
944
- fields: Record<string, {
945
- order: number;
946
- value: string;
947
- }>;
948
- mod: number;
949
- modelName: string;
950
- noteId: number;
951
- profile: string;
952
- tags: string[];
953
- }>> | Request<'notesModTime', 6, {
954
- notes: number[];
955
- }, Array<{
956
- mod: number;
957
- noteId: number;
958
- }>> | Request<'removeEmptyNotes', 6> | Request<'removeTags', 6, {
959
- notes: number[];
960
- tags: string;
961
- }> | Request<'replaceTags', 6, {
962
- notes: number[];
963
- replace_with_tag: string;
964
- tag_to_replace: string;
965
- }> | Request<'replaceTagsInAllNotes', 6, {
966
- replace_with_tag: string;
967
- tag_to_replace: string;
968
- }> | Request<'updateNote', 6, {
969
- note: {
970
- audio?: NoteMedia[];
971
- fields: Record<string, string>;
972
- id: number;
973
- picture?: NoteMedia[];
974
- tags?: string[];
975
- video?: NoteMedia[];
976
- } | {
977
- fields?: Record<string, string>;
978
- id: number;
979
- tags: string[];
980
- };
981
- }> | Request<'updateNoteFields', 6, {
982
- note: {
983
- audio?: NoteMedia[];
984
- fields: Record<string, string>;
985
- id: number;
986
- picture?: NoteMedia[];
987
- video?: NoteMedia[];
988
- };
989
- }> | Request<'updateNoteModel', 6, {
990
- note: {
991
- fields: Record<string, string>;
992
- id: number;
993
- modelName: string;
994
- tags: string[];
995
- };
996
- }> | Request<'updateNoteTags', 6, {
997
- note: number;
998
- tags: string[];
999
- }>;
1000
- //#endregion
1001
- //#region src/types/graphical.d.ts
1002
- type GraphicalRequests = Request<'guiAddCards', 6, {
1003
- note: Note;
1004
- }, number> | Request<'guiAnswerCard', 6, {
1005
- ease: number;
1006
- }, boolean> | Request<'guiBrowse', 6, {
1007
- query: string;
1008
- reorderCards?: {
1009
- columnId: CardBrowserColumns;
1010
- order: 'ascending' | 'descending';
1011
- };
1012
- }, number[]> | Request<'guiCheckDatabase', 6, never, true> | Request<'guiCurrentCard', 6, never, CardInfo | null> | Request<'guiDeckBrowser', 6> | Request<'guiDeckOverview', 6, {
1013
- name: string;
1014
- }, boolean> | Request<'guiDeckReview', 6, {
1015
- name: string;
1016
- }, boolean> | Request<'guiEditNote', 6, {
1017
- note: number;
1018
- }> | Request<'guiExitAnki', 6> | Request<'guiImportFile', 6, {
1019
- path: string;
1020
- }> | Request<'guiPlayAudio', 6, never, true> | Request<'guiSelectCard', 6, {
1021
- card: number;
1022
- }, boolean> | Request<'guiSelectedNotes', 6, never, number[]> | Request<'guiSelectNote', 6, {
1023
- note: number;
1024
- }, boolean> | Request<'guiShowAnswer', 6, never, boolean> | Request<'guiShowQuestion', 6, never, boolean> | Request<'guiStartCardTimer', 6, never, true> | Request<'guiUndo', 6, never, boolean>;
1025
- //#endregion
1026
- //#region src/types/media.d.ts
1027
- type MediaRequests = Request<'deleteMediaFile', 6, {
1028
- filename: string;
1029
- }> | Request<'getMediaDirPath', 6, never, string> | Request<'getMediaFilesNames', 6, {
1030
- pattern: string;
1031
- }, string[]> | Request<'retrieveMediaFile', 6, {
1032
- filename: string;
1033
- }, false | string> | Request<'storeMediaFile', 6, {
1034
- data?: string;
1035
- deleteExisting?: boolean;
1036
- filename: string;
1037
- path?: string;
1038
- url?: string;
1039
- }, string>;
1040
- //#endregion
1041
- //#region src/types/miscellaneous.d.ts
1042
- type MiscellaneousRequests = Request<'apiReflect', 6, {
1043
- actions: null | string[];
1044
- scopes: Array<'actions'>;
4
+ //#region src/lib/model/model.d.ts
5
+ declare const yankiModels: [{
6
+ readonly cardTemplates: [{
7
+ readonly Back: "{{FrontSide}}\n\n<hr id=answer>\n\n{{Back}}";
8
+ readonly Front: "{{Front}}";
9
+ readonly YankiNamespace: "{{YankiNamespace}}";
10
+ }];
11
+ readonly inOrderFields: ["Front", "Back", "YankiNamespace"];
12
+ readonly modelName: "Yanki - Basic";
1045
13
  }, {
1046
- actions: string[];
1047
- scopes: string[];
1048
- }> | Request<'exportPackage', 6, {
1049
- deck: string;
1050
- includeSched?: boolean;
1051
- path: string;
1052
- }, boolean> | Request<'getActiveProfile', 6, never, string> | Request<'getProfiles', 6, never, string[]> | Request<'importPackage', 6, {
1053
- path: string;
1054
- }, boolean> | Request<'loadProfile', 6, {
1055
- name: string;
1056
- }, true> | Request<'multi', 6,
1057
- // Crazy, have to call this experimental
1058
- {
1059
- actions: Array<{
1060
- action: Requests['action'];
1061
- params?: Requests['params'];
1062
- version?: number;
1063
- }>;
1064
- }, Array<Requests['response'] | {
1065
- error: null | string;
1066
- result: Requests['response'];
1067
- }>> | Request<'reloadCollection', 6> | Request<'requestPermission', 6, never, {
1068
- permission: 'denied';
1069
- } | {
1070
- permission: 'granted';
1071
- requireApiKey: boolean;
1072
- version: boolean;
1073
- }> | Request<'sync', 6> | Request<'version', 6, never, number>;
1074
- //#endregion
1075
- //#region src/types/model.d.ts
1076
- type ModelField = {
1077
- collapsed: boolean;
1078
- description: string;
1079
- excludeFromSearch: boolean;
1080
- font: string;
1081
- id: number;
1082
- name: string;
1083
- ord: number;
1084
- plainText: boolean;
1085
- preventDeletion: boolean;
1086
- rtl: boolean;
1087
- size: number;
1088
- sticky: boolean;
1089
- tag: null;
1090
- };
1091
- type ModelTemplate = {
1092
- afmt: string;
1093
- bafmt: string;
1094
- bfont: string;
1095
- bqfmt: string;
1096
- bsize: number;
1097
- did: null;
1098
- id: number;
1099
- name: string;
1100
- ord: number;
1101
- qfmt: string;
1102
- };
1103
- type Model = {
1104
- css: string;
1105
- did: null;
1106
- flds: ModelField[];
1107
- id: number;
1108
- latexPost: string;
1109
- latexPre: string;
1110
- latexsvg: boolean;
1111
- mod: number;
1112
- name: string;
1113
- originalStockKind: number;
1114
- req: Array<[number, string, number[]]>;
1115
- sortf: number;
1116
- tmpls: ModelTemplate[];
1117
- type: number;
1118
- usn: number;
1119
- };
1120
- type ModelToCreate = {
1121
- cardTemplates: Array<{
1122
- [key: string]: string;
1123
- Back: string;
1124
- Front: string;
1125
- }>;
1126
- css?: string;
1127
- inOrderFields: string[];
1128
- isCloze?: boolean;
1129
- modelName: string;
1130
- };
1131
- type ModelRequests = Request<'createModel', 6, ModelToCreate, Model> | Request<'findAndReplaceInModels', 6, {
1132
- model: {
1133
- back: boolean;
1134
- css: boolean;
1135
- fieldText: string;
1136
- front: boolean;
1137
- modelName: string;
1138
- replaceText: string;
1139
- };
1140
- }, number> | Request<'findModelsById', 6, {
1141
- modelIds: number[];
1142
- }, Model[]> | Request<'findModelsByName', 6, {
1143
- modelNames: string[];
1144
- }, Model[]> | Request<'modelFieldAdd', 6, {
1145
- fieldName: string;
1146
- index: number;
1147
- modelName: string;
1148
- }> | Request<'modelFieldDescriptions', 6, {
1149
- description: string;
1150
- fieldName: string;
1151
- modelName: string;
1152
- }, boolean> | Request<'modelFieldFonts', 6, {
1153
- modelName: string;
1154
- }, Record<string, {
1155
- font: string;
1156
- size: number;
1157
- }>> | Request<'modelFieldNames', 6, {
1158
- modelName: string;
1159
- }, string[]> | Request<'modelFieldRemove', 6, {
1160
- fieldName: string;
1161
- modelName: string;
1162
- }> | Request<'modelFieldRename', 6, {
1163
- modelName: string;
1164
- newFieldName: string;
1165
- oldFieldName: string;
1166
- }> | Request<'modelFieldReposition', 6, {
1167
- fieldName: string;
1168
- index: number;
1169
- modelName: string;
1170
- }> | Request<'modelFieldSetDescription', 6, {
1171
- fieldName: string;
1172
- index: number;
1173
- modelName: string;
1174
- }> | Request<'modelFieldSetFont', 6, {
1175
- fieldName: string;
1176
- font: string;
1177
- modelName: string;
1178
- }> | Request<'modelFieldSetFontSize', 6, {
1179
- fieldName: string;
1180
- fontSize: number;
1181
- modelName: string;
1182
- }> | Request<'modelFieldsOnTemplates', 6, {
1183
- modelName: string;
1184
- }, Record<string, [string[], string[]]>> | Request<'modelNames', 6, never, string[]> | Request<'modelNamesAndIds', 6, never, Record<string, number>> | Request<'modelStyling', 6, {
1185
- modelName: string;
14
+ readonly cardTemplates: [{
15
+ readonly Back: "{{cloze:Front}}<br>\n{{Back}}";
16
+ readonly Front: "{{cloze:Front}}";
17
+ readonly YankiNamespace: "{{YankiNamespace}}";
18
+ }];
19
+ readonly inOrderFields: ["Front", "Back", "YankiNamespace"];
20
+ readonly isCloze: true;
21
+ readonly modelName: "Yanki - Cloze";
1186
22
  }, {
1187
- css: string;
1188
- }> | Request<'modelTemplateAdd', 6, {
1189
- modelName: string;
1190
- template: {
1191
- [key: string]: string;
23
+ readonly cardTemplates: [{
24
+ readonly Back: "{{Front}}\n\n<hr id=answer>\n\n{{type:Back}}";
25
+ readonly Front: "{{Front}}\n\n{{type:Back}}";
26
+ readonly YankiNamespace: "{{YankiNamespace}}";
27
+ }];
28
+ readonly inOrderFields: ["Front", "Back", "YankiNamespace"];
29
+ readonly modelName: "Yanki - Basic (type in the answer)";
30
+ }, {
31
+ readonly cardTemplates: [{
32
+ readonly Back: "{{FrontSide}}\n\n<hr id=answer>\n\n{{Back}}{{#Extra}}\n\n<hr>\n\n{{Extra}}{{/Extra}}";
33
+ readonly Front: "{{Front}}";
34
+ readonly YankiNamespace: "{{YankiNamespace}}";
35
+ }, {
36
+ readonly Back: "{{FrontSide}}\n\n<hr id=answer>\n\n{{Front}}{{#Extra}}\n\n<hr>\n\n{{Extra}}{{/Extra}}";
37
+ readonly Front: "{{Back}}";
38
+ readonly YankiNamespace: "{{YankiNamespace}}";
39
+ }];
40
+ readonly inOrderFields: ["Front", "Back", "Extra", "YankiNamespace"];
41
+ readonly modelName: "Yanki - Basic (and reversed card with extra)";
42
+ }];
43
+ type YankiModelName = (typeof yankiModels)[number]['modelName'];
44
+ //#endregion
45
+ //#region src/lib/model/note.d.ts
46
+ type YankiNote = Simplify<Omit<YankiParamsForAction<'addNote'>['note'], 'fields' | 'modelName' | 'options'> & {
47
+ cards?: number[];
48
+ fields: {
1192
49
  Back: string;
50
+ Extra?: string;
1193
51
  Front: string;
52
+ YankiNamespace: string;
1194
53
  };
1195
- }> | Request<'modelTemplateRemove', 6, {
1196
- modelName: string;
1197
- templateName: string;
1198
- }> | Request<'modelTemplateRename', 6, {
1199
- modelName: string;
1200
- newTemplateName: string;
1201
- oldTemplateName: string;
1202
- }> | Request<'modelTemplateReposition', 6, {
1203
- index: number;
1204
- modelName: string;
1205
- templateName: string;
1206
- }> | Request<'modelTemplates', 6, {
1207
- modelName: string;
1208
- }, Record<string, {
1209
- [key: string]: string;
1210
- Back: string;
1211
- Front: string;
1212
- }>> | Request<'updateModelStyling', 6, {
1213
- model: {
1214
- css: string;
1215
- name: string;
1216
- };
1217
- }> | Request<'updateModelTemplates', 6, {
1218
- model: {
1219
- name: string;
1220
- templates: Record<string, {
1221
- Back?: string;
1222
- Front?: string;
1223
- }>;
1224
- };
1225
- }>;
1226
- //#endregion
1227
- //#region src/types/statistic.d.ts
1228
- type ReviewStatisticTuple = [reviewTime: number, cardID: number, usn: number, buttonPressed: number, newInterval: number, previousInterval: number, newFactor: number, reviewDuration: number, reviewType: number];
1229
- type StatisticRequests = Request<'cardReviews', 6, {
1230
- deck: string;
1231
- startID: number;
1232
- }, ReviewStatisticTuple[]> | Request<'getCollectionStatsHTML', 6, {
1233
- wholeCollection: boolean;
1234
- }, string> | Request<'getLatestReviewID', 6, {
1235
- deck: string;
1236
- }, number> | Request<'getNumCardsReviewedByDay', 6, never, Array<[string, number]>> | Request<'getNumCardsReviewedToday', 6, never, number> | Request<'getReviewsOfCards', 6, {
1237
- cards: string[];
1238
- }, Record<string, Array<{
1239
- /** ButtonPressed */
1240
- ease: number;
1241
- /** NewFactor */
1242
- factor: number;
1243
- /** ReviewTime */
1244
- id: number;
1245
- /** NewInterval */
1246
- ivl: number;
1247
- /** PreviousInterval */
1248
- lastIvl: number;
1249
- /** ReviewDuration */
1250
- time: number;
1251
- /** ReviewType */
1252
- type: number;
1253
- /** Usn */
1254
- usn: number;
1255
- }>>> | Request<'insertReviews', 6, {
1256
- reviews: ReviewStatisticTuple[];
54
+ modelName: YankiModelName;
55
+ noteId: number | undefined;
1257
56
  }>;
1258
57
  //#endregion
1259
- //#region src/types/shared.d.ts
1260
- /**
1261
- * Abstract wrapper over an Anki Connect action / response
1262
- */
1263
- type Request<Action extends string, Version extends AnkiConnectVersion, Params = never, Result = null> = {
1264
- action: Action;
1265
- params: Params;
1266
- response: {
1267
- error: null | string;
1268
- result: Result;
1269
- };
1270
- version: Version;
1271
- };
1272
- /**
1273
- * Requests
1274
- */
1275
- type Requests = CardRequests | DeckRequests | GraphicalRequests | MediaRequests | MiscellaneousRequests | ModelRequests | NoteRequests | StatisticRequests;
1276
- type AnkiConnectVersion = 6;
1277
- type ParamsForAction<T extends Requests['action']> = Extract<Requests, {
1278
- action: T;
1279
- }>['params'];
1280
- //#endregion
1281
- //#region src/types/card.d.ts
1282
- type CardBrowserColumns = 'answer' | 'cardDue' | 'cardEase' | 'cardIvl' | 'cardLapses' | 'cardMod' | 'cardReps' | 'deck' | 'note' | 'noteCrt' | 'noteFld' | 'noteMod' | 'noteTags' | 'question' | 'template' | (string & {});
1283
- type CardValueKeys = 'data' | 'did' | 'due' | 'factor' | 'flags' | 'id' | 'ivl' | 'lapses' | 'left' | 'mod' | 'odid' | 'odue' | 'ord' | 'queue' | 'reps' | 'type' | 'usn';
1284
- type CardInfo = {
1285
- answer: string;
1286
- buttons?: number[];
1287
- cardId: number;
1288
- css: string;
1289
- deckName: string;
1290
- due: number;
1291
- fieldOrder: number;
1292
- fields: Record<string, {
1293
- order: number;
1294
- value: string;
58
+ //#region src/lib/shared/types.d.ts
59
+ type FetchAdapter = YankiFetchAdapter;
60
+ type ManageFilenames = 'off' | 'prompt' | 'response';
61
+ type SyncMediaAssets = 'all' | 'local' | 'off' | 'remote';
62
+ type FileAdapter = {
63
+ readFile(filePath: string): Promise<string>;
64
+ readFileBuffer(filePath: string): Promise<Uint8Array>;
65
+ rename(oldPath: string, newPath: string): Promise<void>;
66
+ stat(filePath: string): Promise<{
67
+ ctimeMs: number;
68
+ mtimeMs: number;
69
+ size: number;
1295
70
  }>;
1296
- interval: number;
1297
- lapses: number;
1298
- left: number;
1299
- mod: number;
1300
- modelName: string;
1301
- nextReviews: string[];
1302
- note: number;
1303
- ord: number;
1304
- question: string;
1305
- queue: number;
1306
- reps: number;
1307
- template: string;
1308
- type: number;
71
+ writeFile(filePath: string, data: string): Promise<void>;
1309
72
  };
1310
- type CardRequests = Request<'answerCards', 6, {
1311
- answers: Array<{
1312
- cardId: number;
1313
- ease: number;
1314
- }>;
1315
- }, boolean[]> | Request<'areDue', 6, {
1316
- cards: number[];
1317
- }, boolean[]> | Request<'areSuspended', 6, {
1318
- cards: number[];
1319
- }, Array<boolean | null>> | Request<'cardsInfo', 6, {
1320
- cards: number[];
1321
- }, CardInfo[]> | Request<'cardsModTime', 6, {
1322
- cards: number[];
1323
- }, {
1324
- cardId: number;
1325
- mod: number;
1326
- }> | Request<'cardsToNotes', 6, {
1327
- cards: number[];
1328
- }, number[]> | Request<'findCards', 6, {
1329
- query: string;
1330
- }, number[]> | Request<'forgetCards', 6, {
1331
- cards: number[];
1332
- }> | Request<'getEaseFactors', 6, {
1333
- cards: number[];
1334
- }, number[]> | Request<'getIntervals', 6, {
1335
- cards: number[];
1336
- complete?: boolean;
1337
- }, number[] | number[][]> | Request<'relearnCards', 6, {
1338
- cards: number[];
1339
- }> | Request<'setDueDate', 6, {
1340
- cards: number[];
1341
- days: string;
1342
- }, boolean> | Request<'setEaseFactors', 6, {
1343
- cards: number[];
1344
- easeFactors: number[];
1345
- }, boolean[]> | Request<'setSpecificValueOfCard', 6, {
1346
- card: number;
1347
- keys: CardValueKeys[];
1348
- newValues: string[];
1349
- }, boolean[]> | Request<'suspend', 6, {
1350
- cards: number[];
1351
- }, boolean> | Request<'suspended', 6, {
1352
- card: number;
1353
- }, boolean> | Request<'unsuspend', 6, {
1354
- cards: number[];
1355
- }, boolean>;
1356
- //#endregion
1357
- //#region src/client.d.ts
1358
- /**
1359
- * Subset of built-in Fetch interface that's actually used by Anki, for ease of
1360
- * external re-implementation when passing a custom fetch function to
1361
- * YankiClient.
1362
- */
1363
- type YankiFetchAdapter = (input: string, init?: {
1364
- body?: string;
1365
- headers?: Record<string, string>;
1366
- method?: string;
1367
- mode?: RequestMode;
1368
- }) => Promise<undefined | {
1369
- headers: Headers | Record<string, string>;
1370
- json(): Promise<any>;
1371
- status: number;
1372
- }>;
1373
- /** Optional options to pass when instantiating a new YankiConnect instance. */
1374
- type YankiConnectOptions = {
1375
- /**
1376
- * Attempt to open the desktop Anki.app if it's not already running.
1377
- *
1378
- * - `true` will always attempt to open Anki _when a request is made_. This
1379
- * might introduce significant latency on the first launch.
1380
- * - `false` will never attempt to open Anki. Requests will fail until
1381
- * something or someone else opens the Anki app.
1382
- * - `immediately` is a special option that will open Anki when the client is
1383
- * instantiated.
1384
- *
1385
- * The Anki desktop app must be running for the client and the underlying
1386
- * Anki-Connect service to work.
1387
- *
1388
- * Currently supported on macOS only.
1389
- *
1390
- * The client does not attempt to close the app.
1391
- * @default false
1392
- */
1393
- autoLaunch: 'immediately' | boolean;
1394
- /**
1395
- * Advanced option to customize the resource fetch implementation used to make requests to Anki-Connect.
1396
- *
1397
- * Note that the signature reflects the subset of the built-in Fetch interface that's actually used by yanki-connect.
1398
- *
1399
- * The exact signature of this option is subject to change in the future.
1400
- * @default fetch
1401
- */
1402
- fetchAdapter: undefined | YankiFetchAdapter;
73
+ type GlobalOptions = {
1403
74
  /**
1404
- * Host where the Anki-Connect service is running.
1405
- * @default 'http://127.0.0.1'
75
+ * Used for wiki link resolution
1406
76
  */
1407
- host: string;
77
+ allFilePaths: string[];
78
+ ankiConnectOptions: YankiConnectOptions;
1408
79
  /**
1409
- * Anki-Connect security key (optional)
1410
- * @default undefined
80
+ * Automatically sync any changes to AnkiWeb after Yanki has finished syncing
81
+ * locally. If false, only local Anki data is updated and you must manually
82
+ * invoke a sync to AnkiWeb. This is the equivalent of pushing the "sync"
83
+ * button in the Anki app.
1411
84
  */
1412
- key: string | undefined;
85
+ ankiWeb: boolean; /** Override where "/" should resolve to... useful in Obsidian to set the vault path as the "root" */
86
+ basePath: string | undefined; /** Run Anki's "Check Database" command after sync updates that might produce card corruption */
87
+ checkDatabase: boolean;
88
+ cwd: string;
89
+ dryRun: boolean;
1413
90
  /**
1414
- * Port where the Anki-Connect service is running.
1415
- * @default 8765
91
+ * Exposed for Obsidian, currently only used for getting URL content hashes
92
+ * and inferring MIME types of URLs without extensions.
93
+ * Note that ankiConnectOptions ALSO has a fetch adapter option specifically
94
+ * for communicating with Anki-Connect.
1416
95
  */
1417
- port: number;
96
+ fetchAdapter: FetchAdapter | undefined;
97
+ fileAdapter: FileAdapter | undefined;
98
+ manageFilenames: ManageFilenames; /** Only applies if manageFilenames is `true`. Will _not_ truncate user-specified file names in other cases. */
99
+ maxFilenameLength: number;
100
+ namespace: string; /** Ensures that wiki-style links work correctly */
101
+ obsidianVault: string | undefined; /** Exposed for testing only */
102
+ resolveUrls: boolean;
1418
103
  /**
1419
- * Anki-Connect API version.
1420
- *
1421
- * Only API version 6 is supported for now.
1422
- * @default 6
104
+ * Whether to treat single newlines in Markdown as line breaks in the
105
+ * resulting HTML (Obsidian has an application-level setting for this)
1423
106
  */
1424
- version: AnkiConnectVersion;
107
+ strictLineBreaks: boolean; /** Only consider exact noteId matches between the local and remote copies to be equivalent, don't match local notes with "orphaned" remote notes based on content */
108
+ strictMatching: boolean; /** Sync image, video, and audio assets to Anki's media storage system */
109
+ syncMediaAssets: SyncMediaAssets;
1425
110
  };
1426
-
1427
- declare const yankiModels: [{
1428
- readonly cardTemplates: [{
1429
- readonly Back: "{{FrontSide}}\n\n<hr id=answer>\n\n{{Back}}";
1430
- readonly Front: "{{Front}}";
1431
- readonly YankiNamespace: "{{YankiNamespace}}";
1432
- }];
1433
- readonly inOrderFields: ["Front", "Back", "YankiNamespace"];
1434
- readonly modelName: "Yanki - Basic";
1435
- }, {
1436
- readonly cardTemplates: [{
1437
- readonly Back: "{{cloze:Front}}<br>\n{{Back}}";
1438
- readonly Front: "{{cloze:Front}}";
1439
- readonly YankiNamespace: "{{YankiNamespace}}";
1440
- }];
1441
- readonly inOrderFields: ["Front", "Back", "YankiNamespace"];
1442
- readonly isCloze: true;
1443
- readonly modelName: "Yanki - Cloze";
1444
- }, {
1445
- readonly cardTemplates: [{
1446
- readonly Back: "{{Front}}\n\n<hr id=answer>\n\n{{type:Back}}";
1447
- readonly Front: "{{Front}}\n\n{{type:Back}}";
1448
- readonly YankiNamespace: "{{YankiNamespace}}";
1449
- }];
1450
- readonly inOrderFields: ["Front", "Back", "YankiNamespace"];
1451
- readonly modelName: "Yanki - Basic (type in the answer)";
1452
- }, {
1453
- readonly cardTemplates: [{
1454
- readonly Back: "{{FrontSide}}\n\n<hr id=answer>\n\n{{Back}}{{#Extra}}\n\n<hr>\n\n{{Extra}}{{/Extra}}";
1455
- readonly Front: "{{Front}}";
1456
- readonly YankiNamespace: "{{YankiNamespace}}";
1457
- }, {
1458
- readonly Back: "{{FrontSide}}\n\n<hr id=answer>\n\n{{Front}}{{#Extra}}\n\n<hr>\n\n{{Extra}}{{/Extra}}";
1459
- readonly Front: "{{Back}}";
1460
- readonly YankiNamespace: "{{YankiNamespace}}";
1461
- }];
1462
- readonly inOrderFields: ["Front", "Back", "Extra", "YankiNamespace"];
1463
- readonly modelName: "Yanki - Basic (and reversed card with extra)";
1464
- }];
1465
- type YankiModelName = (typeof yankiModels)[number]['modelName'];
1466
-
1467
- type YankiNote = Simplify<Omit<ParamsForAction<'addNote'>['note'], 'fields' | 'modelName' | 'options'> & {
1468
- cards?: number[];
1469
- fields: {
1470
- Back: string;
1471
- Extra?: string;
1472
- Front: string;
1473
- YankiNamespace: string;
1474
- };
1475
- modelName: YankiModelName;
1476
- noteId: number | undefined;
1477
- }>;
1478
-
1479
- type FetchAdapter = YankiFetchAdapter;
1480
- type ManageFilenames = 'off' | 'prompt' | 'response';
1481
- type SyncMediaAssets = 'all' | 'local' | 'off' | 'remote';
1482
- type FileAdapter = {
1483
- readFile(filePath: string): Promise<string>;
1484
- readFileBuffer(filePath: string): Promise<Uint8Array>;
1485
- rename(oldPath: string, newPath: string): Promise<void>;
1486
- stat(filePath: string): Promise<{
1487
- ctimeMs: number;
1488
- mtimeMs: number;
1489
- size: number;
1490
- }>;
1491
- writeFile(filePath: string, data: string): Promise<void>;
1492
- };
1493
- type GlobalOptions = {
1494
- /**
1495
- * Used for wiki link resolution
1496
- */
1497
- allFilePaths: string[];
1498
- ankiConnectOptions: YankiConnectOptions;
1499
- /**
1500
- * Automatically sync any changes to AnkiWeb after Yanki has finished syncing
1501
- * locally. If false, only local Anki data is updated and you must manually
1502
- * invoke a sync to AnkiWeb. This is the equivalent of pushing the "sync"
1503
- * button in the Anki app.
1504
- */
1505
- ankiWeb: boolean;
1506
- /** Override where "/" should resolve to... useful in Obsidian to set the vault path as the "root" */
1507
- basePath: string | undefined;
1508
- /** Run Anki's "Check Database" command after sync updates that might produce card corruption */
1509
- checkDatabase: boolean;
1510
- cwd: string;
1511
- dryRun: boolean;
1512
- /**
1513
- * Exposed for Obsidian, currently only used for getting URL content hashes
1514
- * and inferring MIME types of URLs without extensions.
1515
- * Note that ankiConnectOptions ALSO has a fetch adapter option specifically
1516
- * for communicating with Anki-Connect.
1517
- */
1518
- fetchAdapter: FetchAdapter | undefined;
1519
- fileAdapter: FileAdapter | undefined;
1520
- manageFilenames: ManageFilenames;
1521
- /** Only applies if manageFilenames is `true`. Will _not_ truncate user-specified file names in other cases. */
1522
- maxFilenameLength: number;
1523
- namespace: string;
1524
- /** Ensures that wiki-style links work correctly */
1525
- obsidianVault: string | undefined;
1526
- /** Exposed for testing only */
1527
- resolveUrls: boolean;
1528
- /**
1529
- * Whether to treat single newlines in Markdown as line breaks in the
1530
- * resulting HTML (Obsidian has an application-level setting for this)
1531
- */
1532
- strictLineBreaks: boolean;
1533
- /** Only consider exact noteId matches between the local and remote copies to be equivalent, don't match local notes with "orphaned" remote notes based on content */
1534
- strictMatching: boolean;
1535
- /** Sync image, video, and audio assets to Anki's media storage system */
1536
- syncMediaAssets: SyncMediaAssets;
1537
- };
1538
-
111
+ //#endregion
112
+ //#region src/lib/actions/clean.d.ts
1539
113
  type CleanOptions = Pick<GlobalOptions, 'ankiConnectOptions' | 'ankiWeb' | 'dryRun' | 'namespace'>;
1540
114
  declare const defaultCleanOptions: CleanOptions;
1541
115
  type CleanResult = Simplify<Pick<GlobalOptions, 'ankiWeb' | 'dryRun' | 'namespace'> & {
1542
- deletedDecks: string[];
1543
- deletedMedia: string[];
1544
- deletedNotes: YankiNote[];
1545
- duration: number;
116
+ deletedDecks: string[];
117
+ deletedMedia: string[];
118
+ deletedNotes: YankiNote[];
119
+ duration: number;
1546
120
  }>;
1547
121
  /**
1548
122
  * Deletes all remote notes in Anki associated with the given namespace.
@@ -1553,34 +127,35 @@ type CleanResult = Simplify<Pick<GlobalOptions, 'ankiWeb' | 'dryRun' | 'namespac
1553
127
  */
1554
128
  declare function cleanNotes(options?: PartialDeep<CleanOptions>): Promise<CleanResult>;
1555
129
  declare function formatCleanResult(result: CleanResult, verbose?: boolean): string;
1556
-
130
+ //#endregion
131
+ //#region src/lib/actions/list.d.ts
1557
132
  type ListOptions = Pick<GlobalOptions, 'ankiConnectOptions' | 'namespace'>;
1558
133
  declare const defaultListOptions: ListOptions;
1559
134
  type ListResult = {
1560
- duration: number;
1561
- namespace: string;
1562
- notes: YankiNote[];
135
+ duration: number;
136
+ namespace: string;
137
+ notes: YankiNote[];
1563
138
  };
1564
139
  /**
1565
140
  * Description List notes currently in Anki...
1566
141
  */
1567
142
  declare function listNotes(options?: PartialDeep<ListOptions>): Promise<ListResult>;
1568
143
  declare function formatListResult(result: ListResult): string;
1569
-
144
+ //#endregion
145
+ //#region src/lib/actions/load-local-notes.d.ts
1570
146
  type LoadOptions = Pick<GlobalOptions, 'allFilePaths' | 'basePath' | 'fetchAdapter' | 'fileAdapter' | 'namespace' | 'obsidianVault' | 'strictLineBreaks' | 'syncMediaAssets'>;
1571
147
  type LocalNote = {
1572
- filePath: string;
1573
- filePathOriginal: string;
1574
- markdown: string;
1575
- note: YankiNote;
148
+ filePath: string;
149
+ filePathOriginal: string;
150
+ markdown: string;
151
+ note: YankiNote;
1576
152
  };
1577
-
1578
- type RenameNotesOptions = Pick<GlobalOptions, 'dryRun' | 'fileAdapter' | 'manageFilenames' | 'maxFilenameLength'
1579
- /** Included because this can technically change the content of the "first line" of a card */
1580
- | 'strictLineBreaks'>;
153
+ //#endregion
154
+ //#region src/lib/actions/rename.d.ts
155
+ type RenameNotesOptions = Pick<GlobalOptions, 'dryRun' | 'fileAdapter' | 'manageFilenames' | 'maxFilenameLength' /** Included because this can technically change the content of the "first line" of a card */ | 'strictLineBreaks'>;
1581
156
  type RenameFilesResult = {
1582
- dryRun: boolean;
1583
- notes: LocalNote[];
157
+ dryRun: boolean;
158
+ notes: LocalNote[];
1584
159
  };
1585
160
  type RenameFilesOptions = Simplify<LoadOptions & RenameNotesOptions>;
1586
161
  declare const defaultRenameFilesOptions: RenameFilesOptions;
@@ -1588,36 +163,38 @@ declare const defaultRenameFilesOptions: RenameFilesOptions;
1588
163
  * Currently used for testing and by `yanki-obsidian`.
1589
164
  */
1590
165
  declare function renameFiles(allLocalFilePaths: string[], options: Partial<RenameFilesOptions>): Promise<RenameFilesResult>;
1591
-
166
+ //#endregion
167
+ //#region src/lib/actions/style.d.ts
1592
168
  type SetStyleOptions = Pick<GlobalOptions, 'ankiConnectOptions' | 'ankiWeb' | 'dryRun'> & {
1593
- css: string;
169
+ css: string;
1594
170
  };
1595
171
  declare const defaultSetStyleOptions: SetStyleOptions;
1596
172
  type SetStyleResult = Simplify<Pick<GlobalOptions, 'ankiWeb' | 'dryRun'> & {
1597
- duration: number;
1598
- models: Array<{
1599
- action: 'unchanged' | 'updated';
1600
- name: string;
1601
- }>;
173
+ duration: number;
174
+ models: Array<{
175
+ action: 'unchanged' | 'updated';
176
+ name: string;
177
+ }>;
1602
178
  }>;
1603
179
  type GetStyleOptions = Pick<GlobalOptions, 'ankiConnectOptions'>;
1604
180
  declare const defaultGetStyleOptions: GetStyleOptions;
1605
181
  declare function getStyle(options: PartialDeep<GetStyleOptions>): Promise<string>;
1606
182
  declare function setStyle(options?: PartialDeep<SetStyleOptions>): Promise<SetStyleResult>;
1607
183
  declare function formatSetStyleResult(result: SetStyleResult, verbose?: boolean): string;
1608
-
184
+ //#endregion
185
+ //#region src/lib/actions/sync-notes.d.ts
1609
186
  type SyncedNote = {
1610
- action: 'ankiUnreachable' | 'created' | 'deleted' | 'matched' | 'unchanged' | 'updated';
1611
- note: YankiNote;
187
+ action: 'ankiUnreachable' | 'created' | 'deleted' | 'matched' | 'unchanged' | 'updated';
188
+ note: YankiNote;
1612
189
  };
1613
190
  type SyncNotesOptions = Pick<GlobalOptions, 'ankiConnectOptions' | 'ankiWeb' | 'checkDatabase' | 'dryRun' | 'namespace' | 'strictMatching'>;
1614
191
  declare const defaultSyncNotesOptions: SyncNotesOptions;
1615
192
  type SyncNotesResult = Simplify<Pick<GlobalOptions, 'ankiWeb' | 'dryRun' | 'namespace'> & {
1616
- deletedDecks: string[];
1617
- deletedMedia: string[];
1618
- duration: number;
1619
- fixedDatabase: boolean;
1620
- synced: SyncedNote[];
193
+ deletedDecks: string[];
194
+ deletedMedia: string[];
195
+ duration: number;
196
+ fixedDatabase: boolean;
197
+ synced: SyncedNote[];
1621
198
  }>;
1622
199
  /**
1623
200
  * Syncs local notes to Anki.
@@ -1627,15 +204,16 @@ type SyncNotesResult = Simplify<Pick<GlobalOptions, 'ankiWeb' | 'dryRun' | 'name
1627
204
  * @throws {Error} For various reasons...
1628
205
  */
1629
206
  declare function syncNotes(allLocalNotes: YankiNote[], options?: PartialDeep<SyncNotesOptions>): Promise<SyncNotesResult>;
1630
-
207
+ //#endregion
208
+ //#region src/lib/actions/sync-files.d.ts
1631
209
  type SyncFilesOptions = Simplify<Pick<GlobalOptions, 'allFilePaths' | 'basePath' | 'fetchAdapter' | 'fileAdapter' | 'manageFilenames' | 'maxFilenameLength' | 'obsidianVault' | 'strictLineBreaks' | 'syncMediaAssets'> & SyncNotesOptions>;
1632
210
  declare const defaultSyncFilesOptions: SyncFilesOptions;
1633
211
  type SyncedFile = Simplify<SyncedNote & {
1634
- filePath: string | undefined;
1635
- filePathOriginal: string | undefined;
212
+ filePath: string | undefined;
213
+ filePathOriginal: string | undefined;
1636
214
  }>;
1637
215
  type SyncFilesResult = Simplify<Omit<SyncNotesResult, 'synced'> & {
1638
- synced: SyncedFile[];
216
+ synced: SyncedFile[];
1639
217
  }>;
1640
218
  /**
1641
219
  * Sync a list of local yanki files to Anki.
@@ -1651,19 +229,19 @@ type SyncFilesResult = Simplify<Omit<SyncNotesResult, 'synced'> & {
1651
229
  */
1652
230
  declare function syncFiles(allLocalFilePaths: string[], options?: PartialDeep<SyncFilesOptions>): Promise<SyncFilesResult>;
1653
231
  declare function formatSyncFilesResult(result: SyncFilesResult, verbose?: boolean): string;
1654
-
232
+ //#endregion
233
+ //#region src/lib/parse/parse.d.ts
1655
234
  type GetNoteFromMarkdownOptions = Pick<GlobalOptions, 'allFilePaths' | 'basePath' | 'cwd' | 'fetchAdapter' | 'fileAdapter' | 'namespace' | 'obsidianVault' | 'resolveUrls' | 'strictLineBreaks' | 'syncMediaAssets'> & {
1656
- /** Needed for the public API, but optional for more efficient use internally when the namespace is already validated. */
1657
- namespaceValidationAndSanitization: boolean;
235
+ /** Needed for the public API, but optional for more efficient use internally when the namespace is already validated. */namespaceValidationAndSanitization: boolean;
1658
236
  };
1659
237
  declare const defaultGetNoteFromMarkdownOptions: GetNoteFromMarkdownOptions;
1660
238
  declare function getNoteFromMarkdown(markdown: string, options?: Partial<GetNoteFromMarkdownOptions>): Promise<YankiNote>;
1661
-
239
+ //#endregion
240
+ //#region src/lib/utilities/url.d.ts
1662
241
  declare function urlToHostAndPort(url: string): undefined | {
1663
- host: string;
1664
- port: number;
242
+ host: string;
243
+ port: number;
1665
244
  };
1666
245
  declare function hostAndPortToUrl(host: string, port: number): string;
1667
-
1668
- export { cleanNotes, defaultCleanOptions, defaultGetNoteFromMarkdownOptions, defaultGetStyleOptions, defaultListOptions, defaultRenameFilesOptions, defaultSetStyleOptions, defaultSyncFilesOptions, defaultSyncNotesOptions, formatCleanResult, formatListResult, formatSetStyleResult, formatSyncFilesResult, getNoteFromMarkdown, getStyle, hostAndPortToUrl, listNotes, renameFiles, setStyle, syncFiles, syncNotes, urlToHostAndPort };
1669
- export type { CleanOptions, CleanResult, FetchAdapter, FileAdapter, GetNoteFromMarkdownOptions, GetStyleOptions, ListOptions, RenameFilesOptions, RenameFilesResult, SetStyleOptions, SetStyleResult, SyncFilesOptions, SyncFilesResult, SyncNotesOptions, SyncNotesResult, YankiNote };
246
+ //#endregion
247
+ export { type CleanOptions, type CleanResult, type FetchAdapter, type FileAdapter, type GetNoteFromMarkdownOptions, type GetStyleOptions, type ListOptions, type RenameFilesOptions, type RenameFilesResult, type SetStyleOptions, type SetStyleResult, type SyncFilesOptions, type SyncFilesResult, type SyncNotesOptions, type SyncNotesResult, type YankiNote, cleanNotes, defaultCleanOptions, defaultGetNoteFromMarkdownOptions, defaultGetStyleOptions, defaultListOptions, defaultRenameFilesOptions, defaultSetStyleOptions, defaultSyncFilesOptions, defaultSyncNotesOptions, formatCleanResult, formatListResult, formatSetStyleResult, formatSyncFilesResult, getNoteFromMarkdown, getStyle, hostAndPortToUrl, listNotes, renameFiles, setStyle, syncFiles, syncNotes, urlToHostAndPort };