-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathgetQueryId.js
More file actions
43 lines (33 loc) · 1.22 KB
/
getQueryId.js
File metadata and controls
43 lines (33 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// -------------------------------------------------------------------------- \\
// File: getQueryId.js \\
// Module: API \\
// Requires: namespace.js \\
// -------------------------------------------------------------------------- \\
/*global O, JMAP */
'use strict';
( function ( JMAP ) {
const guid = O.guid;
// ---
const stringifySorted = function ( item ) {
if ( !item || ( typeof item !== 'object' ) ) {
return JSON.stringify( item );
}
if ( item instanceof Array ) {
return '[' + item.map( stringifySorted ).join( ',' ) + ']';
}
var keys = Object.keys( item );
keys.sort();
return '{' + keys.map( function ( key ) {
return '"' + key + '":' + stringifySorted( item[ key ] );
}).join( ',' ) + '}';
};
const getQueryId = function ( Type, args ) {
return guid( Type ) + ':' + (
( args.accountId || '' ) +
stringifySorted( args.where || args.filter || null ) +
stringifySorted( args.sort || null )
).hash().toString();
};
// --- Export
JMAP.getQueryId = getQueryId;
}( JMAP ) );