@gapi/cli 1.8.124 → 1.8.125

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.
Files changed (27) hide show
  1. package/dist/core/helpers/mkdirp.d.ts +2 -0
  2. package/dist/core/helpers/mkdirp.js +96 -0
  3. package/dist/core/services/file.d.ts +12 -0
  4. package/dist/core/services/file.js +109 -0
  5. package/dist/daemon-server/core/services/daemon.service.d.ts +1 -1
  6. package/dist/daemon-server/core/services/daemon.service.js +2 -1
  7. package/dist/daemon-server/core/services/ipfs/external-importer-config.d.ts +32 -0
  8. package/dist/daemon-server/core/services/ipfs/external-importer-config.js +9 -0
  9. package/dist/daemon-server/core/services/ipfs/external-importer-systemjs.d.ts +185 -0
  10. package/dist/daemon-server/core/services/ipfs/external-importer-systemjs.js +2 -0
  11. package/dist/daemon-server/core/services/ipfs/external-importer.d.ts +57 -0
  12. package/dist/daemon-server/core/services/ipfs/external-importer.js +359 -0
  13. package/dist/daemon-server/core/services/ipfs/npm-service.d.ts +12 -0
  14. package/dist/daemon-server/core/services/ipfs/npm-service.js +55 -0
  15. package/dist/daemon-server/core/services/ipfs/providers.d.ts +5 -0
  16. package/dist/daemon-server/core/services/ipfs/providers.js +21 -0
  17. package/dist/daemon-server/core/services/ipfs/request-cache.d.ts +7 -0
  18. package/dist/daemon-server/core/services/ipfs/request-cache.js +31 -0
  19. package/dist/daemon-server/core/services/ipfs/request.d.ts +6 -0
  20. package/dist/daemon-server/core/services/ipfs/request.js +60 -0
  21. package/dist/daemon-server/core/services/ipfs-hash-map.service.d.ts +1 -1
  22. package/dist/daemon-server/core/services/plugin-loader.service.d.ts +3 -1
  23. package/dist/daemon-server/core/services/plugin-loader.service.js +4 -2
  24. package/dist/tasks/daemon.d.ts +1 -1
  25. package/dist/tasks/daemon.js +2 -1
  26. package/dist/tasks/schema.js +6 -6
  27. package/package.json +5 -5
@@ -0,0 +1,2 @@
1
+ export declare function mkdirp(p?: any, opts?: any, f?: any, made?: any): void;
2
+ export declare function mkdirpSync(p?: any, opts?: any, made?: any): any;
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mkdirpSync = exports.mkdirp = void 0;
4
+ const fs_1 = require("fs");
5
+ const path_1 = require("path");
6
+ const _0777 = parseInt('0777', 8);
7
+ function mkdirp(p, opts, f, made) {
8
+ if (typeof opts === 'function') {
9
+ f = opts;
10
+ opts = {};
11
+ }
12
+ else if (!opts || typeof opts !== 'object') {
13
+ opts = { mode: opts };
14
+ }
15
+ let mode = opts.mode;
16
+ if (mode === undefined) {
17
+ mode = _0777 & ~process.umask();
18
+ }
19
+ if (!made)
20
+ made = null;
21
+ const cb = f ||
22
+ function () {
23
+ //
24
+ };
25
+ p = path_1.resolve(p);
26
+ fs_1.mkdir(p, mode, function (er) {
27
+ if (!er) {
28
+ made = made || p;
29
+ return cb(null, made);
30
+ }
31
+ switch (er.code) {
32
+ case 'ENOENT':
33
+ mkdirp(path_1.dirname(p), opts, function (er, made) {
34
+ if (er)
35
+ cb(er, made);
36
+ else
37
+ mkdirp(p, opts, cb, made);
38
+ });
39
+ break;
40
+ // In the case of any other error, just see if there's a dir
41
+ // there already. If so, then hooray! If not, then something
42
+ // is borked.
43
+ default:
44
+ fs_1.stat(p, function (er2, stat) {
45
+ // if the stat fails, then that's super weird.
46
+ // let the original error be the failure reason.
47
+ if (er2 || !stat.isDirectory())
48
+ cb(er, made);
49
+ else
50
+ cb(null, made);
51
+ });
52
+ break;
53
+ }
54
+ });
55
+ }
56
+ exports.mkdirp = mkdirp;
57
+ function mkdirpSync(p, opts, made) {
58
+ if (!opts || typeof opts !== 'object') {
59
+ opts = { mode: opts };
60
+ }
61
+ let mode = opts.mode;
62
+ if (mode === undefined) {
63
+ mode = _0777 & ~process.umask();
64
+ }
65
+ if (!made)
66
+ made = null;
67
+ p = path_1.resolve(p);
68
+ try {
69
+ fs_1.mkdirSync(p, mode);
70
+ made = made || p;
71
+ }
72
+ catch (err0) {
73
+ switch (err0.code) {
74
+ case 'ENOENT':
75
+ made = mkdirpSync(path_1.dirname(p), opts, made);
76
+ mkdirpSync(p, opts, made);
77
+ break;
78
+ // In the case of any other error, just see if there's a dir
79
+ // there already. If so, then hooray! If not, then something
80
+ // is borked.
81
+ default:
82
+ let stat;
83
+ try {
84
+ stat = fs_1.statSync(p);
85
+ }
86
+ catch (err1) {
87
+ throw err0;
88
+ }
89
+ if (!stat.isDirectory())
90
+ throw err0;
91
+ break;
92
+ }
93
+ }
94
+ return made;
95
+ }
96
+ exports.mkdirpSync = mkdirpSync;
@@ -0,0 +1,12 @@
1
+ import { Observable } from 'rxjs';
2
+ export declare class FileService {
3
+ writeFile(folder: string, fileName: any, moduleName: any, file: any): Observable<unknown>;
4
+ writeFileAsync(folder: string, fileName: any, moduleName: any, file: any): Observable<string>;
5
+ writeFileSync(folder: any, file: any): any;
6
+ readFile(file: string): any;
7
+ isPresent(path: string): boolean;
8
+ writeFileAsyncP(folder: any, fileName: any, content: any): Observable<unknown>;
9
+ mkdirp(folder: any): Observable<boolean>;
10
+ fileWalker(dir: string, exclude?: string): Observable<string[]>;
11
+ private filewalker;
12
+ }
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.FileService = void 0;
10
+ const core_1 = require("@rxdi/core");
11
+ const fs_1 = require("fs");
12
+ const path_1 = require("path");
13
+ const rxjs_1 = require("rxjs");
14
+ const operators_1 = require("rxjs/operators");
15
+ const mkdirp_1 = require("../helpers/mkdirp");
16
+ let FileService = class FileService {
17
+ writeFile(folder, fileName, moduleName, file) {
18
+ return this.mkdirp(folder).pipe(operators_1.tap(() => {
19
+ console.log(`Bootstrap: @Service('${moduleName}'): Saved inside ${folder}`);
20
+ }), operators_1.switchMap(() => this.writeFileAsyncP(folder, fileName, file)));
21
+ }
22
+ writeFileAsync(folder, fileName, moduleName, file) {
23
+ return this.mkdirp(folder).pipe(operators_1.switchMap(() => this.writeFileAsyncP(folder, fileName, file)), operators_1.map(() => {
24
+ console.log(`Bootstrap: external @Module('${moduleName}') namespace: Saved inside ${folder}`);
25
+ return `${folder}/${fileName}`;
26
+ }));
27
+ }
28
+ writeFileSync(folder, file) {
29
+ return fs_1.writeFileSync.bind(null)(folder, JSON.stringify(file, null, 2) + '\n', { encoding: 'utf-8' });
30
+ }
31
+ readFile(file) {
32
+ return JSON.parse(fs_1.readFileSync.bind(null)(file, { encoding: 'utf-8' }));
33
+ }
34
+ isPresent(path) {
35
+ return fs_1.existsSync(path);
36
+ }
37
+ writeFileAsyncP(folder, fileName, content) {
38
+ return new rxjs_1.Observable((o) => fs_1.writeFile(`${folder}/${fileName}`, content, () => o.next(true)));
39
+ }
40
+ mkdirp(folder) {
41
+ return new rxjs_1.Observable((observer) => {
42
+ mkdirp_1.mkdirp(folder, (err) => {
43
+ if (err) {
44
+ console.error(err);
45
+ observer.error(false);
46
+ }
47
+ else {
48
+ observer.next(true);
49
+ }
50
+ observer.complete();
51
+ });
52
+ });
53
+ }
54
+ fileWalker(dir, exclude = 'node_modules') {
55
+ return new rxjs_1.Observable((observer) => {
56
+ this.filewalker(dir, (err, result) => {
57
+ if (err) {
58
+ observer.error(err);
59
+ }
60
+ else {
61
+ observer.next(result);
62
+ }
63
+ observer.complete();
64
+ }, exclude);
65
+ });
66
+ }
67
+ filewalker(dir, done, exclude = 'node_modules') {
68
+ let results = [];
69
+ const fileWalker = this.filewalker.bind(this);
70
+ fs_1.readdir(dir, (err, list) => {
71
+ if (err) {
72
+ return done(err);
73
+ }
74
+ let pending = list.length;
75
+ if (!pending) {
76
+ return done(null, results);
77
+ }
78
+ list.forEach((file) => {
79
+ file = path_1.resolve(dir, file);
80
+ fs_1.stat(file, (err, stat) => {
81
+ if (stat && stat.isDirectory()) {
82
+ results.push(file);
83
+ if (!file.includes(exclude)) {
84
+ fileWalker(file, (err, res) => {
85
+ results = results.concat(res);
86
+ if (!--pending) {
87
+ done(null, results);
88
+ }
89
+ }, exclude);
90
+ }
91
+ else if (!--pending) {
92
+ done(null, results);
93
+ }
94
+ }
95
+ else {
96
+ results.push(file);
97
+ if (!--pending) {
98
+ done(null, results);
99
+ }
100
+ }
101
+ });
102
+ });
103
+ });
104
+ }
105
+ };
106
+ FileService = __decorate([
107
+ core_1.Service()
108
+ ], FileService);
109
+ exports.FileService = FileService;
@@ -1,4 +1,4 @@
1
- import { FileService } from '@rxdi/core';
1
+ import { FileService } from '../../../core/services/file';
2
2
  import { ILinkListType } from '../../api-introspection';
3
3
  import { ChildService } from './child.service';
4
4
  import { ListService } from './list.service';
@@ -25,6 +25,7 @@ const fs_1 = require("fs");
25
25
  const rxjs_1 = require("rxjs");
26
26
  const operators_1 = require("rxjs/operators");
27
27
  const util_1 = require("util");
28
+ const file_1 = require("../../../core/services/file");
28
29
  const daemon_config_1 = require("../../daemon.config");
29
30
  const gapi_cli_config_template_1 = require("../templates/gapi-cli-config.template");
30
31
  const child_service_1 = require("./child.service");
@@ -101,6 +102,6 @@ DaemonService = __decorate([
101
102
  core_1.Service(),
102
103
  __metadata("design:paramtypes", [list_service_1.ListService,
103
104
  child_service_1.ChildService,
104
- core_1.FileService])
105
+ file_1.FileService])
105
106
  ], DaemonService);
106
107
  exports.DaemonService = DaemonService;
@@ -0,0 +1,32 @@
1
+ import { Config } from './external-importer-systemjs';
2
+ export declare class ExternalImporterConfig {
3
+ link: string;
4
+ fileName?: string;
5
+ typings?: string;
6
+ typingsFileName?: string;
7
+ namespace?: string;
8
+ extension?: string;
9
+ crypto?: {
10
+ cyperKey: string;
11
+ cyperIv: string;
12
+ algorithm: string;
13
+ };
14
+ SystemJsConfig?: Config;
15
+ outputFolder?: string | '/node_modules/';
16
+ }
17
+ export declare class ExternalImporterIpfsConfig {
18
+ provider: string;
19
+ hash: string;
20
+ }
21
+ export interface NpmPackageConfig {
22
+ name: string;
23
+ version: string;
24
+ }
25
+ export interface ExternalModuleConfiguration {
26
+ name: string;
27
+ version: string;
28
+ typings: string;
29
+ module: string;
30
+ dependencies?: Array<any>;
31
+ packages?: NpmPackageConfig[];
32
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExternalImporterIpfsConfig = exports.ExternalImporterConfig = void 0;
4
+ class ExternalImporterConfig {
5
+ }
6
+ exports.ExternalImporterConfig = ExternalImporterConfig;
7
+ class ExternalImporterIpfsConfig {
8
+ }
9
+ exports.ExternalImporterIpfsConfig = ExternalImporterIpfsConfig;
@@ -0,0 +1,185 @@
1
+ export declare type ModuleFormat = 'esm' | 'cjs' | 'amd' | 'global' | 'register';
2
+ export interface MetaConfig {
3
+ /**
4
+ * Sets in what format the module is loaded.
5
+ */
6
+ format?: ModuleFormat;
7
+ /**
8
+ * For the global format, when automatic detection of exports is not enough, a custom exports meta value can be set.
9
+ * This tells the loader what global name to use as the module's export value.
10
+ */
11
+ exports?: string;
12
+ /**
13
+ * Dependencies to load before this module. Goes through regular paths and map normalization.
14
+ * Only supported for the cjs, amd and global formats.
15
+ */
16
+ deps?: string[];
17
+ /**
18
+ * A map of global names to module names that should be defined only for the execution of this module.
19
+ * Enables use of legacy code that expects certain globals to be present.
20
+ * Referenced modules automatically becomes dependencies. Only supported for the cjs and global formats.
21
+ */
22
+ globals?: string;
23
+ /**
24
+ * Set a loader for this meta path.
25
+ */
26
+ loader?: string;
27
+ /**
28
+ * For plugin transpilers to set the source map of their transpilation.
29
+ */
30
+ sourceMap?: any;
31
+ /**
32
+ * Load the module using <script> tag injection.
33
+ */
34
+ scriptLoad?: boolean;
35
+ /**
36
+ * The nonce attribute to use when loading the script as a way to enable CSP.
37
+ * This should correspond to the 'nonce-' attribute set in the Content-Security-Policy header.
38
+ */
39
+ nonce?: string;
40
+ /**
41
+ * The subresource integrity attribute corresponding to the script integrity,
42
+ * describing the expected hash of the final code to be executed.
43
+ * For example, System.config({ meta: { 'src/example.js': { integrity: 'sha256-e3b0c44...' }});
44
+ * would throw an error if the translated source of src/example.js doesn't match the expected hash.
45
+ */
46
+ integrity?: string;
47
+ /**
48
+ * When scripts are loaded from a different domain (e.g. CDN) the global error handler (window.onerror)
49
+ * has very limited information about errors to prevent unintended leaking. In order to mitigate this,
50
+ * the <script> tags need to set crossorigin attribute and the server needs to enable CORS.
51
+ * The valid values are 'anonymous' and 'use-credentials'.
52
+ */
53
+ crossOrigin?: string;
54
+ /**
55
+ * When loading a module that is not an ECMAScript Module, we set the module as the default export,
56
+ * but then also iterate the module object and copy named exports for it a well.
57
+ * Use this option to disable this iteration and copying of the exports.
58
+ */
59
+ esmExports?: boolean;
60
+ /**
61
+ * To ignore resources that shouldn't be traced as part of the build.
62
+ * Use with the SystemJS Builder. (https://github.com/systemjs/builder#ignore-resources)
63
+ */
64
+ build?: boolean;
65
+ /**
66
+ * A truthy value enables sending credentials to the server on every request. Additionally, a string value adds
67
+ * an 'Authorization' header with that value to all requests.
68
+ */
69
+ authorization?: string | boolean;
70
+ }
71
+ export interface PackageConfig {
72
+ /**
73
+ * The main entry point of the package (so import 'local/package' is equivalent to import 'local/package/index.js')
74
+ */
75
+ main?: string;
76
+ /**
77
+ * The module format of the package. See Module Formats.
78
+ */
79
+ format?: ModuleFormat;
80
+ /**
81
+ * The default extension to add to modules requested within the package. Takes preference over defaultJSExtensions.
82
+ * Can be set to defaultExtension: false to optionally opt-out of extension-adding when defaultJSExtensions is enabled.
83
+ */
84
+ defaultExtension?: boolean | string;
85
+ /**
86
+ * Local and relative map configurations scoped to the package. Apply for subpaths as well.
87
+ */
88
+ map?: ConfigMap;
89
+ /**
90
+ * Module meta provides an API for SystemJS to understand how to load modules correctly.
91
+ * Package-scoped meta configuration with wildcard support. Modules are subpaths within the package path.
92
+ * This also provides an opt-out mechanism for defaultExtension, by adding modules here that should skip extension adding.
93
+ */
94
+ meta?: ConfigMeta;
95
+ }
96
+ export declare type ConfigMeta = PackageList<MetaConfig>;
97
+ export interface ModulesList {
98
+ [bundleName: string]: string[];
99
+ }
100
+ export interface PackageList<T> {
101
+ [packageName: string]: T;
102
+ }
103
+ export declare type ConfigMap = PackageList<string | PackageList<string>>;
104
+ export declare type Transpiler = 'plugin-traceur' | 'plugin-babel' | 'plugin-typescript' | 'traceur' | 'babel' | 'typescript' | false;
105
+ export interface TraceurOptions {
106
+ properTailCalls?: boolean;
107
+ symbols?: boolean;
108
+ arrayComprehension?: boolean;
109
+ asyncFunctions?: boolean;
110
+ asyncGenerators?: any;
111
+ forOn?: boolean;
112
+ generatorComprehension?: boolean;
113
+ }
114
+ export interface Config {
115
+ /**
116
+ * For custom config names
117
+ */
118
+ [customName: string]: any;
119
+ /**
120
+ * The baseURL provides a special mechanism for loading modules relative to a standard reference URL.
121
+ */
122
+ baseURL?: string;
123
+ /**
124
+ * Set the Babel transpiler options when System.transpiler is set to babel.
125
+ */
126
+ babelOptions?: any;
127
+ /**
128
+ * undles allow a collection of modules to be downloaded together as a package whenever any module from that collection is requested.
129
+ * Useful for splitting an application into sub-modules for production. Use with the SystemJS Builder.
130
+ */
131
+ bundles?: ModulesList;
132
+ /**
133
+ * Backwards-compatibility mode for the loader to automatically add '.js' extensions when not present to module requests.
134
+ * This allows code written for SystemJS 0.16 or less to work easily in the latest version:
135
+ */
136
+ defaultJSExtensions?: boolean;
137
+ /**
138
+ * An alternative to bundling providing a solution to the latency issue of progressively loading dependencies.
139
+ * When a module specified in depCache is loaded, asynchronous loading of its pre-cached dependency list begins in parallel.
140
+ */
141
+ depCache?: ModulesList;
142
+ /**
143
+ * The map option is similar to paths, but acts very early in the normalization process.
144
+ * It allows you to map a module alias to a location or package:
145
+ */
146
+ map?: ConfigMap;
147
+ /**
148
+ * Module meta provides an API for SystemJS to understand how to load modules correctly.
149
+ * Meta is how we set the module format of a module, or know how to shim dependencies of a global script.
150
+ */
151
+ meta?: ConfigMeta;
152
+ /**
153
+ * Packages provide a convenience for setting meta and map configuration that is specific to a common path.
154
+ * In addition packages allow for setting contextual map configuration which only applies within the package itself.
155
+ * This allows for full dependency encapsulation without always needing to have all dependencies in a global namespace.
156
+ */
157
+ packages?: PackageList<PackageConfig>;
158
+ /**
159
+ * The ES6 Module Loader paths implementation, applied after normalization and supporting subpaths via wildcards.
160
+ * It is usually advisable to use map configuration over paths unless you need strict control over normalized module names.
161
+ */
162
+ paths?: PackageList<string>;
163
+ /**
164
+ * Set the Traceur compilation options.
165
+ */
166
+ traceurOptions?: TraceurOptions;
167
+ /**
168
+ * Sets the module name of the transpiler to be used for loading ES6 modules.
169
+ */
170
+ transpiler?: Transpiler;
171
+ trace?: boolean;
172
+ /**
173
+ * Sets the TypeScript transpiler options.
174
+ */
175
+ typescriptOptions?: {
176
+ /**
177
+ * A boolean flag which instructs the plugin to load configuration from 'tsconfig.json'.
178
+ * To override the location of the file set this option to the path of the configuration file,
179
+ * which will be resolved using normal SystemJS resolution.
180
+ * Note: This setting is specific to plugin-typescript.
181
+ */
182
+ tsconfig?: boolean | string;
183
+ [key: string]: any;
184
+ };
185
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,57 @@
1
+ import { BehaviorSubject, Observable } from 'rxjs';
2
+ import { ExternalImporterConfig, ExternalImporterIpfsConfig, ExternalModuleConfiguration } from './external-importer-config';
3
+ import { IPFS_PROVIDERS } from './providers';
4
+ export interface PackagesConfig {
5
+ dependencies: string[];
6
+ provider: string;
7
+ }
8
+ export declare class ExternalImporter {
9
+ defaultJsonFolder: string;
10
+ defaultTypescriptConfigJsonFolder: string;
11
+ private requestService;
12
+ private fileService;
13
+ private npmService;
14
+ providers: BehaviorSubject<{
15
+ name: IPFS_PROVIDERS;
16
+ link: string;
17
+ }[]>;
18
+ defaultProvider: string;
19
+ defaultNamespaceFolder: string;
20
+ defaultOutputFolder: string;
21
+ setDefaultProvider(provider: IPFS_PROVIDERS): void;
22
+ getProvider(name: IPFS_PROVIDERS): string;
23
+ setProviders(...args: {
24
+ name: IPFS_PROVIDERS;
25
+ link: string;
26
+ }[]): void;
27
+ importExternalModule(module: string): Observable<unknown>;
28
+ validateConfig(config: ExternalImporterConfig): void;
29
+ isWeb(): boolean;
30
+ loadTypescriptConfigJson(): {
31
+ compilerOptions?: {
32
+ typeRoots?: string[];
33
+ };
34
+ };
35
+ addNamespaceToTypeRoots(namespace: string): Observable<boolean>;
36
+ writeTypescriptConfigFile(file: any): void;
37
+ loadPackageJson(): any;
38
+ loadNpmPackageJson(): any;
39
+ prepareDependencies(): {
40
+ name: string;
41
+ version: any;
42
+ }[];
43
+ isModulePresent(hash: any): number;
44
+ filterUniquePackages(): number;
45
+ defaultIpfsConfig(): {
46
+ provider: string;
47
+ dependencies: any[];
48
+ }[];
49
+ addPackageToJson(hash: string): void;
50
+ downloadIpfsModules(modules: ExternalImporterIpfsConfig[]): Observable<[any]>;
51
+ downloadIpfsModuleConfig(config: ExternalImporterIpfsConfig): Observable<ExternalModuleConfiguration>;
52
+ private combineDependencies;
53
+ private writeFakeIndexIfMultiModule;
54
+ downloadIpfsModule(config: ExternalImporterIpfsConfig): any;
55
+ downloadTypings(moduleLink: string, folder: string, fileName: string, config: ExternalImporterConfig): Observable<unknown>;
56
+ importModule(config: ExternalImporterConfig, token: string, { folderOverride, waitUntil }?: any): Promise<any>;
57
+ }
@@ -0,0 +1,359 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.ExternalImporter = void 0;
13
+ /* eslint-disable @typescript-eslint/no-explicit-any */
14
+ const rxjs_1 = require("rxjs");
15
+ const operators_1 = require("rxjs/operators");
16
+ const file_1 = require("../../../../core/services/file");
17
+ const providers_1 = require("./providers");
18
+ const SystemJS = require("systemjs");
19
+ const core_1 = require("@rxdi/core");
20
+ const npm_service_1 = require("./npm-service");
21
+ const request_1 = require("./request");
22
+ let ExternalImporter = class ExternalImporter {
23
+ constructor() {
24
+ this.defaultJsonFolder = `${process.cwd()}/package.json`;
25
+ this.defaultTypescriptConfigJsonFolder = `${process.cwd()}/tsconfig.json`;
26
+ this.providers = new rxjs_1.BehaviorSubject(providers_1.IPFS_PROVIDERS);
27
+ this.defaultProvider = this.getProvider('main-ipfs-node');
28
+ this.defaultNamespaceFolder = '@types';
29
+ this.defaultOutputFolder = 'node_modules';
30
+ }
31
+ setDefaultProvider(provider) {
32
+ this.defaultProvider = this.getProvider(provider);
33
+ }
34
+ getProvider(name) {
35
+ return this.providers.getValue().filter((p) => p.name === name)[0].link;
36
+ }
37
+ setProviders(...args) {
38
+ this.providers.next([...this.providers.getValue(), ...args]);
39
+ }
40
+ importExternalModule(module) {
41
+ return rxjs_1.from(SystemJS.import(module));
42
+ }
43
+ validateConfig(config) {
44
+ if (!config) {
45
+ throw new Error('Bootstrap: missing config');
46
+ }
47
+ }
48
+ isWeb() {
49
+ let value = false;
50
+ try {
51
+ if (window) {
52
+ value = true;
53
+ }
54
+ }
55
+ catch (e) { }
56
+ return value;
57
+ }
58
+ loadTypescriptConfigJson() {
59
+ let tsConfig = {};
60
+ try {
61
+ tsConfig = this.fileService.readFile(this.defaultTypescriptConfigJsonFolder);
62
+ }
63
+ catch (e) {
64
+ console.error(`
65
+ Error in loading tsconfig.json in ${this.defaultTypescriptConfigJsonFolder}
66
+ Error: ${e}
67
+ Fallback to creating tsconfig.json
68
+ `);
69
+ }
70
+ tsConfig.compilerOptions = tsConfig.compilerOptions || {};
71
+ tsConfig.compilerOptions.typeRoots =
72
+ tsConfig.compilerOptions.typeRoots || [];
73
+ return tsConfig;
74
+ }
75
+ addNamespaceToTypeRoots(namespace) {
76
+ const defaultNamespace = `./${this.defaultOutputFolder}/@types/${namespace}`;
77
+ const tsConfig = this.loadTypescriptConfigJson();
78
+ const foundNamespace = tsConfig.compilerOptions.typeRoots.filter((t) => t === defaultNamespace).length;
79
+ if (!foundNamespace) {
80
+ tsConfig.compilerOptions.typeRoots.push(defaultNamespace);
81
+ this.writeTypescriptConfigFile(tsConfig);
82
+ }
83
+ return rxjs_1.of(true);
84
+ }
85
+ writeTypescriptConfigFile(file) {
86
+ this.fileService.writeFileSync(process.cwd() + '/tsconfig.json', file);
87
+ }
88
+ loadPackageJson() {
89
+ let packageJson;
90
+ try {
91
+ packageJson = this.fileService.readFile(this.defaultJsonFolder);
92
+ }
93
+ catch (e) {
94
+ packageJson = {};
95
+ }
96
+ return packageJson;
97
+ }
98
+ loadNpmPackageJson() {
99
+ let packageJson;
100
+ try {
101
+ packageJson = this.fileService.readFile(`${process.cwd()}/package.json`);
102
+ }
103
+ catch (e) {
104
+ packageJson = {};
105
+ }
106
+ return packageJson;
107
+ }
108
+ prepareDependencies() {
109
+ const file = this.loadNpmPackageJson();
110
+ if (file.dependencies) {
111
+ return Object.keys(file.dependencies).map((name) => ({
112
+ name,
113
+ version: file.dependencies[name],
114
+ }));
115
+ }
116
+ return [];
117
+ }
118
+ isModulePresent(hash) {
119
+ const file = this.loadPackageJson();
120
+ let ipfsConfig = file.ipfs;
121
+ const found = [];
122
+ if (!ipfsConfig) {
123
+ ipfsConfig = this.defaultIpfsConfig();
124
+ }
125
+ ipfsConfig.forEach((c) => {
126
+ const present = c.dependencies.filter((dep) => dep === hash);
127
+ if (present.length) {
128
+ found.push(present[0]);
129
+ }
130
+ });
131
+ return found.length;
132
+ }
133
+ filterUniquePackages() {
134
+ const file = this.loadPackageJson();
135
+ let ipfsConfig = file.ipfs;
136
+ let dups = [];
137
+ if (!ipfsConfig) {
138
+ ipfsConfig = this.defaultIpfsConfig();
139
+ }
140
+ ipfsConfig.forEach((c) => {
141
+ const uniq = c.dependencies
142
+ .map((name) => {
143
+ return { count: 1, name: name };
144
+ })
145
+ .reduce((a, b) => {
146
+ a[b.name] = (a[b.name] || 0) + b.count;
147
+ return a;
148
+ }, {});
149
+ const duplicates = Object.keys(uniq).filter((a) => uniq[a] > 1);
150
+ dups = [...dups, ...duplicates];
151
+ });
152
+ if (dups.length) {
153
+ throw new Error(`There are packages which are with the same hash ${JSON.stringify(dups)}`);
154
+ }
155
+ return dups.length;
156
+ }
157
+ defaultIpfsConfig() {
158
+ return [{ provider: this.defaultProvider, dependencies: [] }];
159
+ }
160
+ addPackageToJson(hash) {
161
+ const file = this.loadPackageJson();
162
+ let ipfsConfig = file.ipfs;
163
+ if (!ipfsConfig) {
164
+ ipfsConfig = this.defaultIpfsConfig();
165
+ }
166
+ const packages = this.prepareDependencies();
167
+ if (packages.length) {
168
+ file.packages = packages;
169
+ }
170
+ if (this.isModulePresent(hash)) {
171
+ console.log(`Package with hash: ${hash} present and will not be downloaded!`);
172
+ }
173
+ else {
174
+ ipfsConfig[0].dependencies.push(hash);
175
+ file.ipfs = ipfsConfig;
176
+ }
177
+ this.fileService.writeFileSync(this.defaultJsonFolder, file);
178
+ }
179
+ downloadIpfsModules(modules) {
180
+ const latest = modules.map((m) => this.downloadIpfsModule(m));
181
+ return rxjs_1.combineLatest(latest.length ? latest : rxjs_1.of());
182
+ }
183
+ downloadIpfsModuleConfig(config) {
184
+ return this.requestService.get(config.provider + config.hash).pipe(operators_1.map((r) => {
185
+ if (!r) {
186
+ throw new Error('Recieved undefined from provided address' +
187
+ config.provider +
188
+ config.hash);
189
+ }
190
+ let res = r;
191
+ const metaString = '<!--meta-rxdi-ipfs-module-->';
192
+ if (res.includes(metaString)) {
193
+ try {
194
+ res = res.split(metaString)[1];
195
+ }
196
+ catch (e) { }
197
+ }
198
+ return res;
199
+ }), operators_1.map((r) => {
200
+ let res = r;
201
+ try {
202
+ res = JSON.parse(r);
203
+ }
204
+ catch (e) { }
205
+ return res;
206
+ }));
207
+ }
208
+ combineDependencies(dependencies, config) {
209
+ return rxjs_1.combineLatest([
210
+ ...(dependencies.length
211
+ ? dependencies.map((h) => this.downloadIpfsModule({ provider: config.provider, hash: h }))
212
+ : [rxjs_1.of('')]),
213
+ ]);
214
+ }
215
+ writeFakeIndexIfMultiModule(folder, nameSpaceFakeIndex) {
216
+ if (nameSpaceFakeIndex.length === 2) {
217
+ return this.fileService.writeFileAsyncP(`${folder}${this.defaultNamespaceFolder}/${nameSpaceFakeIndex[0]}`, 'index.d.ts', '');
218
+ }
219
+ else {
220
+ return rxjs_1.of(true);
221
+ }
222
+ }
223
+ downloadIpfsModule(config) {
224
+ if (!config.provider) {
225
+ throw new Error(`Missing configuration inside ${config.hash}`);
226
+ }
227
+ if (!config.hash) {
228
+ throw new Error(`Missing configuration inside ${config.provider}`);
229
+ }
230
+ let folder;
231
+ let moduleLink;
232
+ const configLink = config.provider + config.hash;
233
+ let moduleTypings;
234
+ let moduleName;
235
+ let nameSpaceFakeIndex;
236
+ let originalModuleConfig;
237
+ let isNamespace;
238
+ let isRegular;
239
+ return this.downloadIpfsModuleConfig(config).pipe(operators_1.tap((res) => {
240
+ if (!res['module']) {
241
+ console.log('Todo: create logic to load module which is not from rxdi infrastructure for now can be used useDynamic which will do the same job!');
242
+ }
243
+ }), operators_1.filter((res) => !!res.module), operators_1.map((externalModule) => {
244
+ moduleName = externalModule.name;
245
+ nameSpaceFakeIndex = moduleName.split('/');
246
+ folder = `${process.cwd()}/${this.defaultOutputFolder}/`;
247
+ moduleLink = `${config.provider}${externalModule.module}`;
248
+ moduleTypings = `${config.provider}${externalModule.typings}`;
249
+ externalModule.dependencies = externalModule.dependencies || [];
250
+ externalModule.packages = externalModule.packages || [];
251
+ originalModuleConfig = externalModule;
252
+ this.npmService.setPackages(externalModule.packages);
253
+ isNamespace = moduleName.split('/').length === 2;
254
+ isRegular = isNamespace ? moduleName : moduleName.split('/')[0];
255
+ console.log(`Package config for module ${moduleName} downloaded! ${JSON.stringify(externalModule)}`);
256
+ return externalModule;
257
+ }), operators_1.switchMap((externalModule) => this.combineDependencies(externalModule.dependencies, config)), operators_1.switchMap(() => {
258
+ console.log(`--------------------${moduleName}--------------------`);
259
+ console.log(`\nDownloading... ${configLink} `);
260
+ console.log(`Config: ${JSON.stringify(originalModuleConfig, null, 2)} \n`);
261
+ return this.requestService.get(moduleLink);
262
+ }), operators_1.switchMap((file) => this.fileService.writeFile(folder + moduleName, 'index.js', moduleName, file)), operators_1.switchMap(() => this.requestService.get(moduleTypings)), operators_1.switchMap((file) => this.fileService.writeFile(folder + `${this.defaultNamespaceFolder}/${isRegular}`, 'index.d.ts', moduleName, file)), operators_1.tap(() => {
263
+ if (process.env.WRITE_FAKE_INDEX) {
264
+ this.writeFakeIndexIfMultiModule(folder, nameSpaceFakeIndex);
265
+ }
266
+ }), operators_1.switchMap(() => this.addNamespaceToTypeRoots(moduleName.split('/')[0])), operators_1.map(() => ({
267
+ provider: config.provider,
268
+ hash: config.hash,
269
+ version: originalModuleConfig.version,
270
+ name: originalModuleConfig.name,
271
+ dependencies: originalModuleConfig.dependencies,
272
+ packages: originalModuleConfig.packages,
273
+ })), operators_1.tap(() => {
274
+ if (originalModuleConfig.packages.length) {
275
+ this.npmService.installPackages();
276
+ }
277
+ }));
278
+ }
279
+ downloadTypings(moduleLink, folder, fileName, config) {
280
+ if (!moduleLink) {
281
+ return rxjs_1.of(true);
282
+ }
283
+ return this.requestService.get(moduleLink).pipe(operators_1.take(1), operators_1.map((res) => {
284
+ console.log(`Done!`);
285
+ return res;
286
+ }), operators_1.switchMap((res) => this.fileService.writeFile(folder, fileName, config.typingsFileName, res)));
287
+ }
288
+ importModule(config, token, { folderOverride, waitUntil } = {}) {
289
+ const timer$ = rxjs_1.timer(waitUntil || 20 * 1000);
290
+ this.validateConfig(config);
291
+ if (this.isWeb()) {
292
+ SystemJS.config(Object.assign({
293
+ map: {
294
+ [token]: config.link,
295
+ },
296
+ }, config.SystemJsConfig));
297
+ return SystemJS.import(config.link);
298
+ }
299
+ return new rxjs_1.Observable((observer) => {
300
+ const moduleName = config.fileName;
301
+ const moduleNamespace = config.namespace;
302
+ const moduleLink = config.link;
303
+ const moduleExtension = config.extension;
304
+ const moduleSystemJsConfig = config.SystemJsConfig || {};
305
+ const modulesFolder = config.outputFolder || `/${this.defaultOutputFolder}/`;
306
+ const fileFullPath = `${folderOverride || process.cwd()}${modulesFolder}/${moduleNamespace}/${moduleName}.${moduleExtension}`;
307
+ const folder = `${folderOverride || process.cwd()}${modulesFolder}${moduleNamespace}`;
308
+ const fileName = `${moduleName}.${moduleExtension}`;
309
+ Object.assign(moduleSystemJsConfig, {
310
+ paths: Object.assign({ [moduleName]: fileFullPath }, moduleSystemJsConfig.paths),
311
+ });
312
+ SystemJS.config(moduleSystemJsConfig);
313
+ if (this.fileService.isPresent(fileFullPath)) {
314
+ console.log(`Bootstrap -> @Service('${moduleName}'): present inside .${modulesFolder}${moduleNamespace}/${moduleName}.${moduleExtension} folder and loaded from there`);
315
+ this.importExternalModule(moduleName)
316
+ .pipe(operators_1.take(1))
317
+ .subscribe((m) => {
318
+ observer.next(m);
319
+ observer.complete();
320
+ }, (err) => {
321
+ observer.error(err);
322
+ observer.complete();
323
+ });
324
+ }
325
+ else {
326
+ console.log(`Bootstrap -> @Service('${moduleName}'): will be downloaded inside .${modulesFolder}${moduleNamespace}/${moduleName}.${moduleExtension} folder and loaded from there`);
327
+ console.log(`Bootstrap -> @Service('${moduleName}'): ${moduleLink} downloading...`);
328
+ this.requestService
329
+ .get(moduleLink)
330
+ .pipe(operators_1.take(1), operators_1.tap(() => console.log(`Done!`)), operators_1.switchMap((res) => this.fileService.writeFile(folder, fileName, config.fileName, res)), operators_1.switchMap(() => this.downloadTypings(config.typings, folder, fileName, config)), operators_1.switchMap(() => this.importExternalModule(moduleName)))
331
+ .subscribe((m) => {
332
+ observer.next(m);
333
+ observer.complete();
334
+ }, (err) => {
335
+ observer.error(err);
336
+ observer.complete();
337
+ });
338
+ }
339
+ })
340
+ .pipe(operators_1.takeUntil(timer$))
341
+ .toPromise();
342
+ }
343
+ };
344
+ __decorate([
345
+ core_1.Injector(request_1.RequestService),
346
+ __metadata("design:type", request_1.RequestService)
347
+ ], ExternalImporter.prototype, "requestService", void 0);
348
+ __decorate([
349
+ core_1.Injector(file_1.FileService),
350
+ __metadata("design:type", file_1.FileService)
351
+ ], ExternalImporter.prototype, "fileService", void 0);
352
+ __decorate([
353
+ core_1.Injector(npm_service_1.NpmService),
354
+ __metadata("design:type", npm_service_1.NpmService)
355
+ ], ExternalImporter.prototype, "npmService", void 0);
356
+ ExternalImporter = __decorate([
357
+ core_1.Service()
358
+ ], ExternalImporter);
359
+ exports.ExternalImporter = ExternalImporter;
@@ -0,0 +1,12 @@
1
+ /// <reference types="node" />
2
+ import { BehaviorSubject } from 'rxjs';
3
+ import childProcess = require('child_process');
4
+ import { NpmPackageConfig } from './external-importer-config';
5
+ export declare class NpmService {
6
+ packagesToDownload: BehaviorSubject<NpmPackageConfig[]>;
7
+ packages: string[];
8
+ child: childProcess.ChildProcess;
9
+ setPackages(packages: NpmPackageConfig[]): void;
10
+ preparePackages(): void;
11
+ installPackages(): Promise<unknown>;
12
+ }
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.NpmService = void 0;
10
+ const rxjs_1 = require("rxjs");
11
+ const childProcess = require("child_process");
12
+ const core_1 = require("@rxdi/core");
13
+ let NpmService = class NpmService {
14
+ constructor() {
15
+ this.packagesToDownload = new rxjs_1.BehaviorSubject([]);
16
+ this.packages = [];
17
+ }
18
+ setPackages(packages) {
19
+ this.packagesToDownload.next([
20
+ ...this.packagesToDownload.getValue(),
21
+ ...packages,
22
+ ]);
23
+ }
24
+ preparePackages() {
25
+ const arr = this.packagesToDownload.getValue() || [];
26
+ this.packages = [...new Set(arr.map((p) => `${p.name}@${p.version}`))];
27
+ }
28
+ installPackages() {
29
+ return new Promise(() => {
30
+ this.preparePackages();
31
+ if (this.child) {
32
+ this.child.stdout.removeAllListeners('data');
33
+ this.child.stderr.removeAllListeners('data');
34
+ this.child.removeAllListeners('exit');
35
+ this.child.kill();
36
+ }
37
+ console.log(`Installing npm packages on child process! ${this.packages.toString()}`);
38
+ this.child = childProcess.spawn('npm', ['i', ...this.packages]);
39
+ this.child.stdout.on('data', (data) => process.stdout.write(data));
40
+ this.child.stderr.on('data', (data) => {
41
+ process.stdout.write(data);
42
+ // reject(data)
43
+ });
44
+ this.child.on('exit', (code) => {
45
+ console.log(`Child process exited with code ${code}`);
46
+ console.log(`Installing npm packages DONE! ${this.packages.toString()}`);
47
+ this.child = null;
48
+ });
49
+ });
50
+ }
51
+ };
52
+ NpmService = __decorate([
53
+ core_1.Service()
54
+ ], NpmService);
55
+ exports.NpmService = NpmService;
@@ -0,0 +1,5 @@
1
+ export declare const IPFS_PROVIDERS: {
2
+ name: IPFS_PROVIDERS;
3
+ link: string;
4
+ }[];
5
+ export declare type IPFS_PROVIDERS = 'cloudflare' | 'main-ipfs-node' | 'local' | 'infura';
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IPFS_PROVIDERS = void 0;
4
+ exports.IPFS_PROVIDERS = [
5
+ {
6
+ name: 'cloudflare',
7
+ link: 'https://cloudflare-ipfs.com/ipfs/',
8
+ },
9
+ {
10
+ name: 'main-ipfs-node',
11
+ link: 'https://ipfs.io/ipfs/',
12
+ },
13
+ {
14
+ name: 'infura',
15
+ link: 'https://ipfs.infura.io/ipfs/',
16
+ },
17
+ {
18
+ name: 'local',
19
+ link: 'http://127.0.0.1:8080/ipfs/',
20
+ },
21
+ ];
@@ -0,0 +1,7 @@
1
+ import { CacheLayer, CacheLayerItem, CacheService } from '@rxdi/core';
2
+ export declare class RequestCacheService extends CacheService {
3
+ cacheLayer: CacheLayer<CacheLayerItem<any>>;
4
+ constructor();
5
+ put(key: any, data: any): CacheLayerItem<any>;
6
+ get(key: any): CacheLayerItem<any>;
7
+ }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.RequestCacheService = void 0;
13
+ /* eslint-disable @typescript-eslint/no-explicit-any */
14
+ const core_1 = require("@rxdi/core");
15
+ let RequestCacheService = class RequestCacheService extends core_1.CacheService {
16
+ constructor() {
17
+ super(core_1.Container.get(core_1.BootstrapLogger));
18
+ this.cacheLayer = this.createLayer({ name: 'request-cache-layer' });
19
+ }
20
+ put(key, data) {
21
+ return this.cacheLayer.putItem({ key, data });
22
+ }
23
+ get(key) {
24
+ return this.cacheLayer.getItem(key);
25
+ }
26
+ };
27
+ RequestCacheService = __decorate([
28
+ core_1.Service(),
29
+ __metadata("design:paramtypes", [])
30
+ ], RequestCacheService);
31
+ exports.RequestCacheService = RequestCacheService;
@@ -0,0 +1,6 @@
1
+ import { Observable } from 'rxjs';
2
+ export declare class RequestService {
3
+ private cache;
4
+ private logger;
5
+ get(link: string): Observable<any>;
6
+ }
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.RequestService = void 0;
13
+ const core_1 = require("@rxdi/core");
14
+ const http_1 = require("http");
15
+ const https_1 = require("https");
16
+ const rxjs_1 = require("rxjs");
17
+ const operators_1 = require("rxjs/operators");
18
+ const request_cache_1 = require("./request-cache");
19
+ let RequestService = class RequestService {
20
+ get(link) {
21
+ if (this.cache.cacheLayer.map.has(link)) {
22
+ this.logger.log(`Item returned from cacahe: ${link}`);
23
+ return rxjs_1.of(this.cache.cacheLayer.get(link).data);
24
+ }
25
+ return new rxjs_1.Observable((o) => {
26
+ if (link.includes('https://')) {
27
+ https_1.get(link, (resp) => {
28
+ let data = '';
29
+ resp.on('data', (chunk) => (data += chunk));
30
+ resp.on('end', () => o.next(data));
31
+ }).on('error', (err) => {
32
+ console.error('Error: ' + err.message);
33
+ o.error(err);
34
+ });
35
+ }
36
+ else {
37
+ http_1.get(link, (resp) => {
38
+ let data = '';
39
+ resp.on('data', (chunk) => (data += chunk));
40
+ resp.on('end', () => o.next(data));
41
+ }).on('error', (err) => {
42
+ console.error('Error: ' + err.message);
43
+ o.error(err);
44
+ });
45
+ }
46
+ }).pipe(operators_1.tap((res) => this.cache.cacheLayer.putItem({ key: link, data: res })));
47
+ }
48
+ };
49
+ __decorate([
50
+ core_1.Injector(request_cache_1.RequestCacheService),
51
+ __metadata("design:type", request_cache_1.RequestCacheService)
52
+ ], RequestService.prototype, "cache", void 0);
53
+ __decorate([
54
+ core_1.Injector(core_1.BootstrapLogger),
55
+ __metadata("design:type", core_1.BootstrapLogger)
56
+ ], RequestService.prototype, "logger", void 0);
57
+ RequestService = __decorate([
58
+ core_1.Service()
59
+ ], RequestService);
60
+ exports.RequestService = RequestService;
@@ -1,4 +1,4 @@
1
- import { ExternalImporterConfig } from '@gapi/core';
1
+ import { ExternalImporterConfig } from './ipfs/external-importer-config';
2
2
  export interface IPFS_MODULE_MAP {
3
3
  hash: string;
4
4
  module: ExternalImporterConfig;
@@ -1,5 +1,7 @@
1
- import { ExternalImporter, FileService, Metadata } from '@rxdi/core';
1
+ import { Metadata } from '@rxdi/core';
2
+ import { FileService } from '../../../core/services/file';
2
3
  import { IpfsHashMapService } from './ipfs-hash-map.service';
4
+ import { ExternalImporter } from './ipfs/external-importer';
3
5
  import { PluginWatcherService } from './plugin-watcher.service';
4
6
  interface CustomMetadata extends Function {
5
7
  metadata: Metadata;
@@ -25,8 +25,10 @@ const fs_1 = require("fs");
25
25
  const rxjs_1 = require("rxjs");
26
26
  const operators_1 = require("rxjs/operators");
27
27
  const util_1 = require("util");
28
+ const file_1 = require("../../../core/services/file");
28
29
  const daemon_config_1 = require("../../daemon.config");
29
30
  const ipfs_hash_map_service_1 = require("./ipfs-hash-map.service");
31
+ const external_importer_1 = require("./ipfs/external-importer");
30
32
  const plugin_watcher_service_1 = require("./plugin-watcher.service");
31
33
  let PluginLoader = class PluginLoader {
32
34
  constructor(externalImporterService, fileService, pluginWatcherService, ipfsHashMapService) {
@@ -108,8 +110,8 @@ let PluginLoader = class PluginLoader {
108
110
  };
109
111
  PluginLoader = __decorate([
110
112
  core_1.Injectable(),
111
- __metadata("design:paramtypes", [core_1.ExternalImporter,
112
- core_1.FileService,
113
+ __metadata("design:paramtypes", [external_importer_1.ExternalImporter,
114
+ file_1.FileService,
113
115
  plugin_watcher_service_1.PluginWatcherService,
114
116
  ipfs_hash_map_service_1.IpfsHashMapService])
115
117
  ], PluginLoader);
@@ -1,5 +1,5 @@
1
1
  import { CoreModuleConfig } from '@gapi/core';
2
- import { FileService } from '@rxdi/core';
2
+ import { FileService } from '../core/services/file';
3
3
  export declare const DaemonTasks: {
4
4
  start: "start";
5
5
  stop: "stop";
@@ -33,6 +33,7 @@ const helpers_1 = require("../core/helpers");
33
33
  const ps_list_1 = require("../core/helpers/ps-list");
34
34
  const stringEnum_1 = require("../core/helpers/stringEnum");
35
35
  const daemon_executor_service_1 = require("../core/services/daemon-executor/daemon-executor.service");
36
+ const file_1 = require("../core/services/file");
36
37
  const daemon_config_1 = require("../daemon-server/daemon.config");
37
38
  const bootstrap_1 = require("./bootstrap");
38
39
  exports.DaemonTasks = stringEnum_1.strEnum([
@@ -334,6 +335,6 @@ let DaemonTask = class DaemonTask {
334
335
  };
335
336
  DaemonTask = __decorate([
336
337
  core_2.Service(),
337
- __metadata("design:paramtypes", [core_2.FileService])
338
+ __metadata("design:paramtypes", [file_1.FileService])
338
339
  ], DaemonTask);
339
340
  exports.DaemonTask = DaemonTask;
@@ -16,19 +16,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
16
16
  };
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.SchemaTask = void 0;
19
+ const compressor_1 = require("@rxdi/compressor");
19
20
  const core_1 = require("@rxdi/core");
20
21
  const fs_1 = require("fs");
22
+ const node_fetch_1 = require("node-fetch");
21
23
  const rxjs_1 = require("rxjs");
22
24
  const operators_1 = require("rxjs/operators");
23
25
  const util_1 = require("util");
26
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
27
+ const mkdirp_1 = require("../core/helpers/mkdirp");
24
28
  const args_service_1 = require("../core/services/args.service");
25
29
  const config_service_1 = require("../core/services/config.service");
26
30
  const exec_service_1 = require("../core/services/exec.service");
27
31
  const daemon_config_1 = require("../daemon-server/daemon.config");
28
- // eslint-disable-next-line @typescript-eslint/no-var-requires
29
- const { mkdirp } = require('@rxdi/core/dist/services/file/dist');
30
- const compressor_1 = require("@rxdi/compressor");
31
- const node_fetch_1 = require("node-fetch");
32
32
  let SchemaTask = class SchemaTask {
33
33
  constructor() {
34
34
  this.execService = core_1.Container.get(exec_service_1.ExecService);
@@ -73,9 +73,9 @@ let SchemaTask = class SchemaTask {
73
73
  createDir() {
74
74
  return __awaiter(this, void 0, void 0, function* () {
75
75
  if (!(yield util_1.promisify(fs_1.exists)(this.folder))) {
76
- yield util_1.promisify(mkdirp)(this.folder);
76
+ yield util_1.promisify(mkdirp_1.mkdirp)(this.folder);
77
77
  }
78
- yield util_1.promisify(mkdirp)(daemon_config_1.GAPI_DAEMON_CACHE_FOLDER);
78
+ yield util_1.promisify(mkdirp_1.mkdirp)(daemon_config_1.GAPI_DAEMON_CACHE_FOLDER);
79
79
  });
80
80
  }
81
81
  collectFragments() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gapi/cli",
3
- "version": "1.8.124",
3
+ "version": "1.8.125",
4
4
  "description": "Gapi command line interface",
5
5
  "main": "./dist/main.js",
6
6
  "types": "./dist/main.d.ts",
@@ -34,9 +34,9 @@
34
34
  "author": "Kristiyan Tachev (@Stradivario)",
35
35
  "license": "MIT",
36
36
  "dependencies": {
37
- "@gapi/core": "^1.8.123",
37
+ "@gapi/core": "^1.8.124",
38
38
  "graphql": "^14.6.0",
39
- "@gapi/schematics": "^1.8.123",
39
+ "@gapi/schematics": "^1.8.124",
40
40
  "node-fetch": "^2.1.2",
41
41
  "@zeit/ncc": "^0.22.1",
42
42
  "apollo-codegen": "0.20.2",
@@ -45,9 +45,9 @@
45
45
  "cli-spinner": "0.2.8",
46
46
  "commander": "8.2.0",
47
47
  "figlet": "1.2.1",
48
- "@rxdi/compressor": "^0.7.114",
48
+ "@rxdi/compressor": "^0.7.134",
49
49
  "graphql-document-collector": "0.2.1",
50
- "humps": "2.0.1",
50
+ "systemjs": "0.21.4",
51
51
  "node-emoji": "1.10.0",
52
52
  "node-notifier": "^5.4.0",
53
53
  "parcel-bundler": "1.12.3",