@conduit-client/command-http-normalized-cache-control 5.67.0-dev1
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__/http-normalized-cache-control-command.spec.d.ts +1 -0
- package/dist/types/v1/__tests__/index.spec.d.ts +1 -0
- package/dist/types/v1/__tests__/utils/commands.d.ts +49 -0
- package/dist/types/v1/__tests__/utils/types.d.ts +107 -0
- package/dist/types/v1/http-normalized-cache-control-command.d.ts +23 -0
- package/dist/types/v1/index.d.ts +6 -0
- package/dist/v1/index.js +95 -0
- package/dist/v1/index.js.map +1 -0
- package/package.json +51 -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 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { NamedCacheControllerService } from '@conduit-client/service-cache-control/v1';
|
|
2
|
+
import { NamedPubSubService } from '@conduit-client/service-pubsub/v1';
|
|
3
|
+
import { FetchService, NamedFetchService } from '@conduit-client/service-fetch-network/v1';
|
|
4
|
+
import { HttpNormalizedCacheControlCommand } from '../../http-normalized-cache-control-command';
|
|
5
|
+
import { Author, AuthorType, PostType, Post, ExampleModuleTypeRegistry } from './types';
|
|
6
|
+
import { KeyParamsOf, WriteInputOf } from '@conduit-client/type-normalization/v1';
|
|
7
|
+
export declare class GetPostCommand extends HttpNormalizedCacheControlCommand<PostType> {
|
|
8
|
+
config: KeyParamsOf<PostType>;
|
|
9
|
+
protected typeRegistry: ExampleModuleTypeRegistry;
|
|
10
|
+
equals(result1: Post, result2: Post): boolean;
|
|
11
|
+
get fetchParams(): Parameters<FetchService>;
|
|
12
|
+
constructor(config: KeyParamsOf<PostType>, services: NamedCacheControllerService & Partial<NamedPubSubService> & NamedFetchService, typeRegistry: ExampleModuleTypeRegistry);
|
|
13
|
+
protected cacheControlStrategyConfig: {
|
|
14
|
+
readonly type: "max-age";
|
|
15
|
+
readonly requestMaxAge: 100;
|
|
16
|
+
readonly now: 0;
|
|
17
|
+
};
|
|
18
|
+
coerceError(error: any): Promise<Error>;
|
|
19
|
+
buildResultType(): PostType;
|
|
20
|
+
buildWriteInput(data: Post): WriteInputOf<PostType>;
|
|
21
|
+
buildQuery(): {
|
|
22
|
+
readonly keyParams: {
|
|
23
|
+
id: number;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export declare class GetAuthorCommand extends HttpNormalizedCacheControlCommand<AuthorType> {
|
|
28
|
+
config: KeyParamsOf<AuthorType>;
|
|
29
|
+
protected typeRegistry: ExampleModuleTypeRegistry;
|
|
30
|
+
equals(result1: Author, result2: Author): boolean;
|
|
31
|
+
get fetchParams(): Parameters<FetchService>;
|
|
32
|
+
protected cacheControlStrategyConfig: {
|
|
33
|
+
readonly type: "max-age";
|
|
34
|
+
readonly requestMaxAge: 100;
|
|
35
|
+
readonly now: 0;
|
|
36
|
+
};
|
|
37
|
+
constructor(config: KeyParamsOf<AuthorType>, services: NamedCacheControllerService & Partial<NamedPubSubService> & NamedFetchService, typeRegistry: ExampleModuleTypeRegistry);
|
|
38
|
+
coerceError(error: any): Promise<Error>;
|
|
39
|
+
buildResultType(): AuthorType;
|
|
40
|
+
buildQuery(): {
|
|
41
|
+
readonly type: "keyParams";
|
|
42
|
+
readonly keyParams: {
|
|
43
|
+
id: string;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
buildWriteInput(data: Author): {
|
|
47
|
+
data: Author;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { NormalizedLink, TypeRepository, FlattenedKeySelfIdentifiableTypeRepository, DenormalizeDataInput, ReadErrors, WriteResult, ReadResult, WriteErrors, WriteInput, NormalizeDataInput } from '@conduit-client/type-normalization/v1';
|
|
2
|
+
import { Cache, CanonicalCacheControlMetadata, ReadonlyCache } from '@conduit-client/service-cache/v1';
|
|
3
|
+
import { NamedCacheControllerService } from '@conduit-client/service-cache-control/v1';
|
|
4
|
+
import { NamedPubSubService } from '@conduit-client/service-pubsub/v1';
|
|
5
|
+
type City = {
|
|
6
|
+
id: string;
|
|
7
|
+
name: string;
|
|
8
|
+
};
|
|
9
|
+
export type AuthorBio = {
|
|
10
|
+
hometown: City;
|
|
11
|
+
publisher: string;
|
|
12
|
+
birthdate: string;
|
|
13
|
+
};
|
|
14
|
+
type AuthorBioNormalized = AuthorBio;
|
|
15
|
+
export type Author = {
|
|
16
|
+
id: string;
|
|
17
|
+
name: string;
|
|
18
|
+
bio: AuthorBio;
|
|
19
|
+
};
|
|
20
|
+
type AuthorNormalized = {
|
|
21
|
+
id: string;
|
|
22
|
+
name: string;
|
|
23
|
+
bio: AuthorBioNormalized;
|
|
24
|
+
};
|
|
25
|
+
export type Post = {
|
|
26
|
+
id: number;
|
|
27
|
+
title: string;
|
|
28
|
+
text: string;
|
|
29
|
+
author: Author;
|
|
30
|
+
};
|
|
31
|
+
type PostNormalized = {
|
|
32
|
+
id: number;
|
|
33
|
+
title: string;
|
|
34
|
+
text: string;
|
|
35
|
+
author: NormalizedLink;
|
|
36
|
+
};
|
|
37
|
+
export type PostList = {
|
|
38
|
+
list: Post[];
|
|
39
|
+
};
|
|
40
|
+
export declare class ExampleModuleTypeRegistry {
|
|
41
|
+
protected now: number;
|
|
42
|
+
protected services: NamedCacheControllerService & NamedPubSubService;
|
|
43
|
+
protected types: {
|
|
44
|
+
authorBio: AuthorBioType;
|
|
45
|
+
author: AuthorType;
|
|
46
|
+
post: PostType;
|
|
47
|
+
denormalizeErrorType: DenormalizeErrorType;
|
|
48
|
+
};
|
|
49
|
+
constructor(now: number, services: NamedCacheControllerService & NamedPubSubService);
|
|
50
|
+
get authorBio(): AuthorBioType;
|
|
51
|
+
get author(): AuthorType;
|
|
52
|
+
get post(): PostType;
|
|
53
|
+
get denormalizeErrorType(): DenormalizeErrorType;
|
|
54
|
+
}
|
|
55
|
+
declare class AuthorBioType implements TypeRepository<AuthorBio, AuthorBioNormalized, AuthorBioNormalized, AuthorBio> {
|
|
56
|
+
protected services: {};
|
|
57
|
+
protected typeRegistry: ExampleModuleTypeRegistry;
|
|
58
|
+
namespace: string;
|
|
59
|
+
typeName: string;
|
|
60
|
+
constructor(services: {}, typeRegistry: ExampleModuleTypeRegistry);
|
|
61
|
+
write(_cache: Cache, data: AuthorBio): WriteResult<AuthorBioNormalized>;
|
|
62
|
+
read(_cache: ReadonlyCache, data: AuthorBioNormalized): ReadResult<AuthorBio>;
|
|
63
|
+
equals(x: AuthorBio, y: AuthorBio): boolean;
|
|
64
|
+
}
|
|
65
|
+
type AuthorKeyParams = {
|
|
66
|
+
id: string;
|
|
67
|
+
};
|
|
68
|
+
type AuthorWriteInput = WriteInput<Author>;
|
|
69
|
+
type AuthorNormalizeDataInput = NormalizeDataInput<Author, AuthorNormalized>;
|
|
70
|
+
type AuthorDenormalizeDataInput = DenormalizeDataInput<AuthorNormalized>;
|
|
71
|
+
export declare class AuthorType extends FlattenedKeySelfIdentifiableTypeRepository<Author, AuthorNormalized, AuthorKeyParams> {
|
|
72
|
+
protected services: NamedCacheControllerService & NamedPubSubService;
|
|
73
|
+
protected typeRegistry: ExampleModuleTypeRegistry;
|
|
74
|
+
namespace: string;
|
|
75
|
+
typeName: string;
|
|
76
|
+
cacheControl: CanonicalCacheControlMetadata;
|
|
77
|
+
keySchema: string[];
|
|
78
|
+
constructor(services: NamedCacheControllerService & NamedPubSubService, typeRegistry: ExampleModuleTypeRegistry);
|
|
79
|
+
protected normalizeData(cache: Cache, input: AuthorNormalizeDataInput): import("@conduit-client/utils").Result<AuthorNormalized, WriteErrors>;
|
|
80
|
+
buildKeyParams(input: AuthorWriteInput): AuthorKeyParams;
|
|
81
|
+
protected denormalizeData(cache: ReadonlyCache, input: AuthorDenormalizeDataInput): import("@conduit-client/utils").Result<Author, ReadErrors>;
|
|
82
|
+
}
|
|
83
|
+
type PostKeyParams = {
|
|
84
|
+
id: number;
|
|
85
|
+
};
|
|
86
|
+
type PostWriteInput = WriteInput<Post>;
|
|
87
|
+
type PostNormalizeDataInput = NormalizeDataInput<Post, PostNormalized>;
|
|
88
|
+
type PostDenormalizeDataInput = DenormalizeDataInput<PostNormalized>;
|
|
89
|
+
export declare class PostType extends FlattenedKeySelfIdentifiableTypeRepository<Post, PostNormalized, PostKeyParams> {
|
|
90
|
+
protected services: NamedCacheControllerService & NamedPubSubService;
|
|
91
|
+
protected typeRegistry: ExampleModuleTypeRegistry;
|
|
92
|
+
namespace: string;
|
|
93
|
+
typeName: string;
|
|
94
|
+
cacheControl: CanonicalCacheControlMetadata;
|
|
95
|
+
constructor(services: NamedCacheControllerService & NamedPubSubService, typeRegistry: ExampleModuleTypeRegistry);
|
|
96
|
+
keySchema: string[];
|
|
97
|
+
protected normalizeData(cache: Cache, input: PostNormalizeDataInput): import("@conduit-client/utils").Result<PostNormalized, WriteErrors>;
|
|
98
|
+
buildKeyParams(input: PostWriteInput): PostKeyParams;
|
|
99
|
+
protected denormalizeData(cache: ReadonlyCache, input: PostDenormalizeDataInput): import("@conduit-client/utils").Result<Post, ReadErrors>;
|
|
100
|
+
}
|
|
101
|
+
export declare class DenormalizeErrorType extends PostType {
|
|
102
|
+
protected denormalizeData(_cache: ReadonlyCache, _input: PostDenormalizeDataInput): import("@conduit-client/utils").Err<never, {
|
|
103
|
+
type: "unknown";
|
|
104
|
+
error: Error;
|
|
105
|
+
}[]>;
|
|
106
|
+
}
|
|
107
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { HttpCacheControlCommand } from '@conduit-client/command-http-cache-control/v1';
|
|
2
|
+
import { type Result, type SyncOrAsync } from '@conduit-client/utils';
|
|
3
|
+
import { type NamedPubSubService } from '@conduit-client/service-pubsub/v1';
|
|
4
|
+
import type { DataOf, Queryable, QueryFor, ReadInputOf, TypeRepository, WriteInputOf, WriteResponseOf } from '@conduit-client/type-normalization/v1';
|
|
5
|
+
import type { Cache } from '@conduit-client/service-cache/v1';
|
|
6
|
+
import type { NamedCacheControllerService } from '@conduit-client/service-cache-control/v1';
|
|
7
|
+
import type { NamedFetchService } from '@conduit-client/service-fetch-network/v1';
|
|
8
|
+
/**
|
|
9
|
+
* An implementation of BaseCommand that allows for extending abstract cache methods
|
|
10
|
+
*
|
|
11
|
+
* @typeParam Data cache result for read operations
|
|
12
|
+
* @typeParam NetworkResult cache result including network metadata
|
|
13
|
+
* @typeParam ExtraServices additional named services needed by a subclass
|
|
14
|
+
*/
|
|
15
|
+
export declare abstract class HttpNormalizedCacheControlCommand<ResultType extends Queryable<TypeRepository<Data, ReadInput, WriteResponse, WriteInput>, any>, Data = DataOf<ResultType>, NetworkData = Data, ReadInput = ReadInputOf<ResultType>, WriteResponse = WriteResponseOf<ResultType>, WriteInput = WriteInputOf<ResultType>, ExtraServices extends object = object> extends HttpCacheControlCommand<Data, ExtraServices, NetworkData> {
|
|
16
|
+
protected services: NamedCacheControllerService & Partial<NamedPubSubService> & NamedFetchService & ExtraServices;
|
|
17
|
+
abstract buildResultType(): ResultType;
|
|
18
|
+
abstract buildQuery(): QueryFor<ResultType>;
|
|
19
|
+
abstract buildWriteInput(data: NetworkData): WriteInput;
|
|
20
|
+
constructor(services: NamedCacheControllerService & Partial<NamedPubSubService> & NamedFetchService & ExtraServices);
|
|
21
|
+
readFromCache(cache: Cache): SyncOrAsync<Result<Data, Error>>;
|
|
22
|
+
writeToCache(cache: Cache, networkResult: Result<NetworkData, Error>): SyncOrAsync<void>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type NamedService, type ServiceDescriptor } from '@conduit-client/utils';
|
|
2
|
+
import { HttpNormalizedCacheControlCommand } from './http-normalized-cache-control-command';
|
|
3
|
+
export { HttpNormalizedCacheControlCommand } from './http-normalized-cache-control-command';
|
|
4
|
+
export type HttpNormalizedCacheControlCommandServiceDescriptor = ServiceDescriptor<typeof HttpNormalizedCacheControlCommand, 'httpNormalizedCacheControlCommand', '1.0'>;
|
|
5
|
+
export type NamedHttpNormalizedCacheControlCommand = NamedService<'httpNormalizedCacheControlCommand', typeof HttpNormalizedCacheControlCommand>;
|
|
6
|
+
export declare function buildServiceDescriptor(): HttpNormalizedCacheControlCommandServiceDescriptor;
|
package/dist/v1/index.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2022, Salesforce, Inc.,
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* For full license text, see the LICENSE.txt file
|
|
5
|
+
*/
|
|
6
|
+
import { CacheControlCommand } from "@conduit-client/command-cache-control/v1";
|
|
7
|
+
import { toError, ok, err, resolvedPromiseLike, JSONStringify } from "@conduit-client/utils";
|
|
8
|
+
/*!
|
|
9
|
+
* Copyright (c) 2022, Salesforce, Inc.,
|
|
10
|
+
* All rights reserved.
|
|
11
|
+
* For full license text, see the LICENSE.txt file
|
|
12
|
+
*/
|
|
13
|
+
class HttpCacheControlCommand extends CacheControlCommand {
|
|
14
|
+
constructor(services) {
|
|
15
|
+
super(services);
|
|
16
|
+
this.services = services;
|
|
17
|
+
}
|
|
18
|
+
requestFromNetwork() {
|
|
19
|
+
return this.fetch();
|
|
20
|
+
}
|
|
21
|
+
fetch() {
|
|
22
|
+
return this.convertFetchResponseToData(this.services.fetch(...this.fetchParams));
|
|
23
|
+
}
|
|
24
|
+
async coerceError(errorResponse) {
|
|
25
|
+
return toError(errorResponse.statusText);
|
|
26
|
+
}
|
|
27
|
+
processFetchReturnValue(json) {
|
|
28
|
+
return ok(json);
|
|
29
|
+
}
|
|
30
|
+
convertFetchResponseToData(response) {
|
|
31
|
+
return response.then(
|
|
32
|
+
(response2) => {
|
|
33
|
+
if (response2.ok) {
|
|
34
|
+
return response2.json().then(
|
|
35
|
+
(json) => {
|
|
36
|
+
return this.processFetchReturnValue(json);
|
|
37
|
+
},
|
|
38
|
+
(reason) => err(toError(reason))
|
|
39
|
+
).finally(() => {
|
|
40
|
+
try {
|
|
41
|
+
this.afterRequestHooks({ statusCode: response2.status });
|
|
42
|
+
} catch (e) {
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
} else {
|
|
46
|
+
return this.coerceError(response2).then((coercedError) => {
|
|
47
|
+
return err(coercedError);
|
|
48
|
+
}).finally(() => {
|
|
49
|
+
try {
|
|
50
|
+
this.afterRequestHooks({ statusCode: response2.status });
|
|
51
|
+
} catch (e) {
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
(reason) => err(toError(reason))
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
class HttpNormalizedCacheControlCommand extends HttpCacheControlCommand {
|
|
61
|
+
constructor(services) {
|
|
62
|
+
super(services);
|
|
63
|
+
this.services = services;
|
|
64
|
+
}
|
|
65
|
+
readFromCache(cache) {
|
|
66
|
+
const data = this.buildResultType().query(cache, this.buildQuery());
|
|
67
|
+
if (data.isErr()) {
|
|
68
|
+
return resolvedPromiseLike(
|
|
69
|
+
err(new Error(`Failed to build data from type: ${JSONStringify(data.error)}`))
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
return resolvedPromiseLike(ok(data.value));
|
|
73
|
+
}
|
|
74
|
+
writeToCache(cache, networkResult) {
|
|
75
|
+
if (networkResult.isOk()) {
|
|
76
|
+
this.buildResultType().write(
|
|
77
|
+
cache.buildFixedTimeWritableCache(Date.now() / 1e3),
|
|
78
|
+
this.buildWriteInput(networkResult.value)
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
return resolvedPromiseLike(void 0);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function buildServiceDescriptor() {
|
|
85
|
+
return {
|
|
86
|
+
type: "httpNormalizedCacheControlCommand",
|
|
87
|
+
version: "1.0",
|
|
88
|
+
service: HttpNormalizedCacheControlCommand
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
export {
|
|
92
|
+
HttpNormalizedCacheControlCommand,
|
|
93
|
+
buildServiceDescriptor
|
|
94
|
+
};
|
|
95
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../http-cache-control/dist/v1/index.js","../../src/v1/http-normalized-cache-control-command.ts","../../src/v1/index.ts"],"sourcesContent":["/*!\n * Copyright (c) 2022, Salesforce, Inc.,\n * All rights reserved.\n * For full license text, see the LICENSE.txt file\n */\nimport { CacheControlCommand } from \"@conduit-client/command-cache-control/v1\";\nimport { toError, ok, err } from \"@conduit-client/utils\";\nclass HttpCacheControlCommand extends CacheControlCommand {\n constructor(services) {\n super(services);\n this.services = services;\n }\n requestFromNetwork() {\n return this.fetch();\n }\n fetch() {\n return this.convertFetchResponseToData(this.services.fetch(...this.fetchParams));\n }\n async coerceError(errorResponse) {\n return toError(errorResponse.statusText);\n }\n processFetchReturnValue(json) {\n return ok(json);\n }\n convertFetchResponseToData(response) {\n return response.then(\n (response2) => {\n if (response2.ok) {\n return response2.json().then(\n (json) => {\n return this.processFetchReturnValue(json);\n },\n (reason) => err(toError(reason))\n ).finally(() => {\n try {\n this.afterRequestHooks({ statusCode: response2.status });\n } catch (e) {\n }\n });\n } else {\n return this.coerceError(response2).then((coercedError) => {\n return err(coercedError);\n }).finally(() => {\n try {\n this.afterRequestHooks({ statusCode: response2.status });\n } catch (e) {\n }\n });\n }\n },\n (reason) => err(toError(reason))\n );\n }\n}\nfunction buildServiceDescriptor() {\n return {\n type: \"httpCacheControlCommand\",\n version: \"1.0\",\n service: HttpCacheControlCommand\n };\n}\nexport {\n HttpCacheControlCommand,\n buildServiceDescriptor\n};\n//# sourceMappingURL=index.js.map\n","import { HttpCacheControlCommand } from '@conduit-client/command-http-cache-control/v1';\nimport {\n err,\n JSONStringify,\n ok,\n resolvedPromiseLike,\n type Result,\n type SyncOrAsync,\n} from '@conduit-client/utils';\nimport { type NamedPubSubService } from '@conduit-client/service-pubsub/v1';\nimport type {\n DataOf,\n Queryable,\n QueryFor,\n ReadInputOf,\n TypeRepository,\n WriteInputOf,\n WriteResponseOf,\n} from '@conduit-client/type-normalization/v1';\nimport type { Cache } from '@conduit-client/service-cache/v1';\nimport type { NamedCacheControllerService } from '@conduit-client/service-cache-control/v1';\nimport type { NamedFetchService } from '@conduit-client/service-fetch-network/v1';\n\n/**\n * An implementation of BaseCommand that allows for extending abstract cache methods\n *\n * @typeParam Data cache result for read operations\n * @typeParam NetworkResult cache result including network metadata\n * @typeParam ExtraServices additional named services needed by a subclass\n */\nexport abstract class HttpNormalizedCacheControlCommand<\n ResultType extends Queryable<TypeRepository<Data, ReadInput, WriteResponse, WriteInput>, any>,\n Data = DataOf<ResultType>,\n NetworkData = Data,\n ReadInput = ReadInputOf<ResultType>,\n WriteResponse = WriteResponseOf<ResultType>,\n WriteInput = WriteInputOf<ResultType>,\n ExtraServices extends object = object,\n> extends HttpCacheControlCommand<Data, ExtraServices, NetworkData> {\n abstract buildResultType(): ResultType;\n abstract buildQuery(): QueryFor<ResultType>;\n abstract buildWriteInput(data: NetworkData): WriteInput;\n\n constructor(\n protected services: NamedCacheControllerService &\n Partial<NamedPubSubService> &\n NamedFetchService &\n ExtraServices\n ) {\n super(services);\n }\n\n readFromCache(cache: Cache): SyncOrAsync<Result<Data, Error>> {\n const data = this.buildResultType().query(cache, this.buildQuery());\n if (data.isErr()) {\n return resolvedPromiseLike(\n err(new Error(`Failed to build data from type: ${JSONStringify(data.error)}`))\n );\n }\n return resolvedPromiseLike(ok(data.value));\n }\n\n writeToCache(cache: Cache, networkResult: Result<NetworkData, Error>): SyncOrAsync<void> {\n if (networkResult.isOk()) {\n this.buildResultType().write(\n cache.buildFixedTimeWritableCache(Date.now() / 1000),\n this.buildWriteInput(networkResult.value)\n );\n }\n\n return resolvedPromiseLike(undefined);\n }\n}\n","import { type NamedService, type ServiceDescriptor } from '@conduit-client/utils';\nimport { HttpNormalizedCacheControlCommand } from './http-normalized-cache-control-command';\n\nexport { HttpNormalizedCacheControlCommand } from './http-normalized-cache-control-command';\n\nexport type HttpNormalizedCacheControlCommandServiceDescriptor = ServiceDescriptor<\n typeof HttpNormalizedCacheControlCommand,\n 'httpNormalizedCacheControlCommand',\n '1.0'\n>;\n\nexport type NamedHttpNormalizedCacheControlCommand = NamedService<\n 'httpNormalizedCacheControlCommand',\n typeof HttpNormalizedCacheControlCommand\n>;\n\nexport function buildServiceDescriptor(): HttpNormalizedCacheControlCommandServiceDescriptor {\n return {\n type: 'httpNormalizedCacheControlCommand',\n version: '1.0',\n service: HttpNormalizedCacheControlCommand,\n };\n}\n"],"names":[],"mappings":";;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,MAAM,gCAAgC,oBAAoB;AAAA,EACxD,YAAY,UAAU;AACpB,UAAM,QAAQ;AACd,SAAK,WAAW;AAAA,EAClB;AAAA,EACA,qBAAqB;AACnB,WAAO,KAAK,MAAK;AAAA,EACnB;AAAA,EACA,QAAQ;AACN,WAAO,KAAK,2BAA2B,KAAK,SAAS,MAAM,GAAG,KAAK,WAAW,CAAC;AAAA,EACjF;AAAA,EACA,MAAM,YAAY,eAAe;AAC/B,WAAO,QAAQ,cAAc,UAAU;AAAA,EACzC;AAAA,EACA,wBAAwB,MAAM;AAC5B,WAAO,GAAG,IAAI;AAAA,EAChB;AAAA,EACA,2BAA2B,UAAU;AACnC,WAAO,SAAS;AAAA,MACd,CAAC,cAAc;AACb,YAAI,UAAU,IAAI;AAChB,iBAAO,UAAU,KAAI,EAAG;AAAA,YACtB,CAAC,SAAS;AACR,qBAAO,KAAK,wBAAwB,IAAI;AAAA,YAC1C;AAAA,YACA,CAAC,WAAW,IAAI,QAAQ,MAAM,CAAC;AAAA,UAC3C,EAAY,QAAQ,MAAM;AACd,gBAAI;AACF,mBAAK,kBAAkB,EAAE,YAAY,UAAU,OAAM,CAAE;AAAA,YACzD,SAAS,GAAG;AAAA,YACZ;AAAA,UACF,CAAC;AAAA,QACH,OAAO;AACL,iBAAO,KAAK,YAAY,SAAS,EAAE,KAAK,CAAC,iBAAiB;AACxD,mBAAO,IAAI,YAAY;AAAA,UACzB,CAAC,EAAE,QAAQ,MAAM;AACf,gBAAI;AACF,mBAAK,kBAAkB,EAAE,YAAY,UAAU,OAAM,CAAE;AAAA,YACzD,SAAS,GAAG;AAAA,YACZ;AAAA,UACF,CAAC;AAAA,QACH;AAAA,MACF;AAAA,MACA,CAAC,WAAW,IAAI,QAAQ,MAAM,CAAC;AAAA,IACrC;AAAA,EACE;AACF;ACvBO,MAAe,0CAQZ,wBAA0D;AAAA,EAKhE,YACc,UAIZ;AACE,UAAM,QAAQ;AALJ,SAAA,WAAA;AAAA,EAMd;AAAA,EAEA,cAAc,OAAgD;AAC1D,UAAM,OAAO,KAAK,gBAAA,EAAkB,MAAM,OAAO,KAAK,YAAY;AAClE,QAAI,KAAK,SAAS;AACd,aAAO;AAAA,QACH,IAAI,IAAI,MAAM,mCAAmC,cAAc,KAAK,KAAK,CAAC,EAAE,CAAC;AAAA,MAAA;AAAA,IAErF;AACA,WAAO,oBAAoB,GAAG,KAAK,KAAK,CAAC;AAAA,EAC7C;AAAA,EAEA,aAAa,OAAc,eAA8D;AACrF,QAAI,cAAc,QAAQ;AACtB,WAAK,kBAAkB;AAAA,QACnB,MAAM,4BAA4B,KAAK,IAAA,IAAQ,GAAI;AAAA,QACnD,KAAK,gBAAgB,cAAc,KAAK;AAAA,MAAA;AAAA,IAEhD;AAEA,WAAO,oBAAoB,MAAS;AAAA,EACxC;AACJ;ACxDO,SAAS,yBAA6E;AACzF,SAAO;AAAA,IACH,MAAM;AAAA,IACN,SAAS;AAAA,IACT,SAAS;AAAA,EAAA;AAEjB;"}
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@conduit-client/command-http-normalized-cache-control",
|
|
3
|
+
"version": "5.67.0-dev1",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "OneStore HTTP Normalized Cache Control Command",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/salesforce-experience-platform-emu/onestore.git",
|
|
10
|
+
"directory": "packages/@conduit-client/commands/http-normalized-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/main/index.js",
|
|
21
|
+
"module": "./dist/main/index.js",
|
|
22
|
+
"types": "./dist/main/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/command-base": "5.67.0-dev1",
|
|
35
|
+
"@conduit-client/command-cache-control": "5.67.0-dev1",
|
|
36
|
+
"@conduit-client/command-http-cache-control": "5.67.0-dev1",
|
|
37
|
+
"@conduit-client/service-cache-control": "5.67.0-dev1",
|
|
38
|
+
"@conduit-client/service-fetch-network": "5.67.0-dev1",
|
|
39
|
+
"@conduit-client/type-normalization": "5.67.0-dev1",
|
|
40
|
+
"@conduit-client/utils": "5.67.0-dev1"
|
|
41
|
+
},
|
|
42
|
+
"volta": {
|
|
43
|
+
"extends": "../../../../package.json"
|
|
44
|
+
},
|
|
45
|
+
"size-limit": [
|
|
46
|
+
{
|
|
47
|
+
"path": "./dist/v1/index.js",
|
|
48
|
+
"limit": "2 kB"
|
|
49
|
+
}
|
|
50
|
+
]
|
|
51
|
+
}
|