@buildplease/core 1.0.2 → 1.1.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/README.md +22 -1
- package/dist/src-node/index.cjs +2 -2
- package/dist/src-node/index.d.cts +135 -5
- package/dist/src-node/index.d.mts +135 -5
- package/dist/src-node/index.mjs +2 -2
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -18,6 +18,27 @@ const assemblies = coreAssembly();
|
|
|
18
18
|
|
|
19
19
|
Node.js-specific APIs are available from `@buildplease/core/node`.
|
|
20
20
|
|
|
21
|
+
### Environment configuration
|
|
22
|
+
|
|
23
|
+
Node applications use one BuildPlease convention: `environment.config.ts`.
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { defineConfig, defineEnvironments, defineSource } from '@buildplease/core/node';
|
|
27
|
+
|
|
28
|
+
const environments = defineEnvironments({
|
|
29
|
+
test: { file: '.env.test' },
|
|
30
|
+
production: { file: '.env.production' },
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const from = defineSource(environments);
|
|
34
|
+
|
|
35
|
+
export default defineConfig(environments, {
|
|
36
|
+
origin: from.env('API_ORIGIN').default('http://localhost:30000'),
|
|
37
|
+
});
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Core owns config discovery, TypeScript loading, environment-file loading, source resolution, defaults, computed values, and reusable typed configuration contracts. Root configuration resolution always receives one explicit context containing both the selected environment and build metadata. Kits expose their own `defineConfig()` policy while using the same Core engine and loader.
|
|
41
|
+
|
|
21
42
|
## Features
|
|
22
43
|
|
|
23
44
|
- dependency injection and application assemblies
|
|
@@ -25,7 +46,7 @@ Node.js-specific APIs are available from `@buildplease/core/node`.
|
|
|
25
46
|
- errors, validation, and normalization primitives
|
|
26
47
|
- L10n resources and localization helpers
|
|
27
48
|
- security, synchronization, and general utilities
|
|
28
|
-
- Node.js infrastructure helpers
|
|
49
|
+
- Node.js environment configuration and infrastructure helpers
|
|
29
50
|
|
|
30
51
|
## License
|
|
31
52
|
|
package/dist/src-node/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n||t(r,Symbol.toStringTag,{value:`Module`}),r},s=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},c=(e,t,n)=>(s(e,t,`default`),n&&s(n,t,`default`)),l=(n,r,o)=>(o=n==null?{}:e(i(n)),s(r||!n||!n.__esModule||!a.call(n,`default`)?t(o,`default`,{value:n,enumerable:!0}):o,n));let u=require("node:module"),d=require("consola"),f=require("consola/utils"),p=require("
|
|
2
|
-
`)}formatPanelTop(e,t){let n=Math.max(1,t-this.visibleLength(e)-5);return`${f.colors.dim(`╭─`)} ${e} ${f.colors.dim(`─`.repeat(n))}${f.colors.dim(`╮`)}`}formatPanelBottom(e){return`${f.colors.dim(`╰`)}${f.colors.dim(`─`.repeat(e-2))}${f.colors.dim(`╯`)}`}formatPanelRow(e,t,n){let r=e.label.padEnd(14,` `),i=String(e.value),a=this.visibleLength(r)+this.visibleLength(i)+4,o=Math.max(0,t-a);return`${f.colors.dim(`│`)} ${f.colors.blue(r)}${n(i)}${` `.repeat(o)} ${f.colors.dim(`│`)}`}getPanelWidth(e){return Math.max(48,this.getTitleWidth(e),this.getRowsWidth(e.rows))}getTitleWidth(e){return this.visibleLength(e.title)+6}getRowsWidth(e){return Math.max(0,...e.map(e=>this.getRowWidth(e)))}getRowWidth(e){return 14+this.visibleLength(String(e.value))+4}visibleLength(e){return e.replace(ce,``).length}};const k=`${{name:`buildplease`,displayName:`BuildPlease`,scope:`@buildplease`}.name}.Core.DI`,A={DI:{Formatter:{UnitController:Symbol.for(`${k}.Formatter.UnitController`)},Logger:Symbol.for(`${k}.Logger`)}};function ue(e){return e instanceof Error}function j(e,t={}){if(e==null)return{};let{filterNull:n=!0,filterUndefined:r=!0,filterEmptyString:i=!1,filterEmptyObject:a=!1,filterEmptyArray:o=!1}=t;return Object.keys(e).reduce((s,c)=>{let l=e[c];return M(l)&&Object.getPrototypeOf(l)===null&&(l=void 0),de(l)&&(l=j(l,t)),n&&l===null||r&&l===void 0||i&&l===``||a&&N(l)||o&&Array.isArray(l)&&l.length===0||(s[c]=l),s},{})}function M(e){return typeof e==`object`&&!!e}function N(e){return M(e)&&Object.keys(e).length===0}function de(e){return M(e)&&Object.getPrototypeOf(e)===Object.prototype}function P(e){return e==null||[`string`,`number`,`boolean`,`bigint`,`symbol`].includes(typeof e)}Array.prototype.isEmpty=function(){return this==null||this.length===0},String.prototype.capitalized=function(){let e=this==null?``:this.toString();return e.trim()?e.charAt(0).toUpperCase()+e.slice(1):``};var F=class{streetLine1;streetLine2;postalCode;state;city;country;countryCode;constructor(e){this.streetLine1=e.streetLine1,this.streetLine2=e.streetLine2,this.postalCode=e.postalCode,this.state=e.state,this.city=e.city,this.country=e.country,this.countryCode=e.countryCode}toJSON(){return j({streetLine1:this.streetLine1,streetLine2:this.streetLine2,postalCode:this.postalCode,city:this.city,state:this.state,country:this.country,countryCode:this.countryCode},{filterNull:!0,filterUndefined:!0,filterEmptyString:!0})}formatted(){let e=(e,t)=>e.map(e=>e?.trim()).filter(e=>e&&e.length>0).join(t).trim(),t=this.streetLine1;return e([t,e([this.postalCode,this.city],` `),e([this.country],`, `)],`, `)}},I=class{email;fb;ig;phone;web;constructor({email:e,fb:t,ig:n,phone:r,web:i}){this.email=e,this.fb=t,this.ig=n,this.phone=r,this.web=i}toJSON(){return j({email:this.email,fb:this.fb,ig:this.ig,phone:this.phone,web:this.web},{filterNull:!0,filterUndefined:!0,filterEmptyString:!0})}},L=o({DateFormat:()=>z,DateTime:()=>R});c(L,require("date-fns"));var R=class e{date;constructor(e){if(!e){this.date=new Date;return}if(e instanceof Date){if(!(0,m.isValid)(e))throw Error(`Invalid date object`);this.date=e;return}let t=(0,m.parseISO)(e);if(!(0,m.isValid)(t))throw Error(`Invalid date string`);this.date=t}static fromUnixTimestamp(t,n){return new e((0,m.fromUnixTime)(t,n))}static now(){return new e(new Date)}toJSON(){return this.toISOString()}toDate(){return this.date}toUnixTimestamp(){return(0,m.getUnixTime)(this.date)}getTime(){return this.date.getTime()}toISOString(){return(0,m.formatISO)(this.date)}format(e,t){return(0,m.format)(this.date,e,t)}addingDuration(t){return new e((0,m.add)(this.date,t))}addingMilliseconds(t){return new e((0,m.addMilliseconds)(this.date,t))}addingSeconds(t){return new e((0,m.addSeconds)(this.date,t))}addingMinutes(t){return new e((0,m.addMinutes)(this.date,t))}addingHours(t){return new e((0,m.addHours)(this.date,t))}addingDays(t){return new e((0,m.addDays)(this.date,t))}addingWeeks(t){return new e((0,m.addWeeks)(this.date,t))}addingMonths(t){return new e((0,m.addMonths)(this.date,t))}addingYears(t){return new e((0,m.addYears)(this.date,t))}subtractingDuration(t){return new e((0,m.sub)(this.date,t))}subtractingMilliseconds(t){return new e((0,m.subMilliseconds)(this.date,t))}subtractingSeconds(t){return new e((0,m.subSeconds)(this.date,t))}subtractingMinutes(t){return new e((0,m.subMinutes)(this.date,t))}subtractingHours(t){return new e((0,m.subHours)(this.date,t))}subtractingDays(t){return new e((0,m.subDays)(this.date,t))}subtractingWeeks(t){return new e((0,m.subWeeks)(this.date,t))}subtractingMonths(t){return new e((0,m.subMonths)(this.date,t))}subtractingYears(t){return new e((0,m.subYears)(this.date,t))}differenceInMilliseconds(e){return(0,m.differenceInMilliseconds)(this.date,e.date)}differenceInSeconds(e){return(0,m.differenceInSeconds)(this.date,e.date)}differenceInMinutes(e){return(0,m.differenceInMinutes)(this.date,e.date)}differenceInHours(e){return(0,m.differenceInHours)(this.date,e.date)}differenceInDays(e){return(0,m.differenceInDays)(this.date,e.date)}differenceInWeeks(e){return(0,m.differenceInWeeks)(this.date,e.date)}differenceInMonths(e){return(0,m.differenceInMonths)(this.date,e.date)}differenceInYears(e){return(0,m.differenceInYears)(this.date,e.date)}isEqualTo(e){return(0,m.isEqual)(this.date,e.date)}isBefore(e){return(0,m.isBefore)(this.date,e.date)}isAfter(e){return(0,m.isAfter)(this.date,e.date)}compareTo(e){return(0,m.compareAsc)(this.date,e.date)}isSameDayAs(e){return(0,m.isSameDay)(this.date,e.date)}startOfDay(){return new e((0,m.startOfDay)(this.date))}endOfDay(){return new e((0,m.endOfDay)(this.date))}startOfWeek(){return new e((0,m.startOfWeek)(this.date))}endOfWeek(){return new e((0,m.endOfWeek)(this.date))}startOfMonth(){return new e((0,m.startOfMonth)(this.date))}endOfMonth(){return new e((0,m.endOfMonth)(this.date))}startOfYear(){return new e((0,m.startOfYear)(this.date))}endOfYear(){return new e((0,m.endOfYear)(this.date))}get dayOfMonth(){return(0,m.getDate)(this.date)}get dayOfWeek(){return(0,m.getDay)(this.date)}get month(){return(0,m.getMonth)(this.date)}get year(){return(0,m.getYear)(this.date)}get hours(){return(0,m.getHours)(this.date)}get minutes(){return(0,m.getMinutes)(this.date)}get seconds(){return(0,m.getSeconds)(this.date)}settingDayOfMonth(t){return new e((0,m.setDate)(this.date,t))}settingDayOfWeek(t){return new e((0,m.setDay)(this.date,t))}settingMonth(t){return new e((0,m.setMonth)(this.date,t))}settingYear(t){return new e((0,m.setYear)(this.date,t))}settingHours(t){return new e((0,m.setHours)(this.date,t))}settingMinutes(t){return new e((0,m.setMinutes)(this.date,t))}settingSeconds(t){return new e((0,m.setSeconds)(this.date,t))}};let z=function(e){return e.ISO_DATE=`yyyy-MM-dd`,e.ISO_DATETIME=`yyyy-MM-dd'T'HH:mm:ssXXX`,e.MM_DD_YYYY=`MM/dd/yyyy`,e.FULL_MONTH_DAY_YEAR=`MMMM d, yyyy`,e.ABBR_MONTH_DAY_YEAR=`MMM d, yyyy`,e.RFC_3339=`yyyy-MM-dd'T'HH:mm:ss.SSSxxx`,e.ALT_RSS=`d MMM yyyy HH:mm:ss ZZZ`,e.RSS=`EEE, d MMM yyyy HH:mm:ss ZZZ`,e.HTTP_HEADER=`EEE, dd MMM yyyy HH:mm:ss zzz`,e.STANDARD=`EEE MMM dd HH:mm:ss Z yyyy`,e.EXTENDED=`eee dd-MMM-yyyy GG HH:mm:ss.SSS zzz`,e}({});var B=class e{utc;timeZone;constructor(e,t){this.timeZone=e,this.utc=t??new Date}static fromUtc(t,n){return new e(n,t)}static fromLocalIso(t,n){let r=(0,h.fromZonedTime)(t,n);return new e(n,r)}format(e,t){return(0,h.formatInTimeZone)(this.utc,this.timeZone,e,t)}toLocalIsoMinutes(e){return this.format(`yyyy-MM-dd'T'HH:mm`,e)}toLocalIsoSeconds(e){return this.format(`yyyy-MM-dd'T'HH:mm:ss`,e)}toISOString(){return this.utc.toISOString()}toUnixTimestamp(){return Math.floor(this.utc.getTime()/1e3)}toZonedDate(){return(0,h.toZonedTime)(this.utc,this.timeZone)}timezoneOffsetMs(e){return(0,h.getTimezoneOffset)(this.timeZone,e??this.utc)}},V=class{value;constructor([e,t]){if(e<-180||e>180)throw Error(`Longitude must be between -180 and 180.`);if(t<-90||t>90)throw Error(`Latitude must be between -90 and 90.`);this.value=[e,t]}get longitude(){return this.value[0]}get latitude(){return this.value[1]}toJSON(){return this.value}},H=class{type=`Point`;coordinates;bbox;constructor(e,t){this.coordinates=e,this.bbox=t}toJSON(){return{type:this.type,coordinates:this.coordinates.toJSON(),...this.bbox&&{bbox:this.bbox}}}},fe=class{type=`MultiPoint`;coordinates;bbox;constructor(e,t){this.coordinates=e,this.bbox=t}toJSON(){return{type:this.type,coordinates:this.coordinates.map(e=>e.toJSON()),...this.bbox&&{bbox:this.bbox}}}},pe=class{type=`LineString`;coordinates;bbox;constructor(e,t){this.coordinates=e,this.bbox=t}toJSON(){return{type:this.type,coordinates:this.coordinates.map(e=>e.toJSON()),...this.bbox&&{bbox:this.bbox}}}},me=class{type=`MultiLineString`;coordinates;bbox;constructor(e,t){this.coordinates=e,this.bbox=t}toJSON(){return{type:this.type,coordinates:this.coordinates.map(e=>e.map(e=>e.toJSON())),...this.bbox&&{bbox:this.bbox}}}},he=class{type=`Polygon`;coordinates;bbox;constructor(e,t){this.coordinates=e,this.bbox=t}toJSON(){return{type:this.type,coordinates:this.coordinates.map(e=>e.map(e=>e.toJSON())),...this.bbox&&{bbox:this.bbox}}}},ge=class{type=`MultiPolygon`;coordinates;bbox;constructor(e,t){this.coordinates=e,this.bbox=t}toJSON(){return{type:this.type,coordinates:this.coordinates.map(e=>e.map(e=>e.map(e=>e.toJSON()))),...this.bbox&&{bbox:this.bbox}}}};let _e=function(e){return e.Point=`Point`,e.MultiPoint=`MultiPoint`,e.LineString=`LineString`,e.MultiLineString=`MultiLineString`,e.Polygon=`Polygon`,e.MultiPolygon=`MultiPolygon`,e}({});function U(e){return Error(`Invalid ObjectId value: ${String(e)}`)}var ve=class e{value;constructor(e){if(e==null)throw U(e);let t=e.trim();if(t.length===0)throw U(e);this.value=t,Object.freeze(this)}get asString(){return this.value}equals(t){return this.value===e.from(t).value}compare(t){let n=e.from(t).value;return this.value===n?0:this.value<n?-1:1}hash(){return this.value}toJSON(){return this.value}toString(){return this.value}[Symbol.toPrimitive](){return this.value}static from(t){return t instanceof e?t:new e(t)}static isValid(e){return typeof e==`string`&&e.trim().length>0}static toValueSet(t){let n=new Set;for(let r of t)n.add(e.from(r).value);return n}},ye=class{day;intervals;constructor(e,t){this.day=e,this.intervals=t}toJSON(){return j({day:this.day,intervals:this.intervals},{filterNull:!0,filterUndefined:!0,filterEmptyString:!0})}},be=class{_milliseconds;_long;constructor(e,t){if(this._long=t?.long===!0,e==null)throw Error(`Invalid interval format: ${e}`);if(typeof e==`number`)this._milliseconds=e;else{let t=(0,g.default)(e);if(t===void 0)throw Error(`Invalid interval format: ${e}`);this._milliseconds=t}}get milliseconds(){return this._milliseconds}get seconds(){return Math.floor(this._milliseconds/1e3)}get minutes(){return Math.floor(this._milliseconds/6e4)}get hours(){return Math.floor(this._milliseconds/36e5)}get days(){return Math.floor(this._milliseconds/864e5)}get weeks(){return Math.floor(this._milliseconds/6048e5)}get formatted(){return(0,g.default)(this._milliseconds,{long:this._long})}toString(){return(0,g.default)(this._milliseconds,{long:this._long})}toObject(){return{milliseconds:this._milliseconds,seconds:this.seconds,minutes:this.minutes,hours:this.hours,days:this.days,weeks:this.weeks}}};let xe=function(e){return e.Byte=`B`,e.Kilobyte=`KB`,e.Megabyte=`MB`,e.Gigabyte=`GB`,e.Terabyte=`TB`,e}({}),Se=function(e){return e.Millimeter=`mm`,e.Centimeter=`cm`,e.Meter=`m`,e.Kilometer=`km`,e}({}),Ce=function(e){return e.Milligram=`mg`,e.Gram=`g`,e.Kilogram=`kg`,e.Tonne=`t`,e}({});c(o({Address:()=>F,ByteUnit:()=>xe,Contacts:()=>I,Coordinates:()=>V,DateFormat:()=>z,DateTime:()=>R,DistanceUnit:()=>Se,GeoJsonType:()=>_e,LineString:()=>pe,MultiLineString:()=>me,MultiPoint:()=>fe,MultiPolygon:()=>ge,ObjectId:()=>ve,OpeningHour:()=>ye,Point:()=>H,Polygon:()=>he,TimeInterval:()=>be,WeightUnit:()=>Ce,ZonedDateTime:()=>B}),L);function we(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let W=class{formatBytes(e,t){let{inputUnit:n=`B`,outputUnit:r=`auto`,decimals:i=1}=t??{},a=e=>e===`B`?1:e===`KB`?1024:e===`MB`?1048576:e===`GB`?1073741824:1099511627776,o=e*a(n),s=r===`auto`?(()=>{for(let e of[`TB`,`GB`,`MB`,`KB`])if(o/a(e)>=1)return e;return`B`})():r,c=o/a(s),l=10**i;return{value:Math.round(c*l)/l,unit:s,bytes:o}}};W=we([(0,p.injectable)()],W);var Te=class{assemble(e){e.bind(A.DI.Formatter.UnitController).to(W)}};function Ee(){return[new Te]}let De=function(e){return e.Critical=`CRITICAL`,e.Serious=`SERIOUS`,e.Important=`IMPORTANT`,e.Notice=`NOTICE`,e.Routine=`ROUTINE`,e}({});function G(e,t){if(_.default.isAbsolute(t))return _.default.normalize(t);let n;try{let t=new URL(e);if(t.protocol!==`file:`)throw Error(`Unsupported URL protocol "${t.protocol}"`);n=_.default.dirname((0,ee.fileURLToPath)(t))}catch{n=e}return _.default.resolve(n,t)}function Oe(e,t={}){let n=G(process.cwd(),e);if(!v.default.existsSync(n))return;let r=v.default.statSync(n),{recursive:i=!0,force:a=!0,cleanOnly:o=!1}=t;if(o&&r.isDirectory()){for(let e of v.default.readdirSync(n))v.default.rmSync(_.default.join(n,e),{recursive:i,force:a});return}if(o&&r.isFile()){v.default.truncateSync(n,0);return}v.default.rmSync(n,{recursive:r.isDirectory()?i:!1,force:a,maxRetries:3,retryDelay:100})}function K(e){let t=G(process.cwd(),e),n=v.default.existsSync(t)&&v.default.statSync(t).isDirectory()?t:_.default.dirname(t);if(!v.default.existsSync(n))throw Error(`Directory "${n}" does not exist.`);return t}function ke(e){let t=G(process.cwd(),e);_.default.extname(e)&&console.warn(`[createDirectory] Warning: "${e}" looks like a file path.`);try{if(!v.default.existsSync(t))v.default.mkdirSync(t,{recursive:!0});else if(!v.default.statSync(t).isDirectory())throw Error(`"${t}" exists but is not a directory.`);return t}catch(e){throw Error(`Failed to create directory "${t}": ${e.message}`)}}function Ae(e,t=``){let n=G(process.cwd(),e);K(_.default.dirname(n));let r=je(n);if(!r)v.default.writeFileSync(n,t,{encoding:`utf8`,flag:`w`});else{if(!r.isFile())throw Error(`"${n}" exists but is not a file.`);t&&v.default.writeFileSync(n,t,{encoding:`utf8`,flag:`a`})}return n}function je(e){try{return v.default.statSync(e)}catch{return}}async function Me(e,t={}){let n=G(process.cwd(),e),r;try{r=await v.promises.stat(n)}catch(e){if((t.force??!0)&&e.code===`ENOENT`)return;throw e}let{recursive:i=!0,force:a=!0,cleanOnly:o=!1}=t;if(o&&r.isDirectory()){let e=await v.promises.readdir(n);for(let t of e)await v.promises.rm(_.default.join(n,t),{recursive:i,force:a});return}if(o&&r.isFile()){await v.promises.truncate(n,0);return}await v.promises.rm(n,{recursive:r.isDirectory()?i:!1,force:a,maxRetries:3,retryDelay:100})}async function q(e){let t=G(process.cwd(),e),n;try{n=await v.promises.stat(t)}catch{}let r=n?.isDirectory()?t:_.default.dirname(t);try{if(!(await v.promises.stat(r)).isDirectory())throw Error(`"${r}" exists but is not a directory.`)}catch(e){throw e.code===`ENOENT`?Error(`Directory "${r}" does not exist.`):e}return t}async function Ne(e){let t=G(process.cwd(),e);_.default.extname(e)&&console.warn(`[createDirectory] Warning: "${e}" looks like a file path (has extension).`);try{let e;try{e=await v.promises.stat(t)}catch{}if(!e)await v.promises.mkdir(t,{recursive:!0});else if(!e.isDirectory())throw Error(`"${t}" exists but is not a directory.`);return t}catch(e){throw Error(`Failed to create directory "${t}": ${e.message}`)}}async function Pe(e,t=``){let n=G(process.cwd(),e);await q(_.default.dirname(n));try{let e=await Fe(n);if(!e)await v.promises.writeFile(n,t,{encoding:`utf8`,flag:`w`});else{if(!e.isFile())throw Error(`"${n}" exists but is not a file.`);t&&await v.promises.writeFile(n,t,{encoding:`utf8`,flag:`a`})}return n}catch(e){throw Error(`Failed to create file "${n}": ${e.message}`)}}async function Fe(e){try{return await v.promises.stat(e)}catch(e){if(e.code===`ENOENT`)return;throw e}}var J=class{options;instance;constructor(e){this.options=e,this.instance=this.makeInstance()}info(e,t){this.log(`info`,e,t)}debug(e,t){this.log(`debug`,e,t)}trace(e,t){this.log(`trace`,e,t)}warn(e,t){this.log(`warn`,e,t)}error(e,t){this.log(`error`,e,t)}fatal(e,t){this.log(`fatal`,e,t)}child(e){return this.instance.child(e)}log(e,t,n){this.instance[e]({msg:t,...this.formatLogOptions(n)})}formatLogOptions(e){return e?this.normalizeObject({flag:e.flag,details:this.formatUnknown(e.details),error:this.formatUnknown(e.error),metadata:this.formatUnknown(e.metadata)}):{}}formatUnknown(e){if(ue(e)){let t={type:e.constructor.name,message:e.message};this.options.debug&&e.stack&&(t.stack=e.stack);for(let[n,r]of Object.entries(e))n in t||(t[n]=r);let n=this.normalizeObject(t);return N(n)?void 0:n}if(Buffer.isBuffer(e))return`[Buffer]`;if(e&&typeof e.pipe==`function`)return`[Stream]`;if(M(e))try{let t=JSON.stringify(e);if(t===void 0)return;let n=JSON.parse(t);if(Array.isArray(n))return n.length>0?n:void 0;if(M(n)){let e=this.normalizeObject(n);return N(e)?void 0:e}return n}catch{return{type:`NonSerializableObject`}}return P(e)?e:String(e)}normalizeObject(e){return j(Object.fromEntries(Object.entries(e)),{filterNull:!0,filterUndefined:!0,filterEmptyString:!0,filterEmptyArray:!0,filterEmptyObject:!0})}makeInstance(){if(!this.options.enabled)return(0,y.default)({enabled:!1,timestamp:!0});let e=this.options.transports,t={level:this.makeGlobalLogLevel(e),enabled:!0,timestamp:!0,transport:{targets:this.makeTransportTargets(e)}};return(0,y.default)(t)}makeTransportTargets(e){if(e.filter(e=>e.type===`console`).length>1)throw Error(`[Logger] Multiple console transports are not supported.`);return e.map(e=>{switch(e.type){case`console`:return this.makeConsoleTransportTarget(e);case`file`:return this.makeFileTransportTarget(e)}})}makeConsoleTransportTarget(e){return{target:`pino-pretty`,level:this.makeTransportLevel(e.level),options:e.pretty}}makeFileTransportTarget(e){let t=this.makeTransportLevel(e.level),n=_.default.isAbsolute(e.path)?_.default.normalize(e.path):G(process.cwd(),e.path);return K(_.default.dirname(n)),{target:`pino/file`,level:t,options:{destination:n}}}makeTransportLevel(e){return this.options.debug?`trace`:e??`info`}makeGlobalLogLevel(e){if(this.options.debug)return`trace`;let t=e.at(0);if(!t)return`info`;let n={trace:0,debug:1,info:2,warn:3,error:4,fatal:5},r=this.makeTransportLevel(t.level);for(let t of e.slice(1)){let e=this.makeTransportLevel(t.level);n[e]<n[r]&&(r=e)}return r}},Ie=class{options;constructor(e){this.options=e}assemble(e){e.bind(A.DI.Logger).toConstantValue(new J(this.options))}};function Le(e={}){let t=e.logger??{enabled:!1};return[...Ee(),new Ie(t)]}function Y(e){return process.env[e]?.trim()||void 0}function Re(e){let t=Y(e);if(!t)throw Error(`Missing required environment variable: ${e}`);return t}const X=b.default.string().trim().min(1).transform(e=>{let{prefix:t,base:n}=Q(e),r=ze(n);return{original:e,prefix:t,base:n,kebab:Be(r),snake:Ve(r),camel:He(r),pascal:Ue(r)}}),Z=b.default.looseObject({name:X,version:b.default.string().trim().min(1),private:b.default.boolean().optional(),type:b.default.enum([`module`,`commonjs`]).optional(),dependencies:b.default.record(b.default.string(),b.default.string()).default({}),peerDependencies:b.default.record(b.default.string(),b.default.string()).default({}),devDependencies:b.default.record(b.default.string(),b.default.string()).default({})});function Q(e){let t=/^@([^/]+)\/(.+)$/.exec(e);return t&&t[2]?{prefix:t[1],base:t[2]}:{base:e}}function ze(e){let t=e.replace(/([a-z0-9])([A-Z])/g,`$1 $2`).replace(/[^a-zA-Z0-9]+/g,` `).trim().toLowerCase();return t?t.split(/\s+/):[]}function Be(e){return e.join(`-`)}function Ve(e){return e.join(`_`)}function He(e){if(e.length===0)return``;let[t,...n]=e;return t+n.map($).join(``)}function Ue(e){return e.map($).join(``)}function $(e){return e.length===0?``:e.charAt(0).toUpperCase()+e.slice(1)}function We(e){let t,n;try{t=v.default.readFileSync(e,`utf8`)}catch(t){throw Error(`Failed to read package.json at ${e}`,{cause:t})}try{n=JSON.parse(t)}catch(t){throw Error(`Failed to parse package.json at ${e}`,{cause:t})}try{return Z.parse(n)}catch(t){throw Error(`Invalid package.json at ${e}`,{cause:t})}}exports.Console=le,exports.LogFlag=De,exports.LoggerImpl=J,exports.PackageJSONSchema=Z,exports.PackageNameSchema=X,exports.coreNodeAssembly=Le,exports.createDirectory=ke,exports.createDirectoryAsync=Ne,exports.createFile=Ae,exports.createFileAsync=Pe,exports.ensureDirectory=K,exports.ensureDirectoryAsync=q,exports.loadPackageJSON=We,exports.makeDependencyBundlingPolicy=te,exports.optionalEnvironmentVariable=Y,exports.removePath=Oe,exports.removePathAsync=Me,exports.requiredEnvironmentVariable=Re,exports.resolvePath=G;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n||t(r,Symbol.toStringTag,{value:`Module`}),r},s=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},c=(e,t,n)=>(s(e,t,`default`),n&&s(n,t,`default`)),l=(n,r,o)=>(o=n==null?{}:e(i(n)),s(r||!n||!n.__esModule||!a.call(n,`default`)?t(o,`default`,{value:n,enumerable:!0}):o,n));let u=require("node:module"),d=require("consola"),f=require("consola/utils"),p=require("node:fs");p=l(p,1);let m=require("node:path");m=l(m,1);let ee=require("node:url"),h=require("@dotenvx/dotenvx");h=l(h,1);let te=require("jiti"),ne=require("inversify"),g=require("date-fns"),_=require("date-fns-tz"),v=require("ms");v=l(v,1);let y=require("pino");y=l(y,1);let b=require("zod");b=l(b,1);function re(e,t={}){let n=t.includePeers??!0,r=t.includeDependencies??!0,i=t.includeSubpaths??!0,a=t.includeNodeBuiltins??!0,o=t.allowPeerBundling??!1,s=Object.keys(e.peerDependencies??{}),c=Object.keys(e.dependencies??{}),l=S(t.bundle??[]),u=S(t.external??[]);le(u,l),de(l),o||ue(s,l);let d=new Set(l.map(w)),f=n?s.filter(e=>!d.has(e)):[],p=r?c.filter(e=>!d.has(e)):[];return{external:C([...a?ie():[],...x([...f,...p,...u],i)]),bundle:C(x(l,i))}}function ie(){let e=S(u.builtinModules.map(T)),t=e.map(e=>`node:${e}`);return C([...e,...t,/^node:/])}function x(e,t){return t?e.map(e=>ae(e)):[...e]}function ae(e){return se(e)?e:RegExp(`^${ce(e)}(?:/.*)?$`)}function S(e){return Array.from(new Set(e))}function C(e){let t=new Set,n=[];for(let r of e){let e=oe(r);t.has(e)||(t.add(e),n.push(r))}return n}function oe(e){return typeof e==`string`?`string:${e}`:`regexp:${e.source}/${e.flags}`}function w(e){if(e.startsWith(`@`)){let[t,n]=e.split(`/`);return t&&n?`${t}/${n}`:e}let[t]=e.split(`/`);return t??e}function T(e){return e.startsWith(`node:`)?e.slice(5):e}function se(e){return e.includes(`*`)||e.startsWith(`^`)||e.endsWith(`$`)}function ce(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function le(e,t){let n=new Set(e.map(w)),r=t.filter(e=>n.has(w(e)));if(r.length!==0)throw Error(`Packages cannot be both external and bundled: ${r.join(`, `)}`)}function ue(e,t){let n=new Set(e),r=t.filter(e=>n.has(w(e)));if(r.length!==0)throw Error(`Peer dependencies must stay external and cannot be bundled by default: ${r.join(`, `)}`)}function de(e){let t=new Set(u.builtinModules.map(T)),n=e.filter(e=>fe(e,t));if(n.length!==0)throw Error(`Node.js built-in modules cannot be bundled: ${n.join(`, `)}`)}function fe(e,t){let n=T(e),[r]=n.split(`/`);return r?t.has(r):t.has(n)}const pe=/\u001B\[[0-9;]*m/g;var me=class{instance;constructor(e={}){this.instance=(0,d.createConsola)({level:e.enabled===!1?-999:999,formatOptions:{colors:!0,date:!1}})}title(e,t,n=[]){this.printPanel({title:`${e} ${t}`.trim(),renderedTitle:`${f.colors.cyan(f.colors.bold(e))}${t?` ${f.colors.dim(t)}`:``}`,rows:n,formatValue:f.colors.green})}panel(e,t,n){this.printPanel({title:n===void 0?e:`${e} ${n}`,renderedTitle:`${f.colors.cyan(f.colors.bold(e))}${n===void 0?``:` ${f.colors.green(String(n))}`}`,rows:t,formatValue:f.colors.dim})}step(e,t){return`${f.colors.cyan(e.padEnd(10,` `))}${t}`}duration(e){return e<1e3?`${e}ms`:`${(e/1e3).toFixed(2)}s`}emptyLine(){this.instance.log(``)}log(e,...t){this.instance.log(e,...t)}info(e,...t){this.instance.info(e,...t)}start(e,...t){this.instance.start(e,...t)}success(e,...t){this.instance.success(e,...t)}warn(e,...t){this.instance.warn(e,...t)}error(e,...t){this.instance.error(e,...t)}debug(e,...t){this.instance.debug(e,...t)}printPanel(e){this.instance.log(this.formatPanel(e))}formatPanel(e){let t=this.getPanelWidth(e);return[this.formatPanelTop(e.renderedTitle,t),...e.rows.map(n=>this.formatPanelRow(n,t,e.formatValue)),this.formatPanelBottom(t)].join(`
|
|
2
|
+
`)}formatPanelTop(e,t){let n=Math.max(1,t-this.visibleLength(e)-5);return`${f.colors.dim(`╭─`)} ${e} ${f.colors.dim(`─`.repeat(n))}${f.colors.dim(`╮`)}`}formatPanelBottom(e){return`${f.colors.dim(`╰`)}${f.colors.dim(`─`.repeat(e-2))}${f.colors.dim(`╯`)}`}formatPanelRow(e,t,n){let r=e.label.padEnd(14,` `),i=String(e.value),a=this.visibleLength(r)+this.visibleLength(i)+4,o=Math.max(0,t-a);return`${f.colors.dim(`│`)} ${f.colors.blue(r)}${n(i)}${` `.repeat(o)} ${f.colors.dim(`│`)}`}getPanelWidth(e){return Math.max(48,this.getTitleWidth(e),this.getRowsWidth(e.rows))}getTitleWidth(e){return this.visibleLength(e.title)+6}getRowsWidth(e){return Math.max(0,...e.map(e=>this.getRowWidth(e)))}getRowWidth(e){return 14+this.visibleLength(String(e.value))+4}visibleLength(e){return e.replace(pe,``).length}};const E=Symbol.for(`buildplease.environment-configuration.field`),D=Symbol.for(`buildplease.environment-configuration.contract`),O=Symbol.for(`buildplease.environment-configuration.binding`),k=Symbol.for(`buildplease.environment-configuration.config`),he={string(){return N((e,t)=>{if(typeof e!=`string`)throw Error(`${t} must be string.`);let n=e.trim();if(!n)throw Error(`${t} must not be empty.`);return n},{required:!0})},number(){return N((e,t)=>{let n=typeof e==`number`?e:Number(e);if(!Number.isFinite(n))throw Error(`${t} must be number.`);return n},{required:!0})},boolean(){return N((e,t)=>{if(typeof e==`boolean`)return e;if(typeof e==`string`){let t=e.trim().toLowerCase();if(t===`true`)return!0;if(t===`false`)return!1}throw Error(`${t} must be boolean.`)},{required:!0})},array(e){return N((t,n)=>{if(!Array.isArray(t))throw Error(`${n} must be array.`);return t.map((t,r)=>e.parse(t,`${n}[${r}]`))},{required:!0})},custom(){return N(e=>e,{required:!0})}};function ge(e,t){let n=e.trim();if(!n)throw Error(`Configuration key must not be empty.`);let r=(e=>{let t={contract:r,input:e};return Object.defineProperty(t,O,{value:!0}),t});return Object.defineProperties(r,{[D]:{value:!0},key:{value:n},schema:{value:t}}),r}function _e(e,t){let n={environments:e,input:t};return Object.defineProperty(n,k,{value:!0}),n}function A(e){return!!(e&&typeof e==`object`&&e[k]===!0)}function j(e){return!!(e&&typeof e==`object`&&e[E]===!0)}function ve(e){return typeof e==`function`&&e[D]===!0}function M(e){return!!(e&&typeof e==`object`&&e[O]===!0)}function N(e,t){let n={required:t.required,hasDefault:t.hasDefault??!1,defaultValue:t.defaultValue,parse:e,optional(){return N((t,n)=>{if(t!=null)return e(t,n)},{required:!1})},default(t){return N(e,{required:!1,hasDefault:!0,defaultValue:t})},map(n){let r=t.hasDefault&&t.defaultValue!==void 0?n(t.defaultValue):void 0;return N((t,r)=>n(e(t,r)),{required:t.required,hasDefault:t.hasDefault,defaultValue:r})}};return Object.defineProperty(n,E,{value:!0}),n}function P(e,t){if(m.default.isAbsolute(t))return m.default.normalize(t);let n;try{let t=new URL(e);if(t.protocol!==`file:`)throw Error(`Unsupported URL protocol "${t.protocol}"`);n=m.default.dirname((0,ee.fileURLToPath)(t))}catch{n=e}return m.default.resolve(n,t)}function ye(e,t={}){let n=P(process.cwd(),e);if(!p.default.existsSync(n))return;let r=p.default.statSync(n),{recursive:i=!0,force:a=!0,cleanOnly:o=!1}=t;if(o&&r.isDirectory()){for(let e of p.default.readdirSync(n))p.default.rmSync(m.default.join(n,e),{recursive:i,force:a});return}if(o&&r.isFile()){p.default.truncateSync(n,0);return}p.default.rmSync(n,{recursive:r.isDirectory()?i:!1,force:a,maxRetries:3,retryDelay:100})}function F(e){let t=P(process.cwd(),e),n=p.default.existsSync(t)&&p.default.statSync(t).isDirectory()?t:m.default.dirname(t);if(!p.default.existsSync(n))throw Error(`Directory "${n}" does not exist.`);return t}function be(e){let t=P(process.cwd(),e);m.default.extname(e)&&console.warn(`[createDirectory] Warning: "${e}" looks like a file path.`);try{if(!p.default.existsSync(t))p.default.mkdirSync(t,{recursive:!0});else if(!p.default.statSync(t).isDirectory())throw Error(`"${t}" exists but is not a directory.`);return t}catch(e){throw Error(`Failed to create directory "${t}": ${e.message}`)}}function xe(e,t=``){let n=P(process.cwd(),e);F(m.default.dirname(n));let r=Se(n);if(!r)p.default.writeFileSync(n,t,{encoding:`utf8`,flag:`w`});else{if(!r.isFile())throw Error(`"${n}" exists but is not a file.`);t&&p.default.writeFileSync(n,t,{encoding:`utf8`,flag:`a`})}return n}function Se(e){try{return p.default.statSync(e)}catch{return}}async function Ce(e,t={}){let n=P(process.cwd(),e),r;try{r=await p.promises.stat(n)}catch(e){if((t.force??!0)&&e.code===`ENOENT`)return;throw e}let{recursive:i=!0,force:a=!0,cleanOnly:o=!1}=t;if(o&&r.isDirectory()){let e=await p.promises.readdir(n);for(let t of e)await p.promises.rm(m.default.join(n,t),{recursive:i,force:a});return}if(o&&r.isFile()){await p.promises.truncate(n,0);return}await p.promises.rm(n,{recursive:r.isDirectory()?i:!1,force:a,maxRetries:3,retryDelay:100})}async function I(e){let t=P(process.cwd(),e),n;try{n=await p.promises.stat(t)}catch{}let r=n?.isDirectory()?t:m.default.dirname(t);try{if(!(await p.promises.stat(r)).isDirectory())throw Error(`"${r}" exists but is not a directory.`)}catch(e){throw e.code===`ENOENT`?Error(`Directory "${r}" does not exist.`):e}return t}async function we(e){let t=P(process.cwd(),e);m.default.extname(e)&&console.warn(`[createDirectory] Warning: "${e}" looks like a file path (has extension).`);try{let e;try{e=await p.promises.stat(t)}catch{}if(!e)await p.promises.mkdir(t,{recursive:!0});else if(!e.isDirectory())throw Error(`"${t}" exists but is not a directory.`);return t}catch(e){throw Error(`Failed to create directory "${t}": ${e.message}`)}}async function Te(e,t=``){let n=P(process.cwd(),e);await I(m.default.dirname(n));try{let e=await Ee(n);if(!e)await p.promises.writeFile(n,t,{encoding:`utf8`,flag:`w`});else{if(!e.isFile())throw Error(`"${n}" exists but is not a file.`);t&&await p.promises.writeFile(n,t,{encoding:`utf8`,flag:`a`})}return n}catch(e){throw Error(`Failed to create file "${n}": ${e.message}`)}}async function Ee(e){try{return await p.promises.stat(e)}catch(e){if(e.code===`ENOENT`)return;throw e}}function De(e){let t=Object.entries(e);if(!t.length)throw Error(`At least one environment must be defined.`);for(let[e,n]of t)Oe(e,n);return e}function L(e,t,n={}){let r=e[t];if(!r)throw Error(`Environment "${t}" is not defined.`);let i=P(n.baseDir?.trim()||process.cwd(),r.fileDir?.trim()||`.`);return{name:t,file:r.file.trim(),fileDir:i}}function Oe(e,t){if(!e.trim())throw Error(`Environment name must not be empty.`);if(typeof t.file!=`string`||!t.file.trim())throw Error(`Environment file must not be empty for "${e}".`)}function ke(e){return process.env[e]?.trim()||void 0}const R=Symbol.for(`buildplease.environment-configuration.source`);function Ae(e){return{env(e){return B(`env`,{name:e})},byEnvironment(e){return B(`by-environment`,{cases:e})},compute(e){return B(`compute`,{compute:e})},static(e){return B(`static`,{value:e})}}}function z(e){return!!(e&&typeof e==`object`&&e[R]===!0)}function B(e,t,n=[]){let r={kind:e,options:t,transforms:n,default(e){return B(`default`,{source:r,value:e})},map(r){return B(e,t,[...n,r])}};return Object.defineProperty(r,R,{value:!0}),r}async function je(e,t){let n=Fe(t,`config`);return W(e.input,n,`config`)}async function V(e,t,n={}){let r=Me(n);return U(e.schema,t,r,e.key)}async function H(e,t={}){return V(e.contract,e.input,t)}function Me(e){return{buildMetadata:e.buildMetadata,environment:e.environment}}async function U(e,t,n,r){if(j(e))return Ne(e,t,n,r);let i=await W(t,n,r)??{};if(!q(i))throw Error(`${r} must be object.`);let a={};for(let[t,o]of Object.entries(e))a[t]=await U(o,i[t],n,`${r}.${t}`);return a}async function Ne(e,t,n,r){let i=await W(t,n,r);if(i==null){if(e.hasDefault)return K(e.defaultValue);if(!e.required)return;throw Error(`Missing required configuration: ${r}`)}return e.parse(i,r)}async function W(e,t,n){if(z(e))return G(e,t,n);if(M(e))return H(e,t);if(Array.isArray(e))return Promise.all(e.map((e,r)=>W(e,t,`${n}[${r}]`)));if(q(e)){let r={};for(let[i,a]of Object.entries(e))r[i]=await W(a,t,`${n}.${i}`);return r}return e}async function G(e,t,n){let r;switch(e.kind){case`env`:{let{name:t}=e.options;r=ke(t);break}case`by-environment`:{let i=Pe(t,n),{cases:a}=e.options;if(!Object.prototype.hasOwnProperty.call(a,i.name))throw Error(`${n} has no value for environment "${i.name}".`);r=await W(a[i.name],t,n);break}case`compute`:{let i=Fe(t,n),{compute:a}=e.options;r=await a(i);break}case`static`:{let{value:t}=e.options;r=t;break}case`default`:{let{source:i,value:a}=e.options;r=await G(i,t,n)??K(a);break}}for(let t of e.transforms)r=await t(r);return r}function Pe(e,t){if(!e?.environment)throw Error(`${t} requires runtime environment.`);return e.environment}function Fe(e,t){if(!e?.environment)throw Error(`${t} requires runtime environment.`);if(!e.buildMetadata)throw Error(`${t} requires build metadata.`);return e}function K(e){if(Array.isArray(e))return e.map(e=>K(e));if(q(e)){let t={};for(let[n,r]of Object.entries(e))t[n]=K(r);return t}return e}function q(e){if(!e||typeof e!=`object`||Object.prototype.toString.call(e)!==`[object Object]`)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}const J=[`.ts`,`.mts`,`.cts`,`.js`,`.mjs`,`.cjs`];async function Ie(e={}){let t=Le(e.dir);try{let n=Re(t,e.config??`environment.config.ts`),r=await ze(t,n);if(!A(r))throw Error(`Environment config must be defined with defineConfig() (${n}).`);let i=r,a=e.environment?L(i.environments,e.environment,{baseDir:(0,m.dirname)(n)}):void 0;return a&&Be(a),{config:i,configFilePath:n,rootDir:t,environment:a}}catch(e){throw Error(`Failed to load environment config: ${e instanceof Error?e.message:String(e)}`)}}function Le(e){let t=e?P(process.cwd(),e):process.cwd();return F(t),t}function Re(e,t){let n=P(e,t);if(p.default.existsSync(n))return n;if(!J.some(e=>t.endsWith(e)))for(let e of J){let t=`${n}${e}`;if(p.default.existsSync(t))return t}throw Error(`Config file "${n}" does not exist.`)}async function ze(e,t){return(0,te.createJiti)(e,{interopDefault:!0,extensions:[...J],tsconfigPaths:!0}).import(t,{default:!0})}function Be(e){let t=P(e.fileDir,e.file);if(!p.default.existsSync(t))throw Error(`Environment file "${t}" does not exist.`);h.default.config({path:t}),process.env.NODE_ENV=e.name}const Ve=`${{name:`buildplease`,displayName:`BuildPlease`,scope:`@buildplease`}.name}.Core.DI`,He={DI:{Formatter:{UnitController:Symbol.for(`${Ve}.Formatter.UnitController`)},Logger:Symbol.for(`${Ve}.Logger`)}};function Ue(e){return e instanceof Error}function Y(e,t={}){if(e==null)return{};let{filterNull:n=!0,filterUndefined:r=!0,filterEmptyString:i=!1,filterEmptyObject:a=!1,filterEmptyArray:o=!1}=t;return Object.keys(e).reduce((s,c)=>{let l=e[c];return X(l)&&Object.getPrototypeOf(l)===null&&(l=void 0),We(l)&&(l=Y(l,t)),n&&l===null||r&&l===void 0||i&&l===``||a&&Z(l)||o&&Array.isArray(l)&&l.length===0||(s[c]=l),s},{})}function X(e){return typeof e==`object`&&!!e}function Z(e){return X(e)&&Object.keys(e).length===0}function We(e){return X(e)&&Object.getPrototypeOf(e)===Object.prototype}function Ge(e){return e==null||[`string`,`number`,`boolean`,`bigint`,`symbol`].includes(typeof e)}Array.prototype.isEmpty=function(){return this==null||this.length===0},String.prototype.capitalized=function(){let e=this==null?``:this.toString();return e.trim()?e.charAt(0).toUpperCase()+e.slice(1):``};var Ke=class{streetLine1;streetLine2;postalCode;state;city;country;countryCode;constructor(e){this.streetLine1=e.streetLine1,this.streetLine2=e.streetLine2,this.postalCode=e.postalCode,this.state=e.state,this.city=e.city,this.country=e.country,this.countryCode=e.countryCode}toJSON(){return Y({streetLine1:this.streetLine1,streetLine2:this.streetLine2,postalCode:this.postalCode,city:this.city,state:this.state,country:this.country,countryCode:this.countryCode},{filterNull:!0,filterUndefined:!0,filterEmptyString:!0})}formatted(){let e=(e,t)=>e.map(e=>e?.trim()).filter(e=>e&&e.length>0).join(t).trim(),t=this.streetLine1;return e([t,e([this.postalCode,this.city],` `),e([this.country],`, `)],`, `)}},qe=class{email;fb;ig;phone;web;constructor({email:e,fb:t,ig:n,phone:r,web:i}){this.email=e,this.fb=t,this.ig=n,this.phone=r,this.web=i}toJSON(){return Y({email:this.email,fb:this.fb,ig:this.ig,phone:this.phone,web:this.web},{filterNull:!0,filterUndefined:!0,filterEmptyString:!0})}},Je=o({DateFormat:()=>Xe,DateTime:()=>Ye});c(Je,require("date-fns"));var Ye=class e{date;constructor(e){if(!e){this.date=new Date;return}if(e instanceof Date){if(!(0,g.isValid)(e))throw Error(`Invalid date object`);this.date=e;return}let t=(0,g.parseISO)(e);if(!(0,g.isValid)(t))throw Error(`Invalid date string`);this.date=t}static fromUnixTimestamp(t,n){return new e((0,g.fromUnixTime)(t,n))}static now(){return new e(new Date)}toJSON(){return this.toISOString()}toDate(){return this.date}toUnixTimestamp(){return(0,g.getUnixTime)(this.date)}getTime(){return this.date.getTime()}toISOString(){return(0,g.formatISO)(this.date)}format(e,t){return(0,g.format)(this.date,e,t)}addingDuration(t){return new e((0,g.add)(this.date,t))}addingMilliseconds(t){return new e((0,g.addMilliseconds)(this.date,t))}addingSeconds(t){return new e((0,g.addSeconds)(this.date,t))}addingMinutes(t){return new e((0,g.addMinutes)(this.date,t))}addingHours(t){return new e((0,g.addHours)(this.date,t))}addingDays(t){return new e((0,g.addDays)(this.date,t))}addingWeeks(t){return new e((0,g.addWeeks)(this.date,t))}addingMonths(t){return new e((0,g.addMonths)(this.date,t))}addingYears(t){return new e((0,g.addYears)(this.date,t))}subtractingDuration(t){return new e((0,g.sub)(this.date,t))}subtractingMilliseconds(t){return new e((0,g.subMilliseconds)(this.date,t))}subtractingSeconds(t){return new e((0,g.subSeconds)(this.date,t))}subtractingMinutes(t){return new e((0,g.subMinutes)(this.date,t))}subtractingHours(t){return new e((0,g.subHours)(this.date,t))}subtractingDays(t){return new e((0,g.subDays)(this.date,t))}subtractingWeeks(t){return new e((0,g.subWeeks)(this.date,t))}subtractingMonths(t){return new e((0,g.subMonths)(this.date,t))}subtractingYears(t){return new e((0,g.subYears)(this.date,t))}differenceInMilliseconds(e){return(0,g.differenceInMilliseconds)(this.date,e.date)}differenceInSeconds(e){return(0,g.differenceInSeconds)(this.date,e.date)}differenceInMinutes(e){return(0,g.differenceInMinutes)(this.date,e.date)}differenceInHours(e){return(0,g.differenceInHours)(this.date,e.date)}differenceInDays(e){return(0,g.differenceInDays)(this.date,e.date)}differenceInWeeks(e){return(0,g.differenceInWeeks)(this.date,e.date)}differenceInMonths(e){return(0,g.differenceInMonths)(this.date,e.date)}differenceInYears(e){return(0,g.differenceInYears)(this.date,e.date)}isEqualTo(e){return(0,g.isEqual)(this.date,e.date)}isBefore(e){return(0,g.isBefore)(this.date,e.date)}isAfter(e){return(0,g.isAfter)(this.date,e.date)}compareTo(e){return(0,g.compareAsc)(this.date,e.date)}isSameDayAs(e){return(0,g.isSameDay)(this.date,e.date)}startOfDay(){return new e((0,g.startOfDay)(this.date))}endOfDay(){return new e((0,g.endOfDay)(this.date))}startOfWeek(){return new e((0,g.startOfWeek)(this.date))}endOfWeek(){return new e((0,g.endOfWeek)(this.date))}startOfMonth(){return new e((0,g.startOfMonth)(this.date))}endOfMonth(){return new e((0,g.endOfMonth)(this.date))}startOfYear(){return new e((0,g.startOfYear)(this.date))}endOfYear(){return new e((0,g.endOfYear)(this.date))}get dayOfMonth(){return(0,g.getDate)(this.date)}get dayOfWeek(){return(0,g.getDay)(this.date)}get month(){return(0,g.getMonth)(this.date)}get year(){return(0,g.getYear)(this.date)}get hours(){return(0,g.getHours)(this.date)}get minutes(){return(0,g.getMinutes)(this.date)}get seconds(){return(0,g.getSeconds)(this.date)}settingDayOfMonth(t){return new e((0,g.setDate)(this.date,t))}settingDayOfWeek(t){return new e((0,g.setDay)(this.date,t))}settingMonth(t){return new e((0,g.setMonth)(this.date,t))}settingYear(t){return new e((0,g.setYear)(this.date,t))}settingHours(t){return new e((0,g.setHours)(this.date,t))}settingMinutes(t){return new e((0,g.setMinutes)(this.date,t))}settingSeconds(t){return new e((0,g.setSeconds)(this.date,t))}};let Xe=function(e){return e.ISO_DATE=`yyyy-MM-dd`,e.ISO_DATETIME=`yyyy-MM-dd'T'HH:mm:ssXXX`,e.MM_DD_YYYY=`MM/dd/yyyy`,e.FULL_MONTH_DAY_YEAR=`MMMM d, yyyy`,e.ABBR_MONTH_DAY_YEAR=`MMM d, yyyy`,e.RFC_3339=`yyyy-MM-dd'T'HH:mm:ss.SSSxxx`,e.ALT_RSS=`d MMM yyyy HH:mm:ss ZZZ`,e.RSS=`EEE, d MMM yyyy HH:mm:ss ZZZ`,e.HTTP_HEADER=`EEE, dd MMM yyyy HH:mm:ss zzz`,e.STANDARD=`EEE MMM dd HH:mm:ss Z yyyy`,e.EXTENDED=`eee dd-MMM-yyyy GG HH:mm:ss.SSS zzz`,e}({});var Ze=class e{utc;timeZone;constructor(e,t){this.timeZone=e,this.utc=t??new Date}static fromUtc(t,n){return new e(n,t)}static fromLocalIso(t,n){let r=(0,_.fromZonedTime)(t,n);return new e(n,r)}format(e,t){return(0,_.formatInTimeZone)(this.utc,this.timeZone,e,t)}toLocalIsoMinutes(e){return this.format(`yyyy-MM-dd'T'HH:mm`,e)}toLocalIsoSeconds(e){return this.format(`yyyy-MM-dd'T'HH:mm:ss`,e)}toISOString(){return this.utc.toISOString()}toUnixTimestamp(){return Math.floor(this.utc.getTime()/1e3)}toZonedDate(){return(0,_.toZonedTime)(this.utc,this.timeZone)}timezoneOffsetMs(e){return(0,_.getTimezoneOffset)(this.timeZone,e??this.utc)}},Qe=class{value;constructor([e,t]){if(e<-180||e>180)throw Error(`Longitude must be between -180 and 180.`);if(t<-90||t>90)throw Error(`Latitude must be between -90 and 90.`);this.value=[e,t]}get longitude(){return this.value[0]}get latitude(){return this.value[1]}toJSON(){return this.value}},$e=class{type=`Point`;coordinates;bbox;constructor(e,t){this.coordinates=e,this.bbox=t}toJSON(){return{type:this.type,coordinates:this.coordinates.toJSON(),...this.bbox&&{bbox:this.bbox}}}},et=class{type=`MultiPoint`;coordinates;bbox;constructor(e,t){this.coordinates=e,this.bbox=t}toJSON(){return{type:this.type,coordinates:this.coordinates.map(e=>e.toJSON()),...this.bbox&&{bbox:this.bbox}}}},tt=class{type=`LineString`;coordinates;bbox;constructor(e,t){this.coordinates=e,this.bbox=t}toJSON(){return{type:this.type,coordinates:this.coordinates.map(e=>e.toJSON()),...this.bbox&&{bbox:this.bbox}}}},nt=class{type=`MultiLineString`;coordinates;bbox;constructor(e,t){this.coordinates=e,this.bbox=t}toJSON(){return{type:this.type,coordinates:this.coordinates.map(e=>e.map(e=>e.toJSON())),...this.bbox&&{bbox:this.bbox}}}},rt=class{type=`Polygon`;coordinates;bbox;constructor(e,t){this.coordinates=e,this.bbox=t}toJSON(){return{type:this.type,coordinates:this.coordinates.map(e=>e.map(e=>e.toJSON())),...this.bbox&&{bbox:this.bbox}}}},it=class{type=`MultiPolygon`;coordinates;bbox;constructor(e,t){this.coordinates=e,this.bbox=t}toJSON(){return{type:this.type,coordinates:this.coordinates.map(e=>e.map(e=>e.map(e=>e.toJSON()))),...this.bbox&&{bbox:this.bbox}}}};let at=function(e){return e.Point=`Point`,e.MultiPoint=`MultiPoint`,e.LineString=`LineString`,e.MultiLineString=`MultiLineString`,e.Polygon=`Polygon`,e.MultiPolygon=`MultiPolygon`,e}({});function ot(e){return Error(`Invalid ObjectId value: ${String(e)}`)}var st=class e{value;constructor(e){if(e==null)throw ot(e);let t=e.trim();if(t.length===0)throw ot(e);this.value=t,Object.freeze(this)}get asString(){return this.value}equals(t){return this.value===e.from(t).value}compare(t){let n=e.from(t).value;return this.value===n?0:this.value<n?-1:1}hash(){return this.value}toJSON(){return this.value}toString(){return this.value}[Symbol.toPrimitive](){return this.value}static from(t){return t instanceof e?t:new e(t)}static isValid(e){return typeof e==`string`&&e.trim().length>0}static toValueSet(t){let n=new Set;for(let r of t)n.add(e.from(r).value);return n}},ct=class{day;intervals;constructor(e,t){this.day=e,this.intervals=t}toJSON(){return Y({day:this.day,intervals:this.intervals},{filterNull:!0,filterUndefined:!0,filterEmptyString:!0})}},lt=class{_milliseconds;_long;constructor(e,t){if(this._long=t?.long===!0,e==null)throw Error(`Invalid interval format: ${e}`);if(typeof e==`number`)this._milliseconds=e;else{let t=(0,v.default)(e);if(t===void 0)throw Error(`Invalid interval format: ${e}`);this._milliseconds=t}}get milliseconds(){return this._milliseconds}get seconds(){return Math.floor(this._milliseconds/1e3)}get minutes(){return Math.floor(this._milliseconds/6e4)}get hours(){return Math.floor(this._milliseconds/36e5)}get days(){return Math.floor(this._milliseconds/864e5)}get weeks(){return Math.floor(this._milliseconds/6048e5)}get formatted(){return(0,v.default)(this._milliseconds,{long:this._long})}toString(){return(0,v.default)(this._milliseconds,{long:this._long})}toObject(){return{milliseconds:this._milliseconds,seconds:this.seconds,minutes:this.minutes,hours:this.hours,days:this.days,weeks:this.weeks}}};let ut=function(e){return e.Byte=`B`,e.Kilobyte=`KB`,e.Megabyte=`MB`,e.Gigabyte=`GB`,e.Terabyte=`TB`,e}({}),dt=function(e){return e.Millimeter=`mm`,e.Centimeter=`cm`,e.Meter=`m`,e.Kilometer=`km`,e}({}),ft=function(e){return e.Milligram=`mg`,e.Gram=`g`,e.Kilogram=`kg`,e.Tonne=`t`,e}({});c(o({Address:()=>Ke,ByteUnit:()=>ut,Contacts:()=>qe,Coordinates:()=>Qe,DateFormat:()=>Xe,DateTime:()=>Ye,DistanceUnit:()=>dt,GeoJsonType:()=>at,LineString:()=>tt,MultiLineString:()=>nt,MultiPoint:()=>et,MultiPolygon:()=>it,ObjectId:()=>st,OpeningHour:()=>ct,Point:()=>$e,Polygon:()=>rt,TimeInterval:()=>lt,WeightUnit:()=>ft,ZonedDateTime:()=>Ze}),Je);function pt(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let Q=class{formatBytes(e,t){let{inputUnit:n=`B`,outputUnit:r=`auto`,decimals:i=1}=t??{},a=e=>e===`B`?1:e===`KB`?1024:e===`MB`?1048576:e===`GB`?1073741824:1099511627776,o=e*a(n),s=r===`auto`?(()=>{for(let e of[`TB`,`GB`,`MB`,`KB`])if(o/a(e)>=1)return e;return`B`})():r,c=o/a(s),l=10**i;return{value:Math.round(c*l)/l,unit:s,bytes:o}}};Q=pt([(0,ne.injectable)()],Q);var mt=class{assemble(e){e.bind(He.DI.Formatter.UnitController).to(Q)}};function ht(){return[new mt]}let gt=function(e){return e.Critical=`CRITICAL`,e.Serious=`SERIOUS`,e.Important=`IMPORTANT`,e.Notice=`NOTICE`,e.Routine=`ROUTINE`,e}({});var _t=class{options;instance;constructor(e){this.options=e,this.instance=this.makeInstance()}info(e,t){this.log(`info`,e,t)}debug(e,t){this.log(`debug`,e,t)}trace(e,t){this.log(`trace`,e,t)}warn(e,t){this.log(`warn`,e,t)}error(e,t){this.log(`error`,e,t)}fatal(e,t){this.log(`fatal`,e,t)}child(e){return this.instance.child(e)}log(e,t,n){this.instance[e]({msg:t,...this.formatLogOptions(n)})}formatLogOptions(e){return e?this.normalizeObject({flag:e.flag,details:this.formatUnknown(e.details),error:this.formatUnknown(e.error),metadata:this.formatUnknown(e.metadata)}):{}}formatUnknown(e){if(Ue(e)){let t={type:e.constructor.name,message:e.message};this.options.debug&&e.stack&&(t.stack=e.stack);for(let[n,r]of Object.entries(e))n in t||(t[n]=r);let n=this.normalizeObject(t);return Z(n)?void 0:n}if(Buffer.isBuffer(e))return`[Buffer]`;if(e&&typeof e.pipe==`function`)return`[Stream]`;if(X(e))try{let t=JSON.stringify(e);if(t===void 0)return;let n=JSON.parse(t);if(Array.isArray(n))return n.length>0?n:void 0;if(X(n)){let e=this.normalizeObject(n);return Z(e)?void 0:e}return n}catch{return{type:`NonSerializableObject`}}return Ge(e)?e:String(e)}normalizeObject(e){return Y(Object.fromEntries(Object.entries(e)),{filterNull:!0,filterUndefined:!0,filterEmptyString:!0,filterEmptyArray:!0,filterEmptyObject:!0})}makeInstance(){if(!this.options.enabled)return(0,y.default)({enabled:!1,timestamp:!0});let e=this.options.transports,t={level:this.makeGlobalLogLevel(e),enabled:!0,timestamp:!0,transport:{targets:this.makeTransportTargets(e)}};return(0,y.default)(t)}makeTransportTargets(e){if(e.filter(e=>e.type===`console`).length>1)throw Error(`[Logger] Multiple console transports are not supported.`);return e.map(e=>{switch(e.type){case`console`:return this.makeConsoleTransportTarget(e);case`file`:return this.makeFileTransportTarget(e)}})}makeConsoleTransportTarget(e){return{target:`pino-pretty`,level:this.makeTransportLevel(e.level),options:e.pretty}}makeFileTransportTarget(e){let t=this.makeTransportLevel(e.level),n=m.default.isAbsolute(e.path)?m.default.normalize(e.path):P(process.cwd(),e.path);return F(m.default.dirname(n)),{target:`pino/file`,level:t,options:{destination:n}}}makeTransportLevel(e){return this.options.debug?`trace`:e??`info`}makeGlobalLogLevel(e){if(this.options.debug)return`trace`;let t=e.at(0);if(!t)return`info`;let n={trace:0,debug:1,info:2,warn:3,error:4,fatal:5},r=this.makeTransportLevel(t.level);for(let t of e.slice(1)){let e=this.makeTransportLevel(t.level);n[e]<n[r]&&(r=e)}return r}},vt=class{options;constructor(e){this.options=e}assemble(e){e.bind(He.DI.Logger).toConstantValue(new _t(this.options))}};function yt(e={}){let t=e.logger??{enabled:!1};return[...ht(),new vt(t)]}const bt=b.default.string().trim().min(1).transform(e=>{let{prefix:t,base:n}=St(e),r=Ct(n);return{original:e,prefix:t,base:n,kebab:wt(r),snake:Tt(r),camel:Et(r),pascal:Dt(r)}}),xt=b.default.looseObject({name:bt,version:b.default.string().trim().min(1),private:b.default.boolean().optional(),type:b.default.enum([`module`,`commonjs`]).optional(),dependencies:b.default.record(b.default.string(),b.default.string()).default({}),peerDependencies:b.default.record(b.default.string(),b.default.string()).default({}),devDependencies:b.default.record(b.default.string(),b.default.string()).default({})});function St(e){let t=/^@([^/]+)\/(.+)$/.exec(e);return t&&t[2]?{prefix:t[1],base:t[2]}:{base:e}}function Ct(e){let t=e.replace(/([a-z0-9])([A-Z])/g,`$1 $2`).replace(/[^a-zA-Z0-9]+/g,` `).trim().toLowerCase();return t?t.split(/\s+/):[]}function wt(e){return e.join(`-`)}function Tt(e){return e.join(`_`)}function Et(e){if(e.length===0)return``;let[t,...n]=e;return t+n.map($).join(``)}function Dt(e){return e.map($).join(``)}function $(e){return e.length===0?``:e.charAt(0).toUpperCase()+e.slice(1)}function Ot(e){let t,n;try{t=p.default.readFileSync(e,`utf8`)}catch(t){throw Error(`Failed to read package.json at ${e}`,{cause:t})}try{n=JSON.parse(t)}catch(t){throw Error(`Failed to parse package.json at ${e}`,{cause:t})}try{return xt.parse(n)}catch(t){throw Error(`Invalid package.json at ${e}`,{cause:t})}}exports.Console=me,exports.ENVIRONMENT_CONFIG_FILE=`environment.config.ts`,exports.LogFlag=gt,exports.LoggerImpl=_t,exports.PackageJSONSchema=xt,exports.PackageNameSchema=bt,exports.coreNodeAssembly=yt,exports.createDirectory=be,exports.createDirectoryAsync=we,exports.createFile=xe,exports.createFileAsync=Te,exports.defineConfig=_e,exports.defineConfiguration=ge,exports.defineEnvironments=De,exports.defineSource=Ae,exports.ensureDirectory=F,exports.ensureDirectoryAsync=I,exports.field=he,exports.isConfigDefinition=A,exports.isConfigurationBinding=M,exports.isConfigurationContract=ve,exports.isConfigurationField=j,exports.isConfigurationSource=z,exports.loadConfig=Ie,exports.loadPackageJSON=Ot,exports.makeDependencyBundlingPolicy=re,exports.removePath=ye,exports.removePathAsync=Ce,exports.resolveConfig=je,exports.resolveConfiguration=V,exports.resolveConfigurationBinding=H,exports.resolveEnvironment=L,exports.resolvePath=P;
|
|
@@ -195,6 +195,140 @@ declare class Console {
|
|
|
195
195
|
private visibleLength;
|
|
196
196
|
}
|
|
197
197
|
//#endregion
|
|
198
|
+
//#region src-node/environment-configuration/environment.d.ts
|
|
199
|
+
interface EnvironmentDefinition {
|
|
200
|
+
readonly file: string;
|
|
201
|
+
readonly fileDir?: string;
|
|
202
|
+
}
|
|
203
|
+
interface EnvironmentConfig<Name extends string = string> {
|
|
204
|
+
readonly name: Name;
|
|
205
|
+
readonly file: string;
|
|
206
|
+
readonly fileDir: string;
|
|
207
|
+
}
|
|
208
|
+
type EnvironmentRegistry = Record<string, EnvironmentDefinition>;
|
|
209
|
+
type EnvironmentName<Environments extends EnvironmentRegistry> = keyof Environments & string;
|
|
210
|
+
type EnvironmentConfigFromRegistry<Environments extends EnvironmentRegistry> = EnvironmentConfig<EnvironmentName<Environments>>;
|
|
211
|
+
interface ResolveEnvironmentOptions {
|
|
212
|
+
readonly baseDir?: string;
|
|
213
|
+
}
|
|
214
|
+
declare function defineEnvironments<const Environments extends EnvironmentRegistry>(environments: Environments): Environments;
|
|
215
|
+
declare function resolveEnvironment<Environments extends EnvironmentRegistry>(environments: Environments, name: string, options?: ResolveEnvironmentOptions): EnvironmentConfigFromRegistry<Environments>;
|
|
216
|
+
//#endregion
|
|
217
|
+
//#region src-node/build-metadata.d.ts
|
|
218
|
+
interface BuildMetadata {
|
|
219
|
+
readonly name: {
|
|
220
|
+
readonly original: string;
|
|
221
|
+
readonly base: string;
|
|
222
|
+
};
|
|
223
|
+
readonly version: string;
|
|
224
|
+
readonly id: string;
|
|
225
|
+
readonly createdAt: string;
|
|
226
|
+
}
|
|
227
|
+
//#endregion
|
|
228
|
+
//#region src-node/environment-configuration/source.d.ts
|
|
229
|
+
type ConfigurationSourceKind = 'env' | 'by-environment' | 'compute' | 'static' | 'default';
|
|
230
|
+
interface ConfigurationResolveContext<EnvironmentName extends string = string> {
|
|
231
|
+
readonly environment: EnvironmentConfig<EnvironmentName>;
|
|
232
|
+
readonly buildMetadata: BuildMetadata;
|
|
233
|
+
}
|
|
234
|
+
interface ConfigurationSource<Output = unknown> {
|
|
235
|
+
readonly kind: ConfigurationSourceKind;
|
|
236
|
+
readonly options: unknown;
|
|
237
|
+
readonly transforms: readonly ConfigurationSourceTransform[];
|
|
238
|
+
default<Default>(value: Default): ConfigurationSource<Exclude<Output, null | undefined> | Default>;
|
|
239
|
+
map<NextOutput>(transform: (value: Output) => NextOutput | Promise<NextOutput>): ConfigurationSource<NextOutput>;
|
|
240
|
+
}
|
|
241
|
+
declare function defineSource<const Environments extends EnvironmentRegistry>(_environments: Environments): {
|
|
242
|
+
env(name: string): ConfigurationSource<string | undefined>;
|
|
243
|
+
byEnvironment<const Cases extends { readonly [Key in keyof Environments & string]: unknown; }>(cases: Cases): ConfigurationSource<InferSourceOutput<Cases[keyof Environments & string]>>;
|
|
244
|
+
compute<Output>(compute: (context: ConfigurationResolveContext<keyof Environments & string>) => Output | Promise<Output>): ConfigurationSource<Output>;
|
|
245
|
+
static<Output>(value: Output): ConfigurationSource<Output>;
|
|
246
|
+
};
|
|
247
|
+
declare function isConfigurationSource(input: unknown): input is ConfigurationSource;
|
|
248
|
+
type ConfigurationSourceTransform = (value: unknown) => unknown | Promise<unknown>;
|
|
249
|
+
type InferSourceOutput<T> = T extends ConfigurationSource<infer Output> ? Output : T extends ((...args: any[]) => any) ? T : T extends readonly [unknown, ...unknown[]] ? { readonly [Key in keyof T]: InferSourceOutput<T[Key]>; } : T extends readonly (infer Item)[] ? readonly InferSourceOutput<Item>[] : T extends object ? { readonly [Key in keyof T]: InferSourceOutput<T[Key]>; } : T;
|
|
250
|
+
//#endregion
|
|
251
|
+
//#region src-node/environment-configuration/configuration.d.ts
|
|
252
|
+
interface ConfigurationField<Output, Required extends boolean = true, Input = Output> {
|
|
253
|
+
readonly required: Required;
|
|
254
|
+
readonly hasDefault: boolean;
|
|
255
|
+
readonly defaultValue?: Output;
|
|
256
|
+
parse(value: unknown, path: string): Output;
|
|
257
|
+
optional(): ConfigurationField<Output | undefined, false, Input | undefined | null>;
|
|
258
|
+
default(value: Output): ConfigurationField<Output, false, Input>;
|
|
259
|
+
map<NextOutput>(transform: (value: Output) => NextOutput): ConfigurationField<NextOutput, Required, Input>;
|
|
260
|
+
}
|
|
261
|
+
declare const field: {
|
|
262
|
+
string(): ConfigurationField<string, true, string>;
|
|
263
|
+
number(): ConfigurationField<number, true, string | number>;
|
|
264
|
+
boolean(): ConfigurationField<boolean, true, string | boolean>;
|
|
265
|
+
array<Item, ItemInput>(item: ConfigurationField<Item, boolean, ItemInput>): ConfigurationField<readonly Item[], true, readonly ItemInput[]>;
|
|
266
|
+
custom<T>(): ConfigurationField<T, true, T>;
|
|
267
|
+
};
|
|
268
|
+
type ConfigurationSchema = ConfigurationField<any, boolean, any> | {
|
|
269
|
+
readonly [key: string]: ConfigurationSchema;
|
|
270
|
+
};
|
|
271
|
+
type InferSchemaOutput<Schema> = Schema extends ConfigurationField<infer Output, any, any> ? Output : Schema extends object ? { readonly [Key in keyof Schema]: InferSchemaOutput<Schema[Key]>; } : never;
|
|
272
|
+
type InferSchemaInput<Schema> = Schema extends ConfigurationField<any, any, infer Input> ? Input : Schema extends object ? { readonly [Key in RequiredSchemaKeys<Schema>]: InferSchemaInput<Schema[Key]>; } & { readonly [Key in OptionalSchemaKeys<Schema>]?: InferSchemaInput<Schema[Key]>; } : never;
|
|
273
|
+
type ConfigurationValueInput<T> = ConfigurationSource<T | undefined> | (T extends unknown ? ConfigurationValueInputValue<T> : never);
|
|
274
|
+
type ConfigurationInputFromSchema<Schema> = ConfigurationSource<InferSchemaInput<Schema> | undefined> | (Schema extends ConfigurationField<any, any, infer Input> ? ConfigurationValueInput<Input> : Schema extends object ? { readonly [Key in RequiredSchemaKeys<Schema>]: ConfigurationInputFromSchema<Schema[Key]>; } & { readonly [Key in OptionalSchemaKeys<Schema>]?: ConfigurationInputFromSchema<Schema[Key]>; } : never);
|
|
275
|
+
interface ConfigurationContract<Output, Schema extends ConfigurationSchema = ConfigurationSchema> {
|
|
276
|
+
readonly key: string;
|
|
277
|
+
readonly schema: Schema;
|
|
278
|
+
(input: ConfigurationInputFromSchema<Schema>): ConfigurationBinding<Output, Schema>;
|
|
279
|
+
}
|
|
280
|
+
interface ConfigurationBinding<Output = unknown, Schema extends ConfigurationSchema = ConfigurationSchema> {
|
|
281
|
+
readonly contract: ConfigurationContract<Output, Schema>;
|
|
282
|
+
readonly input: ConfigurationInputFromSchema<Schema>;
|
|
283
|
+
}
|
|
284
|
+
type InferConfiguration<Contract> = Contract extends ConfigurationContract<infer Output, any> ? Output : never;
|
|
285
|
+
declare function defineConfiguration<const Schema extends ConfigurationSchema>(key: string, schema: Schema): ConfigurationContract<InferSchemaOutput<Schema>, Schema>;
|
|
286
|
+
interface ConfigDefinition<Environments extends EnvironmentRegistry = EnvironmentRegistry, Input = unknown> {
|
|
287
|
+
readonly environments: Environments;
|
|
288
|
+
readonly input: Input;
|
|
289
|
+
}
|
|
290
|
+
type InferConfig<Config> = Config extends ConfigDefinition<any, infer Input> ? InferConfigValue<Input> : never;
|
|
291
|
+
type InferConfigValue<Input> = Input extends ConfigurationSource<infer Output> ? Output : Input extends ConfigurationBinding<infer Output> ? Output : Input extends ((...args: any[]) => any) ? Input : Input extends readonly [unknown, ...unknown[]] ? { readonly [Key in keyof Input]: InferConfigValue<Input[Key]>; } : Input extends readonly (infer Item)[] ? readonly InferConfigValue<Item>[] : Input extends object ? { readonly [Key in keyof Input]: InferConfigValue<Input[Key]>; } : Input;
|
|
292
|
+
declare function defineConfig<const Environments extends EnvironmentRegistry, const Input>(environments: Environments, input: Input): ConfigDefinition<Environments, Input>;
|
|
293
|
+
declare function isConfigDefinition(input: unknown): input is ConfigDefinition;
|
|
294
|
+
declare function isConfigurationField(input: unknown): input is ConfigurationField<unknown, boolean, unknown>;
|
|
295
|
+
declare function isConfigurationContract(input: unknown): input is ConfigurationContract<unknown>;
|
|
296
|
+
declare function isConfigurationBinding(input: unknown): input is ConfigurationBinding;
|
|
297
|
+
type ConfigurationValueInputValue<T> = T extends ((...args: any[]) => any) ? T : T extends readonly [unknown, ...unknown[]] ? { readonly [Key in keyof T]: ConfigurationValueInput<T[Key]>; } : T extends readonly (infer Item)[] ? readonly ConfigurationValueInput<Item>[] : T extends object ? { readonly [Key in keyof T]: ConfigurationValueInput<T[Key]>; } : T;
|
|
298
|
+
type IsSchemaInputRequired<Schema> = Schema extends ConfigurationField<any, infer Required, any> ? Required : Schema extends object ? RequiredSchemaKeys<Schema> extends never ? false : true : true;
|
|
299
|
+
type RequiredSchemaKeys<Schema extends object> = { [Key in keyof Schema]-?: IsSchemaInputRequired<Schema[Key]> extends true ? Key : never; }[keyof Schema];
|
|
300
|
+
type OptionalSchemaKeys<Schema extends object> = { [Key in keyof Schema]-?: IsSchemaInputRequired<Schema[Key]> extends true ? never : Key; }[keyof Schema];
|
|
301
|
+
//#endregion
|
|
302
|
+
//#region src-node/environment-configuration/engine.d.ts
|
|
303
|
+
interface ResolveConfigurationOptions {
|
|
304
|
+
readonly buildMetadata?: BuildMetadata;
|
|
305
|
+
readonly environment?: EnvironmentConfig;
|
|
306
|
+
}
|
|
307
|
+
declare function resolveConfig<Config extends ConfigDefinition<any>>(config: Config, context: ConfigurationResolveContext<keyof Config['environments'] & string>): Promise<InferConfig<Config>>;
|
|
308
|
+
declare function resolveConfiguration<Output, Schema extends ConfigurationSchema>(contract: ConfigurationContract<Output, Schema>, input: ConfigurationInputFromSchema<Schema> | undefined, options?: ResolveConfigurationOptions): Promise<Output>;
|
|
309
|
+
declare function resolveConfigurationBinding<Output>(binding: ConfigurationBinding<Output>, options?: ResolveConfigurationOptions): Promise<Output>;
|
|
310
|
+
//#endregion
|
|
311
|
+
//#region src-node/environment-configuration/loader.d.ts
|
|
312
|
+
declare const ENVIRONMENT_CONFIG_FILE = "environment.config.ts";
|
|
313
|
+
interface LoadConfigOptions {
|
|
314
|
+
readonly dir?: string;
|
|
315
|
+
readonly config?: string;
|
|
316
|
+
readonly environment?: string;
|
|
317
|
+
}
|
|
318
|
+
interface LoadedConfig<Config extends ConfigDefinition = ConfigDefinition> {
|
|
319
|
+
readonly config: Config;
|
|
320
|
+
readonly configFilePath: string;
|
|
321
|
+
readonly rootDir: string;
|
|
322
|
+
readonly environment?: EnvironmentConfigFromRegistry<Config['environments']>;
|
|
323
|
+
}
|
|
324
|
+
interface LoadedEnvironmentConfig<Config extends ConfigDefinition = ConfigDefinition> extends LoadedConfig<Config> {
|
|
325
|
+
readonly environment: EnvironmentConfigFromRegistry<Config['environments']>;
|
|
326
|
+
}
|
|
327
|
+
declare function loadConfig<Config extends ConfigDefinition = ConfigDefinition>(options: LoadConfigOptions & {
|
|
328
|
+
readonly environment: string;
|
|
329
|
+
}): Promise<LoadedEnvironmentConfig<Config>>;
|
|
330
|
+
declare function loadConfig<Config extends ConfigDefinition = ConfigDefinition>(options?: LoadConfigOptions): Promise<LoadedConfig<Config>>;
|
|
331
|
+
//#endregion
|
|
198
332
|
//#region src-node/logger/log-flag.d.ts
|
|
199
333
|
declare enum LogFlag {
|
|
200
334
|
Critical = "CRITICAL",
|
|
@@ -282,10 +416,6 @@ interface CoreNodeAssemblyOptions {
|
|
|
282
416
|
}
|
|
283
417
|
declare function coreNodeAssembly(options?: CoreNodeAssemblyOptions): Assembly[];
|
|
284
418
|
//#endregion
|
|
285
|
-
//#region src-node/environment/environment-variable.d.ts
|
|
286
|
-
declare function optionalEnvironmentVariable(name: string): string | undefined;
|
|
287
|
-
declare function requiredEnvironmentVariable(name: string): string;
|
|
288
|
-
//#endregion
|
|
289
419
|
//#region src-node/file/file-sync.d.ts
|
|
290
420
|
/**
|
|
291
421
|
* Resolve `relative` against `base`, unless `relative` is already absolute,
|
|
@@ -452,4 +582,4 @@ declare const PackageJSONSchema: z.ZodObject<{
|
|
|
452
582
|
*/
|
|
453
583
|
declare function loadPackageJSON(path: string): PackageJSONModel;
|
|
454
584
|
//#endregion
|
|
455
|
-
export { BaseLoggerTransportOptions, Console, ConsoleOptions, ConsolePanelRow, CoreNodeAssemblyOptions, DependencyBundlingMatcher, DependencyBundlingPackageJSON, DependencyBundlingPolicy, LogFlag, LogOptions, Logger, LoggerConsoleTransportOptions, LoggerFileTransportOptions, LoggerImpl, LoggerOptions, LoggerTransportOptions, MakeDependencyBundlingPolicyOptions, PackageJSONModel, PackageJSONSchema, PackageNameModel, PackageNameSchema, coreNodeAssembly, createDirectory, createDirectoryAsync, createFile, createFileAsync, ensureDirectory, ensureDirectoryAsync, loadPackageJSON, makeDependencyBundlingPolicy,
|
|
585
|
+
export { BaseLoggerTransportOptions, type BuildMetadata, type ConfigDefinition, type ConfigurationBinding, type ConfigurationContract, type ConfigurationField, type ConfigurationInputFromSchema, type ConfigurationResolveContext, type ConfigurationSchema, type ConfigurationSource, type ConfigurationSourceKind, type ConfigurationValueInput, Console, ConsoleOptions, ConsolePanelRow, CoreNodeAssemblyOptions, DependencyBundlingMatcher, DependencyBundlingPackageJSON, DependencyBundlingPolicy, ENVIRONMENT_CONFIG_FILE, type EnvironmentConfig, type EnvironmentConfigFromRegistry, type EnvironmentDefinition, type EnvironmentName, type EnvironmentRegistry, type InferConfig, type InferConfigValue, type InferConfiguration, type InferSchemaInput, type InferSchemaOutput, type LoadConfigOptions, type LoadedConfig, type LoadedEnvironmentConfig, LogFlag, LogOptions, Logger, LoggerConsoleTransportOptions, LoggerFileTransportOptions, LoggerImpl, LoggerOptions, LoggerTransportOptions, MakeDependencyBundlingPolicyOptions, PackageJSONModel, PackageJSONSchema, PackageNameModel, PackageNameSchema, type ResolveConfigurationOptions, type ResolveEnvironmentOptions, coreNodeAssembly, createDirectory, createDirectoryAsync, createFile, createFileAsync, defineConfig, defineConfiguration, defineEnvironments, defineSource, ensureDirectory, ensureDirectoryAsync, field, isConfigDefinition, isConfigurationBinding, isConfigurationContract, isConfigurationField, isConfigurationSource, loadConfig, loadPackageJSON, makeDependencyBundlingPolicy, removePath, removePathAsync, resolveConfig, resolveConfiguration, resolveConfigurationBinding, resolveEnvironment, resolvePath };
|
|
@@ -195,6 +195,140 @@ declare class Console {
|
|
|
195
195
|
private visibleLength;
|
|
196
196
|
}
|
|
197
197
|
//#endregion
|
|
198
|
+
//#region src-node/environment-configuration/environment.d.ts
|
|
199
|
+
interface EnvironmentDefinition {
|
|
200
|
+
readonly file: string;
|
|
201
|
+
readonly fileDir?: string;
|
|
202
|
+
}
|
|
203
|
+
interface EnvironmentConfig<Name extends string = string> {
|
|
204
|
+
readonly name: Name;
|
|
205
|
+
readonly file: string;
|
|
206
|
+
readonly fileDir: string;
|
|
207
|
+
}
|
|
208
|
+
type EnvironmentRegistry = Record<string, EnvironmentDefinition>;
|
|
209
|
+
type EnvironmentName<Environments extends EnvironmentRegistry> = keyof Environments & string;
|
|
210
|
+
type EnvironmentConfigFromRegistry<Environments extends EnvironmentRegistry> = EnvironmentConfig<EnvironmentName<Environments>>;
|
|
211
|
+
interface ResolveEnvironmentOptions {
|
|
212
|
+
readonly baseDir?: string;
|
|
213
|
+
}
|
|
214
|
+
declare function defineEnvironments<const Environments extends EnvironmentRegistry>(environments: Environments): Environments;
|
|
215
|
+
declare function resolveEnvironment<Environments extends EnvironmentRegistry>(environments: Environments, name: string, options?: ResolveEnvironmentOptions): EnvironmentConfigFromRegistry<Environments>;
|
|
216
|
+
//#endregion
|
|
217
|
+
//#region src-node/build-metadata.d.ts
|
|
218
|
+
interface BuildMetadata {
|
|
219
|
+
readonly name: {
|
|
220
|
+
readonly original: string;
|
|
221
|
+
readonly base: string;
|
|
222
|
+
};
|
|
223
|
+
readonly version: string;
|
|
224
|
+
readonly id: string;
|
|
225
|
+
readonly createdAt: string;
|
|
226
|
+
}
|
|
227
|
+
//#endregion
|
|
228
|
+
//#region src-node/environment-configuration/source.d.ts
|
|
229
|
+
type ConfigurationSourceKind = 'env' | 'by-environment' | 'compute' | 'static' | 'default';
|
|
230
|
+
interface ConfigurationResolveContext<EnvironmentName extends string = string> {
|
|
231
|
+
readonly environment: EnvironmentConfig<EnvironmentName>;
|
|
232
|
+
readonly buildMetadata: BuildMetadata;
|
|
233
|
+
}
|
|
234
|
+
interface ConfigurationSource<Output = unknown> {
|
|
235
|
+
readonly kind: ConfigurationSourceKind;
|
|
236
|
+
readonly options: unknown;
|
|
237
|
+
readonly transforms: readonly ConfigurationSourceTransform[];
|
|
238
|
+
default<Default>(value: Default): ConfigurationSource<Exclude<Output, null | undefined> | Default>;
|
|
239
|
+
map<NextOutput>(transform: (value: Output) => NextOutput | Promise<NextOutput>): ConfigurationSource<NextOutput>;
|
|
240
|
+
}
|
|
241
|
+
declare function defineSource<const Environments extends EnvironmentRegistry>(_environments: Environments): {
|
|
242
|
+
env(name: string): ConfigurationSource<string | undefined>;
|
|
243
|
+
byEnvironment<const Cases extends { readonly [Key in keyof Environments & string]: unknown; }>(cases: Cases): ConfigurationSource<InferSourceOutput<Cases[keyof Environments & string]>>;
|
|
244
|
+
compute<Output>(compute: (context: ConfigurationResolveContext<keyof Environments & string>) => Output | Promise<Output>): ConfigurationSource<Output>;
|
|
245
|
+
static<Output>(value: Output): ConfigurationSource<Output>;
|
|
246
|
+
};
|
|
247
|
+
declare function isConfigurationSource(input: unknown): input is ConfigurationSource;
|
|
248
|
+
type ConfigurationSourceTransform = (value: unknown) => unknown | Promise<unknown>;
|
|
249
|
+
type InferSourceOutput<T> = T extends ConfigurationSource<infer Output> ? Output : T extends ((...args: any[]) => any) ? T : T extends readonly [unknown, ...unknown[]] ? { readonly [Key in keyof T]: InferSourceOutput<T[Key]>; } : T extends readonly (infer Item)[] ? readonly InferSourceOutput<Item>[] : T extends object ? { readonly [Key in keyof T]: InferSourceOutput<T[Key]>; } : T;
|
|
250
|
+
//#endregion
|
|
251
|
+
//#region src-node/environment-configuration/configuration.d.ts
|
|
252
|
+
interface ConfigurationField<Output, Required extends boolean = true, Input = Output> {
|
|
253
|
+
readonly required: Required;
|
|
254
|
+
readonly hasDefault: boolean;
|
|
255
|
+
readonly defaultValue?: Output;
|
|
256
|
+
parse(value: unknown, path: string): Output;
|
|
257
|
+
optional(): ConfigurationField<Output | undefined, false, Input | undefined | null>;
|
|
258
|
+
default(value: Output): ConfigurationField<Output, false, Input>;
|
|
259
|
+
map<NextOutput>(transform: (value: Output) => NextOutput): ConfigurationField<NextOutput, Required, Input>;
|
|
260
|
+
}
|
|
261
|
+
declare const field: {
|
|
262
|
+
string(): ConfigurationField<string, true, string>;
|
|
263
|
+
number(): ConfigurationField<number, true, string | number>;
|
|
264
|
+
boolean(): ConfigurationField<boolean, true, string | boolean>;
|
|
265
|
+
array<Item, ItemInput>(item: ConfigurationField<Item, boolean, ItemInput>): ConfigurationField<readonly Item[], true, readonly ItemInput[]>;
|
|
266
|
+
custom<T>(): ConfigurationField<T, true, T>;
|
|
267
|
+
};
|
|
268
|
+
type ConfigurationSchema = ConfigurationField<any, boolean, any> | {
|
|
269
|
+
readonly [key: string]: ConfigurationSchema;
|
|
270
|
+
};
|
|
271
|
+
type InferSchemaOutput<Schema> = Schema extends ConfigurationField<infer Output, any, any> ? Output : Schema extends object ? { readonly [Key in keyof Schema]: InferSchemaOutput<Schema[Key]>; } : never;
|
|
272
|
+
type InferSchemaInput<Schema> = Schema extends ConfigurationField<any, any, infer Input> ? Input : Schema extends object ? { readonly [Key in RequiredSchemaKeys<Schema>]: InferSchemaInput<Schema[Key]>; } & { readonly [Key in OptionalSchemaKeys<Schema>]?: InferSchemaInput<Schema[Key]>; } : never;
|
|
273
|
+
type ConfigurationValueInput<T> = ConfigurationSource<T | undefined> | (T extends unknown ? ConfigurationValueInputValue<T> : never);
|
|
274
|
+
type ConfigurationInputFromSchema<Schema> = ConfigurationSource<InferSchemaInput<Schema> | undefined> | (Schema extends ConfigurationField<any, any, infer Input> ? ConfigurationValueInput<Input> : Schema extends object ? { readonly [Key in RequiredSchemaKeys<Schema>]: ConfigurationInputFromSchema<Schema[Key]>; } & { readonly [Key in OptionalSchemaKeys<Schema>]?: ConfigurationInputFromSchema<Schema[Key]>; } : never);
|
|
275
|
+
interface ConfigurationContract<Output, Schema extends ConfigurationSchema = ConfigurationSchema> {
|
|
276
|
+
readonly key: string;
|
|
277
|
+
readonly schema: Schema;
|
|
278
|
+
(input: ConfigurationInputFromSchema<Schema>): ConfigurationBinding<Output, Schema>;
|
|
279
|
+
}
|
|
280
|
+
interface ConfigurationBinding<Output = unknown, Schema extends ConfigurationSchema = ConfigurationSchema> {
|
|
281
|
+
readonly contract: ConfigurationContract<Output, Schema>;
|
|
282
|
+
readonly input: ConfigurationInputFromSchema<Schema>;
|
|
283
|
+
}
|
|
284
|
+
type InferConfiguration<Contract> = Contract extends ConfigurationContract<infer Output, any> ? Output : never;
|
|
285
|
+
declare function defineConfiguration<const Schema extends ConfigurationSchema>(key: string, schema: Schema): ConfigurationContract<InferSchemaOutput<Schema>, Schema>;
|
|
286
|
+
interface ConfigDefinition<Environments extends EnvironmentRegistry = EnvironmentRegistry, Input = unknown> {
|
|
287
|
+
readonly environments: Environments;
|
|
288
|
+
readonly input: Input;
|
|
289
|
+
}
|
|
290
|
+
type InferConfig<Config> = Config extends ConfigDefinition<any, infer Input> ? InferConfigValue<Input> : never;
|
|
291
|
+
type InferConfigValue<Input> = Input extends ConfigurationSource<infer Output> ? Output : Input extends ConfigurationBinding<infer Output> ? Output : Input extends ((...args: any[]) => any) ? Input : Input extends readonly [unknown, ...unknown[]] ? { readonly [Key in keyof Input]: InferConfigValue<Input[Key]>; } : Input extends readonly (infer Item)[] ? readonly InferConfigValue<Item>[] : Input extends object ? { readonly [Key in keyof Input]: InferConfigValue<Input[Key]>; } : Input;
|
|
292
|
+
declare function defineConfig<const Environments extends EnvironmentRegistry, const Input>(environments: Environments, input: Input): ConfigDefinition<Environments, Input>;
|
|
293
|
+
declare function isConfigDefinition(input: unknown): input is ConfigDefinition;
|
|
294
|
+
declare function isConfigurationField(input: unknown): input is ConfigurationField<unknown, boolean, unknown>;
|
|
295
|
+
declare function isConfigurationContract(input: unknown): input is ConfigurationContract<unknown>;
|
|
296
|
+
declare function isConfigurationBinding(input: unknown): input is ConfigurationBinding;
|
|
297
|
+
type ConfigurationValueInputValue<T> = T extends ((...args: any[]) => any) ? T : T extends readonly [unknown, ...unknown[]] ? { readonly [Key in keyof T]: ConfigurationValueInput<T[Key]>; } : T extends readonly (infer Item)[] ? readonly ConfigurationValueInput<Item>[] : T extends object ? { readonly [Key in keyof T]: ConfigurationValueInput<T[Key]>; } : T;
|
|
298
|
+
type IsSchemaInputRequired<Schema> = Schema extends ConfigurationField<any, infer Required, any> ? Required : Schema extends object ? RequiredSchemaKeys<Schema> extends never ? false : true : true;
|
|
299
|
+
type RequiredSchemaKeys<Schema extends object> = { [Key in keyof Schema]-?: IsSchemaInputRequired<Schema[Key]> extends true ? Key : never; }[keyof Schema];
|
|
300
|
+
type OptionalSchemaKeys<Schema extends object> = { [Key in keyof Schema]-?: IsSchemaInputRequired<Schema[Key]> extends true ? never : Key; }[keyof Schema];
|
|
301
|
+
//#endregion
|
|
302
|
+
//#region src-node/environment-configuration/engine.d.ts
|
|
303
|
+
interface ResolveConfigurationOptions {
|
|
304
|
+
readonly buildMetadata?: BuildMetadata;
|
|
305
|
+
readonly environment?: EnvironmentConfig;
|
|
306
|
+
}
|
|
307
|
+
declare function resolveConfig<Config extends ConfigDefinition<any>>(config: Config, context: ConfigurationResolveContext<keyof Config['environments'] & string>): Promise<InferConfig<Config>>;
|
|
308
|
+
declare function resolveConfiguration<Output, Schema extends ConfigurationSchema>(contract: ConfigurationContract<Output, Schema>, input: ConfigurationInputFromSchema<Schema> | undefined, options?: ResolveConfigurationOptions): Promise<Output>;
|
|
309
|
+
declare function resolveConfigurationBinding<Output>(binding: ConfigurationBinding<Output>, options?: ResolveConfigurationOptions): Promise<Output>;
|
|
310
|
+
//#endregion
|
|
311
|
+
//#region src-node/environment-configuration/loader.d.ts
|
|
312
|
+
declare const ENVIRONMENT_CONFIG_FILE = "environment.config.ts";
|
|
313
|
+
interface LoadConfigOptions {
|
|
314
|
+
readonly dir?: string;
|
|
315
|
+
readonly config?: string;
|
|
316
|
+
readonly environment?: string;
|
|
317
|
+
}
|
|
318
|
+
interface LoadedConfig<Config extends ConfigDefinition = ConfigDefinition> {
|
|
319
|
+
readonly config: Config;
|
|
320
|
+
readonly configFilePath: string;
|
|
321
|
+
readonly rootDir: string;
|
|
322
|
+
readonly environment?: EnvironmentConfigFromRegistry<Config['environments']>;
|
|
323
|
+
}
|
|
324
|
+
interface LoadedEnvironmentConfig<Config extends ConfigDefinition = ConfigDefinition> extends LoadedConfig<Config> {
|
|
325
|
+
readonly environment: EnvironmentConfigFromRegistry<Config['environments']>;
|
|
326
|
+
}
|
|
327
|
+
declare function loadConfig<Config extends ConfigDefinition = ConfigDefinition>(options: LoadConfigOptions & {
|
|
328
|
+
readonly environment: string;
|
|
329
|
+
}): Promise<LoadedEnvironmentConfig<Config>>;
|
|
330
|
+
declare function loadConfig<Config extends ConfigDefinition = ConfigDefinition>(options?: LoadConfigOptions): Promise<LoadedConfig<Config>>;
|
|
331
|
+
//#endregion
|
|
198
332
|
//#region src-node/logger/log-flag.d.ts
|
|
199
333
|
declare enum LogFlag {
|
|
200
334
|
Critical = "CRITICAL",
|
|
@@ -282,10 +416,6 @@ interface CoreNodeAssemblyOptions {
|
|
|
282
416
|
}
|
|
283
417
|
declare function coreNodeAssembly(options?: CoreNodeAssemblyOptions): Assembly[];
|
|
284
418
|
//#endregion
|
|
285
|
-
//#region src-node/environment/environment-variable.d.ts
|
|
286
|
-
declare function optionalEnvironmentVariable(name: string): string | undefined;
|
|
287
|
-
declare function requiredEnvironmentVariable(name: string): string;
|
|
288
|
-
//#endregion
|
|
289
419
|
//#region src-node/file/file-sync.d.ts
|
|
290
420
|
/**
|
|
291
421
|
* Resolve `relative` against `base`, unless `relative` is already absolute,
|
|
@@ -452,4 +582,4 @@ declare const PackageJSONSchema: z.ZodObject<{
|
|
|
452
582
|
*/
|
|
453
583
|
declare function loadPackageJSON(path: string): PackageJSONModel;
|
|
454
584
|
//#endregion
|
|
455
|
-
export { BaseLoggerTransportOptions, Console, ConsoleOptions, ConsolePanelRow, CoreNodeAssemblyOptions, DependencyBundlingMatcher, DependencyBundlingPackageJSON, DependencyBundlingPolicy, LogFlag, LogOptions, Logger, LoggerConsoleTransportOptions, LoggerFileTransportOptions, LoggerImpl, LoggerOptions, LoggerTransportOptions, MakeDependencyBundlingPolicyOptions, PackageJSONModel, PackageJSONSchema, PackageNameModel, PackageNameSchema, coreNodeAssembly, createDirectory, createDirectoryAsync, createFile, createFileAsync, ensureDirectory, ensureDirectoryAsync, loadPackageJSON, makeDependencyBundlingPolicy,
|
|
585
|
+
export { BaseLoggerTransportOptions, type BuildMetadata, type ConfigDefinition, type ConfigurationBinding, type ConfigurationContract, type ConfigurationField, type ConfigurationInputFromSchema, type ConfigurationResolveContext, type ConfigurationSchema, type ConfigurationSource, type ConfigurationSourceKind, type ConfigurationValueInput, Console, ConsoleOptions, ConsolePanelRow, CoreNodeAssemblyOptions, DependencyBundlingMatcher, DependencyBundlingPackageJSON, DependencyBundlingPolicy, ENVIRONMENT_CONFIG_FILE, type EnvironmentConfig, type EnvironmentConfigFromRegistry, type EnvironmentDefinition, type EnvironmentName, type EnvironmentRegistry, type InferConfig, type InferConfigValue, type InferConfiguration, type InferSchemaInput, type InferSchemaOutput, type LoadConfigOptions, type LoadedConfig, type LoadedEnvironmentConfig, LogFlag, LogOptions, Logger, LoggerConsoleTransportOptions, LoggerFileTransportOptions, LoggerImpl, LoggerOptions, LoggerTransportOptions, MakeDependencyBundlingPolicyOptions, PackageJSONModel, PackageJSONSchema, PackageNameModel, PackageNameSchema, type ResolveConfigurationOptions, type ResolveEnvironmentOptions, coreNodeAssembly, createDirectory, createDirectoryAsync, createFile, createFileAsync, defineConfig, defineConfiguration, defineEnvironments, defineSource, ensureDirectory, ensureDirectoryAsync, field, isConfigDefinition, isConfigurationBinding, isConfigurationContract, isConfigurationField, isConfigurationSource, loadConfig, loadPackageJSON, makeDependencyBundlingPolicy, removePath, removePathAsync, resolveConfig, resolveConfiguration, resolveConfigurationBinding, resolveEnvironment, resolvePath };
|
package/dist/src-node/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{builtinModules as e}from"node:module";import{createConsola as t}from"consola";import{colors as n}from"consola/utils";import{injectable as
|
|
2
|
-
`)}formatPanelTop(e,t){let r=Math.max(1,t-this.visibleLength(e)-5);return`${n.dim(`╭─`)} ${e} ${n.dim(`─`.repeat(r))}${n.dim(`╮`)}`}formatPanelBottom(e){return`${n.dim(`╰`)}${n.dim(`─`.repeat(e-2))}${n.dim(`╯`)}`}formatPanelRow(e,t,r){let i=e.label.padEnd(14,` `),a=String(e.value),o=this.visibleLength(i)+this.visibleLength(a)+4,s=Math.max(0,t-o);return`${n.dim(`│`)} ${n.blue(i)}${r(a)}${` `.repeat(s)} ${n.dim(`│`)}`}getPanelWidth(e){return Math.max(48,this.getTitleWidth(e),this.getRowsWidth(e.rows))}getTitleWidth(e){return this.visibleLength(e.title)+6}getRowsWidth(e){return Math.max(0,...e.map(e=>this.getRowWidth(e)))}getRowWidth(e){return 14+this.visibleLength(String(e.value))+4}visibleLength(e){return e.replace(ot,``).length}};const I=`${{name:`buildplease`,displayName:`BuildPlease`,scope:`@buildplease`}.name}.Core.DI`,L={DI:{Formatter:{UnitController:Symbol.for(`${I}.Formatter.UnitController`)},Logger:Symbol.for(`${I}.Logger`)}};function ct(e){return e instanceof Error}function R(e,t={}){if(e==null)return{};let{filterNull:n=!0,filterUndefined:r=!0,filterEmptyString:i=!1,filterEmptyObject:a=!1,filterEmptyArray:o=!1}=t;return Object.keys(e).reduce((s,c)=>{let l=e[c];return z(l)&&Object.getPrototypeOf(l)===null&&(l=void 0),lt(l)&&(l=R(l,t)),n&&l===null||r&&l===void 0||i&&l===``||a&&B(l)||o&&Array.isArray(l)&&l.length===0||(s[c]=l),s},{})}function z(e){return typeof e==`object`&&!!e}function B(e){return z(e)&&Object.keys(e).length===0}function lt(e){return z(e)&&Object.getPrototypeOf(e)===Object.prototype}function ut(e){return e==null||[`string`,`number`,`boolean`,`bigint`,`symbol`].includes(typeof e)}Array.prototype.isEmpty=function(){return this==null||this.length===0},String.prototype.capitalized=function(){let e=this==null?``:this.toString();return e.trim()?e.charAt(0).toUpperCase()+e.slice(1):``};var dt=class{streetLine1;streetLine2;postalCode;state;city;country;countryCode;constructor(e){this.streetLine1=e.streetLine1,this.streetLine2=e.streetLine2,this.postalCode=e.postalCode,this.state=e.state,this.city=e.city,this.country=e.country,this.countryCode=e.countryCode}toJSON(){return R({streetLine1:this.streetLine1,streetLine2:this.streetLine2,postalCode:this.postalCode,city:this.city,state:this.state,country:this.country,countryCode:this.countryCode},{filterNull:!0,filterUndefined:!0,filterEmptyString:!0})}formatted(){let e=(e,t)=>e.map(e=>e?.trim()).filter(e=>e&&e.length>0).join(t).trim(),t=this.streetLine1;return e([t,e([this.postalCode,this.city],` `),e([this.country],`, `)],`, `)}},ft=class{email;fb;ig;phone;web;constructor({email:e,fb:t,ig:n,phone:r,web:i}){this.email=e,this.fb=t,this.ig=n,this.phone=r,this.web=i}toJSON(){return R({email:this.email,fb:this.fb,ig:this.ig,phone:this.phone,web:this.web},{filterNull:!0,filterUndefined:!0,filterEmptyString:!0})}},V=O({DateFormat:()=>U,DateTime:()=>H});import*as pt from"date-fns";A(V,pt);var H=class e{date;constructor(e){if(!e){this.date=new Date;return}if(e instanceof Date){if(!h(e))throw Error(`Invalid date object`);this.date=e;return}let t=Ee(e);if(!h(t))throw Error(`Invalid date string`);this.date=t}static fromUnixTimestamp(t,n){return new e(pe(t,n))}static now(){return new e(new Date)}toJSON(){return this.toISOString()}toDate(){return this.date}toUnixTimestamp(){return be(this.date)}getTime(){return this.date.getTime()}toISOString(){return fe(this.date)}format(e,t){return de(this.date,e,t)}addingDuration(t){return new e(i(this.date,t))}addingMilliseconds(t){return new e(s(this.date,t))}addingSeconds(t){return new e(u(this.date,t))}addingMinutes(t){return new e(c(this.date,t))}addingHours(t){return new e(o(this.date,t))}addingDays(t){return new e(a(this.date,t))}addingWeeks(t){return new e(d(this.date,t))}addingMonths(t){return new e(l(this.date,t))}addingYears(t){return new e(f(this.date,t))}subtractingDuration(t){return new e(b(this.date,t))}subtractingMilliseconds(t){return new e(Ie(this.date,t))}subtractingSeconds(t){return new e(ze(this.date,t))}subtractingMinutes(t){return new e(Le(this.date,t))}subtractingHours(t){return new e(Fe(this.date,t))}subtractingDays(t){return new e(Pe(this.date,t))}subtractingWeeks(t){return new e(Be(this.date,t))}subtractingMonths(t){return new e(Re(this.date,t))}subtractingYears(t){return new e(Ve(this.date,t))}differenceInMilliseconds(e){return ne(this.date,e.date)}differenceInSeconds(e){return ae(this.date,e.date)}differenceInMinutes(e){return re(this.date,e.date)}differenceInHours(e){return te(this.date,e.date)}differenceInDays(e){return ee(this.date,e.date)}differenceInWeeks(e){return oe(this.date,e.date)}differenceInMonths(e){return ie(this.date,e.date)}differenceInYears(e){return se(this.date,e.date)}isEqualTo(e){return we(this.date,e.date)}isBefore(e){return Ce(this.date,e.date)}isAfter(e){return Se(this.date,e.date)}compareTo(e){return p(this.date,e.date)}isSameDayAs(e){return Te(this.date,e.date)}startOfDay(){return new e(g(this.date))}endOfDay(){return new e(m(this.date))}startOfWeek(){return new e(v(this.date))}endOfWeek(){return new e(le(this.date))}startOfMonth(){return new e(_(this.date))}endOfMonth(){return new e(ce(this.date))}startOfYear(){return new e(y(this.date))}endOfYear(){return new e(ue(this.date))}get dayOfMonth(){return me(this.date)}get dayOfWeek(){return he(this.date)}get month(){return ve(this.date)}get year(){return xe(this.date)}get hours(){return ge(this.date)}get minutes(){return _e(this.date)}get seconds(){return ye(this.date)}settingDayOfMonth(t){return new e(De(this.date,t))}settingDayOfWeek(t){return new e(Oe(this.date,t))}settingMonth(t){return new e(je(this.date,t))}settingYear(t){return new e(Ne(this.date,t))}settingHours(t){return new e(ke(this.date,t))}settingMinutes(t){return new e(Ae(this.date,t))}settingSeconds(t){return new e(Me(this.date,t))}};let U=function(e){return e.ISO_DATE=`yyyy-MM-dd`,e.ISO_DATETIME=`yyyy-MM-dd'T'HH:mm:ssXXX`,e.MM_DD_YYYY=`MM/dd/yyyy`,e.FULL_MONTH_DAY_YEAR=`MMMM d, yyyy`,e.ABBR_MONTH_DAY_YEAR=`MMM d, yyyy`,e.RFC_3339=`yyyy-MM-dd'T'HH:mm:ss.SSSxxx`,e.ALT_RSS=`d MMM yyyy HH:mm:ss ZZZ`,e.RSS=`EEE, d MMM yyyy HH:mm:ss ZZZ`,e.HTTP_HEADER=`EEE, dd MMM yyyy HH:mm:ss zzz`,e.STANDARD=`EEE MMM dd HH:mm:ss Z yyyy`,e.EXTENDED=`eee dd-MMM-yyyy GG HH:mm:ss.SSS zzz`,e}({});var mt=class e{utc;timeZone;constructor(e,t){this.timeZone=e,this.utc=t??new Date}static fromUtc(t,n){return new e(n,t)}static fromLocalIso(t,n){let r=Ue(t,n);return new e(n,r)}format(e,t){return He(this.utc,this.timeZone,e,t)}toLocalIsoMinutes(e){return this.format(`yyyy-MM-dd'T'HH:mm`,e)}toLocalIsoSeconds(e){return this.format(`yyyy-MM-dd'T'HH:mm:ss`,e)}toISOString(){return this.utc.toISOString()}toUnixTimestamp(){return Math.floor(this.utc.getTime()/1e3)}toZonedDate(){return Ge(this.utc,this.timeZone)}timezoneOffsetMs(e){return We(this.timeZone,e??this.utc)}},ht=class{value;constructor([e,t]){if(e<-180||e>180)throw Error(`Longitude must be between -180 and 180.`);if(t<-90||t>90)throw Error(`Latitude must be between -90 and 90.`);this.value=[e,t]}get longitude(){return this.value[0]}get latitude(){return this.value[1]}toJSON(){return this.value}},gt=class{type=`Point`;coordinates;bbox;constructor(e,t){this.coordinates=e,this.bbox=t}toJSON(){return{type:this.type,coordinates:this.coordinates.toJSON(),...this.bbox&&{bbox:this.bbox}}}},_t=class{type=`MultiPoint`;coordinates;bbox;constructor(e,t){this.coordinates=e,this.bbox=t}toJSON(){return{type:this.type,coordinates:this.coordinates.map(e=>e.toJSON()),...this.bbox&&{bbox:this.bbox}}}},vt=class{type=`LineString`;coordinates;bbox;constructor(e,t){this.coordinates=e,this.bbox=t}toJSON(){return{type:this.type,coordinates:this.coordinates.map(e=>e.toJSON()),...this.bbox&&{bbox:this.bbox}}}},yt=class{type=`MultiLineString`;coordinates;bbox;constructor(e,t){this.coordinates=e,this.bbox=t}toJSON(){return{type:this.type,coordinates:this.coordinates.map(e=>e.map(e=>e.toJSON())),...this.bbox&&{bbox:this.bbox}}}},bt=class{type=`Polygon`;coordinates;bbox;constructor(e,t){this.coordinates=e,this.bbox=t}toJSON(){return{type:this.type,coordinates:this.coordinates.map(e=>e.map(e=>e.toJSON())),...this.bbox&&{bbox:this.bbox}}}},xt=class{type=`MultiPolygon`;coordinates;bbox;constructor(e,t){this.coordinates=e,this.bbox=t}toJSON(){return{type:this.type,coordinates:this.coordinates.map(e=>e.map(e=>e.map(e=>e.toJSON()))),...this.bbox&&{bbox:this.bbox}}}};let St=function(e){return e.Point=`Point`,e.MultiPoint=`MultiPoint`,e.LineString=`LineString`,e.MultiLineString=`MultiLineString`,e.Polygon=`Polygon`,e.MultiPolygon=`MultiPolygon`,e}({});function W(e){return Error(`Invalid ObjectId value: ${String(e)}`)}var Ct=class e{value;constructor(e){if(e==null)throw W(e);let t=e.trim();if(t.length===0)throw W(e);this.value=t,Object.freeze(this)}get asString(){return this.value}equals(t){return this.value===e.from(t).value}compare(t){let n=e.from(t).value;return this.value===n?0:this.value<n?-1:1}hash(){return this.value}toJSON(){return this.value}toString(){return this.value}[Symbol.toPrimitive](){return this.value}static from(t){return t instanceof e?t:new e(t)}static isValid(e){return typeof e==`string`&&e.trim().length>0}static toValueSet(t){let n=new Set;for(let r of t)n.add(e.from(r).value);return n}},wt=class{day;intervals;constructor(e,t){this.day=e,this.intervals=t}toJSON(){return R({day:this.day,intervals:this.intervals},{filterNull:!0,filterUndefined:!0,filterEmptyString:!0})}},Tt=class{_milliseconds;_long;constructor(e,t){if(this._long=t?.long===!0,e==null)throw Error(`Invalid interval format: ${e}`);if(typeof e==`number`)this._milliseconds=e;else{let t=x(e);if(t===void 0)throw Error(`Invalid interval format: ${e}`);this._milliseconds=t}}get milliseconds(){return this._milliseconds}get seconds(){return Math.floor(this._milliseconds/1e3)}get minutes(){return Math.floor(this._milliseconds/6e4)}get hours(){return Math.floor(this._milliseconds/36e5)}get days(){return Math.floor(this._milliseconds/864e5)}get weeks(){return Math.floor(this._milliseconds/6048e5)}get formatted(){return x(this._milliseconds,{long:this._long})}toString(){return x(this._milliseconds,{long:this._long})}toObject(){return{milliseconds:this._milliseconds,seconds:this.seconds,minutes:this.minutes,hours:this.hours,days:this.days,weeks:this.weeks}}};let Et=function(e){return e.Byte=`B`,e.Kilobyte=`KB`,e.Megabyte=`MB`,e.Gigabyte=`GB`,e.Terabyte=`TB`,e}({}),Dt=function(e){return e.Millimeter=`mm`,e.Centimeter=`cm`,e.Meter=`m`,e.Kilometer=`km`,e}({}),Ot=function(e){return e.Milligram=`mg`,e.Gram=`g`,e.Kilogram=`kg`,e.Tonne=`t`,e}({});A(O({Address:()=>dt,ByteUnit:()=>Et,Contacts:()=>ft,Coordinates:()=>ht,DateFormat:()=>U,DateTime:()=>H,DistanceUnit:()=>Dt,GeoJsonType:()=>St,LineString:()=>vt,MultiLineString:()=>yt,MultiPoint:()=>_t,MultiPolygon:()=>xt,ObjectId:()=>Ct,OpeningHour:()=>wt,Point:()=>gt,Polygon:()=>bt,TimeInterval:()=>Tt,WeightUnit:()=>Ot,ZonedDateTime:()=>mt}),V);function kt(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let G=class{formatBytes(e,t){let{inputUnit:n=`B`,outputUnit:r=`auto`,decimals:i=1}=t??{},a=e=>e===`B`?1:e===`KB`?1024:e===`MB`?1048576:e===`GB`?1073741824:1099511627776,o=e*a(n),s=r===`auto`?(()=>{for(let e of[`TB`,`GB`,`MB`,`KB`])if(o/a(e)>=1)return e;return`B`})():r,c=o/a(s),l=10**i;return{value:Math.round(c*l)/l,unit:s,bytes:o}}};G=kt([r()],G);var At=class{assemble(e){e.bind(L.DI.Formatter.UnitController).to(G)}};function jt(){return[new At]}let Mt=function(e){return e.Critical=`CRITICAL`,e.Serious=`SERIOUS`,e.Important=`IMPORTANT`,e.Notice=`NOTICE`,e.Routine=`ROUTINE`,e}({});function K(e,t){if(S.isAbsolute(t))return S.normalize(t);let n;try{let t=new URL(e);if(t.protocol!==`file:`)throw Error(`Unsupported URL protocol "${t.protocol}"`);n=S.dirname(Ke(t))}catch{n=e}return S.resolve(n,t)}function Nt(e,t={}){let n=K(process.cwd(),e);if(!C.existsSync(n))return;let r=C.statSync(n),{recursive:i=!0,force:a=!0,cleanOnly:o=!1}=t;if(o&&r.isDirectory()){for(let e of C.readdirSync(n))C.rmSync(S.join(n,e),{recursive:i,force:a});return}if(o&&r.isFile()){C.truncateSync(n,0);return}C.rmSync(n,{recursive:r.isDirectory()?i:!1,force:a,maxRetries:3,retryDelay:100})}function q(e){let t=K(process.cwd(),e),n=C.existsSync(t)&&C.statSync(t).isDirectory()?t:S.dirname(t);if(!C.existsSync(n))throw Error(`Directory "${n}" does not exist.`);return t}function Pt(e){let t=K(process.cwd(),e);S.extname(e)&&console.warn(`[createDirectory] Warning: "${e}" looks like a file path.`);try{if(!C.existsSync(t))C.mkdirSync(t,{recursive:!0});else if(!C.statSync(t).isDirectory())throw Error(`"${t}" exists but is not a directory.`);return t}catch(e){throw Error(`Failed to create directory "${t}": ${e.message}`)}}function Ft(e,t=``){let n=K(process.cwd(),e);q(S.dirname(n));let r=It(n);if(!r)C.writeFileSync(n,t,{encoding:`utf8`,flag:`w`});else{if(!r.isFile())throw Error(`"${n}" exists but is not a file.`);t&&C.writeFileSync(n,t,{encoding:`utf8`,flag:`a`})}return n}function It(e){try{return C.statSync(e)}catch{return}}async function Lt(e,t={}){let n=K(process.cwd(),e),r;try{r=await w.stat(n)}catch(e){if((t.force??!0)&&e.code===`ENOENT`)return;throw e}let{recursive:i=!0,force:a=!0,cleanOnly:o=!1}=t;if(o&&r.isDirectory()){let e=await w.readdir(n);for(let t of e)await w.rm(S.join(n,t),{recursive:i,force:a});return}if(o&&r.isFile()){await w.truncate(n,0);return}await w.rm(n,{recursive:r.isDirectory()?i:!1,force:a,maxRetries:3,retryDelay:100})}async function J(e){let t=K(process.cwd(),e),n;try{n=await w.stat(t)}catch{}let r=n?.isDirectory()?t:S.dirname(t);try{if(!(await w.stat(r)).isDirectory())throw Error(`"${r}" exists but is not a directory.`)}catch(e){throw e.code===`ENOENT`?Error(`Directory "${r}" does not exist.`):e}return t}async function Rt(e){let t=K(process.cwd(),e);S.extname(e)&&console.warn(`[createDirectory] Warning: "${e}" looks like a file path (has extension).`);try{let e;try{e=await w.stat(t)}catch{}if(!e)await w.mkdir(t,{recursive:!0});else if(!e.isDirectory())throw Error(`"${t}" exists but is not a directory.`);return t}catch(e){throw Error(`Failed to create directory "${t}": ${e.message}`)}}async function zt(e,t=``){let n=K(process.cwd(),e);await J(S.dirname(n));try{let e=await Bt(n);if(!e)await w.writeFile(n,t,{encoding:`utf8`,flag:`w`});else{if(!e.isFile())throw Error(`"${n}" exists but is not a file.`);t&&await w.writeFile(n,t,{encoding:`utf8`,flag:`a`})}return n}catch(e){throw Error(`Failed to create file "${n}": ${e.message}`)}}async function Bt(e){try{return await w.stat(e)}catch(e){if(e.code===`ENOENT`)return;throw e}}var Y=class{options;instance;constructor(e){this.options=e,this.instance=this.makeInstance()}info(e,t){this.log(`info`,e,t)}debug(e,t){this.log(`debug`,e,t)}trace(e,t){this.log(`trace`,e,t)}warn(e,t){this.log(`warn`,e,t)}error(e,t){this.log(`error`,e,t)}fatal(e,t){this.log(`fatal`,e,t)}child(e){return this.instance.child(e)}log(e,t,n){this.instance[e]({msg:t,...this.formatLogOptions(n)})}formatLogOptions(e){return e?this.normalizeObject({flag:e.flag,details:this.formatUnknown(e.details),error:this.formatUnknown(e.error),metadata:this.formatUnknown(e.metadata)}):{}}formatUnknown(e){if(ct(e)){let t={type:e.constructor.name,message:e.message};this.options.debug&&e.stack&&(t.stack=e.stack);for(let[n,r]of Object.entries(e))n in t||(t[n]=r);let n=this.normalizeObject(t);return B(n)?void 0:n}if(Buffer.isBuffer(e))return`[Buffer]`;if(e&&typeof e.pipe==`function`)return`[Stream]`;if(z(e))try{let t=JSON.stringify(e);if(t===void 0)return;let n=JSON.parse(t);if(Array.isArray(n))return n.length>0?n:void 0;if(z(n)){let e=this.normalizeObject(n);return B(e)?void 0:e}return n}catch{return{type:`NonSerializableObject`}}return ut(e)?e:String(e)}normalizeObject(e){return R(Object.fromEntries(Object.entries(e)),{filterNull:!0,filterUndefined:!0,filterEmptyString:!0,filterEmptyArray:!0,filterEmptyObject:!0})}makeInstance(){if(!this.options.enabled)return T({enabled:!1,timestamp:!0});let e=this.options.transports,t={level:this.makeGlobalLogLevel(e),enabled:!0,timestamp:!0,transport:{targets:this.makeTransportTargets(e)}};return T(t)}makeTransportTargets(e){if(e.filter(e=>e.type===`console`).length>1)throw Error(`[Logger] Multiple console transports are not supported.`);return e.map(e=>{switch(e.type){case`console`:return this.makeConsoleTransportTarget(e);case`file`:return this.makeFileTransportTarget(e)}})}makeConsoleTransportTarget(e){return{target:`pino-pretty`,level:this.makeTransportLevel(e.level),options:e.pretty}}makeFileTransportTarget(e){let t=this.makeTransportLevel(e.level),n=S.isAbsolute(e.path)?S.normalize(e.path):K(process.cwd(),e.path);return q(S.dirname(n)),{target:`pino/file`,level:t,options:{destination:n}}}makeTransportLevel(e){return this.options.debug?`trace`:e??`info`}makeGlobalLogLevel(e){if(this.options.debug)return`trace`;let t=e.at(0);if(!t)return`info`;let n={trace:0,debug:1,info:2,warn:3,error:4,fatal:5},r=this.makeTransportLevel(t.level);for(let t of e.slice(1)){let e=this.makeTransportLevel(t.level);n[e]<n[r]&&(r=e)}return r}},Vt=class{options;constructor(e){this.options=e}assemble(e){e.bind(L.DI.Logger).toConstantValue(new Y(this.options))}};function Ht(e={}){let t=e.logger??{enabled:!1};return[...jt(),new Vt(t)]}function X(e){return process.env[e]?.trim()||void 0}function Ut(e){let t=X(e);if(!t)throw Error(`Missing required environment variable: ${e}`);return t}const Z=E.string().trim().min(1).transform(e=>{let{prefix:t,base:n}=Wt(e),r=Gt(n);return{original:e,prefix:t,base:n,kebab:Kt(r),snake:qt(r),camel:Jt(r),pascal:Yt(r)}}),Q=E.looseObject({name:Z,version:E.string().trim().min(1),private:E.boolean().optional(),type:E.enum([`module`,`commonjs`]).optional(),dependencies:E.record(E.string(),E.string()).default({}),peerDependencies:E.record(E.string(),E.string()).default({}),devDependencies:E.record(E.string(),E.string()).default({})});function Wt(e){let t=/^@([^/]+)\/(.+)$/.exec(e);return t&&t[2]?{prefix:t[1],base:t[2]}:{base:e}}function Gt(e){let t=e.replace(/([a-z0-9])([A-Z])/g,`$1 $2`).replace(/[^a-zA-Z0-9]+/g,` `).trim().toLowerCase();return t?t.split(/\s+/):[]}function Kt(e){return e.join(`-`)}function qt(e){return e.join(`_`)}function Jt(e){if(e.length===0)return``;let[t,...n]=e;return t+n.map($).join(``)}function Yt(e){return e.map($).join(``)}function $(e){return e.length===0?``:e.charAt(0).toUpperCase()+e.slice(1)}function Xt(e){let t,n;try{t=C.readFileSync(e,`utf8`)}catch(t){throw Error(`Failed to read package.json at ${e}`,{cause:t})}try{n=JSON.parse(t)}catch(t){throw Error(`Failed to parse package.json at ${e}`,{cause:t})}try{return Q.parse(n)}catch(t){throw Error(`Invalid package.json at ${e}`,{cause:t})}}export{st as Console,Mt as LogFlag,Y as LoggerImpl,Q as PackageJSONSchema,Z as PackageNameSchema,Ht as coreNodeAssembly,Pt as createDirectory,Rt as createDirectoryAsync,Ft as createFile,zt as createFileAsync,q as ensureDirectory,J as ensureDirectoryAsync,Xt as loadPackageJSON,Xe as makeDependencyBundlingPolicy,X as optionalEnvironmentVariable,Nt as removePath,Lt as removePathAsync,Ut as requiredEnvironmentVariable,K as resolvePath};
|
|
1
|
+
import{builtinModules as e}from"node:module";import{createConsola as t}from"consola";import{colors as n}from"consola/utils";import r,{promises as i}from"node:fs";import a,{dirname as o}from"node:path";import{fileURLToPath as s}from"node:url";import c from"@dotenvx/dotenvx";import{createJiti as l}from"jiti";import{injectable as u}from"inversify";import{add as d,addDays as f,addHours as ee,addMilliseconds as te,addMinutes as ne,addMonths as re,addSeconds as ie,addWeeks as ae,addYears as oe,compareAsc as se,differenceInDays as ce,differenceInHours as le,differenceInMilliseconds as ue,differenceInMinutes as de,differenceInMonths as fe,differenceInSeconds as pe,differenceInWeeks as me,differenceInYears as he,endOfDay as ge,endOfMonth as _e,endOfWeek as ve,endOfYear as ye,format as be,formatISO as xe,fromUnixTime as Se,getDate as Ce,getDay as we,getHours as Te,getMinutes as Ee,getMonth as De,getSeconds as Oe,getUnixTime as ke,getYear as Ae,isAfter as je,isBefore as Me,isEqual as Ne,isSameDay as Pe,isValid as p,parseISO as Fe,setDate as Ie,setDay as Le,setHours as Re,setMinutes as ze,setMonth as Be,setSeconds as Ve,setYear as He,startOfDay as Ue,startOfMonth as We,startOfWeek as Ge,startOfYear as Ke,sub as qe,subDays as Je,subHours as Ye,subMilliseconds as Xe,subMinutes as Ze,subMonths as Qe,subSeconds as $e,subWeeks as et,subYears as tt}from"date-fns";import{formatInTimeZone as nt,fromZonedTime as rt,getTimezoneOffset as it,toZonedTime as at}from"date-fns-tz";import m from"ms";import h from"pino";import g from"zod";var _=Object.defineProperty,ot=Object.getOwnPropertyDescriptor,st=Object.getOwnPropertyNames,ct=Object.prototype.hasOwnProperty,v=(e,t)=>{let n={};for(var r in e)_(n,r,{get:e[r],enumerable:!0});return t||_(n,Symbol.toStringTag,{value:`Module`}),n},y=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=st(t),a=0,o=i.length,s;a<o;a++)s=i[a],!ct.call(e,s)&&s!==n&&_(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=ot(t,s))||r.enumerable});return e},b=(e,t,n)=>(y(e,t,`default`),n&&y(n,t,`default`));function lt(e,t={}){let n=t.includePeers??!0,r=t.includeDependencies??!0,i=t.includeSubpaths??!0,a=t.includeNodeBuiltins??!0,o=t.allowPeerBundling??!1,s=Object.keys(e.peerDependencies??{}),c=Object.keys(e.dependencies??{}),l=S(t.bundle??[]),u=S(t.external??[]);ht(u,l),_t(l),o||gt(s,l);let d=new Set(l.map(w)),f=n?s.filter(e=>!d.has(e)):[],ee=r?c.filter(e=>!d.has(e)):[];return{external:C([...a?ut():[],...x([...f,...ee,...u],i)]),bundle:C(x(l,i))}}function ut(){let t=S(e.map(T)),n=t.map(e=>`node:${e}`);return C([...t,...n,/^node:/])}function x(e,t){return t?e.map(e=>dt(e)):[...e]}function dt(e){return pt(e)?e:RegExp(`^${mt(e)}(?:/.*)?$`)}function S(e){return Array.from(new Set(e))}function C(e){let t=new Set,n=[];for(let r of e){let e=ft(r);t.has(e)||(t.add(e),n.push(r))}return n}function ft(e){return typeof e==`string`?`string:${e}`:`regexp:${e.source}/${e.flags}`}function w(e){if(e.startsWith(`@`)){let[t,n]=e.split(`/`);return t&&n?`${t}/${n}`:e}let[t]=e.split(`/`);return t??e}function T(e){return e.startsWith(`node:`)?e.slice(5):e}function pt(e){return e.includes(`*`)||e.startsWith(`^`)||e.endsWith(`$`)}function mt(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function ht(e,t){let n=new Set(e.map(w)),r=t.filter(e=>n.has(w(e)));if(r.length!==0)throw Error(`Packages cannot be both external and bundled: ${r.join(`, `)}`)}function gt(e,t){let n=new Set(e),r=t.filter(e=>n.has(w(e)));if(r.length!==0)throw Error(`Peer dependencies must stay external and cannot be bundled by default: ${r.join(`, `)}`)}function _t(t){let n=new Set(e.map(T)),r=t.filter(e=>vt(e,n));if(r.length!==0)throw Error(`Node.js built-in modules cannot be bundled: ${r.join(`, `)}`)}function vt(e,t){let n=T(e),[r]=n.split(`/`);return r?t.has(r):t.has(n)}const yt=/\u001B\[[0-9;]*m/g;var bt=class{instance;constructor(e={}){this.instance=t({level:e.enabled===!1?-999:999,formatOptions:{colors:!0,date:!1}})}title(e,t,r=[]){this.printPanel({title:`${e} ${t}`.trim(),renderedTitle:`${n.cyan(n.bold(e))}${t?` ${n.dim(t)}`:``}`,rows:r,formatValue:n.green})}panel(e,t,r){this.printPanel({title:r===void 0?e:`${e} ${r}`,renderedTitle:`${n.cyan(n.bold(e))}${r===void 0?``:` ${n.green(String(r))}`}`,rows:t,formatValue:n.dim})}step(e,t){return`${n.cyan(e.padEnd(10,` `))}${t}`}duration(e){return e<1e3?`${e}ms`:`${(e/1e3).toFixed(2)}s`}emptyLine(){this.instance.log(``)}log(e,...t){this.instance.log(e,...t)}info(e,...t){this.instance.info(e,...t)}start(e,...t){this.instance.start(e,...t)}success(e,...t){this.instance.success(e,...t)}warn(e,...t){this.instance.warn(e,...t)}error(e,...t){this.instance.error(e,...t)}debug(e,...t){this.instance.debug(e,...t)}printPanel(e){this.instance.log(this.formatPanel(e))}formatPanel(e){let t=this.getPanelWidth(e);return[this.formatPanelTop(e.renderedTitle,t),...e.rows.map(n=>this.formatPanelRow(n,t,e.formatValue)),this.formatPanelBottom(t)].join(`
|
|
2
|
+
`)}formatPanelTop(e,t){let r=Math.max(1,t-this.visibleLength(e)-5);return`${n.dim(`╭─`)} ${e} ${n.dim(`─`.repeat(r))}${n.dim(`╮`)}`}formatPanelBottom(e){return`${n.dim(`╰`)}${n.dim(`─`.repeat(e-2))}${n.dim(`╯`)}`}formatPanelRow(e,t,r){let i=e.label.padEnd(14,` `),a=String(e.value),o=this.visibleLength(i)+this.visibleLength(a)+4,s=Math.max(0,t-o);return`${n.dim(`│`)} ${n.blue(i)}${r(a)}${` `.repeat(s)} ${n.dim(`│`)}`}getPanelWidth(e){return Math.max(48,this.getTitleWidth(e),this.getRowsWidth(e.rows))}getTitleWidth(e){return this.visibleLength(e.title)+6}getRowsWidth(e){return Math.max(0,...e.map(e=>this.getRowWidth(e)))}getRowWidth(e){return 14+this.visibleLength(String(e.value))+4}visibleLength(e){return e.replace(yt,``).length}};const E=Symbol.for(`buildplease.environment-configuration.field`),D=Symbol.for(`buildplease.environment-configuration.contract`),O=Symbol.for(`buildplease.environment-configuration.binding`),xt=Symbol.for(`buildplease.environment-configuration.config`),St={string(){return A((e,t)=>{if(typeof e!=`string`)throw Error(`${t} must be string.`);let n=e.trim();if(!n)throw Error(`${t} must not be empty.`);return n},{required:!0})},number(){return A((e,t)=>{let n=typeof e==`number`?e:Number(e);if(!Number.isFinite(n))throw Error(`${t} must be number.`);return n},{required:!0})},boolean(){return A((e,t)=>{if(typeof e==`boolean`)return e;if(typeof e==`string`){let t=e.trim().toLowerCase();if(t===`true`)return!0;if(t===`false`)return!1}throw Error(`${t} must be boolean.`)},{required:!0})},array(e){return A((t,n)=>{if(!Array.isArray(t))throw Error(`${n} must be array.`);return t.map((t,r)=>e.parse(t,`${n}[${r}]`))},{required:!0})},custom(){return A(e=>e,{required:!0})}};function Ct(e,t){let n=e.trim();if(!n)throw Error(`Configuration key must not be empty.`);let r=(e=>{let t={contract:r,input:e};return Object.defineProperty(t,O,{value:!0}),t});return Object.defineProperties(r,{[D]:{value:!0},key:{value:n},schema:{value:t}}),r}function wt(e,t){let n={environments:e,input:t};return Object.defineProperty(n,xt,{value:!0}),n}function Tt(e){return!!(e&&typeof e==`object`&&e[xt]===!0)}function Et(e){return!!(e&&typeof e==`object`&&e[E]===!0)}function Dt(e){return typeof e==`function`&&e[D]===!0}function k(e){return!!(e&&typeof e==`object`&&e[O]===!0)}function A(e,t){let n={required:t.required,hasDefault:t.hasDefault??!1,defaultValue:t.defaultValue,parse:e,optional(){return A((t,n)=>{if(t!=null)return e(t,n)},{required:!1})},default(t){return A(e,{required:!1,hasDefault:!0,defaultValue:t})},map(n){let r=t.hasDefault&&t.defaultValue!==void 0?n(t.defaultValue):void 0;return A((t,r)=>n(e(t,r)),{required:t.required,hasDefault:t.hasDefault,defaultValue:r})}};return Object.defineProperty(n,E,{value:!0}),n}function j(e,t){if(a.isAbsolute(t))return a.normalize(t);let n;try{let t=new URL(e);if(t.protocol!==`file:`)throw Error(`Unsupported URL protocol "${t.protocol}"`);n=a.dirname(s(t))}catch{n=e}return a.resolve(n,t)}function Ot(e,t={}){let n=j(process.cwd(),e);if(!r.existsSync(n))return;let i=r.statSync(n),{recursive:o=!0,force:s=!0,cleanOnly:c=!1}=t;if(c&&i.isDirectory()){for(let e of r.readdirSync(n))r.rmSync(a.join(n,e),{recursive:o,force:s});return}if(c&&i.isFile()){r.truncateSync(n,0);return}r.rmSync(n,{recursive:i.isDirectory()?o:!1,force:s,maxRetries:3,retryDelay:100})}function M(e){let t=j(process.cwd(),e),n=r.existsSync(t)&&r.statSync(t).isDirectory()?t:a.dirname(t);if(!r.existsSync(n))throw Error(`Directory "${n}" does not exist.`);return t}function kt(e){let t=j(process.cwd(),e);a.extname(e)&&console.warn(`[createDirectory] Warning: "${e}" looks like a file path.`);try{if(!r.existsSync(t))r.mkdirSync(t,{recursive:!0});else if(!r.statSync(t).isDirectory())throw Error(`"${t}" exists but is not a directory.`);return t}catch(e){throw Error(`Failed to create directory "${t}": ${e.message}`)}}function At(e,t=``){let n=j(process.cwd(),e);M(a.dirname(n));let i=jt(n);if(!i)r.writeFileSync(n,t,{encoding:`utf8`,flag:`w`});else{if(!i.isFile())throw Error(`"${n}" exists but is not a file.`);t&&r.writeFileSync(n,t,{encoding:`utf8`,flag:`a`})}return n}function jt(e){try{return r.statSync(e)}catch{return}}async function Mt(e,t={}){let n=j(process.cwd(),e),r;try{r=await i.stat(n)}catch(e){if((t.force??!0)&&e.code===`ENOENT`)return;throw e}let{recursive:o=!0,force:s=!0,cleanOnly:c=!1}=t;if(c&&r.isDirectory()){let e=await i.readdir(n);for(let t of e)await i.rm(a.join(n,t),{recursive:o,force:s});return}if(c&&r.isFile()){await i.truncate(n,0);return}await i.rm(n,{recursive:r.isDirectory()?o:!1,force:s,maxRetries:3,retryDelay:100})}async function N(e){let t=j(process.cwd(),e),n;try{n=await i.stat(t)}catch{}let r=n?.isDirectory()?t:a.dirname(t);try{if(!(await i.stat(r)).isDirectory())throw Error(`"${r}" exists but is not a directory.`)}catch(e){throw e.code===`ENOENT`?Error(`Directory "${r}" does not exist.`):e}return t}async function Nt(e){let t=j(process.cwd(),e);a.extname(e)&&console.warn(`[createDirectory] Warning: "${e}" looks like a file path (has extension).`);try{let e;try{e=await i.stat(t)}catch{}if(!e)await i.mkdir(t,{recursive:!0});else if(!e.isDirectory())throw Error(`"${t}" exists but is not a directory.`);return t}catch(e){throw Error(`Failed to create directory "${t}": ${e.message}`)}}async function Pt(e,t=``){let n=j(process.cwd(),e);await N(a.dirname(n));try{let e=await Ft(n);if(!e)await i.writeFile(n,t,{encoding:`utf8`,flag:`w`});else{if(!e.isFile())throw Error(`"${n}" exists but is not a file.`);t&&await i.writeFile(n,t,{encoding:`utf8`,flag:`a`})}return n}catch(e){throw Error(`Failed to create file "${n}": ${e.message}`)}}async function Ft(e){try{return await i.stat(e)}catch(e){if(e.code===`ENOENT`)return;throw e}}function It(e){let t=Object.entries(e);if(!t.length)throw Error(`At least one environment must be defined.`);for(let[e,n]of t)Lt(e,n);return e}function P(e,t,n={}){let r=e[t];if(!r)throw Error(`Environment "${t}" is not defined.`);let i=j(n.baseDir?.trim()||process.cwd(),r.fileDir?.trim()||`.`);return{name:t,file:r.file.trim(),fileDir:i}}function Lt(e,t){if(!e.trim())throw Error(`Environment name must not be empty.`);if(typeof t.file!=`string`||!t.file.trim())throw Error(`Environment file must not be empty for "${e}".`)}function Rt(e){return process.env[e]?.trim()||void 0}const F=Symbol.for(`buildplease.environment-configuration.source`);function zt(e){return{env(e){return L(`env`,{name:e})},byEnvironment(e){return L(`by-environment`,{cases:e})},compute(e){return L(`compute`,{compute:e})},static(e){return L(`static`,{value:e})}}}function I(e){return!!(e&&typeof e==`object`&&e[F]===!0)}function L(e,t,n=[]){let r={kind:e,options:t,transforms:n,default(e){return L(`default`,{source:r,value:e})},map(r){return L(e,t,[...n,r])}};return Object.defineProperty(r,F,{value:!0}),r}async function Bt(e,t){let n=U(t,`config`);return V(e.input,n,`config`)}async function R(e,t,n={}){let r=Vt(n);return B(e.schema,t,r,e.key)}async function z(e,t={}){return R(e.contract,e.input,t)}function Vt(e){return{buildMetadata:e.buildMetadata,environment:e.environment}}async function B(e,t,n,r){if(Et(e))return Ht(e,t,n,r);let i=await V(t,n,r)??{};if(!G(i))throw Error(`${r} must be object.`);let a={};for(let[t,o]of Object.entries(e))a[t]=await B(o,i[t],n,`${r}.${t}`);return a}async function Ht(e,t,n,r){let i=await V(t,n,r);if(i==null){if(e.hasDefault)return W(e.defaultValue);if(!e.required)return;throw Error(`Missing required configuration: ${r}`)}return e.parse(i,r)}async function V(e,t,n){if(I(e))return H(e,t,n);if(k(e))return z(e,t);if(Array.isArray(e))return Promise.all(e.map((e,r)=>V(e,t,`${n}[${r}]`)));if(G(e)){let r={};for(let[i,a]of Object.entries(e))r[i]=await V(a,t,`${n}.${i}`);return r}return e}async function H(e,t,n){let r;switch(e.kind){case`env`:{let{name:t}=e.options;r=Rt(t);break}case`by-environment`:{let i=Ut(t,n),{cases:a}=e.options;if(!Object.prototype.hasOwnProperty.call(a,i.name))throw Error(`${n} has no value for environment "${i.name}".`);r=await V(a[i.name],t,n);break}case`compute`:{let i=U(t,n),{compute:a}=e.options;r=await a(i);break}case`static`:{let{value:t}=e.options;r=t;break}case`default`:{let{source:i,value:a}=e.options;r=await H(i,t,n)??W(a);break}}for(let t of e.transforms)r=await t(r);return r}function Ut(e,t){if(!e?.environment)throw Error(`${t} requires runtime environment.`);return e.environment}function U(e,t){if(!e?.environment)throw Error(`${t} requires runtime environment.`);if(!e.buildMetadata)throw Error(`${t} requires build metadata.`);return e}function W(e){if(Array.isArray(e))return e.map(e=>W(e));if(G(e)){let t={};for(let[n,r]of Object.entries(e))t[n]=W(r);return t}return e}function G(e){if(!e||typeof e!=`object`||Object.prototype.toString.call(e)!==`[object Object]`)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}const K=[`.ts`,`.mts`,`.cts`,`.js`,`.mjs`,`.cjs`],Wt=`environment.config.ts`;async function Gt(e={}){let t=Kt(e.dir);try{let n=qt(t,e.config??`environment.config.ts`),r=await Jt(t,n);if(!Tt(r))throw Error(`Environment config must be defined with defineConfig() (${n}).`);let i=r,a=e.environment?P(i.environments,e.environment,{baseDir:o(n)}):void 0;return a&&Yt(a),{config:i,configFilePath:n,rootDir:t,environment:a}}catch(e){throw Error(`Failed to load environment config: ${e instanceof Error?e.message:String(e)}`)}}function Kt(e){let t=e?j(process.cwd(),e):process.cwd();return M(t),t}function qt(e,t){let n=j(e,t);if(r.existsSync(n))return n;if(!K.some(e=>t.endsWith(e)))for(let e of K){let t=`${n}${e}`;if(r.existsSync(t))return t}throw Error(`Config file "${n}" does not exist.`)}async function Jt(e,t){return l(e,{interopDefault:!0,extensions:[...K],tsconfigPaths:!0}).import(t,{default:!0})}function Yt(e){let t=j(e.fileDir,e.file);if(!r.existsSync(t))throw Error(`Environment file "${t}" does not exist.`);c.config({path:t}),process.env.NODE_ENV=e.name}const q=`${{name:`buildplease`,displayName:`BuildPlease`,scope:`@buildplease`}.name}.Core.DI`,J={DI:{Formatter:{UnitController:Symbol.for(`${q}.Formatter.UnitController`)},Logger:Symbol.for(`${q}.Logger`)}};function Xt(e){return e instanceof Error}function Y(e,t={}){if(e==null)return{};let{filterNull:n=!0,filterUndefined:r=!0,filterEmptyString:i=!1,filterEmptyObject:a=!1,filterEmptyArray:o=!1}=t;return Object.keys(e).reduce((s,c)=>{let l=e[c];return X(l)&&Object.getPrototypeOf(l)===null&&(l=void 0),Zt(l)&&(l=Y(l,t)),n&&l===null||r&&l===void 0||i&&l===``||a&&Z(l)||o&&Array.isArray(l)&&l.length===0||(s[c]=l),s},{})}function X(e){return typeof e==`object`&&!!e}function Z(e){return X(e)&&Object.keys(e).length===0}function Zt(e){return X(e)&&Object.getPrototypeOf(e)===Object.prototype}function Qt(e){return e==null||[`string`,`number`,`boolean`,`bigint`,`symbol`].includes(typeof e)}Array.prototype.isEmpty=function(){return this==null||this.length===0},String.prototype.capitalized=function(){let e=this==null?``:this.toString();return e.trim()?e.charAt(0).toUpperCase()+e.slice(1):``};var $t=class{streetLine1;streetLine2;postalCode;state;city;country;countryCode;constructor(e){this.streetLine1=e.streetLine1,this.streetLine2=e.streetLine2,this.postalCode=e.postalCode,this.state=e.state,this.city=e.city,this.country=e.country,this.countryCode=e.countryCode}toJSON(){return Y({streetLine1:this.streetLine1,streetLine2:this.streetLine2,postalCode:this.postalCode,city:this.city,state:this.state,country:this.country,countryCode:this.countryCode},{filterNull:!0,filterUndefined:!0,filterEmptyString:!0})}formatted(){let e=(e,t)=>e.map(e=>e?.trim()).filter(e=>e&&e.length>0).join(t).trim(),t=this.streetLine1;return e([t,e([this.postalCode,this.city],` `),e([this.country],`, `)],`, `)}},en=class{email;fb;ig;phone;web;constructor({email:e,fb:t,ig:n,phone:r,web:i}){this.email=e,this.fb=t,this.ig=n,this.phone=r,this.web=i}toJSON(){return Y({email:this.email,fb:this.fb,ig:this.ig,phone:this.phone,web:this.web},{filterNull:!0,filterUndefined:!0,filterEmptyString:!0})}},tn=v({DateFormat:()=>an,DateTime:()=>rn});import*as nn from"date-fns";b(tn,nn);var rn=class e{date;constructor(e){if(!e){this.date=new Date;return}if(e instanceof Date){if(!p(e))throw Error(`Invalid date object`);this.date=e;return}let t=Fe(e);if(!p(t))throw Error(`Invalid date string`);this.date=t}static fromUnixTimestamp(t,n){return new e(Se(t,n))}static now(){return new e(new Date)}toJSON(){return this.toISOString()}toDate(){return this.date}toUnixTimestamp(){return ke(this.date)}getTime(){return this.date.getTime()}toISOString(){return xe(this.date)}format(e,t){return be(this.date,e,t)}addingDuration(t){return new e(d(this.date,t))}addingMilliseconds(t){return new e(te(this.date,t))}addingSeconds(t){return new e(ie(this.date,t))}addingMinutes(t){return new e(ne(this.date,t))}addingHours(t){return new e(ee(this.date,t))}addingDays(t){return new e(f(this.date,t))}addingWeeks(t){return new e(ae(this.date,t))}addingMonths(t){return new e(re(this.date,t))}addingYears(t){return new e(oe(this.date,t))}subtractingDuration(t){return new e(qe(this.date,t))}subtractingMilliseconds(t){return new e(Xe(this.date,t))}subtractingSeconds(t){return new e($e(this.date,t))}subtractingMinutes(t){return new e(Ze(this.date,t))}subtractingHours(t){return new e(Ye(this.date,t))}subtractingDays(t){return new e(Je(this.date,t))}subtractingWeeks(t){return new e(et(this.date,t))}subtractingMonths(t){return new e(Qe(this.date,t))}subtractingYears(t){return new e(tt(this.date,t))}differenceInMilliseconds(e){return ue(this.date,e.date)}differenceInSeconds(e){return pe(this.date,e.date)}differenceInMinutes(e){return de(this.date,e.date)}differenceInHours(e){return le(this.date,e.date)}differenceInDays(e){return ce(this.date,e.date)}differenceInWeeks(e){return me(this.date,e.date)}differenceInMonths(e){return fe(this.date,e.date)}differenceInYears(e){return he(this.date,e.date)}isEqualTo(e){return Ne(this.date,e.date)}isBefore(e){return Me(this.date,e.date)}isAfter(e){return je(this.date,e.date)}compareTo(e){return se(this.date,e.date)}isSameDayAs(e){return Pe(this.date,e.date)}startOfDay(){return new e(Ue(this.date))}endOfDay(){return new e(ge(this.date))}startOfWeek(){return new e(Ge(this.date))}endOfWeek(){return new e(ve(this.date))}startOfMonth(){return new e(We(this.date))}endOfMonth(){return new e(_e(this.date))}startOfYear(){return new e(Ke(this.date))}endOfYear(){return new e(ye(this.date))}get dayOfMonth(){return Ce(this.date)}get dayOfWeek(){return we(this.date)}get month(){return De(this.date)}get year(){return Ae(this.date)}get hours(){return Te(this.date)}get minutes(){return Ee(this.date)}get seconds(){return Oe(this.date)}settingDayOfMonth(t){return new e(Ie(this.date,t))}settingDayOfWeek(t){return new e(Le(this.date,t))}settingMonth(t){return new e(Be(this.date,t))}settingYear(t){return new e(He(this.date,t))}settingHours(t){return new e(Re(this.date,t))}settingMinutes(t){return new e(ze(this.date,t))}settingSeconds(t){return new e(Ve(this.date,t))}};let an=function(e){return e.ISO_DATE=`yyyy-MM-dd`,e.ISO_DATETIME=`yyyy-MM-dd'T'HH:mm:ssXXX`,e.MM_DD_YYYY=`MM/dd/yyyy`,e.FULL_MONTH_DAY_YEAR=`MMMM d, yyyy`,e.ABBR_MONTH_DAY_YEAR=`MMM d, yyyy`,e.RFC_3339=`yyyy-MM-dd'T'HH:mm:ss.SSSxxx`,e.ALT_RSS=`d MMM yyyy HH:mm:ss ZZZ`,e.RSS=`EEE, d MMM yyyy HH:mm:ss ZZZ`,e.HTTP_HEADER=`EEE, dd MMM yyyy HH:mm:ss zzz`,e.STANDARD=`EEE MMM dd HH:mm:ss Z yyyy`,e.EXTENDED=`eee dd-MMM-yyyy GG HH:mm:ss.SSS zzz`,e}({});var on=class e{utc;timeZone;constructor(e,t){this.timeZone=e,this.utc=t??new Date}static fromUtc(t,n){return new e(n,t)}static fromLocalIso(t,n){let r=rt(t,n);return new e(n,r)}format(e,t){return nt(this.utc,this.timeZone,e,t)}toLocalIsoMinutes(e){return this.format(`yyyy-MM-dd'T'HH:mm`,e)}toLocalIsoSeconds(e){return this.format(`yyyy-MM-dd'T'HH:mm:ss`,e)}toISOString(){return this.utc.toISOString()}toUnixTimestamp(){return Math.floor(this.utc.getTime()/1e3)}toZonedDate(){return at(this.utc,this.timeZone)}timezoneOffsetMs(e){return it(this.timeZone,e??this.utc)}},sn=class{value;constructor([e,t]){if(e<-180||e>180)throw Error(`Longitude must be between -180 and 180.`);if(t<-90||t>90)throw Error(`Latitude must be between -90 and 90.`);this.value=[e,t]}get longitude(){return this.value[0]}get latitude(){return this.value[1]}toJSON(){return this.value}},cn=class{type=`Point`;coordinates;bbox;constructor(e,t){this.coordinates=e,this.bbox=t}toJSON(){return{type:this.type,coordinates:this.coordinates.toJSON(),...this.bbox&&{bbox:this.bbox}}}},ln=class{type=`MultiPoint`;coordinates;bbox;constructor(e,t){this.coordinates=e,this.bbox=t}toJSON(){return{type:this.type,coordinates:this.coordinates.map(e=>e.toJSON()),...this.bbox&&{bbox:this.bbox}}}},un=class{type=`LineString`;coordinates;bbox;constructor(e,t){this.coordinates=e,this.bbox=t}toJSON(){return{type:this.type,coordinates:this.coordinates.map(e=>e.toJSON()),...this.bbox&&{bbox:this.bbox}}}},dn=class{type=`MultiLineString`;coordinates;bbox;constructor(e,t){this.coordinates=e,this.bbox=t}toJSON(){return{type:this.type,coordinates:this.coordinates.map(e=>e.map(e=>e.toJSON())),...this.bbox&&{bbox:this.bbox}}}},fn=class{type=`Polygon`;coordinates;bbox;constructor(e,t){this.coordinates=e,this.bbox=t}toJSON(){return{type:this.type,coordinates:this.coordinates.map(e=>e.map(e=>e.toJSON())),...this.bbox&&{bbox:this.bbox}}}},pn=class{type=`MultiPolygon`;coordinates;bbox;constructor(e,t){this.coordinates=e,this.bbox=t}toJSON(){return{type:this.type,coordinates:this.coordinates.map(e=>e.map(e=>e.map(e=>e.toJSON()))),...this.bbox&&{bbox:this.bbox}}}};let mn=function(e){return e.Point=`Point`,e.MultiPoint=`MultiPoint`,e.LineString=`LineString`,e.MultiLineString=`MultiLineString`,e.Polygon=`Polygon`,e.MultiPolygon=`MultiPolygon`,e}({});function hn(e){return Error(`Invalid ObjectId value: ${String(e)}`)}var gn=class e{value;constructor(e){if(e==null)throw hn(e);let t=e.trim();if(t.length===0)throw hn(e);this.value=t,Object.freeze(this)}get asString(){return this.value}equals(t){return this.value===e.from(t).value}compare(t){let n=e.from(t).value;return this.value===n?0:this.value<n?-1:1}hash(){return this.value}toJSON(){return this.value}toString(){return this.value}[Symbol.toPrimitive](){return this.value}static from(t){return t instanceof e?t:new e(t)}static isValid(e){return typeof e==`string`&&e.trim().length>0}static toValueSet(t){let n=new Set;for(let r of t)n.add(e.from(r).value);return n}},_n=class{day;intervals;constructor(e,t){this.day=e,this.intervals=t}toJSON(){return Y({day:this.day,intervals:this.intervals},{filterNull:!0,filterUndefined:!0,filterEmptyString:!0})}},vn=class{_milliseconds;_long;constructor(e,t){if(this._long=t?.long===!0,e==null)throw Error(`Invalid interval format: ${e}`);if(typeof e==`number`)this._milliseconds=e;else{let t=m(e);if(t===void 0)throw Error(`Invalid interval format: ${e}`);this._milliseconds=t}}get milliseconds(){return this._milliseconds}get seconds(){return Math.floor(this._milliseconds/1e3)}get minutes(){return Math.floor(this._milliseconds/6e4)}get hours(){return Math.floor(this._milliseconds/36e5)}get days(){return Math.floor(this._milliseconds/864e5)}get weeks(){return Math.floor(this._milliseconds/6048e5)}get formatted(){return m(this._milliseconds,{long:this._long})}toString(){return m(this._milliseconds,{long:this._long})}toObject(){return{milliseconds:this._milliseconds,seconds:this.seconds,minutes:this.minutes,hours:this.hours,days:this.days,weeks:this.weeks}}};let yn=function(e){return e.Byte=`B`,e.Kilobyte=`KB`,e.Megabyte=`MB`,e.Gigabyte=`GB`,e.Terabyte=`TB`,e}({}),bn=function(e){return e.Millimeter=`mm`,e.Centimeter=`cm`,e.Meter=`m`,e.Kilometer=`km`,e}({}),xn=function(e){return e.Milligram=`mg`,e.Gram=`g`,e.Kilogram=`kg`,e.Tonne=`t`,e}({});b(v({Address:()=>$t,ByteUnit:()=>yn,Contacts:()=>en,Coordinates:()=>sn,DateFormat:()=>an,DateTime:()=>rn,DistanceUnit:()=>bn,GeoJsonType:()=>mn,LineString:()=>un,MultiLineString:()=>dn,MultiPoint:()=>ln,MultiPolygon:()=>pn,ObjectId:()=>gn,OpeningHour:()=>_n,Point:()=>cn,Polygon:()=>fn,TimeInterval:()=>vn,WeightUnit:()=>xn,ZonedDateTime:()=>on}),tn);function Sn(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let Q=class{formatBytes(e,t){let{inputUnit:n=`B`,outputUnit:r=`auto`,decimals:i=1}=t??{},a=e=>e===`B`?1:e===`KB`?1024:e===`MB`?1048576:e===`GB`?1073741824:1099511627776,o=e*a(n),s=r===`auto`?(()=>{for(let e of[`TB`,`GB`,`MB`,`KB`])if(o/a(e)>=1)return e;return`B`})():r,c=o/a(s),l=10**i;return{value:Math.round(c*l)/l,unit:s,bytes:o}}};Q=Sn([u()],Q);var Cn=class{assemble(e){e.bind(J.DI.Formatter.UnitController).to(Q)}};function wn(){return[new Cn]}let Tn=function(e){return e.Critical=`CRITICAL`,e.Serious=`SERIOUS`,e.Important=`IMPORTANT`,e.Notice=`NOTICE`,e.Routine=`ROUTINE`,e}({});var En=class{options;instance;constructor(e){this.options=e,this.instance=this.makeInstance()}info(e,t){this.log(`info`,e,t)}debug(e,t){this.log(`debug`,e,t)}trace(e,t){this.log(`trace`,e,t)}warn(e,t){this.log(`warn`,e,t)}error(e,t){this.log(`error`,e,t)}fatal(e,t){this.log(`fatal`,e,t)}child(e){return this.instance.child(e)}log(e,t,n){this.instance[e]({msg:t,...this.formatLogOptions(n)})}formatLogOptions(e){return e?this.normalizeObject({flag:e.flag,details:this.formatUnknown(e.details),error:this.formatUnknown(e.error),metadata:this.formatUnknown(e.metadata)}):{}}formatUnknown(e){if(Xt(e)){let t={type:e.constructor.name,message:e.message};this.options.debug&&e.stack&&(t.stack=e.stack);for(let[n,r]of Object.entries(e))n in t||(t[n]=r);let n=this.normalizeObject(t);return Z(n)?void 0:n}if(Buffer.isBuffer(e))return`[Buffer]`;if(e&&typeof e.pipe==`function`)return`[Stream]`;if(X(e))try{let t=JSON.stringify(e);if(t===void 0)return;let n=JSON.parse(t);if(Array.isArray(n))return n.length>0?n:void 0;if(X(n)){let e=this.normalizeObject(n);return Z(e)?void 0:e}return n}catch{return{type:`NonSerializableObject`}}return Qt(e)?e:String(e)}normalizeObject(e){return Y(Object.fromEntries(Object.entries(e)),{filterNull:!0,filterUndefined:!0,filterEmptyString:!0,filterEmptyArray:!0,filterEmptyObject:!0})}makeInstance(){if(!this.options.enabled)return h({enabled:!1,timestamp:!0});let e=this.options.transports,t={level:this.makeGlobalLogLevel(e),enabled:!0,timestamp:!0,transport:{targets:this.makeTransportTargets(e)}};return h(t)}makeTransportTargets(e){if(e.filter(e=>e.type===`console`).length>1)throw Error(`[Logger] Multiple console transports are not supported.`);return e.map(e=>{switch(e.type){case`console`:return this.makeConsoleTransportTarget(e);case`file`:return this.makeFileTransportTarget(e)}})}makeConsoleTransportTarget(e){return{target:`pino-pretty`,level:this.makeTransportLevel(e.level),options:e.pretty}}makeFileTransportTarget(e){let t=this.makeTransportLevel(e.level),n=a.isAbsolute(e.path)?a.normalize(e.path):j(process.cwd(),e.path);return M(a.dirname(n)),{target:`pino/file`,level:t,options:{destination:n}}}makeTransportLevel(e){return this.options.debug?`trace`:e??`info`}makeGlobalLogLevel(e){if(this.options.debug)return`trace`;let t=e.at(0);if(!t)return`info`;let n={trace:0,debug:1,info:2,warn:3,error:4,fatal:5},r=this.makeTransportLevel(t.level);for(let t of e.slice(1)){let e=this.makeTransportLevel(t.level);n[e]<n[r]&&(r=e)}return r}},Dn=class{options;constructor(e){this.options=e}assemble(e){e.bind(J.DI.Logger).toConstantValue(new En(this.options))}};function On(e={}){let t=e.logger??{enabled:!1};return[...wn(),new Dn(t)]}const kn=g.string().trim().min(1).transform(e=>{let{prefix:t,base:n}=An(e),r=jn(n);return{original:e,prefix:t,base:n,kebab:Mn(r),snake:Nn(r),camel:Pn(r),pascal:Fn(r)}}),$=g.looseObject({name:kn,version:g.string().trim().min(1),private:g.boolean().optional(),type:g.enum([`module`,`commonjs`]).optional(),dependencies:g.record(g.string(),g.string()).default({}),peerDependencies:g.record(g.string(),g.string()).default({}),devDependencies:g.record(g.string(),g.string()).default({})});function An(e){let t=/^@([^/]+)\/(.+)$/.exec(e);return t&&t[2]?{prefix:t[1],base:t[2]}:{base:e}}function jn(e){let t=e.replace(/([a-z0-9])([A-Z])/g,`$1 $2`).replace(/[^a-zA-Z0-9]+/g,` `).trim().toLowerCase();return t?t.split(/\s+/):[]}function Mn(e){return e.join(`-`)}function Nn(e){return e.join(`_`)}function Pn(e){if(e.length===0)return``;let[t,...n]=e;return t+n.map(In).join(``)}function Fn(e){return e.map(In).join(``)}function In(e){return e.length===0?``:e.charAt(0).toUpperCase()+e.slice(1)}function Ln(e){let t,n;try{t=r.readFileSync(e,`utf8`)}catch(t){throw Error(`Failed to read package.json at ${e}`,{cause:t})}try{n=JSON.parse(t)}catch(t){throw Error(`Failed to parse package.json at ${e}`,{cause:t})}try{return $.parse(n)}catch(t){throw Error(`Invalid package.json at ${e}`,{cause:t})}}export{bt as Console,Wt as ENVIRONMENT_CONFIG_FILE,Tn as LogFlag,En as LoggerImpl,$ as PackageJSONSchema,kn as PackageNameSchema,On as coreNodeAssembly,kt as createDirectory,Nt as createDirectoryAsync,At as createFile,Pt as createFileAsync,wt as defineConfig,Ct as defineConfiguration,It as defineEnvironments,zt as defineSource,M as ensureDirectory,N as ensureDirectoryAsync,St as field,Tt as isConfigDefinition,k as isConfigurationBinding,Dt as isConfigurationContract,Et as isConfigurationField,I as isConfigurationSource,Gt as loadConfig,Ln as loadPackageJSON,lt as makeDependencyBundlingPolicy,Ot as removePath,Mt as removePathAsync,Bt as resolveConfig,R as resolveConfiguration,z as resolveConfigurationBinding,P as resolveEnvironment,j as resolvePath};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@buildplease/core",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"keywords": [],
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -47,11 +47,13 @@
|
|
|
47
47
|
"resources"
|
|
48
48
|
],
|
|
49
49
|
"dependencies": {
|
|
50
|
+
"@dotenvx/dotenvx": "2.21.0",
|
|
50
51
|
"async-mutex": "0.5.0",
|
|
51
52
|
"bcryptjs": "3.0.3",
|
|
52
53
|
"consola": "3.4.2",
|
|
53
54
|
"date-fns": "4.4.0",
|
|
54
55
|
"date-fns-tz": "3.2.0",
|
|
56
|
+
"jiti": "2.7.0",
|
|
55
57
|
"ms": "2.1.3",
|
|
56
58
|
"pino": "10.3.1",
|
|
57
59
|
"pino-pretty": "13.1.3"
|