core-3nweb-client-lib 0.46.0 → 0.46.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -6,18 +6,36 @@
6
6
  ## Development and testing
7
7
 
8
8
  After repository clone, bring down all NodeJS modules, by running in project's folder:
9
- ```
9
+ ```bash
10
10
  npm ci
11
11
  ```
12
12
 
13
13
  Tests have some unit and integrated components. Integration test uses 3NWeb spec server. Integrated tests use server and dns mocking from `spec-3nweb-server`.
14
14
 
15
15
  Build is done with
16
- ```
16
+ ```bash
17
17
  npm run build
18
18
  ```
19
19
 
20
20
  Test is done with (after build)
21
- ```
21
+ ```bash
22
22
  npm run test
23
23
  ```
24
+
25
+
26
+ ## Reuse on non-Node and injecting implementation
27
+
28
+ To reuse this library in non-Node environments, like Android's jsengine and browser, we need to provide different implementations for access to network, files.
29
+
30
+ Some of these functions are explicitly passed in setup phases, like naming functionality that may either use DNS of DoH. Switch between these may even be done based on same platform, but depending on user prefernces.
31
+
32
+ Other functions, like access to device's file system, depend only on environment. For these we use a bit cheaper injection approach. We articulate types that should be implemented. And modules expect to get implementation from `globalThis`. Hence, environments that use core should inject respective implementations at some early stage.
33
+
34
+ Note that import of implementations of injected for node should be done directly, placing it before other imports that need injected global value(s). Do something like:
35
+ ```typescript
36
+ import { makePlatformDeviceFS } from 'core-3nweb-client-lib/build/injected-globals/inject-on-node';
37
+ globalThis.platform = {
38
+ device_fs: makePlatformDeviceFS()
39
+ };
40
+ import ... // other modules
41
+ ```
@@ -16,6 +16,7 @@
16
16
  this program. If not, see <http://www.gnu.org/licenses/>.
17
17
  */
18
18
  var _a;
19
+ var _b;
19
20
  Object.defineProperty(exports, "__esModule", { value: true });
20
21
  exports.copyFile = exports.writeFile = exports.unlink = exports.truncate = exports.symlink = exports.stat = exports.rmdir = exports.rename = exports.readlink = exports.readdir = exports.readFile = exports.open = exports.mkdir = exports.lstat = exports.appendFile = void 0;
21
22
  exports.readToBuf = readToBuf;
@@ -37,6 +38,9 @@ const deferred_1 = require("./processes/deferred");
37
38
  const bytes_fifo_buffer_1 = require("./byte-streaming/bytes-fifo-buffer");
38
39
  const buffer_utils_1 = require("./buffer-utils");
39
40
  function noop() { }
41
+ if (!((_b = globalThis.platform) === null || _b === void 0 ? void 0 : _b.device_fs)) {
42
+ throw new Error(`Expected globally injected object globalThis.platform?.device_fs is missing`);
43
+ }
40
44
  /**
41
45
  * fs functions follow node's type, and are injected via global object to allow injection in
42
46
  * non-node environments, like Android or browser.
@@ -14,4 +14,3 @@ export { makeLogger } from './lib-client/logging/log-to-file';
14
14
  export declare const SYSTEM_DOMAIN = "3nweb.computer";
15
15
  export { checkServicesStartingFromSignup } from './lib-client/service-checks';
16
16
  export { dohAt } from './lib-client/doh';
17
- export * as injectOnNode from './injected-globals/inject-on-node';
@@ -30,7 +30,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
30
30
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
31
31
  };
32
32
  Object.defineProperty(exports, "__esModule", { value: true });
33
- exports.injectOnNode = exports.dohAt = exports.checkServicesStartingFromSignup = exports.SYSTEM_DOMAIN = exports.makeLogger = exports.DeviceFS = exports.sysFolders = exports.appDirs = exports.makeNetClient = exports.makeServiceLocator = exports.ASMail = exports.SignIn = exports.reverseDomain = exports.Storages = exports.IdManager = exports.SignUp = void 0;
33
+ exports.dohAt = exports.checkServicesStartingFromSignup = exports.SYSTEM_DOMAIN = exports.makeLogger = exports.DeviceFS = exports.sysFolders = exports.appDirs = exports.makeNetClient = exports.makeServiceLocator = exports.ASMail = exports.SignIn = exports.reverseDomain = exports.Storages = exports.IdManager = exports.SignUp = void 0;
34
34
  __exportStar(require("./core"), exports);
35
35
  var sign_up_1 = require("./core/startup/sign-up");
36
36
  Object.defineProperty(exports, "SignUp", { enumerable: true, get: function () { return sign_up_1.SignUp; } });
@@ -60,5 +60,4 @@ var service_checks_1 = require("./lib-client/service-checks");
60
60
  Object.defineProperty(exports, "checkServicesStartingFromSignup", { enumerable: true, get: function () { return service_checks_1.checkServicesStartingFromSignup; } });
61
61
  var doh_1 = require("./lib-client/doh");
62
62
  Object.defineProperty(exports, "dohAt", { enumerable: true, get: function () { return doh_1.dohAt; } });
63
- exports.injectOnNode = require("./injected-globals/inject-on-node");
64
63
  Object.freeze(exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "core-3nweb-client-lib",
3
- "version": "0.46.0",
3
+ "version": "0.46.1",
4
4
  "description": "3NWeb client core library, embeddable into different environments",
5
5
  "main": "build/lib-index.js",
6
6
  "types": "build/lib-index.d.ts",