[{"data":1,"prerenderedAt":582},["ShallowReactive",2],{"content-\u002Freference\u002F0.4.x\u002Fimports":3,"use-cases-nav":575},{"id":4,"title":5,"author":6,"body":7,"date":6,"description":567,"extension":568,"meta":569,"navigation":53,"order":50,"path":570,"seo":571,"stem":572,"version":573,"__hash__":574},"content\u002Freference\u002F0.4.x\u002Fimports.md","Imports",null,{"type":8,"value":9,"toc":558},"minimark",[10,19,75,80,83,94,113,117,128,146,166,176,181,184,241,313,319,323,330,377,424,437,463,473,477,480,509,531,535,538,554],[11,12,13,14,18],"p",{},"Since 0.4 a schema can be split across several files and pull definitions from\nelsewhere. An import is a line starting with ",[15,16,17],"code",{},"@import",", and imports come\nfirst, before any type definition:",[20,21,26],"pre",{"className":22,"code":23,"language":24,"meta":25,"style":25},"language-finitio shiki shiki-themes github-light github-dark","@import finitio\u002Fdata\n@import .\u002Fmeasures\n\n{ taken: Date, values: [Measure] }\n","finitio","",[15,27,28,40,48,55],{"__ignoreMap":25},[29,30,33,36],"span",{"class":31,"line":32},"line",1,[29,34,17],{"class":35},"szBVR",[29,37,39],{"class":38},"sZZnC"," finitio\u002Fdata\n",[29,41,43,45],{"class":31,"line":42},2,[29,44,17],{"class":35},[29,46,47],{"class":38}," .\u002Fmeasures\n",[29,49,51],{"class":31,"line":50},3,[29,52,54],{"emptyLinePlaceholder":53},true,"\n",[29,56,58,62,66,69,72],{"class":31,"line":57},4,[29,59,61],{"class":60},"sVt8B","{ taken: ",[29,63,65],{"class":64},"sj4cs","Date",[29,67,68],{"class":60},", values: [",[29,70,71],{"class":64},"Measure",[29,73,74],{"class":60},"] }\n",[76,77,79],"h2",{"id":78},"the-standard-library","The standard library",[11,81,82],{},"The most common import by far, and the one nearly every 0.4 schema starts\nwith:",[20,84,86],{"className":22,"code":85,"language":24,"meta":25,"style":25},"@import finitio\u002Fdata\n",[15,87,88],{"__ignoreMap":25},[29,89,90,92],{"class":31,"line":32},[29,91,17],{"class":35},[29,93,39],{"class":38},[11,95,96,97,100,101,100,104,106,107,112],{},"It brings ",[15,98,99],{},"String",", ",[15,102,103],{},"Integer",[15,105,65],{}," and the rest into scope. See the\n",[108,109,111],"a",{"href":110},"\u002Freference\u002F0.4.x\u002Fstdlib","standard library"," for what it contains and where the\ntwo implementations differ.",[76,114,116],{"id":115},"relative-imports","Relative imports",[11,118,119,120,123,124,127],{},"A path starting with ",[15,121,122],{},".\u002F"," or ",[15,125,126],{},"..\u002F"," is resolved relative to the file the schema\nwas loaded from:",[20,129,131],{"className":22,"code":130,"language":24,"meta":25,"style":25},"@import .\u002Fmeasures\n@import ..\u002Fshared\u002Funits\n",[15,132,133,139],{"__ignoreMap":25},[29,134,135,137],{"class":31,"line":32},[29,136,17],{"class":35},[29,138,47],{"class":38},[29,140,141,143],{"class":31,"line":42},[29,142,17],{"class":35},[29,144,145],{"class":38}," ..\u002Fshared\u002Funits\n",[11,147,148,149,153,154,157,158,161,162,165],{},"Write the path ",[150,151,152],"strong",{},"without"," the ",[15,155,156],{},".fio"," extension. The extension is added by the\nresolver, so ",[15,159,160],{},"@import .\u002Fmeasures.fio"," looks for ",[15,163,164],{},"measures.fio.fio"," and fails.",[167,168,170],"impl-note",{"impl":169},"finitio.js",[11,171,172,173,175],{},"finitio.js tolerates the ",[15,174,156],{}," extension; finitio-rb does not. Leave it off\nand the import works in both. Note that finitio-rb's README currently shows\nthe extension form — it does not work in 0.12.0.",[177,178,180],"h3",{"id":179},"relative-to-what","Relative to what?",[11,182,183],{},"A relative import needs to know where the schema came from, and a schema\nparsed from a bare string does not. Load it from a file instead:",[20,185,189],{"className":186,"code":187,"language":188,"meta":25,"style":25},"language-ruby shiki shiki-themes github-light github-dark","# Ruby\nrequire 'pathname'\nsystem = Finitio.system(Pathname.new('schemas\u002Fparent.fio'))\n","ruby",[15,190,191,197,205],{"__ignoreMap":25},[29,192,193],{"class":31,"line":32},[29,194,196],{"class":195},"sJ8bj","# Ruby\n",[29,198,199,202],{"class":31,"line":42},[29,200,201],{"class":35},"require",[29,203,204],{"class":38}," 'pathname'\n",[29,206,207,211,214,217,220,222,225,228,230,233,235,238],{"class":31,"line":50},[29,208,210],{"class":209},"s4XuR","system",[29,212,213],{"class":35}," =",[29,215,216],{"class":64}," Finitio",[29,218,219],{"class":60},".",[29,221,210],{"class":64},[29,223,224],{"class":60},"(",[29,226,227],{"class":64},"Pathname",[29,229,219],{"class":60},[29,231,232],{"class":35},"new",[29,234,224],{"class":60},[29,236,237],{"class":38},"'schemas\u002Fparent.fio'",[29,239,240],{"class":60},"))\n",[20,242,246],{"className":243,"code":244,"language":245,"meta":25,"style":25},"language-javascript shiki shiki-themes github-light github-dark","\u002F\u002F JavaScript\nconst world = Finitio.world({ sourceUrl: `file:\u002F\u002F${path}` })\nconst system = Finitio.system(fs.readFileSync(path, 'utf8'), world)\n","javascript",[15,247,248,253,285],{"__ignoreMap":25},[29,249,250],{"class":31,"line":32},[29,251,252],{"class":195},"\u002F\u002F JavaScript\n",[29,254,255,258,261,263,266,270,273,276,279,282],{"class":31,"line":42},[29,256,257],{"class":35},"const",[29,259,260],{"class":64}," world",[29,262,213],{"class":35},[29,264,265],{"class":60}," Finitio.",[29,267,269],{"class":268},"sScJk","world",[29,271,272],{"class":60},"({ sourceUrl: ",[29,274,275],{"class":38},"`file:\u002F\u002F${",[29,277,278],{"class":60},"path",[29,280,281],{"class":38},"}`",[29,283,284],{"class":60}," })\n",[29,286,287,289,292,294,296,298,301,304,307,310],{"class":31,"line":50},[29,288,257],{"class":35},[29,290,291],{"class":64}," system",[29,293,213],{"class":35},[29,295,265],{"class":60},[29,297,210],{"class":268},[29,299,300],{"class":60},"(fs.",[29,302,303],{"class":268},"readFileSync",[29,305,306],{"class":60},"(path, ",[29,308,309],{"class":38},"'utf8'",[29,311,312],{"class":60},"), world)\n",[11,314,315,316,219],{},"Passing the source as a plain string with no context raises an error such as\n",[15,317,318],{},"Unable to resolve '.\u002Fmeasures'",[76,320,322],{"id":321},"imports-are-not-re-exported","Imports are not re-exported",[11,324,325,326,329],{},"An imported type is usable inside the importing schema, but is ",[150,327,328],{},"not"," passed\non to schemas that in turn import it. Given:",[20,331,333],{"className":22,"code":332,"language":24,"meta":25,"style":25},"# child.fio\n@import finitio\u002Fdata\nPosint = Integer( i | i >= 0 )\n",[15,334,335,340,346],{"__ignoreMap":25},[29,336,337],{"class":31,"line":32},[29,338,339],{"class":195},"# child.fio\n",[29,341,342,344],{"class":31,"line":42},[29,343,17],{"class":35},[29,345,39],{"class":38},[29,347,348,351,353,356,359,362,365,368,371,374],{"class":31,"line":50},[29,349,350],{"class":268},"Posint",[29,352,213],{"class":35},[29,354,355],{"class":64}," Integer",[29,357,358],{"class":60},"( ",[29,360,361],{"class":209},"i",[29,363,364],{"class":35}," |",[29,366,367],{"class":60}," i ",[29,369,370],{"class":35},">=",[29,372,373],{"class":64}," 0",[29,375,376],{"class":60}," )\n",[20,378,380],{"className":22,"code":379,"language":24,"meta":25,"style":25},"# parent.fio\n@import .\u002Fchild\nByte = Posint( i | i \u003C= 255 )     # fine: Posint is in scope here\n",[15,381,382,387,394],{"__ignoreMap":25},[29,383,384],{"class":31,"line":32},[29,385,386],{"class":195},"# parent.fio\n",[29,388,389,391],{"class":31,"line":42},[29,390,17],{"class":35},[29,392,393],{"class":38}," .\u002Fchild\n",[29,395,396,399,401,404,406,408,410,412,415,418,421],{"class":31,"line":50},[29,397,398],{"class":268},"Byte",[29,400,213],{"class":35},[29,402,403],{"class":64}," Posint",[29,405,358],{"class":60},[29,407,361],{"class":209},[29,409,364],{"class":35},[29,411,367],{"class":60},[29,413,414],{"class":35},"\u003C=",[29,416,417],{"class":64}," 255",[29,419,420],{"class":60}," )     ",[29,422,423],{"class":195},"# fine: Posint is in scope here\n",[11,425,426,427,430,431,433,434,436],{},"then a third schema importing ",[15,428,429],{},"parent"," sees ",[15,432,398],{}," but not ",[15,435,350],{},":",[20,438,440],{"className":22,"code":439,"language":24,"meta":25,"style":25},"@import .\u002Fparent\nByte      # fine\nPosint    # error: No such type `Posint`\n",[15,441,442,449,456],{"__ignoreMap":25},[29,443,444,446],{"class":31,"line":32},[29,445,17],{"class":35},[29,447,448],{"class":38}," .\u002Fparent\n",[29,450,451,453],{"class":31,"line":42},[29,452,398],{"class":64},[29,454,455],{"class":195},"      # fine\n",[29,457,458,460],{"class":31,"line":50},[29,459,350],{"class":64},[29,461,462],{"class":195},"    # error: No such type `Posint`\n",[11,464,465,466,468,469,472],{},"This keeps a schema's surface deliberate: what a file exports is what it\ndefines, not everything it happens to depend on. If ",[15,467,350],{}," should be part of\nthe public surface of ",[15,470,471],{},"parent.fio",", define an alias for it there.",[76,474,476],{"id":475},"qualified-imports","Qualified imports",[11,478,479],{},"An import can be given a qualifier, so its definitions are reached through a\nprefix rather than merged into the current scope:",[20,481,483],{"className":22,"code":482,"language":24,"meta":25,"style":25},"@import finitio\u002Fdata as d\n\n{ name: d.String }\n",[15,484,485,495,499],{"__ignoreMap":25},[29,486,487,489,492],{"class":31,"line":32},[29,488,17],{"class":35},[29,490,491],{"class":38}," finitio\u002Fdata",[29,493,494],{"class":60}," as d\n",[29,496,497],{"class":31,"line":42},[29,498,54],{"emptyLinePlaceholder":53},[29,500,501,504,506],{"class":31,"line":50},[29,502,503],{"class":60},"{ name: d.",[29,505,99],{"class":64},[29,507,508],{"class":60}," }\n",[167,510,511],{"impl":169},[11,512,513,514,517,518,522,523,526,527,530],{},"finitio-rb does not parse the ",[15,515,516],{},"as"," form. Use a plain import and rely on the\n",[108,519,521],{"href":520},"\u002Freference\u002F0.4.x\u002Ftype-system","dotted naming convention"," — ",[15,524,525],{},"People.Type",",\n",[15,528,529],{},"People.Attrs"," — when you need to group related definitions portably.",[76,532,534],{"id":533},"bundling","Bundling",[11,536,537],{},"Imports are resolved when the schema is loaded, which means the files must be\nreachable at that moment. That is fine on a server and awkward in a browser,\nwhere there is no filesystem.",[167,539,540,543,551],{"impl":169},[11,541,542],{},"finitio.js can flatten a schema and everything it imports into a single\nartefact ahead of time:",[20,544,549],{"className":545,"code":547,"language":548},[546],"language-text","finitio bundle schema.fio -t javascript > schema.js\n","text",[15,550,547],{"__ignoreMap":25},[11,552,553],{},"The result carries no imports and needs no resolver at runtime. A TypeScript\ntarget is available too, which additionally emits type declarations matching\nthe schema.",[555,556,557],"style",{},"html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sJ8bj, html code.shiki .sJ8bj{--shiki-default:#6A737D;--shiki-dark:#6A737D}html pre.shiki code .s4XuR, html code.shiki .s4XuR{--shiki-default:#E36209;--shiki-dark:#FFAB70}html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}",{"title":25,"searchDepth":50,"depth":50,"links":559},[560,561,564,565,566],{"id":78,"depth":42,"text":79},{"id":115,"depth":42,"text":116,"children":562},[563],{"id":179,"depth":50,"text":180},{"id":321,"depth":42,"text":322},{"id":475,"depth":42,"text":476},{"id":533,"depth":42,"text":534},"Finitio 0.4 imports: splitting a schema across files and reusing definitions.","md",{},"\u002Freference\u002F0.4.x\u002Fimports",{"title":5,"description":567},"reference\u002F0.4.x\u002Fimports","0.4.x","e5TYFYnEoLjXmdBxuAF-43B79p2T3LbZG1LSzpJP2_8",[576,579],{"path":577,"title":578},"\u002Fuse-cases","Use cases",{"path":580,"title":581},"\u002Fuse-cases\u002Fcleaning-csv-files","Cleaning .csv files",1786026251330]