@conduit-client/service-cache-control 2.0.0
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/LICENSE.txt +27 -0
- package/README.md +1 -0
- package/dist/main/index.js +6 -0
- package/dist/main/index.js.map +1 -0
- package/dist/types/index.d.ts +0 -0
- package/dist/types/v1/__tests__/cache-control.spec.d.ts +1 -0
- package/dist/types/v1/__tests__/utils.d.ts +28 -0
- package/dist/types/v1/cache-control-strategies/__tests__/cache-control-strategy.spec.d.ts +1 -0
- package/dist/types/v1/cache-control-strategies/__tests__/max-age-cache-control-strategy.spec.d.ts +1 -0
- package/dist/types/v1/cache-control-strategies/__tests__/no-cache-control-strategy.spec.d.ts +1 -0
- package/dist/types/v1/cache-control-strategies/__tests__/only-if-cached-cache-control-strategy.spec.d.ts +1 -0
- package/dist/types/v1/cache-control-strategies/cache-control-strategy.d.ts +18 -0
- package/dist/types/v1/cache-control-strategies/index.d.ts +3 -0
- package/dist/types/v1/cache-control-strategies/max-age-cache-control-strategy.d.ts +15 -0
- package/dist/types/v1/cache-control-strategies/no-cache-control-strategy.d.ts +9 -0
- package/dist/types/v1/cache-control-strategies/only-if-cached-cache-control-strategy.d.ts +25 -0
- package/dist/types/v1/cache-control.d.ts +43 -0
- package/dist/types/v1/index.d.ts +11 -0
- package/dist/v1/index.js +227 -0
- package/dist/v1/index.js.map +1 -0
- package/package.json +47 -0
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
*Attorney/Client Privileged + Confidential*
|
|
2
|
+
|
|
3
|
+
Terms of Use for Public Code (Non-OSS)
|
|
4
|
+
|
|
5
|
+
*NOTE:* Before publishing code under this license/these Terms of Use, please review https://salesforce.quip.com/WFfvAMKB18AL and confirm that you’ve completed all prerequisites described therein. *These Terms of Use may not be used or modified without input from IP and Product Legal.*
|
|
6
|
+
|
|
7
|
+
*Terms of Use*
|
|
8
|
+
|
|
9
|
+
Copyright 2022 Salesforce, Inc. All rights reserved.
|
|
10
|
+
|
|
11
|
+
These Terms of Use govern the download, installation, and/or use of this software provided by Salesforce, Inc. (“Salesforce”) (the “Software”), were last updated on April 15, 2022, ** and constitute a legally binding agreement between you and Salesforce. If you do not agree to these Terms of Use, do not install or use the Software.
|
|
12
|
+
|
|
13
|
+
Salesforce grants you a worldwide, non-exclusive, no-charge, royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, sublicense, and distribute the Software and derivative works subject to these Terms. These Terms shall be included in all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
Subject to the limited rights expressly granted hereunder, Salesforce reserves all rights, title, and interest in and to all intellectual property subsisting in the Software. No rights are granted to you hereunder other than as expressly set forth herein. Users residing in countries on the United States Office of Foreign Assets Control sanction list, or which are otherwise subject to a US export embargo, may not use the Software.
|
|
16
|
+
|
|
17
|
+
Implementation of the Software may require development work, for which you are responsible. The Software may contain bugs, errors and incompatibilities and is made available on an AS IS basis without support, updates, or service level commitments.
|
|
18
|
+
|
|
19
|
+
Salesforce reserves the right at any time to modify, suspend, or discontinue, the Software (or any part thereof) with or without notice. You agree that Salesforce shall not be liable to you or to any third party for any modification, suspension, or discontinuance.
|
|
20
|
+
|
|
21
|
+
You agree to defend Salesforce against any claim, demand, suit or proceeding made or brought against Salesforce by a third party arising out of or accruing from (a) your use of the Software, and (b) any application you develop with the Software that infringes any copyright, trademark, trade secret, trade dress, patent, or other intellectual property right of any person or defames any person or violates their rights of publicity or privacy (each a “Claim Against Salesforce”), and will indemnify Salesforce from any damages, attorney fees, and costs finally awarded against Salesforce as a result of, or for any amounts paid by Salesforce under a settlement approved by you in writing of, a Claim Against Salesforce, provided Salesforce (x) promptly gives you written notice of the Claim Against Salesforce, (y) gives you sole control of the defense and settlement of the Claim Against Salesforce (except that you may not settle any Claim Against Salesforce unless it unconditionally releases Salesforce of all liability), and (z) gives you all reasonable assistance, at your expense.
|
|
22
|
+
|
|
23
|
+
WITHOUT LIMITING THE GENERALITY OF THE FOREGOING, THE SOFTWARE IS NOT SUPPORTED AND IS PROVIDED "AS IS," WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. IN NO EVENT SHALL SALESFORCE HAVE ANY LIABILITY FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO, DIRECT, INDIRECT, SPECIAL, INCIDENTAL, PUNITIVE, OR CONSEQUENTIAL DAMAGES, OR DAMAGES BASED ON LOST PROFITS, DATA, OR USE, IN CONNECTION WITH THE SOFTWARE, HOWEVER CAUSED AND WHETHER IN CONTRACT, TORT, OR UNDER ANY OTHER THEORY OF LIABILITY, WHETHER OR NOT YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
|
24
|
+
|
|
25
|
+
These Terms of Use shall be governed exclusively by the internal laws of the State of California, without regard to its conflicts of laws rules. Each party hereby consents to the exclusive jurisdiction of the state and federal courts located in San Francisco County, California to adjudicate any dispute arising out of or relating to these Terms of Use and the download, installation, and/or use of the Software. Except as expressly stated herein, these Terms of Use constitute the entire agreement between the parties, and supersede all prior and contemporaneous agreements, proposals, or representations, written or oral, concerning their subject matter. No modification, amendment, or waiver of any provision of these Terms of Use shall be effective unless it is by an update to these Terms of Use that Salesforce makes available, or is in writing and signed by the party against whom the modification, amendment, or waiver is to be asserted.
|
|
26
|
+
|
|
27
|
+
_*Data Privacy*_: Salesforce may collect, process, and store device, system, and other information related to your use of the Software. This information includes, but is not limited to, IP address, user metrics, and other data (“Usage Data”). Salesforce may use Usage Data for analytics, product development, and marketing purposes. You acknowledge that files generated in conjunction with the Software may contain sensitive or confidential data, and you are solely responsible for anonymizing and protecting such data.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
This software is provided as-is with no support provided.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Key, Cache } from '@conduit-client/service-cache/v1';
|
|
2
|
+
import { DurableCacheInclusionPolicy } from '@conduit-client/service-cache-inclusion-policy/v1';
|
|
3
|
+
import { SyncOrAsync } from '@conduit-client/utils';
|
|
4
|
+
import type { RequestRunner } from '../cache-control';
|
|
5
|
+
export declare class TestRequestRunner implements RequestRunner<any, any> {
|
|
6
|
+
data: any;
|
|
7
|
+
getData: () => any;
|
|
8
|
+
readFromCache: import("vitest").Mock<(...args: any[]) => any>;
|
|
9
|
+
requestFromNetwork: import("vitest").Mock<(...args: any[]) => any>;
|
|
10
|
+
writeToCache: import("vitest").Mock<(...args: any[]) => any>;
|
|
11
|
+
}
|
|
12
|
+
export declare class NetworkRequestErrorRequestRunner extends TestRequestRunner {
|
|
13
|
+
requestFromNetwork: import("vitest").Mock<(...args: any[]) => any>;
|
|
14
|
+
}
|
|
15
|
+
export declare class CacheMissAfterNetworkRequestRunner extends TestRequestRunner {
|
|
16
|
+
writeToCache: import("vitest").Mock<(...args: any[]) => any>;
|
|
17
|
+
}
|
|
18
|
+
export declare class TestDurableCacheInclusionPolicy extends DurableCacheInclusionPolicy {
|
|
19
|
+
l2: Cache;
|
|
20
|
+
constructor();
|
|
21
|
+
revive(keys: Set<Key>, l1: Cache): SyncOrAsync<Set<Key>>;
|
|
22
|
+
syncToL2Cache(updatedKeys: Set<Key>, l1: Cache): SyncOrAsync<void>;
|
|
23
|
+
find: import("vitest").Mock<(...args: any[]) => any>;
|
|
24
|
+
findAndModify: import("vitest").Mock<(...args: any[]) => any>;
|
|
25
|
+
}
|
|
26
|
+
export declare class NoCacheRequestRunner extends TestRequestRunner {
|
|
27
|
+
writeToCache: import("vitest").Mock<(...args: any[]) => any>;
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/types/v1/cache-control-strategies/__tests__/max-age-cache-control-strategy.spec.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SyncOrAsync, type Result } from '@conduit-client/utils';
|
|
2
|
+
import type { ExecuteOptions, RequestRunner } from '../cache-control';
|
|
3
|
+
import type { CacheControlMetadata, NamedCacheService, Cache } from '@conduit-client/service-cache/v1';
|
|
4
|
+
import type { MaxAgeRequestConfig } from './max-age-cache-control-strategy';
|
|
5
|
+
import type { NoCacheRequestConfig } from './no-cache-control-strategy';
|
|
6
|
+
import type { OnlyIfCachedRequestConfig } from './only-if-cached-cache-control-strategy';
|
|
7
|
+
import { NamedInstrumentationService } from '@conduit-client/service-instrumentation/v1';
|
|
8
|
+
import { NamedCacheInclusionPolicyService } from '@conduit-client/service-cache-inclusion-policy/v1';
|
|
9
|
+
export type CacheControlStrategyConfig = MaxAgeRequestConfig | NoCacheRequestConfig | OnlyIfCachedRequestConfig;
|
|
10
|
+
export declare abstract class CacheControlStrategy<NetworkResult, Error> {
|
|
11
|
+
protected services: NamedCacheService & NamedCacheInclusionPolicyService & Partial<NamedInstrumentationService>;
|
|
12
|
+
protected config: CacheControlStrategyConfig;
|
|
13
|
+
protected requestRunner: RequestRunner<NetworkResult, Error>;
|
|
14
|
+
filteredCache: Cache;
|
|
15
|
+
constructor(services: NamedCacheService & NamedCacheInclusionPolicyService & Partial<NamedInstrumentationService>, config: CacheControlStrategyConfig, requestRunner: RequestRunner<NetworkResult, Error>);
|
|
16
|
+
abstract execute(options?: ExecuteOptions): SyncOrAsync<Result<void, Error>>;
|
|
17
|
+
protected get expiredChecks(): ((cacheControlMetadata: CacheControlMetadata) => boolean)[];
|
|
18
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type Result, type SyncOrAsync } from '@conduit-client/utils';
|
|
2
|
+
import { CacheControlStrategy } from './cache-control-strategy';
|
|
3
|
+
import type { CacheControlMetadata } from '@conduit-client/service-cache/v1';
|
|
4
|
+
import type { ExecuteOptions } from '../cache-control';
|
|
5
|
+
export type MaxAgeRequestConfig = {
|
|
6
|
+
type: 'max-age';
|
|
7
|
+
requestMaxAge: number;
|
|
8
|
+
now: number;
|
|
9
|
+
};
|
|
10
|
+
export declare class MaxAgeCacheControlStrategy<NetworkResult, Error> extends CacheControlStrategy<NetworkResult, Error> {
|
|
11
|
+
execute(options?: ExecuteOptions): SyncOrAsync<Result<void, Error>>;
|
|
12
|
+
private collectCacheHitInstrumentation;
|
|
13
|
+
private collectCacheMissInstrumentation;
|
|
14
|
+
protected get expiredChecks(): ((cacheControlMetadata: CacheControlMetadata) => boolean)[];
|
|
15
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SyncOrAsync, type Result } from '@conduit-client/utils';
|
|
2
|
+
import { CacheControlStrategy } from './cache-control-strategy';
|
|
3
|
+
export type NoCacheRequestConfig = {
|
|
4
|
+
type: 'no-cache';
|
|
5
|
+
now: number;
|
|
6
|
+
};
|
|
7
|
+
export declare class NoCacheCacheControlStrategy<NetworkResult, Error> extends CacheControlStrategy<NetworkResult, Error> {
|
|
8
|
+
execute(): SyncOrAsync<Result<void, Error>>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type Result, type SyncOrAsync } from '@conduit-client/utils';
|
|
2
|
+
import { CacheControlStrategy } from './cache-control-strategy';
|
|
3
|
+
import type { CacheControlMetadata } from '@conduit-client/service-cache/v1';
|
|
4
|
+
import type { ExecuteOptions } from '../cache-control';
|
|
5
|
+
export type OnlyIfCachedRequestConfig = {
|
|
6
|
+
type: 'only-if-cached';
|
|
7
|
+
now: number;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Only-if-cached strategy:
|
|
11
|
+
* - Never performs a network request
|
|
12
|
+
* - Returns cached data if present
|
|
13
|
+
* - Allows serving stale entries per RFC 9111 (only-if-cached may be satisfied by a stored response)
|
|
14
|
+
* - Excludes no-store entries
|
|
15
|
+
*/
|
|
16
|
+
export declare class OnlyIfCachedCacheControlStrategy<NetworkResult, Error> extends CacheControlStrategy<NetworkResult, Error> {
|
|
17
|
+
execute(options?: ExecuteOptions): SyncOrAsync<Result<void, Error>>;
|
|
18
|
+
protected get expiredChecks(): ((cacheControlMetadata: CacheControlMetadata) => cacheControlMetadata is {
|
|
19
|
+
type: "no-store";
|
|
20
|
+
} & {
|
|
21
|
+
generatedTime: number;
|
|
22
|
+
})[];
|
|
23
|
+
private collectCacheHitInstrumentation;
|
|
24
|
+
private collectCacheMissInstrumentation;
|
|
25
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type SyncOrAsync, type Result, DeepReadonly } from '@conduit-client/utils';
|
|
2
|
+
import type { CacheControlStrategyConfig } from './cache-control-strategies/cache-control-strategy';
|
|
3
|
+
import type { Cache, CacheEntry, NamedCacheService, Key, ReadonlyCache } from '@conduit-client/service-cache/v1';
|
|
4
|
+
import type { InstrumentationAttributes, NamedInstrumentationService } from '@conduit-client/service-instrumentation/v1';
|
|
5
|
+
import { NamedCacheInclusionPolicyService, CacheQuery, CacheUpdate } from '@conduit-client/service-cache-inclusion-policy/v1';
|
|
6
|
+
/**
|
|
7
|
+
* A class that exposes access for
|
|
8
|
+
* - reading from a cache
|
|
9
|
+
* - writing to a cache
|
|
10
|
+
* - making a network request
|
|
11
|
+
*
|
|
12
|
+
* This allows the cache controller to run these methods in any order
|
|
13
|
+
* based on the canonical & requested cache control metadata, without having
|
|
14
|
+
* to understand the inner workings of these functions
|
|
15
|
+
*/
|
|
16
|
+
export type RequestRunner<NetworkResult, E> = {
|
|
17
|
+
readFromCache: (cache: ReadonlyCache) => SyncOrAsync<Result<void, E>>;
|
|
18
|
+
requestFromNetwork: () => AsyncGenerator<NetworkResult | undefined, void, void>;
|
|
19
|
+
writeToCache: (cache: Cache, networkResult: NetworkResult) => SyncOrAsync<Result<void, E>>;
|
|
20
|
+
};
|
|
21
|
+
export type ExecuteOptions = {
|
|
22
|
+
instrumentationAttributes?: InstrumentationAttributes;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* A class that allows the execution of requested cache control strategies,
|
|
26
|
+
* while also enforcing the canonical cache control metadata.
|
|
27
|
+
*/
|
|
28
|
+
export declare class CacheController {
|
|
29
|
+
protected services: NamedCacheService & NamedCacheInclusionPolicyService & Partial<NamedInstrumentationService>;
|
|
30
|
+
constructor(services: NamedCacheService & NamedCacheInclusionPolicyService & Partial<NamedInstrumentationService>);
|
|
31
|
+
execute<NetworkResult, E = unknown>(config: CacheControlStrategyConfig, requestRunner: RequestRunner<NetworkResult, E>, options?: ExecuteOptions): SyncOrAsync<Result<void, E>>;
|
|
32
|
+
private getCacheControlStrategy;
|
|
33
|
+
/**
|
|
34
|
+
* Finds cache entries that match the given query.
|
|
35
|
+
* Returns an async generator that yields `[key, entry]`.
|
|
36
|
+
*/
|
|
37
|
+
find(query: CacheQuery): AsyncGenerator<[key: Key, value: DeepReadonly<CacheEntry<unknown>>], void, unknown>;
|
|
38
|
+
/**
|
|
39
|
+
* Finds and modifies cache entries that match the given query.
|
|
40
|
+
* Extends `find(query)` and returns an async generator of modified keys.
|
|
41
|
+
*/
|
|
42
|
+
findAndModify(query: CacheQuery, cacheUpdate: CacheUpdate): AsyncGenerator<Key, void, unknown>;
|
|
43
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CacheController } from './cache-control';
|
|
2
|
+
import type { ServiceDescriptor, NamedService, PublicInterface } from '@conduit-client/utils';
|
|
3
|
+
import type { Cache } from '@conduit-client/service-cache/v1';
|
|
4
|
+
import type { CacheInclusionPolicyService } from '@conduit-client/service-cache-inclusion-policy/v1';
|
|
5
|
+
import { InstrumentationService } from '@conduit-client/service-instrumentation/v1';
|
|
6
|
+
export type { CacheControlStrategyConfig } from './cache-control-strategies';
|
|
7
|
+
export type { RequestRunner } from './cache-control';
|
|
8
|
+
export type ICacheController = PublicInterface<CacheController>;
|
|
9
|
+
export type NamedCacheControllerService<Name extends string = 'cacheController'> = NamedService<Name, ICacheController>;
|
|
10
|
+
export type CacheControllerServiceDescriptor = ServiceDescriptor<ICacheController, 'cacheController', '1.0'>;
|
|
11
|
+
export declare function buildServiceDescriptor(cache: Cache, cacheInclusionPolicy: CacheInclusionPolicyService, instrumentation?: InstrumentationService): CacheControllerServiceDescriptor;
|
package/dist/v1/index.js
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2022, Salesforce, Inc.,
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* For full license text, see the LICENSE.txt file
|
|
5
|
+
*/
|
|
6
|
+
import { ok, err, UserVisibleError, FetchResponse, HttpStatusCode } from "@conduit-client/utils";
|
|
7
|
+
class CacheControlStrategy {
|
|
8
|
+
constructor(services, config, requestRunner) {
|
|
9
|
+
this.services = services;
|
|
10
|
+
this.config = config;
|
|
11
|
+
this.requestRunner = requestRunner;
|
|
12
|
+
this.filteredCache = this.services.cache.filter((_, entry) => {
|
|
13
|
+
const { cacheControl } = entry.metadata;
|
|
14
|
+
return !this.expiredChecks.some((check) => check(cacheControl));
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
get expiredChecks() {
|
|
18
|
+
return [
|
|
19
|
+
(cacheControlMetadata) => cacheControlMetadata.type === "max-age" && this.config.now > cacheControlMetadata.generatedTime + cacheControlMetadata.maxAge,
|
|
20
|
+
(cacheControlMetadata) => cacheControlMetadata.type === "max-age" && cacheControlMetadata.maxAge <= 0,
|
|
21
|
+
(cacheControlMetadata) => cacheControlMetadata.type === "no-store",
|
|
22
|
+
(cacheControlMetadata) => cacheControlMetadata.type === "no-cache" && cacheControlMetadata.generatedTime < this.config.now
|
|
23
|
+
];
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
class NoCacheCacheControlStrategy extends CacheControlStrategy {
|
|
27
|
+
execute() {
|
|
28
|
+
const tempCache = this.filteredCache;
|
|
29
|
+
return new Promise(async (resolve, reject) => {
|
|
30
|
+
try {
|
|
31
|
+
let readResult = ok(void 0);
|
|
32
|
+
for await (const rfnResult of this.requestRunner.requestFromNetwork()) {
|
|
33
|
+
if (rfnResult) {
|
|
34
|
+
const result = await this.services.cacheInclusionPolicy.write({
|
|
35
|
+
l1: tempCache,
|
|
36
|
+
writeToL1: (l1) => this.requestRunner.writeToCache(l1, rfnResult)
|
|
37
|
+
});
|
|
38
|
+
if (result.isErr()) {
|
|
39
|
+
return resolve(result);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
readResult = await this.services.cacheInclusionPolicy.read({
|
|
43
|
+
l1: tempCache,
|
|
44
|
+
readFromL1: (l1) => this.requestRunner.readFromCache(l1)
|
|
45
|
+
});
|
|
46
|
+
if (readResult.isOk()) {
|
|
47
|
+
resolve(readResult);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return resolve(readResult);
|
|
51
|
+
} catch (error) {
|
|
52
|
+
return reject(error);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
class MaxAgeCacheControlStrategy extends CacheControlStrategy {
|
|
58
|
+
execute(options) {
|
|
59
|
+
const startTime = this.services.instrumentation ? this.services.instrumentation.currentTimeMs() : 0;
|
|
60
|
+
return this.services.cacheInclusionPolicy.read({
|
|
61
|
+
l1: this.filteredCache,
|
|
62
|
+
readFromL1: (l1) => this.requestRunner.readFromCache(l1)
|
|
63
|
+
}).then((value) => {
|
|
64
|
+
if (value.isOk()) {
|
|
65
|
+
this.collectCacheHitInstrumentation(
|
|
66
|
+
startTime,
|
|
67
|
+
options == null ? void 0 : options.instrumentationAttributes
|
|
68
|
+
);
|
|
69
|
+
return ok(void 0);
|
|
70
|
+
}
|
|
71
|
+
this.collectCacheMissInstrumentation(startTime, options == null ? void 0 : options.instrumentationAttributes);
|
|
72
|
+
const tempCache = this.filteredCache;
|
|
73
|
+
return new Promise(async (resolve, reject) => {
|
|
74
|
+
try {
|
|
75
|
+
let readResult = ok(void 0);
|
|
76
|
+
for await (const rfnResult of this.requestRunner.requestFromNetwork()) {
|
|
77
|
+
if (rfnResult) {
|
|
78
|
+
const result = await this.services.cacheInclusionPolicy.write({
|
|
79
|
+
l1: tempCache,
|
|
80
|
+
writeToL1: (l1) => this.requestRunner.writeToCache(l1, rfnResult)
|
|
81
|
+
});
|
|
82
|
+
if (result.isErr()) {
|
|
83
|
+
return resolve(err(result.error));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
readResult = await this.services.cacheInclusionPolicy.read({
|
|
87
|
+
l1: tempCache,
|
|
88
|
+
readFromL1: (l1) => this.requestRunner.readFromCache(l1)
|
|
89
|
+
});
|
|
90
|
+
if (readResult.isOk()) {
|
|
91
|
+
resolve(ok(void 0));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return resolve(readResult);
|
|
95
|
+
} catch (e) {
|
|
96
|
+
return reject(e);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
collectCacheHitInstrumentation(startTime, instrumentationAttributes) {
|
|
102
|
+
if (this.services.instrumentation) {
|
|
103
|
+
const meter = this.services.instrumentation.metrics.getMeter("onestore");
|
|
104
|
+
meter.createCounter(`command.max-age.cache-hit.count`).add(1, instrumentationAttributes);
|
|
105
|
+
meter.createHistogram(`command.max-age.cache-hit.duration`).record(
|
|
106
|
+
this.services.instrumentation.currentTimeMs() - startTime,
|
|
107
|
+
instrumentationAttributes
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
collectCacheMissInstrumentation(startTime, instrumentationAttributes) {
|
|
112
|
+
if (this.services.instrumentation) {
|
|
113
|
+
const meter = this.services.instrumentation.metrics.getMeter("onestore");
|
|
114
|
+
meter.createCounter(`command.max-age.cache-miss.count`).add(1, instrumentationAttributes);
|
|
115
|
+
meter.createHistogram(`command.max-age.cache-miss.duration`).record(
|
|
116
|
+
this.services.instrumentation.currentTimeMs() - startTime,
|
|
117
|
+
instrumentationAttributes
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
get expiredChecks() {
|
|
122
|
+
const config = this.config;
|
|
123
|
+
return [
|
|
124
|
+
...super.expiredChecks,
|
|
125
|
+
(cacheControlMetadata) => {
|
|
126
|
+
return cacheControlMetadata.generatedTime + config.requestMaxAge < config.now;
|
|
127
|
+
}
|
|
128
|
+
];
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
class OnlyIfCachedCacheControlStrategy extends CacheControlStrategy {
|
|
132
|
+
execute(options) {
|
|
133
|
+
const startTime = this.services.instrumentation ? this.services.instrumentation.currentTimeMs() : 0;
|
|
134
|
+
return this.services.cacheInclusionPolicy.read({
|
|
135
|
+
l1: this.filteredCache,
|
|
136
|
+
readFromL1: (l1) => this.requestRunner.readFromCache(l1)
|
|
137
|
+
}).then((result) => {
|
|
138
|
+
if (result.isOk()) {
|
|
139
|
+
this.collectCacheHitInstrumentation(
|
|
140
|
+
startTime,
|
|
141
|
+
options == null ? void 0 : options.instrumentationAttributes
|
|
142
|
+
);
|
|
143
|
+
return ok(void 0);
|
|
144
|
+
}
|
|
145
|
+
this.collectCacheMissInstrumentation(startTime, options == null ? void 0 : options.instrumentationAttributes);
|
|
146
|
+
const error = new UserVisibleError(
|
|
147
|
+
new FetchResponse(HttpStatusCode.GatewayTimeout, {
|
|
148
|
+
error: "Cache miss for only-if-cached request"
|
|
149
|
+
})
|
|
150
|
+
);
|
|
151
|
+
return err(error);
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
get expiredChecks() {
|
|
155
|
+
return [
|
|
156
|
+
(cacheControlMetadata) => cacheControlMetadata.type === "no-store"
|
|
157
|
+
];
|
|
158
|
+
}
|
|
159
|
+
collectCacheHitInstrumentation(startTime, instrumentationAttributes) {
|
|
160
|
+
if (this.services.instrumentation) {
|
|
161
|
+
const meter = this.services.instrumentation.metrics.getMeter("onestore");
|
|
162
|
+
meter.createCounter(`command.only-if-cached.cache-hit.count`).add(1, instrumentationAttributes);
|
|
163
|
+
meter.createHistogram(
|
|
164
|
+
`command.only-if-cached.cache-hit.duration`
|
|
165
|
+
).record(
|
|
166
|
+
this.services.instrumentation.currentTimeMs() - startTime,
|
|
167
|
+
instrumentationAttributes
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
collectCacheMissInstrumentation(startTime, instrumentationAttributes) {
|
|
172
|
+
if (this.services.instrumentation) {
|
|
173
|
+
const meter = this.services.instrumentation.metrics.getMeter("onestore");
|
|
174
|
+
meter.createCounter(`command.only-if-cached.cache-miss.count`).add(1, instrumentationAttributes);
|
|
175
|
+
meter.createHistogram(
|
|
176
|
+
`command.only-if-cached.cache-miss.duration`
|
|
177
|
+
).record(
|
|
178
|
+
this.services.instrumentation.currentTimeMs() - startTime,
|
|
179
|
+
instrumentationAttributes
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
class CacheController {
|
|
185
|
+
constructor(services) {
|
|
186
|
+
this.services = services;
|
|
187
|
+
}
|
|
188
|
+
execute(config, requestRunner, options) {
|
|
189
|
+
const strategy = this.getCacheControlStrategy(config, requestRunner);
|
|
190
|
+
return strategy.execute(options);
|
|
191
|
+
}
|
|
192
|
+
getCacheControlStrategy(config, requestRunner) {
|
|
193
|
+
if (config.type === "max-age") {
|
|
194
|
+
return new MaxAgeCacheControlStrategy(this.services, config, requestRunner);
|
|
195
|
+
} else if (config.type === "no-cache") {
|
|
196
|
+
return new NoCacheCacheControlStrategy(this.services, config, requestRunner);
|
|
197
|
+
} else if (config.type === "only-if-cached") {
|
|
198
|
+
return new OnlyIfCachedCacheControlStrategy(this.services, config, requestRunner);
|
|
199
|
+
}
|
|
200
|
+
throw new Error(`Unknown cache control strategy ${config.type}`);
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Finds cache entries that match the given query.
|
|
204
|
+
* Returns an async generator that yields `[key, entry]`.
|
|
205
|
+
*/
|
|
206
|
+
async *find(query) {
|
|
207
|
+
yield* this.services.cacheInclusionPolicy.find(query);
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Finds and modifies cache entries that match the given query.
|
|
211
|
+
* Extends `find(query)` and returns an async generator of modified keys.
|
|
212
|
+
*/
|
|
213
|
+
async *findAndModify(query, cacheUpdate) {
|
|
214
|
+
yield* this.services.cacheInclusionPolicy.findAndModify(query, cacheUpdate);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
function buildServiceDescriptor(cache, cacheInclusionPolicy, instrumentation) {
|
|
218
|
+
return {
|
|
219
|
+
type: "cacheController",
|
|
220
|
+
version: "1.0",
|
|
221
|
+
service: new CacheController({ cache, cacheInclusionPolicy, instrumentation })
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
export {
|
|
225
|
+
buildServiceDescriptor
|
|
226
|
+
};
|
|
227
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/v1/cache-control-strategies/cache-control-strategy.ts","../../src/v1/cache-control-strategies/no-cache-control-strategy.ts","../../src/v1/cache-control-strategies/max-age-cache-control-strategy.ts","../../src/v1/cache-control-strategies/only-if-cached-cache-control-strategy.ts","../../src/v1/cache-control.ts","../../src/v1/index.ts"],"sourcesContent":["import { SyncOrAsync, type Result } from '@conduit-client/utils';\nimport type { ExecuteOptions, RequestRunner } from '../cache-control';\nimport type {\n CacheControlMetadata,\n CacheEntry,\n NamedCacheService,\n Cache,\n} from '@conduit-client/service-cache/v1';\nimport type { MaxAgeRequestConfig } from './max-age-cache-control-strategy';\nimport type { NoCacheRequestConfig } from './no-cache-control-strategy';\nimport type { OnlyIfCachedRequestConfig } from './only-if-cached-cache-control-strategy';\nimport { NamedInstrumentationService } from '@conduit-client/service-instrumentation/v1';\nimport { NamedCacheInclusionPolicyService } from '@conduit-client/service-cache-inclusion-policy/v1';\n\nexport type CacheControlStrategyConfig =\n | MaxAgeRequestConfig\n | NoCacheRequestConfig\n | OnlyIfCachedRequestConfig;\n\nexport abstract class CacheControlStrategy<NetworkResult, Error> {\n filteredCache: Cache;\n constructor(\n protected services: NamedCacheService &\n NamedCacheInclusionPolicyService &\n Partial<NamedInstrumentationService>,\n protected config: CacheControlStrategyConfig,\n protected requestRunner: RequestRunner<NetworkResult, Error>\n ) {\n this.filteredCache = this.services.cache.filter((_, entry: CacheEntry<unknown>) => {\n const { cacheControl } = entry.metadata;\n return !this.expiredChecks.some((check) => check(cacheControl));\n });\n }\n\n abstract execute(options?: ExecuteOptions): SyncOrAsync<Result<void, Error>>;\n\n protected get expiredChecks() {\n return [\n (cacheControlMetadata: CacheControlMetadata) =>\n cacheControlMetadata.type === 'max-age' &&\n this.config.now > cacheControlMetadata.generatedTime + cacheControlMetadata.maxAge,\n (cacheControlMetadata: CacheControlMetadata) =>\n cacheControlMetadata.type === 'max-age' && cacheControlMetadata.maxAge <= 0,\n (cacheControlMetadata: CacheControlMetadata) =>\n cacheControlMetadata.type === 'no-store',\n (cacheControlMetadata: CacheControlMetadata) =>\n cacheControlMetadata.type === 'no-cache' &&\n cacheControlMetadata.generatedTime < this.config.now,\n ];\n }\n}\n","import { err, ok, SyncOrAsync, type Result } from '@conduit-client/utils';\nimport { CacheControlStrategy } from './cache-control-strategy';\n\nexport type NoCacheRequestConfig = {\n type: 'no-cache';\n now: number; // seconds\n};\n\nexport class NoCacheCacheControlStrategy<NetworkResult, Error> extends CacheControlStrategy<\n NetworkResult,\n Error\n> {\n execute(): SyncOrAsync<Result<void, Error>> {\n // TODO - should be using wrapper here that suppresses no-store writes\n const tempCache = this.filteredCache;\n return new Promise(async (resolve, reject) => {\n try {\n let readResult: Result<void, Error> = ok(undefined);\n for await (const rfnResult of this.requestRunner.requestFromNetwork()) {\n if (rfnResult) {\n const result = await this.services.cacheInclusionPolicy.write({\n l1: tempCache,\n writeToL1: (l1) => this.requestRunner.writeToCache(l1, rfnResult),\n });\n if (result.isErr()) {\n return resolve(result);\n }\n }\n // give readFromCache another shot at the cache\n readResult = await this.services.cacheInclusionPolicy.read({\n l1: tempCache,\n readFromL1: (l1) => this.requestRunner.readFromCache(l1),\n });\n if (readResult.isOk()) {\n resolve(readResult);\n }\n }\n return resolve(readResult);\n } catch (error) {\n return reject(error);\n }\n });\n }\n}\n","import {\n type Err,\n err,\n ok,\n resolvedPromiseLike,\n type Result,\n type SyncOrAsync,\n} from '@conduit-client/utils';\nimport { CacheControlStrategy } from './cache-control-strategy';\nimport type { CacheControlMetadata, Cache } from '@conduit-client/service-cache/v1';\nimport type { ExecuteOptions } from '../cache-control';\nimport { InstrumentationAttributes } from '@conduit-client/service-instrumentation/v1';\n\nexport type MaxAgeRequestConfig = {\n type: 'max-age';\n requestMaxAge: number; // seconds\n now: number; // seconds\n};\nexport class MaxAgeCacheControlStrategy<NetworkResult, Error> extends CacheControlStrategy<\n NetworkResult,\n Error\n> {\n execute(options?: ExecuteOptions): SyncOrAsync<Result<void, Error>> {\n const startTime: number = this.services.instrumentation\n ? this.services.instrumentation.currentTimeMs()\n : 0;\n\n return this.services.cacheInclusionPolicy\n .read({\n l1: this.filteredCache,\n readFromL1: (l1) => this.requestRunner.readFromCache(l1),\n })\n .then((value) => {\n // ignore error from initial cache read\n if (value.isOk()) {\n this.collectCacheHitInstrumentation(\n startTime,\n options?.instrumentationAttributes\n );\n return ok(undefined);\n }\n\n this.collectCacheMissInstrumentation(startTime, options?.instrumentationAttributes);\n\n // initial cache read failed, awaits are ok beyond this point since the data\n // must come from network requests\n const tempCache = this.filteredCache;\n return new Promise(async (resolve, reject) => {\n try {\n let readResult: Result<void, Error> = ok(undefined);\n for await (const rfnResult of this.requestRunner.requestFromNetwork()) {\n // async generator has a value to ingest\n if (rfnResult) {\n const result = await this.services.cacheInclusionPolicy.write({\n l1: tempCache,\n writeToL1: (l1) =>\n this.requestRunner.writeToCache(l1, rfnResult),\n });\n if (result.isErr()) {\n return resolve(err(result.error));\n }\n }\n\n // give readFromCache another shot at the cache\n readResult = await this.services.cacheInclusionPolicy.read({\n l1: tempCache,\n readFromL1: (l1) => this.requestRunner.readFromCache(l1),\n });\n if (readResult.isOk()) {\n resolve(ok(undefined));\n }\n }\n return resolve(readResult);\n } catch (e) {\n return reject(e);\n }\n });\n });\n }\n\n private collectCacheHitInstrumentation(\n startTime: number,\n instrumentationAttributes: InstrumentationAttributes | undefined\n ) {\n if (this.services.instrumentation) {\n const meter = this.services.instrumentation.metrics.getMeter('onestore');\n meter\n .createCounter<InstrumentationAttributes>(`command.max-age.cache-hit.count`)\n .add(1, instrumentationAttributes);\n meter\n .createHistogram<InstrumentationAttributes>(`command.max-age.cache-hit.duration`)\n .record(\n this.services.instrumentation.currentTimeMs() - startTime,\n instrumentationAttributes\n );\n }\n }\n\n private collectCacheMissInstrumentation(\n startTime: number,\n instrumentationAttributes: InstrumentationAttributes | undefined\n ) {\n if (this.services.instrumentation) {\n const meter = this.services.instrumentation.metrics.getMeter('onestore');\n meter\n .createCounter<InstrumentationAttributes>(`command.max-age.cache-miss.count`)\n .add(1, instrumentationAttributes);\n meter\n .createHistogram<InstrumentationAttributes>(`command.max-age.cache-miss.duration`)\n .record(\n this.services.instrumentation.currentTimeMs() - startTime,\n instrumentationAttributes\n );\n }\n }\n\n protected get expiredChecks() {\n const config = this.config as MaxAgeRequestConfig;\n return [\n ...super.expiredChecks,\n (cacheControlMetadata: CacheControlMetadata) => {\n return cacheControlMetadata.generatedTime + config.requestMaxAge < config.now;\n },\n ];\n }\n}\n","import {\n err,\n type Result,\n type SyncOrAsync,\n FetchResponse,\n HttpStatusCode,\n UserVisibleError,\n ok,\n} from '@conduit-client/utils';\nimport { CacheControlStrategy } from './cache-control-strategy';\nimport type { CacheControlMetadata } from '@conduit-client/service-cache/v1';\nimport type { ExecuteOptions } from '../cache-control';\nimport { InstrumentationAttributes } from '@conduit-client/service-instrumentation/v1';\n\nexport type OnlyIfCachedRequestConfig = {\n type: 'only-if-cached';\n now: number; // seconds\n};\n\n/**\n * Only-if-cached strategy:\n * - Never performs a network request\n * - Returns cached data if present\n * - Allows serving stale entries per RFC 9111 (only-if-cached may be satisfied by a stored response)\n * - Excludes no-store entries\n */\nexport class OnlyIfCachedCacheControlStrategy<NetworkResult, Error> extends CacheControlStrategy<\n NetworkResult,\n Error\n> {\n execute(options?: ExecuteOptions): SyncOrAsync<Result<void, Error>> {\n const startTime: number = this.services.instrumentation\n ? this.services.instrumentation.currentTimeMs()\n : 0;\n\n return this.services.cacheInclusionPolicy\n .read({\n l1: this.filteredCache,\n readFromL1: (l1) => this.requestRunner.readFromCache(l1),\n })\n .then((result) => {\n if (result.isOk()) {\n this.collectCacheHitInstrumentation(\n startTime,\n options?.instrumentationAttributes\n );\n return ok(undefined);\n }\n this.collectCacheMissInstrumentation(startTime, options?.instrumentationAttributes);\n const error = new UserVisibleError(\n new FetchResponse(HttpStatusCode.GatewayTimeout, {\n error: 'Cache miss for only-if-cached request',\n })\n );\n return err(error as unknown as Error);\n });\n }\n\n protected get expiredChecks() {\n // Allow stale cached entries (max-age expired or no-cache) to be used.\n // Still exclude no-store entries.\n return [\n (cacheControlMetadata: CacheControlMetadata) =>\n cacheControlMetadata.type === 'no-store',\n ];\n }\n\n private collectCacheHitInstrumentation(\n startTime: number,\n instrumentationAttributes: InstrumentationAttributes | undefined\n ) {\n if (this.services.instrumentation) {\n const meter = this.services.instrumentation.metrics.getMeter('onestore');\n meter\n .createCounter<InstrumentationAttributes>(`command.only-if-cached.cache-hit.count`)\n .add(1, instrumentationAttributes);\n meter\n .createHistogram<InstrumentationAttributes>(\n `command.only-if-cached.cache-hit.duration`\n )\n .record(\n this.services.instrumentation.currentTimeMs() - startTime,\n instrumentationAttributes\n );\n }\n }\n\n private collectCacheMissInstrumentation(\n startTime: number,\n instrumentationAttributes: InstrumentationAttributes | undefined\n ) {\n if (this.services.instrumentation) {\n const meter = this.services.instrumentation.metrics.getMeter('onestore');\n meter\n .createCounter<InstrumentationAttributes>(`command.only-if-cached.cache-miss.count`)\n .add(1, instrumentationAttributes);\n meter\n .createHistogram<InstrumentationAttributes>(\n `command.only-if-cached.cache-miss.duration`\n )\n .record(\n this.services.instrumentation.currentTimeMs() - startTime,\n instrumentationAttributes\n );\n }\n }\n}\n","import { type SyncOrAsync, type Result, DeepReadonly } from '@conduit-client/utils';\nimport { NoCacheCacheControlStrategy } from './cache-control-strategies/no-cache-control-strategy';\nimport { MaxAgeCacheControlStrategy } from './cache-control-strategies/max-age-cache-control-strategy';\nimport { OnlyIfCachedCacheControlStrategy } from './cache-control-strategies/only-if-cached-cache-control-strategy';\nimport type {\n CacheControlStrategy,\n CacheControlStrategyConfig,\n} from './cache-control-strategies/cache-control-strategy';\nimport type {\n Cache,\n CacheEntry,\n NamedCacheService,\n Key,\n ReadonlyCache,\n} from '@conduit-client/service-cache/v1';\nimport type {\n InstrumentationAttributes,\n NamedInstrumentationService,\n} from '@conduit-client/service-instrumentation/v1';\nimport {\n NamedCacheInclusionPolicyService,\n CacheQuery,\n CacheUpdate,\n} from '@conduit-client/service-cache-inclusion-policy/v1';\n\n/**\n * A class that exposes access for\n * - reading from a cache\n * - writing to a cache\n * - making a network request\n *\n * This allows the cache controller to run these methods in any order\n * based on the canonical & requested cache control metadata, without having\n * to understand the inner workings of these functions\n */\nexport type RequestRunner<NetworkResult, E> = {\n readFromCache: (cache: ReadonlyCache) => SyncOrAsync<Result<void, E>>;\n requestFromNetwork: () => AsyncGenerator<NetworkResult | undefined, void, void>;\n writeToCache: (cache: Cache, networkResult: NetworkResult) => SyncOrAsync<Result<void, E>>;\n};\n\nexport type ExecuteOptions = {\n instrumentationAttributes?: InstrumentationAttributes;\n};\n\n/**\n * A class that allows the execution of requested cache control strategies,\n * while also enforcing the canonical cache control metadata.\n */\nexport class CacheController {\n constructor(\n protected services: NamedCacheService &\n NamedCacheInclusionPolicyService &\n Partial<NamedInstrumentationService>\n ) {}\n\n execute<NetworkResult, E = unknown>(\n config: CacheControlStrategyConfig,\n requestRunner: RequestRunner<NetworkResult, E>,\n options?: ExecuteOptions\n ) {\n const strategy = this.getCacheControlStrategy<NetworkResult, E>(config, requestRunner);\n return strategy.execute(options);\n }\n\n private getCacheControlStrategy<NetworkResult, Error>(\n config: CacheControlStrategyConfig,\n requestRunner: RequestRunner<NetworkResult, Error>\n ): CacheControlStrategy<NetworkResult, Error> {\n if (config.type === 'max-age') {\n return new MaxAgeCacheControlStrategy(this.services, config, requestRunner);\n } else if (config.type === 'no-cache') {\n return new NoCacheCacheControlStrategy(this.services, config, requestRunner);\n } else if (config.type === 'only-if-cached') {\n return new OnlyIfCachedCacheControlStrategy(this.services, config, requestRunner);\n }\n\n throw new Error(`Unknown cache control strategy ${(config as any).type}`);\n }\n\n /**\n * Finds cache entries that match the given query.\n * Returns an async generator that yields `[key, entry]`.\n */\n async *find(\n query: CacheQuery\n ): AsyncGenerator<[key: Key, value: DeepReadonly<CacheEntry<unknown>>], void, unknown> {\n yield* this.services.cacheInclusionPolicy.find(query);\n }\n\n /**\n * Finds and modifies cache entries that match the given query.\n * Extends `find(query)` and returns an async generator of modified keys.\n */\n async *findAndModify(\n query: CacheQuery,\n cacheUpdate: CacheUpdate\n ): AsyncGenerator<Key, void, unknown> {\n yield* this.services.cacheInclusionPolicy.findAndModify(query, cacheUpdate);\n }\n}\n","import { CacheController } from './cache-control';\nimport type { ServiceDescriptor, NamedService, PublicInterface } from '@conduit-client/utils';\nimport type { Cache } from '@conduit-client/service-cache/v1';\nimport type { CacheInclusionPolicyService } from '@conduit-client/service-cache-inclusion-policy/v1';\nimport { InstrumentationService } from '@conduit-client/service-instrumentation/v1';\nexport type { CacheControlStrategyConfig } from './cache-control-strategies';\n\nexport type { RequestRunner } from './cache-control';\n\nexport type ICacheController = PublicInterface<CacheController>;\n\nexport type NamedCacheControllerService<Name extends string = 'cacheController'> = NamedService<\n Name,\n ICacheController\n>;\n\nexport type CacheControllerServiceDescriptor = ServiceDescriptor<\n ICacheController,\n 'cacheController',\n '1.0'\n>;\n\nexport function buildServiceDescriptor(\n cache: Cache,\n cacheInclusionPolicy: CacheInclusionPolicyService,\n instrumentation?: InstrumentationService\n): CacheControllerServiceDescriptor {\n return {\n type: 'cacheController',\n version: '1.0',\n service: new CacheController({ cache, cacheInclusionPolicy, instrumentation }),\n };\n}\n"],"names":[],"mappings":";;;;;;AAmBO,MAAe,qBAA2C;AAAA,EAE7D,YACc,UAGA,QACA,eACZ;AALY,SAAA,WAAA;AAGA,SAAA,SAAA;AACA,SAAA,gBAAA;AAEV,SAAK,gBAAgB,KAAK,SAAS,MAAM,OAAO,CAAC,GAAG,UAA+B;AAC/E,YAAM,EAAE,iBAAiB,MAAM;AAC/B,aAAO,CAAC,KAAK,cAAc,KAAK,CAAC,UAAU,MAAM,YAAY,CAAC;AAAA,IAClE,CAAC;AAAA,EACL;AAAA,EAIA,IAAc,gBAAgB;AAC1B,WAAO;AAAA,MACH,CAAC,yBACG,qBAAqB,SAAS,aAC9B,KAAK,OAAO,MAAM,qBAAqB,gBAAgB,qBAAqB;AAAA,MAChF,CAAC,yBACG,qBAAqB,SAAS,aAAa,qBAAqB,UAAU;AAAA,MAC9E,CAAC,yBACG,qBAAqB,SAAS;AAAA,MAClC,CAAC,yBACG,qBAAqB,SAAS,cAC9B,qBAAqB,gBAAgB,KAAK,OAAO;AAAA,IAAA;AAAA,EAE7D;AACJ;AC1CO,MAAM,oCAA0D,qBAGrE;AAAA,EACE,UAA4C;AAExC,UAAM,YAAY,KAAK;AACvB,WAAO,IAAI,QAAQ,OAAO,SAAS,WAAW;AAC1C,UAAI;AACA,YAAI,aAAkC,GAAG,MAAS;AAClD,yBAAiB,aAAa,KAAK,cAAc,mBAAA,GAAsB;AACnE,cAAI,WAAW;AACX,kBAAM,SAAS,MAAM,KAAK,SAAS,qBAAqB,MAAM;AAAA,cAC1D,IAAI;AAAA,cACJ,WAAW,CAAC,OAAO,KAAK,c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AAK,SAAS,gBAAgB,cAAA,IAAkB;AAAA,QAChD;AAAA,MAAA;AAAA,IAEZ;AAAA,EACJ;AACJ;ACzDO,MAAM,gBAAgB;AAAA,EACzB,YACc,UAGZ;AAHY,SAAA,WAAA;AAAA,EAGX;AAAA,EAEH,QACI,QACA,eACA,SACF;AACE,UAAM,WAAW,KAAK,wBAA0C,QAAQ,aAAa;AACrF,WAAO,SAAS,QAAQ,OAAO;AAAA,EACnC;AAAA,EAEQ,wBACJ,QACA,eAC0C;AAC1C,QAAI,OAAO,SAAS,WAAW;AAC3B,aAAO,IAAI,2BAA2B,KAAK,UAAU,QAAQ,aAAa;AAAA,IAC9E,WAAW,OAAO,SAAS,YAAY;AACnC,aAAO,IAAI,4BAA4B,KAAK,UAAU,QAAQ,aAAa;AAAA,IAC/E,WAAW,OAAO,SAAS,kBAAkB;AACzC,aAAO,IAAI,iCAAiC,KAAK,UAAU,QAAQ,aAAa;AAAA,IACpF;AAEA,UAAM,IAAI,MAAM,kCAAmC,OAAe,IAAI,EAAE;AAAA,EAC5E;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,OAAO,KACH,OACmF;AACnF,WAAO,KAAK,SAAS,qBAAqB,KAAK,KAAK;AAAA,EACxD;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,OAAO,cACH,OACA,aACkC;AAClC,WAAO,KAAK,SAAS,qBAAqB,cAAc,OAAO,WAAW;AAAA,EAC9E;AACJ;AC9EO,SAAS,uBACZ,OACA,sBACA,iBACgC;AAChC,SAAO;AAAA,IACH,MAAM;AAAA,IACN,SAAS;AAAA,IACT,SAAS,IAAI,gBAAgB,EAAE,OAAO,sBAAsB,iBAAiB;AAAA,EAAA;AAErF;"}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@conduit-client/service-cache-control",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "OneStore Cache Control Service definition",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/salesforce-experience-platform-emu/luvio-next.git",
|
|
10
|
+
"directory": "packages/@conduit-client/services/cache-control"
|
|
11
|
+
},
|
|
12
|
+
"license": "SEE LICENSE IN LICENSE.txt",
|
|
13
|
+
"exports": {
|
|
14
|
+
"./v1": {
|
|
15
|
+
"import": "./dist/v1/index.js",
|
|
16
|
+
"types": "./dist/types/v1/index.d.ts",
|
|
17
|
+
"require": "./dist/v1/index.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"main": "dist/index.js",
|
|
21
|
+
"module": "./dist/main/index.js",
|
|
22
|
+
"types": "dist/types/index.d.ts",
|
|
23
|
+
"files": [
|
|
24
|
+
"dist/"
|
|
25
|
+
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "vite build && tsc --build --emitDeclarationOnly",
|
|
28
|
+
"clean": "rm -rf dist",
|
|
29
|
+
"test": "vitest run",
|
|
30
|
+
"test:size": "size-limit",
|
|
31
|
+
"watch": "npm run build --watch"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@conduit-client/service-cache": "2.0.0",
|
|
35
|
+
"@conduit-client/service-cache-inclusion-policy": "2.0.0",
|
|
36
|
+
"@conduit-client/utils": "2.0.0"
|
|
37
|
+
},
|
|
38
|
+
"volta": {
|
|
39
|
+
"extends": "../../../../package.json"
|
|
40
|
+
},
|
|
41
|
+
"size-limit": [
|
|
42
|
+
{
|
|
43
|
+
"path": "./dist/v1/index.js",
|
|
44
|
+
"limit": "2.6 kB"
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
}
|