@stacksjs/docs 0.75.622 → 0.75.624
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/dist/screenshots.js +1 -1
- package/package.json +7 -7
package/dist/screenshots.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{createHash as se}from"crypto";import{lstat as N,mkdir as C,mkdtemp as oe,readFile as E,rename as W,rm as ne,stat as ie}from"fs/promises";import{dirname as ae,isAbsolute as I,join as y,relative as M,resolve as k}from"path";import{pathToFileURL as ce}from"url";import{createHash as z}from"crypto";import{readFile as G}from"fs/promises";import{existsSync as Q}from"fs";import{isAbsolute as X,join as Y,relative as Z,resolve as ee}from"path";import{loadModelRegistry as te,modelFiles as J}from"@stacksjs/orm/model-registry";function U(r){let i=Object.entries(r).map(([e,n])=>{let a=Object.entries(n.attributes??{}),u=n.belongsTo??[],x=(Array.isArray(u)?u:Object.values(u)).map((p)=>typeof p==="string"?p:p&&typeof p==="object"?String(p.model??p.name??""):"").filter(Boolean),S=n.traits?.useApi,v=n.traits?.useSeeder??n.traits?.seedable,g=(p,R)=>Boolean(R.hidden||R.encrypted||R.personal||/password|token|secret|api.?key|email|phone|address/i.test(p)),w=a.filter(([,p])=>p.required&&!p.nullable&&typeof p.factory!=="function"&&!Object.hasOwn(p,"default")).map(([p])=>p);return{name:String(n.name??e),table:n.table,primaryKey:String(n.primaryKey??"id"),...S?.uri?{api:String(S.uri)}:{},parents:[...new Set([...x,...Array.isArray(v?.after)?v.after.map(String):[]])].sort(),seederCount:typeof v?.count==="number"?v.count:null,factoryFields:a.filter(([,p])=>typeof p.factory==="function").map(([p])=>p),defaultFields:a.filter(([,p])=>Object.hasOwn(p,"default")).map(([p])=>p),requiredWithoutFactory:w,sensitiveFields:a.filter(([p,R])=>g(p,R)).map(([p])=>p),suggestedStates:[...new Set(["empty","populated",...S?.routes?.includes("show")?["detail"]:[],...S?.middleware?.length?["permission-denied"]:[],...n.traits?.useSoftDeletes||n.traits?.softDeletable?["archived"]:[]])]}}).sort((e,n)=>e.name.localeCompare(n.name)),l=new Set(i.map((e)=>e.name)),s=new Map(i.map((e)=>[e.name,e])),d=[];for(;;){let e=[...s.values()].filter((n)=>n.parents.every((a)=>!l.has(a)||d.includes(a)));if(!e.length)break;for(let n of e)d.push(n.name),s.delete(n.name)}let m=new Set,f=new Map,h=new Map,b=[],o=new Set,t=0;function c(e){f.set(e,t),h.set(e,t++),b.push(e),o.add(e);for(let u of s.get(e)?.parents??[]){if(!s.has(u))continue;if(!f.has(u))c(u),h.set(e,Math.min(h.get(e),h.get(u)));else if(o.has(u))h.set(e,Math.min(h.get(e),f.get(u)))}if(h.get(e)!==f.get(e))return;let n=[],a;do a=b.pop(),o.delete(a),n.push(a);while(a!==e);if(n.length>1||s.get(e)?.parents.includes(e))for(let u of n)m.add(u)}for(let e of s.keys())if(!f.has(e))c(e);return{models:i,creationOrder:d,cycles:[...m].sort(),blocked:[...s.keys()].filter((e)=>!m.has(e)),externalParents:[...new Set(i.flatMap((e)=>e.parents).filter((e)=>!l.has(e)))].sort()}}async function F(r,i={}){if(i===!1)return U({});if(i.directory!==void 0&&!i.directory.trim())throw Error("Model directory must not be empty");let l=ee(r,i.directory??"app/Models");if(X(i.directory??"")||Z(r,l).split(/[\\/]/)[0]==="..")throw Error("Model directory must be inside the project");let s=i.includeDefaults?Y(r,"storage/framework/defaults/app/Models"):void 0;if(!Q(l)&&!s)return U({});let d=[],m=await te({userRoot:l,defaultsRoot:s,onImportError:(b)=>d.push(b)});if(d.length)throw Error(`Cannot inspect screenshot models: ${d.join(", ")}`);let f=U(m),h=[...J(l),...s?J(s):[]].sort();return f.sourceHash=z("sha256").update(Buffer.concat(await Promise.all(h.map((b)=>G(b))))).digest("hex"),f}function T(r,i,l,s){if(!/\[[^\]]+\]|:[a-z][\w]*(?=\/|$|[?#])/i.test(r))return r;let d=i?s.models.filter((h)=>h.name===i):s.models.filter((h)=>h.api&&r.replace(/^\//,"").startsWith(`${h.api.replace(/^\//,"")}/`)),m=d.length===1?d[0]:void 0;if(!m)throw Error("A dynamic screenshot route needs an explicit model or an unambiguous model API URI");let f=l[m.name];if(!f)throw Error(`No screenshot fixture supplied for ${m.name}`);return r.replace(/\[([^\]]+)\]|:([a-z][\w]*)(?=\/|$|[?#])/gi,(h,b,o)=>{let t=b||o,c=t==="id"?m.primaryKey:t;if(m.sensitiveFields.includes(c)||/token|secret|password/i.test(t))throw Error(`Refusing to publish a sensitive route parameter: ${t}`);let e=f[c];if(e===void 0||e===""||typeof e!=="string"&&typeof e!=="number"||typeof e==="number"&&!Number.isFinite(e))throw Error(`Screenshot fixture ${m.name} has no ${t}`);return encodeURIComponent(String(e))})}import{spawnOwnedProcess as de}from"@stacksjs/cli/owned-process";var O="0.75.
|
|
2
|
+
import{createHash as se}from"crypto";import{lstat as N,mkdir as C,mkdtemp as oe,readFile as E,rename as W,rm as ne,stat as ie}from"fs/promises";import{dirname as ae,isAbsolute as I,join as y,relative as M,resolve as k}from"path";import{pathToFileURL as ce}from"url";import{createHash as z}from"crypto";import{readFile as G}from"fs/promises";import{existsSync as Q}from"fs";import{isAbsolute as X,join as Y,relative as Z,resolve as ee}from"path";import{loadModelRegistry as te,modelFiles as J}from"@stacksjs/orm/model-registry";function U(r){let i=Object.entries(r).map(([e,n])=>{let a=Object.entries(n.attributes??{}),u=n.belongsTo??[],x=(Array.isArray(u)?u:Object.values(u)).map((p)=>typeof p==="string"?p:p&&typeof p==="object"?String(p.model??p.name??""):"").filter(Boolean),S=n.traits?.useApi,v=n.traits?.useSeeder??n.traits?.seedable,g=(p,R)=>Boolean(R.hidden||R.encrypted||R.personal||/password|token|secret|api.?key|email|phone|address/i.test(p)),w=a.filter(([,p])=>p.required&&!p.nullable&&typeof p.factory!=="function"&&!Object.hasOwn(p,"default")).map(([p])=>p);return{name:String(n.name??e),table:n.table,primaryKey:String(n.primaryKey??"id"),...S?.uri?{api:String(S.uri)}:{},parents:[...new Set([...x,...Array.isArray(v?.after)?v.after.map(String):[]])].sort(),seederCount:typeof v?.count==="number"?v.count:null,factoryFields:a.filter(([,p])=>typeof p.factory==="function").map(([p])=>p),defaultFields:a.filter(([,p])=>Object.hasOwn(p,"default")).map(([p])=>p),requiredWithoutFactory:w,sensitiveFields:a.filter(([p,R])=>g(p,R)).map(([p])=>p),suggestedStates:[...new Set(["empty","populated",...S?.routes?.includes("show")?["detail"]:[],...S?.middleware?.length?["permission-denied"]:[],...n.traits?.useSoftDeletes||n.traits?.softDeletable?["archived"]:[]])]}}).sort((e,n)=>e.name.localeCompare(n.name)),l=new Set(i.map((e)=>e.name)),s=new Map(i.map((e)=>[e.name,e])),d=[];for(;;){let e=[...s.values()].filter((n)=>n.parents.every((a)=>!l.has(a)||d.includes(a)));if(!e.length)break;for(let n of e)d.push(n.name),s.delete(n.name)}let m=new Set,f=new Map,h=new Map,b=[],o=new Set,t=0;function c(e){f.set(e,t),h.set(e,t++),b.push(e),o.add(e);for(let u of s.get(e)?.parents??[]){if(!s.has(u))continue;if(!f.has(u))c(u),h.set(e,Math.min(h.get(e),h.get(u)));else if(o.has(u))h.set(e,Math.min(h.get(e),f.get(u)))}if(h.get(e)!==f.get(e))return;let n=[],a;do a=b.pop(),o.delete(a),n.push(a);while(a!==e);if(n.length>1||s.get(e)?.parents.includes(e))for(let u of n)m.add(u)}for(let e of s.keys())if(!f.has(e))c(e);return{models:i,creationOrder:d,cycles:[...m].sort(),blocked:[...s.keys()].filter((e)=>!m.has(e)),externalParents:[...new Set(i.flatMap((e)=>e.parents).filter((e)=>!l.has(e)))].sort()}}async function F(r,i={}){if(i===!1)return U({});if(i.directory!==void 0&&!i.directory.trim())throw Error("Model directory must not be empty");let l=ee(r,i.directory??"app/Models");if(X(i.directory??"")||Z(r,l).split(/[\\/]/)[0]==="..")throw Error("Model directory must be inside the project");let s=i.includeDefaults?Y(r,"storage/framework/defaults/app/Models"):void 0;if(!Q(l)&&!s)return U({});let d=[],m=await te({userRoot:l,defaultsRoot:s,onImportError:(b)=>d.push(b)});if(d.length)throw Error(`Cannot inspect screenshot models: ${d.join(", ")}`);let f=U(m),h=[...J(l),...s?J(s):[]].sort();return f.sourceHash=z("sha256").update(Buffer.concat(await Promise.all(h.map((b)=>G(b))))).digest("hex"),f}function T(r,i,l,s){if(!/\[[^\]]+\]|:[a-z][\w]*(?=\/|$|[?#])/i.test(r))return r;let d=i?s.models.filter((h)=>h.name===i):s.models.filter((h)=>h.api&&r.replace(/^\//,"").startsWith(`${h.api.replace(/^\//,"")}/`)),m=d.length===1?d[0]:void 0;if(!m)throw Error("A dynamic screenshot route needs an explicit model or an unambiguous model API URI");let f=l[m.name];if(!f)throw Error(`No screenshot fixture supplied for ${m.name}`);return r.replace(/\[([^\]]+)\]|:([a-z][\w]*)(?=\/|$|[?#])/gi,(h,b,o)=>{let t=b||o,c=t==="id"?m.primaryKey:t;if(m.sensitiveFields.includes(c)||/token|secret|password/i.test(t))throw Error(`Refusing to publish a sensitive route parameter: ${t}`);let e=f[c];if(e===void 0||e===""||typeof e!=="string"&&typeof e!=="number"||typeof e==="number"&&!Number.isFinite(e))throw Error(`Screenshot fixture ${m.name} has no ${t}`);return encodeURIComponent(String(e))})}import{spawnOwnedProcess as de}from"@stacksjs/cli/owned-process";var O="0.75.624";var Pe=(r)=>r,P=[{name:"desktop",width:1440,height:900},{name:"mobile",width:390,height:844}],H=(r)=>se("sha256").update(r).digest("hex"),B=(r)=>/^[a-z0-9][a-z0-9._-]*$/i.test(r)&&!r.endsWith(".")&&!/^(con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/i.test(r),V=(r)=>{let i=new URL(r);return i.origin+i.pathname};async function le(r,i=process.cwd()){let l=new URL(r.baseUrl);if(!["http:","https:"].includes(l.protocol)||l.username||l.password||l.search||l.hash)throw Error("baseUrl must be an http(s) URL without credentials, query or fragment");if(!r.outDir||!r.pages.length)throw Error("outDir and at least one page are required");if(r.timeoutMs!==void 0&&(!Number.isFinite(r.timeoutMs)||r.timeoutMs<100||r.timeoutMs>120000))throw Error("timeoutMs must be between 100 and 120000");if(r.backend&&!["webkit","chrome"].includes(r.backend))throw Error("backend must be webkit or chrome");if(r.requireHttpStatus!==void 0&&typeof r.requireHttpStatus!=="boolean")throw Error("requireHttpStatus must be a boolean");let s=Object.keys(r.profiles??{default:{}});if(!s.length||s.some((o)=>!B(o)))throw Error("Profile names must be safe filenames");let d=new Set,m=new Set;for(let o of r.pages){if(!B(o.id)||d.has(o.id))throw Error(`Duplicate or invalid screen id: ${o.id}`);if(d.add(o.id),o.expectedStatus!==void 0&&(!Number.isInteger(o.expectedStatus)||o.expectedStatus<100||o.expectedStatus>599))throw Error(`Invalid expected HTTP status for ${o.id}`);if(!o.title.trim()||!o.description.trim()||!o.waitFor.trim())throw Error(`Screen ${o.id} needs title, description and waitFor`);if(typeof o.path!=="string"&&(typeof o.path!=="function"||!o.route))throw Error(`Screen ${o.id} needs a route pattern for its path resolver`);let t=new URL(typeof o.path==="string"?o.path:o.route,l);if(t.origin!==l.origin||t.username||t.password)throw Error(`Screen ${o.id} must stay on baseUrl's origin`);if(o.profiles?.some((c)=>!s.includes(c))||o.profiles?.length===0)throw Error(`Unknown or empty profiles for ${o.id}`);for(let c of o.sources??[]){let e=k(i,c);if(M(i,e).startsWith("..")||I(c))throw Error(`Source must be inside the project: ${c}`);await E(e),m.add(M(i,e).replaceAll("\\","/"))}}let f=new Set;for(let o of r.viewports??P){if(!B(o.name)||f.has(o.name)||![o.width,o.height].every((t)=>Number.isInteger(t)&&t>=200&&t<=7680))throw Error("Viewports need unique safe names and integer dimensions from 200 to 7680");f.add(o.name)}if(!f.size)throw Error("At least one viewport is required");for(let o of r.inputs??[])await E(k(i,o));let h=[],b=new Set;for(let o of r.coverage?.directories??[]){let t=k(i,o);if(M(i,t).startsWith(".."))throw Error("Coverage directories must be inside the project");if(!(await ie(t)).isDirectory())throw Error(`Missing coverage directory: ${o}`);let c=0;for await(let e of new Bun.Glob("**/*.stx").scan({cwd:t,onlyFiles:!0})){c++;let n=M(i,y(t,e)).replaceAll("\\","/");if(b.add(n),!m.has(n)&&!r.coverage?.exclude?.[n]?.trim())h.push(n)}if(!c)throw Error(`No .stx screens found in ${o}`)}for(let[o,t]of Object.entries(r.coverage?.exclude??{}))if(!t.trim()||!b.has(o))throw Error(`Stale or unexplained coverage exclusion: ${o}`);if(h.length)throw Error(`Undocumented screens:
|
|
3
3
|
${h.sort().join(`
|
|
4
4
|
`)}`)}async function _(r){let i=(await import(ce(r).href)).default;if(!i||typeof i!=="object")throw Error("Screenshot configuration must have a default export");return i}async function ue(r,i){let l=Date.now()+i;while(!await r()){if(Date.now()>=l)throw Error("The screen did not become ready before its deadline");await Bun.sleep(100)}}function K(r,i){let l=r instanceof Error?r.message:"Screenshot capture failed";for(let s of i.redactEnv??[]){let d=process.env[s];if(d)l=l.replaceAll(d,"[redacted]")}return l.slice(0,1000)}async function pe(r,i,l){let s=await _(r),d=k(l.root),m=k(d,l.outDir??s.outDir),f=[],h=await F(d,s.models);try{let b={...s.fixtures,...await s.data?.prepare(h)},o=s.backend??(process.platform==="darwin"?"webkit":"chrome"),t=s.timeoutMs??30000;for(let c of s.viewports??P){if(l.viewports?.length&&!l.viewports.includes(c.name))continue;for(let e of s.pages){if(l.only?.length&&!l.only.includes(e.id))continue;if(!(e.profiles??Object.keys(s.profiles??{default:{}})).includes(i))continue;let n={id:e.id,profile:i,viewport:c,title:e.title,description:e.description,...e.reason?{reason:e.reason}:{},path:new URL(typeof e.path==="string"?e.path:e.route,s.baseUrl).pathname,status:"failed"};if(f.push(n),e.skip){n.status="skipped",n.error=e.skip,process.send?.({type:"screenshot-result",result:n});continue}let a="starting the browser",u,j;try{if(typeof Bun.WebView!=="function")throw Error("This Bun has no WebView. Upgrade Bun before capturing screens.");u=new Bun.WebView({width:c.width,height:c.height,backend:o==="chrome"?{type:"chrome",url:!1,argv:process.env.CI?["--no-sandbox","--disable-dev-shm-usage"]:[]}:"webkit"}),await Promise.race([(async()=>{let x=typeof e.path==="function"?await e.path({fixtures:b,models:h,profile:i}):T(e.path,e.model,b,h),S=new URL(x,s.baseUrl);if(S.origin!==new URL(s.baseUrl).origin||S.username||S.password)throw Error("Resolved screenshot path must stay on the configured origin");let v={...e,path:x},g={view:u,baseUrl:s.baseUrl,profile:i,viewport:c,page:v};n.path=S.pathname,a="preparing the review profile",await s.profiles?.[i]?.prepare?.(g),a="opening the screen",await u.navigate(new URL(v.path,s.baseUrl).href),a="checking the document HTTP status";let w=Number(await u.evaluate("performance.getEntriesByType('navigation')[0]?.responseStatus || 0"));if(Number.isInteger(w)&&w>=100&&w<=599)g.httpStatus=n.httpStatus=w;if(!g.httpStatus&&(s.requireHttpStatus||e.expectedStatus!==void 0))throw Error("The browser did not expose a document HTTP status; choose the chrome backend for HTTP-verified captures");if(e.expectedStatus!==void 0?g.httpStatus!==e.expectedStatus:w>=400)throw Error(`The screen returned HTTP ${w}${e.expectedStatus!==void 0?` instead of ${e.expectedStatus}`:"; check its route, access and fixture"}`);a="preparing the screen state",await e.prepare?.(g),a="waiting for screen readiness",await ue(async()=>Boolean(await u.evaluate(`Boolean(document.querySelector(${JSON.stringify(e.waitFor)}))`))&&(!e.ready||await e.ready(g)),t);let p=String(await u.evaluate("location.href"));if(V(p)!==V(new URL(v.path,s.baseUrl).href))throw Error("The screen redirected to a different route; check its login and fixture");if(a="loading fonts and visible images",await u.evaluate(`(async () => {
|
|
5
5
|
const style = document.createElement('style'); style.textContent = '*{animation:none!important;transition:none!important;scroll-behavior:auto!important;caret-color:transparent!important}'; document.head.append(style);
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@stacksjs/docs",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"sideEffects": false,
|
|
5
|
-
"version": "0.75.
|
|
5
|
+
"version": "0.75.624",
|
|
6
6
|
"description": "The Stacks way to document.",
|
|
7
7
|
"author": "Chris Breuer",
|
|
8
8
|
"contributors": [
|
|
@@ -58,15 +58,15 @@
|
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"@stacksjs/bunpress": "^0.2.25",
|
|
61
|
-
"@stacksjs/cli": "0.75.
|
|
62
|
-
"@stacksjs/config": "0.75.
|
|
63
|
-
"@stacksjs/path": "0.75.
|
|
64
|
-
"@stacksjs/orm": "0.75.
|
|
61
|
+
"@stacksjs/cli": "0.75.624",
|
|
62
|
+
"@stacksjs/config": "0.75.624",
|
|
63
|
+
"@stacksjs/path": "0.75.624",
|
|
64
|
+
"@stacksjs/orm": "0.75.624",
|
|
65
65
|
"@stacksjs/stx": "^0.2.908"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
|
-
"@stacksjs/alias": "0.75.
|
|
69
|
-
"@stacksjs/server": "0.75.
|
|
68
|
+
"@stacksjs/alias": "0.75.624",
|
|
69
|
+
"@stacksjs/server": "0.75.624",
|
|
70
70
|
"better-dx": "^0.2.39"
|
|
71
71
|
}
|
|
72
72
|
}
|