apollo-cache-core
Advanced tools
Comparing version
import { DocumentNode } from 'graphql'; | ||
import { DataProxy, DataProxyReadQueryOptions, DataProxyReadFragmentOptions, DataProxyWriteQueryOptions, DataProxyWriteFragmentOptions, DiffResult } from './types'; | ||
export declare type CacheWrite = { | ||
dataId: string; | ||
result: any; | ||
document: DocumentNode; | ||
variables?: Object; | ||
}; | ||
export declare type QueryWatch = { | ||
query: DocumentNode; | ||
variables: any; | ||
rootId?: string; | ||
previousResult: () => any; | ||
optimistic: boolean; | ||
callback: (newData: any) => void; | ||
}; | ||
export declare abstract class Cache implements DataProxy { | ||
import { DataProxy, Cache } from './types'; | ||
export declare type Transaction = (c: ApolloCache) => void; | ||
export declare abstract class ApolloCache implements DataProxy { | ||
abstract reset(): Promise<void>; | ||
abstract transformDocument(document: DocumentNode): DocumentNode; | ||
abstract diffQuery(query: { | ||
query: DocumentNode; | ||
variables: any; | ||
returnPartialData?: boolean; | ||
previousResult?: any; | ||
optimistic: boolean; | ||
}): any; | ||
abstract read<T>(query: { | ||
query: DocumentNode; | ||
variables: any; | ||
rootId?: string; | ||
previousResult?: any; | ||
optimistic: boolean; | ||
}): DiffResult<T>; | ||
readQuery<QueryType>(options: DataProxyReadQueryOptions, optimistic?: boolean): DiffResult<QueryType>; | ||
readFragment<FragmentType>(options: DataProxyReadFragmentOptions, optimistic?: boolean): DiffResult<FragmentType> | null; | ||
abstract writeResult(write: CacheWrite): void; | ||
writeQuery(options: DataProxyWriteQueryOptions): void; | ||
writeFragment(options: DataProxyWriteFragmentOptions): void; | ||
abstract diffQuery<T>(query: Cache.DiffQueryOptions): Cache.DiffResult<T>; | ||
abstract read<T>(query: Cache.ReadOptions): Cache.DiffResult<T>; | ||
abstract writeResult(write: Cache.WriteResult): void; | ||
abstract removeOptimistic(id: string): void; | ||
abstract getOptimisticData(): any; | ||
abstract performTransaction(transaction: (c: Cache) => void): void; | ||
abstract recordOptimisticTransaction(transaction: (c: Cache) => void, id: string): void; | ||
abstract watch(watch: QueryWatch): () => void; | ||
abstract performTransaction(transaction: Transaction): void; | ||
abstract recordOptimisticTransaction(transaction: Transaction, id: string): void; | ||
abstract watch(watch: Cache.WatchOptions): () => void; | ||
writeQuery(options: Cache.WriteQueryOptions): void; | ||
writeFragment(options: Cache.WriteFragmentOptions): void; | ||
readQuery<QueryType>(options: DataProxy.ReadQueryOptions, optimistic?: boolean): Cache.DiffResult<QueryType>; | ||
readFragment<FragmentType>(options: DataProxy.ReadFragmentOptions, optimistic?: boolean): Cache.DiffResult<FragmentType> | null; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var apollo_utilities_1 = require("apollo-utilities"); | ||
var Cache = (function () { | ||
function Cache() { | ||
var ApolloCache = (function () { | ||
function ApolloCache() { | ||
} | ||
Cache.prototype.readQuery = function (options, optimistic) { | ||
ApolloCache.prototype.writeQuery = function (options) { | ||
this.writeResult({ | ||
dataId: 'ROOT_QUERY', | ||
result: options.data, | ||
document: options.query, | ||
variables: options.variables, | ||
}); | ||
}; | ||
ApolloCache.prototype.writeFragment = function (options) { | ||
var document = apollo_utilities_1.getFragmentQueryDocument(options.fragment, options.fragmentName); | ||
this.writeResult({ | ||
dataId: options.id, | ||
result: options.data, | ||
document: document, | ||
variables: options.variables, | ||
}); | ||
}; | ||
ApolloCache.prototype.readQuery = function (options, optimistic) { | ||
if (optimistic === void 0) { optimistic = false; } | ||
@@ -15,3 +32,3 @@ return this.read({ | ||
}; | ||
Cache.prototype.readFragment = function (options, optimistic) { | ||
ApolloCache.prototype.readFragment = function (options, optimistic) { | ||
if (optimistic === void 0) { optimistic = false; } | ||
@@ -26,22 +43,5 @@ var document = apollo_utilities_1.getFragmentQueryDocument(options.fragment, options.fragmentName); | ||
}; | ||
Cache.prototype.writeQuery = function (options) { | ||
this.writeResult({ | ||
dataId: 'ROOT_QUERY', | ||
result: options.data, | ||
document: options.query, | ||
variables: options.variables, | ||
}); | ||
}; | ||
Cache.prototype.writeFragment = function (options) { | ||
var document = apollo_utilities_1.getFragmentQueryDocument(options.fragment, options.fragmentName); | ||
this.writeResult({ | ||
dataId: options.id, | ||
result: options.data, | ||
document: document, | ||
variables: options.variables, | ||
}); | ||
}; | ||
return Cache; | ||
return ApolloCache; | ||
}()); | ||
exports.Cache = Cache; | ||
exports.ApolloCache = ApolloCache; | ||
//# sourceMappingURL=cache.js.map |
@@ -7,2 +7,3 @@ "use strict"; | ||
__export(require("./cache")); | ||
__export(require("./types")); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "apollo-cache-core", | ||
"version": "0.2.0-alpha.6", | ||
"version": "0.2.0-alpha.7", | ||
"description": "Core abstract of Caching layer for Apollo Client", | ||
@@ -5,0 +5,0 @@ "author": "James Baxley <james@meteor.com>", |
@@ -1,2 +0,2 @@ | ||
import { Cache } from '../cache'; | ||
import { ApolloCache as Cache } from '../cache'; | ||
@@ -3,0 +3,0 @@ class TestCache extends Cache {} |
119
src/cache.ts
@@ -5,28 +5,7 @@ import { DocumentNode } from 'graphql'; | ||
import { | ||
DataProxy, | ||
DataProxyReadQueryOptions, | ||
DataProxyReadFragmentOptions, | ||
DataProxyWriteQueryOptions, | ||
DataProxyWriteFragmentOptions, | ||
DiffResult, | ||
} from './types'; | ||
import { DataProxy, Cache } from './types'; | ||
export type CacheWrite = { | ||
dataId: string; | ||
result: any; | ||
document: DocumentNode; | ||
variables?: Object; | ||
}; | ||
export type Transaction = (c: ApolloCache) => void; | ||
export type QueryWatch = { | ||
query: DocumentNode; | ||
variables: any; | ||
rootId?: string; | ||
previousResult: () => any; | ||
optimistic: boolean; | ||
callback: (newData: any) => void; | ||
}; | ||
export abstract class Cache implements DataProxy { | ||
export abstract class ApolloCache implements DataProxy { | ||
public abstract reset(): Promise<void>; | ||
@@ -36,48 +15,22 @@ | ||
public abstract diffQuery(query: { | ||
query: DocumentNode; | ||
variables: any; | ||
returnPartialData?: boolean; | ||
previousResult?: any; | ||
optimistic: boolean; | ||
}): any; | ||
public abstract diffQuery<T>( | ||
query: Cache.DiffQueryOptions, | ||
): Cache.DiffResult<T>; | ||
public abstract read<T>(query: { | ||
query: DocumentNode; | ||
variables: any; | ||
rootId?: string; | ||
previousResult?: any; | ||
optimistic: boolean; | ||
}): DiffResult<T>; | ||
public abstract read<T>(query: Cache.ReadOptions): Cache.DiffResult<T>; | ||
public readQuery<QueryType>( | ||
options: DataProxyReadQueryOptions, | ||
optimistic: boolean = false, | ||
): DiffResult<QueryType> { | ||
return this.read({ | ||
query: options.query, | ||
variables: options.variables, | ||
optimistic, | ||
}); | ||
} | ||
public abstract writeResult(write: Cache.WriteResult): void; | ||
public readFragment<FragmentType>( | ||
options: DataProxyReadFragmentOptions, | ||
optimistic: boolean = false, | ||
): DiffResult<FragmentType> | null { | ||
let document = getFragmentQueryDocument( | ||
options.fragment, | ||
options.fragmentName, | ||
); | ||
return this.read({ | ||
query: document, | ||
variables: options.variables, | ||
rootId: options.id, | ||
optimistic, | ||
}); | ||
} | ||
public abstract removeOptimistic(id: string): void; | ||
public abstract getOptimisticData(): any; | ||
public abstract writeResult(write: CacheWrite): void; | ||
public abstract performTransaction(transaction: Transaction): void; | ||
public abstract recordOptimisticTransaction( | ||
transaction: Transaction, | ||
id: string, | ||
): void; | ||
public writeQuery(options: DataProxyWriteQueryOptions): void { | ||
public abstract watch(watch: Cache.WatchOptions): () => void; | ||
public writeQuery(options: Cache.WriteQueryOptions): void { | ||
this.writeResult({ | ||
@@ -91,3 +44,3 @@ dataId: 'ROOT_QUERY', | ||
public writeFragment(options: DataProxyWriteFragmentOptions): void { | ||
public writeFragment(options: Cache.WriteFragmentOptions): void { | ||
let document = getFragmentQueryDocument( | ||
@@ -105,12 +58,28 @@ options.fragment, | ||
public abstract removeOptimistic(id: string): void; | ||
public abstract getOptimisticData(): any; | ||
public readQuery<QueryType>( | ||
options: DataProxy.ReadQueryOptions, | ||
optimistic: boolean = false, | ||
): Cache.DiffResult<QueryType> { | ||
return this.read({ | ||
query: options.query, | ||
variables: options.variables, | ||
optimistic, | ||
}); | ||
} | ||
public abstract performTransaction(transaction: (c: Cache) => void): void; | ||
public abstract recordOptimisticTransaction( | ||
transaction: (c: Cache) => void, | ||
id: string, | ||
): void; | ||
public abstract watch(watch: QueryWatch): () => void; | ||
public readFragment<FragmentType>( | ||
options: DataProxy.ReadFragmentOptions, | ||
optimistic: boolean = false, | ||
): Cache.DiffResult<FragmentType> | null { | ||
let document = getFragmentQueryDocument( | ||
options.fragment, | ||
options.fragmentName, | ||
); | ||
return this.read({ | ||
query: document, | ||
variables: options.variables, | ||
rootId: options.id, | ||
optimistic, | ||
}); | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
20010
16.32%24
50%480
9.84%1
Infinity%