Skip to content

Commit

Permalink
fix all eslint errors
Browse files Browse the repository at this point in the history
Co-authored-by: elf Pavlik <[email protected]>
  • Loading branch information
samurex and elf-pavlik committed Jan 17, 2024
1 parent 3f5f535 commit 189fd0b
Show file tree
Hide file tree
Showing 84 changed files with 162 additions and 271 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ module.exports = {
'import/extensions': 'off',
'import/no-unresolved': 'off',
'import/prefer-default-export': 'off',
'import/no-extraneous-dependencies': 'off',
'no-restricted-syntax': 'off',
'no-useless-constructor': 'off',
'no-empty-function': ['error', { 'allow': ['constructors'] }],
'dot-notation': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'no-shadow': 'off',
'@typescript-eslint/no-shadow': 'warn'
'@typescript-eslint/no-shadow': 'warn',
},
overrides: [
{
Expand Down
2 changes: 1 addition & 1 deletion examples/vuejectron/src/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
*/

// Plugins
import type { App } from 'vue';
import { loadFonts } from './webfontloader';
import vuetify from './vuetify';
import pinia from '../store';
import router from '../router';

// Types
import type { App } from 'vue';

export function registerPlugins(app: App) {
loadFonts();
Expand Down
23 changes: 12 additions & 11 deletions examples/vuejectron/src/router/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
// Composables
import { h } from 'vue';
import { useCoreStore } from '@/store/core';
import { createRouter, createWebHistory } from 'vue-router';
import { useCoreStore } from '@/store/core';

async function handleRedirect() {
const coreStore = useCoreStore();
await coreStore.handleRedirect(window.location.href);
const restoreUrl = localStorage.getItem('restorePath');
localStorage.removeItem('restorePath');
const defaultRoute = { name: 'agent', query: { agent: coreStore.userId } };
return restoreUrl || defaultRoute;
}

const routes = [
{
Expand Down Expand Up @@ -51,6 +60,7 @@ const router = createRouter({
routes
});

/* eslint-disable consistent-return */
router.beforeEach(async (to) => {
if (to.name === 'redirect') return;
const coreStore = useCoreStore();
Expand All @@ -65,15 +75,6 @@ router.beforeEach(async (to) => {
}
});

async function handleRedirect() {
const coreStore = useCoreStore();
await coreStore.handleRedirect(window.location.href);
const restoreUrl = localStorage.getItem('restorePath');
localStorage.removeItem('restorePath');
const defaultRoute = { name: 'agent', query: { agent: coreStore.userId } };
return restoreUrl ? restoreUrl : defaultRoute;
}

router.afterEach((to, from) => {
let direction = 'none';

Expand All @@ -84,7 +85,7 @@ router.afterEach((to, from) => {
if ((from.name === 'agent' && to.name === 'dashboard') || (from.name === 'project' && to.name === 'agent')) {
direction = 'right';
}

// eslint-disable-next-line no-param-reassign
to.meta.transition = direction;
});

Expand Down
59 changes: 30 additions & 29 deletions examples/vuejectron/src/sai.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { getDefaultSession } from '@inrupt/solid-client-authn-browser';
import { Application, SaiEvent } from '@janeirodigital/interop-application';
import { Agent, Project, Registration, Task, FileInstance, ImageInstance } from '@/models';
import { ACL, RDFS, buildNamespace } from '@janeirodigital/interop-utils';
import type { DataInstance } from '@janeirodigital/interop-data-model';
import { Agent, Project, Registration, Task, FileInstance, ImageInstance } from '@/models';

const cache: { [key: string]: DataInstance } = {};
const ownerIndex: { [key: string]: string } = {};
Expand Down Expand Up @@ -70,33 +70,6 @@ let webId: string;

const authnFetch = getDefaultSession().fetch;

export function useSai(userId: string | null) {
if (saiSession) {
if (saiSession.webId !== webId) throw new Error('WebId mismatch!');
} else {
if (!userId) throw new Error('no user id');
webId = userId;
}

return {
getStream,
isAuthorized,
getAuthorizationRedirectUri,
share,
getAgents,
getProjects,
getTasks,
updateTask,
deleteTask,
getFiles,
updateFile,
getImages,
dataUrl,
update,
getAccessModes
};
}

async function ensureSaiSession(): Promise<Application> {
if (saiSession) return saiSession;
const deps = { fetch: authnFetch, randomUUID: crypto.randomUUID.bind(crypto) };
Expand Down Expand Up @@ -159,6 +132,7 @@ async function getProjects(
canCreate: registration.grant.accessMode.includes(ACL.Create.value)
});
projects[registration.iri] = [];
// eslint-disable-next-line no-await-in-loop
for await (const dataInstance of registration.dataInstances) {
cache[dataInstance.iri] = dataInstance;
ownerIndex[dataInstance.iri] = ownerId;
Expand Down Expand Up @@ -279,8 +253,35 @@ async function update(iri: string, blob?: File) {
}

async function dataUrl(url: string): Promise<string> {
const fetch = getDefaultSession().fetch;
const { fetch } = getDefaultSession();
return fetch(url)
.then((response) => response.blob())
.then((blb) => URL.createObjectURL(blb));
}

export function useSai(userId: string | null) {
if (saiSession) {
if (saiSession.webId !== webId) throw new Error('WebId mismatch!');
} else {
if (!userId) throw new Error('no user id');
webId = userId;
}

return {
getStream,
isAuthorized,
getAuthorizationRedirectUri,
share,
getAgents,
getProjects,
getTasks,
updateTask,
deleteTask,
getFiles,
updateFile,
getImages,
dataUrl,
update,
getAccessModes
};
}
16 changes: 9 additions & 7 deletions examples/vuejectron/src/store/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,22 @@ export const useAppStore = defineStore('app', () => {
const currentAgent = ref<Agent>();
const currentProject = ref<Project>();

async function loadAgents(force = false): Promise<void> {
if (force || !agents.value.length) {
const sai = useSai(coreStore.userId);
agents.value = await sai.getAgents();
}
}

// DO NOT AWAIT! (infinite loop)
async function watchSai(): Promise<void> {
const sai = useSai(coreStore.userId);
const stream = await sai.getStream();
if (stream.locked) return;
const reader = stream.getReader();
// eslint-disable-next-line no-constant-condition
while (true) {
// eslint-disable-next-line no-await-in-loop
const { done, value } = await reader.read();
if (done) {
break;
Expand All @@ -31,13 +40,6 @@ export const useAppStore = defineStore('app', () => {
}
}

async function loadAgents(force = false): Promise<void> {
if (force || !agents.value.length) {
const sai = useSai(coreStore.userId);
agents.value = await sai.getAgents();
}
}

async function loadProjects(ownerId: string): Promise<void> {
if (registrations.value[ownerId]) return;
const sai = useSai(coreStore.userId);
Expand Down
1 change: 0 additions & 1 deletion examples/vuejectron/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable import/no-extraneous-dependencies */
// Plugins
import vue from '@vitejs/plugin-vue';
import vuetify, { transformAssetUrls } from 'vite-plugin-vuetify';
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"build": "pnpx turbo run build",
"test": "pnpx turbo run test",
"dev": "pnpm --filter '@janeirodigital/sai-server' redis && pnpx turbo run dev",
"watch": "./node_modules/.bin/turbowatch turbowatch.ts"
"watch": "./node_modules/.bin/turbowatch turbowatch.ts",
"lint": "eslint --config .eslintrc.js"
},
"volta": {
"node": "20.7.0"
Expand Down
1 change: 0 additions & 1 deletion packages/api-messages/test/requests-test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { describe, test, expect } from '@jest/globals';
import {
AddSocialAgentRequest,
Expand Down
1 change: 0 additions & 1 deletion packages/api-messages/test/responses-test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { describe, test, expect } from '@jest/globals';
import {
AccessAuthorization,
Expand Down
2 changes: 0 additions & 2 deletions packages/application/test/application-test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { randomUUID } from 'crypto';
// eslint-disable-next-line import/no-extraneous-dependencies
import { jest, describe, test, expect } from '@jest/globals';
// eslint-disable-next-line import/no-extraneous-dependencies
import { statelessFetch } from '@janeirodigital/interop-test-utils';
import { ReadableApplicationRegistration, DataOwner } from '@janeirodigital/interop-data-model';
import { RdfResponse } from '@janeirodigital/interop-utils';
Expand Down
2 changes: 0 additions & 2 deletions packages/authorization-agent/test/authorization-agent-test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { randomUUID } from 'crypto';
// eslint-disable-next-line import/no-extraneous-dependencies
import { jest, describe, test, beforeEach, expect } from '@jest/globals';
// eslint-disable-next-line import/no-extraneous-dependencies
import { statelessFetch, createStatefulFetch } from '@janeirodigital/interop-test-utils';
import {
CRUDRegistrySet,
Expand Down
1 change: 1 addition & 0 deletions packages/data-model/src/resource.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { INTEROP, getAllMatchingQuads, getOneMatchingQuad, RdfFetch } from '@janeirodigital/interop-utils';
import { DatasetCore, NamedNode, Quad, Term } from '@rdfjs/types';
import { DataFactory, Store } from 'n3';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ACL, INTEROP } from '@janeirodigital/interop-utils';
// eslint-disable-next-line import/no-extraneous-dependencies
import { fetch } from '@janeirodigital/interop-test-utils';
import { randomUUID } from 'crypto';
import {
Expand Down
1 change: 0 additions & 1 deletion packages/data-model/test/base-factory-test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { fetch } from '@janeirodigital/interop-test-utils';
import { parseTurtle } from '@janeirodigital/interop-utils';
import { randomUUID } from 'crypto';
Expand Down
3 changes: 0 additions & 3 deletions packages/data-model/test/crud/access-consent-registry-test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import 'jest-rdf';
// eslint-disable-next-line import/no-extraneous-dependencies
import { jest } from '@jest/globals';
// eslint-disable-next-line import/no-extraneous-dependencies
import { fetch } from '@janeirodigital/interop-test-utils';
import { randomUUID } from 'crypto';
import { DataFactory } from 'n3';
Expand Down
2 changes: 0 additions & 2 deletions packages/data-model/test/crud/agent-registration-test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import 'jest-rdf';
// eslint-disable-next-line import/no-extraneous-dependencies
import { fetch } from '@janeirodigital/interop-test-utils';
import { randomUUID } from 'crypto';
import { DataFactory } from 'n3';
Expand Down
2 changes: 0 additions & 2 deletions packages/data-model/test/crud/agent-registry-test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { INTEROP } from '@janeirodigital/interop-utils';
// eslint-disable-next-line import/no-extraneous-dependencies
import { fetch } from '@janeirodigital/interop-test-utils';
import { randomUUID } from 'crypto';
import { DataFactory } from 'n3';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import 'jest-rdf';
import { DataFactory } from 'n3';
// eslint-disable-next-line import/no-extraneous-dependencies
import { fetch } from '@janeirodigital/interop-test-utils';
import { randomUUID } from 'crypto';
import { AuthorizationAgentFactory } from '../../src';
Expand Down
3 changes: 0 additions & 3 deletions packages/data-model/test/crud/container-test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { jest } from '@jest/globals';
// eslint-disable-next-line import/no-extraneous-dependencies
import 'jest-rdf';
import { randomUUID } from 'crypto';
import { DataFactory, Store } from 'n3';
// eslint-disable-next-line import/no-extraneous-dependencies
import { fetch } from '@janeirodigital/interop-test-utils';
import { insertPatch, RdfResponse } from '@janeirodigital/interop-utils';

Expand Down
2 changes: 0 additions & 2 deletions packages/data-model/test/crud/data-registration-test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import 'jest-rdf';
// eslint-disable-next-line import/no-extraneous-dependencies
import { fetch } from '@janeirodigital/interop-test-utils';
import { randomUUID } from 'crypto';
import { DataFactory } from 'n3';
Expand Down
14 changes: 3 additions & 11 deletions packages/data-model/test/crud/data-registry-test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import 'jest-rdf';
// eslint-disable-next-line import/no-extraneous-dependencies
import { jest } from '@jest/globals';
// eslint-disable-next-line import/no-extraneous-dependencies
import { fetch } from '@janeirodigital/interop-test-utils';
import { randomUUID } from 'crypto';
import { DataFactory } from 'n3';
import { INTEROP } from '@janeirodigital/interop-utils';
import {
AuthorizationAgentFactory,
ReadableDataRegistration,
CRUDDataRegistration,
DataRegistrationData
} from '../../src';
import { AuthorizationAgentFactory, ReadableDataRegistration, CRUDDataRegistration } from '../../src';

const webId = 'https://alice.example/#id';
const agentId = 'https://jarvis.alice.example/#agent';
Expand Down Expand Up @@ -53,12 +45,12 @@ describe('createRegistration', () => {
const localFactory = new AuthorizationAgentFactory(webId, agentId, { fetch, randomUUID });
const updateMock = jest.fn();
localFactory.crud.dataRegistration = jest.fn(
() => ({ update: updateMock } as unknown as Promise<CRUDDataRegistration>)
() => ({ update: updateMock }) as unknown as Promise<CRUDDataRegistration>
);

const otherShapeTree = 'https://solidshapes.example/tree/Other';
const dataRegistry = await localFactory.crud.dataRegistry(snippetIri);
const registration = await dataRegistry.createRegistration(otherShapeTree);
await dataRegistry.createRegistration(otherShapeTree);

expect(updateMock).toBeCalled();
});
Expand Down
1 change: 0 additions & 1 deletion packages/data-model/test/crud/registry-set-test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { fetch } from '@janeirodigital/interop-test-utils';
import { randomUUID } from 'crypto';
import { CRUDRegistrySet, AuthorizationAgentFactory, CRUDDataRegistry } from '../../src';
Expand Down
9 changes: 3 additions & 6 deletions packages/data-model/test/crud/resoruce-test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { jest } from '@jest/globals';
// eslint-disable-next-line import/no-extraneous-dependencies
import 'jest-rdf';
// eslint-disable-next-line import/no-extraneous-dependencies
import { fetch } from '@janeirodigital/interop-test-utils';
import { randomUUID } from 'crypto';
import { DataFactory, Store } from 'n3';
Expand All @@ -29,10 +26,10 @@ class CRUDTestResource extends CRUDResource {

public static async build(
iri: string,
factory: ApplicationFactory,
data?: { beep: string }
applicationFactory: ApplicationFactory,
resourceData?: { beep: string }
): Promise<CRUDTestResource> {
const instance = new CRUDTestResource(iri, factory, data);
const instance = new CRUDTestResource(iri, applicationFactory, resourceData);
await instance.bootstrap();
return instance;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { fetch } from '@janeirodigital/interop-test-utils';
import { randomUUID } from 'crypto';
import { AuthorizationAgentFactory } from '../../src';
Expand Down
Loading

0 comments on commit 189fd0b

Please sign in to comment.