Socket
Socket
Sign inDemoInstall

@n1ru4l/in-memory-live-query-store

Package Overview
Dependencies
5
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.8.0 to 0.9.0-alpha-51b566b.0

56

esm/index.js

@@ -185,16 +185,34 @@ import { visit, visitWithTypeInfo, isNonNullType, isScalarType, execute, getOperationAST, GraphQLError, defaultFieldResolver, TypeInfo } from 'graphql';

newFieldConfig.resolve = (src, args, context, info) => {
var _a;
var _a, _b;
if (!context || ORIGINAL_CONTEXT_SYMBOL in context === false) {
return resolve(src, args, context, info);
}
const collectResourceIdentifier = context.collectResourceIdentifier;
const addResourceIdentifier = context.addResourceIdentifier;
context = context[ORIGINAL_CONTEXT_SYMBOL];
const result = resolve(src, args, context, info);
const liveQueyContext = context;
const result = resolve(src, args, liveQueyContext[ORIGINAL_CONTEXT_SYMBOL], info);
const fieldConfigExtensions = fieldConfig.extensions;
if ((_a = fieldConfigExtensions === null || fieldConfigExtensions === void 0 ? void 0 : fieldConfigExtensions.liveQuery) === null || _a === void 0 ? void 0 : _a.collectResourceIdentifiers) {
addResourceIdentifier(fieldConfigExtensions.liveQuery.collectResourceIdentifiers(src, args));
liveQueyContext.addResourceIdentifier(fieldConfigExtensions.liveQuery.collectResourceIdentifiers(src, args));
}
const fieldCoordinate = `${typename}.${fieldName}`;
const indicesForCoordinate = (_b = liveQueyContext.indices) === null || _b === void 0 ? void 0 : _b.get(fieldCoordinate);
if (indicesForCoordinate) {
for (const index of indicesForCoordinate) {
let parts = [];
for (const part of index) {
if (Array.isArray(part)) {
if (args[part[0]] === part[1]) {
parts.push(`${part[0]}:"${args[part[0]]}"`);
}
}
else if (args[part] !== undefined) {
parts.push(`${part}:"${args[part]}"`);
}
}
if (parts.length) {
liveQueyContext.addResourceIdentifier(`${fieldCoordinate}(${parts.join(",")})`);
}
}
}
if (isIDField) {
runWith(result, (id) => collectResourceIdentifier({ typename, id }));
runWith(result, (id) => liveQueyContext.collectResourceIdentifier({ typename, id }));
}

@@ -219,2 +237,3 @@ return result;

this._idFieldName = "id";
this._indices = null;
this.makeExecute = (execute) => (args) => {

@@ -289,2 +308,8 @@ const { schema: inputSchema, document, rootValue, contextValue, variableValues, operationName, ...additionalArguments } = args;

};
const context = {
[ORIGINAL_CONTEXT_SYMBOL]: contextValue,
collectResourceIdentifier,
addResourceIdentifier,
indices: this._indices,
};
const result = execute({

@@ -295,7 +320,3 @@ schema,

rootValue,
contextValue: {
[ORIGINAL_CONTEXT_SYMBOL]: contextValue,
collectResourceIdentifier,
addResourceIdentifier,
},
contextValue: context,
variableValues,

@@ -377,2 +398,13 @@ ...additionalArguments,

}
if (params === null || params === void 0 ? void 0 : params.indexBy) {
this._indices = new Map();
for (const { field, args } of params.indexBy) {
let indices = this._indices.get(field);
if (!indices) {
indices = [];
this._indices.set(field, indices);
}
indices.push(args);
}
}
this._includeIdentifierExtension =

@@ -379,0 +411,0 @@ (_a = params === null || params === void 0 ? void 0 : params.includeIdentifierExtension) !== null && _a !== void 0 ? _a : (typeof process === "undefined"

@@ -189,16 +189,34 @@ 'use strict';

newFieldConfig.resolve = (src, args, context, info) => {
var _a;
var _a, _b;
if (!context || ORIGINAL_CONTEXT_SYMBOL in context === false) {
return resolve(src, args, context, info);
}
const collectResourceIdentifier = context.collectResourceIdentifier;
const addResourceIdentifier = context.addResourceIdentifier;
context = context[ORIGINAL_CONTEXT_SYMBOL];
const result = resolve(src, args, context, info);
const liveQueyContext = context;
const result = resolve(src, args, liveQueyContext[ORIGINAL_CONTEXT_SYMBOL], info);
const fieldConfigExtensions = fieldConfig.extensions;
if ((_a = fieldConfigExtensions === null || fieldConfigExtensions === void 0 ? void 0 : fieldConfigExtensions.liveQuery) === null || _a === void 0 ? void 0 : _a.collectResourceIdentifiers) {
addResourceIdentifier(fieldConfigExtensions.liveQuery.collectResourceIdentifiers(src, args));
liveQueyContext.addResourceIdentifier(fieldConfigExtensions.liveQuery.collectResourceIdentifiers(src, args));
}
const fieldCoordinate = `${typename}.${fieldName}`;
const indicesForCoordinate = (_b = liveQueyContext.indices) === null || _b === void 0 ? void 0 : _b.get(fieldCoordinate);
if (indicesForCoordinate) {
for (const index of indicesForCoordinate) {
let parts = [];
for (const part of index) {
if (Array.isArray(part)) {
if (args[part[0]] === part[1]) {
parts.push(`${part[0]}:"${args[part[0]]}"`);
}
}
else if (args[part] !== undefined) {
parts.push(`${part}:"${args[part]}"`);
}
}
if (parts.length) {
liveQueyContext.addResourceIdentifier(`${fieldCoordinate}(${parts.join(",")})`);
}
}
}
if (isIDField) {
runWith(result, (id) => collectResourceIdentifier({ typename, id }));
runWith(result, (id) => liveQueyContext.collectResourceIdentifier({ typename, id }));
}

@@ -223,2 +241,3 @@ return result;

this._idFieldName = "id";
this._indices = null;
this.makeExecute = (execute) => (args) => {

@@ -293,2 +312,8 @@ const { schema: inputSchema, document, rootValue, contextValue, variableValues, operationName, ...additionalArguments } = args;

};
const context = {
[ORIGINAL_CONTEXT_SYMBOL]: contextValue,
collectResourceIdentifier,
addResourceIdentifier,
indices: this._indices,
};
const result = execute({

@@ -299,7 +324,3 @@ schema,

rootValue,
contextValue: {
[ORIGINAL_CONTEXT_SYMBOL]: contextValue,
collectResourceIdentifier,
addResourceIdentifier,
},
contextValue: context,
variableValues,

@@ -381,2 +402,13 @@ ...additionalArguments,

}
if (params === null || params === void 0 ? void 0 : params.indexBy) {
this._indices = new Map();
for (const { field, args } of params.indexBy) {
let indices = this._indices.get(field);
if (!indices) {
indices = [];
this._indices.set(field, indices);
}
indices.push(args);
}
}
this._includeIdentifierExtension =

@@ -383,0 +415,0 @@ (_a = params === null || params === void 0 ? void 0 : params.includeIdentifierExtension) !== null && _a !== void 0 ? _a : (typeof process === "undefined"

@@ -5,2 +5,5 @@ import { ExecutionResult, execute as defaultExecute, ExecutionArgs } from "graphql";

declare type PromiseOrValue<T> = T | Promise<T>;
declare type ArgumentName = string;
declare type ArgumentValue = string;
declare type IndexConfiguration = Array<ArgumentName | [arg: ArgumentName, value: ArgumentValue]>;
export declare type BuildResourceIdentifierFunction = (parameter: Readonly<{

@@ -46,2 +49,9 @@ typename: string;

validateThrottleValue?: ValidateThrottleValueFunction;
/**
* Specify which fields should be indexed for specific invalidations.
*/
indexBy?: Array<{
field: string;
args: IndexConfiguration;
}>;
};

@@ -57,2 +67,3 @@ declare type LiveExecuteReturnType = PromiseOrValue<AsyncIterableIterator<ExecutionResult | LiveExecutionResult> | ExecutionResult>;

private _validateThrottleValue;
private _indices;
constructor(params?: InMemoryLiveQueryStoreParameter);

@@ -59,0 +70,0 @@ private _getPatchedSchema;

{
"name": "@n1ru4l/in-memory-live-query-store",
"version": "0.8.0",
"version": "0.9.0-alpha-51b566b.0",
"peerDependencies": {

@@ -5,0 +5,0 @@ "graphql": "^15.4.0 || ^16.0.0"

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc