Socket
Socket
Sign inDemoInstall

apollo-cache-core

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apollo-cache-core - npm Package Compare versions

Comparing version 0.2.0-alpha.6 to 0.2.0-alpha.7

lib/types/Cache.d.ts

51

lib/cache.d.ts
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 {}

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc