Skip to content

Commit a16193c

Browse files
committed
build
1 parent a1b7de0 commit a16193c

37 files changed

+80652
-6
lines changed

dist/actions/action.d.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { Arguments, Data, DispatchFunction } from "../support/interfaces";
2+
import Model from "../orm/model";
3+
import RootState from "@vuex-orm/core/lib/modules/contracts/RootState";
4+
/**
5+
* Base class for all Vuex actions. Contains some utility and convenience methods.
6+
*/
7+
export default class Action {
8+
/**
9+
* Sends a mutation.
10+
*
11+
* @param {string} name Name of the mutation like 'createUser'
12+
* @param {Data | undefined} variables Variables to send with the mutation
13+
* @param {Function} dispatch Vuex Dispatch method for the model
14+
* @param {Model} model The model this mutation affects.
15+
* @param {boolean} multiple Tells if we're requesting a single record or multiple.
16+
* @returns {Promise<any>}
17+
*/
18+
protected static mutation(name: string, variables: Data | undefined, dispatch: DispatchFunction, model: Model): Promise<any>;
19+
/**
20+
* Convenience method to get the model from the state.
21+
* @param {RootState} state Vuex state
22+
* @returns {Model}
23+
*/
24+
static getModelFromState(state: RootState): Model;
25+
/**
26+
* Makes sure args is a hash.
27+
*
28+
* @param {Arguments|undefined} args
29+
* @param {any} id When not undefined, it's added to the args
30+
* @returns {Arguments}
31+
*/
32+
static prepareArgs(args?: Arguments, id?: any): Arguments;
33+
/**
34+
* Adds the record itself to the args and sends it through transformOutgoingData. Key is named by the singular name
35+
* of the model.
36+
*
37+
* @param {Arguments} args
38+
* @param {Model} model
39+
* @param {Data} data
40+
* @returns {Arguments}
41+
*/
42+
static addRecordToArgs(args: Arguments, model: Model, data: Data): Arguments;
43+
/**
44+
* Transforms each field of the args which contains a model.
45+
* @param {Arguments} args
46+
* @returns {Arguments}
47+
*/
48+
protected static transformArgs(args: Arguments): Arguments;
49+
}

dist/actions/destroy.d.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { ActionParams } from "../support/interfaces";
2+
import Action from "./action";
3+
/**
4+
* Destroy action for sending a delete mutation. Will be used for record.$destroy().
5+
*/
6+
export default class Destroy extends Action {
7+
/**
8+
* @param {State} state The Vuex state
9+
* @param {DispatchFunction} dispatch Vuex Dispatch method for the model
10+
* @param {string} id ID of the record to delete
11+
* @returns {Promise<any>} true
12+
*/
13+
static call({ state, dispatch }: ActionParams, { id, args }: ActionParams): Promise<boolean>;
14+
}

dist/actions/fetch.d.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { ActionParams, Data } from "../support/interfaces";
2+
import Action from "./action";
3+
/**
4+
* Fetch action for sending a query. Will be used for Model.fetch().
5+
*/
6+
export default class Fetch extends Action {
7+
/**
8+
* @param {any} state The Vuex state
9+
* @param {DispatchFunction} dispatch Vuex Dispatch method for the model
10+
* @param {ActionParams} params Optional params to send with the query
11+
* @returns {Promise<Data>} The fetched records as hash
12+
*/
13+
static call({ state, dispatch }: ActionParams, params?: ActionParams): Promise<Data>;
14+
}

dist/actions/index.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import Action from './action';
2+
import Destroy from './destroy';
3+
import Fetch from './fetch';
4+
import Mutate from './mutate';
5+
import Persist from './persist';
6+
import Push from './push';
7+
export { Action, Destroy, Fetch, Mutate, Persist, Push };

dist/actions/mutate.d.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { ActionParams, Data } from "../support/interfaces";
2+
import Action from "./action";
3+
/**
4+
* Mutate action for sending a custom mutation. Will be used for Model.mutate() and record.$mutate().
5+
*/
6+
export default class Mutate extends Action {
7+
/**
8+
* @param {any} state The Vuex state
9+
* @param {DispatchFunction} dispatch Vuex Dispatch method for the model
10+
* @param {string} name Name of the query
11+
* @param {boolean} multiple Fetch one or multiple?
12+
* @param {Arguments} args Arguments for the mutation. Must contain a 'mutation' field.
13+
* @returns {Promise<Data>} The new record if any
14+
*/
15+
static call({ state, dispatch }: ActionParams, { args, name }: ActionParams): Promise<Data>;
16+
}

dist/actions/persist.d.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { ActionParams, Data } from "../support/interfaces";
2+
import Action from "./action";
3+
/**
4+
* Persist action for sending a create mutation. Will be used for record.$persist().
5+
*/
6+
export default class Persist extends Action {
7+
/**
8+
* @param {any} state The Vuex state
9+
* @param {DispatchFunction} dispatch Vuex Dispatch method for the model
10+
* @param {string} id ID of the record to persist
11+
* @returns {Promise<Data>} The saved record
12+
*/
13+
static call({ state, dispatch }: ActionParams, { id, args }: ActionParams): Promise<Data>;
14+
/**
15+
* It's very likely that the server generated different ID for this record.
16+
* In this case Action.mutation has inserted a new record instead of updating the existing one.
17+
*
18+
* @param {Model} model
19+
* @param {Data} record
20+
* @returns {Promise<void>}
21+
*/
22+
private static deleteObsoleteRecord;
23+
}

dist/actions/push.d.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { ActionParams, Data } from "../support/interfaces";
2+
import Action from "./action";
3+
/**
4+
* Push action for sending a update mutation. Will be used for record.$push().
5+
*/
6+
export default class Push extends Action {
7+
/**
8+
* @param {any} state The Vuex state
9+
* @param {DispatchFunction} dispatch Vuex Dispatch method for the model
10+
* @param {Arguments} data New data to save
11+
* @param {Arguments} args Additional arguments
12+
* @returns {Promise<Data>} The updated record
13+
*/
14+
static call({ state, dispatch }: ActionParams, { data, args }: ActionParams): Promise<Data>;
15+
}

dist/actions/query.d.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { ActionParams, Data } from "../support/interfaces";
2+
import Action from "./action";
3+
/**
4+
* Query action for sending a custom query. Will be used for Model.customQuery() and record.$customQuery.
5+
*/
6+
export default class Query extends Action {
7+
/**
8+
* @param {any} state The Vuex state
9+
* @param {DispatchFunction} dispatch Vuex Dispatch method for the model
10+
* @param {string} name Name of the query
11+
* @param {boolean} multiple Fetch one or multiple?
12+
* @param {object} filter Filter object (arguments)
13+
* @param {boolean} bypassCache Whether to bypass the cache
14+
* @returns {Promise<Data>} The fetched records as hash
15+
*/
16+
static call({ state, dispatch }: ActionParams, { name, filter, bypassCache }: ActionParams): Promise<Data>;
17+
}

dist/actions/simple-mutation.d.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { ActionParams } from "../support/interfaces";
2+
import Action from "./action";
3+
/**
4+
* SimpleMutation action for sending a model unrelated simple mutation.
5+
*/
6+
export default class SimpleMutation extends Action {
7+
/**
8+
* @param {DispatchFunction} dispatch Vuex Dispatch method for the model
9+
* @param {string} query The query to send
10+
* @param {Arguments} variables
11+
* @returns {Promise<any>} The result
12+
*/
13+
static call({ dispatch }: ActionParams, { query, variables }: ActionParams): Promise<any>;
14+
}

dist/actions/simple-query.d.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { ActionParams } from "../support/interfaces";
2+
import Action from "./action";
3+
/**
4+
* SimpleQuery action for sending a model unrelated simple query.
5+
*/
6+
export default class SimpleQuery extends Action {
7+
/**
8+
* @param {DispatchFunction} dispatch Vuex Dispatch method for the model
9+
* @param {string} query The query to send
10+
* @param {Arguments} variables
11+
* @param {boolean} bypassCache Whether to bypass the cache
12+
* @returns {Promise<any>} The result
13+
*/
14+
static call({ dispatch }: ActionParams, { query, bypassCache, variables }: ActionParams): Promise<any>;
15+
}

dist/adapters/adapter.d.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import Model from "../orm/model";
2+
export declare enum ConnectionMode {
3+
AUTO = 0,
4+
PLAIN = 1,
5+
NODES = 2,
6+
EDGES = 3
7+
}
8+
export declare enum ArgumentMode {
9+
TYPE = 0,
10+
LIST = 1
11+
}
12+
export default interface Adapter {
13+
getRootQueryName(): string;
14+
getRootMutationName(): string;
15+
getNameForPersist(model: Model): string;
16+
getNameForPush(model: Model): string;
17+
getNameForDestroy(model: Model): string;
18+
getNameForFetch(model: Model, plural: boolean): string;
19+
getConnectionMode(): ConnectionMode;
20+
getArgumentMode(): ArgumentMode;
21+
getFilterTypeName(model: Model): string;
22+
getInputTypeName(model: Model, action?: string): string;
23+
prepareSchemaTypeName(name: string): string;
24+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import Adapter, { ConnectionMode, ArgumentMode } from "../adapter";
2+
import Model from "../../orm/model";
3+
export default class DefaultAdapter implements Adapter {
4+
getRootMutationName(): string;
5+
getRootQueryName(): string;
6+
getConnectionMode(): ConnectionMode;
7+
getArgumentMode(): ArgumentMode;
8+
getFilterTypeName(model: Model): string;
9+
getInputTypeName(model: Model, action?: string): string;
10+
getNameForDestroy(model: Model): string;
11+
getNameForFetch(model: Model, plural: boolean): string;
12+
getNameForPersist(model: Model): string;
13+
getNameForPush(model: Model): string;
14+
prepareSchemaTypeName(name: string): string;
15+
}

dist/common/context.d.ts

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
import Logger from "./logger";
2+
import Model from "../orm/model";
3+
import { PluginComponents } from "@vuex-orm/core/lib/plugins/use";
4+
import Apollo from "../graphql/apollo";
5+
import Database from "@vuex-orm/core/lib/database/Database";
6+
import { Options } from "../support/interfaces";
7+
import Schema from "../graphql/schema";
8+
import { Mock, MockOptions } from "../test-utils";
9+
import Adapter, { ConnectionMode } from "../adapters/adapter";
10+
/**
11+
* Internal context of the plugin. This class contains all information, the models, database, logger and so on.
12+
*
13+
* It's a singleton class, so just call Context.getInstance() anywhere you need the context.
14+
*/
15+
export default class Context {
16+
/**
17+
* Contains the instance for the singleton pattern.
18+
* @type {Context}
19+
*/
20+
static instance: Context;
21+
/**
22+
* Components collection of Vuex-ORM
23+
* @type {PluginComponents}
24+
*/
25+
readonly components: PluginComponents;
26+
/**
27+
* The options which have been passed to VuexOrm.install
28+
* @type {Options}
29+
*/
30+
readonly options: Options;
31+
/**
32+
* GraphQL Adapter.
33+
* @type {Adapter}
34+
*/
35+
readonly adapter: Adapter;
36+
/**
37+
* The Vuex-ORM database
38+
* @type {Database}
39+
*/
40+
readonly database: Database;
41+
/**
42+
* Collection of all Vuex-ORM models wrapped in a Model instance.
43+
* @type {Map<any, any>}
44+
*/
45+
readonly models: Map<string, Model>;
46+
/**
47+
* When true, the logging is enabled.
48+
* @type {boolean}
49+
*/
50+
readonly debugMode: boolean;
51+
/**
52+
* Our nice Vuex-ORM-GraphQL logger
53+
* @type {Logger}
54+
*/
55+
readonly logger: Logger;
56+
/**
57+
* Instance of Apollo which cares about the communication with the graphql endpoint.
58+
* @type {Apollo}
59+
*/
60+
apollo: Apollo;
61+
/**
62+
* The graphql schema. Is null until the first request.
63+
* @type {Schema}
64+
*/
65+
schema: Schema | undefined;
66+
/**
67+
* Tells if the schema is already loaded or the loading is currently processed.
68+
* @type {boolean}
69+
*/
70+
private schemaWillBeLoaded;
71+
/**
72+
* Defines how to query connections. 'auto' | 'nodes' | 'edges' | 'plain'
73+
*/
74+
connectionMode: ConnectionMode;
75+
/**
76+
* Container for the global mocks.
77+
* @type {Object}
78+
*/
79+
private globalMocks;
80+
/**
81+
* Private constructor, called by the setup method
82+
*
83+
* @constructor
84+
* @param {PluginComponents} components The Vuex-ORM Components collection
85+
* @param {Options} options The options passed to VuexORM.install
86+
*/
87+
private constructor();
88+
/**
89+
* Get the singleton instance of the context.
90+
* @returns {Context}
91+
*/
92+
static getInstance(): Context;
93+
/**
94+
* This is called only once and creates a new instance of the Context.
95+
* @param {PluginComponents} components The Vuex-ORM Components collection
96+
* @param {Options} options The options passed to VuexORM.install
97+
* @returns {Context}
98+
*/
99+
static setup(components: PluginComponents, options: Options): Context;
100+
loadSchema(): Promise<Schema>;
101+
processSchema(): void;
102+
/**
103+
* Returns a model from the model collection by it's name
104+
*
105+
* @param {Model|string} model A Model instance, a singular or plural name of the model
106+
* @param {boolean} allowNull When true this method returns null instead of throwing an exception when no model was
107+
* found. Default is false
108+
* @returns {Model}
109+
*/
110+
getModel(model: Model | string, allowNull?: boolean): Model;
111+
/**
112+
* Will add a mock for simple mutations or queries. These are model unrelated and have to be
113+
* handled globally.
114+
*
115+
* @param {Mock} mock - Mock config.
116+
*/
117+
addGlobalMock(mock: Mock): boolean;
118+
/**
119+
* Finds a global mock for the given action and options.
120+
*
121+
* @param {string} action - Name of the action like 'simpleQuery' or 'simpleMutation'.
122+
* @param {MockOptions} options - MockOptions like { name: 'example' }.
123+
* @returns {Mock | null} null when no mock was found.
124+
*/
125+
findGlobalMock(action: string, options: MockOptions | undefined): Mock | null;
126+
/**
127+
* Hook to be called by simpleMutation and simpleQuery actions in order to get the global mock
128+
* returnValue.
129+
*
130+
* @param {string} action - Name of the action like 'simpleQuery' or 'simpleMutation'.
131+
* @param {MockOptions} options - MockOptions.
132+
* @returns {any} null when no mock was found.
133+
*/
134+
globalMockHook(action: string, options: MockOptions): any;
135+
/**
136+
* Wraps all Vuex-ORM entities in a Model object and saves them into this.models
137+
*/
138+
private collectModels;
139+
}

0 commit comments

Comments
 (0)