|
1 | 1 | import {note,debug,colors,when,stash,flip,functor,string,not,pattern,revert,each,describe,clock,observe,is,has,same,minor,slip,something,compound,infer,tether,whether,collect,provide,buffer,differ,compose,combine,either,drop,crop,swap,wait,exit,pass,binary,simple,array,expect} from "./Blik_2023_inference.js"; |
2 | | - import {thread,resolve,access,locate,prompt,list,window,jsdom,fetch,digest,persist,version,compress,stage,cookies,cookie,feature} from "./Blik_2023_interface.js"; |
| 2 | + import {loader,resolve,access,locate,prompt,list,window,jsdom,fetch,digest,persist,version,compress,stage,cookies,cookie,feature} from "./Blik_2023_interface.js"; |
3 | 3 | import {search,merge,sum,prune,extract,encrypt,record,remember,route} from "./Blik_2023_search.js"; |
4 | 4 | import {mime,bytes} from "./Blik_2023_meta.js"; |
5 | 5 | import {document} from "./Blik_2023_fragment.js"; |
|
11 | 11 | let [module,...fields]=string(protocol)?await locate(protocol.split("/")):[protocol]; |
12 | 12 | let [{default:routes,relay,syndication,encryption,classify,classified,published,permit},{default:credentials}]= |
13 | 13 | await [source,module].reduce(record(module=> |
14 | | - string(module)?resolve(module):{default:module}),[]); |
| 14 | + string(module)?resolve.bind(import.meta.url)(module):{default:module}),[]); |
15 | 15 | let {network,port,certification={},distinguishedname,cache}=note(search.call(credentials,fields)); |
16 | | - let agent=await resolve(network); |
| 16 | + let agent=await resolve.bind(import.meta.url)(network); |
17 | 17 | let [[domain,[signature,certificate]=[]]=[]]=Object.entries(certification); |
18 | 18 | let [encrypted,syndicated]=await [encryption,syndication].reduce(record(required=> |
19 | 19 | required?prompt(extract.call(credentials,Object.keys(required))):{}),[]); |
|
23 | 23 | merge(certification,required&&{[domain]:[signature,certificate]}); |
24 | 24 | merge(encryption,prune.call(encrypted,([field,value])=>encrypt(value))); |
25 | 25 | merge(globalThis,{cache,published,classified,classify}); |
26 | | - let certificates=Object.values(certification).flat().map(compose(crop(1),slip("path","resolve"),resolve)); |
| 26 | + let certificates=Object.values(certification).flat().map(compose(crop(1),slip("path","resolve"),resolve.bind(import.meta.url))); |
27 | 27 | await classify?.(module,...certificates); |
28 | 28 | // send jsdom composition to loader thread too so it can fetch modules from this interface during eg. server-side rendering. |
29 | 29 | let origin=agent.globalAgent.protocol+"//localhost"+":"+port; |
30 | | - delegate.call(thread,[[origin],"interface/jsdom"]); |
| 30 | + delegate.call(loader,[[origin],"interface/jsdom"]); |
31 | 31 | jsdom(origin); |
32 | 32 | let certifications=prune.call(certification,([domain,certificates])=> |
33 | 33 | certify(certificates,distinguishedname,[domain]),0,0); |
34 | | - // if(await resolve("cluster","isMaster"))return fork(); |
| 34 | + // if(await resolve.bind(import.meta.url)("cluster","isMaster"))return fork(); |
35 | 35 | var router=compose(combine(whether |
36 | 36 | (compose("url",/^http/,"match"),fetch |
37 | 37 | ,compose(combine(path,infer()),buffer(route.bind(routes),either(tether(routes.error),crop(1)))) |
|
56 | 56 | // for self-signed certificates, assign them to the NODE_EXTRA_CA_CERTS option. |
57 | 57 | pass(compose(domain,certification,"addContext"))) |
58 | 58 | ,pass(host=>note.call(2,[host._connectionKey||port," open"].join(""))) |
59 | | -,pass(compose(relay,broadcast,resolve)) |
| 59 | +,pass(compose(relay,broadcast,resolve.bind(import.meta.url))) |
60 | 60 | ,revert((close,error,channel)=>observe.call(channel,{close,error})&&suspend||close(channel)) |
61 | 61 | )(agent,Object.values(certifications)[0],buffer(respond,compose(note,exit))); |
62 | 62 | }; |
|
112 | 112 | async function fork() |
113 | 113 | {// https://github.com/nodejs/node/issues/35158 |
114 | 114 | //if(!process.argv[1])process.argv[1]=import.meta.url; |
115 | | - await resolve("cluster","on","exit",(worker,code,signal)=>note.call(code,worker.process.id+" exited with status "+code)); |
| 115 | + await resolve.bind(import.meta.url)("cluster","on","exit",(worker,code,signal)=>note.call(code,worker.process.id+" exited with status "+code)); |
116 | 116 | let os=await import("os"); |
117 | 117 | let cpus=note(os.cpus()); |
118 | 118 | if(!cpus.length) |
119 | 119 | cpus=[{model:os.platform()}]; |
120 | 120 | return cpus.reduce(record((cpu,index,cpus)=> |
121 | | - compose.call("cluster","fork",resolve,pass(compose |
| 121 | + compose.call("cluster","fork",resolve.bind(import.meta.url),pass(compose |
122 | 122 | ("id",cpus.length+" "+cpu.model+(!cpus[index+1]?"":"\nnext fork in a second..."),collect,"/","join",note.bind(1) |
123 | 123 | )),wait(index*1000))) |
124 | 124 | ,[]); |
|
137 | 137 | async function certify(certification,distinguishedname,altnames,duration=1) |
138 | 138 | {if(!certification) |
139 | 139 | return []; |
140 | | - let [path,url]=await resolve(["path","url"]); |
| 140 | + let [path,url]=await resolve.bind(import.meta.url)(["path","url"]); |
141 | 141 | let location=path.dirname(url.fileURLToPath(import.meta.url)); |
142 | 142 | let [key,cert]=await Promise.all(certification.map(certificate=> |
143 | 143 | buffer(access,swap(null))(path.resolve(location,certificate),true))); |
|
160 | 160 | {[key.match(/^[A-Z]{2}$/)?"shortName":"name"]:key,value})); |
161 | 161 | let altnames={name:"subjectAltName",altNames:[{type:2,value:"localhost"},{type:7,ip:"127.0.0.1"}]};//,{type:6,value:"https://"+distinguishedname.commonName}]}; |
162 | 162 | let certificate=this.pki.createCertificate(); |
163 | | - let asn1=await resolve("crypto","randomBytes",19).then(infer("toString","hex")); |
| 163 | + let asn1=await resolve.bind(import.meta.url)("crypto","randomBytes",19).then(infer("toString","hex")); |
164 | 164 | Object.assign(certificate,{publicKey,serialNumber:"01"+asn1}); |
165 | 165 | Object.assign(certificate.validity,{notBefore:new Date(),notAfter:new Date()}); |
166 | 166 | certificate.validity.notAfter.setFullYear(certificate.validity.notBefore.getFullYear()+duration); |
|
181 | 181 |
|
182 | 182 | async function authorize({privateKey,publicKey},distinguishedname) |
183 | 183 | {let encryption=this.rsa.generateKeyPair(2048); |
184 | | - let hash=compose(stash(compose(drop(),"crypto","createHash","sha256",resolve)),flip,"update","digest"); |
| 184 | + let hash=compose(stash(compose(drop(),"crypto","createHash","sha256",resolve.bind(import.meta.url))),flip,"update","digest"); |
185 | 185 | let {asn1:{Class:{UNIVERSAL},Type:{SEQUENCE,OID,NULL,OCTETSTRING}}}=this; |
186 | 186 | let SHA256identifier=this.asn1.create(UNIVERSAL,SEQUENCE,true, |
187 | 187 | [this.asn1.oidToDer(this.oids.sha256).getBytes(),'' |
|
285 | 285 | ({name,icon:"/svg/animal/"+name+"/document"})); |
286 | 286 |
|
287 | 287 | export async function traverse(source) |
288 | | -{let {default:{interface:html,...routes}}=await resolve(source); |
| 288 | +{let {default:{interface:html,...routes}}=await resolve.bind(import.meta.url)(source); |
289 | 289 | if(!functor(html)) |
290 | 290 | return; |
291 | 291 | return prune.call(routes,([field,value],path)=> |
|
0 commit comments