zaileys 3.1.0 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +2 -2
- package/dist/index.mjs +2 -2
- package/package.json +5 -2
- package/.changeset/README.md +0 -8
- package/.changeset/config.json +0 -11
- package/.kelar/kelar-tools.cjs +0 -829
- package/.kelar/memory/INDEX.md +0 -21
- package/.kelar/memory/technical/issue-34-sendpresenceupdate-undefined.md +0 -4
- package/.kelar/memory/technical/lmdb-native-binary-fallback.md +0 -4
- package/.kelar/memory/technical/nedbadapter-ignoring-encoder-causes-buffer-typing-crash-err-invalid-arg-type.md +0 -4
- package/.kelar/memory/technical/signal-media-constructor-input-contract.md +0 -4
- package/.kelar/memory/technical/sticker-example-source-format.md +0 -4
- package/.kelar/memory/technical/ts2307-missing-seald-io-nedb.md +0 -4
- package/.kelar/memory/technical/ts2307-missing-zaileys-store-adapters.md +0 -4
- package/.kelar/plans/README.md +0 -3
- package/.kelar/research/README.md +0 -3
- package/.kelar/research/mysql-adapter-research.md +0 -32
- package/.kelar/state/ASSUMPTIONS.md +0 -14
- package/.kelar/state/DEBT.md +0 -13
- package/.kelar/state/DIARY.md +0 -15
- package/.kelar/state/HANDOFF.md +0 -54
- package/.kelar/state/PATTERNS.md +0 -43
- package/.kelar/state/STATE.md +0 -37
- package/.kelar/state/TASKS.md +0 -146
- package/AGENTS.md +0 -108
- package/CHANGELOG.md +0 -12
- package/GEMINI.md +0 -58
- package/packages/media-process/CHANGELOG.md +0 -7
- package/packages/media-process/LICENSE +0 -21
- package/packages/media-process/dist/index.d.mts +0 -142
- package/packages/media-process/dist/index.d.ts +0 -142
- package/packages/media-process/dist/index.mjs +0 -3
- package/packages/media-process/package.json +0 -39
- package/packages/media-process/tsconfig.json +0 -15
- package/packages/mysql-adapter/dist/index.d.mts +0 -36
- package/packages/mysql-adapter/dist/index.d.ts +0 -36
- package/packages/mysql-adapter/dist/index.js.map +0 -1
- package/packages/mysql-adapter/dist/index.mjs +0 -101
- package/packages/mysql-adapter/dist/index.mjs.map +0 -1
- package/packages/mysql-adapter/package.json +0 -36
- package/pnpm-workspace.yaml +0 -3
- package/tsconfig.json +0 -19
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2022",
|
|
4
|
-
"module": "ESNext",
|
|
5
|
-
"moduleResolution": "bundler",
|
|
6
|
-
"declaration": true,
|
|
7
|
-
"strict": true,
|
|
8
|
-
"esModuleInterop": true,
|
|
9
|
-
"skipLibCheck": true,
|
|
10
|
-
"forceConsistentCasingInFileNames": true,
|
|
11
|
-
"outDir": "./dist",
|
|
12
|
-
"rootDir": "./src"
|
|
13
|
-
},
|
|
14
|
-
"include": ["src/**/*"]
|
|
15
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import mysql from 'mysql2/promise';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Interface definition copied from zaileys/src/Types/store.ts
|
|
5
|
-
* (Since we are in a sibling package, we'll keep it decoupled)
|
|
6
|
-
*/
|
|
7
|
-
interface IStoreAdapter {
|
|
8
|
-
get(id: string): Promise<any | null>;
|
|
9
|
-
set(id: string, value: any): Promise<void>;
|
|
10
|
-
del(id: string): Promise<void>;
|
|
11
|
-
}
|
|
12
|
-
interface MySQLAdapterOptions {
|
|
13
|
-
table?: string;
|
|
14
|
-
batchInterval?: number;
|
|
15
|
-
batchSize?: number;
|
|
16
|
-
}
|
|
17
|
-
declare class MySQLAdapter implements IStoreAdapter {
|
|
18
|
-
private pool;
|
|
19
|
-
private table;
|
|
20
|
-
private batchInterval;
|
|
21
|
-
private batchSize;
|
|
22
|
-
private writeBuffer;
|
|
23
|
-
private deleteBuffer;
|
|
24
|
-
private mutex;
|
|
25
|
-
private timer;
|
|
26
|
-
constructor(config: mysql.PoolOptions, options?: MySQLAdapterOptions);
|
|
27
|
-
private init;
|
|
28
|
-
private startTimer;
|
|
29
|
-
get(id: string): Promise<any | null>;
|
|
30
|
-
set(id: string, value: any): Promise<void>;
|
|
31
|
-
del(id: string): Promise<void>;
|
|
32
|
-
flush(): Promise<void>;
|
|
33
|
-
close(): Promise<void>;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export { type IStoreAdapter, MySQLAdapter, type MySQLAdapterOptions };
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import mysql from 'mysql2/promise';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Interface definition copied from zaileys/src/Types/store.ts
|
|
5
|
-
* (Since we are in a sibling package, we'll keep it decoupled)
|
|
6
|
-
*/
|
|
7
|
-
interface IStoreAdapter {
|
|
8
|
-
get(id: string): Promise<any | null>;
|
|
9
|
-
set(id: string, value: any): Promise<void>;
|
|
10
|
-
del(id: string): Promise<void>;
|
|
11
|
-
}
|
|
12
|
-
interface MySQLAdapterOptions {
|
|
13
|
-
table?: string;
|
|
14
|
-
batchInterval?: number;
|
|
15
|
-
batchSize?: number;
|
|
16
|
-
}
|
|
17
|
-
declare class MySQLAdapter implements IStoreAdapter {
|
|
18
|
-
private pool;
|
|
19
|
-
private table;
|
|
20
|
-
private batchInterval;
|
|
21
|
-
private batchSize;
|
|
22
|
-
private writeBuffer;
|
|
23
|
-
private deleteBuffer;
|
|
24
|
-
private mutex;
|
|
25
|
-
private timer;
|
|
26
|
-
constructor(config: mysql.PoolOptions, options?: MySQLAdapterOptions);
|
|
27
|
-
private init;
|
|
28
|
-
private startTimer;
|
|
29
|
-
get(id: string): Promise<any | null>;
|
|
30
|
-
set(id: string, value: any): Promise<void>;
|
|
31
|
-
del(id: string): Promise<void>;
|
|
32
|
-
flush(): Promise<void>;
|
|
33
|
-
close(): Promise<void>;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export { type IStoreAdapter, MySQLAdapter, type MySQLAdapterOptions };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { Mutex } from 'async-mutex';\nimport mysql, { Pool } from 'mysql2/promise';\n\n/**\n * Interface definition copied from zaileys/src/Types/store.ts\n * (Since we are in a sibling package, we'll keep it decoupled)\n */\nexport interface IStoreAdapter {\n get(id: string): Promise<any | null>;\n set(id: string, value: any): Promise<void>;\n del(id: string): Promise<void>;\n}\n\nexport interface MySQLAdapterOptions {\n table?: string;\n batchInterval?: number;\n batchSize?: number;\n}\n\nexport class MySQLAdapter implements IStoreAdapter {\n private pool: Pool;\n private table: string;\n private batchInterval: number;\n private batchSize: number;\n \n private writeBuffer = new Map<string, any>();\n private deleteBuffer = new Set<string>();\n private mutex = new Mutex();\n private timer: NodeJS.Timeout | null = null;\n\n constructor(config: mysql.PoolOptions, options: MySQLAdapterOptions = {}) {\n this.pool = mysql.createPool({\n ...config,\n waitForConnections: true,\n connectionLimit: 10,\n queueLimit: 0\n });\n\n this.table = options.table || 'zaileys_store';\n this.batchInterval = options.batchInterval || 1000;\n this.batchSize = options.batchSize || 500;\n\n this.init();\n }\n\n private async init() {\n await this.pool.execute(`\n CREATE TABLE IF NOT EXISTS \\`${this.table}\\` (\n \\`id\\` VARCHAR(255) PRIMARY KEY,\n \\`data\\` JSON NOT NULL,\n \\`updatedAt\\` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP\n )\n `);\n \n this.startTimer();\n }\n\n private startTimer() {\n if (this.timer) return;\n this.timer = setInterval(() => this.flush(), this.batchInterval);\n }\n\n async get(id: string): Promise<any | null> {\n // Check buffers first\n if (this.deleteBuffer.has(id)) return null;\n if (this.writeBuffer.has(id)) return this.writeBuffer.get(id);\n\n const [rows]: any = await this.pool.execute(\n `SELECT \\`data\\` FROM \\`${this.table}\\` WHERE \\`id\\` = ?`,\n [id]\n );\n\n return rows.length ? rows[0].data : null;\n }\n\n async set(id: string, value: any): Promise<void> {\n this.deleteBuffer.delete(id);\n this.writeBuffer.set(id, value);\n \n if (this.writeBuffer.size >= this.batchSize) {\n await this.flush();\n }\n }\n\n async del(id: string): Promise<void> {\n this.writeBuffer.delete(id);\n this.deleteBuffer.add(id);\n\n if (this.deleteBuffer.size >= this.batchSize) {\n await this.flush();\n }\n }\n\n async flush(): Promise<void> {\n if (this.writeBuffer.size === 0 && this.deleteBuffer.size === 0) return;\n\n await this.mutex.runExclusive(async () => {\n const writes = Array.from(this.writeBuffer.entries());\n const deletes = Array.from(this.deleteBuffer);\n\n // Reset buffers immediately\n this.writeBuffer.clear();\n this.deleteBuffer.clear();\n\n try {\n // Handle deletions\n if (deletes.length > 0) {\n await this.pool.query(\n `DELETE FROM \\`${this.table}\\` WHERE \\`id\\` IN (?)`,\n [deletes]\n );\n }\n\n // Handle upserts\n if (writes.length > 0) {\n const values = writes.map(([id, data]) => [id, JSON.stringify(data)]);\n await this.pool.query(\n `INSERT INTO \\`${this.table}\\` (\\`id\\`, \\`data\\`) VALUES ? \n ON DUPLICATE KEY UPDATE \\`data\\` = VALUES(\\`data\\`)`,\n [values]\n );\n }\n } catch (error) {\n console.error(`[MySQLAdapter] Flush failed:`, error);\n // Re-buffer on failure? (Optional: based on retry strategy)\n }\n });\n }\n\n async close() {\n if (this.timer) {\n clearInterval(this.timer);\n this.timer = null;\n }\n await this.flush();\n await this.pool.end();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAsB;AACtB,qBAA4B;AAkBrB,IAAM,eAAN,MAA4C;AAAA,EACzC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA,cAAc,oBAAI,IAAiB;AAAA,EACnC,eAAe,oBAAI,IAAY;AAAA,EAC/B,QAAQ,IAAI,yBAAM;AAAA,EAClB,QAA+B;AAAA,EAEvC,YAAY,QAA2B,UAA+B,CAAC,GAAG;AACxE,SAAK,OAAO,eAAAA,QAAM,WAAW;AAAA,MAC3B,GAAG;AAAA,MACH,oBAAoB;AAAA,MACpB,iB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G;AAEjE,UAAM,KAAK,MAAM,aAAa,YAAY;AACxC,YAAM,SAAS,MAAM,KAAK,KAAK,YAAY,QAAQ,CAAC;AACpD,YAAM,UAAU,MAAM,KAAK,KAAK,YAAY;AAG5C,WAAK,YAAY,MAAM;AACvB,WAAK,aAAa,MAAM;AAExB,UAAI;AAEF,YAAI,QAAQ,SAAS,GAAG;AACtB,gBAAM,KAAK,KAAK;AAAA,YACd,iBAAiB,KAAK,KAAK;AAAA,YAC3B,CAAC,OAAO;AAAA,UACV;AAAA,QACF;AAGA,YAAI,OAAO,SAAS,GAAG;AACrB,gBAAM,SAAS,OAAO,IAAI,CAAC,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,KAAK,UAAU,IAAI,CAAC,CAAC;AACpE,gBAAM,KAAK,KAAK;AAAA,YACd,iBAAiB,KAAK,KAAK;AAAA;AAAA,YAE3B,CAAC,MAAM;AAAA,UACT;AAAA,QACF;AAAA,MACF,SAAS,OAAO;AACd,gBAAQ,MAAM,gCAAgC,KAAK;AAAA,MAErD;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EAEA,MAAM,QAAQ;AACZ,QAAI,KAAK,OAAO;AACd,oBAAc,KAAK,KAAK;AACxB,WAAK,QAAQ;AAAA,IACf;AACA,UAAM,KAAK,MAAM;AACjB,UAAM,KAAK,KAAK,IAAI;AAAA,EACtB;AACF;","names":["mysql"]}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
// src/index.ts
|
|
2
|
-
import { Mutex } from "async-mutex";
|
|
3
|
-
import mysql from "mysql2/promise";
|
|
4
|
-
var MySQLAdapter = class {
|
|
5
|
-
pool;
|
|
6
|
-
table;
|
|
7
|
-
batchInterval;
|
|
8
|
-
batchSize;
|
|
9
|
-
writeBuffer = /* @__PURE__ */ new Map();
|
|
10
|
-
deleteBuffer = /* @__PURE__ */ new Set();
|
|
11
|
-
mutex = new Mutex();
|
|
12
|
-
timer = null;
|
|
13
|
-
constructor(config, options = {}) {
|
|
14
|
-
this.pool = mysql.createPool({
|
|
15
|
-
...config,
|
|
16
|
-
waitForConnections: true,
|
|
17
|
-
connectionLimit: 10,
|
|
18
|
-
queueLimit: 0
|
|
19
|
-
});
|
|
20
|
-
this.table = options.table || "zaileys_store";
|
|
21
|
-
this.batchInterval = options.batchInterval || 1e3;
|
|
22
|
-
this.batchSize = options.batchSize || 500;
|
|
23
|
-
this.init();
|
|
24
|
-
}
|
|
25
|
-
async init() {
|
|
26
|
-
await this.pool.execute(`
|
|
27
|
-
CREATE TABLE IF NOT EXISTS \`${this.table}\` (
|
|
28
|
-
\`id\` VARCHAR(255) PRIMARY KEY,
|
|
29
|
-
\`data\` JSON NOT NULL,
|
|
30
|
-
\`updatedAt\` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
|
31
|
-
)
|
|
32
|
-
`);
|
|
33
|
-
this.startTimer();
|
|
34
|
-
}
|
|
35
|
-
startTimer() {
|
|
36
|
-
if (this.timer) return;
|
|
37
|
-
this.timer = setInterval(() => this.flush(), this.batchInterval);
|
|
38
|
-
}
|
|
39
|
-
async get(id) {
|
|
40
|
-
if (this.deleteBuffer.has(id)) return null;
|
|
41
|
-
if (this.writeBuffer.has(id)) return this.writeBuffer.get(id);
|
|
42
|
-
const [rows] = await this.pool.execute(
|
|
43
|
-
`SELECT \`data\` FROM \`${this.table}\` WHERE \`id\` = ?`,
|
|
44
|
-
[id]
|
|
45
|
-
);
|
|
46
|
-
return rows.length ? rows[0].data : null;
|
|
47
|
-
}
|
|
48
|
-
async set(id, value) {
|
|
49
|
-
this.deleteBuffer.delete(id);
|
|
50
|
-
this.writeBuffer.set(id, value);
|
|
51
|
-
if (this.writeBuffer.size >= this.batchSize) {
|
|
52
|
-
await this.flush();
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
async del(id) {
|
|
56
|
-
this.writeBuffer.delete(id);
|
|
57
|
-
this.deleteBuffer.add(id);
|
|
58
|
-
if (this.deleteBuffer.size >= this.batchSize) {
|
|
59
|
-
await this.flush();
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
async flush() {
|
|
63
|
-
if (this.writeBuffer.size === 0 && this.deleteBuffer.size === 0) return;
|
|
64
|
-
await this.mutex.runExclusive(async () => {
|
|
65
|
-
const writes = Array.from(this.writeBuffer.entries());
|
|
66
|
-
const deletes = Array.from(this.deleteBuffer);
|
|
67
|
-
this.writeBuffer.clear();
|
|
68
|
-
this.deleteBuffer.clear();
|
|
69
|
-
try {
|
|
70
|
-
if (deletes.length > 0) {
|
|
71
|
-
await this.pool.query(
|
|
72
|
-
`DELETE FROM \`${this.table}\` WHERE \`id\` IN (?)`,
|
|
73
|
-
[deletes]
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
if (writes.length > 0) {
|
|
77
|
-
const values = writes.map(([id, data]) => [id, JSON.stringify(data)]);
|
|
78
|
-
await this.pool.query(
|
|
79
|
-
`INSERT INTO \`${this.table}\` (\`id\`, \`data\`) VALUES ?
|
|
80
|
-
ON DUPLICATE KEY UPDATE \`data\` = VALUES(\`data\`)`,
|
|
81
|
-
[values]
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
} catch (error) {
|
|
85
|
-
console.error(`[MySQLAdapter] Flush failed:`, error);
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
async close() {
|
|
90
|
-
if (this.timer) {
|
|
91
|
-
clearInterval(this.timer);
|
|
92
|
-
this.timer = null;
|
|
93
|
-
}
|
|
94
|
-
await this.flush();
|
|
95
|
-
await this.pool.end();
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
export {
|
|
99
|
-
MySQLAdapter
|
|
100
|
-
};
|
|
101
|
-
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { Mutex } from 'async-mutex';\nimport mysql, { Pool } from 'mysql2/promise';\n\n/**\n * Interface definition copied from zaileys/src/Types/store.ts\n * (Since we are in a sibling package, we'll keep it decoupled)\n */\nexport interface IStoreAdapter {\n get(id: string): Promise<any | null>;\n set(id: string, value: any): Promise<void>;\n del(id: string): Promise<void>;\n}\n\nexport interface MySQLAdapterOptions {\n table?: string;\n batchInterval?: number;\n batchSize?: number;\n}\n\nexport class MySQLAdapter implements IStoreAdapter {\n private pool: Pool;\n private table: string;\n private batchInterval: number;\n private batchSize: number;\n \n private writeBuffer = new Map<string, any>();\n private deleteBuffer = new Set<string>();\n private mutex = new Mutex();\n private timer: NodeJS.Timeout | null = null;\n\n constructor(config: mysql.PoolOptions, options: MySQLAdapterOptions = {}) {\n this.pool = mysql.createPool({\n ...config,\n waitForConnections: true,\n connectionLimit: 10,\n queueLimit: 0\n });\n\n this.table = options.table || 'zaileys_store';\n this.batchInterval = options.batchInterval || 1000;\n this.batchSize = options.batchSize || 500;\n\n this.init();\n }\n\n private async init() {\n await this.pool.execute(`\n CREATE TABLE IF NOT EXISTS \\`${this.table}\\` (\n \\`id\\` VARCHAR(255) PRIMARY KEY,\n \\`data\\` JSON NOT NULL,\n \\`updatedAt\\` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP\n )\n `);\n \n this.startTimer();\n }\n\n private startTimer() {\n if (this.timer) return;\n this.timer = setInterval(() => this.flush(), this.batchInterval);\n }\n\n async get(id: string): Promise<any | null> {\n // Check buffers first\n if (this.deleteBuffer.has(id)) return null;\n if (this.writeBuffer.has(id)) return this.writeBuffer.get(id);\n\n const [rows]: any = await this.pool.execute(\n `SELECT \\`data\\` FROM \\`${this.table}\\` WHERE \\`id\\` = ?`,\n [id]\n );\n\n return rows.length ? rows[0].data : null;\n }\n\n async set(id: string, value: any): Promise<void> {\n this.deleteBuffer.delete(id);\n this.writeBuffer.set(id, value);\n \n if (this.writeBuffer.size >= this.batchSize) {\n await this.flush();\n }\n }\n\n async del(id: string): Promise<void> {\n this.writeBuffer.delete(id);\n this.deleteBuffer.add(id);\n\n if (this.deleteBuffer.size >= this.batchSize) {\n await this.flush();\n }\n }\n\n async flush(): Promise<void> {\n if (this.writeBuffer.size === 0 && this.deleteBuffer.size === 0) return;\n\n await this.mutex.runExclusive(async () => {\n const writes = Array.from(this.writeBuffer.entries());\n const deletes = Array.from(this.deleteBuffer);\n\n // Reset buffers immediately\n this.writeBuffer.clear();\n this.deleteBuffer.clear();\n\n try {\n // Handle deletions\n if (deletes.length > 0) {\n await this.pool.query(\n `DELETE FROM \\`${this.table}\\` WHERE \\`id\\` IN (?)`,\n [deletes]\n );\n }\n\n // Handle upserts\n if (writes.length > 0) {\n const values = writes.map(([id, data]) => [id, JSON.stringify(data)]);\n await this.pool.query(\n `INSERT INTO \\`${this.table}\\` (\\`id\\`, \\`data\\`) VALUES ? \n ON DUPLICATE KEY UPDATE \\`data\\` = VALUES(\\`data\\`)`,\n [values]\n );\n }\n } catch (error) {\n console.error(`[MySQLAdapter] Flush failed:`, error);\n // Re-buffer on failure? (Optional: based on retry strategy)\n }\n });\n }\n\n async close() {\n if (this.timer) {\n clearInterval(this.timer);\n this.timer = null;\n }\n await this.flush();\n await this.pool.end();\n }\n}\n"],"mappings":";AAAA,SAAS,aAAa;AACtB,OAAO,WAAqB;AAkBrB,IAAM,eAAN,MAA4C;AAAA,EACzC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA,cAAc,oBAAI,IAAiB;AAAA,EACnC,eAAe,oBAAI,IAAY;AAAA,EAC/B,QAAQ,IAAI,MAAM;AAAA,EAClB,QAA+B;AAAA,EAEvC,YAAY,QAA2B,UAA+B,CAAC,GAAG;AACxE,SAAK,OAAO,MAAM,WAAW;AAAA,MAC3B,GAAG;AAAA,MACH,oBAAoB;AAAA,MACpB,iBAAiB;AAAA,MACjB,YAAY;AAAA,IACd,CAAC;AAED,SAAK,QAAQ,QAAQ,SAAS;AAC9B,SAAK,gBAAgB,QAAQ,iBAAiB;AAC9C,SAAK,YAAY,QAAQ,aAA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G5C,WAAK,YAAY,MAAM;AACvB,WAAK,aAAa,MAAM;AAExB,UAAI;AAEF,YAAI,QAAQ,SAAS,GAAG;AACtB,gBAAM,KAAK,KAAK;AAAA,YACd,iBAAiB,KAAK,KAAK;AAAA,YAC3B,CAAC,OAAO;AAAA,UACV;AAAA,QACF;AAGA,YAAI,OAAO,SAAS,GAAG;AACrB,gBAAM,SAAS,OAAO,IAAI,CAAC,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,KAAK,UAAU,IAAI,CAAC,CAAC;AACpE,gBAAM,KAAK,KAAK;AAAA,YACd,iBAAiB,KAAK,KAAK;AAAA;AAAA,YAE3B,CAAC,MAAM;AAAA,UACT;AAAA,QACF;AAAA,MACF,SAAS,OAAO;AACd,gBAAQ,MAAM,gCAAgC,KAAK;AAAA,MAErD;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EAEA,MAAM,QAAQ;AACZ,QAAI,KAAK,OAAO;AACd,oBAAc,KAAK,KAAK;AACxB,WAAK,QAAQ;AAAA,IACf;AACA,UAAM,KAAK,MAAM;AACjB,UAAM,KAAK,KAAK,IAAI;AAAA,EACtB;AACF;","names":[]}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@zaileys/mysql-adapter",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"description": "High-performance MySQL storage adapter for Zaileys",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"module": "dist/index.mjs",
|
|
7
|
-
"types": "dist/index.d.ts",
|
|
8
|
-
"files": [
|
|
9
|
-
"dist"
|
|
10
|
-
],
|
|
11
|
-
"scripts": {
|
|
12
|
-
"build": "tsup",
|
|
13
|
-
"dev": "tsup --watch"
|
|
14
|
-
},
|
|
15
|
-
"keywords": [
|
|
16
|
-
"baileys",
|
|
17
|
-
"whatsapp",
|
|
18
|
-
"mysql",
|
|
19
|
-
"storage",
|
|
20
|
-
"zaileys"
|
|
21
|
-
],
|
|
22
|
-
"author": "zaadevofc",
|
|
23
|
-
"license": "MIT",
|
|
24
|
-
"dependencies": {
|
|
25
|
-
"async-mutex": "^0.5.0",
|
|
26
|
-
"mysql2": "^3.12.0"
|
|
27
|
-
},
|
|
28
|
-
"devDependencies": {
|
|
29
|
-
"@types/node": "^20.11.0",
|
|
30
|
-
"tsup": "^8.0.2",
|
|
31
|
-
"typescript": "^5.3.3"
|
|
32
|
-
},
|
|
33
|
-
"peerDependencies": {
|
|
34
|
-
"baileys": "^7.0.0-rc.9"
|
|
35
|
-
}
|
|
36
|
-
}
|
package/pnpm-workspace.yaml
DELETED
package/tsconfig.json
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2022",
|
|
4
|
-
"module": "ESNext",
|
|
5
|
-
"declaration": true,
|
|
6
|
-
"declarationMap": true,
|
|
7
|
-
"sourceMap": true,
|
|
8
|
-
"outDir": "dist",
|
|
9
|
-
"strict": false,
|
|
10
|
-
"esModuleInterop": true,
|
|
11
|
-
"skipLibCheck": true,
|
|
12
|
-
"forceConsistentCasingInFileNames": true,
|
|
13
|
-
"moduleResolution": "bundler",
|
|
14
|
-
|
|
15
|
-
"typeRoots": ["node_modules/@types"]
|
|
16
|
-
},
|
|
17
|
-
"include": ["src/**/*"],
|
|
18
|
-
"exclude": ["node_modules", "dist", "**/*.test.ts", "**/*.spec.ts"]
|
|
19
|
-
}
|