@semiont/core 0.2.35-build.98 → 0.2.35
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 +1 -1
- package/dist/index.d.ts +218 -164
- package/dist/index.js +83 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Subject } from 'rxjs';
|
|
1
|
+
import { Subject, Observable } from 'rxjs';
|
|
2
2
|
import Ajv from 'ajv';
|
|
3
3
|
import addFormats from 'ajv-formats';
|
|
4
4
|
|
|
@@ -194,13 +194,13 @@ var EventBus = class {
|
|
|
194
194
|
* @example
|
|
195
195
|
* ```typescript
|
|
196
196
|
* // Emit
|
|
197
|
-
* eventBus.get('
|
|
197
|
+
* eventBus.get('beckon:hover').next({ annotationId: 'ann-1' });
|
|
198
198
|
*
|
|
199
199
|
* // Subscribe
|
|
200
|
-
* const sub = eventBus.get('
|
|
200
|
+
* const sub = eventBus.get('beckon:hover').subscribe(handleHover);
|
|
201
201
|
*
|
|
202
202
|
* // With operators
|
|
203
|
-
* eventBus.get('
|
|
203
|
+
* eventBus.get('beckon:hover')
|
|
204
204
|
* .pipe(debounceTime(100), distinctUntilChanged())
|
|
205
205
|
* .subscribe(handleHover);
|
|
206
206
|
* ```
|
|
@@ -293,6 +293,84 @@ var ScopedEventBus = class _ScopedEventBus {
|
|
|
293
293
|
return new _ScopedEventBus(this.parent, `${this.scopePrefix}:${subScope}`);
|
|
294
294
|
}
|
|
295
295
|
};
|
|
296
|
+
function burstBuffer(options) {
|
|
297
|
+
const { burstWindowMs, maxBatchSize, idleTimeoutMs } = options;
|
|
298
|
+
return (source) => new Observable((subscriber) => {
|
|
299
|
+
let mode = "passthrough";
|
|
300
|
+
let buffer = [];
|
|
301
|
+
let burstTimer = null;
|
|
302
|
+
let idleTimer = null;
|
|
303
|
+
function clearBurstTimer() {
|
|
304
|
+
if (burstTimer !== null) {
|
|
305
|
+
clearTimeout(burstTimer);
|
|
306
|
+
burstTimer = null;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
function clearIdleTimer() {
|
|
310
|
+
if (idleTimer !== null) {
|
|
311
|
+
clearTimeout(idleTimer);
|
|
312
|
+
idleTimer = null;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
function flush() {
|
|
316
|
+
if (buffer.length === 0) return;
|
|
317
|
+
const batch = buffer;
|
|
318
|
+
buffer = [];
|
|
319
|
+
subscriber.next(batch);
|
|
320
|
+
}
|
|
321
|
+
function startIdleTimer() {
|
|
322
|
+
clearIdleTimer();
|
|
323
|
+
idleTimer = setTimeout(() => {
|
|
324
|
+
idleTimer = null;
|
|
325
|
+
mode = "passthrough";
|
|
326
|
+
}, idleTimeoutMs);
|
|
327
|
+
}
|
|
328
|
+
const subscription = source.subscribe({
|
|
329
|
+
next(value) {
|
|
330
|
+
clearIdleTimer();
|
|
331
|
+
if (mode === "passthrough") {
|
|
332
|
+
subscriber.next(value);
|
|
333
|
+
mode = "accumulating";
|
|
334
|
+
burstTimer = setTimeout(() => {
|
|
335
|
+
burstTimer = null;
|
|
336
|
+
flush();
|
|
337
|
+
startIdleTimer();
|
|
338
|
+
}, burstWindowMs);
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
buffer.push(value);
|
|
342
|
+
clearBurstTimer();
|
|
343
|
+
if (buffer.length >= maxBatchSize) {
|
|
344
|
+
flush();
|
|
345
|
+
startIdleTimer();
|
|
346
|
+
} else {
|
|
347
|
+
burstTimer = setTimeout(() => {
|
|
348
|
+
burstTimer = null;
|
|
349
|
+
flush();
|
|
350
|
+
startIdleTimer();
|
|
351
|
+
}, burstWindowMs);
|
|
352
|
+
}
|
|
353
|
+
},
|
|
354
|
+
error(err) {
|
|
355
|
+
clearBurstTimer();
|
|
356
|
+
clearIdleTimer();
|
|
357
|
+
flush();
|
|
358
|
+
subscriber.error(err);
|
|
359
|
+
},
|
|
360
|
+
complete() {
|
|
361
|
+
clearBurstTimer();
|
|
362
|
+
clearIdleTimer();
|
|
363
|
+
flush();
|
|
364
|
+
subscriber.complete();
|
|
365
|
+
}
|
|
366
|
+
});
|
|
367
|
+
return () => {
|
|
368
|
+
clearBurstTimer();
|
|
369
|
+
clearIdleTimer();
|
|
370
|
+
subscription.unsubscribe();
|
|
371
|
+
};
|
|
372
|
+
});
|
|
373
|
+
}
|
|
296
374
|
|
|
297
375
|
// src/annotation-utils.ts
|
|
298
376
|
function findBodyItem(body, targetItem) {
|
|
@@ -2297,6 +2375,6 @@ function getAllPlatformTypes() {
|
|
|
2297
2375
|
var CORE_TYPES_VERSION = "0.1.0";
|
|
2298
2376
|
var SDK_VERSION = "0.1.0";
|
|
2299
2377
|
|
|
2300
|
-
export { APIError, CORE_TYPES_VERSION, CREATION_METHODS, ConfigurationError, ConflictError, EventBus, NotFoundError, SDK_VERSION, ScopedEventBus, ScriptError, SemiontError, UnauthorizedError, ValidationError, accessToken, annotationId, annotationIdToURI, annotationUri, authCode, baseUrl, cloneToken, createConfigLoader, deepMerge, didToAgent, displayConfiguration, email, entityType, extractResourceUriFromAnnotationUri, findBodyItem, formatErrors, getAllPlatformTypes, getAnnotationUriFromEvent, getEventType, getNodeEnvForEnvironment, googleCredential, hasAWSConfig, isAnnotationId, isArray, isBoolean, isDefined, isEventRelatedToAnnotation, isFunction, isNull, isNullish, isNumber, isObject, isResourceEvent, isResourceId, isResourceScopedEvent, isResourceEvent2 as isStoredEvent, isString, isSystemEvent, isUndefined, isValidPlatformType, jobId, listEnvironmentNames, mcpToken, parseAndMergeConfigs, parseEnvironment, refreshToken, resolveEnvVars, resourceAnnotationUri, resourceId, resourceIdToURI, resourceUri, searchQuery, uriToAnnotationId, uriToAnnotationIdOrPassthrough, uriToResourceId, userDID, userId, userToAgent, userToDid, validateEnvironment, validateEnvironmentConfig, validateSemiontConfig, validateSiteConfig };
|
|
2378
|
+
export { APIError, CORE_TYPES_VERSION, CREATION_METHODS, ConfigurationError, ConflictError, EventBus, NotFoundError, SDK_VERSION, ScopedEventBus, ScriptError, SemiontError, UnauthorizedError, ValidationError, accessToken, annotationId, annotationIdToURI, annotationUri, authCode, baseUrl, burstBuffer, cloneToken, createConfigLoader, deepMerge, didToAgent, displayConfiguration, email, entityType, extractResourceUriFromAnnotationUri, findBodyItem, formatErrors, getAllPlatformTypes, getAnnotationUriFromEvent, getEventType, getNodeEnvForEnvironment, googleCredential, hasAWSConfig, isAnnotationId, isArray, isBoolean, isDefined, isEventRelatedToAnnotation, isFunction, isNull, isNullish, isNumber, isObject, isResourceEvent, isResourceId, isResourceScopedEvent, isResourceEvent2 as isStoredEvent, isString, isSystemEvent, isUndefined, isValidPlatformType, jobId, listEnvironmentNames, mcpToken, parseAndMergeConfigs, parseEnvironment, refreshToken, resolveEnvVars, resourceAnnotationUri, resourceId, resourceIdToURI, resourceUri, searchQuery, uriToAnnotationId, uriToAnnotationIdOrPassthrough, uriToResourceId, userDID, userId, userToAgent, userToDid, validateEnvironment, validateEnvironmentConfig, validateSemiontConfig, validateSiteConfig };
|
|
2301
2379
|
//# sourceMappingURL=index.js.map
|
|
2302
2380
|
//# sourceMappingURL=index.js.map
|