@xrystal/core 3.51.5 → 3.52.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.
Files changed (121) hide show
  1. package/README.md +35 -1
  2. package/package.json +1 -1
  3. package/x/bin/commands/create.mjs +44 -0
  4. package/x/bin/commands/projects.mjs +53 -0
  5. package/x/bin/commands/sync.mjs +49 -1
  6. package/x/bin/commands/tmp.mjs +1 -1
  7. package/x/bin/helpers/.generated/.generated-from +2 -0
  8. package/x/bin/helpers/.generated/seed-from-tmp.mjs +25 -31
  9. package/x/bin/helpers/.generated/tmp-schema.mjs +156 -96
  10. package/x/bin/helpers/.generated/workspace.mjs +402 -0
  11. package/x/bin/helpers/.generated/xrystal-home-registry.mjs +310 -0
  12. package/x/bin/helpers/build-config.mjs +3 -2
  13. package/x/bin/helpers/cli-help.mjs +3 -1
  14. package/x/bin/helpers/project-artifacts.mjs +9 -0
  15. package/x/bin/helpers/tmp-config.mjs +13 -12
  16. package/x/bin/helpers/tmp-layout.mjs +28 -52
  17. package/x/bin/helpers/tmp-schema.mjs +9 -3
  18. package/x/bin/helpers/workspace-resolve.mjs +11 -0
  19. package/x/bin/helpers/workspace-scaffold.mjs +23 -0
  20. package/x/bin/helpers/xrystal-registry.mjs +13 -0
  21. package/x/bin/main-cli.js +2 -0
  22. package/x/dist/index.js +5 -1
  23. package/x/dist/loader/clients/index.js +22 -1
  24. package/x/dist/loader/configs/index.js +97 -1
  25. package/x/dist/loader/controller/index.js +267 -1
  26. package/x/dist/loader/dto/index.js +92 -1
  27. package/x/dist/loader/events/index.js +39 -1
  28. package/x/dist/loader/index.js +13 -1
  29. package/x/dist/loader/kafka/index.js +142 -1
  30. package/x/dist/loader/kafka/resolve-ssl.js +23 -1
  31. package/x/dist/loader/localizations/index.js +46 -1
  32. package/x/dist/loader/logger/index.js +229 -2
  33. package/x/dist/loader/mongo/index.js +52 -1
  34. package/x/dist/loader/mongo/resolve-connect.js +16 -1
  35. package/x/dist/loader/redis/index.js +57 -1
  36. package/x/dist/loader/redis/resolve-socket.js +31 -1
  37. package/x/dist/loader/registry/index.js +1 -1
  38. package/x/dist/loader/service/index.js +7 -1
  39. package/x/dist/loader/system/index.js +26 -1
  40. package/x/dist/project/index.js +51 -1
  41. package/x/dist/utils/constants/defaults.json +3 -1
  42. package/x/dist/utils/constants/index.d.ts +1 -0
  43. package/x/dist/utils/constants/index.js +42 -1
  44. package/x/dist/utils/constants/package-root.js +6 -1
  45. package/x/dist/utils/helpers/configs/index.js +1 -1
  46. package/x/dist/utils/helpers/context/controller-store.js +12 -1
  47. package/x/dist/utils/helpers/context/index.js +24 -1
  48. package/x/dist/utils/helpers/core/handlebars-resolve.js +15 -1
  49. package/x/dist/utils/helpers/core/index.js +46 -1
  50. package/x/dist/utils/helpers/core/paths.js +78 -1
  51. package/x/dist/utils/helpers/core/tmp-layout.d.ts +4 -4
  52. package/x/dist/utils/helpers/core/tmp-layout.js +229 -1
  53. package/x/dist/utils/helpers/date/index.js +48 -1
  54. package/x/dist/utils/helpers/dispatch/index.js +53 -1
  55. package/x/dist/utils/helpers/dto/index.js +10 -1
  56. package/x/dist/utils/helpers/filters/index.js +44 -1
  57. package/x/dist/utils/helpers/framework/index.js +18 -1
  58. package/x/dist/utils/helpers/handlers/adapters.js +41 -1
  59. package/x/dist/utils/helpers/handlers/execute.js +82 -1
  60. package/x/dist/utils/helpers/handlers/index.js +31 -1
  61. package/x/dist/utils/helpers/hash/crypto.js +22 -1
  62. package/x/dist/utils/helpers/id/index.js +24 -1
  63. package/x/dist/utils/helpers/index.d.ts +1 -0
  64. package/x/dist/utils/helpers/index.js +28 -1
  65. package/x/dist/utils/helpers/ip/index.js +21 -1
  66. package/x/dist/utils/helpers/is/index.js +35 -1
  67. package/x/dist/utils/helpers/kafka-loader-options/index.js +14 -1
  68. package/x/dist/utils/helpers/locales/index.js +82 -1
  69. package/x/dist/utils/helpers/logger-layer/index.js +33 -1
  70. package/x/dist/utils/helpers/math/index.js +14 -1
  71. package/x/dist/utils/helpers/middleware/index.js +36 -1
  72. package/x/dist/utils/helpers/node-env/index.js +20 -1
  73. package/x/dist/utils/helpers/objects/index.js +55 -1
  74. package/x/dist/utils/helpers/path/index.js +5 -1
  75. package/x/dist/utils/helpers/path/resolve-alias-path.d.ts +1 -1
  76. package/x/dist/utils/helpers/path/resolve-alias-path.js +62 -1
  77. package/x/dist/utils/helpers/protocol/index.d.ts +1 -1
  78. package/x/dist/utils/helpers/protocol/index.js +100 -1
  79. package/x/dist/utils/helpers/protocol/options.js +13 -1
  80. package/x/dist/utils/helpers/regex/checkSpecialRegexControl.js +3 -1
  81. package/x/dist/utils/helpers/registry/index.d.ts +6 -0
  82. package/x/dist/utils/helpers/registry/index.js +103 -1
  83. package/x/dist/utils/helpers/runtime/dto-access.js +5 -1
  84. package/x/dist/utils/helpers/runtime/dto-types.js +1 -1
  85. package/x/dist/utils/helpers/runtime/index.js +2 -1
  86. package/x/dist/utils/helpers/runtime/shutdown.js +36 -1
  87. package/x/dist/utils/helpers/state/index.js +185 -1
  88. package/x/dist/utils/helpers/state/props-from-tmp.js +46 -1
  89. package/x/dist/utils/helpers/state/request-key-guard.js +43 -1
  90. package/x/dist/utils/helpers/state/scopes.js +69 -1
  91. package/x/dist/utils/helpers/string/index.js +9 -1
  92. package/x/dist/utils/helpers/timer/index.js +5 -1
  93. package/x/dist/utils/helpers/tmp/index.d.ts +2 -2
  94. package/x/dist/utils/helpers/tmp/index.js +8 -1
  95. package/x/dist/utils/helpers/tmp/loader-tmp-sync.js +14 -1
  96. package/x/dist/utils/helpers/tmp/path-normalize.js +27 -1
  97. package/x/dist/utils/helpers/tmp/runtime-tmp.js +42 -1
  98. package/x/dist/utils/helpers/tmp/seed-from-tmp.d.ts +2 -2
  99. package/x/dist/utils/helpers/tmp/seed-from-tmp.js +62 -1
  100. package/x/dist/utils/helpers/tmp/tmp-interpolate.js +22 -1
  101. package/x/dist/utils/helpers/tmp/tmp-loader.js +56 -1
  102. package/x/dist/utils/helpers/tmp/tmp-schema.d.ts +35 -23
  103. package/x/dist/utils/helpers/tmp/tmp-schema.js +211 -1
  104. package/x/dist/utils/helpers/tmp/tmp-watch.js +23 -1
  105. package/x/dist/utils/helpers/tmp/toolchain-heal.js +157 -2
  106. package/x/dist/utils/helpers/validates/index.js +20 -1
  107. package/x/dist/utils/helpers/workspace/index.d.ts +42 -0
  108. package/x/dist/utils/helpers/workspace/index.js +222 -0
  109. package/x/dist/utils/helpers/xrystal-home/registry.d.ts +32 -0
  110. package/x/dist/utils/helpers/xrystal-home/registry.js +92 -0
  111. package/x/dist/utils/index.js +3 -1
  112. package/x/dist/utils/models/classes/class.clients.js +142 -1
  113. package/x/dist/utils/models/classes/class.interfaces.js +10 -1
  114. package/x/dist/utils/models/classes/class.service-locator.js +16 -1
  115. package/x/dist/utils/models/classes/class.tmp-file-loader.js +61 -1
  116. package/x/dist/utils/models/classes/class.x.js +181 -1
  117. package/x/dist/utils/models/enums/index.d.ts +9 -1
  118. package/x/dist/utils/models/enums/index.js +169 -1
  119. package/x/dist/utils/models/index.js +9 -1
  120. package/x/dist/utils/models/types/index.js +2 -1
  121. package/x/tmp.yml +7 -50
@@ -1,2 +1,229 @@
1
- import X,{format as Q}from"winston";import D from"winston-transport";import"winston-daily-rotate-file";import Z from"node:path";import{Partitioners as N}from"kafkajs";import{LoggerLayerEnum as J}from "../../utils/index.js";import{loggerLayerName as S,meetsLoggerLayerThreshold as B,normalizeLoggerLayer as I}from "../../utils/helpers/logger-layer/index.js";import{readKafkaLoaderOptions as R}from "../../utils/helpers/kafka-loader-options/index.js";import{LogDTO as j}from "../../utils/index.js";import{bindLoaderTmpSync as K}from "../../utils/index.js";import{getRequestId as $}from "../../utils/index.js";class z extends D{service;constructor(x,A){super(x);this.service=A}log(x,A){setImmediate(()=>this.emit("logged",x));this.service.logToKafka(x).finally(()=>A())}}const O={critical:J.CRITICAL,error:J.ERROR,warn:J.WARN,info:J.INFO,http:J.HTTP,debug:J.DEBUG},w={critical:"red",error:"magenta",warn:"yellow",info:"green",http:"cyan",debug:"blue"};export default class Logger{serviceName="";isKafkaReady=!1;kafkaProducer=null;kafkaLogsTopic="";queueLogLevel=J.WARN;winston;#A;#x;#G;constructor({system:x,configs:A,kafkaForCore:H}){this.#A=x;this.#x=A;this.#G=H}onDispose=async()=>{await this.teardownLogger()};onInit=async()=>{await this.syncFromTmp();K(this)};syncFromTmp=async()=>{await this.teardownLogger();this.serviceName=this.#A?.tmp?.configs?.service?.name??"";this.kafkaLogsTopic=this.#x?.all?.kafkaLogsTopic;X.addColors(w);const x=this.#A?.tmp?.configs?.service?.loaders?.loggers,{kafkaBrokers:A}=this.#x.all,H=A?String(A).split(",").map((Y)=>Y.trim()):[],M=R(this.#A?.tmp?.configs?.service?.loaders);if(M.enabled&&M.queueLogEnabled&&H.length>0&&this.#G.instance){this.kafkaProducer=this.#G.instance.producer({createPartitioner:N.DefaultPartitioner,retry:{initialRetryTime:500,retries:5}});try{await this.kafkaProducer?.connect();this.isKafkaReady=!0}catch{this.isKafkaReady=!1}}const V=x?.loadPath||"logs",G=x?.logLevel||x?.loggerLevel||"info",W=I(x?.queueLogLevel??x?.kafkaLogLevel,J.WARN);this.queueLogLevel=W;this.winstonLoader({loadPath:Z.join(this.#x.all.rootFolderPath,V),loggerLevel:G,queueLogLevel:S(W)})};teardownLogger=async()=>{if(this.kafkaProducer){try{await this.kafkaProducer.disconnect()}catch{}this.kafkaProducer=null}this.isKafkaReady=!1;if(this.winston){this.winston.clear();this.winston.close()}};winstonLoader=({loadPath:x,loggerLevel:A,queueLogLevel:H})=>{const{combine:M,timestamp:U,json:V,errors:G}=Q,W=this.getTracingFormat(),Y=M(W,U({format:"YYYY-MM-DD HH:mm:ss"}),G({stack:!0}),V({replacer:this.safeReplacer})),_=[new X.transports.Console({format:this.getConsoleFormat()}),new X.transports.DailyRotateFile({filename:Z.resolve(x,"error","%DATE%_error.log"),level:"error",format:Y,maxSize:"2mb",maxFiles:"7d"}),new X.transports.DailyRotateFile({filename:Z.resolve(x,"critical","%DATE%_critical.log"),level:"critical",format:Y,maxSize:"2mb",maxFiles:"14d"})];if(this.isKafkaReady&&this.kafkaProducer)_.push(new z({level:H},this));this.winston=X.createLogger({level:A,levels:O,format:W,transports:_});return this.winston};safeReplacer=(x,A)=>{if(A instanceof Headers)return Object.fromEntries(A.entries());if(A instanceof Error)return{message:A.message,stack:A.stack};return A};getTracingFormat=Q((x)=>{if(x.id)return x;const A=$();if(A)x.id=A;return x});getConsoleFormat(){return Q.combine(this.getTracingFormat(),Q.timestamp({format:"YYYY-MM-DD HH:mm:ss"}),Q.colorize({all:!0}),Q.printf((x)=>{const A=typeof x.message==="object"?JSON.stringify(x.message,this.safeReplacer):x.message,H=x.id?` : id: ${x.id}`:"",M=x.payload?`
2
- Payload: ${JSON.stringify(x.payload,this.safeReplacer)}`:"",U=x.code?` [Code: ${x.code}]`:"";return`${x.timestamp} [${this.serviceName}] ${x.level}${U}: ${A}${H}${M}`}))}normalizeLevel(x){return typeof x==="string"?x.toLowerCase():J[x].toLowerCase()}normalizeMessage(x){if(x===void 0||x===null)return;return typeof x==="string"?x:JSON.stringify(x,this.safeReplacer)}buildLogBody(x){return j.schema({level:this.normalizeLevel(x.level),service:this.serviceName,message:this.normalizeMessage(x.message),payload:x.payload,code:x.code,timestamp:x.timestamp??new Date().toISOString(),id:x.id??$()??void 0,env:this.#x.all.env}).build()}async logToKafka(x){if(!this.kafkaProducer||!this.isKafkaReady)return;if(!B(x.level,this.queueLogLevel))return;try{const A=this.buildLogBody({level:x.level,message:x.message,payload:x.payload,code:x.code,id:x.id,timestamp:x.timestamp});await this.kafkaProducer.send({topic:this.kafkaLogsTopic,messages:[{value:JSON.stringify(A,this.safeReplacer)}],acks:1})}catch(A){this.isKafkaReady=!1}}log(x,A,H,M){const V=typeof x==="object"&&x!==null&&"level"in x?x:{level:x,message:A,payload:H,code:M},G=this.buildLogBody(V);this.winston.log(G.level,G.message,{id:G.id,payload:G.payload,code:G.code,service:G.service,timestamp:G.timestamp,env:G.env})}}
1
+ import winston, { format } from "winston";
2
+ import Transport from "winston-transport";
3
+ import "winston-daily-rotate-file";
4
+ import path from "node:path";
5
+ import { Partitioners } from "kafkajs";
6
+ import { LoggerLayerEnum } from '../../utils/index.js';
7
+ import { loggerLayerName, meetsLoggerLayerThreshold, normalizeLoggerLayer, } from '../../utils/helpers/logger-layer/index.js';
8
+ import { readKafkaLoaderOptions } from '../../utils/helpers/kafka-loader-options/index.js';
9
+ import { LogDTO } from "../../utils/index.js";
10
+ import { bindLoaderTmpSync } from '../../utils/index.js';
11
+ import { getRequestId } from "../../utils/index.js";
12
+ class KafkaTransport extends Transport {
13
+ service;
14
+ constructor(opts, service) {
15
+ super(opts);
16
+ this.service = service;
17
+ }
18
+ log(info, callback) {
19
+ setImmediate(() => this.emit("logged", info));
20
+ this.service["logToKafka"](info).finally(() => callback());
21
+ }
22
+ }
23
+ const customLevels = {
24
+ critical: LoggerLayerEnum.CRITICAL,
25
+ error: LoggerLayerEnum.ERROR,
26
+ warn: LoggerLayerEnum.WARN,
27
+ info: LoggerLayerEnum.INFO,
28
+ http: LoggerLayerEnum.HTTP,
29
+ debug: LoggerLayerEnum.DEBUG,
30
+ };
31
+ const customColors = {
32
+ critical: "red",
33
+ error: "magenta",
34
+ warn: "yellow",
35
+ info: "green",
36
+ http: "cyan",
37
+ debug: "blue"
38
+ };
39
+ export default class Logger {
40
+ serviceName = "";
41
+ isKafkaReady = false;
42
+ kafkaProducer = null;
43
+ kafkaLogsTopic = "";
44
+ queueLogLevel = LoggerLayerEnum.WARN;
45
+ winston;
46
+ #system;
47
+ #configs;
48
+ #kafka;
49
+ constructor({ system, configs, kafkaForCore, }) {
50
+ this.#system = system;
51
+ this.#configs = configs;
52
+ this.#kafka = kafkaForCore;
53
+ }
54
+ onDispose = async () => {
55
+ await this.teardownLogger();
56
+ };
57
+ onInit = async () => {
58
+ await this.syncFromTmp();
59
+ bindLoaderTmpSync(this);
60
+ };
61
+ syncFromTmp = async () => {
62
+ await this.teardownLogger();
63
+ this.serviceName = this.#system?.tmp?.configs?.service?.name ?? '';
64
+ this.kafkaLogsTopic = this.#configs?.all?.kafkaLogsTopic;
65
+ winston.addColors(customColors);
66
+ const loggersConfigs = this.#system?.tmp?.configs?.service?.loaders?.loggers;
67
+ const { kafkaBrokers } = this.#configs.all;
68
+ const brokers = kafkaBrokers ? String(kafkaBrokers).split(',').map((b) => b.trim()) : [];
69
+ const kafkaOpts = readKafkaLoaderOptions(this.#system?.tmp?.configs?.service?.loaders);
70
+ const isKafkaLogEnabled = kafkaOpts.enabled && kafkaOpts.queueLogEnabled && brokers.length > 0;
71
+ if (isKafkaLogEnabled && this.#kafka.instance) {
72
+ this.kafkaProducer = this.#kafka.instance.producer({
73
+ createPartitioner: Partitioners.DefaultPartitioner,
74
+ retry: { initialRetryTime: 500, retries: 5 },
75
+ });
76
+ try {
77
+ await this.kafkaProducer?.connect();
78
+ this.isKafkaReady = true;
79
+ }
80
+ catch {
81
+ this.isKafkaReady = false;
82
+ }
83
+ }
84
+ const logPath = loggersConfigs?.loadPath || 'logs';
85
+ const loggerLevel = loggersConfigs?.logLevel || loggersConfigs?.loggerLevel || 'info';
86
+ const queueLogLevel = normalizeLoggerLayer(loggersConfigs?.queueLogLevel ?? loggersConfigs?.kafkaLogLevel, LoggerLayerEnum.WARN);
87
+ this.queueLogLevel = queueLogLevel;
88
+ this.winstonLoader({
89
+ loadPath: path.join(this.#configs.all.rootFolderPath, logPath),
90
+ loggerLevel,
91
+ queueLogLevel: loggerLayerName(queueLogLevel),
92
+ });
93
+ };
94
+ teardownLogger = async () => {
95
+ if (this.kafkaProducer) {
96
+ try {
97
+ await this.kafkaProducer.disconnect();
98
+ }
99
+ catch { }
100
+ this.kafkaProducer = null;
101
+ }
102
+ this.isKafkaReady = false;
103
+ if (this.winston) {
104
+ this.winston.clear();
105
+ this.winston.close();
106
+ }
107
+ };
108
+ winstonLoader = ({ loadPath, loggerLevel, queueLogLevel, }) => {
109
+ const { combine, timestamp, json, errors } = format;
110
+ const tracing = this.getTracingFormat();
111
+ const jsonFileFormat = combine(tracing, timestamp({ format: "YYYY-MM-DD HH:mm:ss" }), errors({ stack: true }), json({ replacer: this.safeReplacer }));
112
+ const transports = [
113
+ new winston.transports.Console({
114
+ format: this.getConsoleFormat()
115
+ }),
116
+ new winston.transports.DailyRotateFile({
117
+ filename: path.resolve(loadPath, "error", "%DATE%_error.log"),
118
+ level: "error",
119
+ format: jsonFileFormat,
120
+ maxSize: "2mb",
121
+ maxFiles: "7d"
122
+ }),
123
+ new winston.transports.DailyRotateFile({
124
+ filename: path.resolve(loadPath, "critical", "%DATE%_critical.log"),
125
+ level: "critical",
126
+ format: jsonFileFormat,
127
+ maxSize: "2mb",
128
+ maxFiles: "14d"
129
+ })
130
+ ];
131
+ if (this.isKafkaReady && this.kafkaProducer) {
132
+ transports.push(new KafkaTransport({ level: queueLogLevel }, this));
133
+ }
134
+ this.winston = winston.createLogger({
135
+ level: loggerLevel,
136
+ levels: customLevels,
137
+ format: tracing,
138
+ transports
139
+ });
140
+ return this.winston;
141
+ };
142
+ safeReplacer = (key, value) => {
143
+ if (value instanceof Headers)
144
+ return Object.fromEntries(value.entries());
145
+ if (value instanceof Error)
146
+ return { message: value.message, stack: value.stack };
147
+ return value;
148
+ };
149
+ getTracingFormat = format((info) => {
150
+ if (info.id)
151
+ return info;
152
+ const id = getRequestId();
153
+ if (id)
154
+ info.id = id;
155
+ return info;
156
+ });
157
+ getConsoleFormat() {
158
+ return format.combine(this.getTracingFormat(), format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }), format.colorize({ all: true }), format.printf((info) => {
159
+ const msg = typeof info.message === "object"
160
+ ? JSON.stringify(info.message, this.safeReplacer)
161
+ : info.message;
162
+ const idPart = info.id ? ` : id: ${info.id}` : "";
163
+ const payloadPart = info.payload ? `\nPayload: ${JSON.stringify(info.payload, this.safeReplacer)}` : "";
164
+ const codePart = info.code ? ` [Code: ${info.code}]` : "";
165
+ return `${info.timestamp} [${this.serviceName}] ${info.level}${codePart}: ${msg}${idPart}${payloadPart}`;
166
+ }));
167
+ }
168
+ normalizeLevel(level) {
169
+ return typeof level === 'string' ? level.toLowerCase() : LoggerLayerEnum[level].toLowerCase();
170
+ }
171
+ normalizeMessage(message) {
172
+ if (message === undefined || message === null)
173
+ return undefined;
174
+ return typeof message === 'string' ? message : JSON.stringify(message, this.safeReplacer);
175
+ }
176
+ buildLogBody(params) {
177
+ return LogDTO.schema({
178
+ level: this.normalizeLevel(params.level),
179
+ service: this.serviceName,
180
+ message: this.normalizeMessage(params.message),
181
+ payload: params.payload,
182
+ code: params.code,
183
+ timestamp: params.timestamp ?? new Date().toISOString(),
184
+ id: params.id ?? getRequestId() ?? undefined,
185
+ env: this.#configs.all.env,
186
+ }).build();
187
+ }
188
+ async logToKafka(info) {
189
+ if (!this.kafkaProducer || !this.isKafkaReady)
190
+ return;
191
+ if (!meetsLoggerLayerThreshold(info.level, this.queueLogLevel))
192
+ return;
193
+ try {
194
+ const body = this.buildLogBody({
195
+ level: info.level,
196
+ message: info.message,
197
+ payload: info.payload,
198
+ code: info.code,
199
+ id: info.id,
200
+ timestamp: info.timestamp,
201
+ });
202
+ await this.kafkaProducer.send({
203
+ topic: this.kafkaLogsTopic,
204
+ messages: [{
205
+ value: JSON.stringify(body, this.safeReplacer)
206
+ }],
207
+ acks: 1
208
+ });
209
+ }
210
+ catch (err) {
211
+ this.isKafkaReady = false;
212
+ }
213
+ }
214
+ log(arg1, arg2, arg3, arg4) {
215
+ const isObj = typeof arg1 === 'object' && arg1 !== null && 'level' in arg1;
216
+ const input = isObj
217
+ ? arg1
218
+ : { level: arg1, message: arg2, payload: arg3, code: arg4 };
219
+ const body = this.buildLogBody(input);
220
+ this.winston.log(body.level, body.message, {
221
+ id: body.id,
222
+ payload: body.payload,
223
+ code: body.code,
224
+ service: body.service,
225
+ timestamp: body.timestamp,
226
+ env: body.env,
227
+ });
228
+ }
229
+ }
@@ -1 +1,52 @@
1
- export{resolveMongoConnectOptions}from "./resolve-connect.js";import{MongoClient as q}from"mongodb";import{bindLoaderTmpSync as w}from "../../utils/helpers/tmp/loader-tmp-sync.js";import{resolveMongoConnectOptions as x}from "./resolve-connect.js";export default class MongoForCore{#j=null;#k=null;#w;#q;constructor({system:j,configs:k}){this.#w=j;this.#q=k}onDispose=async()=>{await this.teardown()};onInit=async()=>{await this.syncFromTmp();w(this)};syncFromTmp=async()=>{await this.teardown();if(this.#q.all.isMongoPassive)return;const j=this.#q.all.mongodbUri?.trim();if(!j)return;const k=new q(j,x(j));await k.connect();this.#j=k;this.#k=k.db()};teardown=async()=>{if(!this.#j)return;try{await this.#j.close()}catch{}this.#j=null;this.#k=null};get client(){return this.#j}get db(){return this.#k}}
1
+ export { resolveMongoConnectOptions } from './resolve-connect.js';
2
+ import { MongoClient } from 'mongodb';
3
+ import { bindLoaderTmpSync } from '../../utils/helpers/tmp/loader-tmp-sync.js';
4
+ import { resolveMongoConnectOptions } from './resolve-connect.js';
5
+ export default class MongoForCore {
6
+ #client = null;
7
+ #db = null;
8
+ #system;
9
+ #configs;
10
+ constructor({ system, configs, }) {
11
+ this.#system = system;
12
+ this.#configs = configs;
13
+ }
14
+ onDispose = async () => {
15
+ await this.teardown();
16
+ };
17
+ onInit = async () => {
18
+ await this.syncFromTmp();
19
+ bindLoaderTmpSync(this);
20
+ };
21
+ syncFromTmp = async () => {
22
+ await this.teardown();
23
+ if (this.#configs.all.isMongoPassive) {
24
+ return;
25
+ }
26
+ const uri = this.#configs.all.mongodbUri?.trim();
27
+ if (!uri) {
28
+ return;
29
+ }
30
+ const client = new MongoClient(uri, resolveMongoConnectOptions(uri));
31
+ await client.connect();
32
+ this.#client = client;
33
+ this.#db = client.db();
34
+ };
35
+ teardown = async () => {
36
+ if (!this.#client) {
37
+ return;
38
+ }
39
+ try {
40
+ await this.#client.close();
41
+ }
42
+ catch { }
43
+ this.#client = null;
44
+ this.#db = null;
45
+ };
46
+ get client() {
47
+ return this.#client;
48
+ }
49
+ get db() {
50
+ return this.#db;
51
+ }
52
+ }
@@ -1 +1,16 @@
1
- export function resolveMongoConnectOptions(e){if(!((e?.trim()??"").includes("tls=true")||process.env.MONGODB_SSL==="true"))return{};const t=process.env.MONGODB_SSL_CA||process.env.KAFKA_SSL_CA||"/etc/tls/infra/ca.crt",s=process.env.MONGODB_SSL_PEM||"/etc/tls/infra/mongodb.pem";return{tls:!0,tlsCAFile:t,tlsCertificateKeyFile:s,tlsAllowInvalidHostnames:!0}}
1
+ /** Private CA client TLS for bare-metal Mongo */
2
+ export function resolveMongoConnectOptions(mongodbUri) {
3
+ const uri = mongodbUri?.trim() ?? '';
4
+ const useTls = uri.includes('tls=true') || process.env.MONGODB_SSL === 'true';
5
+ if (!useTls) {
6
+ return {};
7
+ }
8
+ const caFile = process.env.MONGODB_SSL_CA || process.env.KAFKA_SSL_CA || '/etc/tls/infra/ca.crt';
9
+ const pemFile = process.env.MONGODB_SSL_PEM || '/etc/tls/infra/mongodb.pem';
10
+ return {
11
+ tls: true,
12
+ tlsCAFile: caFile,
13
+ tlsCertificateKeyFile: pemFile,
14
+ tlsAllowInvalidHostnames: true,
15
+ };
16
+ }
@@ -1 +1,57 @@
1
- export{resolveRedisSocketOptions}from "./resolve-socket.js";import{createClient as x}from"redis";import{bindLoaderTmpSync as z}from "../../utils/helpers/tmp/loader-tmp-sync.js";import{resolveRedisSocketOptions as A}from "./resolve-socket.js";export default class RedisForCore{#j=null;#w;#q;constructor({system:j,configs:q}){this.#w=j;this.#q=q}onDispose=async()=>{await this.teardown()};onInit=async()=>{await this.syncFromTmp();z(this)};syncFromTmp=async()=>{await this.teardown();if(this.#q.all.isRedisPassive)return;const j=this.#q.all.redisUri?.trim();if(!j)return;const q=x({url:j,socket:A(j)});q.on("error",(w)=>{console.error(`Redis ${w}`)});await q.connect();this.#j=q};teardown=async()=>{if(!this.#j)return;try{await this.#j.quit()}catch{try{await this.#j.disconnect()}catch{}}this.#j=null};get client(){return this.#j}}
1
+ export { resolveRedisSocketOptions } from './resolve-socket.js';
2
+ import { createClient } from 'redis';
3
+ import { bindLoaderTmpSync } from '../../utils/helpers/tmp/loader-tmp-sync.js';
4
+ import { resolveRedisSocketOptions } from './resolve-socket.js';
5
+ export default class RedisForCore {
6
+ #client = null;
7
+ #system;
8
+ #configs;
9
+ constructor({ system, configs, }) {
10
+ this.#system = system;
11
+ this.#configs = configs;
12
+ }
13
+ onDispose = async () => {
14
+ await this.teardown();
15
+ };
16
+ onInit = async () => {
17
+ await this.syncFromTmp();
18
+ bindLoaderTmpSync(this);
19
+ };
20
+ syncFromTmp = async () => {
21
+ await this.teardown();
22
+ if (this.#configs.all.isRedisPassive) {
23
+ return;
24
+ }
25
+ const uri = this.#configs.all.redisUri?.trim();
26
+ if (!uri) {
27
+ return;
28
+ }
29
+ const client = createClient({
30
+ url: uri,
31
+ socket: resolveRedisSocketOptions(uri),
32
+ });
33
+ client.on('error', (err) => {
34
+ console.error(`Redis ${err}`);
35
+ });
36
+ await client.connect();
37
+ this.#client = client;
38
+ };
39
+ teardown = async () => {
40
+ if (!this.#client) {
41
+ return;
42
+ }
43
+ try {
44
+ await this.#client.quit();
45
+ }
46
+ catch {
47
+ try {
48
+ await this.#client.disconnect();
49
+ }
50
+ catch { }
51
+ }
52
+ this.#client = null;
53
+ };
54
+ get client() {
55
+ return this.#client;
56
+ }
57
+ }
@@ -1 +1,31 @@
1
- import q from"node:fs";export function resolveRedisSocketOptions(w){const j={connectTimeout:1e4};if(!((w?.trim()??"").startsWith("rediss://")||process.env.REDIS_SSL==="true"))return j;const k=process.env.REDIS_SSL_CA||process.env.KAFKA_SSL_CA||"/etc/tls/infra/ca.crt";try{if(k&&q.existsSync(k))return{...j,tls:!0,ca:[q.readFileSync(k,"utf-8")],rejectUnauthorized:!1}}catch{}return{...j,tls:!0,rejectUnauthorized:!1}}
1
+ import fs from 'node:fs';
2
+ /** rediss:// + private CA from REDIS_SSL_CA / KAFKA_SSL_CA / infra-tls mount */
3
+ export function resolveRedisSocketOptions(redisUri) {
4
+ const base = {
5
+ connectTimeout: 10000,
6
+ };
7
+ const uri = redisUri?.trim() ?? '';
8
+ const useTls = uri.startsWith('rediss://') || process.env.REDIS_SSL === 'true';
9
+ if (!useTls) {
10
+ return base;
11
+ }
12
+ const caPath = process.env.REDIS_SSL_CA || process.env.KAFKA_SSL_CA || '/etc/tls/infra/ca.crt';
13
+ try {
14
+ if (caPath && fs.existsSync(caPath)) {
15
+ return {
16
+ ...base,
17
+ tls: true,
18
+ ca: [fs.readFileSync(caPath, 'utf-8')],
19
+ rejectUnauthorized: false,
20
+ };
21
+ }
22
+ }
23
+ catch {
24
+ // fall through
25
+ }
26
+ return {
27
+ ...base,
28
+ tls: true,
29
+ rejectUnauthorized: false,
30
+ };
31
+ }
@@ -1 +1 @@
1
- export*from "../../utils/helpers/registry/index.js";
1
+ export * from '../../utils/helpers/registry/index.js';
@@ -1 +1,7 @@
1
- export class BaseService{}export default class Service extends BaseService{constructor(){super()}async onInit(){}}
1
+ export class BaseService {
2
+ }
3
+ export default class Service extends BaseService {
4
+ constructor() { super(); }
5
+ async onInit() {
6
+ }
7
+ }
@@ -1 +1,26 @@
1
- import{G as k,notifyRuntimeTmpChange as q,onTmpReload as v,setRuntimeTmpConfigs as w}from "../../utils/index.js";import{normalizeTmpDocument as x}from "../../utils/helpers/tmp/tmp-schema.js";export default class System{_core={};_tmp={};cwd=process.cwd();g=k;onInit=async({core:j})=>{this._core=j;await this.applyTmp(this._core._);v((b)=>void this.applyTmp(b))};async applyTmp(j){this._tmp=x(j);const b=this._tmp.configs;w(b);this.g.configureFromTmp(this._tmp);await q(b)}get core(){return this._core}get tmp(){return this._tmp}}
1
+ import { G, notifyRuntimeTmpChange, onTmpReload, setRuntimeTmpConfigs, } from '../../utils/index.js';
2
+ import { normalizeTmpDocument } from '../../utils/helpers/tmp/tmp-schema.js';
3
+ export default class System {
4
+ _core = {};
5
+ _tmp = {};
6
+ cwd = process.cwd();
7
+ g = G;
8
+ onInit = async ({ core, }) => {
9
+ this._core = core;
10
+ await this.applyTmp(this._core._);
11
+ onTmpReload((tmp) => void this.applyTmp(tmp));
12
+ };
13
+ async applyTmp(tmp) {
14
+ this._tmp = normalizeTmpDocument(tmp);
15
+ const configs = this._tmp.configs;
16
+ setRuntimeTmpConfigs(configs);
17
+ this.g.configureFromTmp(this._tmp);
18
+ await notifyRuntimeTmpChange(configs);
19
+ }
20
+ get core() {
21
+ return this._core;
22
+ }
23
+ get tmp() {
24
+ return this._tmp;
25
+ }
26
+ }
@@ -1 +1,51 @@
1
- import A from"path";import{fileURLToPath as O}from"node:url";import{System as Q,Configs as V,Logger as W,Events as X,Localizations as Y,DtoRuntime as Z,Clients as _,Controller as $,KafkaForCore as v,RedisForCore as z,MongoForCore as K}from "../loader/index.js";import{Constants as U,getCore as b,x as j}from "../utils/index.js";import{ensureCoreTmpEntry as k,isCorePackageRoot as x}from "../utils/helpers/core/tmp-layout.js";import{getTmpSnapshot as G}from "../utils/helpers/tmp/tmp-loader.js";export{ensureCoreTmpEntry,isCorePackageRoot}from "../utils/helpers/core/tmp-layout.js";export{getTmpSnapshot}from "../utils/helpers/tmp/tmp-loader.js";export const core=b(),coreInit=async(B)=>{const{locales:q}=B;if(q)globalThis.__LOCAL_MESSAGES__=q};let I=!1;const J=A.dirname(O(import.meta.url)),H=A.join(J,"..","loader","**/*.{ts,js}"),P=A.join(J,"..","utils","**/class.x.{ts,js}"),S=async(B={})=>{if(I)return core;const q=process.cwd();if(x(q))k(q);G();try{await(await j.load([H],{exclude:[P]})).initialize([{service:Q,props:{core}},{service:V,props:{}},{service:v,props:{}},{service:z,props:{}},{service:K,props:{}},{service:W,props:{}},{service:X,props:{}},{service:Y,props:{}},{service:Z,props:{}},{service:$,props:{}},{service:_,props:{}}]);I=!0;return core}catch(w){const N=w instanceof Error?w.message:String(w);console.error(`[${U.packageName} core failure]: ${N}`);throw w}};export default S;
1
+ import path from 'path';
2
+ import { fileURLToPath } from 'node:url';
3
+ import { System, Configs, Logger, Events, Localizations, DtoRuntime, Clients, Controller, KafkaForCore, RedisForCore, MongoForCore, } from '../loader/index.js';
4
+ import { Constants, getCore, x } from '../utils/index.js';
5
+ import { ensureCoreTmpEntry, isCorePackageRoot } from '../utils/helpers/core/tmp-layout.js';
6
+ import { getTmpSnapshot } from '../utils/helpers/tmp/tmp-loader.js';
7
+ export { ensureCoreTmpEntry, isCorePackageRoot } from '../utils/helpers/core/tmp-layout.js';
8
+ export { getTmpSnapshot } from '../utils/helpers/tmp/tmp-loader.js';
9
+ export const core = getCore();
10
+ export const coreInit = async (params) => {
11
+ const { locales } = params;
12
+ if (locales)
13
+ globalThis.__LOCAL_MESSAGES__ = locales;
14
+ };
15
+ let coreHasRun = false;
16
+ const projectModuleDir = path.dirname(fileURLToPath(import.meta.url));
17
+ const loaderGlob = path.join(projectModuleDir, '..', 'loader', '**/*.{ts,js}');
18
+ const loaderExcludeGlob = path.join(projectModuleDir, '..', 'utils', '**/class.x.{ts,js}');
19
+ const coreLoader = async (_params = {}) => {
20
+ if (coreHasRun)
21
+ return core;
22
+ const root = process.cwd();
23
+ if (isCorePackageRoot(root))
24
+ ensureCoreTmpEntry(root);
25
+ getTmpSnapshot();
26
+ try {
27
+ await (await x.load([loaderGlob], {
28
+ exclude: [loaderExcludeGlob],
29
+ })).initialize([
30
+ { service: System, props: { core } },
31
+ { service: Configs, props: {} },
32
+ { service: KafkaForCore, props: {} },
33
+ { service: RedisForCore, props: {} },
34
+ { service: MongoForCore, props: {} },
35
+ { service: Logger, props: {} },
36
+ { service: Events, props: {} },
37
+ { service: Localizations, props: {} },
38
+ { service: DtoRuntime, props: {} },
39
+ { service: Controller, props: {} },
40
+ { service: Clients, props: {} },
41
+ ]);
42
+ coreHasRun = true;
43
+ return core;
44
+ }
45
+ catch (error) {
46
+ const errorMessage = error instanceof Error ? error.message : String(error);
47
+ console.error(`[${Constants.packageName} core failure]: ${errorMessage}`);
48
+ throw error;
49
+ }
50
+ };
51
+ export default coreLoader;
@@ -8,6 +8,7 @@
8
8
  "cliBinFile": "main-cli.js",
9
9
  "tmpBaseName": "tmp",
10
10
  "tmpExtension": ".yml",
11
+ "apiServiceTemplateRel": "x/templates/api-service/tmp.yml",
11
12
  "templateRepoUri": "https://github.com/xdloper/api-gpt-svc",
12
13
  "publicFolderName": "public",
13
14
  "kafkaLogsTopic": "log",
@@ -55,9 +56,10 @@
55
56
  "maxIntervalMs": 10000
56
57
  },
57
58
  "buildDefaults": {
59
+ "bundler": "auto",
58
60
  "tsconfig": "tsconfig.json",
59
61
  "typecheck": false,
60
- "tscLenient": false,
62
+ "tscLenient": true,
61
63
  "declarations": false,
62
64
  "sourcemap": false,
63
65
  "minify": false
@@ -39,6 +39,7 @@ export declare class Constants {
39
39
  static readonly cliBinFile: string;
40
40
  /** Prefer package name in logs/errors (not a short brand alias). */
41
41
  static readonly logTag: string;
42
+ static readonly bundledApiServiceTmpPath: string;
42
43
  static readonly bundledCoreTmpPath: string;
43
44
  }
44
45
  export { seedFromTmp, loadSeedFromBundledTmp } from '../../utils/helpers/tmp/seed-from-tmp';
@@ -1 +1,42 @@
1
- import w from"node:path";import{packageRootDir as x}from "../../utils/constants/package-root.js";import b from"./defaults.json" with { type: 'json' };import{seedFromTmp as j}from "../../utils/helpers/tmp/seed-from-tmp.js";export const packageDefaults=Object.freeze({...b,mainSourceFolder:j.sourceFolder,framework:j.framework,layoutPaths:Object.freeze({...j.layout}),brand:Object.freeze({...b.brand}),runtimes:Object.freeze(Object.fromEntries(Object.entries(b.runtimes).map(([n,q])=>[n,Object.freeze({...q})]))),bundlers:Object.freeze([...b.bundlers]),buildDefaults:Object.freeze({...b.buildDefaults}),tmpWatchDefaults:Object.freeze({...b.tmpWatchDefaults}),cliBinNames:Object.freeze([...b.cliBinNames??[b.cliName]])}),coreVersionPattern=/^\d{2}\.\d{2}\.\d{2}-v\d+$/,semverVersionPattern=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z-.]+)?(?:\+[0-9A-Za-z-.]+)?$/;const z=`${packageDefaults.tmpBaseName}${packageDefaults.tmpExtension}`;export class Constants{static packageName=packageDefaults.packageName;static packageRootFolder=packageDefaults.packageRootFolder;static tmpBaseName=packageDefaults.tmpBaseName;static tmpExtension=packageDefaults.tmpExtension;static publicFolderName=packageDefaults.publicFolderName;static kafkaLogsTopic=packageDefaults.kafkaLogsTopic;static templateRepoUri=packageDefaults.templateRepoUri;static cliName=packageDefaults.cliName;static cliBinNames=packageDefaults.cliBinNames;static pathAliasKey=packageDefaults.pathAliasKey;static brand=packageDefaults.brand;static mainSourceFolder=packageDefaults.mainSourceFolder;static framework=packageDefaults.framework;static layoutPaths=packageDefaults.layoutPaths;static cliBinFile=packageDefaults.cliBinFile;static logTag=packageDefaults.packageName;static bundledCoreTmpPath=w.join(x,packageDefaults.packageRootFolder,z)}export{seedFromTmp,loadSeedFromBundledTmp}from "../../utils/helpers/tmp/seed-from-tmp.js";
1
+ import path from 'node:path';
2
+ import { packageRootDir } from '../../utils/constants/package-root.js';
3
+ import defaults from './defaults.json' with { type: 'json' };
4
+ import { seedFromTmp } from '../../utils/helpers/tmp/seed-from-tmp.js';
5
+ export const packageDefaults = Object.freeze({
6
+ ...defaults,
7
+ mainSourceFolder: seedFromTmp.sourceFolder,
8
+ framework: seedFromTmp.framework,
9
+ layoutPaths: Object.freeze({ ...seedFromTmp.layout }),
10
+ brand: Object.freeze({ ...defaults.brand }),
11
+ runtimes: Object.freeze(Object.fromEntries(Object.entries(defaults.runtimes).map(([key, value]) => [key, Object.freeze({ ...value })]))),
12
+ bundlers: Object.freeze([...defaults.bundlers]),
13
+ buildDefaults: Object.freeze({ ...defaults.buildDefaults }),
14
+ tmpWatchDefaults: Object.freeze({ ...defaults.tmpWatchDefaults }),
15
+ cliBinNames: Object.freeze([...(defaults.cliBinNames ?? [defaults.cliName])]),
16
+ });
17
+ export const coreVersionPattern = /^\d{2}\.\d{2}\.\d{2}-v\d+$/;
18
+ export const semverVersionPattern = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z-.]+)?(?:\+[0-9A-Za-z-.]+)?$/;
19
+ const tmpFileName = `${packageDefaults.tmpBaseName}${packageDefaults.tmpExtension}`;
20
+ export class Constants {
21
+ static packageName = packageDefaults.packageName;
22
+ static packageRootFolder = packageDefaults.packageRootFolder;
23
+ static tmpBaseName = packageDefaults.tmpBaseName;
24
+ static tmpExtension = packageDefaults.tmpExtension;
25
+ static publicFolderName = packageDefaults.publicFolderName;
26
+ static kafkaLogsTopic = packageDefaults.kafkaLogsTopic;
27
+ static templateRepoUri = packageDefaults.templateRepoUri;
28
+ static cliName = packageDefaults.cliName;
29
+ static cliBinNames = packageDefaults.cliBinNames;
30
+ static pathAliasKey = packageDefaults.pathAliasKey;
31
+ static brand = packageDefaults.brand;
32
+ static mainSourceFolder = packageDefaults.mainSourceFolder;
33
+ static framework = packageDefaults.framework;
34
+ static layoutPaths = packageDefaults.layoutPaths;
35
+ static cliBinFile = packageDefaults.cliBinFile;
36
+ /** Prefer package name in logs/errors (not a short brand alias). */
37
+ static logTag = packageDefaults.packageName;
38
+ static bundledApiServiceTmpPath = path.join(packageRootDir, packageDefaults.apiServiceTemplateRel
39
+ ?? `${packageDefaults.packageRootFolder}/templates/api-service/${tmpFileName}`);
40
+ static bundledCoreTmpPath = path.join(packageRootDir, packageDefaults.packageRootFolder, tmpFileName);
41
+ }
42
+ export { seedFromTmp, loadSeedFromBundledTmp } from '../../utils/helpers/tmp/seed-from-tmp.js';
@@ -1 +1,6 @@
1
- import b from"node:path";import{fileURLToPath as w}from"node:url";const q=b.dirname(w(import.meta.url));export const sourceDir=b.resolve(q,"..",".."),packageRootDir=b.resolve(q,"..","..","..");
1
+ import path from 'node:path';
2
+ import { fileURLToPath } from 'node:url';
3
+ /** Resolve package / source roots from this file's location (next to defaults.json). */
4
+ const constantsDir = path.dirname(fileURLToPath(import.meta.url));
5
+ export const sourceDir = path.resolve(constantsDir, '..', '..');
6
+ export const packageRootDir = path.resolve(constantsDir, '..', '..', '..');
@@ -1 +1 @@
1
- export const configs={};
1
+ export const configs = {};
@@ -1 +1,12 @@
1
- import{AsyncLocalStorage as o}from"node:async_hooks";export const controllerContextStorage=new o,getControllerCtx=()=>controllerContextStorage.getStore(),runControllerStore=(t,e)=>controllerContextStorage.run(t,e);export function isFetchRequest(t){return typeof t==="object"&&t!==null&&t instanceof Request}export function adapterBagFromRequest(t){if(!t||isFetchRequest(t))return;return t}
1
+ import { AsyncLocalStorage } from 'node:async_hooks';
2
+ export const controllerContextStorage = new AsyncLocalStorage();
3
+ export const getControllerCtx = () => controllerContextStorage.getStore();
4
+ export const runControllerStore = (context, action) => controllerContextStorage.run(context, action);
5
+ export function isFetchRequest(value) {
6
+ return typeof value === 'object' && value !== null && value instanceof Request;
7
+ }
8
+ export function adapterBagFromRequest(value) {
9
+ if (!value || isFetchRequest(value))
10
+ return undefined;
11
+ return value;
12
+ }
@@ -1 +1,24 @@
1
- import{AsyncLocalStorage as w}from"node:async_hooks";export const runContextStorage=new w;export function getRunContext(){return runContextStorage.getStore()}export function getRequestId(){return getRunContext()?.requestId}export function runWithContext(m,j){return runContextStorage.run(m,j)}export function runWithRequestId(m,j,v="http"){return runWithContext({requestId:m,kind:v},j)}export function runWithTrace(m,j,v){return runWithContext({requestId:m,kind:"job",label:v},j)}export function patchRunContext(m){const j=getRunContext();if(!j)return;Object.assign(j,m)}export{controllerContextStorage,getControllerCtx,runControllerStore,adapterBagFromRequest,isFetchRequest}from "../../../utils/helpers/context/controller-store.js";
1
+ import { AsyncLocalStorage } from 'node:async_hooks';
2
+ export const runContextStorage = new AsyncLocalStorage();
3
+ export function getRunContext() {
4
+ return runContextStorage.getStore();
5
+ }
6
+ export function getRequestId() {
7
+ return getRunContext()?.requestId;
8
+ }
9
+ export function runWithContext(context, fn) {
10
+ return runContextStorage.run(context, fn);
11
+ }
12
+ export function runWithRequestId(requestId, fn, kind = 'http') {
13
+ return runWithContext({ requestId, kind }, fn);
14
+ }
15
+ export function runWithTrace(id, fn, label) {
16
+ return runWithContext({ requestId: id, kind: 'job', label }, fn);
17
+ }
18
+ export function patchRunContext(patch) {
19
+ const current = getRunContext();
20
+ if (!current)
21
+ return;
22
+ Object.assign(current, patch);
23
+ }
24
+ export { controllerContextStorage, getControllerCtx, runControllerStore, adapterBagFromRequest, isFetchRequest, } from '../../../utils/helpers/context/controller-store.js';
@@ -1 +1,15 @@
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
+ import Handlebars from 'handlebars';
2
+ /** Interpolate tmp.yml strings/objects with Handlebars (no utils barrel — safe for TmpFileLoader). */
3
+ export function resolveObjWithHandlebars(obj, context) {
4
+ if (typeof obj === 'string') {
5
+ const compileResult = Handlebars.compile(obj);
6
+ return compileResult(context);
7
+ }
8
+ if (typeof obj === 'object' && obj !== null) {
9
+ const record = obj;
10
+ for (const key in record) {
11
+ record[key] = resolveObjWithHandlebars(record[key], context);
12
+ }
13
+ }
14
+ return obj;
15
+ }