1 |
|
2 |
|
3 | const Server = require('./endpoint/server')
|
4 | const Factory = require('./factory')
|
5 |
|
6 | /** @typedef {import("./ipfsd-daemon")} Controller */
|
7 |
|
8 | /**
|
9 | * Creates a factory
|
10 | *
|
11 | * @param {ControllerOptions} options
|
12 | * @param {ControllerOptionsOverrides} overrides
|
13 | * @returns {Factory}
|
14 | */
|
15 | const createFactory = (options, overrides) => {
|
16 | return new Factory(options, overrides)
|
17 | }
|
18 |
|
19 | /**
|
20 | * Creates a node
|
21 | *
|
22 | * @param {ControllerOptions} [options]
|
23 | * @returns {Promise<Controller>}
|
24 | */
|
25 | const createController = (options) => {
|
26 | const f = new Factory()
|
27 | return f.spawn(options)
|
28 | }
|
29 |
|
30 | /**
|
31 | * Create a Endpoint Server
|
32 | *
|
33 | * @param {(Object|number)} options - Configuration options or just the port.
|
34 | * @param {number} options.port - Port to start the server on.
|
35 | * @param {ControllerOptions} factoryOptions
|
36 | * @param {ControllerOptionsOverrides} factoryOverrides
|
37 | * @returns {Server}
|
38 | */
|
39 | const createServer = (options, factoryOptions = {}, factoryOverrides = {}) => {
|
40 | if (typeof options === 'number') {
|
41 | options = { port: options }
|
42 | }
|
43 |
|
44 | return new Server(options, () => {
|
45 | return createFactory(factoryOptions, factoryOverrides)
|
46 | })
|
47 | }
|
48 |
|
49 | module.exports = {
|
50 | createFactory,
|
51 | createController,
|
52 | createServer
|
53 | }
|
54 |
|
55 | /**
|
56 | * Same as https://github.com/ipfs/js-ipfs/blob/master/README.md#ipfs-constructor
|
57 | * @typedef {Object} IpfsOptions
|
58 | * @property {string|Object} [repo] - The file path at which to store the IPFS node’s data. Alternatively, you can set up a customized storage system by providing an ipfs.Repo instance.
|
59 | * @property {boolean|Object} [init=true] - Initialize the repo when creating the IPFS node. Instead of a boolean, you may provide an object with custom initialization options. https://github.com/ipfs/js-ipfs/blob/master/README.md#optionsinit
|
60 | * @property {boolean} [start=true] - If false, do not automatically start the IPFS node. Instead, you’ll need to manually call node.start() yourself.
|
61 | * @property {string} [pass=null] - A passphrase to encrypt/decrypt your keys.
|
62 | * @property {boolean} [silent=false] - Prevents all logging output from the IPFS node.
|
63 | * @property {object} [relay] - Configure circuit relay. https://github.com/ipfs/js-ipfs/blob/master/README.md#optionsrelay Default: `{ enabled: true, hop: { enabled: false, active: false } }`
|
64 | * @property {object} [preload] - Configure remote preload nodes. The remote will preload content added on this node, and also attempt to preload objects requested by this node. https://github.com/ipfs/js-ipfs/blob/master/README.md#optionspreload Default: `{ enabled: true, addresses: [...]`
|
65 | * @property {object} [EXPERIMENTAL] - Enable and configure experimental features. https://github.com/ipfs/js-ipfs/blob/master/README.md#optionsexperimental Default: `{ ipnsPubsub: false, sharding: false }`
|
66 | * @property {object} [config] - Modify the default IPFS node config. This object will be merged with the default config; it will not replace it. The default config is documented in the js-ipfs config file docs. https://github.com/ipfs/js-ipfs/blob/master/README.md#optionsconfig
|
67 | * @property {object} [ipld] - Modify the default IPLD config. This object will be merged with the default config; it will not replace it. Check IPLD docs for more information on the available options. https://github.com/ipfs/js-ipfs/blob/master/README.md#optionsipld
|
68 | * @property {object|function} [libp2p] - The libp2p option allows you to build your libp2p node by configuration, or via a bundle function. https://github.com/ipfs/js-ipfs/blob/master/README.md#optionslibp2p
|
69 | * @property {object} [connectionManager] - Configure the libp2p connection manager. https://github.com/ipfs/js-ipfs/blob/master/README.md#optionsconnectionmanager
|
70 | * @property {boolean} [offline=false] - Run the node offline.
|
71 | */
|
72 |
|
73 | /**
|
74 | * @typedef {Object} ControllerOptions
|
75 | * @property {boolean} [test=false] - Flag to activate custom config for tests.
|
76 | * @property {boolean} [remote] - Use remote endpoint to spawn the controllers. Defaults to `true` when not in node.
|
77 | * @property {string} [endpoint] - Endpoint URL to manage remote Controllers. (Defaults: 'http://localhost:43134').
|
78 | * @property {Boolean} [disposable=true] - A new repo is created and initialized for each invocation, as well as cleaned up automatically once the process exits.
|
79 | * @property {string} [type] - The daemon type, see below the options:
|
80 | * - go - spawn go-ipfs daemon node
|
81 | * - js - spawn js-ipfs daemon node
|
82 | * - proc - spawn in-process js-ipfs node
|
83 | * @property {Object} [env] - Additional environment variables, passed to executing shell. Only applies for Daemon controllers.
|
84 | * @property {Array} [args] - Custom cli args.
|
85 | * @property {Object} [ipfsHttpModule] - Reference to a IPFS HTTP Client object. (defaults to the local require(`ipfs-http-client`))
|
86 | * @property {Object} [ipfsModule] - Reference to a IPFS API object. (defaults to the local require(`ipfs`))
|
87 | * @property {String} [ipfsBin] - Path to a IPFS exectutable
|
88 | * @property {IpfsOptions} [ipfsOptions] - Options for the IPFS node.
|
89 | * @property {boolean} [forceKill] - Whether to use SIGKILL to quit a daemon that does not stop after `.stop()` is called. (default true)
|
90 | * @property {Number} [forceKillTimeout] - How long to wait before force killing a daemon in ms. (default 5000)
|
91 | */
|
92 |
|
93 | /**
|
94 | * @typedef {Object} ControllerOptionsOverrides
|
95 | * @property {ControllerOptions} [js] - Pre-defined defaults options for **JS** controllers these are deep merged with options passed to `Factory.spawn(options)`.
|
96 | * @property {ControllerOptions} [go] - Pre-defined defaults options for **Go** controllers these are deep merged with options passed to `Factory.spawn(options)`.
|
97 | * @property {ControllerOptions} [proc] - Pre-defined defaults options for **Proc** controllers these are deep merged with options passed to `Factory.spawn(options)`.
|
98 | */
|