@xrystal/core 3.47.3 → 3.47.7
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/package.json +5 -1
- package/x/bin/helpers/.generated/tmp-schema.mjs +8 -1
- package/x/bin/helpers/build-config.mjs +10 -3
- package/x/bin/helpers/project-artifacts.mjs +1 -0
- package/x/dist/loader/configs/index.d.ts +2 -1
- package/x/dist/loader/configs/index.js +1 -1
- package/x/dist/loader/kafka/index.js +1 -1
- package/x/dist/utils/helpers/core/handlebars-resolve.d.ts +2 -0
- package/x/dist/utils/helpers/core/handlebars-resolve.js +1 -0
- package/x/dist/utils/helpers/core/index.d.ts +1 -1
- package/x/dist/utils/helpers/core/index.js +1 -1
- package/x/dist/utils/helpers/index.d.ts +1 -0
- package/x/dist/utils/helpers/index.js +1 -1
- package/x/dist/utils/helpers/kafka/index.d.ts +6 -0
- package/x/dist/utils/helpers/kafka/index.js +1 -0
- package/x/dist/utils/models/classes/class.tmp-file-loader.js +1 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "Yusuf Yasir KAYGUSUZ",
|
|
3
3
|
"name": "@xrystal/core",
|
|
4
|
-
"version": "3.47.
|
|
4
|
+
"version": "3.47.7",
|
|
5
5
|
"description": "microservice runtime library",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public",
|
|
@@ -35,6 +35,10 @@
|
|
|
35
35
|
"types": "./x/dist/loader/index.d.ts",
|
|
36
36
|
"default": "./x/dist/loader/index.js"
|
|
37
37
|
},
|
|
38
|
+
"./loader/configs": {
|
|
39
|
+
"types": "./x/dist/loader/configs/index.d.ts",
|
|
40
|
+
"default": "./x/dist/loader/configs/index.js"
|
|
41
|
+
},
|
|
38
42
|
"./loader/controller": {
|
|
39
43
|
"types": "./x/dist/loader/controller/index.d.ts",
|
|
40
44
|
"default": "./x/dist/loader/controller/index.js"
|
|
@@ -129,6 +129,13 @@ function readLayoutFromSpecial(special) {
|
|
|
129
129
|
dist: requireString(block.dist, "configs.service.paths.special.dist")
|
|
130
130
|
};
|
|
131
131
|
}
|
|
132
|
+
function safeProcessCwd() {
|
|
133
|
+
try {
|
|
134
|
+
return process.cwd();
|
|
135
|
+
} catch {
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
132
139
|
function findBundledTmpFile(explicit) {
|
|
133
140
|
if (explicit) {
|
|
134
141
|
if (!fs.existsSync(explicit)) {
|
|
@@ -136,7 +143,7 @@ function findBundledTmpFile(explicit) {
|
|
|
136
143
|
}
|
|
137
144
|
return explicit;
|
|
138
145
|
}
|
|
139
|
-
const starts = [here,
|
|
146
|
+
const starts = [here, safeProcessCwd()].filter((value) => Boolean(value));
|
|
140
147
|
for (const start of starts) {
|
|
141
148
|
let dir = path.resolve(start);
|
|
142
149
|
for (;; ) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fs from 'node:fs'
|
|
2
2
|
import path from 'node:path'
|
|
3
|
+
import { fileURLToPath } from 'node:url'
|
|
3
4
|
import yaml from 'yaml'
|
|
4
5
|
|
|
5
6
|
import { packageDefaults } from '../paths.mjs'
|
|
@@ -15,6 +16,11 @@ import {
|
|
|
15
16
|
|
|
16
17
|
import { CLI_BIN_NAMES, CLI_PRIMARY_NAME } from './cli-identity.mjs'
|
|
17
18
|
|
|
19
|
+
function resolveCoreScriptsBase() {
|
|
20
|
+
const here = path.dirname(fileURLToPath(import.meta.url))
|
|
21
|
+
return path.join(here, '..', 'scripts')
|
|
22
|
+
}
|
|
23
|
+
|
|
18
24
|
function escapeRegExp(value) {
|
|
19
25
|
return String(value).replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
|
20
26
|
}
|
|
@@ -294,7 +300,8 @@ export function resolveBunBuildCommand(entryGlobs, distRel, buildConfig = {}, ts
|
|
|
294
300
|
}
|
|
295
301
|
|
|
296
302
|
export function resolveTscBuildCommand(root, distRel, buildConfig = {}, runtime = detectCliHostRuntime()) {
|
|
297
|
-
|
|
303
|
+
const cmd = withTscProject(root, buildConfig, `--outDir ${distRel}`, runtime)
|
|
304
|
+
return buildConfig.tscLenient ? `${cmd} || true` : cmd
|
|
298
305
|
}
|
|
299
306
|
|
|
300
307
|
export function resolveEsbuildBuildCommand(entryGlobs, distRel, buildConfig = {}, tsconfig = null, runtime = detectCliHostRuntime()) {
|
|
@@ -326,7 +333,7 @@ export function resolveServicePostProcessSteps(root, distRel, buildConfig = {},
|
|
|
326
333
|
|
|
327
334
|
const host = getRuntimeTooling(runtime)
|
|
328
335
|
const aliasRunner = host.tscBin.trim().split(/\s+/)[0]
|
|
329
|
-
const scriptsBase = `node ${
|
|
336
|
+
const scriptsBase = `node ${resolveCoreScriptsBase()}`
|
|
330
337
|
const distArg = distRel.includes(' ') ? `"${distRel}"` : distRel
|
|
331
338
|
const steps = [`${aliasRunner} tsc-alias -p ${tsconfigRel}`]
|
|
332
339
|
|
|
@@ -381,7 +388,7 @@ export function resolveCoreBuildSteps(root, distRel, buildConfig = {}) {
|
|
|
381
388
|
}
|
|
382
389
|
const host = getRuntimeTooling(detectCliHostRuntime())
|
|
383
390
|
const xBin = host.tscBin.trim().split(/\s+/)[0] // bunx | npx
|
|
384
|
-
const scriptsBase = `node ${
|
|
391
|
+
const scriptsBase = `node ${resolveCoreScriptsBase()}`
|
|
385
392
|
const steps = [
|
|
386
393
|
`${scriptsBase}/sync-cli-defaults.mjs`,
|
|
387
394
|
`rm -rf ${distRel}`,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import System from '../../loader/system';
|
|
2
|
-
import { IProvide
|
|
2
|
+
import { IProvide } from '../../utils/models/classes/class.interfaces';
|
|
3
|
+
import { ModeEnum } from '../../utils/models/enums';
|
|
3
4
|
export interface IConfig {
|
|
4
5
|
worker: boolean;
|
|
5
6
|
mode: ModeEnum;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Q from"node:path";import H from"lodash";import{pathToFileURL as W}from"node:url";import{Constants as I}from"../../utils/constants";import{resolveTmpLoadPath as X}from"../../utils/helpers/path/resolve-alias-path";import{bindLoaderTmpSync as Y}from"../../utils/helpers/tmp/loader-tmp-sync";export default class Configs{publicFolderName=I.publicFolderName;kafkaLogsTopic=I.kafkaLogsTopic;#z;#q;constructor({system:z}){this.#z=z;return new Proxy(this,{get:(A,B)=>{return A[B]||A.config?.[B]}})}onInit=async()=>{await this.syncFromTmp();Y(this)};syncFromTmp=async()=>{const z=process.cwd(),q=this.#z.tmp,A=q.configs.service.loaders.configs.loadPath,B=X(A,q,z),J=import(W(B).href);this.#q={worker:process.env.WORKER==="true"?!0:!1,mode:process.env.MODE,nodeEnv:"development",debug:process.env.SYSTEM_LOGGER_LAYER??"",https:process.env.HTTPS??"false",httpsfileEncoding:process.env.ENCODING||"utf8",httpsCertfile:process.env.HTTPS_CERT_FILE??"",httpsKeyfile:process.env.HTTPS_KEY_FILE??"",rootFolderPath:q.configs.rootFolderPath||"x",projectName:q.project.name,serviceName:q.configs.service.name??"",projectNamePrefixEnv:process.env.PROJECT_NAME_PREFIX||"",projectNameEnv:process.env.PROJECT_NAME||"",projectNameSuffixEnv:process.env.PROJECT_NAME_SUFFIX||"",systemStaticFolderPath:Q.resolve(q.configs.rootFolderPath,this.publicFolderName),systemLoggerLayer:process.env.SYSTEM_LOGGER_LAYER??"info",isKafkaPassive:process.env.IS_KAFKA_PASSIVE==="true"?!0:!1,kafkaClientId:q.configs.service.name??"",kafkaBrokers:process.env.KAFKA_BROKERS??"",kafkaUsername:process.env.KAFKA_USERNAME??"",kafkaPassword:process.env.KAFKA_PASSWORD??"",kafkaTopics:[],kafkaLogsTopic:this.kafkaLogsTopic,baseApiUri:process.env.HTTPS==="true"?process.env.SYSTEM_HTTPS_BASE_API_URI??"":process.env.SYSTEM_BASE_API_URI??"",port:Number(process.env.PORT),internalSecret:process.env.INTERNAL_SECRET??"",secret:process.env.SECRET??"",cwd:z,env:"development"};try{const E=await J,K=E?.default||E?.configs||E||{},M=H.mergeWith({},this.#q,K,(G,N)=>{if(H.isArray(G))return G.concat(N)});this.#q=Object.freeze(M)}catch{this.#q=Object.freeze(this.#q)}};setConfig(z){const q=Object.assign(this.#q,z);this.#q=Object.freeze(q)}_(z){return this.#q[z]}get all(){return this.#q}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Kafka as
|
|
1
|
+
import{Kafka as N,logLevel as O}from"kafkajs";import{bindLoaderTmpSync as Q,resolveKafkaJsSsl as R}from"../../utils";export default class KafkaForCore{_instance;_producer;clientId="";brokers="";username=null;password=null;#q;#h;constructor({system:q,configs:h}){this.#q=q;this.#h=h}onDispose=async()=>{await this.teardownKafka()};onInit=async()=>{await this.syncFromTmp();Q(this)};syncFromTmp=async()=>{await this.teardownKafka();this.clientId=this.#h.all?.kafkaClientId;this.brokers=this.#h.all?.kafkaBrokers;this.username=this.#h.all?.kafkaUsername;this.password=this.#h.all?.kafkaPassword;if(this.#h.all.isKafkaPassive)return;const q=(Array.isArray(this.brokers)?this.brokers:this.brokers?.split(",")??[]).map((h)=>h?.trim()).filter(Boolean);if(q.length===0)throw Error("Broker list error");await this.kafkaLoader({clientId:this.clientId,brokers:q,username:this.username,password:this.password});await this.initializeKafkaInfrastructure()};teardownKafka=async()=>{if(this._producer){try{await this._producer.disconnect()}catch{}this._producer=void 0}};kafkaLoader=async({clientId:q,brokers:h,username:F,password:E})=>{const D={clientId:q,brokers:h,sasl:F&&E?{mechanism:"plain",username:F,password:E}:void 0,ssl:R(h),logLevel:O.ERROR,logCreator:()=>{return({level:z,log:G})=>{console.error(`Kafka ${G.message}`)}},retry:{initialRetryTime:100,retries:8}};try{const z=new N(D);this._instance=z;this._producer=z.producer();await this.producer.connect();return z}catch(z){console.error(`Kafka ${z}`)}};initializeKafkaInfrastructure=async()=>{const{kafkaBrokers:q,kafkaTopics:h,isKafkaPassive:F}={isKafkaPassive:process.env.IS_KAFKA_PASSIVE==="true"?!0:!1,kafkaBrokers:process.env?.KAFKA_BROKERS,kafkaTopics:[...new Set([...this.#h.all.kafkaTopics])]};if(F===!0||!q)return;const E=Array.isArray(h)?h:[];if(E.length===0)return;const D=this._instance.admin();try{await D.connect();const z=await D.listTopics(),G=E.filter((M)=>!z.includes(M)).map((M)=>({topic:M,numPartitions:1,replicationFactor:1}));if(G.length>0)await D.createTopics({waitForLeaders:!0,topics:G})}catch(z){}finally{await D.disconnect()}};sendMessage=async(q,h)=>{if(!this.producer)throw Error("Producer not ready");await this.producer.send({topic:q,messages:[{value:JSON.stringify(h)}],acks:0})};get producer(){return this._producer}get instance(){return this._instance}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import C from"handlebars";export function resolveObjWithHandlebars(q,A){if(typeof q==="string")return C.compile(q)(A);if(typeof q==="object"&&q!==null){const z=q;for(const B in z)z[B]=resolveObjWithHandlebars(z[B],A)}return q}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ProtocolEnum } from '../../../utils/index.js';
|
|
2
2
|
export * from '../../../utils/helpers/core/paths';
|
|
3
3
|
export * from '../../../utils/helpers/core/tmp-layout';
|
|
4
|
+
export { resolveObjWithHandlebars } from '../../../utils/helpers/core/handlebars-resolve';
|
|
4
5
|
export declare const getCore: () => {
|
|
5
6
|
_: Record<string, unknown>;
|
|
6
7
|
};
|
|
@@ -9,7 +10,6 @@ export declare const getTmpConfig: ({ root, tmpFileName, ext, }?: {
|
|
|
9
10
|
tmpFileName?: string;
|
|
10
11
|
ext?: string;
|
|
11
12
|
}) => Record<string, unknown>;
|
|
12
|
-
export declare function resolveObjWithHandlebars(obj: any, context: any): any;
|
|
13
13
|
export declare const withProtocol: <T>(callback: () => T | Promise<T>, protocol?: ProtocolEnum | string) => Promise<T>;
|
|
14
14
|
export declare const protocol: (callback: () => Promise<any>, proto?: ProtocolEnum) => Promise<any>;
|
|
15
15
|
export declare const argvsConverter: (argvs: string) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import{Constants as G,ProtocolEnum as H,TmpFileLoader as J}from"../../../utils/index.js";import{controllerContextStorage as K}from"../../../utils/helpers/context/controller-store";import{getTmpSnapshot as M}from"../../../utils/helpers/tmp/tmp-loader";import{findFileRecursively as O}from"../../../utils/helpers/core/paths";import{parseProtocol as Q}from"../../../utils/helpers/protocol/index.js";export*from"../../../utils/helpers/core/paths";export*from"../../../utils/helpers/core/tmp-layout";export{resolveObjWithHandlebars}from"../../../utils/helpers/core/handlebars-resolve";export const getCore=()=>({_:M()}),getTmpConfig=({root:q=process.cwd(),tmpFileName:j=G.tmpBaseName,ext:z=G.tmpExtension}={})=>{const B=O(q,j,z);if(!B)throw Error(`${j}${z.startsWith(".")?z:`.${z}`} file not found`);return new J({filePath:B}).getResolvedTmpFile()},withProtocol=async(q,j=H.HTTP)=>{const z=Q(j),B=K.getStore();if(B)B.protocol=z;return await q()},protocol=async(q,j=H.HTTP)=>withProtocol(q,j),argvsConverter=(q)=>{const j=q?.slice(2),z={};j.forEach((B)=>{if(B.startsWith("--")){console.log(B);const[D,I]=B.split("=");z[D.replace("--","")]=I||""}});return z},findExt=(q)=>{const j=q.split(".");return j[j.length-1]},changeExtensions=(q,j)=>{return q.replace(findExt(q),j)};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export{default as pic}from"picocolors";export*from"../../utils/helpers/core";export*from"../../utils/helpers/path";export*from"../../utils/helpers/is";export*from"../../utils/helpers/id";export*from"../../utils/helpers/validates";export*from"../../utils/helpers/ip";export*from"../../utils/helpers/hash/crypto";export*from"../../utils/helpers/string";export*from"../../utils/helpers/objects";export*from"../../utils/helpers/locales";export*from"../../utils/helpers/timer";export*from"../../utils/helpers/date";export*from"../../utils/helpers/math";export*from"../../utils/helpers/regex/checkSpecialRegexControl";export*from"../../utils/helpers/filters";export*from"../../utils/helpers/framework";export*from"../../utils/helpers/protocol";export*from"../../utils/helpers/dto";export*from"../../utils/helpers/dispatch";export*from"../../utils/helpers/middleware";export*from"../../utils/helpers/context";export*from"../../utils/helpers/tmp";export*from"../../utils/helpers/state";export*from"../../utils/helpers/handlers";export*from"../../utils/helpers/runtime";
|
|
1
|
+
export{default as pic}from"picocolors";export*from"../../utils/helpers/core";export*from"../../utils/helpers/path";export*from"../../utils/helpers/is";export*from"../../utils/helpers/id";export*from"../../utils/helpers/validates";export*from"../../utils/helpers/ip";export*from"../../utils/helpers/hash/crypto";export*from"../../utils/helpers/string";export*from"../../utils/helpers/objects";export*from"../../utils/helpers/locales";export*from"../../utils/helpers/timer";export*from"../../utils/helpers/date";export*from"../../utils/helpers/math";export*from"../../utils/helpers/regex/checkSpecialRegexControl";export*from"../../utils/helpers/filters";export*from"../../utils/helpers/framework";export*from"../../utils/helpers/protocol";export*from"../../utils/helpers/dto";export*from"../../utils/helpers/dispatch";export*from"../../utils/helpers/middleware";export*from"../../utils/helpers/context";export*from"../../utils/helpers/tmp";export*from"../../utils/helpers/state";export*from"../../utils/helpers/handlers";export*from"../../utils/helpers/runtime";export*from"../../utils/helpers/kafka";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import q from"node:fs";export function resolveKafkaJsSsl(x=[]){const y=process.env.KAFKA_SSL==="true",z=x.some((B)=>/:9095\b/.test(B));if(!y&&!z)return!1;const j=process.env.KAFKA_SSL_CA||"/etc/tls/infra/ca.crt";try{if(j&&q.existsSync(j))return{ca:[q.readFileSync(j,"utf-8")],rejectUnauthorized:!1}}catch{}return{rejectUnauthorized:!1}}
|
|
@@ -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";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
|
+
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/core/handlebars-resolve";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))}}
|