@envelop/persisted-operations 4.4.1-alpha-ffbace6f.0 → 4.4.2

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/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@envelop/persisted-operations",
3
- "version": "4.4.1-alpha-ffbace6f.0",
3
+ "version": "4.4.2",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
- "@envelop/core": "2.4.1-alpha-ffbace6f.0",
6
+ "@envelop/core": "^2.4.2",
7
7
  "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
8
8
  },
9
9
  "repository": {
@@ -23,7 +23,7 @@
23
23
  "exports": {
24
24
  ".": {
25
25
  "require": {
26
- "types": "./typings/index.d.ts",
26
+ "types": "./typings/index.d.cts",
27
27
  "default": "./cjs/index.js"
28
28
  },
29
29
  "import": {
@@ -37,7 +37,7 @@
37
37
  },
38
38
  "./*": {
39
39
  "require": {
40
- "types": "./typings/*.d.ts",
40
+ "types": "./typings/*.d.cts",
41
41
  "default": "./cjs/*.js"
42
42
  },
43
43
  "import": {
@@ -0,0 +1,6 @@
1
+ export * from './types.cjs';
2
+ export * from './utils.cjs';
3
+ export * from './stores/aggregated-store.cjs';
4
+ export * from './stores/inmemory-store.cjs';
5
+ export * from './stores/json-file-store.cjs';
6
+ export * from './plugin.cjs';
@@ -0,0 +1,29 @@
1
+ import { Plugin, DefaultContext } from '@envelop/core';
2
+ import { PersistedOperationsFunctionStore, PersistedOperationsStore } from './types.cjs';
3
+ export declare type UsePersistedOperationsOptions<ContextType = DefaultContext> = {
4
+ /**
5
+ * Set to `false` to allow running operations that are not available in the store.
6
+ * Set to `true` to allow running only persisted operations.
7
+ */
8
+ onlyPersisted?: boolean;
9
+ /**
10
+ * The store to use. You can implement a store that loads data from any source.
11
+ * You can even support multiple stores and implement a function that returns one of those stores based on context values.
12
+ */
13
+ store: PersistedOperationsStore | PersistedOperationsFunctionStore<ContextType>;
14
+ /**
15
+ * Function that returns the operation id, e.g. by retrieving it from cusotm properties within context
16
+ */
17
+ extractOperationId?: (context: Readonly<ContextType>) => string | undefined;
18
+ /**
19
+ * Callback function to notify consumer of missing hash match, f.i. to log, monitor and/or analise these events
20
+ */
21
+ onMissingMatch?: (context: Readonly<ContextType>, operationId: string) => void;
22
+ };
23
+ declare const contextProperty: unique symbol;
24
+ export declare type PersistedOperationPluginContext = {
25
+ [contextProperty]: string;
26
+ };
27
+ export declare function readOperationId(context: PersistedOperationPluginContext): string;
28
+ export declare const usePersistedOperations: (rawOptions: UsePersistedOperationsOptions) => Plugin<PersistedOperationPluginContext>;
29
+ export {};
@@ -0,0 +1,7 @@
1
+ import { DocumentNode } from 'graphql';
2
+ import { PersistedOperationsStore } from '../types.cjs';
3
+ export declare class AggregatedStore implements PersistedOperationsStore {
4
+ private stores;
5
+ constructor(stores: PersistedOperationsStore[]);
6
+ get(operationId: string): string | DocumentNode | undefined;
7
+ }
@@ -0,0 +1,12 @@
1
+ import { DocumentNode } from 'graphql';
2
+ import { PersistedOperationsStore } from '../types.cjs';
3
+ export declare type InMemoryStoreDataMap = Map<string, DocumentNode | string>;
4
+ export declare class InMemoryStore implements PersistedOperationsStore {
5
+ private storeData;
6
+ constructor(options?: {
7
+ initialData?: InMemoryStoreDataMap;
8
+ });
9
+ get(operationId: string): string | DocumentNode | undefined;
10
+ prime(operationId: string, document: string | DocumentNode): void;
11
+ clear(operationId: string): void;
12
+ }
@@ -0,0 +1,9 @@
1
+ import { DocumentNode } from 'graphql';
2
+ import { PersistedOperationsStore } from '../types.cjs';
3
+ export declare type JsonFileStoreDataMap = Map<string, DocumentNode | string>;
4
+ export declare class JsonFileStore implements PersistedOperationsStore {
5
+ private storeData;
6
+ get(operationId: string): string | DocumentNode | undefined;
7
+ loadFromFileSync(path: string): void;
8
+ loadFromFile(path: string): Promise<void>;
9
+ }
@@ -0,0 +1,12 @@
1
+ import { DefaultContext } from '@envelop/core';
2
+ import { DocumentNode } from 'graphql';
3
+ export interface PersistedOperationsStore {
4
+ /**
5
+ * Transfroms a hash/id into a DocumentNode or SDL string.
6
+ * Prefer returning `DocumentNode` if available to avoid additional parsing phase.
7
+ * Return `null` in case of a store miss.
8
+ * @param operationId
9
+ */
10
+ get(operationId: string): string | DocumentNode | undefined;
11
+ }
12
+ export declare type PersistedOperationsFunctionStore<ContextType = DefaultContext> = (context: Readonly<ContextType>) => PersistedOperationsStore;
@@ -0,0 +1,2 @@
1
+ import { Source } from 'graphql';
2
+ export declare function operationIdFromSource(source: string | Source): string | undefined;