Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@graphql-live/client

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@graphql-live/client - npm Package Compare versions

Comparing version 0.1.5 to 0.1.6

29

dist/createClient.js

@@ -11,11 +11,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

import { io } from "socket.io-client";
import { applyPatch } from "fast-json-patch";
import { applyPatch, deepClone } from "fast-json-patch";
export function createClient({ url, context, socketOptions } = {}) {
const socket = url ? io(url, socketOptions) : io(socketOptions);
let isOffline = false;
let disconnected = false;
let currentId = 0;
// This stores all ongoing operations waiting for results (possibly result streams) :
const operations = new Map();
const onConnect = () => {
if (isOffline) {
isOffline = false;
if (disconnected) {
disconnected = false;
// If this was a reconnection, re-execute all active operations, to be up-to-date :
for (const record of operations.values())

@@ -26,3 +28,3 @@ record.execute();

const onDisconnect = () => {
isOffline = true;
disconnected = true;
};

@@ -33,5 +35,5 @@ const onOperationResult = ({ id, patch, isFinal }) => {

return;
const previousResult = record.latestResult;
record.latestResult = applyPatch(previousResult, patch).newDocument;
console.log("Patched", previousResult, "with", patch);
// When a patch is sent by the server, apply it to the latest known result and send
// the updated result to the observer :
record.latestResult = applyPatch(deepClone(record.latestResult), patch).newDocument;
record.observer.next(record.latestResult);

@@ -52,10 +54,8 @@ if (isFinal) {

};
setTimeout(() => {
socket.disconnect();
setTimeout(() => {
socket.connect();
}, 6000);
}, 15000);
const execute = (operation, observer) => {
// For each new operation, a unique id is created :
const id = currentId++;
// Also, a record is added to the operation store, keeping track of the observer interested
// in results, the latest known result, and a function to execute the operation (might be
// used for re-executions on reconnections) :
const record = {

@@ -66,2 +66,3 @@ observer,

return __awaiter(this, void 0, void 0, function* () {
record.latestResult = {};
const payload = {

@@ -68,0 +69,0 @@ id,

{
"name": "@graphql-live/client",
"version": "0.1.5",
"version": "0.1.6",
"description": "The client part of the GraphQLive package",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

import { io, ManagerOptions, SocketOptions } from "socket.io-client";
import { ExecutionResult } from "graphql";
import { applyPatch, Operation as PatchOperation } from "fast-json-patch";
import {
applyPatch,
deepClone,
Operation as PatchOperation
} from "fast-json-patch";

@@ -47,9 +51,12 @@ export type ClientOptions = {

const socket = url ? io(url, socketOptions) : io(socketOptions);
let isOffline = false;
let disconnected = false;
let currentId = 0;
// This stores all ongoing operations waiting for results (possibly result streams) :
const operations = new Map<number, OperationRecord>();
const onConnect = () => {
if (isOffline) {
isOffline = false;
if (disconnected) {
disconnected = false;
// If this was a reconnection, re-execute all active operations, to be up-to-date :
for (const record of operations.values()) record.execute();

@@ -60,3 +67,3 @@ }

const onDisconnect = () => {
isOffline = true;
disconnected = true;
};

@@ -67,5 +74,8 @@

if (!record) return;
const previousResult = record.latestResult;
record.latestResult = applyPatch(previousResult, patch).newDocument;
console.log("Patched", previousResult, "with", patch);
// When a patch is sent by the server, apply it to the latest known result and send
// the updated result to the observer :
record.latestResult = applyPatch(
deepClone(record.latestResult),
patch
).newDocument;
record.observer.next(record.latestResult);

@@ -89,11 +99,8 @@ if (isFinal) {

setTimeout(() => {
socket.disconnect();
setTimeout(() => {
socket.connect();
}, 6000);
}, 15000);
const execute = (operation: Operation, observer: ResultObserver) => {
// For each new operation, a unique id is created :
const id = currentId++;
// Also, a record is added to the operation store, keeping track of the observer interested
// in results, the latest known result, and a function to execute the operation (might be
// used for re-executions on reconnections) :
const record: OperationRecord = {

@@ -103,2 +110,3 @@ observer,

async execute() {
record.latestResult = {};
const payload: OperationPayload = {

@@ -105,0 +113,0 @@ id,

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