[{"data":1,"prerenderedAt":1006,"buildId":1007},["ShallowReactive",2],{"page:\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Fstorage":3},{"id":4,"title":5,"body":6,"description":989,"extension":990,"frontmatter":991,"heading":722,"meta":997,"navigation":999,"order":994,"path":1000,"seo":1001,"sitemap":1002,"source":1003,"stem":1004,"__hash__":1005},"docs\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Fstorage.md","Storage - Where Kubb writes generated files",{"type":7,"value":8,"toc":977},"minimark",[9,22,27,37,96,119,125,138,717,724,729,882,888,892,896,920,926,969],[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,118],"blockquote",{"as":99},"note","",[18,102,103],{},"output.format",", ",[18,106,107],{},"output.lint",", and ",[18,110,111],{},"output.postGenerate"," run only for a backend named ",[18,114,73],{},", such as ",[18,117,68],{},", because Kubb treats only that name as writing to disk. An S3 or other remote backend skips them.",[23,120,122],{"id":121},"createstorage",[18,123,124],{},"createStorage",[10,126,127,129,130,133,134,137],{},[18,128,124],{}," turns a builder ",[18,131,132],{},"(options: TOptions) => Storage"," into a factory ",[18,135,136],{},"(options?: TOptions) => Storage",". This is a minimal in-memory backend:",[139,140,145],"pre",{"language":141,"filename":142,"code":143,"class":144},"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 if (!base) return keys\n const dir = `${base.replace(\u002F\\\u002F+$\u002F, '')}\u002F`\n return keys.filter((k) => k.startsWith(dir)).map((k) => k.slice(dir.length))\n },\n async empty(base) {\n const dir = base && `${base.replace(\u002F\\\u002F+$\u002F, '')}\u002F`\n for (const k of store.keys()) if (!dir || k.startsWith(dir)) store.delete(k)\n },\n }\n})","highlights",[18,146,148,175,176,175,178,175,204,175,237,175,246,175,261,175,280,175,308,175,317,175,337,175,359,175,366,175,381,175,398,175,404,175,420,175,447,175,467,175,508,175,577,175,583,175,598,175,638,175,700,175,706,175,712],{"class":147},"language-typescript",[149,150,153,157,161,165,168,171],"span",{"class":151,"style":152},"line","display: inline",[149,154,156],{"style":155},"color:#d73a49;--hls-dark:#f97583","import ",[149,158,160],{"style":159},"color:#005cc5;--hls-dark:#79b8ff","{ ",[149,162,164],{"style":163},"color:#24292e;--hls-dark:#e1e4e8","createStorage ",[149,166,167],{"style":159},"} ",[149,169,170],{"style":155},"from ",[149,172,174],{"style":173},"color:#032f62;--hls-dark:#9ecbff","'kubb\u002Fkit'","\n",[149,177],{"class":151,"style":152},[149,179,180,183,186,189,192,195,198,201],{"class":151,"style":152},[149,181,182],{"style":155},"export ",[149,184,185],{"style":155},"const ",[149,187,188],{"style":163},"memoryStorage ",[149,190,191],{"style":155},"= ",[149,193,124],{"style":194},"color:#6f42c1;--hls-dark:#b392f0",[149,196,197],{"style":159},"(() ",[149,199,200],{"style":155},"=> ",[149,202,203],{"style":159},"{",[149,205,206,209,211,214,216,219,221,224,227,229,231,234],{"class":151,"style":152},[149,207,208],{"style":159}," ",[149,210,185],{"style":155},[149,212,213],{"style":163},"store ",[149,215,191],{"style":155},[149,217,218],{"style":155},"new ",[149,220,94],{"style":194},[149,222,223],{"style":155},"\u003C",[149,225,226],{"style":163},"string",[149,228,104],{"style":155},[149,230,226],{"style":163},[149,232,233],{"style":155},">",[149,235,236],{"style":159},"()",[149,238,239,241,244],{"class":151,"style":152},[149,240,208],{"style":159},[149,242,243],{"style":155},"return ",[149,245,203],{"style":159},[149,247,248,251,253,256,258],{"class":151,"style":152},[149,249,250],{"style":159}," ",[149,252,54],{"style":159},[149,254,255],{"style":155},": ",[149,257,88],{"style":173},[149,259,260],{"style":155},",",[149,262,263,265,268,271,274,277],{"class":151,"style":152},[149,264,250],{"style":155},[149,266,267],{"style":155},"async ",[149,269,270],{"style":194},"readItem",[149,272,273],{"style":159},"(",[149,275,276],{"style":163},"key",[149,278,279],{"style":159},") {",[149,281,282,285,287,290,292,295,297,299,302,305],{"class":151,"style":152},[149,283,284],{"style":159}," ",[149,286,243],{"style":155},[149,288,289],{"style":163},"store",[149,291,36],{"style":155},[149,293,294],{"style":194},"get",[149,296,273],{"style":159},[149,298,276],{"style":163},[149,300,301],{"style":159},") ",[149,303,304],{"style":155},"?? ",[149,306,307],{"style":159},"null",[149,309,310,312,315],{"class":151,"style":152},[149,311,250],{"style":159},[149,313,314],{"style":159},"}",[149,316,260],{"style":155},[149,318,319,321,323,326,328,330,332,335],{"class":151,"style":152},[149,320,250],{"style":155},[149,322,267],{"style":155},[149,324,325],{"style":194},"writeItem",[149,327,273],{"style":159},[149,329,276],{"style":163},[149,331,104],{"style":155},[149,333,334],{"style":163},"value",[149,336,279],{"style":159},[149,338,339,341,343,345,348,350,352,354,356],{"class":151,"style":152},[149,340,284],{"style":159},[149,342,289],{"style":163},[149,344,36],{"style":155},[149,346,347],{"style":194},"set",[149,349,273],{"style":159},[149,351,276],{"style":163},[149,353,104],{"style":155},[149,355,334],{"style":163},[149,357,358],{"style":159},")",[149,360,361,364],{"class":151,"style":152},[149,362,363],{"style":159}," }",[149,365,260],{"style":155},[149,367,368,370,372,375,377,379],{"class":151,"style":152},[149,369,250],{"style":155},[149,371,267],{"style":155},[149,373,374],{"style":194},"removeItem",[149,376,273],{"style":159},[149,378,276],{"style":163},[149,380,279],{"style":159},[149,382,383,385,387,389,392,394,396],{"class":151,"style":152},[149,384,284],{"style":159},[149,386,289],{"style":163},[149,388,36],{"style":155},[149,390,391],{"style":194},"delete",[149,393,273],{"style":159},[149,395,276],{"style":163},[149,397,358],{"style":159},[149,399,400,402],{"class":151,"style":152},[149,401,363],{"style":159},[149,403,260],{"style":155},[149,405,406,408,410,413,415,418],{"class":151,"style":152},[149,407,250],{"style":155},[149,409,267],{"style":155},[149,411,412],{"style":194},"readKeys",[149,414,273],{"style":159},[149,416,417],{"style":163},"base",[149,419,279],{"style":159},[149,421,422,424,426,429,431,434,437,439,441,444],{"class":151,"style":152},[149,423,284],{"style":159},[149,425,185],{"style":155},[149,427,428],{"style":163},"keys ",[149,430,191],{"style":155},[149,432,433],{"style":159},"[",[149,435,436],{"style":155},"...",[149,438,289],{"style":163},[149,440,36],{"style":155},[149,442,443],{"style":194},"keys",[149,445,446],{"style":159},"()]",[149,448,449,451,454,456,459,461,463,465],{"class":151,"style":152},[149,450,284],{"style":159},[149,452,453],{"style":155},"if ",[149,455,273],{"style":159},[149,457,458],{"style":155},"!",[149,460,417],{"style":163},[149,462,301],{"style":159},[149,464,243],{"style":155},[149,466,443],{"style":163},[149,468,469,471,473,476,478,481,484,486,488,491,493,496,498,501,503,505],{"class":151,"style":152},[149,470,284],{"style":163},[149,472,185],{"style":155},[149,474,475],{"style":163},"dir ",[149,477,191],{"style":155},[149,479,480],{"style":173},"`",[149,482,483],{"style":163},"${",[149,485,417],{"style":163},[149,487,36],{"style":155},[149,489,490],{"style":194},"replace",[149,492,273],{"style":159},[149,494,495],{"style":173},"\u002F\\\u002F+$\u002F",[149,497,104],{"style":155},[149,499,500],{"style":173},"''",[149,502,358],{"style":159},[149,504,314],{"style":163},[149,506,507],{"style":173},"\u002F`",[149,509,510,512,514,516,518,521,524,527,529,531,533,535,538,540,543,546,548,551,553,555,557,559,561,563,566,568,570,572,575],{"class":151,"style":152},[149,511,284],{"style":173},[149,513,243],{"style":155},[149,515,443],{"style":163},[149,517,36],{"style":155},[149,519,520],{"style":194},"filter",[149,522,523],{"style":159},"((",[149,525,526],{"style":163},"k",[149,528,301],{"style":159},[149,530,200],{"style":155},[149,532,526],{"style":163},[149,534,36],{"style":155},[149,536,537],{"style":194},"startsWith",[149,539,273],{"style":159},[149,541,542],{"style":163},"dir",[149,544,545],{"style":159},"))",[149,547,36],{"style":155},[149,549,550],{"style":194},"map",[149,552,523],{"style":159},[149,554,526],{"style":163},[149,556,301],{"style":159},[149,558,200],{"style":155},[149,560,526],{"style":163},[149,562,36],{"style":155},[149,564,565],{"style":194},"slice",[149,567,273],{"style":159},[149,569,542],{"style":163},[149,571,36],{"style":155},[149,573,574],{"style":159},"length",[149,576,545],{"style":159},[149,578,579,581],{"class":151,"style":152},[149,580,363],{"style":159},[149,582,260],{"style":155},[149,584,585,587,589,592,594,596],{"class":151,"style":152},[149,586,250],{"style":155},[149,588,267],{"style":155},[149,590,591],{"style":194},"empty",[149,593,273],{"style":159},[149,595,417],{"style":163},[149,597,279],{"style":159},[149,599,600,602,604,606,608,611,614,616,618,620,622,624,626,628,630,632,634,636],{"class":151,"style":152},[149,601,284],{"style":159},[149,603,185],{"style":155},[149,605,475],{"style":163},[149,607,191],{"style":155},[149,609,610],{"style":163},"base ",[149,612,613],{"style":155},"&& ",[149,615,480],{"style":173},[149,617,483],{"style":163},[149,619,417],{"style":163},[149,621,36],{"style":155},[149,623,490],{"style":194},[149,625,273],{"style":159},[149,627,495],{"style":173},[149,629,104],{"style":155},[149,631,500],{"style":173},[149,633,358],{"style":159},[149,635,314],{"style":163},[149,637,507],{"style":173},[149,639,640,642,645,647,649,652,655,657,659,661,664,666,668,670,672,675,677,679,681,683,685,688,690,692,694,696,698],{"class":151,"style":152},[149,641,284],{"style":173},[149,643,644],{"style":155},"for ",[149,646,273],{"style":159},[149,648,185],{"style":155},[149,650,651],{"style":163},"k ",[149,653,654],{"style":155},"of ",[149,656,289],{"style":163},[149,658,36],{"style":155},[149,660,443],{"style":194},[149,662,663],{"style":159},"()) ",[149,665,453],{"style":155},[149,667,273],{"style":159},[149,669,458],{"style":155},[149,671,475],{"style":163},[149,673,674],{"style":155},"|| ",[149,676,526],{"style":163},[149,678,36],{"style":155},[149,680,537],{"style":194},[149,682,273],{"style":159},[149,684,542],{"style":163},[149,686,687],{"style":159},")) ",[149,689,289],{"style":163},[149,691,36],{"style":155},[149,693,391],{"style":194},[149,695,273],{"style":159},[149,697,526],{"style":163},[149,699,358],{"style":159},[149,701,702,704],{"class":151,"style":152},[149,703,363],{"style":159},[149,705,260],{"style":155},[149,707,708,710],{"class":151,"style":152},[149,709,208],{"style":155},[149,711,314],{"style":159},[149,713,714],{"class":151,"style":152},[149,715,716],{"style":159},"})",[23,718,720,723],{"id":719},"storage-interface",[18,721,722],{},"Storage"," interface",[10,725,726,727,36],{},"Every member is required. Keys are the files' absolute paths. The build result exposes the backend as ",[18,728,20],{},[38,730,731,747],{},[41,732,733],{},[44,734,735,738,741,744],{},[47,736,737],{},"Member",[47,739,740],{},"Params",[47,742,743],{},"Returns",[47,745,746],{},"Does",[59,748,749,764,787,811,829,856],{},[44,750,751,755,757,761],{},[64,752,753],{},[18,754,54],{},[64,756],{},[64,758,759],{},[18,760,226],{},[64,762,763],{},"Names the backend in logs and diagnostics.",[44,765,766,771,776,781],{},[64,767,768],{},[18,769,770],{},"readItem()",[64,772,773],{},[18,774,775],{},"key: string",[64,777,778],{},[18,779,780],{},"Promise\u003Cstring | null>",[64,782,783,784,786],{},"Returns an item's content, or ",[18,785,307],{}," for a missing key.",[44,788,789,794,799,804],{},[64,790,791],{},[18,792,793],{},"writeItem()",[64,795,796],{},[18,797,798],{},"key: string, value: string, options?: { stored?: string | null }",[64,800,801],{},[18,802,803],{},"Promise\u003Cvoid>",[64,805,806,807,810],{},"Writes an item. ",[18,808,809],{},"stored"," is the previous content when Kubb already read it.",[44,812,813,818,822,826],{},[64,814,815],{},[18,816,817],{},"removeItem()",[64,819,820],{},[18,821,775],{},[64,823,824],{},[18,825,803],{},[64,827,828],{},"Deletes an item. Does nothing for a missing key.",[44,830,831,836,841,846],{},[64,832,833],{},[18,834,835],{},"readKeys()",[64,837,838],{},[18,839,840],{},"base?: string",[64,842,843],{},[18,844,845],{},"Promise\u003Cstring[]>",[64,847,848,849,851,852,36],{},"Lists keys. With ",[18,850,417],{},", lists the keys inside that folder as posix paths relative to it. See ",[14,853,855],{"href":854},"#storage-keys","Storage keys",[44,857,858,863,867,871],{},[64,859,860],{},[18,861,862],{},"empty()",[64,864,865],{},[18,866,840],{},[64,868,869],{},[18,870,803],{},[64,872,873,874,876,877,879,880,36],{},"Deletes every item, or only the items inside the folder ",[18,875,417],{},". Without ",[18,878,417],{},", the backend decides. See ",[14,881,855],{"href":854},[97,883,884,885,887],{"as":99},"Kubb skips ",[18,886,325],{}," for a file whose content did not change, so do not expect one call per generated file.",[23,889,891],{"id":890},"less-common-cases","Less common cases",[893,894,855],"h3",{"id":895},"storage-keys",[10,897,898,901,902,904,905,908,909,912,913,915,916,919],{},[18,899,900],{},"readKeys(base)"," returns the keys inside the folder ",[18,903,417],{}," as posix paths relative to it, such as ",[18,906,907],{},"models\u002Fpet.ts",", on every backend. A key under a sibling folder, such as ",[18,910,911],{},"${base}2\u002F",", is not inside ",[18,914,417],{},". ",[18,917,918],{},"empty(base)"," removes the same keys. A custom backend must return the same shape.",[10,921,922,923,925],{},"Without ",[18,924,417],{},", the result depends on the backend.",[38,927,928,943],{},[41,929,930],{},[44,931,932,934,939],{},[47,933,49],{},[47,935,936,938],{},[18,937,835],{}," returns",[47,940,941],{},[18,942,862],{},[59,944,945,957],{},[44,946,947,951,954],{},[64,948,949],{},[18,950,68],{},[64,952,953],{},"Paths relative to the working directory",[64,955,956],{},"Does nothing",[44,958,959,963,966],{},[64,960,961],{},[18,962,83],{},[64,964,965],{},"The stored keys (absolute paths)",[64,967,968],{},"Deletes every entry",[10,970,971,972,104,974,976],{},"In ",[18,973,793],{},[18,975,809],{}," is the previous content when Kubb already read it, so the backend can skip a second read.",{"title":100,"searchDepth":978,"depth":978,"links":979},5,[980,982,983,985],{"id":25,"depth":981,"text":26},2,{"id":121,"depth":981,"text":124},{"id":719,"depth":981,"text":984},"Storage interface",{"id":890,"depth":981,"text":891,"children":986},[987],{"id":895,"depth":988,"text":855},3,"Storage backends decide where Kubb writes generated files. Covers createStorage, the Storage interface, and the fsStorage and memoryStorage backends.","md",{"layout":992,"title":5,"description":989,"outline":993,"order":994,"navigation":995},"doc",[981,988],7,{"title":722,"icon":996},"i-iconoir-database",{"layout":992,"outline":998},[981,988],{"title":722,"icon":996},"\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Fstorage",{"title":5,"description":989},{"loc":1000},"kubb-labs\u002Fkubb\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Fstorage.md","docs\u002F5.x\u002Freference\u002Fkit\u002Fstorage","3piE_TS65maCFgxL44NsXIvGtmWvW2rzUejZUFNRv4Q",1795989038030,"2e8b4c62-5b8c-4587-97c0-530d08a9bd53"]