[{"data":1,"prerenderedAt":742},["ShallowReactive",2],{"page:\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Fstorage":3},{"id":4,"title":5,"body":6,"description":724,"extension":725,"frontmatter":726,"heading":5,"meta":733,"navigation":735,"order":730,"path":736,"seo":737,"sitemap":738,"source":739,"stem":740,"__hash__":741},"docs\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Fstorage.md","Storage",{"type":7,"value":8,"toc":714},"minimark",[9,13,21,34,516,522,525,647,667,679,684,693,698,703],[10,11,12],"p",{},"Storage backends persist generated files in the filesystem, memory, or a custom destination.",[14,15,17],"h2",{"id":16},"createstorage",[18,19,20],"code",{},"createStorage",[10,22,23,25,26,29,30,33],{},[18,24,20],{}," takes a builder function ",[18,27,28],{},"(options: TOptions) => Storage"," and returns a factory ",[18,31,32],{},"(options?: TOptions) => Storage",". Call the returned factory to create a backend.",[35,36,41],"pre",{"language":37,"filename":38,"code":39,"class":40},"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      if (!base) return store.clear()\n      for (const k of store.keys()) if (k.startsWith(base)) store.delete(k)\n    },\n  }\n})","highlights",[18,42,44,71,72,71,74,71,100,71,135,71,144,71,161,71,180,71,209,71,218,71,238,71,260,71,267,71,282,71,299,71,305,71,321,71,348,71,395,71,403,71,418,71,445,71,499,71,505,71,511],{"class":43},"language-typescript",[45,46,49,53,57,61,64,67],"span",{"class":47,"style":48},"line","display: inline",[45,50,52],{"style":51},"color:#d73a49;--hls-dark:#f97583","import ",[45,54,56],{"style":55},"color:#005cc5;--hls-dark:#79b8ff","{ ",[45,58,60],{"style":59},"color:#24292e;--hls-dark:#e1e4e8","createStorage ",[45,62,63],{"style":55},"} ",[45,65,66],{"style":51},"from ",[45,68,70],{"style":69},"color:#032f62;--hls-dark:#9ecbff","'kubb\u002Fkit'","\n",[45,73],{"class":47,"style":48},[45,75,76,79,82,85,88,91,94,97],{"class":47,"style":48},[45,77,78],{"style":51},"export ",[45,80,81],{"style":51},"const ",[45,83,84],{"style":59},"memoryStorage ",[45,86,87],{"style":51},"= ",[45,89,20],{"style":90},"color:#6f42c1;--hls-dark:#b392f0",[45,92,93],{"style":55},"(() ",[45,95,96],{"style":51},"=> ",[45,98,99],{"style":55},"{",[45,101,102,105,107,110,112,115,118,121,124,127,129,132],{"class":47,"style":48},[45,103,104],{"style":55},"  ",[45,106,81],{"style":51},[45,108,109],{"style":59},"store ",[45,111,87],{"style":51},[45,113,114],{"style":51},"new ",[45,116,117],{"style":90},"Map",[45,119,120],{"style":51},"\u003C",[45,122,123],{"style":59},"string",[45,125,126],{"style":51},", ",[45,128,123],{"style":59},[45,130,131],{"style":51},">",[45,133,134],{"style":55},"()",[45,136,137,139,142],{"class":47,"style":48},[45,138,104],{"style":55},[45,140,141],{"style":51},"return ",[45,143,99],{"style":55},[45,145,146,149,152,155,158],{"class":47,"style":48},[45,147,148],{"style":55},"    ",[45,150,151],{"style":55},"name",[45,153,154],{"style":51},": ",[45,156,157],{"style":69},"'memory'",[45,159,160],{"style":51},",",[45,162,163,165,168,171,174,177],{"class":47,"style":48},[45,164,148],{"style":51},[45,166,167],{"style":51},"async ",[45,169,170],{"style":90},"readItem",[45,172,173],{"style":55},"(",[45,175,176],{"style":59},"key",[45,178,179],{"style":55},") {",[45,181,182,185,187,190,193,196,198,200,203,206],{"class":47,"style":48},[45,183,184],{"style":55},"      ",[45,186,141],{"style":51},[45,188,189],{"style":59},"store",[45,191,192],{"style":51},".",[45,194,195],{"style":90},"get",[45,197,173],{"style":55},[45,199,176],{"style":59},[45,201,202],{"style":55},") ",[45,204,205],{"style":51},"?? ",[45,207,208],{"style":55},"null",[45,210,211,213,216],{"class":47,"style":48},[45,212,148],{"style":55},[45,214,215],{"style":55},"}",[45,217,160],{"style":51},[45,219,220,222,224,227,229,231,233,236],{"class":47,"style":48},[45,221,148],{"style":51},[45,223,167],{"style":51},[45,225,226],{"style":90},"writeItem",[45,228,173],{"style":55},[45,230,176],{"style":59},[45,232,126],{"style":51},[45,234,235],{"style":59},"value",[45,237,179],{"style":55},[45,239,240,242,244,246,249,251,253,255,257],{"class":47,"style":48},[45,241,184],{"style":55},[45,243,189],{"style":59},[45,245,192],{"style":51},[45,247,248],{"style":90},"set",[45,250,173],{"style":55},[45,252,176],{"style":59},[45,254,126],{"style":51},[45,256,235],{"style":59},[45,258,259],{"style":55},")",[45,261,262,265],{"class":47,"style":48},[45,263,264],{"style":55},"    }",[45,266,160],{"style":51},[45,268,269,271,273,276,278,280],{"class":47,"style":48},[45,270,148],{"style":51},[45,272,167],{"style":51},[45,274,275],{"style":90},"removeItem",[45,277,173],{"style":55},[45,279,176],{"style":59},[45,281,179],{"style":55},[45,283,284,286,288,290,293,295,297],{"class":47,"style":48},[45,285,184],{"style":55},[45,287,189],{"style":59},[45,289,192],{"style":51},[45,291,292],{"style":90},"delete",[45,294,173],{"style":55},[45,296,176],{"style":59},[45,298,259],{"style":55},[45,300,301,303],{"class":47,"style":48},[45,302,264],{"style":55},[45,304,160],{"style":51},[45,306,307,309,311,314,316,319],{"class":47,"style":48},[45,308,148],{"style":51},[45,310,167],{"style":51},[45,312,313],{"style":90},"readKeys",[45,315,173],{"style":55},[45,317,318],{"style":59},"base",[45,320,179],{"style":55},[45,322,323,325,327,330,332,335,338,340,342,345],{"class":47,"style":48},[45,324,184],{"style":55},[45,326,81],{"style":51},[45,328,329],{"style":59},"keys ",[45,331,87],{"style":51},[45,333,334],{"style":55},"[",[45,336,337],{"style":51},"...",[45,339,189],{"style":59},[45,341,192],{"style":51},[45,343,344],{"style":90},"keys",[45,346,347],{"style":55},"()]",[45,349,350,352,354,357,360,362,364,367,370,373,375,377,379,381,384,386,388,391,393],{"class":47,"style":48},[45,351,184],{"style":55},[45,353,141],{"style":51},[45,355,356],{"style":59},"base ",[45,358,359],{"style":51},"? ",[45,361,344],{"style":59},[45,363,192],{"style":51},[45,365,366],{"style":90},"filter",[45,368,369],{"style":55},"((",[45,371,372],{"style":59},"k",[45,374,202],{"style":55},[45,376,96],{"style":51},[45,378,372],{"style":59},[45,380,192],{"style":51},[45,382,383],{"style":90},"startsWith",[45,385,173],{"style":55},[45,387,318],{"style":59},[45,389,390],{"style":55},")) ",[45,392,154],{"style":51},[45,394,344],{"style":59},[45,396,397,399,401],{"class":47,"style":48},[45,398,148],{"style":59},[45,400,215],{"style":55},[45,402,160],{"style":51},[45,404,405,407,409,412,414,416],{"class":47,"style":48},[45,406,148],{"style":51},[45,408,167],{"style":51},[45,410,411],{"style":90},"empty",[45,413,173],{"style":55},[45,415,318],{"style":59},[45,417,179],{"style":55},[45,419,420,422,425,427,430,432,434,436,438,440,443],{"class":47,"style":48},[45,421,184],{"style":55},[45,423,424],{"style":51},"if ",[45,426,173],{"style":55},[45,428,429],{"style":51},"!",[45,431,318],{"style":59},[45,433,202],{"style":55},[45,435,141],{"style":51},[45,437,189],{"style":59},[45,439,192],{"style":51},[45,441,442],{"style":90},"clear",[45,444,134],{"style":55},[45,446,447,449,452,454,456,459,462,464,466,468,471,473,475,477,479,481,483,485,487,489,491,493,495,497],{"class":47,"style":48},[45,448,184],{"style":55},[45,450,451],{"style":51},"for ",[45,453,173],{"style":55},[45,455,81],{"style":51},[45,457,458],{"style":59},"k ",[45,460,461],{"style":51},"of ",[45,463,189],{"style":59},[45,465,192],{"style":51},[45,467,344],{"style":90},[45,469,470],{"style":55},"()) ",[45,472,424],{"style":51},[45,474,173],{"style":55},[45,476,372],{"style":59},[45,478,192],{"style":51},[45,480,383],{"style":90},[45,482,173],{"style":55},[45,484,318],{"style":59},[45,486,390],{"style":55},[45,488,189],{"style":59},[45,490,192],{"style":51},[45,492,292],{"style":90},[45,494,173],{"style":55},[45,496,372],{"style":59},[45,498,259],{"style":55},[45,500,501,503],{"class":47,"style":48},[45,502,264],{"style":55},[45,504,160],{"style":51},[45,506,507,509],{"class":47,"style":48},[45,508,104],{"style":51},[45,510,215],{"style":55},[45,512,513],{"class":47,"style":48},[45,514,515],{"style":55},"})",[14,517,519,521],{"id":518},"storage-interface",[18,520,5],{}," interface",[10,523,524],{},"The engine consumes this interface and exposes the backend through the build result.",[526,527,528,547],"table",{},[529,530,531],"thead",{},[532,533,534,538,541,544],"tr",{},[535,536,537],"th",{},"Method",[535,539,540],{},"Params",[535,542,543],{},"Returns",[535,545,546],{},"Purpose",[548,549,550,571,591,609,629],"tbody",{},[532,551,552,558,563,568],{},[553,554,555],"td",{},[18,556,557],{},"readItem()",[553,559,560],{},[18,561,562],{},"key: string",[553,564,565],{},[18,566,567],{},"Promise\u003Cstring | null>",[553,569,570],{},"Retrieve an item's content",[532,572,573,578,583,588],{},[553,574,575],{},[18,576,577],{},"writeItem()",[553,579,580],{},[18,581,582],{},"key: string, value: string",[553,584,585],{},[18,586,587],{},"Promise\u003Cvoid>",[553,589,590],{},"Write an item",[532,592,593,598,602,606],{},[553,594,595],{},[18,596,597],{},"removeItem()",[553,599,600],{},[18,601,562],{},[553,603,604],{},[18,605,587],{},[553,607,608],{},"Delete an item",[532,610,611,616,621,626],{},[553,612,613],{},[18,614,615],{},"readKeys()",[553,617,618],{},[18,619,620],{},"base?: string",[553,622,623],{},[18,624,625],{},"Promise\u003Cstring[]>",[553,627,628],{},"List keys, optionally filtered by prefix",[532,630,631,636,640,644],{},[553,632,633],{},[18,634,635],{},"empty()",[553,637,638],{},[18,639,620],{},[553,641,642],{},[18,643,587],{},[553,645,646],{},"Delete all items, optionally scoped by prefix",[10,648,649,650,652,653,655,656,659,660,663,664,666],{},"Omitting ",[18,651,318],{}," on ",[18,654,635],{}," is implementation-defined. ",[18,657,658],{},"memoryStorage"," wipes every entry, while the filesystem-backed ",[18,661,662],{},"fsStorage"," treats a missing ",[18,665,318],{}," as a no-op and deletes nothing.",[10,668,669,670,672,673,675,676,678],{},"Every method is required. ",[18,671,170],{}," returns ",[18,674,208],{}," for a missing key. Kubb can skip ",[18,677,226],{}," for a file whose content did not change, so do not expect one call per generated file.",[14,680,682],{"id":681},"fsstorage",[18,683,662],{},[10,685,686,688,689,692],{},[18,687,662],{}," is the default backend. It writes under ",[18,690,691],{},"output.path"," and creates directories as needed.",[14,694,696],{"id":695},"memorystorage",[18,697,658],{},[10,699,700,702],{},[18,701,658],{}," writes nothing to disk, so it suits plugin tests, CI validation, and dry runs.",[10,704,705,706,709,710,713],{},"Both ship from ",[18,707,708],{},"kubb\u002Fkit"," and go straight into the config's ",[18,711,712],{},"storage"," field.",{"title":715,"searchDepth":716,"depth":716,"links":717},"",5,[718,720,722,723],{"id":16,"depth":719,"text":20},2,{"id":518,"depth":719,"text":721},"Storage interface",{"id":681,"depth":719,"text":662},{"id":695,"depth":719,"text":658},"Storage backends decide where generated files are written. Covers createStorage, the Storage interface, and the built-in fsStorage and memoryStorage backends.","md",{"layout":727,"title":5,"description":724,"outline":728,"order":730,"navigation":731},"doc",[719,729],3,7,{"title":5,"icon":732},"i-iconoir-database",{"layout":727,"outline":734},[719,729],{"title":5,"icon":732},"\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Fstorage",{"title":5,"description":724},{"loc":736},"kubb-labs\u002Fkubb\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Fstorage.md","docs\u002F5.x\u002Freference\u002Fkit\u002Fstorage","6Kz-YYz6oL6yemBAyPc0UhxsDX3X5bQzWMeiqOY8tSI",1792931645330]