ncloudchat 1.0.63 → 1.0.65
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/ncloudchat.d.ts +1446 -0
- package/esm/CloudChat.d.ts +12 -0
- package/esm/CloudChat.js +92 -52
- package/esm/CloudChat.js.map +1 -1
- package/esm/graphql/message.d.ts +1 -0
- package/esm/graphql/message.js +2 -1
- package/esm/graphql/message.js.map +1 -1
- package/esm/queries/message.d.ts +11 -0
- package/esm/queries/message.js +25 -1
- package/esm/queries/message.js.map +1 -1
- package/ncloudchat.min.js +1 -1
- package/package.json +1 -1
- package/verify_timerange.cjs +105 -0
package/package.json
CHANGED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// Live verification: getMessages with startDate/endDate (created_at range)
|
|
2
|
+
// Sends 5 messages with gaps, then queries the middle window and asserts
|
|
3
|
+
// the first and last messages are excluded.
|
|
4
|
+
|
|
5
|
+
if (typeof global.window === 'undefined') {
|
|
6
|
+
global.window = { atob: (s) => Buffer.from(s, 'base64').toString('binary') };
|
|
7
|
+
}
|
|
8
|
+
const { default: NCloudChat } = require('./lib/CloudChat');
|
|
9
|
+
|
|
10
|
+
const PROJECT_ID = '4b158ce4-d6c8-48f4-bf8b-8578648eda55';
|
|
11
|
+
const OWNER_ID = 'test-owner';
|
|
12
|
+
const USER_ID = 'test-user';
|
|
13
|
+
const N = 5;
|
|
14
|
+
const GAP_MS = 2000;
|
|
15
|
+
|
|
16
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
17
|
+
function log(t, v) {
|
|
18
|
+
console.log(`\n=== ${t} ===`);
|
|
19
|
+
console.log(typeof v === 'string' ? v : JSON.stringify(v, null, 2));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async function run() {
|
|
23
|
+
const owner = new NCloudChat();
|
|
24
|
+
owner.initialize(PROJECT_ID);
|
|
25
|
+
await owner.connect({ id: OWNER_ID, name: 'Owner', profile: '' });
|
|
26
|
+
|
|
27
|
+
const user = new NCloudChat();
|
|
28
|
+
user.initialize(PROJECT_ID);
|
|
29
|
+
await user.connect({ id: USER_ID, name: 'User', profile: '' });
|
|
30
|
+
console.log('connected owner+user');
|
|
31
|
+
await sleep(2000); // let member records settle
|
|
32
|
+
|
|
33
|
+
const channelName = `tr-test-${Date.now()}`;
|
|
34
|
+
const channel = await owner.createChannel({ name: channelName, type: 'PUBLIC' });
|
|
35
|
+
const channelId = channel.id || channel.channel_id || channel._id;
|
|
36
|
+
log('createChannel', { channelId, name: channelName });
|
|
37
|
+
await sleep(1500);
|
|
38
|
+
|
|
39
|
+
await owner.subscribe(channelId);
|
|
40
|
+
await user.subscribe(channelId);
|
|
41
|
+
|
|
42
|
+
// Send N messages with gaps so created_at differs
|
|
43
|
+
for (let i = 1; i <= N; i++) {
|
|
44
|
+
await user.sendMessage(channelId, { message: `MSG-${i}`, type: 'text' });
|
|
45
|
+
console.log(`sent MSG-${i}`);
|
|
46
|
+
if (i < N) await sleep(GAP_MS);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Wait for Elasticsearch indexing
|
|
50
|
+
console.log('\nwaiting 6s for ES indexing...');
|
|
51
|
+
await sleep(6000);
|
|
52
|
+
|
|
53
|
+
// 1) Baseline: fetch all, ascending by created_at
|
|
54
|
+
const all = await user.getMessages(
|
|
55
|
+
{ channel_id: channelId },
|
|
56
|
+
{ created_at: 1 },
|
|
57
|
+
{ offset: 0, per_page: 100 }
|
|
58
|
+
);
|
|
59
|
+
const nodes = (all.edges || []).map((e) => e.node).filter((n) => /^MSG-\d+$/.test(n.content));
|
|
60
|
+
nodes.sort((a, b) => new Date(a.created_at) - new Date(b.created_at));
|
|
61
|
+
log('ALL messages (content @ created_at)',
|
|
62
|
+
nodes.map((n) => `${n.content} @ ${n.created_at}`).join('\n'));
|
|
63
|
+
console.log('totalCount(all):', all.totalCount, ' MSG nodes:', nodes.length);
|
|
64
|
+
|
|
65
|
+
if (nodes.length < N) {
|
|
66
|
+
console.log(`\n[WARN] expected ${N} MSG nodes, got ${nodes.length}. Aborting assertion.`);
|
|
67
|
+
} else {
|
|
68
|
+
// 2) Window = [created_at of MSG-2, created_at of MSG-4] (inclusive)
|
|
69
|
+
const startDate = nodes[1].created_at; // MSG-2
|
|
70
|
+
const endDate = nodes[3].created_at; // MSG-4
|
|
71
|
+
log('QUERY window', { startDate, endDate });
|
|
72
|
+
|
|
73
|
+
const win = await user.getMessages(
|
|
74
|
+
{ channel_id: channelId, startDate, endDate },
|
|
75
|
+
{ created_at: 1 },
|
|
76
|
+
{ offset: 0, per_page: 100 }
|
|
77
|
+
);
|
|
78
|
+
const winContents = (win.edges || [])
|
|
79
|
+
.map((e) => e.node.content)
|
|
80
|
+
.filter((c) => /^MSG-\d+$/.test(c))
|
|
81
|
+
.sort();
|
|
82
|
+
log('WINDOW result contents', winContents);
|
|
83
|
+
console.log('totalCount(window):', win.totalCount);
|
|
84
|
+
|
|
85
|
+
// 3) Assert: MSG-2,3,4 present; MSG-1, MSG-5 absent
|
|
86
|
+
const expected = ['MSG-2', 'MSG-3', 'MSG-4'];
|
|
87
|
+
const hasExpected = expected.every((c) => winContents.includes(c));
|
|
88
|
+
const excludesEnds = !winContents.includes('MSG-1') && !winContents.includes('MSG-5');
|
|
89
|
+
console.log('\n--- ASSERTION ---');
|
|
90
|
+
console.log('contains MSG-2,3,4 :', hasExpected);
|
|
91
|
+
console.log('excludes MSG-1,5 :', excludesEnds);
|
|
92
|
+
console.log(hasExpected && excludesEnds
|
|
93
|
+
? '✅ PASS: startDate/endDate (created_at range) works'
|
|
94
|
+
: '❌ FAIL: range filter did not behave as expected');
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// cleanup
|
|
98
|
+
try { await owner.deleteChannel(channelId); console.log('\nchannel deleted'); }
|
|
99
|
+
catch (e) { console.log('\ndeleteChannel error:', e.message); }
|
|
100
|
+
await owner.disconnect();
|
|
101
|
+
await user.disconnect();
|
|
102
|
+
process.exit(0);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
run().catch((e) => { console.error('FATAL:', e && e.message ? e.message : e); process.exit(1); });
|