0.7.38 • Published 5 years ago

@rxdi/ipfs-package-example v0.7.38

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

Decentralized @Module example for Reactive extension dependency injection (@rxdi) with Inter planetary file system(IPFS)

This module is created to provide example for future ipfs decentralized node modules using pure nodejs In this repository you will find one module from rxdi infrastructure with included service. Reading above you will understand how to create and deploy your own module using ipfs network and rxdi infrastructure

1. Installing dependencies:
npm install
2. Build module:
npm run build

Before we proceed install ipfs npm i ipfs -g and run daemon jsipfs daemon

3. Deploy module:
npm run deploy

This will print something like this

added QmW1vAT4oy8w1iB8YoZMvmHoVF4GUHT1eE7h49UqViWawW index.d.ts
added QmfCbYHggmJ5ZdnTRZ9X56iV6KR1REqxKmbX6GjspamH5w index.js

Add these hashes inside index.json

JSON

{
    "name":"@test",
    "typings": "QmW1vAT4oy8w1iB8YoZMvmHoVF4GUHT1eE7h49UqViWawW",
    "module": "QmfCbYHggmJ5ZdnTRZ9X56iV6KR1REqxKmbX6GjspamH5w",
    "dependencies": [""]
}
4. Deploy configuration for module index.json
npm run deploy-config

This will print our deployed module

added QmWtJLqyokMZE37DgncpY5HhFvtFQieBzMPDQ318aJeTw6 index.json

Install module inside @rxdi infrastructure:

rxdi install QmWtJLqyokMZE37DgncpY5HhFvtFQieBzMPDQ318aJeTw6
4.1 Deploying html file with metadata for module (Optional):

Purpose of this is to put documentation for current module and the same hash can be used to download module

Instead creating index.json file create index.html

When requesting this page rxdi will parse content between <!--meta-rxdi-ipfs-module--> meta tags

<div style="visibility:hidden;z-index:-10000;position:absolute;">
<!--meta-rxdi-ipfs-module-->
{
    "name":"@test",
    "typings": "QmW1vAT4oy8w1iB8YoZMvmHoVF4GUHT1eE7h49UqViWawW",
    "module": "QmfCbYHggmJ5ZdnTRZ9X56iV6KR1REqxKmbX6GjspamH5w",
    "dependencies": [""]
}
<!--meta-rxdi-ipfs-module-->
</div>

Example index.html module: Link

Complete instructions can be found below.

(Optional) Can be installed ParcelJS Bundler globally npm i -g parcel-bundler

Inside this repository devDependencies, parce-bundler is included

Inside gapi-cli.conf.yml there is a command called gapi module build or npm run build

commands:
  testing:
    browser: jest --env jsdom --testPathPattern="/src/.*\\.browser.spec.(ts|tsx|js)$"
    node: jest --env node --testPathPattern="/src/.*\\.spec.(ts|tsx|js)$"
  module:
    build:
      - ./node_modules/.bin/parcel build --target node development/index.ts
      - ./node_modules/.bin/rxdi-merge --name @test --project . --out dist/index.d.ts
      - find . -not -path "./node_modules/*" -type f -iname \*.map -delete
      - cp -r dist/* .
      - ./node_modules/.bin/gapi module clean
    clean:
      - rm -rf dist
      - rm -rf .cache
    deploy:
      - jsipfs add index.js
      - jsipfs add index.d.ts
    deploy-config:
      - jsipfs add index.json

Lets take a closer look command by command

Building

This will take index.ts inside development folder will bundle it to single js file inside dist/index.js with mapping dist/index.map

You should export everything like export * from '' inside this index.ts because parcel needs to know what this module includes. Else you will end up not having all your files bundled.

parcel build --target node development/index.ts

Merging

This command will search for *.ts files from them will generate index.d.ts file representing all your Typescript Module Definitions

You can install this Globally by typing: npm i @rxdi/dts-merge -g

Inside this repository devDependencies @rxdi/dts-merge is included

rxdi-merge --name @test --project . --out dist/index.d.ts

If you want to change exported namespace aka @test just pass different name inside parameter --name @yourName Remember to change index.json file and redeploy your module.

{
    "name":"@yourName",
    "typings": "hash",
    "module": "hash",
    "dependencies": [""]
}

Then use new generated hash to install your module rxdi i hash

Delete unused .map files

This command will search for all *.map files inside your project generated from parcel and will delete it since we don't need them when module is builded for deployment

find . -not -path "./node_modules/*" -type f -iname \*.map -delete

Copy generated bundle

Copy all generated files to root index.js, index.d.ts these two files represent our module

cp -r dist/* .

Clean build

gapi module clean

Deploy to ipfs network

Now we need to deploy our module to ipfs network

1.Create file called index.json

2.Add this content

{
    "name":"@test",
    "typings": "QmW1vAT4oy8w1iB8YoZMvmHoVF4GUHT1eE7h49UqViWawW",
    "module": "QmfCbYHggmJ5ZdnTRZ9X56iV6KR1REqxKmbX6GjspamH5w",
    "dependencies": [""],
}

Where:

name - Module namespace is important and in the end will be used as follow import { TestModule } from '@test' in this case

typings - Hash from ipfs network leading to our generated types index.d.ts

Download folder: 'node_modules/@types/@test

module - Hash from ipfs network leading to our generated module via ParcelJS index.js

Download folder: 'node_modules/@test

dependencies - Every module can have many dependencies from the same type pass hash 'QmeFUenbAy4kxKj6hA4kP662nwm11dGUTG8HZowBuapbFv'

To use typings you need to set typeRoots to "node_modules/@types" inside tsconfig.json

The system will automatically download typings to @types folder

  "typeRoots": [
    "node_modules/@types"
  ]

Example @test module: https://ipfs.io/ipfs/QmWtJLqyokMZE37DgncpY5HhFvtFQieBzMPDQ318aJeTw6

Now you should know what to do! We need to deploy index.js and index.d.ts files from where we will get Hash key

We need ipfs module to deploy our modules or you can deploy them manually with Desktop application provided from

Ipfs Shipyard Desktop https://github.com/ipfs-shipyard/ipfs-desktop

Documentation for ipfs CLI can be found here: https://github.com/ipfs/js-ipfs

npm install ipfs -g

To add our modules to ipfs:

jsipfs add index.js && jsipfs add index.d.ts

This will print something like this

added QmW1vAT4oy8w1iB8YoZMvmHoVF4GUHT1eE7h49UqViWawW index.d.ts
added QmfCbYHggmJ5ZdnTRZ9X56iV6KR1REqxKmbX6GjspamH5w index.js

Lets prepare our configuration inside index.json

{
    "name":"@test",
    "typings": "QmW1vAT4oy8w1iB8YoZMvmHoVF4GUHT1eE7h49UqViWawW",
    "module": "QmfCbYHggmJ5ZdnTRZ9X56iV6KR1REqxKmbX6GjspamH5w"
}

Deploy index.json to ipfs network

jsipfs add index.json

This will print something like this

added QmWtJLqyokMZE37DgncpY5HhFvtFQieBzMPDQ318aJeTw6 index.json

Voila!!!! You are ready!!! now lets install this module inside rxdi infrastructure

Lets take simple server side example

Inside package.json add the following configuration

  "ipfs": [
    {
      "provider": "https://ipfs.io/ipfs/",
      "dependencies": [
        "QmWtJLqyokMZE37DgncpY5HhFvtFQieBzMPDQ318aJeTw6"
      ]
    }
  ],

where:

provider - This is public gateway from where we will download our modules you can try also with your private gateway http://127.0.0.1:8080/ipfs/

dependencies - This Array from hashes represents our modules with hash aka index.json which we deploy to ipfs network

{
    "name":"@test",
    "typings": "QmW1vAT4oy8w1iB8YoZMvmHoVF4GUHT1eE7h49UqViWawW",
    "module": "QmfCbYHggmJ5ZdnTRZ9X56iV6KR1REqxKmbX6GjspamH5w"
}

Now we need to run our rxdi install command:

This will take configuration from package.json > ipfs and will download all modules representing Hashes inside dependencies See real world example: https://ipfs.io/ipfs/QmWtJLqyokMZE37DgncpY5HhFvtFQieBzMPDQ318aJeTw6

Running from local node_modules installation

node ./node_modules/@rxdi/core/bin/root.js install

or

./node_modules/.bin/rxdi install

or Global

npm i -g @rxdi/core

Now you should have rxdi install command globally for all rxdi projects this will read package.json > "ipfs" object

Command will look for package.json inside current working directory where it is executed

Now when we execute:

rxdi install

You should see something like this:

[
  {
    "hash": "QmWtJLqyokMZE37DgncpY5HhFvtFQieBzMPDQ318aJeTw6",
    "provider": "https://ipfs.io/ipfs/"
  }
]
Modules installed!

If you want to install single dependency type:

Short version it will default to https://ipfs.io/ipfs/ provider

rxdi install QmWtJLqyokMZE37DgncpY5HhFvtFQieBzMPDQ318aJeTw6

Long version

rxdi install --hash=QmWtJLqyokMZE37DgncpY5HhFvtFQieBzMPDQ318aJeTw6 --provider=https://ipfs.io/ipfs/
In Action
import { Module, Bootstrap } from '@gapi/core';
import { TestModule, TestService } from '@test';

@Module({
    imports: [
        TestModule
    ]
})
export class AppModule { }

Bootstrap(AppModule)
    .subscribe(
        () => console.log('Started!'),
        (e) => console.error(e)
    );

This is it ! You can Enjoy decentralized rxdi module system! There is a platform which will be created representing all your private and public modules Purpose is when you copy QmWtJLqyokMZE37DgncpY5HhFvtFQieBzMPDQ318aJeTw6 and paste it inside search it should show you the package with README.md and everything like regular repository.

Njoy!

0.7.38

5 years ago

0.7.37

5 years ago

0.7.36

5 years ago

0.7.35

5 years ago

0.7.34

5 years ago

0.7.33

5 years ago

0.7.32

5 years ago

0.7.31

5 years ago

0.7.30

5 years ago

0.7.29

5 years ago

0.7.28

5 years ago

0.7.27

5 years ago

0.7.26

5 years ago

0.7.25

5 years ago

0.7.24

5 years ago

0.7.23

5 years ago

0.7.22

5 years ago

0.7.21

5 years ago

0.7.20

5 years ago

0.7.19

5 years ago

0.7.18

5 years ago

0.7.17

5 years ago

0.7.16

5 years ago

0.7.15

5 years ago

0.7.14

5 years ago

0.7.13

5 years ago

0.7.12

5 years ago

0.7.11

5 years ago

0.7.10

5 years ago

0.7.9

5 years ago

0.7.8

5 years ago

0.7.7

5 years ago

0.7.6

5 years ago

0.7.5

5 years ago

0.7.4

5 years ago

0.7.3

5 years ago

0.7.2

5 years ago

0.7.1

5 years ago

0.7.0

5 years ago

0.6.13

5 years ago

0.6.12

5 years ago

0.6.11

5 years ago

0.6.10

5 years ago

0.6.9

5 years ago

0.6.8

5 years ago

0.6.7

5 years ago

0.6.6

5 years ago

0.6.5

5 years ago

0.6.4

5 years ago

0.6.3

5 years ago

0.6.2

5 years ago

0.6.1

5 years ago

0.6.0

5 years ago

0.5.21

5 years ago

0.5.20

5 years ago

0.5.19

5 years ago

0.5.18

5 years ago

0.5.17

5 years ago

0.5.16

5 years ago

0.5.15

5 years ago

0.5.14

5 years ago

0.5.13

5 years ago

0.5.12

5 years ago

0.5.11

5 years ago

0.5.10

5 years ago

0.5.9

5 years ago

0.5.8

5 years ago

0.5.7

5 years ago

0.5.6

5 years ago

0.5.5

5 years ago

0.5.4

5 years ago

0.5.3

5 years ago

0.5.2

5 years ago

0.5.1

5 years ago

0.5.0

5 years ago

0.4.35

5 years ago

0.4.34

5 years ago

0.4.33

5 years ago

0.4.32

5 years ago

0.4.31

5 years ago

0.4.30

5 years ago

0.4.29

5 years ago

0.4.28

5 years ago

0.4.27

5 years ago

0.4.26

5 years ago

0.4.25

5 years ago

0.4.24

5 years ago

0.4.23

5 years ago

0.4.22

5 years ago

0.4.21

5 years ago

0.4.20

5 years ago

0.4.19

5 years ago

0.4.18

5 years ago

0.4.17

5 years ago

0.4.16

5 years ago

0.4.15

5 years ago

0.4.14

5 years ago

0.4.13

5 years ago

0.4.12

5 years ago

0.4.11

5 years ago

0.4.10

5 years ago

0.4.9

5 years ago

0.4.8

5 years ago

0.4.7

5 years ago

0.4.6

5 years ago

0.4.5

5 years ago

0.4.4

5 years ago

0.4.3

5 years ago

0.4.2

5 years ago

0.4.1

5 years ago

0.4.0

5 years ago

0.3.19

5 years ago

0.3.18

5 years ago

0.3.17

5 years ago

0.3.16

5 years ago

0.3.15

5 years ago

0.3.14

5 years ago

0.3.13

5 years ago

0.3.12

5 years ago

0.3.11

5 years ago

0.3.10

5 years ago

0.3.9

5 years ago

0.3.8

5 years ago

0.3.7

5 years ago

0.3.6

5 years ago

0.3.5

5 years ago

0.3.4

5 years ago

0.3.3

5 years ago

0.3.2

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.36

5 years ago

0.2.35

5 years ago

0.2.34

5 years ago

0.2.33

5 years ago

0.2.32

5 years ago

0.2.31

5 years ago

0.2.30

5 years ago

0.2.29

5 years ago

0.2.28

5 years ago

0.2.27

5 years ago

0.2.26

5 years ago

0.2.25

5 years ago

0.2.24

5 years ago

0.2.23

5 years ago

0.2.22

5 years ago

0.2.21

5 years ago

0.2.20

5 years ago

0.2.19

5 years ago

0.2.18

5 years ago

0.2.17

5 years ago

0.2.16

5 years ago

0.2.15

5 years ago

0.2.14

5 years ago

0.2.13

5 years ago

0.2.12

5 years ago

0.2.11

5 years ago

0.2.10

5 years ago

0.2.9

5 years ago

0.2.8

5 years ago

0.2.7

5 years ago

0.2.6

5 years ago

0.2.5

5 years ago

0.2.4

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.424

5 years ago

0.0.423

5 years ago

0.0.422

5 years ago

0.0.421

5 years ago

0.0.420

5 years ago

0.0.419

5 years ago

0.0.418

5 years ago

0.0.417

5 years ago

0.0.416

5 years ago

0.0.415

5 years ago

0.0.414

5 years ago

0.0.413

5 years ago

0.0.412

5 years ago

0.0.411

5 years ago

0.0.410

5 years ago

0.0.409

5 years ago

0.0.408

5 years ago

0.0.407

5 years ago

0.0.406

5 years ago

0.0.405

5 years ago

0.0.404

5 years ago

0.0.403

5 years ago

0.0.402

5 years ago

0.0.401

5 years ago

0.0.400

5 years ago

0.0.399

5 years ago

0.0.398

5 years ago

0.0.397

5 years ago

0.0.396

5 years ago

0.0.395

5 years ago

0.0.394

5 years ago

0.0.393

5 years ago

0.0.392

5 years ago

0.0.391

5 years ago

0.0.390

5 years ago

0.0.389

5 years ago

0.0.388

5 years ago

0.0.387

5 years ago

0.0.386

5 years ago

0.0.385

5 years ago

0.0.384

5 years ago

0.0.383

5 years ago

0.0.382

5 years ago

0.0.381

5 years ago

0.0.380

5 years ago

0.0.379

5 years ago

0.0.378

5 years ago

0.0.377

5 years ago

0.0.376

5 years ago

0.0.375

5 years ago

0.0.374

5 years ago

0.0.373

5 years ago

0.0.372

5 years ago

0.0.371

5 years ago

0.0.370

5 years ago

0.0.369

5 years ago

0.0.368

5 years ago

0.0.367

5 years ago

0.0.366

5 years ago

0.0.365

5 years ago

0.0.364

5 years ago

0.0.363

5 years ago

0.0.362

5 years ago

0.0.361

5 years ago

0.0.360

5 years ago

0.0.359

5 years ago

0.0.358

5 years ago

0.0.357

5 years ago

0.0.356

5 years ago

0.0.355

5 years ago

0.0.354

5 years ago

0.0.353

5 years ago

0.0.352

5 years ago

0.0.351

5 years ago

0.0.350

5 years ago

0.0.349

5 years ago

0.0.348

5 years ago

0.0.347

5 years ago

0.0.346

5 years ago

0.0.345

5 years ago

0.0.344

5 years ago

0.0.343

5 years ago

0.0.342

5 years ago

0.0.341

6 years ago

0.0.340

6 years ago

0.0.339

6 years ago

0.0.338

6 years ago

0.0.337

6 years ago

0.0.336

6 years ago

0.0.335

6 years ago

0.0.334

6 years ago

0.0.333

6 years ago

0.0.332

6 years ago

0.0.331

6 years ago

0.0.330

6 years ago

0.0.329

6 years ago

0.0.328

6 years ago

0.0.327

6 years ago

0.0.326

6 years ago

0.0.325

6 years ago

0.0.324

6 years ago

0.0.323

6 years ago

0.0.322

6 years ago

0.0.321

6 years ago

0.0.320

6 years ago

0.0.319

6 years ago

0.0.318

6 years ago

0.0.317

6 years ago

0.0.316

6 years ago

0.0.315

6 years ago

0.0.314

6 years ago

0.0.313

6 years ago

0.0.312

6 years ago

0.0.311

6 years ago

0.0.310

6 years ago

0.0.309

6 years ago

0.0.308

6 years ago

0.0.307

6 years ago

0.0.306

6 years ago

0.0.305

6 years ago

0.0.304

6 years ago

0.0.303

6 years ago

0.0.302

6 years ago

0.0.301

6 years ago

0.0.300

6 years ago

0.0.299

6 years ago

0.0.298

6 years ago

0.0.297

6 years ago

0.0.296

6 years ago

0.0.295

6 years ago

0.0.294

6 years ago

0.0.293

6 years ago

0.0.292

6 years ago

0.0.291

6 years ago

0.0.290

6 years ago

0.0.289

6 years ago

0.0.288

6 years ago

0.0.287

6 years ago

0.0.286

6 years ago

0.0.285

6 years ago

0.0.284

6 years ago

0.0.283

6 years ago

0.0.282

6 years ago

0.0.281

6 years ago

0.0.280

6 years ago

0.0.279

6 years ago

0.0.278

6 years ago

0.0.277

6 years ago

0.0.276

6 years ago

0.0.275

6 years ago

0.0.274

6 years ago

0.0.273

6 years ago

0.0.272

6 years ago

0.0.271

6 years ago

0.0.270

6 years ago

0.0.269

6 years ago

0.0.268

6 years ago

0.0.267

6 years ago

0.0.266

6 years ago

0.0.265

6 years ago

0.0.264

6 years ago

0.0.263

6 years ago

0.0.262

6 years ago

0.0.261

6 years ago

0.0.260

6 years ago

0.0.259

6 years ago

0.0.258

6 years ago

0.0.257

6 years ago

0.0.256

6 years ago

0.0.255

6 years ago

0.0.254

6 years ago

0.0.253

6 years ago

0.0.252

6 years ago

0.0.251

6 years ago

0.0.250

6 years ago

0.0.249

6 years ago

0.0.248

6 years ago

0.0.247

6 years ago

0.0.246

6 years ago

0.0.245

6 years ago

0.0.244

6 years ago

0.0.243

6 years ago

0.0.242

6 years ago

0.0.241

6 years ago

0.0.240

6 years ago

0.0.239

6 years ago

0.0.238

6 years ago

0.0.237

6 years ago

0.0.236

6 years ago

0.0.235

6 years ago

0.0.234

6 years ago

0.0.233

6 years ago

0.0.232

6 years ago

0.0.231

6 years ago

0.0.230

6 years ago

0.0.229

6 years ago

0.0.228

6 years ago

0.0.227

6 years ago

0.0.226

6 years ago

0.0.225

6 years ago

0.0.224

6 years ago

0.0.223

6 years ago

0.0.222

6 years ago

0.0.221

6 years ago

0.0.220

6 years ago

0.0.219

6 years ago

0.0.218

6 years ago

0.0.217

6 years ago

0.0.216

6 years ago

0.0.215

6 years ago

0.0.214

6 years ago

0.0.213

6 years ago

0.0.212

6 years ago

0.0.211

6 years ago

0.0.210

6 years ago

0.0.209

6 years ago

0.0.208

6 years ago

0.0.207

6 years ago

0.0.206

6 years ago

0.0.205

6 years ago

0.0.204

6 years ago

0.0.200

6 years ago

0.0.198

6 years ago

0.0.196

6 years ago

0.0.194

6 years ago

0.0.192

6 years ago

0.0.190

6 years ago

0.0.188

6 years ago

0.0.187

6 years ago

0.0.186

6 years ago

0.0.185

6 years ago

0.0.184

6 years ago

0.0.183

6 years ago

0.0.182

6 years ago

0.0.181

6 years ago