@private.me/xbind 1.2.0 → 1.2.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/README.md +13 -24
- package/dist-standalone/_deps/ux-helpers/cjs/errors.d.ts +4 -0
- package/dist-standalone/_deps/ux-helpers/cjs/errors.d.ts.map +1 -1
- package/dist-standalone/_deps/ux-helpers/cjs/errors.js +1 -1
- package/dist-standalone/_deps/ux-helpers/cjs/errors.js.map +1 -1
- package/dist-standalone/_deps/ux-helpers/cjs/pagination.js +1 -83
- package/dist-standalone/_deps/ux-helpers/cjs/progress.js +1 -143
- package/dist-standalone/_deps/ux-helpers/cjs/search.js +1 -119
- package/dist-standalone/_deps/ux-helpers/cjs/types.js +1 -8
- package/dist-standalone/_deps/ux-helpers/errors.d.ts +4 -0
- package/dist-standalone/_deps/ux-helpers/errors.d.ts.map +1 -1
- package/dist-standalone/_deps/ux-helpers/errors.js +1 -253
- package/dist-standalone/_deps/ux-helpers/errors.js.map +1 -1
- package/dist-standalone/_deps/ux-helpers/index.js +1 -16
- package/dist-standalone/_deps/ux-helpers/pagination.js +1 -79
- package/dist-standalone/_deps/ux-helpers/progress.js +1 -138
- package/dist-standalone/_deps/ux-helpers/search.js +1 -116
- package/dist-standalone/_deps/ux-helpers/types.js +1 -7
- package/dist-standalone/agent.d.ts +9 -4
- package/dist-standalone/agent.js +20 -4
- package/dist-standalone/cjs/agent.js +20 -4
- package/dist-standalone/cjs/correlation-id.js +339 -0
- package/dist-standalone/cjs/http-status-map.js +571 -0
- package/dist-standalone/cjs/index.js +14 -1
- package/dist-standalone/cjs/types/error-response.js +56 -0
- package/dist-standalone/correlation-id.d.ts +222 -0
- package/dist-standalone/correlation-id.js +326 -0
- package/dist-standalone/http-status-map.d.ts +136 -0
- package/dist-standalone/http-status-map.js +561 -0
- package/dist-standalone/index.d.ts +2 -0
- package/dist-standalone/index.js +1 -0
- package/package.json +2 -2
- package/share1.dat +0 -0
|
@@ -1,253 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Error Formatter
|
|
3
|
-
*
|
|
4
|
-
* Provides consistent error formatting across all PRIVATE.ME packages.
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* Create a detailed ACI error.
|
|
8
|
-
*
|
|
9
|
-
* @param code Machine-readable error code (e.g., 'INVALID_DID')
|
|
10
|
-
* @param message Human-readable error message
|
|
11
|
-
* @param options Optional error details (hint, field, docs)
|
|
12
|
-
* @returns Detailed error object
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```typescript
|
|
16
|
-
* const error = createDetailedError(
|
|
17
|
-
* 'INVALID_DID',
|
|
18
|
-
* 'DID format is invalid',
|
|
19
|
-
* {
|
|
20
|
-
* hint: 'DIDs must start with "did:" followed by method (e.g., did:key:z6Mk...)',
|
|
21
|
-
* field: 'recipientDID',
|
|
22
|
-
* docs: 'https://private.me/docs/did-format'
|
|
23
|
-
* }
|
|
24
|
-
* );
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
export function createDetailedError(code, message, options) {
|
|
28
|
-
return {
|
|
29
|
-
code,
|
|
30
|
-
message,
|
|
31
|
-
hint: options?.hint,
|
|
32
|
-
suggested_action: options?.suggested_action,
|
|
33
|
-
field: options?.field,
|
|
34
|
-
docs: options?.docs,
|
|
35
|
-
severity: options?.severity,
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Format an error for display to the user.
|
|
40
|
-
*
|
|
41
|
-
* Creates a human-friendly error message with hints and documentation links.
|
|
42
|
-
*
|
|
43
|
-
* @param error Detailed error object
|
|
44
|
-
* @returns Formatted error string
|
|
45
|
-
*
|
|
46
|
-
* @deprecated Use formatErrorStructured() for new code. This function remains for backward compatibility.
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* ```typescript
|
|
50
|
-
* const error = createDetailedError('INVALID_DID', 'DID format is invalid', {
|
|
51
|
-
* hint: 'DIDs must start with "did:"',
|
|
52
|
-
* docs: 'https://private.me/docs/did-format'
|
|
53
|
-
* });
|
|
54
|
-
*
|
|
55
|
-
* const formatted = formatErrorForUser(error);
|
|
56
|
-
* // "DID format is invalid
|
|
57
|
-
* // Hint: DIDs must start with "did:"
|
|
58
|
-
* // Docs: https://private.me/docs/did-format"
|
|
59
|
-
* ```
|
|
60
|
-
*/
|
|
61
|
-
export function formatErrorForUser(error) {
|
|
62
|
-
const parts = [error.message];
|
|
63
|
-
if (error.field) {
|
|
64
|
-
parts.push(`Field: ${error.field}`);
|
|
65
|
-
}
|
|
66
|
-
if (error.hint) {
|
|
67
|
-
parts.push(`Hint: ${error.hint}`);
|
|
68
|
-
}
|
|
69
|
-
if (error.docs) {
|
|
70
|
-
parts.push(`Docs: ${error.docs}`);
|
|
71
|
-
}
|
|
72
|
-
return parts.join('\n');
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Format an error for logging (includes error code).
|
|
76
|
-
*
|
|
77
|
-
* @param error Detailed error object
|
|
78
|
-
* @returns Formatted log string
|
|
79
|
-
*/
|
|
80
|
-
export function formatErrorForLog(error) {
|
|
81
|
-
const parts = [`[${error.code}] ${error.message}`];
|
|
82
|
-
if (error.field) {
|
|
83
|
-
parts.push(`field=${error.field}`);
|
|
84
|
-
}
|
|
85
|
-
if (error.hint) {
|
|
86
|
-
parts.push(`hint="${error.hint}"`);
|
|
87
|
-
}
|
|
88
|
-
if (error.docs) {
|
|
89
|
-
parts.push(`docs=${error.docs}`);
|
|
90
|
-
}
|
|
91
|
-
return parts.join(' | ');
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Check if an error is an ACIErrorDetail.
|
|
95
|
-
*
|
|
96
|
-
* @param error Unknown error object
|
|
97
|
-
* @returns True if error is an ACIErrorDetail
|
|
98
|
-
*/
|
|
99
|
-
export function isACIError(error) {
|
|
100
|
-
if (typeof error !== 'object' || error === null)
|
|
101
|
-
return false;
|
|
102
|
-
const e = error;
|
|
103
|
-
return (typeof e.code === 'string' &&
|
|
104
|
-
typeof e.message === 'string' &&
|
|
105
|
-
(e.hint === undefined || typeof e.hint === 'string') &&
|
|
106
|
-
(e.field === undefined || typeof e.field === 'string') &&
|
|
107
|
-
(e.docs === undefined || typeof e.docs === 'string'));
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Convert any error to an ACIErrorDetail.
|
|
111
|
-
*
|
|
112
|
-
* @param error Error object (Error, ACIErrorDetail, or unknown)
|
|
113
|
-
* @returns ACIErrorDetail
|
|
114
|
-
*/
|
|
115
|
-
export function toACIError(error) {
|
|
116
|
-
// Already an ACI error
|
|
117
|
-
if (isACIError(error)) {
|
|
118
|
-
return error;
|
|
119
|
-
}
|
|
120
|
-
// Standard Error object
|
|
121
|
-
if (error instanceof Error) {
|
|
122
|
-
return {
|
|
123
|
-
code: 'INTERNAL_ERROR',
|
|
124
|
-
message: error.message,
|
|
125
|
-
hint: 'An unexpected error occurred',
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
// Unknown error type
|
|
129
|
-
return {
|
|
130
|
-
code: 'UNKNOWN_ERROR',
|
|
131
|
-
message: String(error),
|
|
132
|
-
hint: 'An unexpected error occurred',
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Format an error with multiple structured representations.
|
|
137
|
-
*
|
|
138
|
-
* Returns an object with the original error details plus formatted versions
|
|
139
|
-
* optimized for different use cases (display, logging, APIs, docs).
|
|
140
|
-
*
|
|
141
|
-
* @param error Detailed error object
|
|
142
|
-
* @returns Error with formats
|
|
143
|
-
*
|
|
144
|
-
* @example
|
|
145
|
-
* ```typescript
|
|
146
|
-
* const error = createDetailedError('INVALID_DID', 'DID format is invalid', {
|
|
147
|
-
* hint: 'DIDs must start with "did:"',
|
|
148
|
-
* field: 'recipientDID',
|
|
149
|
-
* docs: 'https://private.me/docs/did-format'
|
|
150
|
-
* });
|
|
151
|
-
*
|
|
152
|
-
* const formatted = formatErrorStructured(error);
|
|
153
|
-
* console.log(formatted.formats.singleline);
|
|
154
|
-
* // "error | INVALID_DID | DID format is invalid | field=recipientDID"
|
|
155
|
-
*
|
|
156
|
-
* console.log(formatted.formats.multiline);
|
|
157
|
-
* // "Error: DID format is invalid
|
|
158
|
-
* // Code: INVALID_DID
|
|
159
|
-
* // Field: recipientDID
|
|
160
|
-
* // Hint: DIDs must start with "did:"
|
|
161
|
-
* // Docs: https://private.me/docs/did-format"
|
|
162
|
-
*
|
|
163
|
-
* console.log(formatted.formats.json);
|
|
164
|
-
* // '{"code":"INVALID_DID","message":"DID format is invalid",...}'
|
|
165
|
-
* ```
|
|
166
|
-
*/
|
|
167
|
-
export function formatErrorStructured(error) {
|
|
168
|
-
// Build multiline format (human display)
|
|
169
|
-
const multilineParts = [`Error: ${error.message}`, `Code: ${error.code}`];
|
|
170
|
-
if (error.severity)
|
|
171
|
-
multilineParts.push(`Severity: ${error.severity}`);
|
|
172
|
-
if (error.field)
|
|
173
|
-
multilineParts.push(`Field: ${error.field}`);
|
|
174
|
-
if (error.hint)
|
|
175
|
-
multilineParts.push(`Hint: ${error.hint}`);
|
|
176
|
-
if (error.suggested_action)
|
|
177
|
-
multilineParts.push(`Action: ${error.suggested_action}`);
|
|
178
|
-
if (error.docs)
|
|
179
|
-
multilineParts.push(`Docs: ${error.docs}`);
|
|
180
|
-
const multiline = multilineParts.join('\n');
|
|
181
|
-
// Build singleline format (logs)
|
|
182
|
-
const singlelineParts = ['error', error.code, error.message];
|
|
183
|
-
if (error.severity)
|
|
184
|
-
singlelineParts.push(`severity=${error.severity}`);
|
|
185
|
-
if (error.field)
|
|
186
|
-
singlelineParts.push(`field=${error.field}`);
|
|
187
|
-
if (error.hint) {
|
|
188
|
-
// Escape quotes in hint for proper log formatting
|
|
189
|
-
const escapedHint = error.hint.replace(/"/g, '\\"');
|
|
190
|
-
singlelineParts.push(`hint="${escapedHint}"`);
|
|
191
|
-
}
|
|
192
|
-
if (error.suggested_action) {
|
|
193
|
-
const escapedAction = error.suggested_action.replace(/"/g, '\\"');
|
|
194
|
-
singlelineParts.push(`action="${escapedAction}"`);
|
|
195
|
-
}
|
|
196
|
-
if (error.docs)
|
|
197
|
-
singlelineParts.push(`docs=${error.docs}`);
|
|
198
|
-
const singleline = singlelineParts.join(' | ');
|
|
199
|
-
// Build JSON format (APIs)
|
|
200
|
-
const jsonObj = {
|
|
201
|
-
code: error.code,
|
|
202
|
-
message: error.message,
|
|
203
|
-
};
|
|
204
|
-
if (error.severity)
|
|
205
|
-
jsonObj.severity = error.severity;
|
|
206
|
-
if (error.field)
|
|
207
|
-
jsonObj.field = error.field;
|
|
208
|
-
if (error.hint)
|
|
209
|
-
jsonObj.hint = error.hint;
|
|
210
|
-
if (error.suggested_action)
|
|
211
|
-
jsonObj.suggested_action = error.suggested_action;
|
|
212
|
-
if (error.docs)
|
|
213
|
-
jsonObj.docs = error.docs;
|
|
214
|
-
const json = JSON.stringify(jsonObj);
|
|
215
|
-
// Build markdown format (documentation)
|
|
216
|
-
const markdownParts = [
|
|
217
|
-
`**Error:** ${error.message}`,
|
|
218
|
-
`**Code:** \`${error.code}\``,
|
|
219
|
-
];
|
|
220
|
-
if (error.severity)
|
|
221
|
-
markdownParts.push(`**Severity:** ${error.severity}`);
|
|
222
|
-
if (error.field)
|
|
223
|
-
markdownParts.push(`**Field:** \`${error.field}\``);
|
|
224
|
-
if (error.hint)
|
|
225
|
-
markdownParts.push(`**Hint:** ${error.hint}`);
|
|
226
|
-
if (error.suggested_action)
|
|
227
|
-
markdownParts.push(`**Action:** ${error.suggested_action}`);
|
|
228
|
-
if (error.docs)
|
|
229
|
-
markdownParts.push(`**Docs:** [${error.docs}](${error.docs})`);
|
|
230
|
-
const markdown = markdownParts.join('\n\n');
|
|
231
|
-
return {
|
|
232
|
-
...error,
|
|
233
|
-
formats: {
|
|
234
|
-
multiline,
|
|
235
|
-
singleline,
|
|
236
|
-
json,
|
|
237
|
-
markdown,
|
|
238
|
-
},
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
/**
|
|
242
|
-
* Detailed error information for debugging and user-facing messages.
|
|
243
|
-
* Maps error codes to human-readable descriptions and recovery suggestions.
|
|
244
|
-
*/
|
|
245
|
-
export const ERROR_DETAILS = {
|
|
246
|
-
// Add error details here as needed
|
|
247
|
-
// Example:
|
|
248
|
-
// 'INVALID_CONFIG:TOO_FEW_NODES': {
|
|
249
|
-
// description: 'Configuration specifies fewer than 2 storage nodes',
|
|
250
|
-
// recovery: 'Add more storage nodes. At least 2 required, 3+ recommended.'
|
|
251
|
-
// }
|
|
252
|
-
};
|
|
253
|
-
//# sourceMappingURL=errors.js.map
|
|
1
|
+
export function createDetailedError(_0x1996bd,_0x177488,_0x39edee){return{'code':_0x1996bd,'message':_0x177488,'hint':_0x39edee?.['hint'],'suggested_action':_0x39edee?.['suggested_action'],'field':_0x39edee?.['field'],'docs':_0x39edee?.['docs'],'severity':_0x39edee?.['severity']};}export function formatErrorForUser(_0x58f460){const _0x2b29e4=[_0x58f460['message']];return _0x58f460['field']&&_0x2b29e4['push']('Field:\x20'+_0x58f460['field']),_0x58f460['hint']&&_0x2b29e4['push']('Hint:\x20'+_0x58f460['hint']),_0x58f460['docs']&&_0x2b29e4['push']('Docs:\x20'+_0x58f460['docs']),_0x2b29e4['join']('\x0a');}export function formatErrorForLog(_0x5399ce){const _0x2cda64=['['+_0x5399ce['code']+']\x20'+_0x5399ce['message']];return _0x5399ce['field']&&_0x2cda64['push']('field='+_0x5399ce['field']),_0x5399ce['hint']&&_0x2cda64['push']('hint=\x22'+_0x5399ce['hint']+'\x22'),_0x5399ce['docs']&&_0x2cda64['push']('docs='+_0x5399ce['docs']),_0x2cda64['join']('\x20|\x20');}export function isACIError(_0x4f249e){if(typeof _0x4f249e!=='object'||_0x4f249e===null)return![];const _0x48aca5=_0x4f249e;return typeof _0x48aca5['code']==='string'&&typeof _0x48aca5['message']==='string'&&(_0x48aca5['hint']===undefined||typeof _0x48aca5['hint']==='string')&&(_0x48aca5['field']===undefined||typeof _0x48aca5['field']==='string')&&(_0x48aca5['docs']===undefined||typeof _0x48aca5['docs']==='string');}export function toACIError(_0x5ef635){if(isACIError(_0x5ef635))return _0x5ef635;if(_0x5ef635 instanceof Error)return{'code':'INTERNAL_ERROR','message':_0x5ef635['message'],'hint':'An\x20unexpected\x20error\x20occurred'};return{'code':'UNKNOWN_ERROR','message':String(_0x5ef635),'hint':'An\x20unexpected\x20error\x20occurred'};}export function formatErrorStructured(_0x3241a0){const _0x482d71=['Error:\x20'+_0x3241a0['message'],'Code:\x20'+_0x3241a0['code']];if(_0x3241a0['severity'])_0x482d71['push']('Severity:\x20'+_0x3241a0['severity']);if(_0x3241a0['field'])_0x482d71['push']('Field:\x20'+_0x3241a0['field']);if(_0x3241a0['hint'])_0x482d71['push']('Hint:\x20'+_0x3241a0['hint']);if(_0x3241a0['suggested_action'])_0x482d71['push']('Action:\x20'+_0x3241a0['suggested_action']);if(_0x3241a0['docs'])_0x482d71['push']('Docs:\x20'+_0x3241a0['docs']);const _0x13a390=_0x482d71['join']('\x0a'),_0x177e82=['error',_0x3241a0['code'],_0x3241a0['message']];if(_0x3241a0['severity'])_0x177e82['push']('severity='+_0x3241a0['severity']);if(_0x3241a0['field'])_0x177e82['push']('field='+_0x3241a0['field']);if(_0x3241a0['hint']){const _0x4b1da5=_0x3241a0['hint']['replace'](/"/g,'\x5c\x22');_0x177e82['push']('hint=\x22'+_0x4b1da5+'\x22');}if(_0x3241a0['suggested_action']){const _0x4a2ccc=_0x3241a0['suggested_action']['replace'](/"/g,'\x5c\x22');_0x177e82['push']('action=\x22'+_0x4a2ccc+'\x22');}if(_0x3241a0['docs'])_0x177e82['push']('docs='+_0x3241a0['docs']);const _0xe96333=_0x177e82['join']('\x20|\x20'),_0x4af241={'code':_0x3241a0['code'],'message':_0x3241a0['message']};if(_0x3241a0['severity'])_0x4af241['severity']=_0x3241a0['severity'];if(_0x3241a0['field'])_0x4af241['field']=_0x3241a0['field'];if(_0x3241a0['hint'])_0x4af241['hint']=_0x3241a0['hint'];if(_0x3241a0['suggested_action'])_0x4af241['suggested_action']=_0x3241a0['suggested_action'];if(_0x3241a0['docs'])_0x4af241['docs']=_0x3241a0['docs'];const _0x446a95=JSON['stringify'](_0x4af241),_0x2e6d78=['**Error:**\x20'+_0x3241a0['message'],'**Code:**\x20`'+_0x3241a0['code']+'`'];if(_0x3241a0['severity'])_0x2e6d78['push']('**Severity:**\x20'+_0x3241a0['severity']);if(_0x3241a0['field'])_0x2e6d78['push']('**Field:**\x20`'+_0x3241a0['field']+'`');if(_0x3241a0['hint'])_0x2e6d78['push']('**Hint:**\x20'+_0x3241a0['hint']);if(_0x3241a0['suggested_action'])_0x2e6d78['push']('**Action:**\x20'+_0x3241a0['suggested_action']);if(_0x3241a0['docs'])_0x2e6d78['push']('**Docs:**\x20['+_0x3241a0['docs']+']('+_0x3241a0['docs']+')');const _0x245b2c=_0x2e6d78['join']('\x0a\x0a');return{..._0x3241a0,'formats':{'multiline':_0x13a390,'singleline':_0xe96333,'json':_0x446a95,'markdown':_0x245b2c}};}export const ERROR_DETAILS={};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,mBAAmB,CACjC,IAAY,EACZ,OAAe,EACf,OAAyB;IAEzB,OAAO;QACL,IAAI;QACJ,OAAO;QACP,IAAI,EAAE,OAAO,EAAE,IAAI;QACnB,gBAAgB,EAAE,OAAO,EAAE,gBAAgB;QAC3C,KAAK,EAAE,OAAO,EAAE,KAAK;QACrB,IAAI,EAAE,OAAO,EAAE,IAAI;QACnB,QAAQ,EAAE,OAAO,EAAE,QAAQ;KAC5B,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAqB;IACtD,MA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AC,MAAM,CAAC,CAAC;IAE5C,OAAO;QACL,GAAG,KAAK;QACR,OAAO,EAAE;YACP,SAAS;YACT,UAAU;YACV,IAAI;YACJ,QAAQ;SACT;KACF,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAOrB;AACH,yDAAyD;AACzD,qCAAqC;CACtC,CAAC"}
|
|
@@ -1,16 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* UX Helpers
|
|
3
|
-
*
|
|
4
|
-
* Shared utilities for consistent UX across all PRIVATE.ME packages.
|
|
5
|
-
*
|
|
6
|
-
* @packageDocumentation
|
|
7
|
-
*/
|
|
8
|
-
// Re-export pagination utilities
|
|
9
|
-
export { paginate, createPaginationMetadata } from './pagination.js';
|
|
10
|
-
// Re-export search utilities
|
|
11
|
-
export { search } from './search.js';
|
|
12
|
-
// Re-export progress utilities
|
|
13
|
-
export { ProgressReporter, createStagedProgress } from './progress.js';
|
|
14
|
-
// Re-export error utilities
|
|
15
|
-
export { createDetailedError, formatErrorForUser, formatErrorForLog, isACIError, toACIError, formatErrorStructured, } from './errors.js';
|
|
16
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export{paginate,createPaginationMetadata}from'./pagination.js';export{search}from'./search.js';export{ProgressReporter,createStagedProgress}from'./progress.js';export{createDetailedError,formatErrorForUser,formatErrorForLog,isACIError,toACIError,formatErrorStructured}from'./errors.js';
|
|
@@ -1,79 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Pagination Helper
|
|
3
|
-
*
|
|
4
|
-
* Provides consistent pagination behavior across all PRIVATE.ME packages.
|
|
5
|
-
*/
|
|
6
|
-
/** Default items per page. */
|
|
7
|
-
const DEFAULT_LIMIT = 50;
|
|
8
|
-
/** Maximum items per page. */
|
|
9
|
-
const MAX_LIMIT = 100;
|
|
10
|
-
/**
|
|
11
|
-
* Paginate a collection of items.
|
|
12
|
-
*
|
|
13
|
-
* Returns a subset of items for the requested page along with pagination metadata.
|
|
14
|
-
*
|
|
15
|
-
* @param items Full collection to paginate
|
|
16
|
-
* @param options Pagination options (page number, limit)
|
|
17
|
-
* @returns Paginated result with data and metadata
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```typescript
|
|
21
|
-
* const allItems = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
|
22
|
-
* const result = paginate(allItems, { page: 2, limit: 3 });
|
|
23
|
-
* // result.data = [4, 5, 6]
|
|
24
|
-
* // result.pagination.page = 2
|
|
25
|
-
* // result.pagination.total = 10
|
|
26
|
-
* // result.pagination.totalPages = 4
|
|
27
|
-
* // result.pagination.hasNext = true
|
|
28
|
-
* // result.pagination.hasPrev = true
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
export function paginate(items, options) {
|
|
32
|
-
// Normalize pagination parameters
|
|
33
|
-
const page = Math.max(1, options?.page ?? 1);
|
|
34
|
-
const limit = Math.min(Math.max(1, options?.limit ?? DEFAULT_LIMIT), MAX_LIMIT);
|
|
35
|
-
const total = items.length;
|
|
36
|
-
const totalPages = Math.max(1, Math.ceil(total / limit));
|
|
37
|
-
// Clamp page to valid range
|
|
38
|
-
const safePage = Math.min(page, totalPages);
|
|
39
|
-
// Calculate slice indices
|
|
40
|
-
const startIndex = (safePage - 1) * limit;
|
|
41
|
-
const endIndex = Math.min(startIndex + limit, total);
|
|
42
|
-
// Extract page data
|
|
43
|
-
const data = items.slice(startIndex, endIndex);
|
|
44
|
-
return {
|
|
45
|
-
data,
|
|
46
|
-
pagination: {
|
|
47
|
-
page: safePage,
|
|
48
|
-
limit,
|
|
49
|
-
total,
|
|
50
|
-
totalPages,
|
|
51
|
-
hasNext: safePage < totalPages,
|
|
52
|
-
hasPrev: safePage > 1,
|
|
53
|
-
},
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Create pagination metadata without slicing data.
|
|
58
|
-
*
|
|
59
|
-
* Useful when you already have the page data and just need the metadata.
|
|
60
|
-
*
|
|
61
|
-
* @param total Total number of items in the full collection
|
|
62
|
-
* @param options Pagination options
|
|
63
|
-
* @returns Pagination metadata only
|
|
64
|
-
*/
|
|
65
|
-
export function createPaginationMetadata(total, options) {
|
|
66
|
-
const page = Math.max(1, options?.page ?? 1);
|
|
67
|
-
const limit = Math.min(Math.max(1, options?.limit ?? DEFAULT_LIMIT), MAX_LIMIT);
|
|
68
|
-
const totalPages = Math.max(1, Math.ceil(total / limit));
|
|
69
|
-
const safePage = Math.min(page, totalPages);
|
|
70
|
-
return {
|
|
71
|
-
page: safePage,
|
|
72
|
-
limit,
|
|
73
|
-
total,
|
|
74
|
-
totalPages,
|
|
75
|
-
hasNext: safePage < totalPages,
|
|
76
|
-
hasPrev: safePage > 1,
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
//# sourceMappingURL=pagination.js.map
|
|
1
|
+
const DEFAULT_LIMIT=0x32,MAX_LIMIT=0x64;export function paginate(_0x3362df,_0x3fa86d){const _0x26a8f6=Math['max'](0x1,_0x3fa86d?.['page']??0x1),_0x5371f2=Math['min'](Math['max'](0x1,_0x3fa86d?.['limit']??DEFAULT_LIMIT),MAX_LIMIT),_0x38d987=_0x3362df['length'],_0x223493=Math['max'](0x1,Math['ceil'](_0x38d987/_0x5371f2)),_0x58a754=Math['min'](_0x26a8f6,_0x223493),_0x8c9a5b=(_0x58a754-0x1)*_0x5371f2,_0x16d646=Math['min'](_0x8c9a5b+_0x5371f2,_0x38d987),_0x8c01f3=_0x3362df['slice'](_0x8c9a5b,_0x16d646);return{'data':_0x8c01f3,'pagination':{'page':_0x58a754,'limit':_0x5371f2,'total':_0x38d987,'totalPages':_0x223493,'hasNext':_0x58a754<_0x223493,'hasPrev':_0x58a754>0x1}};}export function createPaginationMetadata(_0x3b1912,_0x25b803){const _0x5a311f=Math['max'](0x1,_0x25b803?.['page']??0x1),_0x3dcce1=Math['min'](Math['max'](0x1,_0x25b803?.['limit']??DEFAULT_LIMIT),MAX_LIMIT),_0x469bfa=Math['max'](0x1,Math['ceil'](_0x3b1912/_0x3dcce1)),_0x300bec=Math['min'](_0x5a311f,_0x469bfa);return{'page':_0x300bec,'limit':_0x3dcce1,'total':_0x3b1912,'totalPages':_0x469bfa,'hasNext':_0x300bec<_0x469bfa,'hasPrev':_0x300bec>0x1};}
|
|
@@ -1,138 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Progress Reporter
|
|
3
|
-
*
|
|
4
|
-
* Provides consistent progress reporting for long-running operations.
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* Progress reporter for long-running operations.
|
|
8
|
-
*
|
|
9
|
-
* Wraps a progress callback with convenient methods for reporting status updates.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```typescript
|
|
13
|
-
* async function processLargeFile(
|
|
14
|
-
* data: Uint8Array,
|
|
15
|
-
* onProgress?: ProgressCallback
|
|
16
|
-
* ): Promise<void> {
|
|
17
|
-
* const progress = new ProgressReporter(onProgress);
|
|
18
|
-
*
|
|
19
|
-
* progress.start('Initializing...');
|
|
20
|
-
* // ... initialization work
|
|
21
|
-
*
|
|
22
|
-
* progress.update('Processing...', 50);
|
|
23
|
-
* // ... processing work
|
|
24
|
-
*
|
|
25
|
-
* progress.complete();
|
|
26
|
-
* }
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
export class ProgressReporter {
|
|
30
|
-
callback;
|
|
31
|
-
lastPercent = 0;
|
|
32
|
-
/**
|
|
33
|
-
* Create a new progress reporter.
|
|
34
|
-
*
|
|
35
|
-
* @param callback Optional callback to invoke on progress updates
|
|
36
|
-
*/
|
|
37
|
-
constructor(callback) {
|
|
38
|
-
this.callback = callback;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Report progress with status and optional percentage.
|
|
42
|
-
*
|
|
43
|
-
* @param status Human-readable status message
|
|
44
|
-
* @param percent Progress percentage (0-100), optional
|
|
45
|
-
*/
|
|
46
|
-
report(status, percent) {
|
|
47
|
-
// Clamp percent to valid range if provided
|
|
48
|
-
const normalizedPercent = percent !== undefined ? Math.max(0, Math.min(100, percent)) : undefined;
|
|
49
|
-
// Update last known percent
|
|
50
|
-
if (normalizedPercent !== undefined) {
|
|
51
|
-
this.lastPercent = normalizedPercent;
|
|
52
|
-
}
|
|
53
|
-
// Call callback if provided
|
|
54
|
-
if (this.callback) {
|
|
55
|
-
this.callback(status, normalizedPercent);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Report the start of an operation (0% progress).
|
|
60
|
-
*
|
|
61
|
-
* @param status Status message
|
|
62
|
-
*/
|
|
63
|
-
start(status) {
|
|
64
|
-
this.report(status, 0);
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Update progress with status and percentage.
|
|
68
|
-
*
|
|
69
|
-
* @param status Status message
|
|
70
|
-
* @param percent Progress percentage (0-100)
|
|
71
|
-
*/
|
|
72
|
-
update(status, percent) {
|
|
73
|
-
this.report(status, percent);
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Report completion (100% progress).
|
|
77
|
-
*/
|
|
78
|
-
complete() {
|
|
79
|
-
this.report('Complete', 100);
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Get the last reported percentage.
|
|
83
|
-
*
|
|
84
|
-
* @returns Last reported percentage (0-100)
|
|
85
|
-
*/
|
|
86
|
-
getLastPercent() {
|
|
87
|
-
return this.lastPercent;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Create a progress reporter that tracks multiple stages.
|
|
92
|
-
*
|
|
93
|
-
* Divides the 0-100% range into equal segments for each stage.
|
|
94
|
-
*
|
|
95
|
-
* @param stages Array of stage names
|
|
96
|
-
* @param callback Progress callback
|
|
97
|
-
* @returns Object with methods for advancing through stages
|
|
98
|
-
*
|
|
99
|
-
* @example
|
|
100
|
-
* ```typescript
|
|
101
|
-
* const progress = createStagedProgress(
|
|
102
|
-
* ['Initializing', 'Processing', 'Finalizing'],
|
|
103
|
-
* (status, percent) => console.log(`${status}: ${percent}%`)
|
|
104
|
-
* );
|
|
105
|
-
*
|
|
106
|
-
* progress.start(); // "Initializing: 0%"
|
|
107
|
-
* progress.nextStage(); // "Processing: 33%"
|
|
108
|
-
* progress.nextStage(); // "Finalizing: 67%"
|
|
109
|
-
* progress.complete(); // "Complete: 100%"
|
|
110
|
-
* ```
|
|
111
|
-
*/
|
|
112
|
-
export function createStagedProgress(stages, callback) {
|
|
113
|
-
const reporter = new ProgressReporter(callback);
|
|
114
|
-
let currentStageIndex = 0;
|
|
115
|
-
const percentPerStage = stages.length > 0 ? 100 / stages.length : 100;
|
|
116
|
-
return {
|
|
117
|
-
start: () => {
|
|
118
|
-
currentStageIndex = 0;
|
|
119
|
-
reporter.start(stages[0] ?? 'Starting...');
|
|
120
|
-
},
|
|
121
|
-
nextStage: () => {
|
|
122
|
-
currentStageIndex = Math.min(currentStageIndex + 1, stages.length - 1);
|
|
123
|
-
const percent = Math.round(currentStageIndex * percentPerStage);
|
|
124
|
-
reporter.update(stages[currentStageIndex] ?? 'Processing...', percent);
|
|
125
|
-
},
|
|
126
|
-
complete: () => {
|
|
127
|
-
currentStageIndex = stages.length;
|
|
128
|
-
reporter.complete();
|
|
129
|
-
},
|
|
130
|
-
getCurrentStage: () => {
|
|
131
|
-
return stages[currentStageIndex] ?? '';
|
|
132
|
-
},
|
|
133
|
-
getProgress: () => {
|
|
134
|
-
return Math.round(currentStageIndex * percentPerStage);
|
|
135
|
-
},
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
//# sourceMappingURL=progress.js.map
|
|
1
|
+
export class ProgressReporter{['callback'];['lastPercent']=0x0;constructor(_0x4fa0af){this['callback']=_0x4fa0af;}['report'](_0x1cd198,_0x4bcab9){const _0xca9b55=_0x4bcab9!==undefined?Math['max'](0x0,Math['min'](0x64,_0x4bcab9)):undefined;_0xca9b55!==undefined&&(this['lastPercent']=_0xca9b55),this['callback']&&this['callback'](_0x1cd198,_0xca9b55);}['start'](_0x3449e1){this['report'](_0x3449e1,0x0);}['update'](_0x539c49,_0x4139d6){this['report'](_0x539c49,_0x4139d6);}['complete'](){this['report']('Complete',0x64);}['getLastPercent'](){return this['lastPercent'];}}export function createStagedProgress(_0x53299d,_0x2555d5){const _0xf575f1=new ProgressReporter(_0x2555d5);let _0x1e5618=0x0;const _0x2a66b5=_0x53299d['length']>0x0?0x64/_0x53299d['length']:0x64;return{'start':()=>{_0x1e5618=0x0,_0xf575f1['start'](_0x53299d[0x0]??'Starting...');},'nextStage':()=>{_0x1e5618=Math['min'](_0x1e5618+0x1,_0x53299d['length']-0x1);const _0x769e59=Math['round'](_0x1e5618*_0x2a66b5);_0xf575f1['update'](_0x53299d[_0x1e5618]??'Processing...',_0x769e59);},'complete':()=>{_0x1e5618=_0x53299d['length'],_0xf575f1['complete']();},'getCurrentStage':()=>{return _0x53299d[_0x1e5618]??'';},'getProgress':()=>{return Math['round'](_0x1e5618*_0x2a66b5);}};}
|
|
@@ -1,116 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Search Helper
|
|
3
|
-
*
|
|
4
|
-
* Provides consistent search behavior across all PRIVATE.ME packages.
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* Search a collection of items.
|
|
8
|
-
*
|
|
9
|
-
* Performs case-insensitive substring matching across specified fields.
|
|
10
|
-
*
|
|
11
|
-
* @param items Collection to search
|
|
12
|
-
* @param options Search options (query, fields, fuzzy, limit)
|
|
13
|
-
* @returns Filtered items matching the search query
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```typescript
|
|
17
|
-
* const items = [
|
|
18
|
-
* { name: 'Alice', email: 'alice@example.com' },
|
|
19
|
-
* { name: 'Bob', email: 'bob@example.com' },
|
|
20
|
-
* { name: 'Charlie', email: 'charlie@example.com' },
|
|
21
|
-
* ];
|
|
22
|
-
*
|
|
23
|
-
* const results = search(items, {
|
|
24
|
-
* query: 'alice',
|
|
25
|
-
* fields: ['name', 'email'],
|
|
26
|
-
* });
|
|
27
|
-
* // results = [{ name: 'Alice', email: 'alice@example.com' }]
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
export function search(items, options) {
|
|
31
|
-
const { query, fields, fuzzy = true, limit } = options;
|
|
32
|
-
// Empty query returns all items
|
|
33
|
-
if (!query.trim()) {
|
|
34
|
-
return limit !== undefined ? items.slice(0, limit) : items;
|
|
35
|
-
}
|
|
36
|
-
// Normalize query for comparison
|
|
37
|
-
const normalizedQuery = fuzzy ? query.toLowerCase() : query;
|
|
38
|
-
// Filter items that match the query
|
|
39
|
-
const results = items.filter((item) => {
|
|
40
|
-
// If fields are specified, search only those fields
|
|
41
|
-
if (fields && fields.length > 0) {
|
|
42
|
-
return fields.some((field) => {
|
|
43
|
-
const value = getNestedValue(item, field);
|
|
44
|
-
if (value === null || value === undefined)
|
|
45
|
-
return false;
|
|
46
|
-
return matchesQuery(String(value), normalizedQuery, fuzzy);
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
// Otherwise, search all string fields
|
|
50
|
-
return searchAllFields(item, normalizedQuery, fuzzy);
|
|
51
|
-
});
|
|
52
|
-
// Apply limit if specified
|
|
53
|
-
return limit !== undefined ? results.slice(0, limit) : results;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Get nested property value using dot notation.
|
|
57
|
-
*
|
|
58
|
-
* @param obj Object to query
|
|
59
|
-
* @param path Dot-separated path (e.g., 'user.profile.name')
|
|
60
|
-
* @returns Value at the path, or null if not found
|
|
61
|
-
*/
|
|
62
|
-
function getNestedValue(obj, path) {
|
|
63
|
-
const parts = path.split('.');
|
|
64
|
-
let current = obj;
|
|
65
|
-
for (const part of parts) {
|
|
66
|
-
if (current === null || current === undefined)
|
|
67
|
-
return null;
|
|
68
|
-
if (typeof current !== 'object')
|
|
69
|
-
return null;
|
|
70
|
-
current = current[part];
|
|
71
|
-
}
|
|
72
|
-
return current;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Check if a value matches the query.
|
|
76
|
-
*
|
|
77
|
-
* @param value Value to check
|
|
78
|
-
* @param query Query string (already normalized)
|
|
79
|
-
* @param fuzzy Whether to use fuzzy (case-insensitive) matching
|
|
80
|
-
* @returns True if value matches query
|
|
81
|
-
*/
|
|
82
|
-
function matchesQuery(value, query, fuzzy) {
|
|
83
|
-
if (fuzzy) {
|
|
84
|
-
return value.toLowerCase().includes(query);
|
|
85
|
-
}
|
|
86
|
-
return value.includes(query);
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Search all string fields in an object recursively.
|
|
90
|
-
*
|
|
91
|
-
* @param obj Object to search
|
|
92
|
-
* @param query Normalized query string
|
|
93
|
-
* @param fuzzy Whether to use fuzzy matching
|
|
94
|
-
* @returns True if any field matches the query
|
|
95
|
-
*/
|
|
96
|
-
function searchAllFields(obj, query, fuzzy) {
|
|
97
|
-
if (obj === null || obj === undefined)
|
|
98
|
-
return false;
|
|
99
|
-
// Check primitive types
|
|
100
|
-
if (typeof obj === 'string') {
|
|
101
|
-
return matchesQuery(obj, query, fuzzy);
|
|
102
|
-
}
|
|
103
|
-
if (typeof obj === 'number' || typeof obj === 'boolean') {
|
|
104
|
-
return matchesQuery(String(obj), query, fuzzy);
|
|
105
|
-
}
|
|
106
|
-
// Recurse into arrays
|
|
107
|
-
if (Array.isArray(obj)) {
|
|
108
|
-
return obj.some((item) => searchAllFields(item, query, fuzzy));
|
|
109
|
-
}
|
|
110
|
-
// Recurse into objects
|
|
111
|
-
if (typeof obj === 'object') {
|
|
112
|
-
return Object.values(obj).some((value) => searchAllFields(value, query, fuzzy));
|
|
113
|
-
}
|
|
114
|
-
return false;
|
|
115
|
-
}
|
|
116
|
-
//# sourceMappingURL=search.js.map
|
|
1
|
+
export function search(_0x56cff6,_0x4cf1f0){const {query:_0xe7d0b6,fields:_0x2ab63a,fuzzy:fuzzy=!![],limit:_0x413aac}=_0x4cf1f0;if(!_0xe7d0b6['trim']())return _0x413aac!==undefined?_0x56cff6['slice'](0x0,_0x413aac):_0x56cff6;const _0x4791d0=fuzzy?_0xe7d0b6['toLowerCase']():_0xe7d0b6,_0x528ebd=_0x56cff6['filter'](_0x27887d=>{if(_0x2ab63a&&_0x2ab63a['length']>0x0)return _0x2ab63a['some'](_0x2a9618=>{const _0x1bad4d=getNestedValue(_0x27887d,_0x2a9618);if(_0x1bad4d===null||_0x1bad4d===undefined)return![];return matchesQuery(String(_0x1bad4d),_0x4791d0,fuzzy);});return searchAllFields(_0x27887d,_0x4791d0,fuzzy);});return _0x413aac!==undefined?_0x528ebd['slice'](0x0,_0x413aac):_0x528ebd;}function getNestedValue(_0x5b4058,_0x239578){const _0x48ea11=_0x239578['split']('.');let _0x381700=_0x5b4058;for(const _0x1130d9 of _0x48ea11){if(_0x381700===null||_0x381700===undefined)return null;if(typeof _0x381700!=='object')return null;_0x381700=_0x381700[_0x1130d9];}return _0x381700;}function matchesQuery(_0x34e0ba,_0x5ccdec,_0x4f270f){if(_0x4f270f)return _0x34e0ba['toLowerCase']()['includes'](_0x5ccdec);return _0x34e0ba['includes'](_0x5ccdec);}function searchAllFields(_0x3f1933,_0x2b0093,_0x59fdd3){if(_0x3f1933===null||_0x3f1933===undefined)return![];if(typeof _0x3f1933==='string')return matchesQuery(_0x3f1933,_0x2b0093,_0x59fdd3);if(typeof _0x3f1933==='number'||typeof _0x3f1933==='boolean')return matchesQuery(String(_0x3f1933),_0x2b0093,_0x59fdd3);if(Array['isArray'](_0x3f1933))return _0x3f1933['some'](_0x501beb=>searchAllFields(_0x501beb,_0x2b0093,_0x59fdd3));if(typeof _0x3f1933==='object')return Object['values'](_0x3f1933)['some'](_0x52a966=>searchAllFields(_0x52a966,_0x2b0093,_0x59fdd3));return![];}
|