planx 20.85.0 → 20.87.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/domain.main.mjs CHANGED
@@ -1,4 +1,4 @@
1
- globalThis.__PLANX_SERVICE_VERSION__="20.85.0";
1
+ globalThis.__PLANX_SERVICE_VERSION__="20.87.0";
2
2
  import { createRequire } from 'module';
3
3
  const require = createRequire(import.meta.url);
4
4
 
@@ -505,7 +505,7 @@ ${I.typeDefs}`:"");try{let F={schema:(0,TB.buildSchema)(r),tables:e,docs:new Map
505
505
 
506
506
  `)})},cancel(){C?.(),C=null}});return new Response(i.pipeThrough(new TextEncoderStream),{headers:{"content-type":"text/event-stream","cache-control":"no-cache"}})})}var FN=$g(PI());var wN=$g(PI());var z0=$g(PI());var $H="http://do.internal";async function $0(A,g,I,Q){let C=await So(A,g,{method:Q.method,url:`${$H}${Q.path}`,headers:{...I?{[lo]:I}:{},...Q.headers},body:Q.body});if(typeof C=="string")throw new Error(`[domain-gateway] ${g} ${Q.path}: ${C}`);return{status:C.response.status,body:await W0(C)}}function AN(A,g,I){return async({document:Q,variables:C})=>{let{status:B,body:i}=await $0(A,g,I,{method:"POST",path:"/graphql",headers:{"content-type":"application/json",[O0]:v0},body:JSON.stringify({query:(0,z0.print)(Q),variables:C})});if(B>=400)throw new Error(`[domain-gateway] ${g} /graphql failed: ${B}`);return JSON.parse(i)}}function gN(A,g,I){return async()=>{let{status:Q,body:C}=await $0(A,g,I,{method:"GET",path:"/federation"});if(Q>=300)return[];try{let B=JSON.parse(C);return Array.isArray(B?.joins)?B.joins:[]}catch{return[]}}}function Ap(A){return`${A.charAt(0).toUpperCase()}${A.slice(1)}`}function gp(A){return[...A].sort((g,I)=>g.name.localeCompare(I.name)).map(g=>({field:g.name,prefix:Ap(g.name),objectId:g.objectId}))}function IN(A,g){return gp(A.plugins()).map(I=>({field:I.field,prefix:I.prefix,executor:AN(A,I.objectId,g),federation:gN(A,I.objectId,g)}))}var hC=$g(PI());var jI=$g(PI()),ei="Domain";function ZQ(A){return new Set(Object.values(A.getTypeMap()).filter(g=>!g.name.startsWith("__")&&!(0,jI.isSpecifiedScalarType)(g)).map(g=>g.name))}function QN(A,g){return{...A,value:`${g}${A.value}`}}function CN(A,g){let I=A.getSubscriptionType()?.name;return[...ZQ(A)].filter(Q=>Q!==I).map(Q=>`${g}${Q}`)}function BN(A,g=ei){let I=ZQ(A),Q=A.getSubscriptionType()?.name,C=i=>i.name.value===Q?null:I.has(i.name.value)?{...i,name:QN(i.name,g)}:i,B=(0,jI.visit)((0,jI.parse)((0,jI.printSchema)(A)),{SchemaDefinition:()=>null,SchemaExtension:()=>null,NamedType:i=>I.has(i.name.value)?{...i,name:QN(i.name,g)}:void 0,ObjectTypeDefinition:C,InterfaceTypeDefinition:C,UnionTypeDefinition:C,EnumTypeDefinition:C,InputObjectTypeDefinition:C,ScalarTypeDefinition:C});return(0,jI.print)({...B,kind:jI.Kind.DOCUMENT})}function EN(A,g,I=ei){let Q=A.startsWith(I)?A.slice(I.length):A;return g.has(Q)?Q:A}var CI=$g(PI());function iN(A,g,I){(0,CI.visit)(A,{FragmentSpread(Q){let C=g[Q.name.value];C&&!I.has(C.name.value)&&(I.set(C.name.value,C),iN(C.selectionSet,g,I))}})}function Ip(A){let g=new Set;for(let I of A)(0,CI.visit)(I,{Variable(Q){g.add(Q.name.value)}});return g}function Qp(A,g,I){return(0,CI.visit)(A,{NamedType:Q=>({...Q,name:{...Q.name,value:EN(Q.name.value,g,I)}})})}function Xn(A,g,I=ei){let Q=A.fieldNodes[0],C=new Map;Q.selectionSet&&iN(Q.selectionSet,A.fragments,C);let B=Ip([Q,...C.values()]),i=(A.operation.variableDefinitions??[]).filter(r=>B.has(r.variable.name.value)),e={kind:CI.Kind.DOCUMENT,definitions:[{kind:CI.Kind.OPERATION_DEFINITION,operation:CI.OperationTypeNode.QUERY,variableDefinitions:i,selectionSet:{kind:CI.Kind.SELECTION_SET,selections:[Q]}},...C.values()]},t=Object.fromEntries(Object.entries(A.variableValues??{}).filter(([r])=>B.has(r)));return{document:Qp(e,g,I),variables:t}}function Cp(A,g){let[I,...Q]=A.definitions,C={kind:CI.Kind.SELECTION_SET,selections:I.selectionSet.selections},B={kind:CI.Kind.FIELD,name:{kind:CI.Kind.NAME,value:g},selectionSet:C};return{...A,definitions:[{...I,selectionSet:{kind:CI.Kind.SELECTION_SET,selections:[B]}},...Q]}}function zn(A,g,I=ei,Q,C=B=>B){let B=ZQ(g);return async(i,e,t,r)=>{let F=Xn(r,B,I),R=C(Q?Cp(F.document,Q):F.document),M=await A({document:R,variables:F.variables}),J=r.fieldNodes[0].alias?.value??r.fieldNodes[0].name.value,q=M.data,oA=Q?q?.[Q]:q,rA=oA?oA[J]:void 0,uA=M.errors??[];if(uA.length>0&&rA==null)throw new CI.GraphQLError(uA.map(xA=>xA.message).join("; "),{nodes:r.fieldNodes[0],path:(0,CI.responsePathAsArray)(r.path)});return Bp(rA,uA,Q?[Q,J]:[J]),rA??null}}function Bp(A,g,I){for(let Q of g){let C=Q.path??[];if(C.length<=I.length||I.some((e,t)=>C[t]!==e))continue;let B=C.slice(I.length),i=A;for(let e=0;e<B.length&&!(typeof i!="object"||i===null);e+=1){let t=i,r=t[B[e]];if(e===B.length-1||r===null||r===void 0){t[B[e]]=new CI.GraphQLError(Q.message);break}i=r}}}var Lo=$g(PI());var $n="session";function Aa(A,g,I){return A.replace(/[A-Za-z_][A-Za-z0-9_]*/g,Q=>g.has(Q)?`${I}${Q}`:Q)}function eN(A,g,I,Q,C){let B=A.getQueryType()?.getFields()[$n],i=B?(0,Lo.getNamedType)(B.type):null;if(!i||!(0,Lo.isObjectType)(i))return[];let e=ZQ(A),t=[];for(let r of Object.values(i.getFields())){if(I.has(r.name)){Q(`[domain-gateway] ${C} \u306E Session \u62E1\u5F35 ${r.name} \u3092\u7E2B\u308F\u306A\u3044 (\u65E2\u5B58\u306E field \u3068\u885D\u7A81)`);continue}I.add(r.name),t.push({name:r.name,type:Aa(String(r.type),e,g)})}return t}var kg=$g(PI());var oN=A=>`__planx_key_${A}`;async function tN(A,g){let I=[];for(let Q of A){let C=await Q.mount.federation?.().catch(()=>[])??[];for(let B of C){let i=A.find(R=>R.mount.field===B.plugin),e=Q.remote.getQueryType()?.getFields()[B.query],t=e?.args.find(R=>R.name===B.arg),r=i?.remote.getType(B.type),F=i?(0,kg.isObjectType)(r)?!e||!t?`${Q.mount.field} \u306B root field ${B.query}(${B.arg}) \u304C\u7121\u3044`:r.getFields()[B.field]?`${B.field} \u306F\u65E2\u306B\u3042\u308B`:null:`\u578B ${B.type} \u304C\u7121\u3044`:`plugin ${B.plugin} \u304C\u7121\u3044`;if(F||!i||!e||!t){g(`[domain-gateway] ${Q.mount.field} \u306E join ${B.plugin}.${B.type}.${B.field} \u3092\u7E2B\u308F\u306A\u3044 (${F})`);continue}I.push({decl:B,source:Q,target:i,returnType:Aa(String(e.type),ZQ(Q.remote),Q.mount.prefix),argType:String(t.type)})}}return I}function sN(A){return A.map(g=>`extend type ${g.target.mount.prefix}${g.decl.type} { ${g.decl.field}: ${g.returnType} }`)}function DN(A,g){let I=new Map;for(let Q of A)I.set(Q.decl.type,[...I.get(Q.decl.type)??[],Q]);return I.size===0?Q=>Q:Q=>{let C=new kg.TypeInfo(g);return(0,kg.visit)(Q,(0,kg.visitWithTypeInfo)(C,{Field:B=>I.get(C.getParentType()?.name??"")?.some(i=>i.decl.field===B.name.value)?null:void 0,SelectionSet:B=>{let i=I.get(C.getParentType()?.name??"");if(!i)return;let t=[...new Set(i.map(r=>r.decl.key))].map(r=>({kind:kg.Kind.FIELD,alias:{kind:kg.Kind.NAME,value:oN(r)},name:{kind:kg.Kind.NAME,value:r}}));return{...B,selections:[...B.selections,...t]}}}))}}function rN(A){let g=new WeakMap,I=async(Q,C)=>{g.delete(Q);let B=[...C.keys.keys()],i=Xn(C.info,ZQ(A.source.remote),A.source.mount.prefix),[e,...t]=i.document.definitions,r=B.map((J,q)=>({kind:kg.Kind.FIELD,alias:{kind:kg.Kind.NAME,value:`k${q}`},name:{kind:kg.Kind.NAME,value:A.decl.query},arguments:[{kind:kg.Kind.ARGUMENT,name:{kind:kg.Kind.NAME,value:A.decl.arg},value:{kind:kg.Kind.VARIABLE,name:{kind:kg.Kind.NAME,value:`__k${q}`}}}],selectionSet:Q.selectionSet})),F=[...e.variableDefinitions??[],...B.map((J,q)=>({kind:kg.Kind.VARIABLE_DEFINITION,variable:{kind:kg.Kind.VARIABLE,name:{kind:kg.Kind.NAME,value:`__k${q}`}},type:(0,kg.parseType)(A.argType)}))],R={kind:kg.Kind.DOCUMENT,definitions:[{...e,variableDefinitions:F,selectionSet:{kind:kg.Kind.SELECTION_SET,selections:r}},...t]},M={...i.variables,...Object.fromEntries(B.map((J,q)=>[`__k${q}`,J]))};try{let J=await A.source.mount.executor({document:R,variables:M}),q=J.data??{};B.forEach((oA,rA)=>{let uA=C.keys.get(oA)??[];if(q[`k${rA}`]===void 0&&J.errors?.length){let xA=new kg.GraphQLError(J.errors.map(Qg=>Qg.message).join("; "));uA.forEach(Qg=>Qg.reject(xA))}else uA.forEach(xA=>xA.resolve(q[`k${rA}`]??null))})}catch(J){C.keys.forEach(q=>q.forEach(oA=>oA.reject(J)))}};return(Q,C,B,i)=>{let e=String(Q[oN(A.decl.key)]??Q[A.decl.key]??""),t=i.fieldNodes[0],r=g.get(t);if(!r){let R={keys:new Map,info:i};r=R,g.set(t,R),queueMicrotask(()=>{I(t,R)})}let F=r.keys.get(e)??[];return r.keys.set(e,F),new Promise((R,M)=>F.push({resolve:R,reject:M}))}}var nN="Query";async function Ep(A){let g=await A({document:(0,hC.parse)((0,hC.getIntrospectionQuery)())});if(!g.data||g.errors&&g.errors.length>0)throw new Error(`[domain-gateway] introspection failed: ${JSON.stringify(g.errors??null)}`);return(0,hC.buildClientSchema)(g.data)}var ga=A=>A.getFields();async function ip(A,g){let I=new Set([nN]),Q=new Set,C=[];for(let B of A){let i=await Ep(B.executor).catch(F=>(g(`[domain-gateway] ${B.field}: ${F instanceof Error?F.message:String(F)}`),null)),e=i?.getQueryType();if(!i||!e)continue;let t=CN(i,B.prefix),r=[...t.filter(F=>I.has(F)),...Q.has(B.field)?[B.field]:[]];if(r.length>0){g(`[domain-gateway] ${B.field} \u3092\u7E2B\u308F\u306A\u3044 (\u885D\u7A81: ${r.join(", ")})`);continue}t.forEach(F=>I.add(F)),Q.add(B.field),C.push({mount:B,remote:i,queryName:`${B.prefix}${e.name}`})}return C}async function aN(A,g=()=>{}){let I=await ip(A,g);if(I.length===0)return null;let Q=new Set(I.map(F=>F.mount.field)),C=I.map(F=>({...F,hoist:eN(F.remote,F.mount.prefix,Q,g,F.mount.field)})),B=[...I.map(F=>`${F.mount.field}: ${F.queryName}`),...C.flatMap(F=>F.hoist.map(R=>`${R.name}: ${R.type}`))],i=await tN(I,g),e=[...I.map(({mount:F,remote:R})=>BN(R,F.prefix)),`type ${nN} { ${B.join(" ")} }`,...sN(i)].join(`
507
507
  `),t=(0,hC.buildSchema)(e),r=ga(t.getQueryType());for(let{mount:F,remote:R,queryName:M,hoist:J}of C){let q=DN(i.filter(rA=>rA.target.mount===F),R);r[F.field].resolve=()=>({});let oA=ga(t.getType(M));for(let rA of Object.keys(R.getQueryType()?.getFields()??{}))oA[rA]&&(oA[rA].resolve=zn(F.executor,R,F.prefix,void 0,q));for(let rA of J)r[rA.name].resolve=zn(F.executor,R,F.prefix,$n,q)}for(let F of i)ga(t.getType(`${F.target.mount.prefix}${F.decl.type}`))[F.decl.field].resolve=rN(F);return t}var ep="\0server";function cN(A,g=()=>{}){let I=new Map;A.onChange(()=>I.clear());async function Q(C){try{let B=await aN(IN(A,C),e=>g(C,e));if(!B)return null;let i=await crypto.subtle.digest("SHA-256",new TextEncoder().encode((0,wN.printSchema)(B)));return{schema:B,hash:Buffer.from(i).toString("hex")}}catch(B){return g(C,B instanceof Error?B.message:String(B)),null}}return{schemaFor(C){let B=C??ep,i=I.get(B);if(i)return i;let e=Q(C);return I.set(B,e),e}}}function op(A){if(typeof A!="object"||A===null)return null;let{query:g,variables:I,operationName:Q}=A;return typeof g!="string"||I!=null&&(typeof I!="object"||Array.isArray(I))||Q!=null&&typeof Q!="string"?null:{query:g,variables:I,operationName:Q}}function hN(A,g){let I=null,Q=()=>I??=g().then(e=>cN(e,(t,r)=>process.stderr.write(`[domain-gateway] ${t??"(server)"}: ${r}
508
- `))),C={error:{code:"NO_GATEWAY",message:"no domain object is mounted"}},B=async(e,t)=>{let r=await(await Q()).schemaFor(t);return r?e.json({hash:r.hash}):e.json(C,404)},i=async(e,t)=>{let r=await(await Q()).schemaFor(t);if(!r)return e.json(C,404);let F=op(await e.req.json().catch(()=>null));if(!F)return e.json({error:{code:"INVALID_BODY",message:"expected { query, variables?, operationName? }"}},400);let R=await(0,FN.graphql)({schema:r.schema,source:F.query,variableValues:F.variables??void 0,operationName:F.operationName??void 0});return e.json(R)};A.get("/domain/sessions/:sessionId/graphql/hash",e=>B(e,e.req.param("sessionId"))),A.post("/domain/sessions/:sessionId/graphql",e=>i(e,e.req.param("sessionId"))),A.get("/graphql/hash",e=>B(e,null)),A.post("/graphql",e=>i(e,null))}import{isIP as tp}from"node:net";var sp="x-planx-l7-peer",yN=new Set(["127.0.0.1","localhost","::1","[::1]"]);function RN(A){let g=A.trim().toLowerCase();return g.startsWith("[")?g.slice(0,g.indexOf("]")+1):g.replace(/:\d+$/,"")}function Dp(A){return!!A&&yN.has(RN(A))}function rp(A){return A?tp(RN(A).replace(/^\[|\]$/g,""))!==0:!1}function np(A){if(!A)return!1;try{let g=new URL(A);return(g.protocol==="http:"||g.protocol==="https:")&&yN.has(g.hostname.toLowerCase())}catch{return!1}}function ap(A){return A.host&&!Dp(A.host)&&!rp(A.host)?"bad-host":A.origin&&!np(A.origin)&&!A.l7Peer?"bad-origin":"allow"}function NN(){return async(A,g)=>{let I=ap({host:A.req.header("host"),origin:A.req.header("origin"),l7Peer:A.req.header(sp)});if(I!=="allow")return new Response(JSON.stringify({error:"Forbidden",reason:I}),{status:403,headers:{"content-type":"application/json"}});await g()}}function GN(A){return[yo,Ro].some(I=>A.message.includes(I))?{status:503,headers:{"retry-after":"1"}}:{status:500,headers:{}}}var hp="20.85.0";function UN(A,g={}){let I=new Bt;I.onError((t,r)=>{let F=t.message||String(t)||t.name||"unknown";process.stderr.write(`[domain-http] ${r.req.method} ${r.req.path} failed: ${F}
508
+ `))),C={error:{code:"NO_GATEWAY",message:"no domain object is mounted"}},B=async(e,t)=>{let r=await(await Q()).schemaFor(t);return r?e.json({hash:r.hash}):e.json(C,404)},i=async(e,t)=>{let r=await(await Q()).schemaFor(t);if(!r)return e.json(C,404);let F=op(await e.req.json().catch(()=>null));if(!F)return e.json({error:{code:"INVALID_BODY",message:"expected { query, variables?, operationName? }"}},400);let R=await(0,FN.graphql)({schema:r.schema,source:F.query,variableValues:F.variables??void 0,operationName:F.operationName??void 0});return e.json(R)};A.get("/domain/sessions/:sessionId/graphql/hash",e=>B(e,e.req.param("sessionId"))),A.post("/domain/sessions/:sessionId/graphql",e=>i(e,e.req.param("sessionId"))),A.get("/graphql/hash",e=>B(e,null)),A.post("/graphql",e=>i(e,null))}import{isIP as tp}from"node:net";var sp="x-planx-l7-peer",yN=new Set(["127.0.0.1","localhost","::1","[::1]"]);function RN(A){let g=A.trim().toLowerCase();return g.startsWith("[")?g.slice(0,g.indexOf("]")+1):g.replace(/:\d+$/,"")}function Dp(A){return!!A&&yN.has(RN(A))}function rp(A){return A?tp(RN(A).replace(/^\[|\]$/g,""))!==0:!1}function np(A){if(!A)return!1;try{let g=new URL(A);return(g.protocol==="http:"||g.protocol==="https:")&&yN.has(g.hostname.toLowerCase())}catch{return!1}}function ap(A){return A.host&&!Dp(A.host)&&!rp(A.host)?"bad-host":A.origin&&!np(A.origin)&&!A.l7Peer?"bad-origin":"allow"}function NN(){return async(A,g)=>{let I=ap({host:A.req.header("host"),origin:A.req.header("origin"),l7Peer:A.req.header(sp)});if(I!=="allow")return new Response(JSON.stringify({error:"Forbidden",reason:I}),{status:403,headers:{"content-type":"application/json"}});await g()}}function GN(A){return[yo,Ro].some(I=>A.message.includes(I))?{status:503,headers:{"retry-after":"1"}}:{status:500,headers:{}}}var hp="20.87.0";function UN(A,g={}){let I=new Bt;I.onError((t,r)=>{let F=t.message||String(t)||t.name||"unknown";process.stderr.write(`[domain-http] ${r.req.method} ${r.req.path} failed: ${F}
509
509
  ${t.stack??""}
510
510
  `);let{status:R,headers:M}=GN(t);return r.json({error:{message:F}},R,M)}),I.use("/*",NN());let{injectWebSocket:Q,upgradeWebSocket:C}=Gc({app:I}),B=A,i=null,e=()=>(B??=wp(Fp(cp(),"domain-objects-")),i??=Mo.restore({dbDir:B,doWorkerEntry:g.doWorkerEntry}),i);return j0(I,e,C),_0(I,e),X0(I,e),hN(I,e),I.get("/health",t=>t.json({status:"ok",service:"domain",version:hp})),{app:I,injectWebSocket:Q}}function MN(){return{port:Number(process.env.PORT??0),portFile:process.env.PLANX_DOMAIN_PORT_FILE,pidFile:process.env.PLANX_DOMAIN_PID_FILE,dbDir:process.env.PLANX_DOMAIN_DB_DIR}}import{existsSync as yp}from"node:fs";import{fileURLToPath as lN}from"node:url";var SN="do-worker.mjs";function kN(A,g=()=>{}){let I=new URL(`./${SN}`,A);if(yp(lN(I)))return I;g(`[domain] ${SN} not found next to ${lN(A)}; domain objects run on the main thread`)}import{renameSync as Rp,rmSync as Np,writeFileSync as Gp}from"fs";var Up=0;function oi(A,g){let I=`${A}.${process.pid}.${++Up}.tmp`;try{Gp(I,g,"utf-8"),Rp(I,A)}catch(Q){throw Np(I,{force:!0}),Q}}function Ia(A,g){oi(A,String(g))}function Qa(A,g){oi(A,String(g))}async function lp(){let{port:A,portFile:g,pidFile:I,dbDir:Q}=MN();Q&&ti.mkdirSync(Q,{recursive:!0});let C=Q?Mp(Q,"objects"):void 0,{app:B,injectWebSocket:i}=UN(C,{doWorkerEntry:kN(import.meta.url,t=>process.stderr.write(`${t}
511
511
  `))}),e=await new Promise(t=>{let r=Ga({fetch:B.fetch,port:A,hostname:"127.0.0.1"},R=>t(R.port));i(r);let F=()=>{try{r.close?.()}catch{}if(I)try{ti.unlinkSync(I)}catch{}if(g)try{ti.unlinkSync(g)}catch{}process.exit(0)};process.on("SIGTERM",F),process.on("SIGINT",F)});g&&Qa(g,e),I&&Ia(I,process.pid),process.stdout.write(JSON.stringify({service:"domain",port:e,pid:process.pid})+`