@alloy-framework/core 0.4.0 β†’ 0.14.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.
@@ -1,171 +0,0 @@
1
- import native from '@alloy-framework/rust';
2
-
3
- /**
4
- * πŸ—οΈ Alloy μ„œλΉ„μŠ€ 기반 클래슀
5
- * Cache, Lock, Task λ“± λ„€μ΄ν‹°λΈŒ μœ ν‹Έλ¦¬ν‹°λ₯Ό μ œκ³΅ν•˜λŠ” λΉ„μ¦ˆλ‹ˆμŠ€ μ„œλΉ„μŠ€ 기반 ν΄λž˜μŠ€μž…λ‹ˆλ‹€.
6
- * 도메인 μ„œλΉ„μŠ€λŠ” 이 클래슀λ₯Ό μƒμ†ν•˜μ—¬ μ‚¬μš©ν•©λ‹ˆλ‹€.
7
- *
8
- * @example
9
- * class UserService extends AlloyService {
10
- * async getUser(id) {
11
- * return this.withCache(`user:${id}`, 300, async () => {
12
- * return await UserModel.findById(id);
13
- * });
14
- * }
15
- * }
16
- */
17
- export class AlloyService {
18
- constructor() {
19
- /** @type {import('@alloy/rust').AlloyService} λ„€μ΄ν‹°λΈŒ μ„œλΉ„μŠ€ μΈμŠ€ν„΄μŠ€ */
20
- this._native = new native.AlloyService();
21
- }
22
-
23
- // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
24
- // πŸ”§ μœ ν‹Έλ¦¬ν‹°
25
- // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
26
-
27
- /**
28
- * 에코 ν…ŒμŠ€νŠΈ (λ„€μ΄ν‹°λΈŒ μ—°κ²° ν™•μΈμš©)
29
- * @param {string} msg - 에코 λ©”μ‹œμ§€
30
- * @returns {string} "Native Echo: {msg}"
31
- */
32
- echo(msg) {
33
- return this._native.echo(msg);
34
- }
35
-
36
- /**
37
- * CPU 집약적 μž‘μ—…μ„ λ„€μ΄ν‹°λΈŒ μŠ€λ ˆλ“œν’€μ—μ„œ μ‹€ν–‰
38
- * @param {string} name - μž‘μ—… 이름
39
- * @param {number} difficulty - λ‚œμ΄λ„
40
- * @returns {Promise<string>} μž‘μ—… κ²°κ³Ό
41
- */
42
- runTask(name, difficulty) {
43
- return this._native.runTask(name, difficulty);
44
- }
45
-
46
- /**
47
- * λ°°μ—΄μ˜ 각 ν•­λͺ©μ— λŒ€ν•΄ 비동기 ν•¨μˆ˜λ₯Ό 병렬 μ‹€ν–‰
48
- * fn이 μ—†μœΌλ©΄ itemsλ₯Ό Promise λ°°μ—΄λ‘œ κ°„μ£Όν•˜μ—¬ 직접 ν•΄μ†Œ
49
- *
50
- * @param {Array} items - μ²˜λ¦¬ν•  ν•­λͺ© λ°°μ—΄ λ˜λŠ” Promise λ°°μ—΄
51
- * @param {Function} [fn] - 각 ν•­λͺ©μ— μ μš©ν•  비동기 ν•¨μˆ˜ (item, index) => Promise (μƒλž΅ κ°€λŠ₯)
52
- * @param {object} [options] - μ˜΅μ…˜ { settled: false }
53
- * @param {boolean} [options.settled=false] - trueλ©΄ Promise.allSettled μ‚¬μš© (λΆ€λΆ„ μ‹€νŒ¨ ν—ˆμš©)
54
- * @returns {Promise<Array>} 병렬 μ‹€ν–‰ κ²°κ³Ό λ°°μ—΄ (μž…λ ₯ μˆœμ„œ μœ μ§€)
55
- *
56
- * @example
57
- * // νŒ¨ν„΄ 1: λ°°μ—΄ + λ§€ν•‘ ν•¨μˆ˜
58
- * const enriched = await this.runParallel(posts, async (post) => {
59
- * const author = await UserModel.findById(post.user_id);
60
- * return { ...post, author_name: author?.nickname };
61
- * });
62
- *
63
- * // νŒ¨ν„΄ 2: Promise λ°°μ—΄ 직접 ν•΄μ†Œ
64
- * const [users, count] = await this.runParallel([fetchUsers(), fetchCount()]);
65
- *
66
- * // νŒ¨ν„΄ 3: λΆ€λΆ„ μ‹€νŒ¨ ν—ˆμš©
67
- * const results = await this.runParallel(items, fetchItem, { settled: true });
68
- */
69
- async runParallel(items, fn, options = {}) {
70
- const resolver = options.settled ? Promise.allSettled.bind(Promise) : Promise.all.bind(Promise);
71
- // fn이 μ—†μœΌλ©΄ itemsλ₯Ό Promise λ°°μ—΄λ‘œ κ°„μ£Ό
72
- if (!fn) return resolver(items);
73
- return resolver(items.map((item, index) => fn(item, index)));
74
- }
75
-
76
- // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
77
- // πŸ“¦ μΊμ‹œ (Redis, λ©”λͺ¨λ¦¬ 폴백)
78
- // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
79
-
80
- /**
81
- * μΊμ‹œ μ €μž₯
82
- * @param {string} key - μΊμ‹œ ν‚€
83
- * @param {string} value - κ°’ (λ¬Έμžμ—΄)
84
- * @param {number} ttlSeconds - TTL (초)
85
- * @returns {Promise<void>}
86
- */
87
- async setCache(key, value, ttlSeconds) {
88
- return await this._native.setCache(key, String(value), ttlSeconds);
89
- }
90
-
91
- /**
92
- * μΊμ‹œ 쑰회
93
- * @param {string} key - μΊμ‹œ ν‚€
94
- * @returns {Promise<string|null>}
95
- */
96
- async getCache(key) {
97
- return await this._native.getCache(key);
98
- }
99
-
100
- /**
101
- * μΊμ‹œ 래퍼 β€” μΊμ‹œ miss μ‹œ fetcher 호좜 ν›„ μ €μž₯
102
- * @param {string} key - μΊμ‹œ ν‚€
103
- * @param {number} ttlSeconds - TTL (초)
104
- * @param {Function} fetcher - 데이터 쑰회 ν•¨μˆ˜
105
- * @returns {Promise<any>} μΊμ‹œλœ λ˜λŠ” μ‹ κ·œ 쑰회 데이터
106
- */
107
- async withCache(key, ttlSeconds, fetcher) {
108
- try {
109
- const cached = await this.getCache(key);
110
- if (cached) {
111
- return JSON.parse(cached);
112
- }
113
- } catch (e) {
114
- console.warn(`[AlloyService] μΊμ‹œ 읽기 μ‹€νŒ¨ (${key}):`, e.message);
115
- }
116
-
117
- // μΊμ‹œ miss β†’ fetcher μ‹€ν–‰
118
- const data = await fetcher();
119
-
120
- if (data !== undefined && data !== null) {
121
- try {
122
- await this.setCache(key, JSON.stringify(data), ttlSeconds);
123
- } catch (e) {
124
- console.warn(`[AlloyService] μΊμ‹œ μ €μž₯ μ‹€νŒ¨ (${key}):`, e.message);
125
- }
126
- }
127
-
128
- return data;
129
- }
130
-
131
- // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
132
- // πŸ” λΆ„μ‚° 락 (Redis)
133
- // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
134
-
135
- /**
136
- * λ„€νŠΈμ›Œν¬ λΆ„μ‚° 락 νšλ“ (Redis SET NX PX)
137
- * @param {string} resource - λ¦¬μ†ŒμŠ€ ν‚€
138
- * @param {number} [ttlMs=5000] - TTL (λ°€λ¦¬μ΄ˆ)
139
- * @returns {Promise<boolean>} νšλ“ 성곡 μ—¬λΆ€
140
- */
141
- async acquireNetworkLock(resource, ttlMs = 5000) {
142
- return await this._native.acquireNetworkLock(resource, ttlMs);
143
- }
144
-
145
- /**
146
- * λ„€νŠΈμ›Œν¬ λΆ„μ‚° 락 ν•΄μ œ
147
- * @param {string} resource - λ¦¬μ†ŒμŠ€ ν‚€
148
- * @returns {Promise<void>}
149
- */
150
- async releaseNetworkLock(resource) {
151
- return await this._native.releaseNetworkLock(resource);
152
- }
153
-
154
- /**
155
- * 둜컬 ν”„λ‘œμ„ΈμŠ€ 락 νšλ“ (인메λͺ¨λ¦¬)
156
- * @param {string} resource - λ¦¬μ†ŒμŠ€ ν‚€
157
- * @param {number} [ttlMs=5000] - TTL (λ°€λ¦¬μ΄ˆ)
158
- * @returns {boolean} νšλ“ 성곡 μ—¬λΆ€
159
- */
160
- acquireLocalLock(resource, ttlMs = 5000) {
161
- return this._native.acquireLocalLock(resource, ttlMs);
162
- }
163
-
164
- /**
165
- * 둜컬 ν”„λ‘œμ„ΈμŠ€ 락 ν•΄μ œ
166
- * @param {string} resource - λ¦¬μ†ŒμŠ€ ν‚€
167
- */
168
- releaseLocalLock(resource) {
169
- this._native.releaseLocalLock(resource);
170
- }
171
- }
@@ -1,23 +0,0 @@
1
- /**
2
- * 🚨 Alloy ν‘œμ€€ μ—λŸ¬ 클래슀
3
- * HTTP μƒνƒœ μ½”λ“œμ™€ μ—λŸ¬ μ½”λ“œλ₯Ό ν¬ν•¨ν•˜λŠ” κ΅¬μ‘°ν™”λœ μ—λŸ¬μž…λ‹ˆλ‹€.
4
- *
5
- * @example
6
- * throw new AlloyError('AUTH_SESSION_EXPIRED', 'μ„Έμ…˜μ΄ λ§Œλ£Œλ˜μ—ˆμŠ΅λ‹ˆλ‹€', 401);
7
- */
8
- export class AlloyError extends Error {
9
- /**
10
- * @param {string} code - μ—λŸ¬ μ½”λ“œ (예: 'AUTH_SESSION_EXPIRED')
11
- * @param {string} [message] - μ‚¬λžŒμ΄ 읽을 수 μžˆλŠ” λ©”μ‹œμ§€ (κΈ°λ³Έκ°’: code)
12
- * @param {number} [statusCode=500] - HTTP μƒνƒœ μ½”λ“œ
13
- */
14
- constructor(code, message, statusCode = 500) {
15
- super(message || code);
16
- /** @type {string} μ—λŸ¬ 이름 */
17
- this.name = 'AlloyError';
18
- /** @type {string} μ—λŸ¬ μ½”λ“œ */
19
- this.code = code;
20
- /** @type {number} HTTP μƒνƒœ μ½”λ“œ */
21
- this.statusCode = statusCode;
22
- }
23
- }
@@ -1,39 +0,0 @@
1
- /**
2
- * πŸ“„ νŽ˜μ΄μ§€λ„€μ΄μ…˜ μœ ν‹Έλ¦¬ν‹°
3
- * μ„œλΉ„μŠ€ λ ˆμ΄μ–΄μ—μ„œ λͺ©λ‘ 쑰회 μ‹œ κ³΅ν†΅μœΌλ‘œ μ‚¬μš©ν•©λ‹ˆλ‹€.
4
- */
5
-
6
- /**
7
- * νŽ˜μ΄μ§€/μ‚¬μ΄μ¦ˆλ₯Ό offset/limit으둜 λ³€ν™˜
8
- * @param {number} [page=1] - ν˜„μž¬ νŽ˜μ΄μ§€ (1λΆ€ν„°)
9
- * @param {number} [size=20] - νŽ˜μ΄μ§€λ‹Ή ν•­λͺ© 수
10
- * @returns {{ offset: number, limit: number }}
11
- */
12
- export function paginate(page = 1, size = 20) {
13
- const safePage = Math.max(1, Math.floor(page)); // μ΅œμ†Œ 1νŽ˜μ΄μ§€
14
- const safeSize = Math.min(100, Math.max(1, Math.floor(size))); // 1~100 λ²”μœ„ μ œν•œ
15
- return {
16
- offset: (safePage - 1) * safeSize,
17
- limit: safeSize,
18
- };
19
- }
20
-
21
- /**
22
- * νŽ˜μ΄μ§€λ„€μ΄μ…˜ 응닡 ꡬ성
23
- * @param {Array} items - 쑰회된 ν•­λͺ© λ°°μ—΄
24
- * @param {number} total - 전체 ν•­λͺ© 수
25
- * @param {number} page - ν˜„μž¬ νŽ˜μ΄μ§€
26
- * @param {number} size - νŽ˜μ΄μ§€λ‹Ή ν•­λͺ© 수
27
- * @returns {{ items: Array, total: number, page: number, size: number, totalPages: number }}
28
- */
29
- export function buildResponse(items, total, page, size) {
30
- const safePage = Math.max(1, Math.floor(page));
31
- const safeSize = Math.min(100, Math.max(1, Math.floor(size)));
32
- return {
33
- items,
34
- total,
35
- page: safePage,
36
- size: safeSize,
37
- totalPages: Math.ceil(total / safeSize), // 전체 νŽ˜μ΄μ§€ 수
38
- };
39
- }
package/src/util/index.js DELETED
@@ -1,6 +0,0 @@
1
- /**
2
- * πŸ”§ 곡용 μœ ν‹Έλ¦¬ν‹° λͺ¨λ“ˆ
3
- * AlloyError, Pagination λ“± ν”„λ ˆμž„μ›Œν¬ λ²”μš© μœ ν‹Έλ¦¬ν‹°λ₯Ό 톡합 export ν•©λ‹ˆλ‹€.
4
- */
5
- export { AlloyError } from './AlloyError.js';
6
- export { paginate, buildResponse } from './Pagination.js';
@@ -1,130 +0,0 @@
1
- // native λͺ¨λ“ˆμ€ AlloyAppμ—μ„œ constructor νŒŒλΌλ―Έν„°λ‘œ μ£Όμž…λ°›μŒ (λͺ¨λ“ˆ 레벨 import λΆˆν•„μš”)
2
-
3
- /**
4
- * πŸ”Œ Alloy WebSocket 래퍼
5
- * Rust λ„€μ΄ν‹°λΈŒ WebSocket μ„Έμ…˜μ„ JSμ—μ„œ 닀루기 μ‰½κ²Œ λž˜ν•‘ν•©λ‹ˆλ‹€.
6
- * AlloyApp의 ws.onConnect μ½œλ°±μ—μ„œ μžλ™ μƒμ„±λ©λ‹ˆλ‹€.
7
- *
8
- * @example
9
- * app.ws({
10
- * onConnect(socket) {
11
- * socket.send({ type: 'welcome', data: 'Hello!' });
12
- * },
13
- * onMessage(socket, message) {
14
- * socket.broadcast({ type: 'chat', data: message });
15
- * },
16
- * });
17
- */
18
- export class AlloyWebSocket {
19
- /**
20
- * @param {string} id - μ„Έμ…˜ ID (Rustμ—μ„œ UUID μžλ™ 생성)
21
- * @param {object} native - λ„€μ΄ν‹°λΈŒ λͺ¨λ“ˆ μ°Έμ‘°
22
- * @param {object} [connectionData] - μ—°κ²° 메타데이터
23
- */
24
- constructor(id, native, connectionData = {}) {
25
- /** @type {string} μ„Έμ…˜ ID */
26
- this.id = id;
27
- /** @type {object} λ„€μ΄ν‹°λΈŒ λͺ¨λ“ˆ μ°Έμ‘° */
28
- this.native = native;
29
- /** @type {string} μ—°κ²° μœ ν˜• ('local' | 'remote') */
30
- this.connectionType = connectionData.type || connectionData.connectionType || 'local';
31
- /** @type {string} ν΄λΌμ΄μ–ΈνŠΈ IP */
32
- this.clientIp = connectionData.ip || connectionData.clientIp || 'unknown';
33
- /** @type {string} μ—°κ²° μ‹œκ° */
34
- this.connectedAt = connectionData.connected_at || connectionData.connectedAt || new Date().toISOString();
35
- /** @type {string} μ„œλ²„ ID */
36
- this.server = connectionData.server || null;
37
- /** @type {object} HTTP μΏ ν‚€ (μ„Έμ…˜ ID μΆ”μΆœμš©) */
38
- this.cookies = connectionData.cookies || {};
39
- }
40
-
41
- // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
42
- // πŸ“¨ λ©”μ‹œμ§€ 전솑
43
- // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
44
-
45
- /**
46
- * 이 μ†ŒμΌ“μ—κ²Œ λ©”μ‹œμ§€ 전솑
47
- * @param {string|object} msg - 전솑할 λ©”μ‹œμ§€ (κ°μ²΄λŠ” JSON λ³€ν™˜)
48
- */
49
- send(msg) {
50
- const payload = (typeof msg === 'object') ? JSON.stringify(msg) : String(msg);
51
- if (this.native.sendTo) {
52
- this.native.sendTo(this.id, payload);
53
- } else {
54
- console.warn('⚠️ native.sendTo not available');
55
- }
56
- }
57
-
58
- /**
59
- * 전체 ν΄λΌμ΄μ–ΈνŠΈμ—κ²Œ λΈŒλ‘œλ“œμΊμŠ€νŠΈ (NATS 경유 ν¬λ‘œμŠ€μ„œλ²„)
60
- * @param {string|object} msg - 전솑할 λ©”μ‹œμ§€
61
- */
62
- broadcast(msg) {
63
- const payload = (typeof msg === 'object') ? JSON.stringify(msg) : String(msg);
64
- this.native.broadcast(payload);
65
- }
66
-
67
- /**
68
- * νŠΉμ • λŒ€μƒμ—κ²Œ λ‹€μ΄λ ‰νŠΈ λ©”μ‹œμ§€ 전솑 (NATS 경유 ν¬λ‘œμŠ€μ„œλ²„)
69
- * @param {string} targetId - λŒ€μƒ μ„Έμ…˜ ID
70
- * @param {string|object} msg - 전솑할 λ©”μ‹œμ§€
71
- */
72
- sendTo(targetId, msg) {
73
- const payload = (typeof msg === 'object') ? JSON.stringify(msg) : String(msg);
74
- this.native.sendTo(targetId, payload);
75
- }
76
-
77
- /**
78
- * 닀쀑 μˆ˜μ‹ μžμ—κ²Œ λ©”μ‹œμ§€ 전솑 (λ©€ν‹°μΊμŠ€νŠΈ)
79
- * @param {string[]} ids - μˆ˜μ‹ μž μ„Έμ…˜ ID λ°°μ—΄
80
- * @param {string|object} msg - 전솑할 λ©”μ‹œμ§€
81
- */
82
- sendToMany(ids, msg) {
83
- const payload = (typeof msg === 'object') ? JSON.stringify(msg) : String(msg);
84
- if (this.native.sendToMany) {
85
- this.native.sendToMany(ids, payload);
86
- } else {
87
- // 폴백: κ°œλ³„ 전솑
88
- for (const id of ids) {
89
- this.native.sendTo(id, payload);
90
- }
91
- }
92
- }
93
-
94
- // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
95
- // πŸ“‹ μ—°κ²° 관리
96
- // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
97
-
98
- /**
99
- * 접속 쀑인 전체 ν΄λΌμ΄μ–ΈνŠΈ ID λͺ©λ‘ (둜컬 + 리λͺ¨νŠΈ)
100
- * @returns {string[]} μ„Έμ…˜ ID λ°°μ—΄
101
- */
102
- getOnlineClients() {
103
- return this.native.getOnlineClients?.() || [];
104
- }
105
-
106
- /**
107
- * 접속 쀑인 전체 ν΄λΌμ΄μ–ΈνŠΈ 상세 λͺ©λ‘ (id + μ—°κ²° ν˜•μ‹)
108
- * @returns {{ id: string, connectionType: string }[]} ν΄λΌμ΄μ–ΈνŠΈ 상세 λ°°μ—΄
109
- */
110
- getOnlineClientsDetail() {
111
- return this.native.getOnlineClientsDetail?.() || [];
112
- }
113
-
114
- /**
115
- * 접속 쀑인 ν΄λΌμ΄μ–ΈνŠΈ 수 (둜컬 + 리λͺ¨νŠΈ)
116
- * @returns {number}
117
- */
118
- getOnlineCount() {
119
- return this.native.getOnlineCount?.() || 0;
120
- }
121
-
122
- /**
123
- * νŠΉμ • ν΄λΌμ΄μ–ΈνŠΈ κ°•μ œ μ’…λ£Œ (Close Code 4001)
124
- * @param {string} targetId - λŒ€μƒ μ„Έμ…˜ ID
125
- * @returns {boolean} 성곡 μ—¬λΆ€
126
- */
127
- disconnectClient(targetId) {
128
- return this.native.disconnectClient?.(targetId) || false;
129
- }
130
- }
@@ -1,174 +0,0 @@
1
- /* tslint:disable */
2
- /* eslint-disable */
3
-
4
- export class AlloyClient {
5
- free(): void;
6
- [Symbol.dispose](): void;
7
- decrypt_custom(key: string, data: string): string;
8
- /**
9
- * Smart DELETE Request
10
- */
11
- delete(path: string, encrypt_enabled?: boolean | null): Promise<any>;
12
- encrypt_custom(key: string, data: string): string;
13
- /**
14
- * Smart GET Request (encrypt_query: defaults to true)
15
- */
16
- get(path: string, encrypt_enabled?: boolean | null): Promise<any>;
17
- constructor(master_secret: string);
18
- /**
19
- * Smart PATCH Request
20
- */
21
- patch(path: string, json_body: any, encrypt_enabled?: boolean | null): Promise<any>;
22
- /**
23
- * Smart POST Request
24
- */
25
- post(path: string, json_body: any, encrypt_enabled?: boolean | null): Promise<any>;
26
- /**
27
- * Smart PUT Request
28
- */
29
- put(path: string, json_body: any, encrypt_enabled?: boolean | null): Promise<any>;
30
- uuid(): string;
31
- }
32
-
33
- /**
34
- * πŸ“‘ AlloySocket β€” WASM 기반 WebSocket ν΄λΌμ΄μ–ΈνŠΈ
35
- *
36
- * 이벀트 기반 λ©”μ‹œμ§€ ({ type, data }) ꡬ쑰λ₯Ό μ‚¬μš©ν•˜λ©°,
37
- * λ©”μ‹œμ§€ μ•”ν˜Έν™”, μžλ™ Ping, 슀마트 μž¬μ—°κ²°μ„ μ§€μ›ν•©λ‹ˆλ‹€.
38
- */
39
- export class AlloySocket {
40
- free(): void;
41
- [Symbol.dispose](): void;
42
- /**
43
- * πŸ”Œ μ„œλ²„ μ—°κ²°
44
- */
45
- connect(): void;
46
- /**
47
- * πŸ”Œ λͺ…μ‹œμ  μ—°κ²° μ’…λ£Œ
48
- */
49
- disconnect(): void;
50
- /**
51
- * πŸ” μ—°κ²° μƒνƒœ 확인
52
- */
53
- is_connected(): boolean;
54
- /**
55
- * πŸ“‘ AlloySocket μƒμ„±μž
56
- *
57
- * @param url - WebSocket μ„œλ²„ μ£Όμ†Œ (예: "ws://localhost:3000/ws")
58
- * @param master_secret - λ©”μ‹œμ§€ μ•”ν˜Έν™” ν‚€
59
- * @param encrypt_enabled - μ•”ν˜Έν™” ν™œμ„±ν™” μ—¬λΆ€ (κΈ°λ³Έ: false)
60
- */
61
- constructor(url: string, master_secret: string, encrypt_enabled?: boolean | null);
62
- /**
63
- * πŸ“© 이벀트 ν•Έλ“€λŸ¬ 등둝
64
- *
65
- * @param event_type - 이벀트 νƒ€μž… (예: "connect", "message", "disconnect", "chat")
66
- * @param callback - JS 콜백 ν•¨μˆ˜
67
- */
68
- on(event_type: string, callback: Function): void;
69
- /**
70
- * πŸ“¨ 이벀트 기반 λ©”μ‹œμ§€ 전솑
71
- *
72
- * @param event_type - 이벀트 νƒ€μž… (예: "chat", "sync")
73
- * @param data - 전솑할 데이터 (JS 객체)
74
- */
75
- send(event_type: string, data: any): void;
76
- /**
77
- * βš™οΈ μžλ™ μž¬μ—°κ²° ν™œμ„±ν™”/λΉ„ν™œμ„±ν™”
78
- */
79
- set_auto_reconnect(enabled: boolean): void;
80
- /**
81
- * βš™οΈ μ΅œλŒ€ μž¬μ—°κ²° μ‹œλ„ 횟수 μ„€μ •
82
- */
83
- set_max_reconnect_attempts(count: number): void;
84
- /**
85
- * βš™οΈ Ping μ£ΌκΈ° μ„€μ • (λ°€λ¦¬μ΄ˆ)
86
- */
87
- set_ping_interval(ms: number): void;
88
- }
89
-
90
- export class AlloyUtil {
91
- private constructor();
92
- free(): void;
93
- [Symbol.dispose](): void;
94
- /**
95
- * Find items > threshold (Example of complex filter)
96
- */
97
- static filter_gt(list: Int32Array, threshold: number): Int32Array;
98
- static md5(input: string): string;
99
- static sha256(input: string): string;
100
- /**
101
- * Shuffle a large array of integers (Fisher-Yates)
102
- * Much faster than JS sort(() => 0.5 - Math.random())
103
- */
104
- static shuffle_i32(list: Int32Array): Int32Array;
105
- /**
106
- * High performance sort
107
- */
108
- static sort_i32(list: Int32Array): Int32Array;
109
- }
110
-
111
- export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
112
-
113
- export interface InitOutput {
114
- readonly memory: WebAssembly.Memory;
115
- readonly __wbg_alloyclient_free: (a: number, b: number) => void;
116
- readonly __wbg_alloysocket_free: (a: number, b: number) => void;
117
- readonly __wbg_alloyutil_free: (a: number, b: number) => void;
118
- readonly alloyclient_decrypt_custom: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
119
- readonly alloyclient_delete: (a: number, b: number, c: number, d: number) => number;
120
- readonly alloyclient_encrypt_custom: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
121
- readonly alloyclient_get: (a: number, b: number, c: number, d: number) => number;
122
- readonly alloyclient_new: (a: number, b: number, c: number) => void;
123
- readonly alloyclient_patch: (a: number, b: number, c: number, d: number, e: number) => number;
124
- readonly alloyclient_post: (a: number, b: number, c: number, d: number, e: number) => number;
125
- readonly alloyclient_put: (a: number, b: number, c: number, d: number, e: number) => number;
126
- readonly alloyclient_uuid: (a: number, b: number) => void;
127
- readonly alloysocket_connect: (a: number, b: number) => void;
128
- readonly alloysocket_disconnect: (a: number) => void;
129
- readonly alloysocket_is_connected: (a: number) => number;
130
- readonly alloysocket_new: (a: number, b: number, c: number, d: number, e: number) => number;
131
- readonly alloysocket_on: (a: number, b: number, c: number, d: number) => void;
132
- readonly alloysocket_send: (a: number, b: number, c: number, d: number, e: number) => void;
133
- readonly alloysocket_set_auto_reconnect: (a: number, b: number) => void;
134
- readonly alloysocket_set_max_reconnect_attempts: (a: number, b: number) => void;
135
- readonly alloysocket_set_ping_interval: (a: number, b: number) => void;
136
- readonly alloyutil_filter_gt: (a: number, b: number, c: number, d: number) => void;
137
- readonly alloyutil_md5: (a: number, b: number, c: number) => void;
138
- readonly alloyutil_sha256: (a: number, b: number, c: number) => void;
139
- readonly alloyutil_shuffle_i32: (a: number, b: number, c: number) => void;
140
- readonly alloyutil_sort_i32: (a: number, b: number, c: number) => void;
141
- readonly __wasm_bindgen_func_elem_87: (a: number, b: number) => void;
142
- readonly __wasm_bindgen_func_elem_665: (a: number, b: number) => void;
143
- readonly __wasm_bindgen_func_elem_713: (a: number, b: number, c: number, d: number) => void;
144
- readonly __wasm_bindgen_func_elem_88: (a: number, b: number, c: number) => void;
145
- readonly __wasm_bindgen_func_elem_666: (a: number, b: number, c: number) => void;
146
- readonly __wasm_bindgen_func_elem_92: (a: number, b: number) => void;
147
- readonly __wbindgen_export: (a: number, b: number) => number;
148
- readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
149
- readonly __wbindgen_export3: (a: number) => void;
150
- readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
151
- readonly __wbindgen_export4: (a: number, b: number, c: number) => void;
152
- }
153
-
154
- export type SyncInitInput = BufferSource | WebAssembly.Module;
155
-
156
- /**
157
- * Instantiates the given `module`, which can either be bytes or
158
- * a precompiled `WebAssembly.Module`.
159
- *
160
- * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
161
- *
162
- * @returns {InitOutput}
163
- */
164
- export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
165
-
166
- /**
167
- * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
168
- * for everything else, calls `WebAssembly.instantiate` directly.
169
- *
170
- * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
171
- *
172
- * @returns {Promise<InitOutput>}
173
- */
174
- export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;