gramstax 0.0.1 → 0.0.2
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/dist/src/index.cjs +2 -0
- package/dist/src/index.cjs.map +1 -0
- package/dist/src/{core/bot.d.ts → index.d.cts} +500 -12
- package/dist/src/index.d.ts +1292 -5
- package/dist/src/index.js +2 -4
- package/dist/src/index.js.map +1 -0
- package/package.json +10 -9
- package/dist/package.json +0 -52
- package/dist/src/base/general.d.ts +0 -7
- package/dist/src/base/general.d.ts.map +0 -1
- package/dist/src/base/general.js +0 -15
- package/dist/src/base/guard.d.ts +0 -13
- package/dist/src/base/guard.d.ts.map +0 -1
- package/dist/src/base/guard.js +0 -8
- package/dist/src/base/index.d.ts +0 -4
- package/dist/src/base/index.d.ts.map +0 -1
- package/dist/src/base/index.js +0 -3
- package/dist/src/base/page.d.ts +0 -263
- package/dist/src/base/page.d.ts.map +0 -1
- package/dist/src/base/page.js +0 -805
- package/dist/src/cache/external.d.ts +0 -10
- package/dist/src/cache/external.d.ts.map +0 -1
- package/dist/src/cache/external.js +0 -16
- package/dist/src/cache/index.d.ts +0 -2
- package/dist/src/cache/index.d.ts.map +0 -1
- package/dist/src/cache/index.js +0 -1
- package/dist/src/core/bot.d.ts.map +0 -1
- package/dist/src/core/bot.js +0 -465
- package/dist/src/core/ctx.d.ts +0 -60
- package/dist/src/core/ctx.d.ts.map +0 -1
- package/dist/src/core/ctx.js +0 -175
- package/dist/src/core/index.d.ts +0 -3
- package/dist/src/core/index.d.ts.map +0 -1
- package/dist/src/core/index.js +0 -2
- package/dist/src/grammy/index.d.ts +0 -2
- package/dist/src/grammy/index.d.ts.map +0 -1
- package/dist/src/grammy/index.js +0 -1
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/template/engine.d.ts +0 -34
- package/dist/src/template/engine.d.ts.map +0 -1
- package/dist/src/template/engine.js +0 -122
- package/dist/src/template/index.d.ts +0 -3
- package/dist/src/template/index.d.ts.map +0 -1
- package/dist/src/template/index.js +0 -2
- package/dist/src/template/manager.d.ts +0 -111
- package/dist/src/template/manager.d.ts.map +0 -1
- package/dist/src/template/manager.js +0 -237
- package/src/base/general.ts +0 -17
- package/src/base/guard.ts +0 -10
- package/src/base/index.ts +0 -3
- package/src/base/page.ts +0 -1111
- package/src/cache/external.ts +0 -15
- package/src/cache/index.ts +0 -1
- package/src/core/bot.ts +0 -535
- package/src/core/ctx.ts +0 -177
- package/src/core/index.ts +0 -2
- package/src/grammy/index.ts +0 -1
- package/src/index.ts +0 -4
- package/src/template/engine.ts +0 -167
- package/src/template/index.ts +0 -2
- package/src/template/manager.ts +0 -280
- package/src/types/page.d.ts +0 -4
package/dist/src/core/ctx.js
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import { setTimeout } from "node:timers/promises";
|
|
2
|
-
import { BaseGeneral } from "../base";
|
|
3
|
-
export class Ctx extends BaseGeneral {
|
|
4
|
-
ct;
|
|
5
|
-
templateManager;
|
|
6
|
-
cacheSession;
|
|
7
|
-
cacheKeyboard;
|
|
8
|
-
data = this.constructor.data; // for internal access (this.**). example this.data.callbackData
|
|
9
|
-
get isPremium() {
|
|
10
|
-
return this.ct.from?.is_premium ?? false;
|
|
11
|
-
}
|
|
12
|
-
get isBot() {
|
|
13
|
-
return this.ct.from?.is_bot ?? false;
|
|
14
|
-
}
|
|
15
|
-
get userid() {
|
|
16
|
-
return this.ct.from?.id;
|
|
17
|
-
}
|
|
18
|
-
get username() {
|
|
19
|
-
return this.ct.from?.username;
|
|
20
|
-
}
|
|
21
|
-
get fullname() {
|
|
22
|
-
return `${this.ct.from?.first_name || ``}${this.ct.from?.last_name || ``}`;
|
|
23
|
-
}
|
|
24
|
-
get firstname() {
|
|
25
|
-
return this.ct.from?.first_name;
|
|
26
|
-
}
|
|
27
|
-
get lastname() {
|
|
28
|
-
return this.ct.from?.last_name;
|
|
29
|
-
}
|
|
30
|
-
get msgText() {
|
|
31
|
-
return this.ct.message?.text;
|
|
32
|
-
}
|
|
33
|
-
get msgTextIntent() {
|
|
34
|
-
return this.msgText && this.msgText.indexOf(` `) != -1 ? this.msgText.split(` `)[0] : ``;
|
|
35
|
-
}
|
|
36
|
-
get msgTextPayloads() {
|
|
37
|
-
return this.msgText && this.msgText.indexOf(` `) != -1 ? this.msgText.split(` `).slice(1) : [];
|
|
38
|
-
}
|
|
39
|
-
get msgTextPayload() {
|
|
40
|
-
return this.msgTextPayloads[0];
|
|
41
|
-
}
|
|
42
|
-
get msgCaption() {
|
|
43
|
-
return this.ct.message?.caption;
|
|
44
|
-
}
|
|
45
|
-
get msgCaptionIntent() {
|
|
46
|
-
return this.msgCaption && this.msgCaption.indexOf(` `) != -1 ? this.msgCaption.split(` `)[0] : ``;
|
|
47
|
-
}
|
|
48
|
-
get msgPhoto() {
|
|
49
|
-
return this.ct.message?.photo;
|
|
50
|
-
}
|
|
51
|
-
get msgVideo() {
|
|
52
|
-
return this.ct.message?.video;
|
|
53
|
-
}
|
|
54
|
-
get msgAudio() {
|
|
55
|
-
return this.ct.message?.audio;
|
|
56
|
-
}
|
|
57
|
-
get callbackData() {
|
|
58
|
-
return this.ct.callbackQuery?.data;
|
|
59
|
-
}
|
|
60
|
-
get callbackDataIntent() {
|
|
61
|
-
return this.callbackData && this.callbackData.indexOf(`:`) != -1 ? this.callbackData.split(`:`)[0] : ``;
|
|
62
|
-
}
|
|
63
|
-
get callbackDataPayloads() {
|
|
64
|
-
return this.callbackData && this.callbackData.indexOf(`:`) != -1 ? this.callbackData.split(`:`).slice(1) : [];
|
|
65
|
-
}
|
|
66
|
-
get callbackDataPayload() {
|
|
67
|
-
return this.callbackDataPayloads?.[0];
|
|
68
|
-
}
|
|
69
|
-
get callbackDataParts() {
|
|
70
|
-
return this.callbackDataPayload && this.callbackDataPayload.indexOf(`+`) != -1 ? this.callbackDataPayload.split(`+`) : [];
|
|
71
|
-
}
|
|
72
|
-
get languageCode() {
|
|
73
|
-
return this.ct.from?.language_code;
|
|
74
|
-
}
|
|
75
|
-
set languageCode(v) {
|
|
76
|
-
;
|
|
77
|
-
this.ct.from.language_code = v;
|
|
78
|
-
}
|
|
79
|
-
session = {};
|
|
80
|
-
constructor(ct, templateManager, cacheSession, cacheKeyboard) {
|
|
81
|
-
super();
|
|
82
|
-
this.ct = ct;
|
|
83
|
-
this.templateManager = templateManager;
|
|
84
|
-
this.cacheSession = cacheSession;
|
|
85
|
-
this.cacheKeyboard = cacheKeyboard;
|
|
86
|
-
}
|
|
87
|
-
async broadcast(ids, languageCode, keyboard, data, baseId, options) {
|
|
88
|
-
const limitFree = 30;
|
|
89
|
-
const msgs = languageCode.map((it) => this.templateManager.getMessage(this.data.name, baseId, it, data));
|
|
90
|
-
for (let index = 0; index < ids.length; index++) {
|
|
91
|
-
const id = ids[index];
|
|
92
|
-
const msg = msgs[index];
|
|
93
|
-
await this.ct.api.sendMessage(id, msg, {
|
|
94
|
-
parse_mode: `HTML`,
|
|
95
|
-
reply_markup: keyboard,
|
|
96
|
-
...options
|
|
97
|
-
});
|
|
98
|
-
if (index + 1 == limitFree) {
|
|
99
|
-
await setTimeout(1200);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
async reply(keyboard, data, baseId, options) {
|
|
104
|
-
const msg = this.templateManager.getMessage(this.data.name, baseId, this.languageCode, data);
|
|
105
|
-
return await this.ct.reply(msg, {
|
|
106
|
-
parse_mode: `HTML`,
|
|
107
|
-
reply_markup: keyboard,
|
|
108
|
-
...options
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
async replyAction(type) {
|
|
112
|
-
return await this.ct.replyWithChatAction(type);
|
|
113
|
-
}
|
|
114
|
-
async edit(keyboard, data, baseId, options) {
|
|
115
|
-
try {
|
|
116
|
-
const msg = this.templateManager.getMessage(this.data.name, baseId, this.languageCode, data);
|
|
117
|
-
return await this.ct.editMessageText(msg, {
|
|
118
|
-
parse_mode: `HTML`,
|
|
119
|
-
reply_markup: keyboard,
|
|
120
|
-
...options
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
catch (error) {
|
|
124
|
-
await this.reply(keyboard, data, baseId, options);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
async delete() {
|
|
128
|
-
return await this.ct.deleteMessage();
|
|
129
|
-
}
|
|
130
|
-
async callbackQueryAnswer(options) {
|
|
131
|
-
try {
|
|
132
|
-
return await this.ct.answerCallbackQuery(options);
|
|
133
|
-
}
|
|
134
|
-
catch {
|
|
135
|
-
return null;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
async sessionSet(method, params, ...moreRoot) {
|
|
139
|
-
try {
|
|
140
|
-
const value = { method, params, ...moreRoot };
|
|
141
|
-
const result = await this.cacheSession.set(`${this.userid}`, { method, params, ...moreRoot });
|
|
142
|
-
if (result) {
|
|
143
|
-
this.session = value;
|
|
144
|
-
}
|
|
145
|
-
return result;
|
|
146
|
-
}
|
|
147
|
-
catch {
|
|
148
|
-
return null;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
async sessionGet() {
|
|
152
|
-
try {
|
|
153
|
-
const result = await this.cacheSession.get(`${this.userid}`);
|
|
154
|
-
if (result) {
|
|
155
|
-
this.session = result;
|
|
156
|
-
}
|
|
157
|
-
return result || null;
|
|
158
|
-
}
|
|
159
|
-
catch {
|
|
160
|
-
return null;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
async sessionClear() {
|
|
164
|
-
try {
|
|
165
|
-
const result = await this.cacheSession.delete(`${this.userid}`);
|
|
166
|
-
if (result) {
|
|
167
|
-
this.session = {};
|
|
168
|
-
}
|
|
169
|
-
return result;
|
|
170
|
-
}
|
|
171
|
-
catch {
|
|
172
|
-
return null;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}
|
package/dist/src/core/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAA;AACrB,cAAc,OAAO,CAAA"}
|
package/dist/src/core/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/grammy/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAA"}
|
package/dist/src/grammy/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "grammy";
|
package/dist/src/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAA;AACtB,cAAc,SAAS,CAAA;AACvB,cAAc,QAAQ,CAAA;AACtB,cAAc,YAAY,CAAA"}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
export declare class TemplateEngine {
|
|
2
|
-
static _escape(str: string): string;
|
|
3
|
-
static _processVariables(template: string): string;
|
|
4
|
-
static _processBaseBlocks(template: string): {
|
|
5
|
-
[baseId: string]: string;
|
|
6
|
-
};
|
|
7
|
-
static _processScriptBlocks(template: string): string;
|
|
8
|
-
static _processSpaceBlocks(template: string): string;
|
|
9
|
-
static _processDivBlocks(template: string): string;
|
|
10
|
-
static _processMessageBlocks(template: string): {
|
|
11
|
-
[lang: string]: string;
|
|
12
|
-
};
|
|
13
|
-
static _processKeyboardBlocks(template: string): {
|
|
14
|
-
[lang: string]: {
|
|
15
|
-
inline?: string;
|
|
16
|
-
default?: string;
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
static _compileToFunction<T extends boolean>(template: T extends true ? string[] : string, isArray: T): T extends true ? (data?: Record<string, any>) => string[] : (data?: Record<string, any>) => string;
|
|
20
|
-
static compileMessages(template: string): {
|
|
21
|
-
[baseId: string]: {
|
|
22
|
-
[lang: string]: (data?: Record<string, any>) => string;
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
static compileKeyboards(template: string): {
|
|
26
|
-
[baseId: string]: {
|
|
27
|
-
[lang: string]: {
|
|
28
|
-
inline?: (data?: Record<string, any>) => string[];
|
|
29
|
-
default?: (data?: Record<string, any>) => string[];
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
//# sourceMappingURL=engine.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../../src/template/engine.ts"],"names":[],"mappings":"AAAA,qBAAa,cAAc;WACX,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;WAM5B,iBAAiB,CAAC,QAAQ,EAAE,MAAM;WAIlC,kBAAkB,CAAC,QAAQ,EAAE,MAAM;;;WAoBnC,oBAAoB,CAAC,QAAQ,EAAE,MAAM;WASrC,mBAAmB,CAAC,QAAQ,EAAE,MAAM;WAIpC,iBAAiB,CAAC,QAAQ,EAAE,MAAM;WAUlC,qBAAqB,CAAC,QAAQ,EAAE,MAAM;;;WAkBtC,sBAAsB,CAAC,QAAQ,EAAE,MAAM;;qBAItC,MAAM;sBACL,MAAM;;;WAgBR,kBAAkB,CAAC,CAAC,SAAS,OAAO,EAAE,QAAQ,EAAE,CAAC,SAAS,IAAI,GAAG,MAAM,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,CAAC,GAAG,CAAC,SAAS,IAAI,GAAG,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,MAAM;WAqBnM,eAAe,CAAC,QAAQ,EAAE,MAAM;;oCAIhB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,MAAM;;;WAiB9C,gBAAgB,CAAC,QAAQ,EAAE,MAAM;;;yBAK9B,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,MAAM,EAAE;0BACvC,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,MAAM,EAAE;;;;CAyB3D"}
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
export class TemplateEngine {
|
|
2
|
-
static _escape(str) {
|
|
3
|
-
return str
|
|
4
|
-
.replace(/\\/g, `\\\\`) // escape backslash: \ → \\
|
|
5
|
-
.replace(/`/g, `\\\``); // escape backtick: ` → \`
|
|
6
|
-
}
|
|
7
|
-
static _processVariables(template) {
|
|
8
|
-
return template.replace(/\{\{(\w+)\}\}/g, (_, key) => `\${(data && data["${key}"]) ?? ""}`);
|
|
9
|
-
}
|
|
10
|
-
static _processBaseBlocks(template) {
|
|
11
|
-
const baseRegex = /<base\b[^>]*?(?:\sid=(["']?)([^"'\s>]+)\1)?[^>]*?>([\s\S]*?)<\/base>/g;
|
|
12
|
-
const result = {};
|
|
13
|
-
for (const match of template.matchAll(baseRegex)) {
|
|
14
|
-
const idValue = match[2] ?? `default`;
|
|
15
|
-
const inner = match[3] ?? ``;
|
|
16
|
-
const cleaned = inner
|
|
17
|
-
.replace(/^[\t ]+/gm, ``)
|
|
18
|
-
.replace(/^\n+/, ``)
|
|
19
|
-
.replace(/\n+$/, ``)
|
|
20
|
-
.trim();
|
|
21
|
-
result[idValue] = cleaned;
|
|
22
|
-
}
|
|
23
|
-
return result;
|
|
24
|
-
}
|
|
25
|
-
static _processScriptBlocks(template) {
|
|
26
|
-
return template.replace(/<script\b[^>]*>([\s\S]*?)<\/script>/gi, (_, rawCode) => {
|
|
27
|
-
const innerCode = rawCode.trim();
|
|
28
|
-
if (!innerCode)
|
|
29
|
-
return ``;
|
|
30
|
-
return `\${(() => { if (!data) return ''; try { with(data) { ${innerCode} } } catch(e) { return '' } })()}`;
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
static _processSpaceBlocks(template) {
|
|
34
|
-
return template.replace(/^[ \t]*<space\s*\/>[ \t]*$/gim, ``);
|
|
35
|
-
}
|
|
36
|
-
static _processDivBlocks(template) {
|
|
37
|
-
return template.replace(/<div>([\s\S]*?)<\/div>/gi, (_, inner) => {
|
|
38
|
-
const cleaned = inner
|
|
39
|
-
.replace(/^[\t ]+/gm, ``)
|
|
40
|
-
.replace(/^\n+/, ``)
|
|
41
|
-
.replace(/\n+$/, ``);
|
|
42
|
-
return cleaned;
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
static _processMessageBlocks(template) {
|
|
46
|
-
const messageRegex = /<message\s+lang="([^"]+)"\s*>([\s\S]*?)<\/message>/gi;
|
|
47
|
-
const result = {};
|
|
48
|
-
for (const [, lang, rawContent] of template.matchAll(messageRegex)) {
|
|
49
|
-
const cleaned = rawContent
|
|
50
|
-
.replace(/^[\t ]+/gm, ``)
|
|
51
|
-
.replace(/^\n+/, ``)
|
|
52
|
-
.replace(/\n+$/, ``)
|
|
53
|
-
.trim();
|
|
54
|
-
result[lang] = cleaned;
|
|
55
|
-
}
|
|
56
|
-
return result;
|
|
57
|
-
}
|
|
58
|
-
static _processKeyboardBlocks(template) {
|
|
59
|
-
const keyboardRegex = /<keyboard\b[^>]*\blang="([^"]*)"[^>]*?(?:\sfor="([^"]*)")?[^>]*>([\s\S]*?)<\/keyboard>/gi;
|
|
60
|
-
const result = {};
|
|
61
|
-
for (const [, lang, forAttr, rawContent] of template.matchAll(keyboardRegex)) {
|
|
62
|
-
const mode = forAttr === `default` ? `default` : `inline`;
|
|
63
|
-
const cleaned = rawContent.trim();
|
|
64
|
-
if (!result[lang]) {
|
|
65
|
-
result[lang] = {};
|
|
66
|
-
}
|
|
67
|
-
result[lang][mode] = cleaned;
|
|
68
|
-
}
|
|
69
|
-
return result;
|
|
70
|
-
}
|
|
71
|
-
static _compileToFunction(template, isArray) {
|
|
72
|
-
let singleOrCombined;
|
|
73
|
-
if (isArray) {
|
|
74
|
-
const multiTemplate = template;
|
|
75
|
-
singleOrCombined = multiTemplate.map((t) => `\`${t}\``).join(`,`);
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
singleOrCombined = `\`${template}\``;
|
|
79
|
-
}
|
|
80
|
-
let processed = singleOrCombined;
|
|
81
|
-
processed = this._processScriptBlocks(this._processDivBlocks(this._processSpaceBlocks(processed)));
|
|
82
|
-
if (isArray) {
|
|
83
|
-
const functionBody = `return [${processed}]`;
|
|
84
|
-
return new Function(`data`, functionBody);
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
const functionBody = `return ${processed}`;
|
|
88
|
-
return new Function(`data`, functionBody);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
static compileMessages(template) {
|
|
92
|
-
const baseBlocks = this._processBaseBlocks(template);
|
|
93
|
-
const result = {};
|
|
94
|
-
for (const [baseId, baseContent] of Object.entries(baseBlocks)) {
|
|
95
|
-
const messages = this._processMessageBlocks(baseContent);
|
|
96
|
-
result[baseId] = {};
|
|
97
|
-
for (const [lang, content] of Object.entries(messages)) {
|
|
98
|
-
const processed = this._processVariables(this._processScriptBlocks(content));
|
|
99
|
-
result[baseId][lang] = this._compileToFunction(processed, false);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
return result;
|
|
103
|
-
}
|
|
104
|
-
static compileKeyboards(template) {
|
|
105
|
-
const baseBlocks = this._processBaseBlocks(template);
|
|
106
|
-
const result = {};
|
|
107
|
-
for (const [baseId, baseContent] of Object.entries(baseBlocks)) {
|
|
108
|
-
const keyboards = this._processKeyboardBlocks(baseContent);
|
|
109
|
-
result[baseId] = {};
|
|
110
|
-
for (const [lang, modes] of Object.entries(keyboards)) {
|
|
111
|
-
result[baseId][lang] = {};
|
|
112
|
-
for (const [mode, content] of Object.entries(modes)) {
|
|
113
|
-
// Pisahkan label, handle escaped comma
|
|
114
|
-
const labels = content.split(/(?<!\\),\s*/).map((label) => label.replace(/\\,/g, `,`).trim());
|
|
115
|
-
const processedLabels = labels.map((label) => this._processVariables(this._processScriptBlocks(label)));
|
|
116
|
-
result[baseId][lang][mode] = this._compileToFunction(processedLabels, true);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
return result;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/template/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA"}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { TemplateEngine } from ".";
|
|
2
|
-
import { FSWatcher } from "chokidar";
|
|
3
|
-
/** Template file interface for better type safety */
|
|
4
|
-
type ICompiledTemplate = {
|
|
5
|
-
message: ReturnType<typeof TemplateEngine.compileMessages>;
|
|
6
|
-
keyboard: ReturnType<typeof TemplateEngine.compileKeyboards>;
|
|
7
|
-
};
|
|
8
|
-
/** Template loading options */
|
|
9
|
-
type ITemplateOptions = {
|
|
10
|
-
/** Enable file watching for hot reloading (if have templatePath) */
|
|
11
|
-
enableWatch?: boolean;
|
|
12
|
-
/** Base path for template files (set null if dont want read template from file) */
|
|
13
|
-
path?: string | undefined | null;
|
|
14
|
-
/** Force language params to this value */
|
|
15
|
-
forceLanguage?: string | undefined | null;
|
|
16
|
-
};
|
|
17
|
-
/** Template management system */
|
|
18
|
-
export declare class TemplateManager {
|
|
19
|
-
_map: Map<string, ICompiledTemplate>;
|
|
20
|
-
_engine: typeof TemplateEngine;
|
|
21
|
-
_watcher: FSWatcher | null;
|
|
22
|
-
_supportedExtensions: Set<string>;
|
|
23
|
-
readonly _path: string | null;
|
|
24
|
-
readonly _forceLanguage: string | null;
|
|
25
|
-
readonly _isWatchEnabled: boolean;
|
|
26
|
-
constructor(options?: ITemplateOptions);
|
|
27
|
-
/** Validate and ensure template directory exists. @returns Void */
|
|
28
|
-
_validatePath(): void;
|
|
29
|
-
/** Initialize file system watcher for hot reloading. @returns Void */
|
|
30
|
-
_initializeWatcher(): void;
|
|
31
|
-
/** Handle file change events */
|
|
32
|
-
_handleFileChange(filepath: string): Promise<void>;
|
|
33
|
-
/** Handle file add events */
|
|
34
|
-
_handleFileAdd(filePath: string): Promise<void>;
|
|
35
|
-
/** Handle file delete events */
|
|
36
|
-
_handleFileDelete(filePath: string): void;
|
|
37
|
-
/** Handle watcher errors */
|
|
38
|
-
_handleWatchError(error: any): void;
|
|
39
|
-
/** Load all Template files during initialization */
|
|
40
|
-
_loadAllFiles(): void;
|
|
41
|
-
/** Load and compile a single template file */
|
|
42
|
-
_loadFile(filename: string, useSync?: boolean): Promise<void>;
|
|
43
|
-
_isValidFile(filename: string): boolean;
|
|
44
|
-
_getKey(filename: string): string;
|
|
45
|
-
compile(key: string, rawTemplate: string, keepIfExist?: Partial<{
|
|
46
|
-
[K in keyof ICompiledTemplate]: boolean;
|
|
47
|
-
}>): void;
|
|
48
|
-
/**
|
|
49
|
-
* Get compiled message template
|
|
50
|
-
* @param key Template identifier (filename without extension)
|
|
51
|
-
* @param baseId Base id attr from block
|
|
52
|
-
* @param language Target language code
|
|
53
|
-
* @param data Template variables
|
|
54
|
-
* @returns Rendered message string
|
|
55
|
-
*/
|
|
56
|
-
getMessage(key: string, baseId?: string, language?: string, data?: Record<string, any>): string;
|
|
57
|
-
/**
|
|
58
|
-
* Get compiled keyboard template
|
|
59
|
-
* @param key Template identifier (filename without extension)
|
|
60
|
-
* @param baseId Base id attr from block
|
|
61
|
-
* @param language Target language code
|
|
62
|
-
* @param data Template variables
|
|
63
|
-
* @returns Array of rendered button labels
|
|
64
|
-
*/
|
|
65
|
-
getKeyboard(key: string, baseId?: string, language?: string, display?: `inline` | `default`, data?: Record<string, any>): string[];
|
|
66
|
-
/**
|
|
67
|
-
* Update message template in memory
|
|
68
|
-
* @param key Template identifier (filename without extension)
|
|
69
|
-
* @param rawTemplate Raw template string
|
|
70
|
-
*/
|
|
71
|
-
setMessage(key: string, rawTemplate: string): void;
|
|
72
|
-
/**
|
|
73
|
-
* Update keyboard template in memory
|
|
74
|
-
* @param key Template identifier (filename without extension)
|
|
75
|
-
* @param rawTemplate Raw template string
|
|
76
|
-
*/
|
|
77
|
-
setKeyboard(key: string, rawTemplate: string): void;
|
|
78
|
-
/**
|
|
79
|
-
* Write template to file and update cache
|
|
80
|
-
* @param filename Target filename (with extension)
|
|
81
|
-
* @param rawTemplate Template to write
|
|
82
|
-
* @returns Promise that resolves when file is written
|
|
83
|
-
*/
|
|
84
|
-
write(filename: string, rawTemplate: string): Promise<void>;
|
|
85
|
-
/**
|
|
86
|
-
* Get list of available template
|
|
87
|
-
* @returns Array of template names
|
|
88
|
-
*/
|
|
89
|
-
getAvailable(): string[];
|
|
90
|
-
/**
|
|
91
|
-
* Check if template exists
|
|
92
|
-
* @param key Template identifier
|
|
93
|
-
* @returns True if template exists
|
|
94
|
-
*/
|
|
95
|
-
has(key: string): boolean;
|
|
96
|
-
/**
|
|
97
|
-
* Get cache statistics
|
|
98
|
-
* @returns Object with cache information
|
|
99
|
-
*/
|
|
100
|
-
getCacheStats(): {
|
|
101
|
-
templateCount: number;
|
|
102
|
-
totalSize: number;
|
|
103
|
-
};
|
|
104
|
-
/**
|
|
105
|
-
* Cleanup resources and close watchers
|
|
106
|
-
* @returns Promise void
|
|
107
|
-
*/
|
|
108
|
-
destroy(): Promise<void>;
|
|
109
|
-
}
|
|
110
|
-
export {};
|
|
111
|
-
//# sourceMappingURL=manager.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../../src/template/manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,GAAG,CAAA;AAElC,OAAO,EAAS,SAAS,EAAE,MAAM,UAAU,CAAA;AAI3C,qDAAqD;AACrD,KAAK,iBAAiB,GAAG;IACvB,OAAO,EAAE,UAAU,CAAC,OAAO,cAAc,CAAC,eAAe,CAAC,CAAA;IAC1D,QAAQ,EAAE,UAAU,CAAC,OAAO,c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