Skip to content

Commit

Permalink
Fix: linting
Browse files Browse the repository at this point in the history
  • Loading branch information
flipsimon committed Oct 19, 2023
1 parent 1a3a6cc commit 8b44677
Show file tree
Hide file tree
Showing 28 changed files with 116 additions and 83 deletions.
2 changes: 1 addition & 1 deletion packages/repco-cli/src/commands/ds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const add = createCommand({
},
async run(opts, args) {
const repo = await Repo.openWithDefaults(opts.repo)
const prisma = repo.prisma
// const prisma = repo.prisma
const config = JSON.parse(args.config)
const instance = await repo.dsr.create(
repo.prisma,
Expand Down
8 changes: 5 additions & 3 deletions packages/repco-core/src/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ export abstract class BaseDataSource implements DataSource {

type FailedHydrates = { err: Error; row: any }

function errToSerializable(err: Error): Prisma.InputJsonValue {
return Object.fromEntries(Object.entries(err))
}
// function errToSerializable(err: Error): Prisma.InputJsonValue {
// return Object.fromEntries(Object.entries(err))
// }

export class DataSourceRegistry extends Registry<DataSource> {
_hydrating?: Promise<{ failed: FailedHydrates[] }>
Expand All @@ -151,6 +151,8 @@ export class DataSourceRegistry extends Registry<DataSource> {

for (const [uid, uris] of Object.entries(buckets)) {
const filteredUris = uris.filter((uri) => !found.has(uri))
// checked above
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const ds = this.get(uid)!
const sourceRecords = await ds.fetchByUriBatch(filteredUris)
const entities = await mapAndPersistSourceRecord(repo, ds, sourceRecords)
Expand Down
9 changes: 5 additions & 4 deletions packages/repco-core/src/datasources/activitypub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,15 @@ export class ActivityPubDataSource
}
// iterate over items on page backwards to find items that are newer than the cursor
for (let i = items.length - 1; i >= 0; i--) {
if (items[i] === undefined) {
const item = items[i]
if (item === undefined) {
continue
}
if (new Date(items[i]!.published) <= cursor.lastPublishedDate) {
if (new Date(item.published) <= cursor.lastPublishedDate) {
continue
}
newVideoObjects.push(items[i]!)
cursor.lastPublishedDate = new Date(items[i]!.published)
newVideoObjects.push(item)
cursor.lastPublishedDate = new Date(item.published)
}
}
const records = [
Expand Down
6 changes: 3 additions & 3 deletions packages/repco-core/src/datasources/cba.ts
Original file line number Diff line number Diff line change
Expand Up @@ -739,9 +739,9 @@ export class CbaDataSource implements DataSource {

/**
* Parse a datetime string without timezone information as a UTC date
*
*
* @param dateString Datetime string in format 1998-10-17T00:00:00
*/
function parseAsUTC(dateString: string): Date {
function parseAsUTC(dateString: string): Date {
return new Date(dateString + '.000Z')
}
}
2 changes: 1 addition & 1 deletion packages/repco-core/src/datasources/defaults.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ActivityPubDataSourcePlugin } from './activitypub.js'
import { CbaDataSourcePlugin } from './cba.js'
import { RssDataSourcePlugin } from './rss.js'
import { XrcbDataSourcePlugin } from './xrcb.js'
import { DataSourcePluginRegistry } from '../plugins.js'
import { ActivityPubDataSourcePlugin } from './activitypub.js'

export const plugins = new DataSourcePluginRegistry()

Expand Down
40 changes: 20 additions & 20 deletions packages/repco-core/src/datasources/rss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,26 +214,26 @@ export class RssDataSource extends BaseDataSource implements DataSource {
}

// TODO: Implement
async _crawlBackwardsFrom(cursor: Cursor) {
// const lastLeastRecentPubDate = cursor.newest.leastRecentPubDate || new Date()
// const maxPageNumber = cursor.newest.maxPageNumber || 0
// // TODO: Make configurable
// const pagination = {
// offsetParam: 'start',
// limitParam: 'anzahl',
// limit: 5,
// }
// const url = new URL(this.endpoint)
// const page = maxPageNumber + 1
// url.searchParams.set(pagination.limitParam, pagination.limit.toString())
// url.searchParams.set(
// pagination.offsetParam,
// (page * pagination.limit).toString(),
// )
// const { feed, entities } = await this.fetchPage(url)
// const [newestPubDate, oldestPubDate] = getDateRangeFromFeed(feed)
// const nextCursor = { ...cursor }
}
// async _crawlBackwardsFrom(cursor: Cursor) {
// const lastLeastRecentPubDate = cursor.newest.leastRecentPubDate || new Date()
// const maxPageNumber = cursor.newest.maxPageNumber || 0
// // TODO: Make configurable
// const pagination = {
// offsetParam: 'start',
// limitParam: 'anzahl',
// limit: 5,
// }
// const url = new URL(this.endpoint)
// const page = maxPageNumber + 1
// url.searchParams.set(pagination.limitParam, pagination.limit.toString())
// url.searchParams.set(
// pagination.offsetParam,
// (page * pagination.limit).toString(),
// )
// const { feed, entities } = await this.fetchPage(url)
// const [newestPubDate, oldestPubDate] = getDateRangeFromFeed(feed)
// const nextCursor = { ...cursor }
// }

async fetchPage(url: URL): Promise<string> {
// console.log('FETCH', url.toString())
Expand Down
2 changes: 1 addition & 1 deletion packages/repco-core/src/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import z from 'zod'
import { RevisionHeaders, revisionHeaders } from 'repco-common/schema'
import { revisionHeaders } from 'repco-common/schema'
import { repco } from 'repco-prisma'
import {
ConceptKind,
Expand Down
11 changes: 8 additions & 3 deletions packages/repco-core/src/repo.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as ucans from '@ucans/ucans'
import * as common from 'repco-common/zod'
import { CID } from 'multiformats/cid.js'
import { EventEmitter } from 'node:events'
import { createLogger, Logger } from 'repco-common'
import {
CommitBundle,
Expand Down Expand Up @@ -53,7 +54,6 @@ import { ParseError } from './util/error.js'
import { createEntityId } from './util/id.js'
import { notEmpty } from './util/misc.js'
import { Mutex } from './util/mutex.js'
import { EventEmitter } from 'node:events'

// export * from './repo/types.js'

Expand Down Expand Up @@ -445,7 +445,10 @@ export class Repo extends EventEmitter {
return importRepoFromCar(this, stream, onProgress)
}

async saveBatch(inputs: UnknownEntityInput[], opts: Partial<SaveBatchOpts> = {}) {
async saveBatch(
inputs: UnknownEntityInput[],
opts: Partial<SaveBatchOpts> = {},
) {
if (!this.writeable) throw new Error('Repo is not writeable')
const fullOpts: SaveBatchOpts = { ...SAVE_BATCH_DEFAULTS, ...opts }

Expand Down Expand Up @@ -779,7 +782,9 @@ function parseEntity(input: UnknownEntityInput): EntityFormWithHeaders {
}
}

export function parseEntities(inputs: UnknownEntityInput[]): EntityFormWithHeaders[] {
export function parseEntities(
inputs: UnknownEntityInput[],
): EntityFormWithHeaders[] {
return inputs.map(parseEntity)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/repco-core/src/repo/blockstore.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as Block from 'multiformats/block'
import * as uint8arrays from 'uint8arrays'
import * as codec from './codec.js'
import { blake3 as hasher } from './hash.js'
import { Level } from 'level'
import { CID } from 'multiformats/cid'
import { Prisma } from 'repco-prisma'
import { blake3 as hasher } from './hash.js'

export async function createCID(value: Uint8Array): Promise<CID> {
const block = await Block.encode({ value, hasher, codec })
Expand Down
17 changes: 14 additions & 3 deletions packages/repco-core/src/repo/codec-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ function preEncode(value: any): Ipld {

if (value instanceof Date) return value.toISOString()
if (value instanceof CID) return { '/': value.toString() }
if (value instanceof Uint8Array || value instanceof Buffer) return { '/': { bytes: uint8arrays.toString(value, 'base64') }}
if (value instanceof Uint8Array || value instanceof Buffer)
return { '/': { bytes: uint8arrays.toString(value, 'base64') } }
if (value === undefined || value === null) return null

if (value instanceof Set) value = Array.from(value).sort()
Expand Down Expand Up @@ -90,10 +91,20 @@ function postDecode(value: any): any {
}
return value
}
if (typeof value === 'object' && Object.keys(value).length === 1 && typeof value['/'] === 'string') {
if (
typeof value === 'object' &&
Object.keys(value).length === 1 &&
typeof value['/'] === 'string'
) {
return CID.parse(value['/'])
}
if (typeof value === 'object' && Object.keys(value).length === 1 && typeof value['/'] === 'object' && Object.keys(value['/']).length === 1 && typeof value['/']['bytes'] === 'string') {
if (
typeof value === 'object' &&
Object.keys(value).length === 1 &&
typeof value['/'] === 'object' &&
Object.keys(value['/']).length === 1 &&
typeof value['/']['bytes'] === 'string'
) {
return uint8arrays.fromString(value['/']['bytes'], 'base64')
}
if (value instanceof CID) return value
Expand Down
2 changes: 1 addition & 1 deletion packages/repco-core/src/repo/export.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { CarWriter } from '@ipld/car'
import { Block, BlockWriter } from '@ipld/car/api.js'
import { CID } from 'multiformats/cid'
import { CommitIpld, RootIpld } from 'repco-common/schema'
import { Prisma } from 'repco-prisma'
import { IpldBlockStore } from './blockstore.js'
import { CommitIpld, RootIpld } from 'repco-common/schema'
import { Repo } from '../repo.js'

export async function exportRepoToCar(
Expand Down
11 changes: 9 additions & 2 deletions packages/repco-core/src/repo/graph.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { DequeSet } from '../util/collections.js'

export class GGraphError extends Error {
constructor(public id: string, public edge: string, public path: string[] | undefined, msg: string) {
constructor(
public id: string,
public edge: string,
public path: string[] | undefined,
msg: string,
) {
super(msg)
}
}
Expand All @@ -26,7 +31,9 @@ export class GGraph {
id,
edge,
path,
`Recursion: ${id}->${edge} is invalid because of ${path?.join('->')}`,
`Recursion: ${id}->${edge} is invalid because of ${path?.join(
'->',
)}`,
)
throw error
}
Expand Down
14 changes: 7 additions & 7 deletions packages/repco-core/src/repo/import.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import { CarBlockIterator } from '@ipld/car'
import { Block } from '@ipld/car/api.js'
import { CID } from 'multiformats/cid.js'
import { verifyRoot } from './auth.js'
import {
BlockT,
parseBytesWith,
parseToIpld,
validateCID,
} from './blockstore.js'
import {
CommitBundle,
CommitIpld,
Expand All @@ -17,6 +10,13 @@ import {
RootIpld,
rootIpld,
} from 'repco-common/schema'
import { verifyRoot } from './auth.js'
import {
BlockT,
parseBytesWith,
parseToIpld,
validateCID,
} from './blockstore.js'
import { Repo } from '../repo.js'

export type OnProgressCallback = (progress: ImportProgress) => void
Expand Down
2 changes: 1 addition & 1 deletion packages/repco-core/src/repo/ipld-repo.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as ucans from '@ucans/ucans'
import * as common from 'repco-common/zod'
import { CID } from 'multiformats/cid'
import { IpldBlockStore } from './blockstore.js'
import {
CommitBundle,
CommitForm,
Expand All @@ -11,6 +10,7 @@ import {
revisionIpld,
rootIpld,
} from 'repco-common/schema'
import { IpldBlockStore } from './blockstore.js'
import { EntityInputWithHeaders } from '../entity.js'
import { SaveBatchOpts } from '../repo'
import { createEntityId, createRevisionId } from '../util/id.js'
Expand Down
27 changes: 16 additions & 11 deletions packages/repco-core/test/activitypub.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import test from 'brittle'
import fs from 'fs/promises'
import p from 'path'
import { fileURLToPath } from 'node:url'
import { assertFixture, mockFetch } from './util/fetch.js'
import { setup } from './util/setup.js'
Expand All @@ -9,11 +7,13 @@ import { ingestUpdatesFromDataSources } from '../src/datasource.js'
import { ActivityPubDataSourcePlugin } from '../src/datasources/activitypub.js'
import { DataSourcePluginRegistry } from '../src/plugins.js'


// Path to fixtures. Resolves to repco-core/test/fixtures/datasource-activitypub/$name
const fixturePath = (name: string) =>
fileURLToPath(
new URL(`../../test/fixtures/datasource-activitypub/${name}`, import.meta.url),
new URL(
`../../test/fixtures/datasource-activitypub/${name}`,
import.meta.url,
),
)

test('peertube datasource - basic1', async (assert) => {
Expand All @@ -23,13 +23,18 @@ test('peertube datasource - basic1', async (assert) => {
const plugins = new DataSourcePluginRegistry()
const activityPubPlugin = new ActivityPubDataSourcePlugin()
plugins.register(activityPubPlugin)
await repo.dsr.create(repo.prisma, plugins, activityPubPlugin.definition.uid, {
// user: 'blender_channel',
// domain: 'video.blender.org'
user: 'cryptix_channel',
// user: 'mirsal',
domain: 'peertube.1312.media'
})
await repo.dsr.create(
repo.prisma,
plugins,
activityPubPlugin.definition.uid,
{
// user: 'blender_channel',
// domain: 'video.blender.org'
user: 'cryptix_channel',
// user: 'mirsal',
domain: 'peertube.1312.media',
},
)
await ingestUpdatesFromDataSources(repo)
// TODO: Provide mocking capability to uids
const entities = await prisma.contentItem.findMany({
Expand Down
4 changes: 1 addition & 3 deletions packages/repco-core/test/cba.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import test from 'brittle'
import fs from 'fs/promises'
import p from 'path'
import { fileURLToPath } from 'node:url'
import { assertFixture, mockFetch } from './util/fetch.js'
import { setup } from './util/setup.js'
Expand All @@ -24,7 +22,7 @@ test('cba datasource - basic1', async (assert) => {
plugins.register(cbaPlugin)
await repo.dsr.create(repo.prisma, plugins, cbaPlugin.definition.uid, {
pageLimit: 2,
apiKey: null
apiKey: null,
})
await ingestUpdatesFromDataSources(repo)
// TODO: Provide mocking capability to uids
Expand Down
4 changes: 2 additions & 2 deletions packages/repco-core/test/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ const intoSourceRecord = (body: EntityForm): SourceRecordForm => ({

const DS_UID = 'urn:repco:datasource:test'

const fromSourceRecord = (record: SourceRecordForm) =>
JSON.parse(record.body) as EntityForm
// const fromSourceRecord = (record: SourceRecordForm) =>
// JSON.parse(record.body) as EntityForm

class TestDataSourcePlugin implements DataSourcePlugin {
createInstance(_config: any) {
Expand Down
4 changes: 2 additions & 2 deletions packages/repco-core/test/util/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs/promises'
import { Test } from 'brittle'
import p from 'path'
import { Test } from 'brittle'
import { readdirSync, unlinkSync } from 'fs'
import { getGlobalDispatcher, setGlobalDispatcher } from 'undici'
import { CachingDispatcher, FsCacheStorage } from '../../src/util/fetch.js'
Expand All @@ -17,7 +17,7 @@ export function mockFetch(test: Test, path: string) {
if (CREATE_FIXTURES) {
try {
for (const file of readdirSync(path)) {
unlinkSync(p.join(path, file))
unlinkSync(p.join(path, file))
}
} catch (err) {}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/repco-frontend/app/components/player/player.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ function Timeslider({
max={100}
type="range"
aria-label="progress"
value={pos * 100}
value={value}
onDragStart={onChangeStart}
onDragEnd={(e) => onChangeEnd(Number(e.currentTarget.value))}
onChange={(e) => {
Expand Down
Loading

0 comments on commit 8b44677

Please sign in to comment.