Skip to content

Commit

Permalink
Merge pull request #4 from viapip/master
Browse files Browse the repository at this point in the history
added packages
  • Loading branch information
semyenov authored Jul 1, 2024
2 parents 4be60e8 + 0cf6508 commit 362d243
Show file tree
Hide file tree
Showing 1,683 changed files with 44,769 additions and 4,560 deletions.
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/backend.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions apps/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,17 @@
"release": "yarn npm publish",
"clean": "yarn exec rm -rf dist",
"lint": "yarn eslint --config eslint.config.js",
"server": "yarn tsx --watch src/server",
"dev": "yarn tsx --watch src",
"client": "yarn tsx --watch src/client",
"workers": "yarn tsx --watch src/workers",
"generate:types": "yarn tsx scripts/generate_types.ts",
"generate:keys": "yarn tsx scripts/generate_keys.ts"
},
"dependencies": {
"@antfu/utils": "^0.7.10",
"@chainsafe/libp2p-gossipsub": "^13.1.0",
"@msgpack/msgpack": "^3.0.0-beta2",
"@orbitdb/core": "^2.2.0",
"@regioni/build": "workspace:^",
"@trpc/client": "^10.45.2",
"@trpc/server": "^10.45.2",
Expand All @@ -61,6 +63,7 @@
"ajv-formats": "^3.0.1",
"ajv-i18n": "^4.2.0",
"ajv-keywords": "^5.1.0",
"blockstore-level": "^1.1.8",
"bullmq": "^5.8.2",
"c12": "^1.11.1",
"chalk": "^5.3.0",
Expand All @@ -70,7 +73,9 @@
"dotenv": "^16.4.5",
"fast-glob": "^3.3.2",
"h3": "^1.12.0",
"helia": "^4.2.4",
"jose": "^5.6.2",
"libp2p": "^1.7.0",
"listhen": "^1.7.2",
"mongodb": "^6.8.0",
"nanoid": "^5.0.7",
Expand All @@ -79,12 +84,15 @@
"superjson": "^2.2.1",
"ts-pattern": "^5.1.0",
"unstorage": "^1.10.2",
"winston": "^3.13.0",
"ws": "^8.16.0",
"zod": "^3.22.4"
},
"devDependencies": {
"@regioni/lib": "workspace:^",
"@types/orbitdb__core": "workspace:^",
"esbuild": "^0.21.5",
"rollup": "^4.14.0"
"rollup": "^4.14.0",
"tsx": "^4.7.2"
}
}
4 changes: 3 additions & 1 deletion apps/backend/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export async function createContext(
_opts: CreateContextOptions,
) {
const ajv = await createAjv()
const redis = await createRedisStore()
const redis = await createRedisStore({
url: 'redis://redis:6379',
})

return {
ajv,
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { router } from './router'
import type { Router } from './router'

const logger = consola.withTag('server')

export const app = createHTTPServer({
router,
createContext,
Expand Down Expand Up @@ -37,3 +36,4 @@ applyWSSHandler<Router>({
})

app.listen(4000)
logger.info('Listening on 4000')
55 changes: 55 additions & 0 deletions apps/backend/src/orbitdb/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { gossipsub } from '@chainsafe/libp2p-gossipsub'
import { noise } from '@chainsafe/libp2p-noise'
import { yamux } from '@chainsafe/libp2p-yamux'
import { circuitRelayTransport } from '@libp2p/circuit-relay-v2'
import { identify } from '@libp2p/identify'
import { mdns } from '@libp2p/mdns'
import { tcp } from '@libp2p/tcp'
import { webRTC } from '@libp2p/webrtc'
import { webSockets } from '@libp2p/websockets'
import { all } from '@libp2p/websockets/filters'

import type { Libp2pOptions } from 'libp2p'

export const DefaultLibp2pOptions: Libp2pOptions = {
addresses: {
listen: ['/ip4/127.0.0.1/tcp/0/ws'],
},
peerDiscovery: [mdns()],
transports: [
tcp(),
webRTC(),
webSockets({ filter: all }),
circuitRelayTransport({ discoverRelays: 1 }),
],
connectionEncryption: [noise()],
streamMuxers: [yamux()],
connectionGater: {
denyDialMultiaddr: () => false,
},
services: {
identify: identify(),
pubsub: gossipsub({ allowPublishToZeroTopicPeers: true }),
},
}

export const DefaultLibp2pBrowserOptions: Libp2pOptions = {
addresses: {
listen: ['/webrtc'],
},
transports: [
tcp(),
webRTC(),
webSockets({ filter: all }),
circuitRelayTransport({ discoverRelays: 1 }),
],
connectionEncryption: [noise()],
streamMuxers: [yamux()],
connectionGater: {
denyDialMultiaddr: () => false,
},
services: {
identify: identify(),
pubsub: gossipsub({ allowPublishToZeroTopicPeers: true }),
},
}
Empty file.
54 changes: 54 additions & 0 deletions apps/backend/src/orbitdb/keystore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { bitswap } from '@helia/block-brokers'
import { Identities, KeyStore, OrbitDBAccessController, PublicKeyIdentityProvider, createOrbitDB } from '@orbitdb/core'
import { createHelia } from 'helia'
import { createLibp2p } from 'libp2p'

import { DefaultLibp2pOptions } from './config'
import initLogger from '@regioni/lib/logger'

const id = 'userA'
const keysPath = './.out/keys'
const options = DefaultLibp2pOptions

const logger = initLogger()

const ipfs = await createHelia({
libp2p: await createLibp2p({ ...options }),
// blockstore: new LevelBlockstore(levelPath),
blockBrokers: [bitswap()],
})

await ipfs.start()

const keystore = await KeyStore({ path: keysPath })
const identities = await Identities({ keystore, ipfs })
const provider = PublicKeyIdentityProvider({ keystore })

const identity = await identities.createIdentity({ id, provider })
const result = await identities.getIdentity(identity.hash)

logger.log('result', result)
logger.log('address', ipfs.libp2p.peerId)

const orbit = await createOrbitDB({
id: 'orbitdb-AAA',
ipfs,
identities,
identity,
directory: './.out/orbitdb',
})

const db = await orbit.open('test', {
type: 'events',
AccessController: OrbitDBAccessController({
write: [identity.id],
}),
})

for (let i = 0; i < 10; i++) {
await db.add({ message: `Hello, world! ${i}` })
}

logger.log('db', db.address)

// await ipfs.stop()
52 changes: 52 additions & 0 deletions apps/backend/src/orbitdb/orbit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { bitswap } from '@helia/block-brokers'
import {
createOrbitDB,
} from '@orbitdb/core'
import { LevelBlockstore } from 'blockstore-level'
import { createHelia } from 'helia'
import { createLibp2p } from 'libp2p'

import { DefaultLibp2pBrowserOptions, DefaultLibp2pOptions } from './config'
import initLogger from '@regioni/lib/logger'

import type {
CreateOrbitDBOptions,
OrbitDBInstance,
} from '@orbitdb/core'

const logger = initLogger()

let spied: any

const isBrowser = () => typeof window !== 'undefined'
export async function startOrbitDB({
id,
identity,
identities,
directory = '.',
}: Omit<CreateOrbitDBOptions, 'ipfs'>) {
const options = isBrowser()
? DefaultLibp2pBrowserOptions
: DefaultLibp2pOptions

const ipfs = await createHelia({
libp2p: await createLibp2p({ ...options }),
blockstore: new LevelBlockstore(`${directory}/ipfs/blocks`),
blockBrokers: [bitswap()],
})

return createOrbitDB({
id,
identity,
identities,
directory,
ipfs,
})
}

export async function stopOrbitDB(orbitdb: OrbitDBInstance): Promise<void> {
await orbitdb.stop()
await orbitdb.ipfs.stop()

logger.debug('orbitdb stopped', spied.calls, spied.returns)
}
1 change: 1 addition & 0 deletions apps/frontend/.nuxtignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/*.test.*
2 changes: 2 additions & 0 deletions apps/frontend/.nuxtrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
telemetry.enabled=false
telemetry.consent=1
67 changes: 67 additions & 0 deletions apps/frontend/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"recommendations": [
"aaron-bond.better-comments",
"alefragnani.bookmarks",
"aliariff.auto-add-brackets",
"antfu.auto-npx",
"antfu.file-nesting",
"antfu.goto-alias",
"antfu.iconify",
"antfu.vite",
"antfu.where-am-i",
"arcanis.vscode-zipfs",
"bibhasdn.unique-lines",
"bierner.markdown-yaml-preamble",
"bmalehorn.print-it",
"bradlc.vscode-tailwindcss",
"Cardinal90.multi-cursor-case-preserve",
"christian-kohler.npm-intellisense",
"christian-kohler.path-intellisense",
"Codeium.codeium",
"cpylua.language-postcss",
"dbaeumer.vscode-eslint",
"eamodio.gitlens",
"editorconfig.editorconfig",
"esbenp.prettier-vscode",
"formulahendry.auto-rename-tag",
"foxundermoon.shell-format",
"helixquar.randomeverything",
"heybourn.headwind",
"howardzuo.vscode-npm-dependency",
"IBM.output-colorizer",
"kisstkondoros.vscode-codemetrics",
"lacroixdavid1.vscode-format-context-menu",
"lokalise.i18n-ally",
"maciejdems.add-to-gitignore",
"MatthewNespor.vscode-color-identifiers-mode",
"Med-H.color-me",
"mflo999.lintel",
"mhutchie.git-graph",
"micnil.vscode-checkpoints",
"mikestead.dotenv",
"mkxml.vscode-filesize",
"ms-vscode.vscode-js-profile-flame",
"Nuxt.mdc",
"oderwat.indent-rainbow",
"phind.phind",
"piotrpalarz.vscode-gitignore-generator",
"quicktype.quicktype",
"solomonkinard.git-search",
"stackbreak.comment-divider",
"stivo.tailwind-fold",
"stylelint.vscode-stylelint",
"tombonnike.vscode-status-bar-format-toggle",
"Tyriar.sort-lines",
"usernamehw.errorlens",
"VisualStudioExptTeam.vscodeintellicode",
"vivaxy.vscode-conventional-commits",
"vue.volar",
"wejectchan.vue3-snippets-for-vscode",
"wmaurer.change-case",
"yatki.vscode-surround",
"yoavbls.pretty-ts-errors",
"Yseop.vscode-yseopml",
"zardoy.ts-essential-plugins"
],
"unwantedRecommendations": ["vscode.typescript-language-features"]
}
Loading

0 comments on commit 362d243

Please sign in to comment.