@prezly/theme-kit-core 10.9.2 → 10.9.3
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/build/content-delivery/ContentDelivery.cjs +98 -13
- package/build/content-delivery/ContentDelivery.d.ts +3 -1
- package/build/content-delivery/ContentDelivery.mjs +98 -13
- package/build/content-delivery/RequestCoalescer.cjs +7 -2
- package/build/content-delivery/RequestCoalescer.d.ts +1 -1
- package/build/content-delivery/RequestCoalescer.mjs +8 -3
- package/build/content-delivery/cache/memory.cjs +3 -1
- package/build/content-delivery/cache/memory.mjs +3 -1
- package/build/content-delivery/cache/stacked.cjs +17 -5
- package/build/content-delivery/cache/stacked.mjs +17 -5
- package/build/content-delivery/cache/type.d.ts +2 -1
- package/build/content-delivery/index.cjs +32 -1
- package/build/content-delivery/index.d.ts +2 -0
- package/build/content-delivery/index.mjs +3 -1
- package/build/content-delivery/metrics.cjs +280 -0
- package/build/content-delivery/metrics.d.ts +14 -0
- package/build/content-delivery/metrics.mjs +273 -0
- package/build/content-delivery/telemetry.cjs +52 -0
- package/build/content-delivery/telemetry.d.ts +58 -0
- package/build/content-delivery/telemetry.mjs +42 -0
- package/build/content-delivery/telemetry.test.cjs +346 -0
- package/build/content-delivery/telemetry.test.mjs +344 -0
- package/package.json +2 -2
|
@@ -8,6 +8,7 @@ exports.createClient = createClient;
|
|
|
8
8
|
exports.story = exports.stories = exports.galleries = void 0;
|
|
9
9
|
var _sdk = require("@prezly/sdk");
|
|
10
10
|
var _RequestCoalescer = require("./RequestCoalescer.cjs");
|
|
11
|
+
var _telemetry = require("./telemetry.cjs");
|
|
11
12
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
12
13
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
13
14
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
@@ -32,7 +33,8 @@ function createClient(prezly, newsroomUuid, newsroomThemeUuid) {
|
|
|
32
33
|
var _ref = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
|
|
33
34
|
_ref$formats = _ref.formats,
|
|
34
35
|
formats = _ref$formats === void 0 ? [_sdk.Story.FormatVersion.SLATEJS_V4] : _ref$formats,
|
|
35
|
-
cache = _ref.cache
|
|
36
|
+
cache = _ref.cache,
|
|
37
|
+
telemetry = _ref.telemetry;
|
|
36
38
|
var client = {
|
|
37
39
|
newsroom() {
|
|
38
40
|
return prezly.newsrooms.get(newsroomUuid);
|
|
@@ -295,12 +297,32 @@ function createClient(prezly, newsroomUuid, newsroomThemeUuid) {
|
|
|
295
297
|
// A single schema prefix keeps old readers away from scoped envelopes.
|
|
296
298
|
// Scope/version changes overwrite the same keys rather than adding namespaces.
|
|
297
299
|
var storage = cache.scope === undefined ? cache.storage : cache.storage.namespace('scoped-v1');
|
|
298
|
-
injectCache(client, storage.namespace(namespace), cache.latestVersion, cache.scope, namespace, UNCACHED_METHODS);
|
|
300
|
+
injectCache(client, storage.namespace(namespace), cache.latestVersion, cache.scope, namespace, UNCACHED_METHODS, telemetry);
|
|
301
|
+
} else if (telemetry) {
|
|
302
|
+
var _loop2 = function _loop2() {
|
|
303
|
+
if (UNCACHED_METHODS.includes(methodName)) return 1; // continue
|
|
304
|
+
var invoke = client[methodName].bind(client);
|
|
305
|
+
var operation = contentOperation(methodName);
|
|
306
|
+
client[methodName] = function () {
|
|
307
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
308
|
+
args[_key] = arguments[_key];
|
|
309
|
+
}
|
|
310
|
+
(0, _telemetry.emit)(telemetry, {
|
|
311
|
+
type: 'content_request',
|
|
312
|
+
operation
|
|
313
|
+
});
|
|
314
|
+
return observeOrigin(() => invoke(...args), telemetry, operation);
|
|
315
|
+
};
|
|
316
|
+
};
|
|
317
|
+
for (var methodName of Object.keys(client)) {
|
|
318
|
+
if (_loop2()) continue;
|
|
319
|
+
}
|
|
299
320
|
}
|
|
300
321
|
return client;
|
|
301
322
|
}
|
|
302
323
|
function injectCache(client, cache, latestVersion, scope, namespace) {
|
|
303
324
|
var uncachedMethods = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : [];
|
|
325
|
+
var telemetry = arguments.length > 6 ? arguments[6] : undefined;
|
|
304
326
|
// An opaque SDK client does not expose its credentials/source. Callers without
|
|
305
327
|
// an explicit scope keep request-local sharing; the Next.js adapter supplies one.
|
|
306
328
|
var requests = scope === undefined ? new _RequestCoalescer.RequestCoalescer() : _RequestCoalescer.sharedContentRequests;
|
|
@@ -308,44 +330,107 @@ function injectCache(client, cache, latestVersion, scope, namespace) {
|
|
|
308
330
|
methodNames.forEach(methodName => {
|
|
309
331
|
if (uncachedMethods.includes(methodName)) return;
|
|
310
332
|
var uncachedFn = client[methodName].bind(client);
|
|
333
|
+
var operation = contentOperation(methodName);
|
|
311
334
|
client[methodName] = /*#__PURE__*/_asyncToGenerator(function* () {
|
|
312
|
-
for (var
|
|
313
|
-
args[
|
|
335
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
336
|
+
args[_key2] = arguments[_key2];
|
|
314
337
|
}
|
|
338
|
+
(0, _telemetry.emit)(telemetry, {
|
|
339
|
+
type: 'content_request',
|
|
340
|
+
operation
|
|
341
|
+
});
|
|
315
342
|
// Preserve existing argument serialization; query canonicalization is separate.
|
|
316
343
|
var cacheKey = "".concat(methodName, ":").concat(JSON.stringify(args));
|
|
317
344
|
var dedupeKey = JSON.stringify([scope, namespace, latestVersion, cacheKey]);
|
|
318
345
|
return requests.run(dedupeKey, /*#__PURE__*/_asyncToGenerator(function* () {
|
|
319
346
|
try {
|
|
320
|
-
var
|
|
347
|
+
var layer = 'custom';
|
|
348
|
+
var _stored = telemetry ? yield cache.get(cacheKey, latestVersion, source => {
|
|
349
|
+
layer = source === 'memory' || source === 'redis' ? source : 'custom';
|
|
350
|
+
}) : yield cache.get(cacheKey, latestVersion);
|
|
321
351
|
var cached = scope === undefined ? _stored : (_stored === null || _stored === void 0 ? void 0 : _stored.scope) === scope ? _stored.value : undefined;
|
|
322
352
|
// Preserve existing negative-cache semantics until null results
|
|
323
353
|
// have a deliberately short TTL and correct error classification.
|
|
324
|
-
if (cached)
|
|
325
|
-
|
|
326
|
-
|
|
354
|
+
if (cached) {
|
|
355
|
+
(0, _telemetry.emit)(telemetry, {
|
|
356
|
+
type: 'cache_hit',
|
|
357
|
+
operation,
|
|
358
|
+
layer
|
|
359
|
+
});
|
|
360
|
+
return {
|
|
361
|
+
value: cached
|
|
362
|
+
};
|
|
363
|
+
}
|
|
327
364
|
} catch (_unused) {
|
|
365
|
+
(0, _telemetry.emit)(telemetry, {
|
|
366
|
+
type: 'cache_error',
|
|
367
|
+
operation,
|
|
368
|
+
action: 'read'
|
|
369
|
+
});
|
|
328
370
|
// A cache failure must not prevent a bounded origin fallback.
|
|
329
371
|
}
|
|
330
|
-
|
|
372
|
+
(0, _telemetry.emit)(telemetry, {
|
|
373
|
+
type: 'cache_miss',
|
|
374
|
+
operation
|
|
375
|
+
});
|
|
376
|
+
var value = yield observeOrigin(() => uncachedFn(...args), telemetry, operation);
|
|
331
377
|
var stored = scope === undefined ? value : {
|
|
332
378
|
scope,
|
|
333
379
|
value
|
|
334
380
|
};
|
|
335
381
|
// Observe synchronous and asynchronous write failures without holding
|
|
336
382
|
// up a successful response or leaving an unhandled rejection.
|
|
337
|
-
var cacheWrite = Promise.resolve().then(() => cache.set(cacheKey, stored, latestVersion)).catch(() =>
|
|
383
|
+
var cacheWrite = Promise.resolve().then(() => cache.set(cacheKey, stored, latestVersion)).catch(() => {
|
|
384
|
+
(0, _telemetry.emit)(telemetry, {
|
|
385
|
+
type: 'cache_error',
|
|
386
|
+
operation,
|
|
387
|
+
action: 'write'
|
|
388
|
+
});
|
|
389
|
+
});
|
|
338
390
|
return {
|
|
339
391
|
value,
|
|
340
392
|
cacheWrite
|
|
341
393
|
};
|
|
342
|
-
}))
|
|
394
|
+
}), telemetry ? event => (0, _telemetry.emit)(telemetry, {
|
|
395
|
+
type: event === 'coalesced' ? 'coalesced' : 'content_rejected',
|
|
396
|
+
operation
|
|
397
|
+
}) : undefined);
|
|
343
398
|
});
|
|
344
399
|
});
|
|
345
400
|
}
|
|
401
|
+
function contentOperation(name) {
|
|
402
|
+
return _telemetry.CONTENT_OPERATIONS.includes(name) ? name : 'other';
|
|
403
|
+
}
|
|
404
|
+
function observeOrigin(invoke, telemetry, operation) {
|
|
405
|
+
if (!telemetry) return invoke();
|
|
406
|
+
var start = (0, _telemetry.telemetryNow)();
|
|
407
|
+
var complete = outcome => (0, _telemetry.emit)(telemetry, {
|
|
408
|
+
type: 'origin',
|
|
409
|
+
operation,
|
|
410
|
+
outcome,
|
|
411
|
+
seconds: (0, _telemetry.elapsedSeconds)(start)
|
|
412
|
+
});
|
|
413
|
+
try {
|
|
414
|
+
var value = invoke();
|
|
415
|
+
if (value && typeof value.then === 'function') {
|
|
416
|
+
return Promise.resolve(value).then(result => {
|
|
417
|
+
complete('success');
|
|
418
|
+
return result;
|
|
419
|
+
}, error => {
|
|
420
|
+
complete('error');
|
|
421
|
+
throw error;
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
complete('success');
|
|
425
|
+
return value;
|
|
426
|
+
} catch (error) {
|
|
427
|
+
complete('error');
|
|
428
|
+
throw error;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
346
431
|
function mergeQueries() {
|
|
347
|
-
for (var
|
|
348
|
-
queries[
|
|
432
|
+
for (var _len3 = arguments.length, queries = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
433
|
+
queries[_key3] = arguments[_key3];
|
|
349
434
|
}
|
|
350
435
|
var queryObjects = queries.filter(query => Boolean(query)).map(query => {
|
|
351
436
|
if (typeof query === 'string') {
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { Culture, Newsroom, NewsroomTheme, PrezlyClient, Query, TranslatedCategory } from '@prezly/sdk';
|
|
2
2
|
import { Category, NewsroomGallery, Stories, Story } from '@prezly/sdk';
|
|
3
3
|
import type { Cache, UnixTimestampInSeconds } from './cache';
|
|
4
|
+
import { type Telemetry } from './telemetry';
|
|
4
5
|
export interface Options {
|
|
5
6
|
formats?: Story.FormatVersion[];
|
|
7
|
+
telemetry?: Telemetry;
|
|
6
8
|
cache?: {
|
|
7
9
|
storage: Cache;
|
|
8
10
|
latestVersion: UnixTimestampInSeconds;
|
|
@@ -55,7 +57,7 @@ export declare namespace galleries {
|
|
|
55
57
|
}
|
|
56
58
|
}
|
|
57
59
|
export type Client = ReturnType<typeof createClient>;
|
|
58
|
-
export declare function createClient(prezly: PrezlyClient, newsroomUuid: Newsroom['uuid'], newsroomThemeUuid: NewsroomTheme['id'] | undefined, { formats, cache }?: Options): {
|
|
60
|
+
export declare function createClient(prezly: PrezlyClient, newsroomUuid: Newsroom['uuid'], newsroomThemeUuid: NewsroomTheme['id'] | undefined, { formats, cache, telemetry }?: Options): {
|
|
59
61
|
newsroom(): Promise<Newsroom>;
|
|
60
62
|
theme(): Promise<import("@prezly/sdk").NewsroomThemePreset> | undefined;
|
|
61
63
|
themeSettings(): Promise<Record<string, any> | undefined>;
|
|
@@ -7,6 +7,7 @@ function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.
|
|
|
7
7
|
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
|
|
8
8
|
import { ApiError, Category, NewsroomGallery, SortOrder, Stories, Story } from '@prezly/sdk';
|
|
9
9
|
import { RequestCoalescer, sharedContentRequests } from "./RequestCoalescer.mjs";
|
|
10
|
+
import { CONTENT_OPERATIONS, emit, elapsedSeconds, telemetryNow } from "./telemetry.mjs";
|
|
10
11
|
export var stories;
|
|
11
12
|
export var allStories;
|
|
12
13
|
export var story;
|
|
@@ -24,7 +25,8 @@ export function createClient(prezly, newsroomUuid, newsroomThemeUuid) {
|
|
|
24
25
|
var _ref = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
|
|
25
26
|
_ref$formats = _ref.formats,
|
|
26
27
|
formats = _ref$formats === void 0 ? [Story.FormatVersion.SLATEJS_V4] : _ref$formats,
|
|
27
|
-
cache = _ref.cache
|
|
28
|
+
cache = _ref.cache,
|
|
29
|
+
telemetry = _ref.telemetry;
|
|
28
30
|
var client = {
|
|
29
31
|
newsroom() {
|
|
30
32
|
return prezly.newsrooms.get(newsroomUuid);
|
|
@@ -287,12 +289,32 @@ export function createClient(prezly, newsroomUuid, newsroomThemeUuid) {
|
|
|
287
289
|
// A single schema prefix keeps old readers away from scoped envelopes.
|
|
288
290
|
// Scope/version changes overwrite the same keys rather than adding namespaces.
|
|
289
291
|
var storage = cache.scope === undefined ? cache.storage : cache.storage.namespace('scoped-v1');
|
|
290
|
-
injectCache(client, storage.namespace(namespace), cache.latestVersion, cache.scope, namespace, UNCACHED_METHODS);
|
|
292
|
+
injectCache(client, storage.namespace(namespace), cache.latestVersion, cache.scope, namespace, UNCACHED_METHODS, telemetry);
|
|
293
|
+
} else if (telemetry) {
|
|
294
|
+
var _loop2 = function _loop2() {
|
|
295
|
+
if (UNCACHED_METHODS.includes(methodName)) return 1; // continue
|
|
296
|
+
var invoke = client[methodName].bind(client);
|
|
297
|
+
var operation = contentOperation(methodName);
|
|
298
|
+
client[methodName] = function () {
|
|
299
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
300
|
+
args[_key] = arguments[_key];
|
|
301
|
+
}
|
|
302
|
+
emit(telemetry, {
|
|
303
|
+
type: 'content_request',
|
|
304
|
+
operation
|
|
305
|
+
});
|
|
306
|
+
return observeOrigin(() => invoke(...args), telemetry, operation);
|
|
307
|
+
};
|
|
308
|
+
};
|
|
309
|
+
for (var methodName of Object.keys(client)) {
|
|
310
|
+
if (_loop2()) continue;
|
|
311
|
+
}
|
|
291
312
|
}
|
|
292
313
|
return client;
|
|
293
314
|
}
|
|
294
315
|
function injectCache(client, cache, latestVersion, scope, namespace) {
|
|
295
316
|
var uncachedMethods = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : [];
|
|
317
|
+
var telemetry = arguments.length > 6 ? arguments[6] : undefined;
|
|
296
318
|
// An opaque SDK client does not expose its credentials/source. Callers without
|
|
297
319
|
// an explicit scope keep request-local sharing; the Next.js adapter supplies one.
|
|
298
320
|
var requests = scope === undefined ? new RequestCoalescer() : sharedContentRequests;
|
|
@@ -300,44 +322,107 @@ function injectCache(client, cache, latestVersion, scope, namespace) {
|
|
|
300
322
|
methodNames.forEach(methodName => {
|
|
301
323
|
if (uncachedMethods.includes(methodName)) return;
|
|
302
324
|
var uncachedFn = client[methodName].bind(client);
|
|
325
|
+
var operation = contentOperation(methodName);
|
|
303
326
|
client[methodName] = /*#__PURE__*/_asyncToGenerator(function* () {
|
|
304
|
-
for (var
|
|
305
|
-
args[
|
|
327
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
328
|
+
args[_key2] = arguments[_key2];
|
|
306
329
|
}
|
|
330
|
+
emit(telemetry, {
|
|
331
|
+
type: 'content_request',
|
|
332
|
+
operation
|
|
333
|
+
});
|
|
307
334
|
// Preserve existing argument serialization; query canonicalization is separate.
|
|
308
335
|
var cacheKey = "".concat(methodName, ":").concat(JSON.stringify(args));
|
|
309
336
|
var dedupeKey = JSON.stringify([scope, namespace, latestVersion, cacheKey]);
|
|
310
337
|
return requests.run(dedupeKey, /*#__PURE__*/_asyncToGenerator(function* () {
|
|
311
338
|
try {
|
|
312
|
-
var
|
|
339
|
+
var layer = 'custom';
|
|
340
|
+
var _stored = telemetry ? yield cache.get(cacheKey, latestVersion, source => {
|
|
341
|
+
layer = source === 'memory' || source === 'redis' ? source : 'custom';
|
|
342
|
+
}) : yield cache.get(cacheKey, latestVersion);
|
|
313
343
|
var cached = scope === undefined ? _stored : (_stored === null || _stored === void 0 ? void 0 : _stored.scope) === scope ? _stored.value : undefined;
|
|
314
344
|
// Preserve existing negative-cache semantics until null results
|
|
315
345
|
// have a deliberately short TTL and correct error classification.
|
|
316
|
-
if (cached)
|
|
317
|
-
|
|
318
|
-
|
|
346
|
+
if (cached) {
|
|
347
|
+
emit(telemetry, {
|
|
348
|
+
type: 'cache_hit',
|
|
349
|
+
operation,
|
|
350
|
+
layer
|
|
351
|
+
});
|
|
352
|
+
return {
|
|
353
|
+
value: cached
|
|
354
|
+
};
|
|
355
|
+
}
|
|
319
356
|
} catch (_unused) {
|
|
357
|
+
emit(telemetry, {
|
|
358
|
+
type: 'cache_error',
|
|
359
|
+
operation,
|
|
360
|
+
action: 'read'
|
|
361
|
+
});
|
|
320
362
|
// A cache failure must not prevent a bounded origin fallback.
|
|
321
363
|
}
|
|
322
|
-
|
|
364
|
+
emit(telemetry, {
|
|
365
|
+
type: 'cache_miss',
|
|
366
|
+
operation
|
|
367
|
+
});
|
|
368
|
+
var value = yield observeOrigin(() => uncachedFn(...args), telemetry, operation);
|
|
323
369
|
var stored = scope === undefined ? value : {
|
|
324
370
|
scope,
|
|
325
371
|
value
|
|
326
372
|
};
|
|
327
373
|
// Observe synchronous and asynchronous write failures without holding
|
|
328
374
|
// up a successful response or leaving an unhandled rejection.
|
|
329
|
-
var cacheWrite = Promise.resolve().then(() => cache.set(cacheKey, stored, latestVersion)).catch(() =>
|
|
375
|
+
var cacheWrite = Promise.resolve().then(() => cache.set(cacheKey, stored, latestVersion)).catch(() => {
|
|
376
|
+
emit(telemetry, {
|
|
377
|
+
type: 'cache_error',
|
|
378
|
+
operation,
|
|
379
|
+
action: 'write'
|
|
380
|
+
});
|
|
381
|
+
});
|
|
330
382
|
return {
|
|
331
383
|
value,
|
|
332
384
|
cacheWrite
|
|
333
385
|
};
|
|
334
|
-
})
|
|
386
|
+
}), telemetry ? event => emit(telemetry, {
|
|
387
|
+
type: event === 'coalesced' ? 'coalesced' : 'content_rejected',
|
|
388
|
+
operation
|
|
389
|
+
}) : undefined);
|
|
335
390
|
});
|
|
336
391
|
});
|
|
337
392
|
}
|
|
393
|
+
function contentOperation(name) {
|
|
394
|
+
return CONTENT_OPERATIONS.includes(name) ? name : 'other';
|
|
395
|
+
}
|
|
396
|
+
function observeOrigin(invoke, telemetry, operation) {
|
|
397
|
+
if (!telemetry) return invoke();
|
|
398
|
+
var start = telemetryNow();
|
|
399
|
+
var complete = outcome => emit(telemetry, {
|
|
400
|
+
type: 'origin',
|
|
401
|
+
operation,
|
|
402
|
+
outcome,
|
|
403
|
+
seconds: elapsedSeconds(start)
|
|
404
|
+
});
|
|
405
|
+
try {
|
|
406
|
+
var value = invoke();
|
|
407
|
+
if (value && typeof value.then === 'function') {
|
|
408
|
+
return Promise.resolve(value).then(result => {
|
|
409
|
+
complete('success');
|
|
410
|
+
return result;
|
|
411
|
+
}, error => {
|
|
412
|
+
complete('error');
|
|
413
|
+
throw error;
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
complete('success');
|
|
417
|
+
return value;
|
|
418
|
+
} catch (error) {
|
|
419
|
+
complete('error');
|
|
420
|
+
throw error;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
338
423
|
function mergeQueries() {
|
|
339
|
-
for (var
|
|
340
|
-
queries[
|
|
424
|
+
for (var _len3 = arguments.length, queries = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
425
|
+
queries[_key3] = arguments[_key3];
|
|
341
426
|
}
|
|
342
427
|
var queryObjects = queries.filter(query => Boolean(query)).map(query => {
|
|
343
428
|
if (typeof query === 'string') {
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.sharedContentRequests = exports.RequestCoalescer = void 0;
|
|
7
|
+
var _telemetry = require("./telemetry.cjs");
|
|
7
8
|
var _registry$key;
|
|
8
9
|
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
9
10
|
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
|
|
@@ -22,11 +23,15 @@ class RequestCoalescer {
|
|
|
22
23
|
throw new RangeError('The pending content request limit must be a positive integer.');
|
|
23
24
|
}
|
|
24
25
|
}
|
|
25
|
-
run(key, invoke) {
|
|
26
|
+
run(key, invoke, observer) {
|
|
26
27
|
var _this = this;
|
|
27
28
|
var existing = this.pending.get(key);
|
|
28
|
-
if (existing)
|
|
29
|
+
if (existing) {
|
|
30
|
+
(0, _telemetry.notify)(observer, 'coalesced');
|
|
31
|
+
return existing;
|
|
32
|
+
}
|
|
29
33
|
if (this.pending.size >= this.limit) {
|
|
34
|
+
(0, _telemetry.notify)(observer, 'rejected');
|
|
30
35
|
return Promise.reject(new Error('Too many pending content requests.'));
|
|
31
36
|
}
|
|
32
37
|
var resolve;
|
|
@@ -7,7 +7,7 @@ export declare class RequestCoalescer {
|
|
|
7
7
|
private readonly limit;
|
|
8
8
|
private readonly pending;
|
|
9
9
|
constructor(limit?: number);
|
|
10
|
-
run<T>(key: string, invoke: () => Promise<Result<T
|
|
10
|
+
run<T>(key: string, invoke: () => Promise<Result<T>>, observer?: (event: 'coalesced' | 'rejected') => unknown): Promise<T>;
|
|
11
11
|
}
|
|
12
12
|
export declare const sharedContentRequests: RequestCoalescer;
|
|
13
13
|
export {};
|
|
@@ -16,11 +16,15 @@ export class RequestCoalescer {
|
|
|
16
16
|
throw new RangeError('The pending content request limit must be a positive integer.');
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
-
run(key, invoke) {
|
|
19
|
+
run(key, invoke, observer) {
|
|
20
20
|
var _this = this;
|
|
21
21
|
var existing = this.pending.get(key);
|
|
22
|
-
if (existing)
|
|
22
|
+
if (existing) {
|
|
23
|
+
notify(observer, 'coalesced');
|
|
24
|
+
return existing;
|
|
25
|
+
}
|
|
23
26
|
if (this.pending.size >= this.limit) {
|
|
27
|
+
notify(observer, 'rejected');
|
|
24
28
|
return Promise.reject(new Error('Too many pending content requests.'));
|
|
25
29
|
}
|
|
26
30
|
var resolve;
|
|
@@ -60,4 +64,5 @@ export class RequestCoalescer {
|
|
|
60
64
|
// Share across the ESM/CJS entrypoints and duplicate copies in one JS runtime.
|
|
61
65
|
var key = Symbol.for('@prezly/theme-kit-core/content-requests/v1');
|
|
62
66
|
var registry = globalThis;
|
|
63
|
-
export var sharedContentRequests = (_registry$key = registry[key]) !== null && _registry$key !== void 0 ? _registry$key : registry[key] = new RequestCoalescer();
|
|
67
|
+
export var sharedContentRequests = (_registry$key = registry[key]) !== null && _registry$key !== void 0 ? _registry$key : registry[key] = new RequestCoalescer();
|
|
68
|
+
import { notify } from "./telemetry.mjs";
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.RECORDS_LIMIT = void 0;
|
|
7
7
|
exports.createSharedMemoryCache = createSharedMemoryCache;
|
|
8
|
+
var _telemetry = require("../telemetry.cjs");
|
|
8
9
|
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
9
10
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
10
11
|
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
@@ -17,7 +18,7 @@ var CACHE = new Map();
|
|
|
17
18
|
function createSharedMemoryCache() {
|
|
18
19
|
var prefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
19
20
|
return {
|
|
20
|
-
get(key, latestVersion) {
|
|
21
|
+
get(key, latestVersion, onSource) {
|
|
21
22
|
var entry = CACHE.get("".concat(prefix).concat(key));
|
|
22
23
|
if (!entry) {
|
|
23
24
|
return undefined;
|
|
@@ -33,6 +34,7 @@ function createSharedMemoryCache() {
|
|
|
33
34
|
version,
|
|
34
35
|
accessed: Date.now()
|
|
35
36
|
});
|
|
37
|
+
if (onSource && value !== undefined) (0, _telemetry.notify)(onSource, 'memory');
|
|
36
38
|
return value;
|
|
37
39
|
},
|
|
38
40
|
set(key, value, version) {
|
|
@@ -4,13 +4,14 @@ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r)
|
|
|
4
4
|
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
5
5
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
6
6
|
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
7
|
+
import { notify } from "../telemetry.mjs";
|
|
7
8
|
export var RECORDS_LIMIT = 10000;
|
|
8
9
|
var GC_PROBABILITY = 1 / 100;
|
|
9
10
|
var CACHE = new Map();
|
|
10
11
|
export function createSharedMemoryCache() {
|
|
11
12
|
var prefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
12
13
|
return {
|
|
13
|
-
get(key, latestVersion) {
|
|
14
|
+
get(key, latestVersion, onSource) {
|
|
14
15
|
var entry = CACHE.get("".concat(prefix).concat(key));
|
|
15
16
|
if (!entry) {
|
|
16
17
|
return undefined;
|
|
@@ -26,6 +27,7 @@ export function createSharedMemoryCache() {
|
|
|
26
27
|
version,
|
|
27
28
|
accessed: Date.now()
|
|
28
29
|
});
|
|
30
|
+
if (onSource && value !== undefined) notify(onSource, 'memory');
|
|
29
31
|
return value;
|
|
30
32
|
},
|
|
31
33
|
set(key, value, version) {
|
|
@@ -4,17 +4,29 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.createStackedCache = createStackedCache;
|
|
7
|
+
var _telemetry = require("../telemetry.cjs");
|
|
7
8
|
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
8
9
|
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
|
|
9
10
|
function createStackedCache(caches) {
|
|
10
11
|
return {
|
|
11
|
-
get(key, latestVersion) {
|
|
12
|
+
get(key, latestVersion, onSource) {
|
|
12
13
|
return _asyncToGenerator(function* () {
|
|
14
|
+
var _loop = function* _loop() {
|
|
15
|
+
var source = 'custom';
|
|
16
|
+
var value = onSource ? yield caches[i].get(key, latestVersion, layer => {
|
|
17
|
+
source = layer;
|
|
18
|
+
}) : yield caches[i].get(key, latestVersion);
|
|
19
|
+
if (value !== undefined) {
|
|
20
|
+
if (onSource) (0, _telemetry.notify)(onSource, source);
|
|
21
|
+
return {
|
|
22
|
+
v: value
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
_ret;
|
|
13
27
|
for (var i = 0; i < caches.length; i += 1) {
|
|
14
|
-
|
|
15
|
-
if (
|
|
16
|
-
return value;
|
|
17
|
-
}
|
|
28
|
+
_ret = yield* _loop();
|
|
29
|
+
if (_ret) return _ret.v;
|
|
18
30
|
}
|
|
19
31
|
return undefined;
|
|
20
32
|
})();
|
|
@@ -1,14 +1,26 @@
|
|
|
1
1
|
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
2
2
|
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
|
|
3
|
+
import { notify } from "../telemetry.mjs";
|
|
3
4
|
export function createStackedCache(caches) {
|
|
4
5
|
return {
|
|
5
|
-
get(key, latestVersion) {
|
|
6
|
+
get(key, latestVersion, onSource) {
|
|
6
7
|
return _asyncToGenerator(function* () {
|
|
8
|
+
var _loop = function* _loop() {
|
|
9
|
+
var source = 'custom';
|
|
10
|
+
var value = onSource ? yield caches[i].get(key, latestVersion, layer => {
|
|
11
|
+
source = layer;
|
|
12
|
+
}) : yield caches[i].get(key, latestVersion);
|
|
13
|
+
if (value !== undefined) {
|
|
14
|
+
if (onSource) notify(onSource, source);
|
|
15
|
+
return {
|
|
16
|
+
v: value
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
_ret;
|
|
7
21
|
for (var i = 0; i < caches.length; i += 1) {
|
|
8
|
-
|
|
9
|
-
if (
|
|
10
|
-
return value;
|
|
11
|
-
}
|
|
22
|
+
_ret = yield* _loop();
|
|
23
|
+
if (_ret) return _ret.v;
|
|
12
24
|
}
|
|
13
25
|
return undefined;
|
|
14
26
|
})();
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export type UnixTimestampInSeconds = number;
|
|
2
2
|
type Awaitable<T> = T | Promise<T>;
|
|
3
3
|
export interface Cache {
|
|
4
|
-
get<T>(key: string, latestVersion: UnixTimestampInSeconds): Awaitable<T | undefined>;
|
|
4
|
+
get<T>(key: string, latestVersion: UnixTimestampInSeconds, onSource?: (layer: CacheLayer) => void): Awaitable<T | undefined>;
|
|
5
5
|
set<T>(key: string, value: T, version: UnixTimestampInSeconds): Awaitable<void>;
|
|
6
6
|
namespace(namespace: string): Cache;
|
|
7
7
|
}
|
|
8
|
+
import type { CacheLayer } from '../telemetry';
|
|
8
9
|
export {};
|
|
@@ -3,9 +3,26 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
createMetricsCollector: true,
|
|
8
|
+
getMetricsCollector: true
|
|
9
|
+
};
|
|
10
|
+
Object.defineProperty(exports, "createMetricsCollector", {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function get() {
|
|
13
|
+
return _metrics.createMetricsCollector;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
Object.defineProperty(exports, "getMetricsCollector", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function get() {
|
|
19
|
+
return _metrics.getMetricsCollector;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
6
22
|
var _index = require("./cache/index.cjs");
|
|
7
23
|
Object.keys(_index).forEach(function (key) {
|
|
8
24
|
if (key === "default" || key === "__esModule") return;
|
|
25
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
9
26
|
if (key in exports && exports[key] === _index[key]) return;
|
|
10
27
|
Object.defineProperty(exports, key, {
|
|
11
28
|
enumerable: true,
|
|
@@ -17,6 +34,7 @@ Object.keys(_index).forEach(function (key) {
|
|
|
17
34
|
var _ContentDelivery = require("./ContentDelivery.cjs");
|
|
18
35
|
Object.keys(_ContentDelivery).forEach(function (key) {
|
|
19
36
|
if (key === "default" || key === "__esModule") return;
|
|
37
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
20
38
|
if (key in exports && exports[key] === _ContentDelivery[key]) return;
|
|
21
39
|
Object.defineProperty(exports, key, {
|
|
22
40
|
enumerable: true,
|
|
@@ -24,4 +42,17 @@ Object.keys(_ContentDelivery).forEach(function (key) {
|
|
|
24
42
|
return _ContentDelivery[key];
|
|
25
43
|
}
|
|
26
44
|
});
|
|
27
|
-
});
|
|
45
|
+
});
|
|
46
|
+
var _telemetry = require("./telemetry.cjs");
|
|
47
|
+
Object.keys(_telemetry).forEach(function (key) {
|
|
48
|
+
if (key === "default" || key === "__esModule") return;
|
|
49
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
50
|
+
if (key in exports && exports[key] === _telemetry[key]) return;
|
|
51
|
+
Object.defineProperty(exports, key, {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
get: function get() {
|
|
54
|
+
return _telemetry[key];
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
var _metrics = require("./metrics.cjs");
|