@joystick.js/test-canary 0.0.0-canary.3 → 0.0.0-canary.31
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/.build/index.js +1 -1
- package/_package.json +11 -1
- package/dist/helpers/component/event.js +1 -0
- package/dist/helpers/component/index.js +1 -1
- package/dist/helpers/databases/index.js +1 -1
- package/dist/helpers/databases/mongodb/availableQueryParameters.js +1 -0
- package/dist/helpers/databases/mongodb/buildConnectionString.js +1 -0
- package/dist/helpers/databases/mongodb/buildQueryParameters.js +1 -0
- package/dist/helpers/databases/mongodb/index.js +6 -0
- package/dist/helpers/databases/postgresql/addColumnToTable.js +1 -0
- package/dist/helpers/databases/postgresql/createAccountsIndexes.js +1 -0
- package/dist/helpers/databases/postgresql/createAccountsTables.js +1 -0
- package/dist/helpers/databases/postgresql/createDatabase.js +0 -0
- package/dist/helpers/databases/postgresql/index.js +11 -0
- package/dist/helpers/load/index.js +1 -17
- package/dist/helpers/queues/index.js +1 -1
- package/dist/index.js +1 -20
- package/dist/lib/CLILog.js +13 -0
- package/dist/lib/generateId.js +1 -0
- package/dist/lib/isValidJSONString.js +1 -0
- package/dist/lib/loadSettings.js +1 -0
- package/dist/lib/rainbowRoad.js +1 -5
- package/dist/lib/serializeQueryParameters.js +1 -0
- package/dist/test.js +1 -4
- package/package.json +5 -2
- package/src/helpers/component/event.js +9 -0
- package/src/helpers/component/index.js +44 -1
- package/src/helpers/databases/index.js +58 -1
- package/src/helpers/databases/mongodb/availableQueryParameters.js +39 -0
- package/src/helpers/databases/mongodb/buildConnectionString.js +28 -0
- package/src/helpers/databases/mongodb/buildQueryParameters.js +15 -0
- package/src/helpers/databases/mongodb/index.js +43 -0
- package/src/helpers/databases/postgresql/addColumnToTable.js +3 -0
- package/src/helpers/databases/postgresql/createAccountsIndexes.js +29 -0
- package/src/helpers/databases/postgresql/createAccountsTables.js +44 -0
- package/src/helpers/databases/postgresql/createDatabase.js +0 -0
- package/src/helpers/databases/postgresql/index.js +52 -0
- package/src/helpers/load/index.js +11 -6
- package/src/helpers/queues/index.js +9 -1
- package/src/index.js +4 -0
- package/src/lib/{log.js → CLILog.js} +1 -1
- package/src/lib/generateId.js +73 -0
- package/src/lib/isValidJSONString.js +7 -0
- package/src/lib/loadSettings.js +90 -0
- package/src/lib/serializeQueryParameters.js +5 -0
- package/src/test.js +23 -1
- package/dist/lib/log.js +0 -17
package/.build/index.js
CHANGED
package/_package.json
CHANGED
|
@@ -13,5 +13,15 @@
|
|
|
13
13
|
},
|
|
14
14
|
"keywords": [],
|
|
15
15
|
"author": "",
|
|
16
|
-
"license": "SAUCR"
|
|
16
|
+
"license": "SAUCR",
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"ava": "^5.3.1",
|
|
19
|
+
"chalk": "^5.3.0",
|
|
20
|
+
"dayjs": "^1.11.9",
|
|
21
|
+
"esbuild": "^0.18.17",
|
|
22
|
+
"linkedom": "^0.15.1",
|
|
23
|
+
"mongo-uri-tool": "^1.0.1",
|
|
24
|
+
"mongodb": "^5.7.0",
|
|
25
|
+
"pg": "^8.11.2"
|
|
26
|
+
}
|
|
17
27
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var o=(e="",t="",n={})=>{const p=n?.document?.querySelector("#app")?.querySelector(t),r=new Event(e);return p.dispatchEvent(r),!0};export{o as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var e={};export{
|
|
1
|
+
import{parseHTML as a}from"linkedom";import c from"@joystick.js/ui-canary";import s from"./event.js";import d from"../load/index.js";const p=()=>{const o=a('<div id="app"></div>'),{window:t,document:e,Element:n,Event:r,HTMLElement:l}=o;return global.window=t,global.document=e,global.HTMLElement=l,global.Element=n,global.Event=r,global.console={log:console.log,warn:console.warn,error:console.error},o};var b=async(o="",t={})=>{const e=p();window.joystick={};const n=await d(o,{default:!0}),r=c.mount(n,t?.props||{},document.querySelector("#app"));return{...e,component:r,test:{event:(l="",m="")=>s(l,m,e)}}};export{b as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var e={};export{
|
|
1
|
+
import n from"../../lib/loadSettings.js";import p from"./mongodb/index.js";import i from"./postgresql/index.js";var l=async()=>{const r=(await n({environment:"test"}))?.parsed?.config?.databases?.map(e=>({provider:e?.provider,settings:e}));for(let e=0;e<r?.length;e+=1){const t=r[e],a=r?.filter(s=>s?.provider===s?.provider)?.length>1,o=parseInt(process.env.PORT,10)+10+e;if(t?.provider==="mongodb"){const s=await p(t?.settings,o);process.databases={...process.databases||{},mongodb:a?{...process?.databases?.mongodb||{},[t?.settings?.name||`mongodb_${o}`]:s}:s}}if(t?.provider==="postgresql"){const s=await i(t?.settings,o);process.databases={...process.databases||{},postgresql:a?{...process?.databases?.postgresql||{},[t?.settings?.name||`postgresql_${o}`]:{...s?.pool,query:s?.query}}:{...s?.pool,query:s?.query}}}}return process.databases};export{l as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=["replicaSet","tls","ssl","tlsCertificateKeyFile","tlsCertificateKeyFilePassword","tlsCAFile","tlsAllowInvalidCertificates","tlsAllowInvalidHostnames","tlsInsecure","connectTimeoutMS","socketTimeoutMS","compressors","zlibCompressionLevel","maxPoolSize","minPoolSize","maxIdleTimeMS","waitQueueMultiple","waitQueueTimeoutMS","w","wtimeoutMS","journal","readConcernLevel","readPreference","maxStalenessSeconds","readPreferenceTags","authSource","authMechanism","authMechanismProperties","gssapiServiceName","localThresholdMS","serverSelectionTimeoutMS","serverSelectionTryOnce","heartbeatFrequencyMS","appName","retryReads","retryWrites","uuidRepresentation"];export{e as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import m from"./buildQueryParameters.js";import $ from"../../../lib/serializeQueryParameters.js";var p=(r={})=>{let s="mongodb://";r&&(r.username||r.password)&&(s=`${s}${r.username||r.password?`${r.username||""}${r.username&&r.password?":":""}${r.password||""}@`:""}`),r&&r.hosts&&Array.isArray(r.hosts)&&(s=`${s}${r.hosts.map(e=>`${e.hostname}:${e.port}`).join(",")}`),r&&r.database&&(s=`${s}/${r.database}`);const a=m(r);return Object.keys(a)?.length>0&&(s=`${s}?${$(a)}`),s};export{p as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import l from"./availableQueryParameters.js";var f=(r={})=>{const t={};for(let a=0;a<l.length;a+=1){const e=l[a];r&&r[e]&&(t[e]=r[e])}return t};export{f as default};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{MongoClient as s}from"mongodb";import c from"chalk";import a from"mongo-uri-tool";import p from"fs";import l from"./buildConnectionString.js";var b=async(o={},e=2610)=>{const r=o?.connection||{hosts:[{hostname:"127.0.0.1",port:e}],database:"app",replicaSet:`joystick_${e}`},t=l(r),i=a.parseUri(t);try{const n={useNewUrlParser:!0,useUnifiedTopology:!0,ssl:!["development","test"].includes(process.env.NODE_ENV),...o?.options||{}};return o?.options?.ca&&(n.ca=p.readFileSync(o?.options?.ca)),(await s.connect(t,n)).db(i.db)}catch(n){console.warn(c.yellowBright(`
|
|
2
|
+
Failed to connect to MongoDB. Please double-check connection settings and try again.
|
|
3
|
+
|
|
4
|
+
Error from MongoDB:
|
|
5
|
+
|
|
6
|
+
${c.redBright(n?.message)}`))}};export{b as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var a=(e="",r="",s="")=>process.databases._users?.query(`ALTER TABLE ${e} ADD COLUMN ${r} ${s}`);export{a as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const a=async(s="",r="",_=[])=>process.databases._users?.query(`CREATE UNIQUE INDEX IF NOT EXISTS ${s} ON ${r}(${_.join(", ")})`),e=async(s="",r="",_=[])=>process.databases._users?.query(`CREATE INDEX IF NOT EXISTS ${s} ON ${r}(${_.join(", ")})`);var o=async()=>{await e("user_by_email","users",["email_address"]),await e("user_by_username","users",["username"]),await e("user_by_user_id","users",["user_id"]),await e("user_session_by_token","users_sessions",["token"]),await e("user_password_reset_token_by_token","users_password_reset_tokens",["token"]),await e("user_password_reset_token_by_user_id_token","users_password_reset_tokens",["user_id","token"]),await e("user_role","users_roles",["role"]),await e("user_roles_by_user_id_role","users_roles",["user_id","role"]),await e("role","roles",["role"]),await a("user_roles","users_roles",["user_id","role"])};export{o as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=async(t="",s=[])=>process.databases._users?.query(`CREATE TABLE IF NOT EXISTS ${t} (${s.join(", ")})`);var r=async()=>{await e("users",["id bigserial primary key","user_id text","email_address text","password text","username text","language text"]),await e("users_sessions",["id bigserial primary key","user_id text","token text","token_expires_at text"]),await e("users_password_reset_tokens",["id bigserial primary key","user_id text","token text","requested_at text"]),await e("users_verify_email_tokens",["id bigserial primary key","user_id text","token text"]),await e("roles",["id bigserial primary key","role text"]),await e("users_roles",["id bigserial primary key","user_id text","role text"])};export{r as default};
|
|
File without changes
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import l from"pg";import n from"chalk";import h from"os";const{Pool:i}=l;var u=async(r={},c=2610)=>{const o=r?.connection||{hosts:[{hostname:"127.0.0.1",port:c}],database:"app",username:(h.userInfo()||{}).username||"",password:""};try{const e=o.hosts&&o.hosts[0],a=new i({user:o?.username||"",database:o?.database,password:o?.password||"",host:e?.hostname,port:e?.port,...r?.options||{}});return{pool:a,query:(...t)=>a.query(...t).then(s=>s?.rows||[]).catch(s=>{throw console.log(n.redBright(`
|
|
2
|
+
Failed SQL Statement:
|
|
3
|
+
`)),console.log(t[0]),console.log(`
|
|
4
|
+
`),console.log(n.redBright(`
|
|
5
|
+
Failed Values:
|
|
6
|
+
`)),console.log(t[1]),s})}}catch(e){console.warn(n.yellowBright(`
|
|
7
|
+
Failed to connect to PostgreSQL. Please double-check connection settings and try again.
|
|
8
|
+
|
|
9
|
+
Error from PostgreSQL:
|
|
10
|
+
|
|
11
|
+
${n.redBright(e?.message)}`))}};export{u as default};
|
|
@@ -1,17 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
`:`
|
|
3
|
-
`)+t,n=o+1,o=r.indexOf(`
|
|
4
|
-
`,n)}while(o!==-1);return l+=r.slice(n),l}var{stdout:S,stderr:F}=B,C=Symbol("GENERATOR"),d=Symbol("STYLER"),b=Symbol("IS_EMPTY"),w=["ansi","ansi","ansi256","ansi16m"],g=Object.create(null),W=(r,e={})=>{if(e.level&&!(Number.isInteger(e.level)&&e.level>=0&&e.level<=3))throw new Error("The `level` option should be an integer from 0 to 3");let t=S?S.level:0;r.level=e.level===void 0?t:e.level};var K=r=>{let e=(...t)=>t.join(" ");return W(e,r),Object.setPrototypeOf(e,m.prototype),e};function m(r){return K(r)}Object.setPrototypeOf(m.prototype,Function.prototype);for(let[r,e]of Object.entries(f))g[r]={get(){let t=O(this,R(e.open,e.close,this[d]),this[b]);return Object.defineProperty(this,r,{value:t}),t}};g.visible={get(){let r=O(this,this[d],!0);return Object.defineProperty(this,"visible",{value:r}),r}};var y=(r,e,t,...o)=>r==="rgb"?e==="ansi16m"?f[t].ansi16m(...o):e==="ansi256"?f[t].ansi256(f.rgbToAnsi256(...o)):f[t].ansi(f.rgbToAnsi(...o)):r==="hex"?y("rgb",e,t,...f.hexToRgb(...o)):f[t][r](...o),z=["rgb","hex","ansi256"];for(let r of z){g[r]={get(){let{level:t}=this;return function(...o){let n=R(y(r,w[t],"color",...o),f.color.close,this[d]);return O(this,n,this[b])}}};let e="bg"+r[0].toUpperCase()+r.slice(1);g[e]={get(){let{level:t}=this;return function(...o){let n=R(y(r,w[t],"bgColor",...o),f.bgColor.close,this[d]);return O(this,n,this[b])}}}}var H=Object.defineProperties(()=>{},{...g,level:{enumerable:!0,get(){return this[C].level},set(r){this[C].level=r}}}),R=(r,e,t)=>{let o,n;return t===void 0?(o=r,n=e):(o=t.openAll+r,n=e+t.closeAll),{open:r,close:e,openAll:o,closeAll:n,parent:t}},O=(r,e,t)=>{let o=(...n)=>Q(o,n.length===1?""+n[0]:n.join(" "));return Object.setPrototypeOf(o,H),o[C]=r,o[d]=e,o[b]=t,o},Q=(r,e)=>{if(r.level<=0||!e)return r[b]?"":e;let t=r[d];if(t===void 0)return e;let{openAll:o,closeAll:n}=t;if(e.includes("\x1B"))for(;t!==void 0;)e=I(e,t.close,t.open),t=t.parent;let l=e.indexOf(`
|
|
5
|
-
`);return l!==-1&&(e=M(e,n,o,l)),o+e+n};Object.defineProperties(m.prototype,g);var q=m(),ae=m({level:F?F.level:0});var a=q;var A=()=>`${a.red("=")}${a.green("=")}${a.blue("=")}${a.red("=")}${a.green("=")}${a.blue("=")}`;var k=(r="",e={})=>{let t={info:"blue",success:"green",warning:"yellowBright",danger:"red"},o={info:"\u2771 Info",success:"\u2771 Ok",warning:"\u2771 Warning",danger:"\u2771 Error"},n=e.level?t[e.level]:"gray",l=e.level?o[e.level]:"Log",c=e.docs||"https://cheatcode.co/docs/joystick";console.log(`
|
|
6
|
-
${e.padding||""}${A()}
|
|
7
|
-
`),console.log(`${e.padding||""}${a[n](`${l}:`)}
|
|
8
|
-
`),console.log(`${e.padding||""}${a.white(r)}
|
|
9
|
-
`),console.log(`${e.padding||""}${a.grey("---")}
|
|
10
|
-
`),console.log(`${e.padding||""}${a.white("Relevant Documentation:")}
|
|
11
|
-
`),console.log(`${e.padding||""}${a.blue(c)}
|
|
12
|
-
`),console.log(`${e.padding||""}${a.white("Stuck? Ask a Question:")}
|
|
13
|
-
`),console.log(`${e.padding||""}${a.blue("https://github.com/cheatcode/joystick/discussions")}
|
|
14
|
-
`),e.tools&&Array.isArray(e.tools)&&(console.log(`${e.padding||""}${a.white("Helpful Tools:")}
|
|
15
|
-
`),e.tools.forEach(h=>{console.log(`${e.padding||""}${a.blue(`${h.title} \u2014 ${h.url}`)}
|
|
16
|
-
`)})),console.log(`${e.padding||""}${A()}
|
|
17
|
-
`)};var Oe=async(r="",e={})=>{let o=`.joystick/build/${r?.charAt(0)==="/"?r.substring(1,r.length):r}`;if(!J.existsSync(o))return k(`[test.load] Path at ${o} not found.`,{level:"warning",docs:"https://cheatcode.co/docs/joystick/test/load"}),null;let l=await import(o);return l?.default&&e?.default?l.default:l};export{Oe as default};
|
|
1
|
+
import n from"fs";import a from"../../lib/CLILog.js";const c=async(o="",s={})=>{const t=await import(`${o}?update=${Date.now()}`);return t?.default&&s?.default?t.default:t};var u=async(o="",s={})=>{const e=o?.charAt(0)==="/"?o.substring(1,o.length):o,t=`${process.cwd()}/.joystick/build/${e}`;return n.existsSync(t)?c(t,s):(a(`[test.load] Path at ${t} not found.`,{level:"warning",docs:"https://cheatcode.co/docs/joystick/test/load"}),null)};export{u as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var e={};export{
|
|
1
|
+
var u={job:(e="",o={})=>{}};export{u as default};
|
package/dist/index.js
CHANGED
|
@@ -1,20 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
$ ava ${r}
|
|
4
|
-
`),x.exit(1)}else throw new Error("The \u2019ava\u2019 module can only be imported in test files")});var F=C(p=>{"use strict";p.flags={loadedMain:!1};p.refs={runnerChain:null};p.sharedWorkerTeardowns=[];p.waitForReady=[]});var j=C((Ye,_)=>{"use strict";S();var Oe=m("node:assert"),{flags:Ce,refs:k}=F();Oe(k.runnerChain);Ce.loadedMain=!0;_.exports=k.runnerChain});var A=de(j(),1);var v=class{constructor(){}that(e="",t=null){return(0,A.default)(e,t)}},P=new v;var L={};var G={};var Y={};var D={};var q={};import ke from"fs";var U=(r=0)=>e=>`\x1B[${e+r}m`,V=(r=0)=>e=>`\x1B[${38+r};5;${e}m`,W=(r=0)=>(e,t,o)=>`\x1B[${38+r};2;${e};${t};${o}m`,s={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],overline:[53,55],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],blackBright:[90,39],gray:[90,39],grey:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgGray:[100,49],bgGrey:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}},Qe=Object.keys(s.modifier),Te=Object.keys(s.color),Re=Object.keys(s.bgColor),Je=[...Te,...Re];function ye(){let r=new Map;for(let[e,t]of Object.entries(s)){for(let[o,n]of Object.entries(t))s[o]={open:`\x1B[${n[0]}m`,close:`\x1B[${n[1]}m`},t[o]=s[o],r.set(n[0],n[1]);Object.defineProperty(s,e,{value:t,enumerable:!1})}return Object.defineProperty(s,"codes",{value:r,enumerable:!1}),s.color.close="\x1B[39m",s.bgColor.close="\x1B[49m",s.color.ansi=U(),s.color.ansi256=V(),s.color.ansi16m=W(),s.bgColor.ansi=U(10),s.bgColor.ansi256=V(10),s.bgColor.ansi16m=W(10),Object.defineProperties(s,{rgbToAnsi256:{value(e,t,o){return e===t&&t===o?e<8?16:e>248?231:Math.round((e-8)/247*24)+232:16+36*Math.round(e/255*5)+6*Math.round(t/255*5)+Math.round(o/255*5)},enumerable:!1},hexToRgb:{value(e){let t=/[a-f\d]{6}|[a-f\d]{3}/i.exec(e.toString(16));if(!t)return[0,0,0];let[o]=t;o.length===3&&(o=[...o].map(l=>l+l).join(""));let n=Number.parseInt(o,16);return[n>>16&255,n>>8&255,n&255]},enumerable:!1},hexToAnsi256:{value:e=>s.rgbToAnsi256(...s.hexToRgb(e)),enumerable:!1},ansi256ToAnsi:{value(e){if(e<8)return 30+e;if(e<16)return 90+(e-8);let t,o,n;if(e>=232)t=((e-232)*10+8)/255,o=t,n=t;else{e-=16;let h=e%36;t=Math.floor(e/36)/5,o=Math.floor(h/6)/5,n=h%6/5}let l=Math.max(t,o,n)*2;if(l===0)return 30;let a=30+(Math.round(n)<<2|Math.round(o)<<1|Math.round(t));return l===2&&(a+=60),a},enumerable:!1},rgbToAnsi:{value:(e,t,o)=>s.ansi256ToAnsi(s.rgbToAnsi256(e,t,o)),enumerable:!1},hexToAnsi:{value:e=>s.ansi256ToAnsi(s.hexToAnsi256(e)),enumerable:!1}}),s}var xe=ye(),f=xe;import E from"node:process";import Ae from"node:os";import K from"node:tty";function u(r,e=globalThis.Deno?globalThis.Deno.args:E.argv){let t=r.startsWith("-")?"":r.length===1?"-":"--",o=e.indexOf(t+r),n=e.indexOf("--");return o!==-1&&(n===-1||o<n)}var{env:i}=E,T;u("no-color")||u("no-colors")||u("color=false")||u("color=never")?T=0:(u("color")||u("colors")||u("color=true")||u("color=always"))&&(T=1);function ve(){if("FORCE_COLOR"in i)return i.FORCE_COLOR==="true"?1:i.FORCE_COLOR==="false"?0:i.FORCE_COLOR.length===0?1:Math.min(Number.parseInt(i.FORCE_COLOR,10),3)}function Ee(r){return r===0?!1:{level:r,hasBasic:!0,has256:r>=2,has16m:r>=3}}function $e(r,{streamIsTTY:e,sniffFlags:t=!0}={}){let o=ve();o!==void 0&&(T=o);let n=t?T:o;if(n===0)return 0;if(t){if(u("color=16m")||u("color=full")||u("color=truecolor"))return 3;if(u("color=256"))return 2}if("TF_BUILD"in i&&"AGENT_NAME"in i)return 1;if(r&&!e&&n===void 0)return 0;let l=n||0;if(i.TERM==="dumb")return l;if(E.platform==="win32"){let a=Ae.release().split(".");return Number(a[0])>=10&&Number(a[2])>=10586?Number(a[2])>=14931?3:2:1}if("CI"in i)return"GITHUB_ACTIONS"in i||"GITEA_ACTIONS"in i?3:["TRAVIS","CIRCLECI","APPVEYOR","GITLAB_CI","BUILDKITE","DRONE"].some(a=>a in i)||i.CI_NAME==="codeship"?1:l;if("TEAMCITY_VERSION"in i)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(i.TEAMCITY_VERSION)?1:0;if(i.COLORTERM==="truecolor"||i.TERM==="xterm-kitty")return 3;if("TERM_PROGRAM"in i){let a=Number.parseInt((i.TERM_PROGRAM_VERSION||"").split(".")[0],10);switch(i.TERM_PROGRAM){case"iTerm.app":return a>=3?3:2;case"Apple_Terminal":return 2}}return/-256(color)?$/i.test(i.TERM)?2:/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(i.TERM)||"COLORTERM"in i?1:l}function z(r,e={}){let t=$e(r,{streamIsTTY:r&&r.isTTY,...e});return Ee(t)}var Ie={stdout:z({isTTY:K.isatty(1)}),stderr:z({isTTY:K.isatty(2)})},H=Ie;function Q(r,e,t){let o=r.indexOf(e);if(o===-1)return r;let n=e.length,l=0,a="";do a+=r.slice(l,o)+e+t,l=o+n,o=r.indexOf(e,l);while(o!==-1);return a+=r.slice(l),a}function J(r,e,t,o){let n=0,l="";do{let a=r[o-1]==="\r";l+=r.slice(n,a?o-1:o)+e+(a?`\r
|
|
5
|
-
`:`
|
|
6
|
-
`)+t,n=o+1,o=r.indexOf(`
|
|
7
|
-
`,n)}while(o!==-1);return l+=r.slice(n),l}var{stdout:X,stderr:Z}=H,$=Symbol("GENERATOR"),d=Symbol("STYLER"),b=Symbol("IS_EMPTY"),ee=["ansi","ansi","ansi256","ansi16m"],g=Object.create(null),Ne=(r,e={})=>{if(e.level&&!(Number.isInteger(e.level)&&e.level>=0&&e.level<=3))throw new Error("The `level` option should be an integer from 0 to 3");let t=X?X.level:0;r.level=e.level===void 0?t:e.level};var Be=r=>{let e=(...t)=>t.join(" ");return Ne(e,r),Object.setPrototypeOf(e,O.prototype),e};function O(r){return Be(r)}Object.setPrototypeOf(O.prototype,Function.prototype);for(let[r,e]of Object.entries(f))g[r]={get(){let t=R(this,N(e.open,e.close,this[d]),this[b]);return Object.defineProperty(this,r,{value:t}),t}};g.visible={get(){let r=R(this,this[d],!0);return Object.defineProperty(this,"visible",{value:r}),r}};var I=(r,e,t,...o)=>r==="rgb"?e==="ansi16m"?f[t].ansi16m(...o):e==="ansi256"?f[t].ansi256(f.rgbToAnsi256(...o)):f[t].ansi(f.rgbToAnsi(...o)):r==="hex"?I("rgb",e,t,...f.hexToRgb(...o)):f[t][r](...o),Me=["rgb","hex","ansi256"];for(let r of Me){g[r]={get(){let{level:t}=this;return function(...o){let n=N(I(r,ee[t],"color",...o),f.color.close,this[d]);return R(this,n,this[b])}}};let e="bg"+r[0].toUpperCase()+r.slice(1);g[e]={get(){let{level:t}=this;return function(...o){let n=N(I(r,ee[t],"bgColor",...o),f.bgColor.close,this[d]);return R(this,n,this[b])}}}}var we=Object.defineProperties(()=>{},{...g,level:{enumerable:!0,get(){return this[$].level},set(r){this[$].level=r}}}),N=(r,e,t)=>{let o,n;return t===void 0?(o=r,n=e):(o=t.openAll+r,n=e+t.closeAll),{open:r,close:e,openAll:o,closeAll:n,parent:t}},R=(r,e,t)=>{let o=(...n)=>Se(o,n.length===1?""+n[0]:n.join(" "));return Object.setPrototypeOf(o,we),o[$]=r,o[d]=e,o[b]=t,o},Se=(r,e)=>{if(r.level<=0||!e)return r[b]?"":e;let t=r[d];if(t===void 0)return e;let{openAll:o,closeAll:n}=t;if(e.includes("\x1B"))for(;t!==void 0;)e=Q(e,t.close,t.open),t=t.parent;let l=e.indexOf(`
|
|
8
|
-
`);return l!==-1&&(e=J(e,n,o,l)),o+e+n};Object.defineProperties(O.prototype,g);var Fe=O(),ir=O({level:Z?Z.level:0});var c=Fe;var B=()=>`${c.red("=")}${c.green("=")}${c.blue("=")}${c.red("=")}${c.green("=")}${c.blue("=")}`;var re=(r="",e={})=>{let t={info:"blue",success:"green",warning:"yellowBright",danger:"red"},o={info:"\u2771 Info",success:"\u2771 Ok",warning:"\u2771 Warning",danger:"\u2771 Error"},n=e.level?t[e.level]:"gray",l=e.level?o[e.level]:"Log",a=e.docs||"https://cheatcode.co/docs/joystick";console.log(`
|
|
9
|
-
${e.padding||""}${B()}
|
|
10
|
-
`),console.log(`${e.padding||""}${c[n](`${l}:`)}
|
|
11
|
-
`),console.log(`${e.padding||""}${c.white(r)}
|
|
12
|
-
`),console.log(`${e.padding||""}${c.grey("---")}
|
|
13
|
-
`),console.log(`${e.padding||""}${c.white("Relevant Documentation:")}
|
|
14
|
-
`),console.log(`${e.padding||""}${c.blue(a)}
|
|
15
|
-
`),console.log(`${e.padding||""}${c.white("Stuck? Ask a Question:")}
|
|
16
|
-
`),console.log(`${e.padding||""}${c.blue("https://github.com/cheatcode/joystick/discussions")}
|
|
17
|
-
`),e.tools&&Array.isArray(e.tools)&&(console.log(`${e.padding||""}${c.white("Helpful Tools:")}
|
|
18
|
-
`),e.tools.forEach(h=>{console.log(`${e.padding||""}${c.blue(`${h.title} \u2014 ${h.url}`)}
|
|
19
|
-
`)})),console.log(`${e.padding||""}${B()}
|
|
20
|
-
`)};var te=async(r="",e={})=>{let o=`.joystick/build/${r?.charAt(0)==="/"?r.substring(1,r.length):r}`;if(!ke.existsSync(o))return re(`[test.load] Path at ${o} not found.`,{level:"warning",docs:"https://cheatcode.co/docs/joystick/test/load"}),null;let l=await import(o);return l?.default&&e?.default?l.default:l};var oe={};var ne={};var le={};var Br={api:L,component:G,databases:Y,email:D,load:te,queues:q,routes:oe,that:P.that,uploaders:ne,websockets:le};export{Br as default};
|
|
1
|
+
import o from"./test.js";import r from"./helpers/api/index.js";import t from"./helpers/component/index.js";import e from"./helpers/databases/index.js";import m from"./helpers/email/index.js";import f from"./helpers/queues/index.js";import a from"./helpers/load/index.js";import p from"./helpers/routes/index.js";import i from"./helpers/uploaders/index.js";import s from"./helpers/websockets/index.js";var w={after:o.after,afterEach:o.afterEach,api:r,before:o.before,beforeEach:o.beforeEach,component:t,databases:e,email:m,load:a,queues:f,routes:p,that:o.that,uploaders:i,websockets:s};export{w as default};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import l from"chalk";import o from"./rainbowRoad.js";var t=(c="",e={})=>{const g={info:"blue",success:"green",warning:"yellowBright",danger:"red"},d={info:"\u2771 Info",success:"\u2771 Ok",warning:"\u2771 Warning",danger:"\u2771 Error"},a=e.level?g[e.level]:"gray",r=e.level?d[e.level]:"Log",$=e.docs||"https://github.com/cheatcode/joystick";console.log(`
|
|
2
|
+
${e.padding||""}${o()}
|
|
3
|
+
`),console.log(`${e.padding||""}${l[a](`${r}:`)}
|
|
4
|
+
`),console.log(`${e.padding||""}${l.white(c)}
|
|
5
|
+
`),console.log(`${e.padding||""}${l.grey("---")}
|
|
6
|
+
`),console.log(`${e.padding||""}${l.white("Relevant Documentation:")}
|
|
7
|
+
`),console.log(`${e.padding||""}${l.blue($)}
|
|
8
|
+
`),console.log(`${e.padding||""}${l.white("Stuck? Ask a Question:")}
|
|
9
|
+
`),console.log(`${e.padding||""}${l.blue("https://github.com/cheatcode/joystick/discussions")}
|
|
10
|
+
`),e.tools&&Array.isArray(e.tools)&&(console.log(`${e.padding||""}${l.white("Helpful Tools:")}
|
|
11
|
+
`),e.tools.forEach(n=>{console.log(`${e.padding||""}${l.blue(`${n.title} \u2014 ${n.url}`)}
|
|
12
|
+
`)})),console.log(`${e.padding||""}${o()}
|
|
13
|
+
`)};export{t as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var l=(e=16)=>{let t=[],a=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"];for(let r=0;r<e;r++)t.push(a[Math.floor(Math.random()*16)]);return t.join("")};export{l as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var t=(r="")=>{try{return JSON.parse(r)}catch{return!1}};export{t as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import r from"fs";import i from"./CLILog.js";import c from"./isValidJSONString.js";const a=(e="")=>{try{const t=c(e),s=process.env.NODE_ENV==="test"?"test":"start";t||(i(`Failed to parse settings file. Double-check the syntax in your settings.${process.env.NODE_ENV}.json file at the root of your project and rerun joystick ${s}.`,{level:"danger",docs:"https://cheatcode.co/docs/joystick/environment-settings",tools:[{title:"JSON Linter",url:"https://jsonlint.com/"}]}),process.exit(0))}catch(t){throw new Error(`[loadSettings.warnIfInvalidJSONInSettings] ${t.message}`)}},d=(e="")=>{try{return r.readFileSync(e,"utf-8")}catch(t){throw new Error(`[loadSettings.getSettings] ${t.message}`)}},g=(e="")=>{try{const t=r.existsSync(e),s=process.env.NODE_ENV==="test"?"test":"start";t||(i(`A settings file could not be found for this environment (${process.env.NODE_ENV}). Create a settings.${process.env.NODE_ENV}.json file at the root of your project and rerun joystick ${s}.`,{level:"danger",docs:`https://cheatcode.co/docs/joystick/cli/${s}`}),process.exit(0))}catch(t){throw new Error(`[loadSettings.warnIfSettingsNotFound] ${t.message}`)}},l=e=>{try{if(!e)throw new Error("options object is required.");if(!e.environment)throw new Error("options.environment is required.")}catch(t){throw new Error(`[loadSettings.validateOptions] ${t.message}`)}},p=(e,{resolve:t,reject:s})=>{try{l(e);const o=`${process.cwd()}/settings.${e.environment}.json`;g(o);const n=d(o);a(n),process.env.JOYSTICK_SETTINGS=n,t({parsed:JSON.parse(n),unparsed:n})}catch(o){s(`[loadSettings] ${o.message}`)}};var N=e=>new Promise((t,s)=>{p(e,{resolve:t,reject:s})});export{N as default};
|
package/dist/lib/rainbowRoad.js
CHANGED
|
@@ -1,5 +1 @@
|
|
|
1
|
-
|
|
2
|
-
`:`
|
|
3
|
-
`)+t,n=o+1,o=r.indexOf(`
|
|
4
|
-
`,n)}while(o!==-1);return i+=r.slice(n),i}var{stdout:S,stderr:F}=B,C=Symbol("GENERATOR"),b=Symbol("STYLER"),d=Symbol("IS_EMPTY"),_=["ansi","ansi","ansi256","ansi16m"],h=Object.create(null),U=(r,e={})=>{if(e.level&&!(Number.isInteger(e.level)&&e.level>=0&&e.level<=3))throw new Error("The `level` option should be an integer from 0 to 3");let t=S?S.level:0;r.level=e.level===void 0?t:e.level};var V=r=>{let e=(...t)=>t.join(" ");return U(e,r),Object.setPrototypeOf(e,m.prototype),e};function m(r){return V(r)}Object.setPrototypeOf(m.prototype,Function.prototype);for(let[r,e]of Object.entries(a))h[r]={get(){let t=p(this,R(e.open,e.close,this[b]),this[d]);return Object.defineProperty(this,r,{value:t}),t}};h.visible={get(){let r=p(this,this[b],!0);return Object.defineProperty(this,"visible",{value:r}),r}};var T=(r,e,t,...o)=>r==="rgb"?e==="ansi16m"?a[t].ansi16m(...o):e==="ansi256"?a[t].ansi256(a.rgbToAnsi256(...o)):a[t].ansi(a.rgbToAnsi(...o)):r==="hex"?T("rgb",e,t,...a.hexToRgb(...o)):a[t][r](...o),K=["rgb","hex","ansi256"];for(let r of K){h[r]={get(){let{level:t}=this;return function(...o){let n=R(T(r,_[t],"color",...o),a.color.close,this[b]);return p(this,n,this[d])}}};let e="bg"+r[0].toUpperCase()+r.slice(1);h[e]={get(){let{level:t}=this;return function(...o){let n=R(T(r,_[t],"bgColor",...o),a.bgColor.close,this[b]);return p(this,n,this[d])}}}}var W=Object.defineProperties(()=>{},{...h,level:{enumerable:!0,get(){return this[C].level},set(r){this[C].level=r}}}),R=(r,e,t)=>{let o,n;return t===void 0?(o=r,n=e):(o=t.openAll+r,n=e+t.closeAll),{open:r,close:e,openAll:o,closeAll:n,parent:t}},p=(r,e,t)=>{let o=(...n)=>H(o,n.length===1?""+n[0]:n.join(" "));return Object.setPrototypeOf(o,W),o[C]=r,o[b]=e,o[d]=t,o},H=(r,e)=>{if(r.level<=0||!e)return r[d]?"":e;let t=r[b];if(t===void 0)return e;let{openAll:o,closeAll:n}=t;if(e.includes("\x1B"))for(;t!==void 0;)e=M(e,t.close,t.open),t=t.parent;let i=e.indexOf(`
|
|
5
|
-
`);return i!==-1&&(e=I(e,n,o,i)),o+e+n};Object.defineProperties(m.prototype,h);var q=m(),se=m({level:F?F.level:0});var f=q;var ce=()=>`${f.red("=")}${f.green("=")}${f.blue("=")}${f.red("=")}${f.green("=")}${f.blue("=")}`;export{ce as default};
|
|
1
|
+
import e from"chalk";var $=()=>`${e.red("=")}${e.green("=")}${e.blue("=")}${e.red("=")}${e.green("=")}${e.blue("=")}`;export{$ as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var n=(e={})=>Object.entries(e).map(([r,t])=>`${r}=${t}`)?.join("&");export{n as default};
|
package/dist/test.js
CHANGED
|
@@ -1,4 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
$ ava ${e}
|
|
4
|
-
`),u.exit(1)}else throw new Error("The \u2019ava\u2019 module can only be imported in test files")});var g=o(i=>{"use strict";i.flags={loadedMain:!1};i.refs={runnerChain:null};i.sharedWorkerTeardowns=[];i.waitForReady=[]});var w=o((z,m)=>{"use strict";p();var k=t("node:assert"),{flags:E,refs:q}=g();k(q.runnerChain);E.loadedMain=!0;m.exports=q.runnerChain});var l=y(w(),1);var c=class{constructor(){}that(r="",n=null){return(0,l.default)(r,n)}},G=new c;export{G as default};
|
|
1
|
+
import e from"ava";class a{constructor(){}before(r=null){return e.serial.before(r)}beforeEach(r=null){return e.beforeEach(r)}after(r=null){return e.after.always(r)}afterEach(r=null){return e.afterEach.always(r)}that(r="",t=null){return e(r,t)}}var u=new a;export{u as default};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@joystick.js/test-canary",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.0-canary.
|
|
4
|
+
"version": "0.0.0-canary.31",
|
|
5
5
|
"description": "Isomorphic testing framework for the Joystick JavaScript framework.",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"scripts": {
|
|
@@ -13,5 +13,8 @@
|
|
|
13
13
|
},
|
|
14
14
|
"keywords": [],
|
|
15
15
|
"author": "",
|
|
16
|
-
"license": "SAUCR"
|
|
16
|
+
"license": "SAUCR",
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"ava": "^5.3.1"
|
|
19
|
+
}
|
|
17
20
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export default (eventType = '', eventTarget = '', dom = {}) => {
|
|
2
|
+
const app = dom?.document?.querySelector('#app');
|
|
3
|
+
const target = app?.querySelector(eventTarget);
|
|
4
|
+
const eventToDispatch = new Event(eventType);
|
|
5
|
+
|
|
6
|
+
target.dispatchEvent(eventToDispatch);
|
|
7
|
+
|
|
8
|
+
return true;
|
|
9
|
+
};
|
|
@@ -1 +1,44 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
|
+
import { parseHTML } from 'linkedom';
|
|
3
|
+
import joystick from '@joystick.js/ui-canary';
|
|
4
|
+
import event from './event.js';
|
|
5
|
+
import load from "../load/index.js";
|
|
6
|
+
|
|
7
|
+
const loadDOM = () => {
|
|
8
|
+
const dom = parseHTML(`<div id="app"></div>`);
|
|
9
|
+
const { window, document, Element, Event, HTMLElement } = dom;
|
|
10
|
+
|
|
11
|
+
global.window = window;
|
|
12
|
+
global.document = document;
|
|
13
|
+
global.HTMLElement = HTMLElement;
|
|
14
|
+
global.Element = Element;
|
|
15
|
+
global.Event = Event;
|
|
16
|
+
global.console = {
|
|
17
|
+
log: console.log,
|
|
18
|
+
warn: console.warn,
|
|
19
|
+
error: console.error,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
return dom;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export default async (pathToComponent = '', options = {}) => {
|
|
26
|
+
const dom = loadDOM();
|
|
27
|
+
|
|
28
|
+
window.joystick = {};
|
|
29
|
+
|
|
30
|
+
// NOTE: Force default to true as that's the prescribed pattern for
|
|
31
|
+
// Joystick component files.
|
|
32
|
+
const Component = await load(pathToComponent, { default: true });
|
|
33
|
+
const component = joystick.mount(Component, options?.props || {}, document.querySelector('#app'));
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
...dom,
|
|
37
|
+
component,
|
|
38
|
+
test: {
|
|
39
|
+
event: (eventType = '', eventTarget = '') => {
|
|
40
|
+
return event(eventType, eventTarget, dom);
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
};
|
|
@@ -1 +1,58 @@
|
|
|
1
|
-
|
|
1
|
+
import loadSettings from "../../lib/loadSettings.js";
|
|
2
|
+
import connectMongoDB from './mongodb/index.js';
|
|
3
|
+
import connectPostgreSQL from './postgresql/index.js';
|
|
4
|
+
|
|
5
|
+
export default async () => {
|
|
6
|
+
const settings = (await loadSettings({ environment: 'test' }))?.parsed;
|
|
7
|
+
|
|
8
|
+
const databases = settings?.config?.databases?.map((database) => {
|
|
9
|
+
return {
|
|
10
|
+
provider: database?.provider,
|
|
11
|
+
settings: database,
|
|
12
|
+
};
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
for (
|
|
16
|
+
let databaseIndex = 0;
|
|
17
|
+
databaseIndex < databases?.length;
|
|
18
|
+
databaseIndex += 1
|
|
19
|
+
) {
|
|
20
|
+
const database = databases[databaseIndex];
|
|
21
|
+
const hasMultipleOfProvider = (databases?.filter((database) => database?.provider === database?.provider))?.length > 1;
|
|
22
|
+
const databasePort = parseInt(process.env.PORT, 10) + 10 + databaseIndex;
|
|
23
|
+
|
|
24
|
+
if (database?.provider === "mongodb") {
|
|
25
|
+
const mongodb = await connectMongoDB(database?.settings, databasePort);
|
|
26
|
+
process.databases = {
|
|
27
|
+
...(process.databases || {}),
|
|
28
|
+
mongodb: !hasMultipleOfProvider ? mongodb : {
|
|
29
|
+
...(process?.databases?.mongodb || {}),
|
|
30
|
+
[database?.settings?.name || `mongodb_${databasePort}`]: mongodb,
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (database?.provider === "postgresql") {
|
|
36
|
+
const postgresql = await connectPostgreSQL(
|
|
37
|
+
database?.settings,
|
|
38
|
+
databasePort
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
process.databases = {
|
|
42
|
+
...(process.databases || {}),
|
|
43
|
+
postgresql: !hasMultipleOfProvider ? {
|
|
44
|
+
...postgresql?.pool,
|
|
45
|
+
query: postgresql?.query,
|
|
46
|
+
} : {
|
|
47
|
+
...(process?.databases?.postgresql || {}),
|
|
48
|
+
[database?.settings?.name || `postgresql_${databasePort}`]: {
|
|
49
|
+
...postgresql?.pool,
|
|
50
|
+
query: postgresql?.query,
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return process.databases;
|
|
58
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export default [
|
|
2
|
+
"replicaSet",
|
|
3
|
+
"tls",
|
|
4
|
+
"ssl",
|
|
5
|
+
"tlsCertificateKeyFile",
|
|
6
|
+
"tlsCertificateKeyFilePassword",
|
|
7
|
+
"tlsCAFile",
|
|
8
|
+
"tlsAllowInvalidCertificates",
|
|
9
|
+
"tlsAllowInvalidHostnames",
|
|
10
|
+
"tlsInsecure",
|
|
11
|
+
"connectTimeoutMS",
|
|
12
|
+
"socketTimeoutMS",
|
|
13
|
+
"compressors",
|
|
14
|
+
"zlibCompressionLevel",
|
|
15
|
+
"maxPoolSize",
|
|
16
|
+
"minPoolSize",
|
|
17
|
+
"maxIdleTimeMS",
|
|
18
|
+
"waitQueueMultiple",
|
|
19
|
+
"waitQueueTimeoutMS",
|
|
20
|
+
"w",
|
|
21
|
+
"wtimeoutMS",
|
|
22
|
+
"journal",
|
|
23
|
+
"readConcernLevel",
|
|
24
|
+
"readPreference",
|
|
25
|
+
"maxStalenessSeconds",
|
|
26
|
+
"readPreferenceTags",
|
|
27
|
+
"authSource",
|
|
28
|
+
"authMechanism",
|
|
29
|
+
"authMechanismProperties",
|
|
30
|
+
"gssapiServiceName",
|
|
31
|
+
"localThresholdMS",
|
|
32
|
+
"serverSelectionTimeoutMS",
|
|
33
|
+
"serverSelectionTryOnce",
|
|
34
|
+
"heartbeatFrequencyMS",
|
|
35
|
+
"appName",
|
|
36
|
+
"retryReads",
|
|
37
|
+
"retryWrites",
|
|
38
|
+
"uuidRepresentation"
|
|
39
|
+
];
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import buildQueryParameters from "./buildQueryParameters.js";
|
|
2
|
+
import serializeQueryParameters from "../../../lib/serializeQueryParameters.js";
|
|
3
|
+
|
|
4
|
+
export default (connection = {}) => {
|
|
5
|
+
let connectionString = "mongodb://";
|
|
6
|
+
|
|
7
|
+
if (connection && (connection.username || connection.password)) {
|
|
8
|
+
connectionString = `${connectionString}${connection.username || connection.password ? `${connection.username || ""}${!!connection.username && !!connection.password ? ':' : ''}${connection.password || ""}@` : ''}`;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
if (connection && connection.hosts && Array.isArray(connection.hosts)) {
|
|
12
|
+
connectionString = `${connectionString}${connection.hosts
|
|
13
|
+
.map((host) => `${host.hostname}:${host.port}`)
|
|
14
|
+
.join(",")}`;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (connection && connection.database) {
|
|
18
|
+
connectionString = `${connectionString}/${connection.database}`;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const queryParameters = buildQueryParameters(connection);
|
|
22
|
+
|
|
23
|
+
if (Object.keys(queryParameters)?.length > 0 ) {
|
|
24
|
+
connectionString = `${connectionString}?${serializeQueryParameters(queryParameters)}`;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return connectionString;
|
|
28
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import availableQueryParameters from "./availableQueryParameters.js";
|
|
2
|
+
|
|
3
|
+
export default (connection = {}) => {
|
|
4
|
+
const queryParameters = {};
|
|
5
|
+
|
|
6
|
+
for (let i = 0; i < availableQueryParameters.length; i += 1) {
|
|
7
|
+
const availableParameter = availableQueryParameters[i];
|
|
8
|
+
|
|
9
|
+
if (connection && connection[availableParameter]) {
|
|
10
|
+
queryParameters[availableParameter] = connection[availableParameter];
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return queryParameters;
|
|
15
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { MongoClient } from "mongodb";
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
import mongoUri from "mongo-uri-tool";
|
|
4
|
+
import fs from 'fs';
|
|
5
|
+
import buildConnectionString from "./buildConnectionString.js";
|
|
6
|
+
|
|
7
|
+
export default async (settings = {}, databasePort = 2610) => {
|
|
8
|
+
const connection = settings?.connection || {
|
|
9
|
+
hosts: [
|
|
10
|
+
// NOTE: By default, expect databases start from 2610 (assuming a PORT of 2600).
|
|
11
|
+
{ hostname: "127.0.0.1", port: databasePort },
|
|
12
|
+
],
|
|
13
|
+
database: "app",
|
|
14
|
+
replicaSet: `joystick_${databasePort}`,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const connectionString = buildConnectionString(connection);
|
|
18
|
+
const parsedURI = mongoUri.parseUri(connectionString);
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
const connectionOptions = {
|
|
22
|
+
useNewUrlParser: true,
|
|
23
|
+
useUnifiedTopology: true,
|
|
24
|
+
ssl: !['development', 'test'].includes(process.env.NODE_ENV),
|
|
25
|
+
...(settings?.options || {})
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
if (settings?.options?.ca) {
|
|
29
|
+
connectionOptions.ca = fs.readFileSync(settings?.options?.ca);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const client = await MongoClient.connect(connectionString, connectionOptions);
|
|
33
|
+
const db = client.db(parsedURI.db);
|
|
34
|
+
|
|
35
|
+
return db;
|
|
36
|
+
} catch (exception) {
|
|
37
|
+
console.warn(
|
|
38
|
+
chalk.yellowBright(
|
|
39
|
+
`\nFailed to connect to MongoDB. Please double-check connection settings and try again.\n\nError from MongoDB:\n\n${chalk.redBright(exception?.message)}`
|
|
40
|
+
),
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const createUniqueIndex = async (indexName = '', tableName = '', tableColumns = []) => {
|
|
2
|
+
return process.databases._users?.query(`CREATE UNIQUE INDEX IF NOT EXISTS ${indexName} ON ${tableName}(${tableColumns.join(', ')})`);
|
|
3
|
+
};
|
|
4
|
+
|
|
5
|
+
const createIndex = async (indexName = '', tableName = '', tableColumns = []) => {
|
|
6
|
+
return process.databases._users?.query(`CREATE INDEX IF NOT EXISTS ${indexName} ON ${tableName}(${tableColumns.join(', ')})`);
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export default async () => {
|
|
10
|
+
// users
|
|
11
|
+
await createIndex('user_by_email', 'users', ['email_address']);
|
|
12
|
+
await createIndex('user_by_username', 'users', ['username']);
|
|
13
|
+
await createIndex('user_by_user_id', 'users', ['user_id']);
|
|
14
|
+
|
|
15
|
+
// users_sessions
|
|
16
|
+
await createIndex('user_session_by_token', 'users_sessions', ['token']);
|
|
17
|
+
|
|
18
|
+
// users_password_reset_tokens
|
|
19
|
+
await createIndex('user_password_reset_token_by_token', 'users_password_reset_tokens', ['token']);
|
|
20
|
+
await createIndex('user_password_reset_token_by_user_id_token', 'users_password_reset_tokens', ['user_id', 'token']);
|
|
21
|
+
|
|
22
|
+
// users_roles
|
|
23
|
+
await createIndex('user_role', 'users_roles', ['role']);
|
|
24
|
+
await createIndex('user_roles_by_user_id_role', 'users_roles', ['user_id', 'role']);
|
|
25
|
+
|
|
26
|
+
// roles
|
|
27
|
+
await createIndex('role', 'roles', ['role']);
|
|
28
|
+
await createUniqueIndex('user_roles', 'users_roles', ['user_id', 'role']);
|
|
29
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
const createTable = async (table = "", tableColumns = []) => {
|
|
2
|
+
return process.databases._users?.query(
|
|
3
|
+
`CREATE TABLE IF NOT EXISTS ${table} (${tableColumns.join(", ")})`
|
|
4
|
+
);
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export default async () => {
|
|
8
|
+
await createTable("users", [
|
|
9
|
+
"id bigserial primary key",
|
|
10
|
+
"user_id text",
|
|
11
|
+
"email_address text",
|
|
12
|
+
"password text",
|
|
13
|
+
"username text",
|
|
14
|
+
"language text",
|
|
15
|
+
]);
|
|
16
|
+
|
|
17
|
+
await createTable("users_sessions", [
|
|
18
|
+
"id bigserial primary key",
|
|
19
|
+
"user_id text",
|
|
20
|
+
"token text",
|
|
21
|
+
"token_expires_at text",
|
|
22
|
+
]);
|
|
23
|
+
|
|
24
|
+
await createTable("users_password_reset_tokens", [
|
|
25
|
+
"id bigserial primary key",
|
|
26
|
+
"user_id text",
|
|
27
|
+
"token text",
|
|
28
|
+
"requested_at text",
|
|
29
|
+
]);
|
|
30
|
+
|
|
31
|
+
await createTable("users_verify_email_tokens", [
|
|
32
|
+
"id bigserial primary key",
|
|
33
|
+
"user_id text",
|
|
34
|
+
"token text",
|
|
35
|
+
]);
|
|
36
|
+
|
|
37
|
+
await createTable("roles", ["id bigserial primary key", "role text"]);
|
|
38
|
+
|
|
39
|
+
await createTable("users_roles", [
|
|
40
|
+
"id bigserial primary key",
|
|
41
|
+
"user_id text",
|
|
42
|
+
"role text",
|
|
43
|
+
]);
|
|
44
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import postgresql from 'pg';
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
import os from 'os';
|
|
4
|
+
|
|
5
|
+
const { Pool } = postgresql;
|
|
6
|
+
|
|
7
|
+
export default async (settings = {}, databasePort = 2610) => {
|
|
8
|
+
const connection = settings?.connection || {
|
|
9
|
+
hosts: [
|
|
10
|
+
{ hostname: "127.0.0.1", port: databasePort },
|
|
11
|
+
],
|
|
12
|
+
database: "app",
|
|
13
|
+
// NOTE: PostgreSQL creates a default superuser based on the OS username.
|
|
14
|
+
username: (os.userInfo() || {}).username || "",
|
|
15
|
+
password: "",
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
try {
|
|
19
|
+
const host = connection.hosts && connection.hosts[0];
|
|
20
|
+
const pool = new Pool({
|
|
21
|
+
user: connection?.username || '',
|
|
22
|
+
database: connection?.database,
|
|
23
|
+
password: connection?.password || '',
|
|
24
|
+
host: host?.hostname,
|
|
25
|
+
port: host?.port,
|
|
26
|
+
...(settings?.options || {})
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
pool,
|
|
31
|
+
query: (...args) => {
|
|
32
|
+
return pool.query(...args).then((response) => {
|
|
33
|
+
return response?.rows || [];
|
|
34
|
+
}).catch((error) => {
|
|
35
|
+
console.log(chalk.redBright(`\nFailed SQL Statement:\n`));
|
|
36
|
+
console.log(args[0]);
|
|
37
|
+
console.log(`\n`);
|
|
38
|
+
console.log(chalk.redBright(`\nFailed Values:\n`));
|
|
39
|
+
console.log(args[1]);
|
|
40
|
+
|
|
41
|
+
throw error;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
} catch (exception) {
|
|
46
|
+
console.warn(
|
|
47
|
+
chalk.yellowBright(
|
|
48
|
+
`\nFailed to connect to PostgreSQL. Please double-check connection settings and try again.\n\nError from PostgreSQL:\n\n${chalk.redBright(exception?.message)}`
|
|
49
|
+
),
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
|
-
import
|
|
2
|
+
import CLILog from "../../lib/CLILog.js";
|
|
3
|
+
|
|
4
|
+
const uncachedImport = async (path = '', options = {}) => {
|
|
5
|
+
const modulePath = `${path}?update=${Date.now()}`
|
|
6
|
+
const contents = await import(modulePath);
|
|
7
|
+
return (contents?.default && options?.default) ? contents.default : contents;
|
|
8
|
+
};
|
|
3
9
|
|
|
4
10
|
export default async (path = '', options = {}) => {
|
|
5
11
|
const sanitizedPath = path?.charAt(0) === '/' ? path.substring(1, path.length) : path;
|
|
6
|
-
|
|
12
|
+
// NOTE: Use timestamp to cache bust on import() below.
|
|
13
|
+
const buildPath = `${process.cwd()}/.joystick/build/${sanitizedPath}`;
|
|
7
14
|
const pathExists = fs.existsSync(buildPath);
|
|
8
15
|
|
|
9
16
|
if (!pathExists) {
|
|
10
|
-
|
|
17
|
+
CLILog(`[test.load] Path at ${buildPath} not found.`, {
|
|
11
18
|
level: 'warning',
|
|
12
19
|
docs: 'https://cheatcode.co/docs/joystick/test/load',
|
|
13
20
|
});
|
|
@@ -15,7 +22,5 @@ export default async (path = '', options = {}) => {
|
|
|
15
22
|
return null;
|
|
16
23
|
}
|
|
17
24
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return (contents?.default && options?.default) ? contents.default : contents;
|
|
25
|
+
return uncachedImport(buildPath, options);
|
|
21
26
|
};
|
|
@@ -1 +1,9 @@
|
|
|
1
|
-
export default {
|
|
1
|
+
export default {
|
|
2
|
+
job: (queueName = '', job = {}) => {
|
|
3
|
+
// TODO: Add a job of name to queueName.
|
|
4
|
+
// TODO: Run the job immediately.
|
|
5
|
+
// TODO: Return result of job.
|
|
6
|
+
// TODO: In test, either verify that response is as expected, or, test for known
|
|
7
|
+
// side-effects of the job in database.
|
|
8
|
+
},
|
|
9
|
+
};
|
package/src/index.js
CHANGED
|
@@ -10,7 +10,11 @@ import uploaders from './helpers/uploaders/index.js';
|
|
|
10
10
|
import websockets from './helpers/websockets/index.js';
|
|
11
11
|
|
|
12
12
|
export default {
|
|
13
|
+
after: test.after,
|
|
14
|
+
afterEach: test.afterEach,
|
|
13
15
|
api,
|
|
16
|
+
before: test.before,
|
|
17
|
+
beforeEach: test.beforeEach,
|
|
14
18
|
component,
|
|
15
19
|
databases,
|
|
16
20
|
email,
|
|
@@ -18,7 +18,7 @@ export default (message = '', options = {}) => {
|
|
|
18
18
|
|
|
19
19
|
const color = options.level ? colors[options.level] : 'gray';
|
|
20
20
|
const title = options.level ? titles[options.level] : 'Log';
|
|
21
|
-
const docs = options.docs || 'https://
|
|
21
|
+
const docs = options.docs || 'https://github.com/cheatcode/joystick';
|
|
22
22
|
|
|
23
23
|
console.log(`\n${(options.padding || '')}${rainbowRoad()}\n`);
|
|
24
24
|
console.log(`${(options.padding || '')}${chalk[color](`${title}:`)}\n`)
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export default (length = 16) => {
|
|
2
|
+
let result = [];
|
|
3
|
+
let character = [
|
|
4
|
+
"0",
|
|
5
|
+
"1",
|
|
6
|
+
"2",
|
|
7
|
+
"3",
|
|
8
|
+
"4",
|
|
9
|
+
"5",
|
|
10
|
+
"6",
|
|
11
|
+
"7",
|
|
12
|
+
"8",
|
|
13
|
+
"9",
|
|
14
|
+
"a",
|
|
15
|
+
"b",
|
|
16
|
+
"c",
|
|
17
|
+
"d",
|
|
18
|
+
"e",
|
|
19
|
+
"f",
|
|
20
|
+
"g",
|
|
21
|
+
"h",
|
|
22
|
+
"i",
|
|
23
|
+
"j",
|
|
24
|
+
"k",
|
|
25
|
+
"l",
|
|
26
|
+
"m",
|
|
27
|
+
"n",
|
|
28
|
+
"o",
|
|
29
|
+
"p",
|
|
30
|
+
"q",
|
|
31
|
+
"r",
|
|
32
|
+
"s",
|
|
33
|
+
"t",
|
|
34
|
+
"u",
|
|
35
|
+
"v",
|
|
36
|
+
"w",
|
|
37
|
+
"x",
|
|
38
|
+
"y",
|
|
39
|
+
"z",
|
|
40
|
+
"A",
|
|
41
|
+
"B",
|
|
42
|
+
"C",
|
|
43
|
+
"D",
|
|
44
|
+
"E",
|
|
45
|
+
"F",
|
|
46
|
+
"G",
|
|
47
|
+
"H",
|
|
48
|
+
"I",
|
|
49
|
+
"J",
|
|
50
|
+
"K",
|
|
51
|
+
"L",
|
|
52
|
+
"M",
|
|
53
|
+
"N",
|
|
54
|
+
"O",
|
|
55
|
+
"P",
|
|
56
|
+
"Q",
|
|
57
|
+
"R",
|
|
58
|
+
"S",
|
|
59
|
+
"T",
|
|
60
|
+
"U",
|
|
61
|
+
"V",
|
|
62
|
+
"W",
|
|
63
|
+
"X",
|
|
64
|
+
"Y",
|
|
65
|
+
"Z",
|
|
66
|
+
];
|
|
67
|
+
|
|
68
|
+
for (let n = 0; n < length; n++) {
|
|
69
|
+
result.push(character[Math.floor(Math.random() * 16)]);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return result.join("");
|
|
73
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/* eslint-disable consistent-return */
|
|
2
|
+
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import CLILog from "./CLILog.js";
|
|
5
|
+
import isValidJSONString from "./isValidJSONString.js";
|
|
6
|
+
|
|
7
|
+
const warnIfInvalidJSONInSettings = (settings = '') => {
|
|
8
|
+
try {
|
|
9
|
+
const isValidJSON = isValidJSONString(settings);
|
|
10
|
+
const context = process.env.NODE_ENV === 'test' ? 'test' : 'start';
|
|
11
|
+
|
|
12
|
+
if (!isValidJSON) {
|
|
13
|
+
CLILog(
|
|
14
|
+
`Failed to parse settings file. Double-check the syntax in your settings.${process.env.NODE_ENV}.json file at the root of your project and rerun joystick ${context}.`,
|
|
15
|
+
{
|
|
16
|
+
level: "danger",
|
|
17
|
+
docs: `https://cheatcode.co/docs/joystick/environment-settings`,
|
|
18
|
+
tools: [{ title: "JSON Linter", url: "https://jsonlint.com/" }],
|
|
19
|
+
}
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
process.exit(0);
|
|
23
|
+
}
|
|
24
|
+
} catch (exception) {
|
|
25
|
+
throw new Error(`[loadSettings.warnIfInvalidJSONInSettings] ${exception.message}`);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const getSettings = (settingsPath = '') => {
|
|
30
|
+
try {
|
|
31
|
+
return fs.readFileSync(settingsPath, 'utf-8');
|
|
32
|
+
} catch (exception) {
|
|
33
|
+
throw new Error(`[loadSettings.getSettings] ${exception.message}`);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const warnIfSettingsNotFound = (settingsPath = '') => {
|
|
38
|
+
try {
|
|
39
|
+
const hasSettingsFile = fs.existsSync(settingsPath);
|
|
40
|
+
const context = process.env.NODE_ENV === 'test' ? 'test' : 'start';
|
|
41
|
+
|
|
42
|
+
if (!hasSettingsFile) {
|
|
43
|
+
CLILog(
|
|
44
|
+
`A settings file could not be found for this environment (${process.env.NODE_ENV}). Create a settings.${process.env.NODE_ENV}.json file at the root of your project and rerun joystick ${context}.`,
|
|
45
|
+
{
|
|
46
|
+
level: "danger",
|
|
47
|
+
docs: `https://cheatcode.co/docs/joystick/cli/${context}`,
|
|
48
|
+
}
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
process.exit(0);
|
|
52
|
+
}
|
|
53
|
+
} catch (exception) {
|
|
54
|
+
throw new Error(`[loadSettings.warnIfSettingsNotFound] ${exception.message}`);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const validateOptions = (options) => {
|
|
59
|
+
try {
|
|
60
|
+
if (!options) throw new Error('options object is required.');
|
|
61
|
+
if (!options.environment) throw new Error('options.environment is required.');
|
|
62
|
+
} catch (exception) {
|
|
63
|
+
throw new Error(`[loadSettings.validateOptions] ${exception.message}`);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const loadSettings = (options, { resolve, reject }) => {
|
|
68
|
+
try {
|
|
69
|
+
validateOptions(options);
|
|
70
|
+
|
|
71
|
+
const settingsPath = `${process.cwd()}/settings.${options.environment}.json`;
|
|
72
|
+
warnIfSettingsNotFound(settingsPath);
|
|
73
|
+
const settings = getSettings(settingsPath);
|
|
74
|
+
warnIfInvalidJSONInSettings(settings);
|
|
75
|
+
|
|
76
|
+
process.env.JOYSTICK_SETTINGS = settings;
|
|
77
|
+
|
|
78
|
+
resolve({
|
|
79
|
+
parsed: JSON.parse(settings),
|
|
80
|
+
unparsed: settings,
|
|
81
|
+
});
|
|
82
|
+
} catch (exception) {
|
|
83
|
+
reject(`[loadSettings] ${exception.message}`);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export default (options) =>
|
|
88
|
+
new Promise((resolve, reject) => {
|
|
89
|
+
loadSettings(options, { resolve, reject });
|
|
90
|
+
});
|
package/src/test.js
CHANGED
|
@@ -4,7 +4,29 @@ class Test {
|
|
|
4
4
|
constructor() {
|
|
5
5
|
|
|
6
6
|
}
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
before(callback = null) {
|
|
9
|
+
// NOTE: Prefer serial before to async to align better with
|
|
10
|
+
// expectations and avoid confusion.
|
|
11
|
+
return test.serial.before(callback);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
beforeEach(callback = null) {
|
|
15
|
+
return test.beforeEach(callback);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
after(callback = null) {
|
|
19
|
+
// NOTE: Prefer after always to guarantee cleanup and avoid
|
|
20
|
+
// messy test suites that may or may not cleanup due to failures.
|
|
21
|
+
return test.after.always(callback);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
afterEach(callback = null) {
|
|
25
|
+
// NOTE: Prefer afterEach always to guarantee cleanup and avoid
|
|
26
|
+
// messy test suites that may or may not cleanup due to failures.
|
|
27
|
+
return test.afterEach.always(callback);
|
|
28
|
+
}
|
|
29
|
+
|
|
8
30
|
that(description = '', callback = null) {
|
|
9
31
|
return test(description, callback);
|
|
10
32
|
}
|
package/dist/lib/log.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
var E=(r=0)=>e=>`\x1B[${e+r}m`,v=(r=0)=>e=>`\x1B[${38+r};5;${e}m`,x=(r=0)=>(e,o,t)=>`\x1B[${38+r};2;${e};${o};${t}m`,l={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],overline:[53,55],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],blackBright:[90,39],gray:[90,39],grey:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgGray:[100,49],bgGrey:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}},z=Object.keys(l.modifier),_=Object.keys(l.color),k=Object.keys(l.bgColor),J=[..._,...k];function j(){let r=new Map;for(let[e,o]of Object.entries(l)){for(let[t,n]of Object.entries(o))l[t]={open:`\x1B[${n[0]}m`,close:`\x1B[${n[1]}m`},o[t]=l[t],r.set(n[0],n[1]);Object.defineProperty(l,e,{value:o,enumerable:!1})}return Object.defineProperty(l,"codes",{value:r,enumerable:!1}),l.color.close="\x1B[39m",l.bgColor.close="\x1B[49m",l.color.ansi=E(),l.color.ansi256=v(),l.color.ansi16m=x(),l.bgColor.ansi=E(10),l.bgColor.ansi256=v(10),l.bgColor.ansi16m=x(10),Object.defineProperties(l,{rgbToAnsi256:{value(e,o,t){return e===o&&o===t?e<8?16:e>248?231:Math.round((e-8)/247*24)+232:16+36*Math.round(e/255*5)+6*Math.round(o/255*5)+Math.round(t/255*5)},enumerable:!1},hexToRgb:{value(e){let o=/[a-f\d]{6}|[a-f\d]{3}/i.exec(e.toString(16));if(!o)return[0,0,0];let[t]=o;t.length===3&&(t=[...t].map(s=>s+s).join(""));let n=Number.parseInt(t,16);return[n>>16&255,n>>8&255,n&255]},enumerable:!1},hexToAnsi256:{value:e=>l.rgbToAnsi256(...l.hexToRgb(e)),enumerable:!1},ansi256ToAnsi:{value(e){if(e<8)return 30+e;if(e<16)return 90+(e-8);let o,t,n;if(e>=232)o=((e-232)*10+8)/255,t=o,n=o;else{e-=16;let b=e%36;o=Math.floor(e/36)/5,t=Math.floor(b/6)/5,n=b%6/5}let s=Math.max(o,t,n)*2;if(s===0)return 30;let c=30+(Math.round(n)<<2|Math.round(t)<<1|Math.round(o));return s===2&&(c+=60),c},enumerable:!1},rgbToAnsi:{value:(e,o,t)=>l.ansi256ToAnsi(l.rgbToAnsi256(e,o,t)),enumerable:!1},hexToAnsi:{value:e=>l.ansi256ToAnsi(l.hexToAnsi256(e)),enumerable:!1}}),l}var L=j(),f=L;import T from"node:process";import P from"node:os";import N from"node:tty";function u(r,e=globalThis.Deno?globalThis.Deno.args:T.argv){let o=r.startsWith("-")?"":r.length===1?"-":"--",t=e.indexOf(o+r),n=e.indexOf("--");return t!==-1&&(n===-1||t<n)}var{env:i}=T,p;u("no-color")||u("no-colors")||u("color=false")||u("color=never")?p=0:(u("color")||u("colors")||u("color=true")||u("color=always"))&&(p=1);function G(){if("FORCE_COLOR"in i)return i.FORCE_COLOR==="true"?1:i.FORCE_COLOR==="false"?0:i.FORCE_COLOR.length===0?1:Math.min(Number.parseInt(i.FORCE_COLOR,10),3)}function Y(r){return r===0?!1:{level:r,hasBasic:!0,has256:r>=2,has16m:r>=3}}function D(r,{streamIsTTY:e,sniffFlags:o=!0}={}){let t=G();t!==void 0&&(p=t);let n=o?p:t;if(n===0)return 0;if(o){if(u("color=16m")||u("color=full")||u("color=truecolor"))return 3;if(u("color=256"))return 2}if("TF_BUILD"in i&&"AGENT_NAME"in i)return 1;if(r&&!e&&n===void 0)return 0;let s=n||0;if(i.TERM==="dumb")return s;if(T.platform==="win32"){let c=P.release().split(".");return Number(c[0])>=10&&Number(c[2])>=10586?Number(c[2])>=14931?3:2:1}if("CI"in i)return"GITHUB_ACTIONS"in i||"GITEA_ACTIONS"in i?3:["TRAVIS","CIRCLECI","APPVEYOR","GITLAB_CI","BUILDKITE","DRONE"].some(c=>c in i)||i.CI_NAME==="codeship"?1:s;if("TEAMCITY_VERSION"in i)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(i.TEAMCITY_VERSION)?1:0;if(i.COLORTERM==="truecolor"||i.TERM==="xterm-kitty")return 3;if("TERM_PROGRAM"in i){let c=Number.parseInt((i.TERM_PROGRAM_VERSION||"").split(".")[0],10);switch(i.TERM_PROGRAM){case"iTerm.app":return c>=3?3:2;case"Apple_Terminal":return 2}}return/-256(color)?$/i.test(i.TERM)?2:/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(i.TERM)||"COLORTERM"in i?1:s}function $(r,e={}){let o=D(r,{streamIsTTY:r&&r.isTTY,...e});return Y(o)}var U={stdout:$({isTTY:N.isatty(1)}),stderr:$({isTTY:N.isatty(2)})},B=U;function I(r,e,o){let t=r.indexOf(e);if(t===-1)return r;let n=e.length,s=0,c="";do c+=r.slice(s,t)+e+o,s=t+n,t=r.indexOf(e,s);while(t!==-1);return c+=r.slice(s),c}function M(r,e,o,t){let n=0,s="";do{let c=r[t-1]==="\r";s+=r.slice(n,c?t-1:t)+e+(c?`\r
|
|
2
|
-
`:`
|
|
3
|
-
`)+o,n=t+1,t=r.indexOf(`
|
|
4
|
-
`,n)}while(t!==-1);return s+=r.slice(n),s}var{stdout:S,stderr:F}=B,C=Symbol("GENERATOR"),d=Symbol("STYLER"),h=Symbol("IS_EMPTY"),w=["ansi","ansi","ansi256","ansi16m"],g=Object.create(null),V=(r,e={})=>{if(e.level&&!(Number.isInteger(e.level)&&e.level>=0&&e.level<=3))throw new Error("The `level` option should be an integer from 0 to 3");let o=S?S.level:0;r.level=e.level===void 0?o:e.level};var W=r=>{let e=(...o)=>o.join(" ");return V(e,r),Object.setPrototypeOf(e,m.prototype),e};function m(r){return W(r)}Object.setPrototypeOf(m.prototype,Function.prototype);for(let[r,e]of Object.entries(f))g[r]={get(){let o=O(this,y(e.open,e.close,this[d]),this[h]);return Object.defineProperty(this,r,{value:o}),o}};g.visible={get(){let r=O(this,this[d],!0);return Object.defineProperty(this,"visible",{value:r}),r}};var R=(r,e,o,...t)=>r==="rgb"?e==="ansi16m"?f[o].ansi16m(...t):e==="ansi256"?f[o].ansi256(f.rgbToAnsi256(...t)):f[o].ansi(f.rgbToAnsi(...t)):r==="hex"?R("rgb",e,o,...f.hexToRgb(...t)):f[o][r](...t),K=["rgb","hex","ansi256"];for(let r of K){g[r]={get(){let{level:o}=this;return function(...t){let n=y(R(r,w[o],"color",...t),f.color.close,this[d]);return O(this,n,this[h])}}};let e="bg"+r[0].toUpperCase()+r.slice(1);g[e]={get(){let{level:o}=this;return function(...t){let n=y(R(r,w[o],"bgColor",...t),f.bgColor.close,this[d]);return O(this,n,this[h])}}}}var H=Object.defineProperties(()=>{},{...g,level:{enumerable:!0,get(){return this[C].level},set(r){this[C].level=r}}}),y=(r,e,o)=>{let t,n;return o===void 0?(t=r,n=e):(t=o.openAll+r,n=e+o.closeAll),{open:r,close:e,openAll:t,closeAll:n,parent:o}},O=(r,e,o)=>{let t=(...n)=>Q(t,n.length===1?""+n[0]:n.join(" "));return Object.setPrototypeOf(t,H),t[C]=r,t[d]=e,t[h]=o,t},Q=(r,e)=>{if(r.level<=0||!e)return r[h]?"":e;let o=r[d];if(o===void 0)return e;let{openAll:t,closeAll:n}=o;if(e.includes("\x1B"))for(;o!==void 0;)e=I(e,o.close,o.open),o=o.parent;let s=e.indexOf(`
|
|
5
|
-
`);return s!==-1&&(e=M(e,n,t,s)),t+e+n};Object.defineProperties(m.prototype,g);var q=m(),ie=m({level:F?F.level:0});var a=q;var A=()=>`${a.red("=")}${a.green("=")}${a.blue("=")}${a.red("=")}${a.green("=")}${a.blue("=")}`;var ge=(r="",e={})=>{let o={info:"blue",success:"green",warning:"yellowBright",danger:"red"},t={info:"\u2771 Info",success:"\u2771 Ok",warning:"\u2771 Warning",danger:"\u2771 Error"},n=e.level?o[e.level]:"gray",s=e.level?t[e.level]:"Log",c=e.docs||"https://cheatcode.co/docs/joystick";console.log(`
|
|
6
|
-
${e.padding||""}${A()}
|
|
7
|
-
`),console.log(`${e.padding||""}${a[n](`${s}:`)}
|
|
8
|
-
`),console.log(`${e.padding||""}${a.white(r)}
|
|
9
|
-
`),console.log(`${e.padding||""}${a.grey("---")}
|
|
10
|
-
`),console.log(`${e.padding||""}${a.white("Relevant Documentation:")}
|
|
11
|
-
`),console.log(`${e.padding||""}${a.blue(c)}
|
|
12
|
-
`),console.log(`${e.padding||""}${a.white("Stuck? Ask a Question:")}
|
|
13
|
-
`),console.log(`${e.padding||""}${a.blue("https://github.com/cheatcode/joystick/discussions")}
|
|
14
|
-
`),e.tools&&Array.isArray(e.tools)&&(console.log(`${e.padding||""}${a.white("Helpful Tools:")}
|
|
15
|
-
`),e.tools.forEach(b=>{console.log(`${e.padding||""}${a.blue(`${b.title} \u2014 ${b.url}`)}
|
|
16
|
-
`)})),console.log(`${e.padding||""}${A()}
|
|
17
|
-
`)};export{ge as default};
|