@xrystal/core 3.38.1 → 3.38.3

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.
Files changed (56) hide show
  1. package/README.md +251 -2146
  2. package/package.json +3 -3
  3. package/x/bin/helpers/.generated/tmp-schema.mjs +8 -1
  4. package/x/bin/helpers/build-config.mjs +2 -0
  5. package/x/bin/helpers/defaults.json +44 -0
  6. package/x/bin/helpers/package-defaults.mjs +21 -0
  7. package/x/bin/helpers/project-artifacts.mjs +14 -1
  8. package/x/bin/paths.mjs +1 -1
  9. package/x/bin/scripts/clean-dist-tests.mjs +50 -0
  10. package/x/bin/scripts/fix-dist-imports.mjs +11 -2
  11. package/x/bin/scripts/sync-cli-defaults.mjs +16 -0
  12. package/x/dist/loader/clients/index.js +1 -1
  13. package/x/dist/loader/configs/index.js +1 -1
  14. package/x/dist/loader/controller/index.js +1 -1
  15. package/x/dist/loader/dto/index.js +1 -1
  16. package/x/dist/loader/events/index.js +1 -1
  17. package/x/dist/loader/index.js +1 -1
  18. package/x/dist/loader/kafka/index.js +1 -1
  19. package/x/dist/loader/localizations/index.js +1 -1
  20. package/x/dist/loader/logger/index.js +1 -1
  21. package/x/dist/loader/system/index.js +1 -1
  22. package/x/dist/project/index.js +1 -1
  23. package/x/dist/utils/constants/index.js +1 -1
  24. package/x/dist/utils/helpers/context/index.js +1 -1
  25. package/x/dist/utils/helpers/core/index.js +1 -1
  26. package/x/dist/utils/helpers/core/tmp-layout.js +1 -1
  27. package/x/dist/utils/helpers/date/index.js +1 -1
  28. package/x/dist/utils/helpers/dispatch/index.js +1 -1
  29. package/x/dist/utils/helpers/framework/index.js +1 -1
  30. package/x/dist/utils/helpers/handlers/adapters.js +1 -1
  31. package/x/dist/utils/helpers/handlers/execute.js +1 -1
  32. package/x/dist/utils/helpers/handlers/index.js +1 -1
  33. package/x/dist/utils/helpers/index.js +1 -1
  34. package/x/dist/utils/helpers/middleware/index.js +1 -1
  35. package/x/dist/utils/helpers/protocol/index.js +1 -1
  36. package/x/dist/utils/helpers/protocol/options.js +1 -1
  37. package/x/dist/utils/helpers/runtime/dto-access.js +1 -1
  38. package/x/dist/utils/helpers/runtime/index.js +1 -1
  39. package/x/dist/utils/helpers/runtime/shutdown.js +1 -1
  40. package/x/dist/utils/helpers/state/index.js +1 -1
  41. package/x/dist/utils/helpers/state/props-from-tmp.js +1 -1
  42. package/x/dist/utils/helpers/state/request-key-guard.js +1 -1
  43. package/x/dist/utils/helpers/state/scopes.js +1 -1
  44. package/x/dist/utils/helpers/tmp/index.js +1 -1
  45. package/x/dist/utils/helpers/tmp/loader-tmp-sync.js +1 -1
  46. package/x/dist/utils/helpers/tmp/tmp-loader.js +1 -1
  47. package/x/dist/utils/helpers/tmp/tmp-schema.js +1 -1
  48. package/x/dist/utils/helpers/tmp/tmp-watch.js +1 -1
  49. package/x/dist/utils/index.js +1 -1
  50. package/x/dist/utils/models/classes/class.clients.js +1 -1
  51. package/x/dist/utils/models/classes/class.tmp-file-loader.js +1 -1
  52. package/x/dist/utils/models/index.js +1 -1
  53. package/x/dist/utils/helpers/tests/tmp-schema.test.d.ts +0 -1
  54. package/x/dist/utils/helpers/tests/tmp-schema.test.js +0 -1
  55. package/x/dist/utils/helpers/tests/tmp-watch.test.d.ts +0 -1
  56. package/x/dist/utils/helpers/tests/tmp-watch.test.js +0 -1
@@ -1 +1 @@
1
- import{createStore as w}from"zustand/vanilla";import{subscribeWithSelector as I}from"zustand/middleware";import{GStoreScopeEnum as Z}from"../../../utils/models/enums/index.js";import{propsFromTmp,resolveGStoreBoot,G_PROP_NOT_ALLOWED}from"../../../utils/helpers/state/props-from-tmp.js";import{warnIfRequestScopedKey as Q,G_REQUEST_KEY_WARN,looksLikeRequestScopedKey}from"../../../utils/helpers/state/request-key-guard.js";import{buildStoresSnapshot as U,patchControllerScope as Y,patchRunScope as q}from"../../../utils/helpers/state/scopes.js";export{propsFromTmp,resolveGStoreBoot,G_PROP_NOT_ALLOWED,G_REQUEST_KEY_WARN,looksLikeRequestScopedKey};export{GStoreScopeEnum}from"../../../utils/models/enums/index.js";export{buildStoresSnapshot,summarizeController,runContextValues,patchControllerScope,patchRunScope}from"../../../utils/helpers/state/scopes.js";const V=(j)=>JSON.parse(JSON.stringify(j));function $(j,z){const H=new Set([...Object.keys(j),...Object.keys(z)]),M=[];for(const J of H)if(j[J]!==z[J])M.push({key:J,value:z[J],prev:j[J]});return M}class GStoreFacade{store;baseline={};allowedKeys=new Set;allowAutoCreateProps=!0;warnOnRequestKeys=!0;constructor(){this.store=w(I(()=>({})))}configureFromTmp(j={}){const z=resolveGStoreBoot(j);this.allowAutoCreateProps=z.allowAutoCreateProps;this.warnOnRequestKeys=z.warnOnRequestKeys;this.allowedKeys=new Set(Object.keys(z.vars));const H=V(z.bootstrap?z.vars:{});this.store.setState(H,!0);this.baseline=V(H);return this}allowsAutoCreateProps(){return this.allowAutoCreateProps}declaredKeys(){return[...this.allowedKeys]}guardRequestKey(j){Q(j,this.warnOnRequestKeys)}assertPropAllowed(j){if(this.allowAutoCreateProps)return;if(!this.allowedKeys.has(j))throw Error(`${G_PROP_NOT_ALLOWED}: ${j}`)}registerAllowedKeys(j){for(const z of j)this.allowedKeys.add(z)}getState(){return this.store.getState()}select(j){return j(this.getState())}get(j,z){const H=this.getState();if(!(j in H))return z;return H[j]}set(j,z){this.guardRequestKey(j);this.assertPropAllowed(j);const H=this.getState();if(H[j]===z)return this;this.store.setState({...H,[j]:z});return this}merge(j){for(const M of Object.keys(j)){this.guardRequestKey(M);this.assertPropAllowed(M)}const z=this.getState();if(!$(z,{...z,...j}).length)return this;this.store.setState({...z,...j});return this}has(j){return j in this.getState()}remove(...j){const H={...this.getState()};let M=!1;for(const J of j)if(J in H){delete H[J];M=!0}if(M)this.store.setState(H,!0);return this}keys(){return Object.keys(this.getState())}entries(){return Object.entries(this.getState())}snapshot(){return{...this.getState()}}subscribe(j){return this.store.subscribe((z,H)=>j(z,H,$(H,z)))}subscribeKey(j,z){return this.store.subscribe((H)=>H[j],(H,M)=>z(H,M,{key:j,value:H,prev:M}))}bootstrap(j){if(!this.allowAutoCreateProps)for(const z of Object.keys(j))this.assertPropAllowed(z);else this.registerAllowedKeys(Object.keys(j));this.merge(j);this.baseline=V(this.getState());return this}reset(){this.store.setState(V(this.baseline),!0)}stores(){return U(this.snapshot())}list(){return Object.values(this.stores())}scope(j){const H=this.stores()[j],M={name:j,active:H.active,keys:()=>H.keys,get(J,X){if(!H.values||!(J in H.values))return X;return H.values[J]}};if(j===Z.GLOBAL)return{...M,set:(J,X)=>{this.set(J,X);return!0},merge:(J)=>{this.merge(J);return!0}};if(j===Z.RUN)return{...M,patch:(J)=>q(J)};return{...M,patch:(J)=>Y(J)}}}export{GStoreFacade};export const G=new GStoreFacade;
1
+ import{createStore as w}from"zustand/vanilla";import{subscribeWithSelector as I}from"zustand/middleware";import{GStoreScopeEnum as Z}from"../../../utils/models/enums";import{propsFromTmp,resolveGStoreBoot,G_PROP_NOT_ALLOWED}from"../../../utils/helpers/state/props-from-tmp";import{warnIfRequestScopedKey as Q,G_REQUEST_KEY_WARN,looksLikeRequestScopedKey}from"../../../utils/helpers/state/request-key-guard";import{buildStoresSnapshot as U,patchControllerScope as Y,patchRunScope as q}from"../../../utils/helpers/state/scopes";export{propsFromTmp,resolveGStoreBoot,G_PROP_NOT_ALLOWED,G_REQUEST_KEY_WARN,looksLikeRequestScopedKey};export{GStoreScopeEnum}from"../../../utils/models/enums";export{buildStoresSnapshot,summarizeController,runContextValues,patchControllerScope,patchRunScope}from"../../../utils/helpers/state/scopes";const V=(j)=>JSON.parse(JSON.stringify(j));function $(j,z){const H=new Set([...Object.keys(j),...Object.keys(z)]),M=[];for(const J of H)if(j[J]!==z[J])M.push({key:J,value:z[J],prev:j[J]});return M}class GStoreFacade{store;baseline={};allowedKeys=new Set;allowAutoCreateProps=!0;warnOnRequestKeys=!0;constructor(){this.store=w(I(()=>({})))}configureFromTmp(j={}){const z=resolveGStoreBoot(j);this.allowAutoCreateProps=z.allowAutoCreateProps;this.warnOnRequestKeys=z.warnOnRequestKeys;this.allowedKeys=new Set(Object.keys(z.vars));const H=V(z.bootstrap?z.vars:{});this.store.setState(H,!0);this.baseline=V(H);return this}allowsAutoCreateProps(){return this.allowAutoCreateProps}declaredKeys(){return[...this.allowedKeys]}guardRequestKey(j){Q(j,this.warnOnRequestKeys)}assertPropAllowed(j){if(this.allowAutoCreateProps)return;if(!this.allowedKeys.has(j))throw Error(`${G_PROP_NOT_ALLOWED}: ${j}`)}registerAllowedKeys(j){for(const z of j)this.allowedKeys.add(z)}getState(){return this.store.getState()}select(j){return j(this.getState())}get(j,z){const H=this.getState();if(!(j in H))return z;return H[j]}set(j,z){this.guardRequestKey(j);this.assertPropAllowed(j);const H=this.getState();if(H[j]===z)return this;this.store.setState({...H,[j]:z});return this}merge(j){for(const M of Object.keys(j)){this.guardRequestKey(M);this.assertPropAllowed(M)}const z=this.getState();if(!$(z,{...z,...j}).length)return this;this.store.setState({...z,...j});return this}has(j){return j in this.getState()}remove(...j){const H={...this.getState()};let M=!1;for(const J of j)if(J in H){delete H[J];M=!0}if(M)this.store.setState(H,!0);return this}keys(){return Object.keys(this.getState())}entries(){return Object.entries(this.getState())}snapshot(){return{...this.getState()}}subscribe(j){return this.store.subscribe((z,H)=>j(z,H,$(H,z)))}subscribeKey(j,z){return this.store.subscribe((H)=>H[j],(H,M)=>z(H,M,{key:j,value:H,prev:M}))}bootstrap(j){if(!this.allowAutoCreateProps)for(const z of Object.keys(j))this.assertPropAllowed(z);else this.registerAllowedKeys(Object.keys(j));this.merge(j);this.baseline=V(this.getState());return this}reset(){this.store.setState(V(this.baseline),!0)}stores(){return U(this.snapshot())}list(){return Object.values(this.stores())}scope(j){const H=this.stores()[j],M={name:j,active:H.active,keys:()=>H.keys,get(J,X){if(!H.values||!(J in H.values))return X;return H.values[J]}};if(j===Z.GLOBAL)return{...M,set:(J,X)=>{this.set(J,X);return!0},merge:(J)=>{this.merge(J);return!0}};if(j===Z.RUN)return{...M,patch:(J)=>q(J)};return{...M,patch:(J)=>Y(J)}}}export{GStoreFacade};export const G=new GStoreFacade;
@@ -1 +1 @@
1
- import{readTmpServiceBlock as I}from"../../../utils/helpers/tmp/tmp-schema.js";export const G_PROP_NOT_ALLOWED="[xrystal] G prop not declared in tmp.yml vars — set autoCreateProps: true to allow runtime keys";const F=()=>({});function J(j){return I(j).loaders?.system?.gStore}function L(j){if(typeof j.bootstrap==="boolean")return j.bootstrap;return!0}function M(j){if(typeof j.autoCreateProps==="boolean")return j.autoCreateProps;return!0}function Q(j){if(typeof j.warnOnRequestKeys==="boolean")return j.warnOnRequestKeys;return!0}export function resolveGStoreBoot(j={}){const x=j.configs??j,z=J(x);if(!z)return{bootstrap:!0,allowAutoCreateProps:!0,warnOnRequestKeys:!0,vars:F()};const E=z.options??{},D=z.vars,H=D&&typeof D==="object"&&!Array.isArray(D)?{...D}:F();return{bootstrap:L(E),allowAutoCreateProps:M(E),warnOnRequestKeys:Q(E),vars:H}}export function propsFromTmp(j={}){const x=resolveGStoreBoot(j);return x.bootstrap?x.vars:F()}
1
+ import{readTmpServiceBlock as I}from"../../../utils/helpers/tmp/tmp-schema";export const G_PROP_NOT_ALLOWED="[xrystal] G prop not declared in tmp.yml vars — set autoCreateProps: true to allow runtime keys";const F=()=>({});function J(j){return I(j).loaders?.system?.gStore}function L(j){if(typeof j.bootstrap==="boolean")return j.bootstrap;return!0}function M(j){if(typeof j.autoCreateProps==="boolean")return j.autoCreateProps;return!0}function Q(j){if(typeof j.warnOnRequestKeys==="boolean")return j.warnOnRequestKeys;return!0}export function resolveGStoreBoot(j={}){const x=j.configs??j,z=J(x);if(!z)return{bootstrap:!0,allowAutoCreateProps:!0,warnOnRequestKeys:!0,vars:F()};const E=z.options??{},D=z.vars,H=D&&typeof D==="object"&&!Array.isArray(D)?{...D}:F();return{bootstrap:L(E),allowAutoCreateProps:M(E),warnOnRequestKeys:Q(E),vars:H}}export function propsFromTmp(j={}){const x=resolveGStoreBoot(j);return x.bootstrap?x.vars:F()}
@@ -1 +1 @@
1
- import{getRunContext as B}from"../../../utils/helpers/context/index.js";import{getControllerCtx as D}from"../../../utils/helpers/context/controller-store.js";export const G_REQUEST_KEY_WARN="[xrystal] G: key looks request-scoped — use run/controller context, not global G";const F=new Set(["requestid","reqid","correlationid","cookies","cookie","headers","header","body","query","queries","params","locals","session","sessionid"]);export function looksLikeRequestScopedKey(j){const z=j.trim();if(!z)return!1;const f=z.toLowerCase();if(F.has(f))return!0;if(f.endsWith("requestid")||f.endsWith("correlationid"))return!0;if(f==="req"||f==="res")return!0;return!1}export function warnIfRequestScopedKey(j,z){if(!z||!looksLikeRequestScopedKey(j))return;const f=B()?"run":D()?"controller":"outside-request";console.warn(`${G_REQUEST_KEY_WARN} (key: ${j}, scope: ${f})`)}
1
+ import{getRunContext as B}from"../../../utils/helpers/context";import{getControllerCtx as D}from"../../../utils/helpers/context/controller-store";export const G_REQUEST_KEY_WARN="[xrystal] G: key looks request-scoped — use run/controller context, not global G";const F=new Set(["requestid","reqid","correlationid","cookies","cookie","headers","header","body","query","queries","params","locals","session","sessionid"]);export function looksLikeRequestScopedKey(j){const z=j.trim();if(!z)return!1;const f=z.toLowerCase();if(F.has(f))return!0;if(f.endsWith("requestid")||f.endsWith("correlationid"))return!0;if(f==="req"||f==="res")return!0;return!1}export function warnIfRequestScopedKey(j,z){if(!z||!looksLikeRequestScopedKey(j))return;const f=B()?"run":D()?"controller":"outside-request";console.warn(`${G_REQUEST_KEY_WARN} (key: ${j}, scope: ${f})`)}
@@ -1 +1 @@
1
- import{GStoreScopeEnum as j}from"../../../utils/models/enums/index.js";import{getRunContext as q,patchRunContext as w}from"../../../utils/helpers/context/index.js";import{getControllerCtx as v}from"../../../utils/helpers/context/controller-store.js";export function summarizeController(d){if(!d)return null;return{protocol:d.protocol,framework:d.framework,requestId:d.requestId,metadata:d.metadata,hasReq:!!d.req,hasRes:!!d.res,hasSocket:!!d.socket}}export function runContextValues(d){if(!d)return null;return{...d}}export function buildStoresSnapshot(d){const f=q(),k=summarizeController(v());return{[j.GLOBAL]:{name:j.GLOBAL,active:!0,keys:Object.keys(d),values:{...d}},[j.RUN]:{name:j.RUN,active:!!f,keys:f?Object.keys(f):[],values:runContextValues(f)},[j.CONTROLLER]:{name:j.CONTROLLER,active:!!k,keys:k?Object.keys(k):[],values:k}}}export function patchControllerScope(d){const f=v();if(!f)return!1;if(d.requestId!==void 0)f.requestId=d.requestId;if(d.metadata)f.metadata={...f.metadata,...d.metadata,locals:{...f.metadata?.locals??{},...d.metadata.locals??{}}};return!0}export function patchRunScope(d){if(!q())return!1;w(d);return!0}
1
+ import{GStoreScopeEnum as j}from"../../../utils/models/enums";import{getRunContext as q,patchRunContext as w}from"../../../utils/helpers/context";import{getControllerCtx as v}from"../../../utils/helpers/context/controller-store";export function summarizeController(d){if(!d)return null;return{protocol:d.protocol,framework:d.framework,requestId:d.requestId,metadata:d.metadata,hasReq:!!d.req,hasRes:!!d.res,hasSocket:!!d.socket}}export function runContextValues(d){if(!d)return null;return{...d}}export function buildStoresSnapshot(d){const f=q(),k=summarizeController(v());return{[j.GLOBAL]:{name:j.GLOBAL,active:!0,keys:Object.keys(d),values:{...d}},[j.RUN]:{name:j.RUN,active:!!f,keys:f?Object.keys(f):[],values:runContextValues(f)},[j.CONTROLLER]:{name:j.CONTROLLER,active:!!k,keys:k?Object.keys(k):[],values:k}}}export function patchControllerScope(d){const f=v();if(!f)return!1;if(d.requestId!==void 0)f.requestId=d.requestId;if(d.metadata)f.metadata={...f.metadata,...d.metadata,locals:{...f.metadata?.locals??{},...d.metadata.locals??{}}};return!0}export function patchRunScope(d){if(!q())return!1;w(d);return!0}
@@ -1 +1 @@
1
- export{setRuntimeTmpConfigs,getRuntimeTmpConfigs,onRuntimeTmpChange,notifyRuntimeTmpChange,clearRuntimeTmpConfigs}from"../../../utils/helpers/tmp/runtime-tmp.js";export{getTmpLoader,getTmpLoaderPath,getTmpSnapshot,onTmpReload,resetTmpLoaderForTests,stopTmpLoader}from"../../../utils/helpers/tmp/tmp-loader.js";export{bindLoaderTmpSync}from"../../../utils/helpers/tmp/loader-tmp-sync.js";export{resolveTmpWatchIntervalMs}from"../../../utils/helpers/tmp/tmp-watch.js";export{normalizeTmpDocument,normalizeRootFolder,normalizeSourceFolder,readTmpCoreBlock,readTmpServiceBlock,resolveServiceLayoutPaths,resolveTmpRuntimeConfigs}from"../../../utils/helpers/tmp/tmp-schema.js";
1
+ export{setRuntimeTmpConfigs,getRuntimeTmpConfigs,onRuntimeTmpChange,notifyRuntimeTmpChange,clearRuntimeTmpConfigs}from"../../../utils/helpers/tmp/runtime-tmp";export{getTmpLoader,getTmpLoaderPath,getTmpSnapshot,onTmpReload,resetTmpLoaderForTests,stopTmpLoader}from"../../../utils/helpers/tmp/tmp-loader";export{bindLoaderTmpSync}from"../../../utils/helpers/tmp/loader-tmp-sync";export{resolveTmpWatchIntervalMs}from"../../../utils/helpers/tmp/tmp-watch";export{normalizeTmpDocument,normalizeRootFolder,normalizeSourceFolder,readTmpCoreBlock,readTmpServiceBlock,resolveServiceLayoutPaths,resolveTmpRuntimeConfigs}from"../../../utils/helpers/tmp/tmp-schema";
@@ -1 +1 @@
1
- import{onRuntimeTmpChange as k}from"../../../utils/helpers/tmp/runtime-tmp.js";export function bindLoaderTmpSync(c){const f=c.constructor.name;k(async()=>{try{await c.syncFromTmp()}catch(b){const j=b instanceof Error?b.message:String(b);console.warn(`[xrystal] ${f} tmp reload failed: ${j}`)}})}
1
+ import{onRuntimeTmpChange as k}from"../../../utils/helpers/tmp/runtime-tmp";export function bindLoaderTmpSync(c){const f=c.constructor.name;k(async()=>{try{await c.syncFromTmp()}catch(b){const j=b instanceof Error?b.message:String(b);console.warn(`[xrystal] ${f} tmp reload failed: ${j}`)}})}
@@ -1 +1 @@
1
- import J from"node:fs";import K from"node:path";import{Constants as E}from"../../../utils/constants/index.js";import{assertCoreTmpGuard as M,coreCanonicalTmpPath as O,isCorePackageRoot as Q}from"../../../utils/helpers/core/tmp-layout.js";import{findFileRecursively as U}from"../../../utils/helpers/core/paths.js";import{TmpFileLoader as V}from"../../../utils/models/classes/class.tmp-file-loader.js";import{registerGracefulShutdown as W}from"../../../utils/helpers/runtime/shutdown.js";let q=null,A=null;function X(B=process.cwd(),j=E.tmpBaseName,b=E.tmpExtension){const z=K.resolve(B);if(Q(z)){const D=O(z);if(!J.existsSync(D))throw Error(`${E.packageRootFolder}/tmp.yml not found. Run xcore tmp or ensureCoreTmpEntry() before starting @xrystal/core`);M(z,D);return D}const H=U(z,j,b);if(!H)throw Error(`${j}${b.startsWith(".")?b:`.${b}`} file not found`);return H}export function getTmpLoaderPath(){if(!A)A=X();return A}export function getTmpLoader(){if(!q){q=new V({filePath:getTmpLoaderPath()});W()}return q}export function getTmpSnapshot(){return getTmpLoader().getResolvedTmpFile()}export function onTmpReload(B){const j=getTmpLoader(),b=()=>B(j.getResolvedTmpFile());j.on("reload",b);return()=>j.off("reload",b)}export function stopTmpLoader(){if(q){q.stop();q=null;A=null}}export function resetTmpLoaderForTests(){stopTmpLoader()}
1
+ import J from"node:fs";import K from"node:path";import{Constants as E}from"../../../utils/constants";import{assertCoreTmpGuard as M,coreCanonicalTmpPath as O,isCorePackageRoot as Q}from"../../../utils/helpers/core/tmp-layout";import{findFileRecursively as U}from"../../../utils/helpers/core/paths";import{TmpFileLoader as V}from"../../../utils/models/classes/class.tmp-file-loader";import{registerGracefulShutdown as W}from"../../../utils/helpers/runtime/shutdown";let q=null,A=null;function X(B=process.cwd(),j=E.tmpBaseName,b=E.tmpExtension){const z=K.resolve(B);if(Q(z)){const D=O(z);if(!J.existsSync(D))throw Error(`${E.packageRootFolder}/tmp.yml not found. Run xcore tmp or ensureCoreTmpEntry() before starting @xrystal/core`);M(z,D);return D}const H=U(z,j,b);if(!H)throw Error(`${j}${b.startsWith(".")?b:`.${b}`} file not found`);return H}export function getTmpLoaderPath(){if(!A)A=X();return A}export function getTmpLoader(){if(!q){q=new V({filePath:getTmpLoaderPath()});W()}return q}export function getTmpSnapshot(){return getTmpLoader().getResolvedTmpFile()}export function onTmpReload(B){const j=getTmpLoader(),b=()=>B(j.getResolvedTmpFile());j.on("reload",b);return()=>j.off("reload",b)}export function stopTmpLoader(){if(q){q.stop();q=null;A=null}}export function resetTmpLoaderForTests(){stopTmpLoader()}
@@ -1 +1 @@
1
- import{Constants as G}from"../../../utils/constants/index.js";function A(j){return typeof j==="object"&&j!==null&&!Array.isArray(j)}function M(j){if(typeof j==="number"||typeof j==="string")return j;return}export function normalizeRootFolder(j){if(!j?.trim())return G.packageRootFolder;return j.trim().replace(/^\.\/+/,"")}export function normalizeSourceFolder(j){if(!j?.trim())return G.mainSourceFolder;const q=j.trim();if(q.startsWith("./")||q.startsWith("../"))return q;return`./${q}`}export function readTmpCoreBlock(j){const q=A(j?.core)?j.core:{},x=A(q.tmp)?q.tmp:{};return{tmp:{fileWatchIntervalMs:M(x.fileWatchIntervalMs)}}}export function readTmpServiceBlock(j){const q=A(j?.service)?j.service:{},x=A(q.paths)?q.paths:{},D=A(x.special)?x.special:{};let E=A(q.loaders)?{...q.loaders}:void 0,H=A(q.build)?q.build:void 0;if(E&&A(E.build)){const{build:J,...K}=E;E=K;if(!H&&A(J))H=J}return{name:typeof q.name==="string"?q.name:void 0,framework:typeof q.framework==="string"?q.framework:void 0,paths:{root:typeof x.root==="string"?x.root:void 0,source:typeof x.source==="string"?x.source:void 0,special:{tests:typeof D.tests==="string"?D.tests:void 0,environments:typeof D.environments==="string"?D.environments:void 0,dist:typeof D.dist==="string"?D.dist:void 0}},protocols:q.protocols,loaders:E,build:H}}export function resolveServiceLayoutPaths(j){const q=j.paths?.special??{};return{tests:q.tests?.trim()||G.layoutPaths.tests,environments:q.environments?.trim()||G.layoutPaths.environments,dist:q.dist?.trim()||G.layoutPaths.dist}}function O(j){const q=resolveServiceLayoutPaths(j);return{name:j.name,framework:j.framework??"elysia",paths:{root:j.paths?.root??G.packageRootFolder,source:j.paths?.source??G.mainSourceFolder,special:q},protocols:j.protocols,loaders:j.loaders,build:j.build}}function Q(j){return{tmp:{fileWatchIntervalMs:j.tmp?.fileWatchIntervalMs}}}export function resolveTmpRuntimeConfigs(j){const q=A(j?.configs)?j.configs:{},x=readTmpServiceBlock(q),D=readTmpCoreBlock(q),E=O(x);return{service:E,core:Q(D),rootFolderPath:normalizeRootFolder(E.paths.root)}}export function normalizeTmpDocument(j){return{...j,configs:resolveTmpRuntimeConfigs(j)}}
1
+ import{Constants as G}from"../../../utils/constants";function A(j){return typeof j==="object"&&j!==null&&!Array.isArray(j)}function M(j){if(typeof j==="number"||typeof j==="string")return j;return}export function normalizeRootFolder(j){if(!j?.trim())return G.packageRootFolder;return j.trim().replace(/^\.\/+/,"")}export function normalizeSourceFolder(j){if(!j?.trim())return G.mainSourceFolder;const q=j.trim();if(q.startsWith("./")||q.startsWith("../"))return q;return`./${q}`}export function readTmpCoreBlock(j){const q=A(j?.core)?j.core:{},x=A(q.tmp)?q.tmp:{};return{tmp:{fileWatchIntervalMs:M(x.fileWatchIntervalMs)}}}export function readTmpServiceBlock(j){const q=A(j?.service)?j.service:{},x=A(q.paths)?q.paths:{},D=A(x.special)?x.special:{};let E=A(q.loaders)?{...q.loaders}:void 0,H=A(q.build)?q.build:void 0;if(E&&A(E.build)){const{build:J,...K}=E;E=K;if(!H&&A(J))H=J}return{name:typeof q.name==="string"?q.name:void 0,framework:typeof q.framework==="string"?q.framework:void 0,paths:{root:typeof x.root==="string"?x.root:void 0,source:typeof x.source==="string"?x.source:void 0,special:{tests:typeof D.tests==="string"?D.tests:void 0,environments:typeof D.environments==="string"?D.environments:void 0,dist:typeof D.dist==="string"?D.dist:void 0}},protocols:q.protocols,loaders:E,build:H}}export function resolveServiceLayoutPaths(j){const q=j.paths?.special??{};return{tests:q.tests?.trim()||G.layoutPaths.tests,environments:q.environments?.trim()||G.layoutPaths.environments,dist:q.dist?.trim()||G.layoutPaths.dist}}function O(j){const q=resolveServiceLayoutPaths(j);return{name:j.name,framework:j.framework??"elysia",paths:{root:j.paths?.root??G.packageRootFolder,source:j.paths?.source??G.mainSourceFolder,special:q},protocols:j.protocols,loaders:j.loaders,build:j.build}}function Q(j){return{tmp:{fileWatchIntervalMs:j.tmp?.fileWatchIntervalMs}}}export function resolveTmpRuntimeConfigs(j){const q=A(j?.configs)?j.configs:{},x=readTmpServiceBlock(q),D=readTmpCoreBlock(q),E=O(x);return{service:E,core:Q(D),rootFolderPath:normalizeRootFolder(E.paths.root)}}export function normalizeTmpDocument(j){return{...j,configs:resolveTmpRuntimeConfigs(j)}}
@@ -1 +1 @@
1
- import I from"../../../utils/constants/defaults.json" with { type: 'json' };import{readTmpCoreBlock as J}from"../../../utils/helpers/tmp/tmp-schema.js";const b=I.tmpWatchDefaults??{intervalMs:500,minIntervalMs:100,maxIntervalMs:1e4};export function resolveTmpWatchIntervalMs(q){const v=q?.configs,y=J(v).tmp?.fileWatchIntervalMs??b.intervalMs,j=Number(y);if(!Number.isFinite(j))return b.intervalMs;const z=b.minIntervalMs??100,G=b.maxIntervalMs??1e4;return Math.min(G,Math.max(z,Math.round(j)))}
1
+ import I from"../../../utils/constants/defaults.json" with { type: 'json' };import{readTmpCoreBlock as J}from"../../../utils/helpers/tmp/tmp-schema";const b=I.tmpWatchDefaults??{intervalMs:500,minIntervalMs:100,maxIntervalMs:1e4};export function resolveTmpWatchIntervalMs(q){const v=q?.configs,y=J(v).tmp?.fileWatchIntervalMs??b.intervalMs,j=Number(y);if(!Number.isFinite(j))return b.intervalMs;const z=b.minIntervalMs??100,G=b.maxIntervalMs??1e4;return Math.min(G,Math.max(z,Math.round(j)))}
@@ -1 +1 @@
1
- export*from"../utils/constants/index.js";export*from"../utils/helpers/index.js";export*from"../utils/models/index.js";
1
+ export*from"../utils/constants";export*from"../utils/helpers";export*from"../utils/models";
@@ -1 +1 @@
1
- import{createHash as k,createHmac as E}from"node:crypto";import{Configs as y,Logger as N}from"../../../loader/index.js";import{LoggerLayerEnum as x,x as b}from"../../../utils/index.js";import{getRequestId as D}from"../../../utils/helpers/context/index.js";export class ClientStore{static _store={};static get(t){return this._store[t]||{}}static set(t,e){this._store[t]={...this._store[t],...e}}}export class Client{logger=b.get(N);configs=b.get(y);clientName;baseURL;version=null;timeout=15000;debug;authConfigs;breaker={failures:0,lastFailure:0,state:"CLOSED",threshold:5,cooldown:30000};constructor({clientName:t,baseURL:e,version:r,timeout:i,auth:s,debug:n}){this.clientName=t;this.baseURL=e;this.version=r||null;this.authConfigs=s;this.timeout=i||15000;const c=Number(this.configs.all.debug)>=x.DEBUG;this.debug=n??c;if(s?.token)ClientStore.set(t,{accessToken:s.token})}resolvePath(t,e){return e.split(".").reduce((r,i)=>r?r[i]:void 0,t)}static cryptoHashGenerate=({algorithm:t,input:e,digest:r="hex"})=>{return k(t).update(e).digest(r)}}export class BaseApiClient extends Client{constructor(t){super(t)}async request(t,e={}){if(this.breaker.state==="OPEN")if(Date.now()-this.breaker.lastFailure>this.breaker.cooldown)this.breaker.state="HALF_OPEN";else throw Error(`[CircuitBreaker] ${this.clientName} is OPEN`);const r=e.retries??3;let i=0;while(i<r)try{const s=await this._execute(t,{...e});if(s.ok||s.status===401){this.breaker.failures=0;this.breaker.state="CLOSED";return s}if([502,503,504].includes(s.status))throw Error(`Server Error: ${s.status}`);return s}catch(s){i++;this.breaker.failures++;this.breaker.lastFailure=Date.now();if(this.breaker.failures>=this.breaker.threshold)this.breaker.state="OPEN";if(i>=r)throw s;const n=Math.pow(2,i)*500;await new Promise((c)=>setTimeout(c,n))}throw Error(`${this.clientName} failed after ${r} attempts`)}async _execute(t,e){const r=this.baseURL.replace(/\/$/,""),i=e.version!==void 0?e.version:this.version,s=i?`/${i.replace(/^\//,"")}`:"",n=`${r}${s}${t}`,c=D(),l=new Headers(e.headers||{}),u=e.body instanceof URLSearchParams,d=e.body instanceof FormData;if(!u&&!d)l.set("Content-Type","application/json");if(c)l.set("x-correlation-id",c);const f=this.configs.all.internalSecret||process.env.INTERNAL_SECRET;if(f){const a=Date.now().toString(),w=E("sha256",f).update(a+this.clientName).digest("hex");l.set("x-internal-signature",w);l.set("x-internal-timestamp",a);l.set("x-internal-client",this.clientName)}const p=e.debug??this.debug,{version:L,retries:$,debug:v,...h}=e;let o=h.body;if(o&&typeof o==="object"&&!u&&!d)o=JSON.stringify(o);if(p){const a={method:h.method||"GET",url:n,body:o&&typeof o==="string"?JSON.parse(o):o};console.log(`[DEBUG] ${this.clientName}`,a);this.logger.winston.info(`${this.clientName} Request`,a)}const m=new AbortController,g=setTimeout(()=>m.abort(),this.timeout);try{const a=await fetch(n,{...h,body:o,headers:l,signal:m.signal});clearTimeout(g);return a}catch(a){clearTimeout(g);throw a}}}
1
+ import{createHash as k,createHmac as E}from"node:crypto";import{Configs as y,Logger as N}from"../../../loader";import{LoggerLayerEnum as x,x as b}from"../../../utils";import{getRequestId as D}from"../../../utils/helpers/context";export class ClientStore{static _store={};static get(t){return this._store[t]||{}}static set(t,e){this._store[t]={...this._store[t],...e}}}export class Client{logger=b.get(N);configs=b.get(y);clientName;baseURL;version=null;timeout=15000;debug;authConfigs;breaker={failures:0,lastFailure:0,state:"CLOSED",threshold:5,cooldown:30000};constructor({clientName:t,baseURL:e,version:r,timeout:i,auth:s,debug:n}){this.clientName=t;this.baseURL=e;this.version=r||null;this.authConfigs=s;this.timeout=i||15000;const c=Number(this.configs.all.debug)>=x.DEBUG;this.debug=n??c;if(s?.token)ClientStore.set(t,{accessToken:s.token})}resolvePath(t,e){return e.split(".").reduce((r,i)=>r?r[i]:void 0,t)}static cryptoHashGenerate=({algorithm:t,input:e,digest:r="hex"})=>{return k(t).update(e).digest(r)}}export class BaseApiClient extends Client{constructor(t){super(t)}async request(t,e={}){if(this.breaker.state==="OPEN")if(Date.now()-this.breaker.lastFailure>this.breaker.cooldown)this.breaker.state="HALF_OPEN";else throw Error(`[CircuitBreaker] ${this.clientName} is OPEN`);const r=e.retries??3;let i=0;while(i<r)try{const s=await this._execute(t,{...e});if(s.ok||s.status===401){this.breaker.failures=0;this.breaker.state="CLOSED";return s}if([502,503,504].includes(s.status))throw Error(`Server Error: ${s.status}`);return s}catch(s){i++;this.breaker.failures++;this.breaker.lastFailure=Date.now();if(this.breaker.failures>=this.breaker.threshold)this.breaker.state="OPEN";if(i>=r)throw s;const n=Math.pow(2,i)*500;await new Promise((c)=>setTimeout(c,n))}throw Error(`${this.clientName} failed after ${r} attempts`)}async _execute(t,e){const r=this.baseURL.replace(/\/$/,""),i=e.version!==void 0?e.version:this.version,s=i?`/${i.replace(/^\//,"")}`:"",n=`${r}${s}${t}`,c=D(),l=new Headers(e.headers||{}),u=e.body instanceof URLSearchParams,d=e.body instanceof FormData;if(!u&&!d)l.set("Content-Type","application/json");if(c)l.set("x-correlation-id",c);const f=this.configs.all.internalSecret||process.env.INTERNAL_SECRET;if(f){const a=Date.now().toString(),w=E("sha256",f).update(a+this.clientName).digest("hex");l.set("x-internal-signature",w);l.set("x-internal-timestamp",a);l.set("x-internal-client",this.clientName)}const p=e.debug??this.debug,{version:L,retries:$,debug:v,...h}=e;let o=h.body;if(o&&typeof o==="object"&&!u&&!d)o=JSON.stringify(o);if(p){const a={method:h.method||"GET",url:n,body:o&&typeof o==="string"?JSON.parse(o):o};console.log(`[DEBUG] ${this.clientName}`,a);this.logger.winston.info(`${this.clientName} Request`,a)}const m=new AbortController,g=setTimeout(()=>m.abort(),this.timeout);try{const a=await fetch(n,{...h,body:o,headers:l,signal:m.signal});clearTimeout(g);return a}catch(a){clearTimeout(g);throw a}}}
@@ -1 +1 @@
1
- import{EventEmitter as L}from"node:events";import{readFileSync as N,unwatchFile as G,watchFile as Q}from"node:fs";import{resolve as R}from"node:path";import{parse as U}from"yaml";import{resolveObjWithHandlebars as V}from"../../../utils/helpers/index.js";import{normalizeTmpDocument as X}from"../../../utils/helpers/tmp/tmp-schema.js";import{resolveTmpWatchIntervalMs as A}from"../../../utils/helpers/tmp/tmp-watch.js";export class TmpFileLoader extends L{#k={};#q;#B=A(null);#A=!1;constructor({filePath:k}){super();this.#q=R(k);this.#G();this.#K()}#G(){try{const k=N(this.#q,"utf8"),q=U(k),B=A(q),K=this.#A&&B!==this.#B;this.#k=q;this.#B=B;this.emit("reload",this.#k);if(K)this.#K()}catch(k){console.error(`[TmpFileLoader] Error: ${k}`)}}#K(){if(this.#A)G(this.#q);this.#B=A(this.#k);Q(this.#q,{interval:this.#B},(k,q)=>{if(k.mtimeMs!==q.mtimeMs)this.#G()});this.#A=!0}stop(){if(this.#A){G(this.#q);this.#A=!1}this.removeAllListeners()}getResolvedTmpFile(){const k=Object.keys(this.#k).length>0?this.#k:(this.#G(),this.#k);return X(V(k,k))}}
1
+ import{EventEmitter as L}from"node:events";import{readFileSync as N,unwatchFile as G,watchFile as Q}from"node:fs";import{resolve as R}from"node:path";import{parse as U}from"yaml";import{resolveObjWithHandlebars as V}from"../../../utils/helpers";import{normalizeTmpDocument as X}from"../../../utils/helpers/tmp/tmp-schema";import{resolveTmpWatchIntervalMs as A}from"../../../utils/helpers/tmp/tmp-watch";export class TmpFileLoader extends L{#k={};#q;#B=A(null);#A=!1;constructor({filePath:k}){super();this.#q=R(k);this.#G();this.#K()}#G(){try{const k=N(this.#q,"utf8"),q=U(k),B=A(q),K=this.#A&&B!==this.#B;this.#k=q;this.#B=B;this.emit("reload",this.#k);if(K)this.#K()}catch(k){console.error(`[TmpFileLoader] Error: ${k}`)}}#K(){if(this.#A)G(this.#q);this.#B=A(this.#k);Q(this.#q,{interval:this.#B},(k,q)=>{if(k.mtimeMs!==q.mtimeMs)this.#G()});this.#A=!0}stop(){if(this.#A){G(this.#q);this.#A=!1}this.removeAllListeners()}getResolvedTmpFile(){const k=Object.keys(this.#k).length>0?this.#k:(this.#G(),this.#k);return X(V(k,k))}}
@@ -1 +1 @@
1
- import _ from"lodash";import x from"../../utils/models/classes/class.x.js";import locator from"../../utils/models/classes/class.service-locator.js";export*from"../../utils/models/classes/class.tmp-file-loader.js";export*from"../../utils/models/classes/class.interfaces.js";export*from"../../utils/models/classes/class.clients.js";export*from"../../utils/models/types/index.js";export*from"../../utils/models/enums/index.js";export{x,locator,_};
1
+ import _ from"lodash";import x from"../../utils/models/classes/class.x";import locator from"../../utils/models/classes/class.service-locator";export*from"../../utils/models/classes/class.tmp-file-loader";export*from"../../utils/models/classes/class.interfaces";export*from"../../utils/models/classes/class.clients";export*from"../../utils/models/types";export*from"../../utils/models/enums";export{x,locator,_};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- import{describe as K,expect as j,test as A}from"bun:test";import{normalizeRootFolder as H,normalizeTmpDocument as N,readTmpCoreBlock as O,readTmpServiceBlock as J,resolveServiceLayoutPaths as Q,resolveTmpRuntimeConfigs as U}from"../../../utils/helpers/tmp/tmp-schema.js";import{resolveTmpWatchIntervalMs as V}from"../../../utils/helpers/tmp/tmp-watch.js";const G={configs:{service:{name:"my-api",framework:"elysia",paths:{root:"./infra.js",source:"./src.js",special:{tests:"specs",environments:"env",dist:"out"}},protocols:["http"],build:{typecheck:!0},loaders:{dto:{withDefaultHeaders:!0}}},core:{tmp:{fileWatchIntervalMs:200}}}};K("tmp-schema service + core blocks",()=>{A("readTmpServiceBlock reads paths.root, paths.source, paths.special",()=>{const q=J(G.configs);j(q.paths?.root).toBe("./infra.js");j(q.paths?.source).toBe("./src.js");j(q.paths?.special?.tests).toBe("specs");j(q.name).toBe("my-api");j(q.build?.typecheck).toBe(!0)});A("readTmpCoreBlock reads core.tmp.fileWatchIntervalMs",()=>{j(O(G.configs).tmp?.fileWatchIntervalMs).toBe(200)});A("normalizeRootFolder strips ./ prefix",()=>{j(H("./x.js")).toBe("x");j(H("infra")).toBe("infra")});A("resolveTmpRuntimeConfigs returns service, core, and rootFolderPath",()=>{const q=U(G);j(Object.keys(q)).toEqual(["service","core","rootFolderPath"]);j(q.rootFolderPath).toBe("infra");j(q.service.paths?.special?.dist).toBe("out");j(q.service.framework).toBe("elysia");j(q.service.loaders).toEqual({dto:{withDefaultHeaders:!0}});j(q.core.tmp?.fileWatchIntervalMs).toBe(200);j("loaders"in q).toBe(!1);j("mainFolderPath"in q).toBe(!1)});A("normalizeTmpDocument merges service + core + derived rootFolderPath onto configs",()=>{const E=N(G).configs;j(E.service).toBeTruthy();j(E.core).toBeTruthy();j(E.rootFolderPath).toBe("infra");j(E.service.loaders).toBeTruthy();j(E.loaders).toBeUndefined();j(E.mainFolderPath).toBeUndefined()});A("resolveTmpWatchIntervalMs reads core.tmp.fileWatchIntervalMs",()=>{j(V(G)).toBe(200)});A("resolveServiceLayoutPaths uses defaults when special omitted",()=>{const q=Q(J({service:{paths:{}}}));j(q.tests).toBe("tests");j(q.dist).toBe("dist")})});
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- import{describe as k,expect as f,test as j}from"bun:test";import{resolveTmpWatchIntervalMs as g}from"../../../utils/helpers/tmp/tmp-watch.js";k("resolveTmpWatchIntervalMs",()=>{j("defaults to 500ms when core.tmp omitted",()=>{f(g({configs:{}})).toBe(500)});j("reads configs.core.tmp.fileWatchIntervalMs",()=>{f(g({configs:{core:{tmp:{fileWatchIntervalMs:200}}}})).toBe(200)});j("clamps to min/max bounds",()=>{f(g({configs:{core:{tmp:{fileWatchIntervalMs:10}}}})).toBe(100);f(g({configs:{core:{tmp:{fileWatchIntervalMs:60000}}}})).toBe(1e4)})});