[{"data":1,"prerenderedAt":869,"buildId":870},["ShallowReactive",2],{"page:\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Fstorage":3},{"id":4,"title":5,"body":6,"description":852,"extension":853,"frontmatter":854,"heading":605,"meta":860,"navigation":862,"order":857,"path":863,"seo":864,"sitemap":865,"source":866,"stem":867,"__hash__":868},"docs\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Fstorage.md","Storage - Where Kubb writes generated files",{"type":7,"value":8,"toc":840},"minimark",[9,22,27,37,96,118,124,141,600,607,612,757,763,767,771,780,832],[10,11,12,13,21],"p",{},"A storage backend decides where Kubb writes generated files: to disk, to memory, or to your own destination. Set it with the config's ",[14,15,17],"a",{"href":16},"\u002Fdocs\u002F5.x\u002Freference\u002Fconfiguration#storage",[18,19,20],"code",{},"storage"," field.",[23,24,26],"h2",{"id":25},"built-in-backends","Built-in backends",[10,28,29,30,33,34,36],{},"Both ship from ",[18,31,32],{},"kubb\u002Fkit"," and go straight into ",[18,35,20],{},".",[38,39,40,58],"table",{},[41,42,43],"thead",{},[44,45,46,50,55],"tr",{},[47,48,49],"th",{},"Backend",[47,51,52],{},[18,53,54],{},"name",[47,56,57],{},"Writes",[59,60,61,77],"tbody",{},[44,62,63,69,74],{},[64,65,66],"td",{},[18,67,68],{},"fsStorage()",[64,70,71],{},[18,72,73],{},"'fs'",[64,75,76],{},"Each file to its path on disk, creating folders. Skips a file with the same content. The default.",[44,78,79,84,89],{},[64,80,81],{},[18,82,83],{},"memoryStorage()",[64,85,86],{},[18,87,88],{},"'memory'",[64,90,91,92,95],{},"A ",[18,93,94],{},"Map"," in memory, so nothing reaches disk. Suits plugin tests, CI checks, and dry runs.",[97,98,100,101,104,105,108,109,112,113,115,116,36],"blockquote",{"as":99},"note","",[18,102,103],{},"output.format",", ",[18,106,107],{},"output.lint",", and ",[18,110,111],{},"output.postGenerate"," run only when the backend's ",[18,114,54],{}," is ",[18,117,73],{},[23,119,121],{"id":120},"createstorage",[18,122,123],{},"createStorage",[10,125,126,128,129,132,133,136,137,140],{},[18,127,123],{}," turns a builder ",[18,130,131],{},"(options: TOptions) => Storage"," into a factory ",[18,134,135],{},"(options?: TOptions) => Storage",". This is the built-in ",[18,138,139],{},"memoryStorage",":",[142,143,148],"pre",{"language":144,"filename":145,"code":146,"class":147},"typescript","memory-storage.ts","import { createStorage } from 'kubb\u002Fkit'\n\nexport const memoryStorage = createStorage(() => {\n const store = new Map\u003Cstring, string>()\n return {\n name: 'memory',\n async readItem(key) {\n return store.get(key) ?? null\n },\n async writeItem(key, value) {\n store.set(key, value)\n },\n async removeItem(key) {\n store.delete(key)\n },\n async readKeys(base) {\n const keys = [...store.keys()]\n return base ? keys.filter((k) => k.startsWith(base)) : keys\n },\n async empty(base) {\n for (const k of store.keys()) if (!base || k.startsWith(base)) store.delete(k)\n },\n }\n})","highlights",[18,149,151,178,179,178,181,178,207,178,240,178,249,178,264,178,283,178,311,178,320,178,340,178,362,178,369,178,384,178,401,178,407,178,423,178,450,178,497,178,505,178,520,178,583,178,589,178,595],{"class":150},"language-typescript",[152,153,156,160,164,168,171,174],"span",{"class":154,"style":155},"line","display: inline",[152,157,159],{"style":158},"color:#d73a49;--hls-dark:#f97583","import ",[152,161,163],{"style":162},"color:#005cc5;--hls-dark:#79b8ff","{ ",[152,165,167],{"style":166},"color:#24292e;--hls-dark:#e1e4e8","createStorage ",[152,169,170],{"style":162},"} ",[152,172,173],{"style":158},"from ",[152,175,177],{"style":176},"color:#032f62;--hls-dark:#9ecbff","'kubb\u002Fkit'","\n",[152,180],{"class":154,"style":155},[152,182,183,186,189,192,195,198,201,204],{"class":154,"style":155},[152,184,185],{"style":158},"export ",[152,187,188],{"style":158},"const ",[152,190,191],{"style":166},"memoryStorage ",[152,193,194],{"style":158},"= ",[152,196,123],{"style":197},"color:#6f42c1;--hls-dark:#b392f0",[152,199,200],{"style":162},"(() ",[152,202,203],{"style":158},"=> ",[152,205,206],{"style":162},"{",[152,208,209,212,214,217,219,222,224,227,230,232,234,237],{"class":154,"style":155},[152,210,211],{"style":162}," ",[152,213,188],{"style":158},[152,215,216],{"style":166},"store ",[152,218,194],{"style":158},[152,220,221],{"style":158},"new ",[152,223,94],{"style":197},[152,225,226],{"style":158},"\u003C",[152,228,229],{"style":166},"string",[152,231,104],{"style":158},[152,233,229],{"style":166},[152,235,236],{"style":158},">",[152,238,239],{"style":162},"()",[152,241,242,244,247],{"class":154,"style":155},[152,243,211],{"style":162},[152,245,246],{"style":158},"return ",[152,248,206],{"style":162},[152,250,251,254,256,259,261],{"class":154,"style":155},[152,252,253],{"style":162}," ",[152,255,54],{"style":162},[152,257,258],{"style":158},": ",[152,260,88],{"style":176},[152,262,263],{"style":158},",",[152,265,266,268,271,274,277,280],{"class":154,"style":155},[152,267,253],{"style":158},[152,269,270],{"style":158},"async ",[152,272,273],{"style":197},"readItem",[152,275,276],{"style":162},"(",[152,278,279],{"style":166},"key",[152,281,282],{"style":162},") {",[152,284,285,288,290,293,295,298,300,302,305,308],{"class":154,"style":155},[152,286,287],{"style":162}," ",[152,289,246],{"style":158},[152,291,292],{"style":166},"store",[152,294,36],{"style":158},[152,296,297],{"style":197},"get",[152,299,276],{"style":162},[152,301,279],{"style":166},[152,303,304],{"style":162},") ",[152,306,307],{"style":158},"?? ",[152,309,310],{"style":162},"null",[152,312,313,315,318],{"class":154,"style":155},[152,314,253],{"style":162},[152,316,317],{"style":162},"}",[152,319,263],{"style":158},[152,321,322,324,326,329,331,333,335,338],{"class":154,"style":155},[152,323,253],{"style":158},[152,325,270],{"style":158},[152,327,328],{"style":197},"writeItem",[152,330,276],{"style":162},[152,332,279],{"style":166},[152,334,104],{"style":158},[152,336,337],{"style":166},"value",[152,339,282],{"style":162},[152,341,342,344,346,348,351,353,355,357,359],{"class":154,"style":155},[152,343,287],{"style":162},[152,345,292],{"style":166},[152,347,36],{"style":158},[152,349,350],{"style":197},"set",[152,352,276],{"style":162},[152,354,279],{"style":166},[152,356,104],{"style":158},[152,358,337],{"style":166},[152,360,361],{"style":162},")",[152,363,364,367],{"class":154,"style":155},[152,365,366],{"style":162}," }",[152,368,263],{"style":158},[152,370,371,373,375,378,380,382],{"class":154,"style":155},[152,372,253],{"style":158},[152,374,270],{"style":158},[152,376,377],{"style":197},"removeItem",[152,379,276],{"style":162},[152,381,279],{"style":166},[152,383,282],{"style":162},[152,385,386,388,390,392,395,397,399],{"class":154,"style":155},[152,387,287],{"style":162},[152,389,292],{"style":166},[152,391,36],{"style":158},[152,393,394],{"style":197},"delete",[152,396,276],{"style":162},[152,398,279],{"style":166},[152,400,361],{"style":162},[152,402,403,405],{"class":154,"style":155},[152,404,366],{"style":162},[152,406,263],{"style":158},[152,408,409,411,413,416,418,421],{"class":154,"style":155},[152,410,253],{"style":158},[152,412,270],{"style":158},[152,414,415],{"style":197},"readKeys",[152,417,276],{"style":162},[152,419,420],{"style":166},"base",[152,422,282],{"style":162},[152,424,425,427,429,432,434,437,440,442,444,447],{"class":154,"style":155},[152,426,287],{"style":162},[152,428,188],{"style":158},[152,430,431],{"style":166},"keys ",[152,433,194],{"style":158},[152,435,436],{"style":162},"[",[152,438,439],{"style":158},"...",[152,441,292],{"style":166},[152,443,36],{"style":158},[152,445,446],{"style":197},"keys",[152,448,449],{"style":162},"()]",[152,451,452,454,456,459,462,464,466,469,472,475,477,479,481,483,486,488,490,493,495],{"class":154,"style":155},[152,453,287],{"style":162},[152,455,246],{"style":158},[152,457,458],{"style":166},"base ",[152,460,461],{"style":158},"? ",[152,463,446],{"style":166},[152,465,36],{"style":158},[152,467,468],{"style":197},"filter",[152,470,471],{"style":162},"((",[152,473,474],{"style":166},"k",[152,476,304],{"style":162},[152,478,203],{"style":158},[152,480,474],{"style":166},[152,482,36],{"style":158},[152,484,485],{"style":197},"startsWith",[152,487,276],{"style":162},[152,489,420],{"style":166},[152,491,492],{"style":162},")) ",[152,494,258],{"style":158},[152,496,446],{"style":166},[152,498,499,501,503],{"class":154,"style":155},[152,500,253],{"style":166},[152,502,317],{"style":162},[152,504,263],{"style":158},[152,506,507,509,511,514,516,518],{"class":154,"style":155},[152,508,253],{"style":158},[152,510,270],{"style":158},[152,512,513],{"style":197},"empty",[152,515,276],{"style":162},[152,517,420],{"style":166},[152,519,282],{"style":162},[152,521,522,524,527,529,531,534,537,539,541,543,546,549,551,554,556,559,561,563,565,567,569,571,573,575,577,579,581],{"class":154,"style":155},[152,523,287],{"style":162},[152,525,526],{"style":158},"for ",[152,528,276],{"style":162},[152,530,188],{"style":158},[152,532,533],{"style":166},"k ",[152,535,536],{"style":158},"of ",[152,538,292],{"style":166},[152,540,36],{"style":158},[152,542,446],{"style":197},[152,544,545],{"style":162},"()) ",[152,547,548],{"style":158},"if ",[152,550,276],{"style":162},[152,552,553],{"style":158},"!",[152,555,458],{"style":166},[152,557,558],{"style":158},"|| ",[152,560,474],{"style":166},[152,562,36],{"style":158},[152,564,485],{"style":197},[152,566,276],{"style":162},[152,568,420],{"style":166},[152,570,492],{"style":162},[152,572,292],{"style":166},[152,574,36],{"style":158},[152,576,394],{"style":197},[152,578,276],{"style":162},[152,580,474],{"style":166},[152,582,361],{"style":162},[152,584,585,587],{"class":154,"style":155},[152,586,366],{"style":162},[152,588,263],{"style":158},[152,590,591,593],{"class":154,"style":155},[152,592,211],{"style":158},[152,594,317],{"style":162},[152,596,597],{"class":154,"style":155},[152,598,599],{"style":162},"})",[23,601,603,606],{"id":602},"storage-interface",[18,604,605],{},"Storage"," interface",[10,608,609,610,36],{},"Every member is required. Keys are the files' absolute paths. The build result exposes the backend as ",[18,611,20],{},[38,613,614,630],{},[41,615,616],{},[44,617,618,621,624,627],{},[47,619,620],{},"Member",[47,622,623],{},"Params",[47,625,626],{},"Returns",[47,628,629],{},"Does",[59,631,632,647,670,694,712,732],{},[44,633,634,638,640,644],{},[64,635,636],{},[18,637,54],{},[64,639],{},[64,641,642],{},[18,643,229],{},[64,645,646],{},"Names the backend in logs and diagnostics.",[44,648,649,654,659,664],{},[64,650,651],{},[18,652,653],{},"readItem()",[64,655,656],{},[18,657,658],{},"key: string",[64,660,661],{},[18,662,663],{},"Promise\u003Cstring | null>",[64,665,666,667,669],{},"Returns an item's content, or ",[18,668,310],{}," for a missing key.",[44,671,672,677,682,687],{},[64,673,674],{},[18,675,676],{},"writeItem()",[64,678,679],{},[18,680,681],{},"key: string, value: string, options?: { stored?: string | null }",[64,683,684],{},[18,685,686],{},"Promise\u003Cvoid>",[64,688,689,690,693],{},"Writes an item. ",[18,691,692],{},"stored"," is the previous content when Kubb already read it.",[44,695,696,701,705,709],{},[64,697,698],{},[18,699,700],{},"removeItem()",[64,702,703],{},[18,704,658],{},[64,706,707],{},[18,708,686],{},[64,710,711],{},"Deletes an item. Does nothing for a missing key.",[44,713,714,719,724,729],{},[64,715,716],{},[18,717,718],{},"readKeys()",[64,720,721],{},[18,722,723],{},"base?: string",[64,725,726],{},[18,727,728],{},"Promise\u003Cstring[]>",[64,730,731],{},"Lists keys, optionally under a prefix.",[44,733,734,739,743,747],{},[64,735,736],{},[18,737,738],{},"empty()",[64,740,741],{},[18,742,723],{},[64,744,745],{},[18,746,686],{},[64,748,749,750,752,753,36],{},"Deletes every item, optionally under a prefix. Without ",[18,751,420],{},", the backend decides. See ",[14,754,756],{"href":755},"#storage-keys","Storage keys",[97,758,759,760,762],{"as":99},"Kubb skips ",[18,761,328],{}," for a file whose content did not change, so do not expect one call per generated file.",[23,764,766],{"id":765},"less-common-cases","Less common cases",[768,769,756],"h3",{"id":770},"storage-keys",[10,772,773,774,776,777,779],{},"When you call ",[18,775,718],{}," or ",[18,778,738],{}," on a built-in backend, the result depends on the backend.",[38,781,782,801],{},[41,783,784],{},[44,785,786,788,794],{},[47,787,49],{},[47,789,790,793],{},[18,791,792],{},"readKeys(base?)"," returns",[47,795,796,798,799],{},[18,797,738],{}," without ",[18,800,420],{},[59,802,803,818],{},[44,804,805,809,815],{},[64,806,807],{},[18,808,68],{},[64,810,811,812,814],{},"Paths relative to ",[18,813,420],{},", or to the working directory",[64,816,817],{},"Does nothing",[44,819,820,824,829],{},[64,821,822],{},[18,823,83],{},[64,825,826,827],{},"The stored keys (absolute paths) that start with ",[18,828,420],{},[64,830,831],{},"Deletes every entry",[10,833,834,835,104,837,839],{},"In ",[18,836,676],{},[18,838,692],{}," is the previous content when Kubb already read it, so the backend can skip a second read.",{"title":100,"searchDepth":841,"depth":841,"links":842},5,[843,845,846,848],{"id":25,"depth":844,"text":26},2,{"id":120,"depth":844,"text":123},{"id":602,"depth":844,"text":847},"Storage interface",{"id":765,"depth":844,"text":766,"children":849},[850],{"id":770,"depth":851,"text":756},3,"Storage backends decide where Kubb writes generated files. Covers createStorage, the Storage interface, and the fsStorage and memoryStorage backends.","md",{"layout":855,"title":5,"description":852,"outline":856,"order":857,"navigation":858},"doc",[844,851],7,{"title":605,"icon":859},"i-iconoir-database",{"layout":855,"outline":861},[844,851],{"title":605,"icon":859},"\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Fstorage",{"title":5,"description":852},{"loc":863},"kubb-labs\u002Fkubb\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Fstorage.md","docs\u002F5.x\u002Freference\u002Fkit\u002Fstorage","EItYyrBkzLb0-YLjX_Gc4hVCqju3lLyRZ4lZC8WpoP4",1795727678706,"1b64b1eb-29b7-4f90-ad41-6f24721e1669"]