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

@apollo-elements/mixins

Package Overview
Dependencies
Maintainers
1
Versions
62
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@apollo-elements/mixins - npm Package Compare versions

Comparing version 4.1.1-next.0 to 5.0.0

12

apollo-element-mixin.js

@@ -9,6 +9,5 @@ import { __decorate } from "tslib";

constructor(...a) {
var _a;
super(...a);
/** @summary The Apollo Client instance. */
this.client = (_a = window.__APOLLO_CLIENT__) !== null && _a !== void 0 ? _a : null; /* c8 ignore next */ // covered
this.client = window.__APOLLO_CLIENT__ ?? null; /* c8 ignore next */ // covered
/**

@@ -38,5 +37,4 @@ * @summary Operation document.

static get observedAttributes() {
var _a;
return [
...(_a = super.observedAttributes) !== null && _a !== void 0 ? _a : [],
...super.observedAttributes ?? [],
'error-policy',

@@ -47,3 +45,2 @@ 'fetch-policy',

attributeChangedCallback(name, oldVal, newVal) {
var _a;
/* c8 ignore start */ // covered

@@ -58,3 +55,3 @@ switch (name) {

}
(_a = super.attributeChangedCallback) === null || _a === void 0 ? void 0 : _a.call(this, name, oldVal, newVal);
super.attributeChangedCallback?.(name, oldVal, newVal);
/* c8 ignore stop */

@@ -68,6 +65,5 @@ }

disconnectedCallback() {
var _a;
this.dispatchEvent(new ApolloElementEvent('apollo-element-disconnected', this));
window.dispatchEvent(new ApolloElementEvent('apollo-element-disconnected', this));
(_a = super.disconnectedCallback) === null || _a === void 0 ? void 0 : _a.call(this); /* c8 ignore start */ // manual testing showed that both cases were hit
super.disconnectedCallback?.(); /* c8 ignore start */ // manual testing showed that both cases were hit
}

@@ -74,0 +70,0 @@ }

@@ -12,4 +12,4 @@ import { __decorate } from "tslib";

update: this.updater,
onCompleted: data => { var _a; return data && ((_a = this.onCompleted) === null || _a === void 0 ? void 0 : _a.call(this, data)); },
onError: error => { var _a; return (_a = this.onError) === null || _a === void 0 ? void 0 : _a.call(this, error); },
onCompleted: data => data && this.onCompleted?.(data),
onError: error => this.onError?.(error),
});

@@ -22,5 +22,4 @@ this.called = false;

static get observedAttributes() {
var _a;
return [
...((_a = super.observedAttributes) !== null && _a !== void 0 ? _a : []),
...(super.observedAttributes ?? []),
'await-refetch-queries',

@@ -31,7 +30,6 @@ 'refetch-queries',

attributeChangedCallback(name, oldVal, newVal) {
var _a, _b, _c;
(_a = super.attributeChangedCallback) === null || _a === void 0 ? void 0 : _a.call(this, name, oldVal, newVal);
super.attributeChangedCallback?.(name, oldVal, newVal);
/* c8 ignore start */
// @ts-expect-error: ts is not tracking the static side
if (((_c = (_b = super.constructor) === null || _b === void 0 ? void 0 : _b.observedAttributes) !== null && _c !== void 0 ? _c : []).includes(name))
if ((super.constructor?.observedAttributes ?? []).includes(name))
return;

@@ -38,0 +36,0 @@ /* c8 ignore stop */

@@ -29,3 +29,3 @@ import { expect, defineCE, fixture } from '@open-wc/testing';

}
$(id) { var _a; return (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.getElementById(id); }
$(id) { return this.shadowRoot?.getElementById(id); }
update() {

@@ -36,4 +36,3 @@ this.render();

render() {
var _a;
(_a = this.observed) === null || _a === void 0 ? void 0 : _a.forEach(property => {
this.observed?.forEach(property => {
if (this.$(property))

@@ -40,0 +39,0 @@ this.$(property).textContent = stringify(this[property]);

@@ -16,4 +16,4 @@ import { __decorate } from "tslib";

shouldSubscribe: x => this.readyToReceiveDocument && this.shouldSubscribe(x),
onData: data => { var _a; return (_a = this.onData) === null || _a === void 0 ? void 0 : _a.call(this, data); },
onError: error => { var _a; return (_a = this.onError) === null || _a === void 0 ? void 0 : _a.call(this, error); }, /* c8 ignore next */ // covered
onData: data => this.onData?.(data),
onError: error => this.onError?.(error), /* c8 ignore next */ // covered
});

@@ -77,6 +77,5 @@ /**

attributeChangedCallback(name, oldVal, newVal) {
var _a, _b, _c, _d;
(_a = super.attributeChangedCallback) === null || _a === void 0 ? void 0 : _a.call(this, name, oldVal, newVal);
super.attributeChangedCallback?.(name, oldVal, newVal);
// @ts-expect-error: ts is not tracking the static side
if ((_d = (_c = (_b = super.constructor) === null || _b === void 0 ? void 0 : _b.observedAttributes) === null || _c === void 0 ? void 0 : _c.includes) === null || _d === void 0 ? void 0 : _d.call(_c, name))
if (super.constructor?.observedAttributes?.includes?.(name))
return; /* c8 ignore next */ // covered

@@ -83,0 +82,0 @@ switch (name) { /* c8 ignore next */ // covered

@@ -34,4 +34,3 @@ import * as S from '@apollo-elements/test/schema';

render() {
var _a;
(_a = this.observed) === null || _a === void 0 ? void 0 : _a.forEach(property => {
this.observed?.forEach(property => {
if (this.$(property))

@@ -38,0 +37,0 @@ this.$(property).textContent = stringify(this[property]);

@@ -12,5 +12,5 @@ import { __decorate } from "tslib";

shouldSubscribe: x => this.readyToReceiveDocument && this.shouldSubscribe(x),
onData: data => { var _a; return (_a = this.onSubscriptionData) === null || _a === void 0 ? void 0 : _a.call(this, data); },
onComplete: () => { var _a; return (_a = this.onSubscriptionComplete) === null || _a === void 0 ? void 0 : _a.call(this); },
onError: error => { var _a; return (_a = this.onError) === null || _a === void 0 ? void 0 : _a.call(this, error); },
onData: data => this.onSubscriptionData?.(data),
onComplete: () => this.onSubscriptionComplete?.(),
onError: error => this.onError?.(error),
});

@@ -17,0 +17,0 @@ this.subscription = null;

@@ -24,4 +24,3 @@ import { defineCE, expect, fixture } from '@open-wc/testing';

render() {
var _a;
(_a = this.observed) === null || _a === void 0 ? void 0 : _a.forEach(property => {
this.observed?.forEach(property => {
if (this.$(property))

@@ -28,0 +27,0 @@ this.$(property).textContent = stringify(this[property]);

@@ -1,2 +0,1 @@

import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
import { dedupeMixin } from '@open-wc/dedupe-mixin';

@@ -7,36 +6,37 @@ import { setInitialProps } from '@apollo-elements/core/decorators';

function ControllerHostMixinImpl(superclass) {
var _ControllerHostElement_controllers, _ControllerHostElement_updatePending, _ControllerHostElement_resolve, _ControllerHostElement_updateComplete;
class ControllerHostElement extends superclass {
constructor(...args) {
super(...args);
_ControllerHostElement_controllers.set(this, new Set());
_ControllerHostElement_updatePending.set(this, false);
_ControllerHostElement_resolve.set(this, void 0);
_ControllerHostElement_updateComplete.set(this, new Promise(r => {
__classPrivateFieldSet(this, _ControllerHostElement_resolve, r, "f");
}));
this.#controllers = new Set();
this.#updatePending = false;
this.#updateComplete = new Promise(r => {
this.#resolve = r;
});
INITIALIZED.set(this, true);
this.requestUpdate();
}
#controllers;
#updatePending;
#resolve;
#updateComplete;
get updateComplete() {
var _a;
// @ts-expect-error: superclass may or may not have it
return (_a = super.updateComplete) !== null && _a !== void 0 ? _a : __classPrivateFieldGet(this, _ControllerHostElement_updateComplete, "f");
return super.updateComplete ??
this.#updateComplete;
}
async doUpdate() {
__classPrivateFieldSet(this, _ControllerHostElement_updatePending, true, "f");
await __classPrivateFieldGet(this, _ControllerHostElement_updateComplete, "f");
this.#updatePending = true;
await this.#updateComplete;
this.update();
__classPrivateFieldSet(this, _ControllerHostElement_updateComplete, new Promise(r => { __classPrivateFieldSet(this, _ControllerHostElement_resolve, r, "f"); }), "f");
this.#updateComplete = new Promise(r => { this.#resolve = r; });
microtask.then(() => this.updated());
}
connectedCallback() {
var _a;
// assign props that were set before initialization finished
setInitialProps(this);
(_a = super.connectedCallback) === null || _a === void 0 ? void 0 : _a.call(this); /* c8 ignore next */
super.connectedCallback?.(); /* c8 ignore next */
// @ts-expect-error: superclass may or may not have it
if (typeof super.addController !== 'function')
__classPrivateFieldGet(this, _ControllerHostElement_controllers, "f").forEach(c => { var _a; return (_a = c.hostConnected) === null || _a === void 0 ? void 0 : _a.call(c); });
__classPrivateFieldGet(this, _ControllerHostElement_resolve, "f").call(this, true);
this.#controllers.forEach(c => c.hostConnected?.());
this.#resolve(true);
}

@@ -48,3 +48,3 @@ addController(controller) {

else
__classPrivateFieldGet(this, _ControllerHostElement_controllers, "f").add(controller);
this.#controllers.add(controller);
}

@@ -56,3 +56,3 @@ removeController(controller) {

else
__classPrivateFieldGet(this, _ControllerHostElement_controllers, "f").delete(controller);
this.#controllers.delete(controller);
}

@@ -65,3 +65,3 @@ requestUpdate() {

return super.requestUpdate(); /* c8 ignore next */
if (!__classPrivateFieldGet(this, _ControllerHostElement_updatePending, "f"))
if (!this.#updatePending)
this.doUpdate();

@@ -74,3 +74,3 @@ }

else
__classPrivateFieldGet(this, _ControllerHostElement_controllers, "f").forEach(c => { var _a; return (_a = c.hostUpdate) === null || _a === void 0 ? void 0 : _a.call(c); }); /* c8 ignore next */
this.#controllers.forEach(c => c.hostUpdate?.()); /* c8 ignore next */
}

@@ -82,16 +82,14 @@ updated(...args) {

else {
__classPrivateFieldSet(this, _ControllerHostElement_updatePending, false, "f");
__classPrivateFieldGet(this, _ControllerHostElement_controllers, "f").forEach(c => { var _a; return (_a = c.hostUpdated) === null || _a === void 0 ? void 0 : _a.call(c); }); /* c8 ignore next */
__classPrivateFieldGet(this, _ControllerHostElement_resolve, "f").call(this, __classPrivateFieldGet(this, _ControllerHostElement_updatePending, "f"));
this.#updatePending = false;
this.#controllers.forEach(c => c.hostUpdated?.()); /* c8 ignore next */
this.#resolve(this.#updatePending);
}
}
disconnectedCallback() {
var _a;
(_a = super.disconnectedCallback) === null || _a === void 0 ? void 0 : _a.call(this); /* c8 ignore next */
super.disconnectedCallback?.(); /* c8 ignore next */
// @ts-expect-error: superclass may or may not have it
if (typeof super.removeController !== 'function')
__classPrivateFieldGet(this, _ControllerHostElement_controllers, "f").forEach(c => { var _a; return (_a = c.hostDisconnected) === null || _a === void 0 ? void 0 : _a.call(c); });
this.#controllers.forEach(c => c.hostDisconnected?.());
}
}
_ControllerHostElement_controllers = new WeakMap(), _ControllerHostElement_updatePending = new WeakMap(), _ControllerHostElement_resolve = new WeakMap(), _ControllerHostElement_updateComplete = new WeakMap();
return ControllerHostElement;

@@ -98,0 +96,0 @@ }

@@ -36,4 +36,3 @@ import { spy } from 'sinon';

afterEach(function clearFixture() {
var _a;
(_a = element === null || element === void 0 ? void 0 : element.remove) === null || _a === void 0 ? void 0 : _a.call(element);
element?.remove?.();
// @ts-expect-error: just to clear the fixture

@@ -120,4 +119,3 @@ element = undefined;

afterEach(function clearFixture() {
var _a;
(_a = element === null || element === void 0 ? void 0 : element.remove) === null || _a === void 0 ? void 0 : _a.call(element);
element?.remove?.();
// @ts-expect-error: just to clear the fixture

@@ -124,0 +122,0 @@ element = undefined;

@@ -9,4 +9,3 @@ import { gql } from '@apollo/client/core';

function stripHTMLComments(string) {
var _a;
return (_a = string.replace) === null || _a === void 0 ? void 0 : _a.call(string, /<!---->/g, '');
return string.replace?.(/<!---->/g, '');
}

@@ -66,5 +65,5 @@ function GraphQLScriptChildMixinImplementation(superclass) {

/* c8 ignore start */ // covered
if (script === null || script === void 0 ? void 0 : script.src)
if (script?.src)
return this.fetchDocument(script.src);
else if (!(script === null || script === void 0 ? void 0 : script.innerText))
else if (!script?.innerText)
return null;

@@ -93,8 +92,7 @@ else

async connectedCallback() {
var _a, _b, _c;
this.mo = new MutationObserver(this.onDOMMutation.bind(this));
this.mo.observe(this, { characterData: true, childList: true, subtree: true });
(_a = this.document) !== null && _a !== void 0 ? _a : (this.document = await this.getDOMGraphQLDocument());
(_b = this.variables) !== null && _b !== void 0 ? _b : (this.variables = this.getDOMVariables());
(_c = super.connectedCallback) === null || _c === void 0 ? void 0 : _c.call(this);
this.document ??= await this.getDOMGraphQLDocument();
this.variables ??= this.getDOMVariables();
super.connectedCallback?.();
}

@@ -105,5 +103,4 @@ /**

disconnectedCallback() {
var _a, _b;
(_a = super.disconnectedCallback) === null || _a === void 0 ? void 0 : _a.call(this);
(_b = this.mo) === null || _b === void 0 ? void 0 : _b.disconnect();
super.disconnectedCallback?.();
this.mo?.disconnect();
}

@@ -110,0 +107,0 @@ }

@@ -47,4 +47,3 @@ import { spy } from 'sinon';

afterEach(function clearFixture() {
var _a;
(_a = element === null || element === void 0 ? void 0 : element.remove) === null || _a === void 0 ? void 0 : _a.call(element);
element?.remove?.();
// @ts-expect-error: just to clear the fixture

@@ -338,6 +337,5 @@ element = undefined;

beforeEach(() => spy(window.__APOLLO_CLIENT__, 'watchQuery'));
afterEach(() => { var _a, _b; return (_b = (_a = window.__APOLLO_CLIENT__.watchQuery).restore) === null || _b === void 0 ? void 0 : _b.call(_a); });
afterEach(() => window.__APOLLO_CLIENT__.watchQuery.restore?.());
afterEach(function clearFixture() {
var _a;
(_a = element === null || element === void 0 ? void 0 : element.remove) === null || _a === void 0 ? void 0 : _a.call(element);
element?.remove?.();
// @ts-expect-error: just to clear the fixture

@@ -356,3 +354,3 @@ element = undefined;

it('does not change document', function () {
expect(element === null || element === void 0 ? void 0 : element.query).to.be.null;
expect(element?.query).to.be.null;
});

@@ -366,7 +364,6 @@ });

it('does not change document', function () {
expect(element === null || element === void 0 ? void 0 : element.query).to.be.null;
expect(element?.query).to.be.null;
});
it('sets error', function () {
var _a;
expect((_a = element === null || element === void 0 ? void 0 : element.error) === null || _a === void 0 ? void 0 : _a.message.includes('quory')).to.be.true;
expect(element?.error?.message.includes('quory')).to.be.true;
});

@@ -385,10 +382,9 @@ });

it('does not remove script', function () {
expect(element === null || element === void 0 ? void 0 : element.firstElementChild).to.be.an.instanceof(HTMLElement);
expect(element?.firstElementChild).to.be.an.instanceof(HTMLElement);
});
it('sets query property', function () {
expect(element === null || element === void 0 ? void 0 : element.query).to.deep.equal(gql(NoParamQuery.loc.source.body));
expect(element?.query).to.deep.equal(gql(NoParamQuery.loc.source.body));
});
it('subscribes', function () {
var _a;
expect((_a = element === null || element === void 0 ? void 0 : element.client) === null || _a === void 0 ? void 0 : _a.watchQuery).to.have.been.called;
expect(element?.client?.watchQuery).to.have.been.called;
});

@@ -403,4 +399,3 @@ describe('changing the DOM script to HelloQuery', function () {

it('sets the query property', function () {
var _a, _b;
expect((_b = (_a = element === null || element === void 0 ? void 0 : element.shadowRoot) === null || _a === void 0 ? void 0 : _a.getElementById('data')) === null || _b === void 0 ? void 0 : _b.textContent)
expect(element?.shadowRoot?.getElementById('data')?.textContent)
.to.equal(stringify({

@@ -421,4 +416,3 @@ helloWorld: {

it('rerenders', function () {
var _a, _b;
expect((_b = (_a = element === null || element === void 0 ? void 0 : element.shadowRoot) === null || _a === void 0 ? void 0 : _a.getElementById('data')) === null || _b === void 0 ? void 0 : _b.textContent)
expect(element?.shadowRoot?.getElementById('data')?.textContent)
.to.equal(stringify({

@@ -444,4 +438,3 @@ helloWorld: {

afterEach(function clearFixture() {
var _a;
(_a = element === null || element === void 0 ? void 0 : element.remove) === null || _a === void 0 ? void 0 : _a.call(element);
element?.remove?.();
// @ts-expect-error: just to clear the fixture

@@ -477,4 +470,3 @@ element = undefined;

afterEach(function clearFixture() {
var _a;
(_a = element === null || element === void 0 ? void 0 : element.remove) === null || _a === void 0 ? void 0 : _a.call(element);
element?.remove?.();
// @ts-expect-error: just to clear the fixture

@@ -485,13 +477,11 @@ element = undefined;

beforeEach(function clientSpy() {
var _a, _b;
// @ts-expect-error: spy
(_b = (_a = window.__APOLLO_CLIENT__.subscribe) === null || _a === void 0 ? void 0 : _a.restore) === null || _b === void 0 ? void 0 : _b.call(_a);
spies !== null && spies !== void 0 ? spies : (spies = {});
window.__APOLLO_CLIENT__.subscribe?.restore?.();
spies ??= {};
spies['client.subscribe'] = spy(window.__APOLLO_CLIENT__, 'subscribe');
});
beforeEach(async function setupElement() {
var _a;
({ element, spies } = await setupFunction({
innerHTML: `
<script type="application/graphql">${(_a = NoParamSubscription === null || NoParamSubscription === void 0 ? void 0 : NoParamSubscription.loc) === null || _a === void 0 ? void 0 : _a.source.body}</script>
<script type="application/graphql">${NoParamSubscription?.loc?.source.body}</script>
`,

@@ -503,10 +493,9 @@ }));

it('does not remove the script', function () {
expect(element === null || element === void 0 ? void 0 : element.firstElementChild).to.be.an.instanceof(HTMLScriptElement);
expect(element?.firstElementChild).to.be.an.instanceof(HTMLScriptElement);
});
it('sets the subscription property', function () {
expect(element === null || element === void 0 ? void 0 : element.subscription).to.deep.equal(gql(NoParamSubscription.loc.source.body));
expect(element?.subscription).to.deep.equal(gql(NoParamSubscription.loc.source.body));
});
it('calls subscribe()', function () {
var _a;
expect((_a = element === null || element === void 0 ? void 0 : element.client) === null || _a === void 0 ? void 0 : _a.subscribe).to.have.been.calledOnce;
expect(element?.client?.subscribe).to.have.been.calledOnce;
});

@@ -513,0 +502,0 @@ });

{
"name": "@apollo-elements/mixins",
"version": "4.1.1-next.0",
"version": "5.0.0",
"description": "👩‍🚀🌛 Custom Element class mixins for Apollo GraphQL 🚀👨‍🚀",

@@ -55,3 +55,3 @@ "main": "index.js",

"dependencies": {
"@apollo-elements/core": "^1.1.1-next.0",
"@apollo-elements/core": "^2.0.0",
"@apollo/client": "^3.5.4",

@@ -58,0 +58,0 @@ "@open-wc/dedupe-mixin": "^1.3.0",

@@ -10,6 +10,5 @@ import { dedupeMixin } from '@open-wc/dedupe-mixin';

connectedCallback() {
var _a, _b;
(_a = super.connectedCallback) === null || _a === void 0 ? void 0 : _a.call(this);
super.connectedCallback?.();
if (this.typePolicies)
(_b = this.client) === null || _b === void 0 ? void 0 : _b.cache.policies.addTypePolicies(this.typePolicies);
this.client?.cache.policies.addTypePolicies(this.typePolicies);
}

@@ -16,0 +15,0 @@ };

@@ -12,8 +12,7 @@ import { dedupeMixin } from '@open-wc/dedupe-mixin';

const { shouldSubscribe } = this.controller.options;
this.controller.options.shouldSubscribe = (x) => { var _a; return ((_a = shouldSubscribe === null || shouldSubscribe === void 0 ? void 0 : shouldSubscribe(x)) !== null && _a !== void 0 ? _a : true) && this.shouldSubscribe(x); }; /* c8 ignore next */
this.controller.options.shouldSubscribe = (x) => (shouldSubscribe?.(x) ?? true) && this.shouldSubscribe(x); /* c8 ignore next */
}
shouldSubscribe(options) {
var _a, _b, _c, _d;
const query = (_b = (_a = options === null || options === void 0 ? void 0 : options.query) !== null && _a !== void 0 ? _a : this.document) !== null && _b !== void 0 ? _b : undefined;
const variables = (_d = (_c = options === null || options === void 0 ? void 0 : options.variables) !== null && _c !== void 0 ? _c : this.variables) !== null && _d !== void 0 ? _d : undefined;
const query = options?.query ?? this.document ?? undefined;
const variables = options?.variables ?? this.variables ?? undefined;
return hasAllVariables({ query, variables });

@@ -20,0 +19,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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