oc 0.49.7 → 0.49.8
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/CHANGELOG.md +22 -0
- package/README.md +2 -15
- package/dist/cli/domain/clean.d.ts +2 -2
- package/dist/cli/domain/clean.js +10 -13
- package/dist/cli/domain/get-components-by-dir.d.ts +1 -1
- package/dist/cli/domain/get-components-by-dir.js +8 -15
- package/dist/cli/domain/get-mocked-plugins.js +8 -6
- package/dist/cli/domain/handle-dependencies/ensure-compiler-is-declared-as-devDependency.d.ts +1 -1
- package/dist/cli/domain/handle-dependencies/ensure-compiler-is-declared-as-devDependency.js +4 -5
- package/dist/cli/domain/handle-dependencies/get-compiler.d.ts +1 -1
- package/dist/cli/domain/handle-dependencies/get-compiler.js +3 -3
- package/dist/cli/domain/handle-dependencies/index.d.ts +4 -3
- package/dist/cli/domain/handle-dependencies/index.js +40 -34
- package/dist/cli/domain/handle-dependencies/install-compiler.d.ts +1 -1
- package/dist/cli/domain/handle-dependencies/install-compiler.js +14 -7
- package/dist/cli/domain/handle-dependencies/install-missing-dependencies.d.ts +1 -1
- package/dist/cli/domain/handle-dependencies/install-missing-dependencies.js +13 -9
- package/dist/cli/domain/handle-dependencies/link-missing-dependencies.d.ts +1 -1
- package/dist/cli/domain/handle-dependencies/link-missing-dependencies.js +4 -8
- package/dist/cli/domain/init-template/index.d.ts +2 -2
- package/dist/cli/domain/init-template/index.js +6 -8
- package/dist/cli/domain/init-template/install-template.d.ts +2 -2
- package/dist/cli/domain/init-template/install-template.js +10 -9
- package/dist/cli/domain/init-template/scaffold.d.ts +2 -2
- package/dist/cli/domain/init-template/scaffold.js +7 -7
- package/dist/cli/domain/local.js +11 -10
- package/dist/cli/domain/mock.d.ts +1 -1
- package/dist/cli/domain/mock.js +21 -21
- package/dist/cli/domain/package-components.d.ts +1 -1
- package/dist/cli/domain/package-components.js +14 -17
- package/dist/cli/domain/registry.js +68 -81
- package/dist/cli/domain/watch.js +1 -1
- package/dist/cli/facade/clean.d.ts +10 -4
- package/dist/cli/facade/clean.js +38 -28
- package/dist/cli/facade/dev.d.ts +108 -15
- package/dist/cli/facade/dev.js +85 -99
- package/dist/cli/facade/init.d.ts +12 -5
- package/dist/cli/facade/init.js +22 -20
- package/dist/cli/facade/mock.d.ts +12 -5
- package/dist/cli/facade/mock.js +5 -6
- package/dist/cli/facade/package.d.ts +12 -5
- package/dist/cli/facade/package.js +30 -32
- package/dist/cli/facade/preview.d.ts +8 -3
- package/dist/cli/facade/preview.js +12 -10
- package/dist/cli/facade/publish.d.ts +16 -7
- package/dist/cli/facade/publish.js +94 -114
- package/dist/cli/facade/registry-add.d.ts +8 -3
- package/dist/cli/facade/registry-add.js +10 -9
- package/dist/cli/facade/registry-ls.d.ts +4 -1
- package/dist/cli/facade/registry-ls.js +19 -17
- package/dist/cli/facade/registry-remove.d.ts +8 -3
- package/dist/cli/facade/registry-remove.js +10 -9
- package/dist/cli/facade/registry.d.ts +4 -1
- package/dist/cli/facade/registry.js +6 -3
- package/dist/cli/index.js +3 -5
- package/dist/cli/programmatic-api.d.ts +1 -1
- package/dist/components/oc-client/_package/package.json +1 -1
- package/dist/components/oc-client/package.json +1 -1
- package/dist/registry/app-start.d.ts +2 -2
- package/dist/registry/app-start.js +20 -20
- package/dist/registry/domain/components-cache/components-list.d.ts +7 -6
- package/dist/registry/domain/components-cache/components-list.js +31 -45
- package/dist/registry/domain/components-cache/index.d.ts +6 -5
- package/dist/registry/domain/components-cache/index.js +47 -50
- package/dist/registry/domain/components-details.d.ts +5 -4
- package/dist/registry/domain/components-details.js +27 -38
- package/dist/registry/domain/extract-package.d.ts +2 -2
- package/dist/registry/domain/extract-package.js +9 -12
- package/dist/registry/domain/get-package-json-from-temp-dir.d.ts +1 -1
- package/dist/registry/domain/get-package-json-from-temp-dir.js +2 -2
- package/dist/registry/domain/nested-renderer.d.ts +7 -6
- package/dist/registry/domain/nested-renderer.js +36 -72
- package/dist/registry/domain/options-sanitiser.js +5 -3
- package/dist/registry/domain/plugins-initialiser.d.ts +3 -1
- package/dist/registry/domain/plugins-initialiser.js +29 -33
- package/dist/registry/domain/repository.js +78 -100
- package/dist/registry/domain/require-wrapper.js +1 -2
- package/dist/registry/domain/storage-adapter.d.ts +10 -0
- package/dist/registry/domain/storage-adapter.js +55 -0
- package/dist/registry/index.d.ts +2 -2
- package/dist/registry/index.js +15 -28
- package/dist/registry/middleware/index.d.ts +6 -2
- package/dist/registry/middleware/index.js +5 -1
- package/dist/registry/router.d.ts +2 -2
- package/dist/registry/router.js +0 -2
- package/dist/registry/routes/component-info.js +3 -2
- package/dist/registry/routes/component-preview.js +2 -1
- package/dist/registry/routes/components.js +1 -1
- package/dist/registry/routes/helpers/get-component-fallback.d.ts +2 -7
- package/dist/registry/routes/helpers/get-component.d.ts +5 -5
- package/dist/registry/routes/helpers/get-component.js +6 -5
- package/dist/registry/routes/helpers/is-url-discoverable.d.ts +2 -2
- package/dist/registry/routes/helpers/is-url-discoverable.js +15 -9
- package/dist/registry/routes/index.js +4 -3
- package/dist/registry/routes/publish.d.ts +1 -1
- package/dist/registry/routes/publish.js +32 -31
- package/dist/resources/settings.js +1 -1
- package/dist/types.d.ts +35 -43
- package/dist/utils/npm-utils.d.ts +6 -8
- package/dist/utils/npm-utils.js +20 -9
- package/dist/utils/put.d.ts +2 -1
- package/dist/utils/put.js +10 -29
- package/logintervals.md +1 -1
- package/package.json +6 -1
- package/src/cli/domain/clean.ts +10 -20
- package/src/cli/domain/get-components-by-dir.ts +12 -26
- package/src/cli/domain/get-mocked-plugins.ts +32 -26
- package/src/cli/domain/handle-dependencies/ensure-compiler-is-declared-as-devDependency.ts +8 -12
- package/src/cli/domain/handle-dependencies/get-compiler.ts +8 -11
- package/src/cli/domain/handle-dependencies/index.ts +55 -109
- package/src/cli/domain/handle-dependencies/install-compiler.ts +22 -15
- package/src/cli/domain/handle-dependencies/install-missing-dependencies.ts +19 -13
- package/src/cli/domain/handle-dependencies/link-missing-dependencies.ts +8 -16
- package/src/cli/domain/init-template/index.ts +13 -20
- package/src/cli/domain/init-template/install-template.ts +11 -12
- package/src/cli/domain/init-template/scaffold.ts +9 -12
- package/src/cli/domain/local.ts +19 -22
- package/src/cli/domain/mock.ts +32 -36
- package/src/cli/domain/package-components.ts +14 -25
- package/src/cli/domain/registry.ts +80 -116
- package/src/cli/domain/watch.ts +1 -1
- package/src/cli/facade/clean.ts +37 -37
- package/src/cli/facade/dev.ts +159 -182
- package/src/cli/facade/init.ts +36 -38
- package/src/cli/facade/mock.ts +11 -10
- package/src/cli/facade/package.ts +44 -49
- package/src/cli/facade/preview.ts +20 -18
- package/src/cli/facade/publish.ts +134 -172
- package/src/cli/facade/registry-add.ts +16 -15
- package/src/cli/facade/registry-ls.ts +27 -22
- package/src/cli/facade/registry-remove.ts +16 -15
- package/src/cli/facade/registry.ts +7 -5
- package/src/cli/index.ts +3 -5
- package/src/components/oc-client/_package/package.json +1 -1
- package/src/components/oc-client/package.json +1 -1
- package/src/globals.d.ts +38 -0
- package/src/registry/app-start.ts +27 -31
- package/src/registry/domain/components-cache/components-list.ts +45 -67
- package/src/registry/domain/components-cache/index.ts +55 -60
- package/src/registry/domain/components-details.ts +49 -75
- package/src/registry/domain/extract-package.ts +19 -27
- package/src/registry/domain/get-package-json-from-temp-dir.ts +3 -4
- package/src/registry/domain/nested-renderer.ts +64 -122
- package/src/registry/domain/options-sanitiser.ts +6 -3
- package/src/registry/domain/plugins-initialiser.ts +45 -49
- package/src/registry/domain/repository.ts +129 -235
- package/src/registry/domain/require-wrapper.ts +1 -2
- package/src/registry/domain/storage-adapter.ts +85 -0
- package/src/registry/index.ts +48 -79
- package/src/registry/middleware/index.ts +10 -2
- package/src/registry/router.ts +2 -10
- package/src/registry/routes/component-info.ts +4 -3
- package/src/registry/routes/component-preview.ts +3 -2
- package/src/registry/routes/components.ts +1 -1
- package/src/registry/routes/helpers/get-component-fallback.ts +3 -9
- package/src/registry/routes/helpers/get-component.ts +11 -9
- package/src/registry/routes/helpers/is-url-discoverable.ts +14 -15
- package/src/registry/routes/index.ts +18 -13
- package/src/registry/routes/publish.ts +31 -34
- package/src/resources/settings.ts +1 -1
- package/src/types.ts +63 -136
- package/src/utils/npm-utils.ts +38 -37
- package/src/utils/put.ts +15 -37
|
@@ -4,21 +4,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.init = void 0;
|
|
7
|
-
const
|
|
7
|
+
const p_limit_1 = __importDefault(require("p-limit"));
|
|
8
8
|
const lodash_1 = __importDefault(require("lodash"));
|
|
9
9
|
const dependency_graph_1 = require("dependency-graph");
|
|
10
|
+
const util_1 = require("util");
|
|
10
11
|
const resources_1 = __importDefault(require("../../resources"));
|
|
11
12
|
function validatePlugins(plugins) {
|
|
12
|
-
let
|
|
13
|
-
|
|
14
|
-
c++;
|
|
13
|
+
for (let idx = 0; idx < plugins.length; idx++) {
|
|
14
|
+
const plugin = plugins[idx];
|
|
15
15
|
if (!lodash_1.default.isObject(plugin.register) ||
|
|
16
16
|
typeof plugin.register.register !== 'function' ||
|
|
17
17
|
typeof plugin.register.execute !== 'function' ||
|
|
18
18
|
typeof plugin.name !== 'string') {
|
|
19
|
-
throw new Error(resources_1.default.errors.registry.PLUGIN_NOT_VALID(plugin.name || String(
|
|
19
|
+
throw new Error(resources_1.default.errors.registry.PLUGIN_NOT_VALID(plugin.name || String(idx + 1)));
|
|
20
20
|
}
|
|
21
|
-
}
|
|
21
|
+
}
|
|
22
22
|
}
|
|
23
23
|
function checkDependencies(plugins) {
|
|
24
24
|
const graph = new dependency_graph_1.DepGraph();
|
|
@@ -39,19 +39,10 @@ function checkDependencies(plugins) {
|
|
|
39
39
|
return graph.overallOrder();
|
|
40
40
|
}
|
|
41
41
|
let deferredLoads = [];
|
|
42
|
-
|
|
43
|
-
deferredLoads.push(plugin);
|
|
44
|
-
return cb();
|
|
45
|
-
};
|
|
46
|
-
function init(pluginsToRegister, callback) {
|
|
42
|
+
async function init(pluginsToRegister) {
|
|
47
43
|
const registered = {};
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
checkDependencies(pluginsToRegister);
|
|
51
|
-
}
|
|
52
|
-
catch (err) {
|
|
53
|
-
return callback(err, undefined);
|
|
54
|
-
}
|
|
44
|
+
validatePlugins(pluginsToRegister);
|
|
45
|
+
checkDependencies(pluginsToRegister);
|
|
55
46
|
const dependenciesRegistered = (dependencies) => {
|
|
56
47
|
if (dependencies.length === 0) {
|
|
57
48
|
return true;
|
|
@@ -64,36 +55,41 @@ function init(pluginsToRegister, callback) {
|
|
|
64
55
|
});
|
|
65
56
|
return present;
|
|
66
57
|
};
|
|
67
|
-
const loadPlugin = (plugin
|
|
68
|
-
const done = lodash_1.default.once(cb);
|
|
58
|
+
const loadPlugin = async (plugin) => {
|
|
69
59
|
if (registered[plugin.name]) {
|
|
70
|
-
return
|
|
60
|
+
return;
|
|
71
61
|
}
|
|
72
62
|
if (!plugin.register.dependencies) {
|
|
73
63
|
plugin.register.dependencies = [];
|
|
74
64
|
}
|
|
75
65
|
if (!dependenciesRegistered(plugin.register.dependencies)) {
|
|
76
|
-
|
|
66
|
+
deferredLoads.push(plugin);
|
|
67
|
+
return;
|
|
77
68
|
}
|
|
78
69
|
const dependencies = lodash_1.default.pick(registered, plugin.register.dependencies);
|
|
79
|
-
|
|
80
|
-
|
|
70
|
+
const register = (0, util_1.promisify)(plugin.register.register);
|
|
71
|
+
const pluginCallback = plugin.callback || lodash_1.default.noop;
|
|
72
|
+
await register(plugin.options || {}, dependencies).catch(err => {
|
|
81
73
|
pluginCallback(err);
|
|
82
|
-
|
|
83
|
-
// leak to OC consumers
|
|
84
|
-
plugin.register.execute.toString = () => plugin.description || '';
|
|
85
|
-
registered[plugin.name] = plugin.register.execute;
|
|
86
|
-
done(err);
|
|
74
|
+
throw err;
|
|
87
75
|
});
|
|
76
|
+
// Overriding toString so implementation details of plugins do not
|
|
77
|
+
// leak to OC consumers
|
|
78
|
+
plugin.register.execute.toString = () => plugin.description || '';
|
|
79
|
+
registered[plugin.name] = plugin.register.execute;
|
|
80
|
+
pluginCallback();
|
|
88
81
|
};
|
|
89
|
-
const terminator =
|
|
82
|
+
const terminator = async () => {
|
|
90
83
|
if (deferredLoads.length > 0) {
|
|
91
84
|
const deferredPlugins = lodash_1.default.clone(deferredLoads);
|
|
92
85
|
deferredLoads = [];
|
|
93
|
-
|
|
86
|
+
await Promise.all(deferredPlugins.map(plugin => onSeries(() => loadPlugin(plugin))));
|
|
87
|
+
return terminator();
|
|
94
88
|
}
|
|
95
|
-
|
|
89
|
+
return registered;
|
|
96
90
|
};
|
|
97
|
-
|
|
91
|
+
const onSeries = (0, p_limit_1.default)(1);
|
|
92
|
+
await Promise.all(pluginsToRegister.map(plugin => onSeries(() => loadPlugin(plugin))));
|
|
93
|
+
return terminator();
|
|
98
94
|
}
|
|
99
95
|
exports.init = init;
|
|
@@ -25,18 +25,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
25
25
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
26
26
|
const oc_get_unix_utc_timestamp_1 = __importDefault(require("oc-get-unix-utc-timestamp"));
|
|
27
27
|
const path_1 = __importDefault(require("path"));
|
|
28
|
-
const lodash_1 = __importDefault(require("lodash"));
|
|
29
28
|
const components_cache_1 = __importDefault(require("./components-cache"));
|
|
30
29
|
const components_details_1 = __importDefault(require("./components-details"));
|
|
31
30
|
const register_templates_1 = __importDefault(require("./register-templates"));
|
|
32
31
|
const settings_1 = __importDefault(require("../../resources/settings"));
|
|
33
32
|
const resources_1 = __importDefault(require("../../resources"));
|
|
34
33
|
const validator = __importStar(require("./validators"));
|
|
34
|
+
const storage_adapter_1 = __importDefault(require("./storage-adapter"));
|
|
35
35
|
const versionHandler = __importStar(require("./version-handler"));
|
|
36
36
|
const error_to_string_1 = __importDefault(require("../../utils/error-to-string"));
|
|
37
37
|
const packageInfo = fs_extra_1.default.readJsonSync(path_1.default.join(__dirname, '..', '..', '..', 'package.json'));
|
|
38
38
|
function repository(conf) {
|
|
39
|
-
const cdn = !conf.local &&
|
|
39
|
+
const cdn = !conf.local &&
|
|
40
|
+
(0, storage_adapter_1.default)(conf.storage.adapter(conf.storage.options));
|
|
40
41
|
const options = !conf.local ? conf.storage.options : null;
|
|
41
42
|
const repositorySource = conf.local
|
|
42
43
|
? 'local repository'
|
|
@@ -70,18 +71,21 @@ function repository(conf) {
|
|
|
70
71
|
validComponents.push('oc-client');
|
|
71
72
|
return validComponents;
|
|
72
73
|
},
|
|
73
|
-
getComponentVersions(componentName
|
|
74
|
+
getComponentVersions(componentName) {
|
|
74
75
|
if (componentName === 'oc-client') {
|
|
75
|
-
return
|
|
76
|
-
fs_extra_1.default
|
|
76
|
+
return Promise.all([
|
|
77
|
+
fs_extra_1.default
|
|
78
|
+
.readJson(path_1.default.join(__dirname, '../../../package.json'))
|
|
79
|
+
.then(x => x.version)
|
|
77
80
|
]);
|
|
78
81
|
}
|
|
79
|
-
if (!
|
|
80
|
-
return
|
|
82
|
+
if (!local.getComponents().includes(componentName)) {
|
|
83
|
+
return Promise.reject(resources_1.default.errors.registry.COMPONENT_NOT_FOUND(componentName, repositorySource));
|
|
81
84
|
}
|
|
82
|
-
|
|
83
|
-
fs_extra_1.default
|
|
84
|
-
.
|
|
85
|
+
return Promise.all([
|
|
86
|
+
fs_extra_1.default
|
|
87
|
+
.readJson(path_1.default.join(conf.path, `${componentName}/package.json`))
|
|
88
|
+
.then(x => x.version)
|
|
85
89
|
]);
|
|
86
90
|
},
|
|
87
91
|
getDataProvider(componentName) {
|
|
@@ -96,39 +100,29 @@ function repository(conf) {
|
|
|
96
100
|
}
|
|
97
101
|
};
|
|
98
102
|
const repository = {
|
|
99
|
-
getCompiledView(componentName, componentVersion
|
|
103
|
+
getCompiledView(componentName, componentVersion) {
|
|
100
104
|
if (conf.local) {
|
|
101
|
-
return
|
|
105
|
+
return Promise.resolve(local.getCompiledView(componentName));
|
|
102
106
|
}
|
|
103
|
-
cdn.getFile(getFilePath(componentName, componentVersion, 'template.js')
|
|
107
|
+
return cdn.getFile(getFilePath(componentName, componentVersion, 'template.js'));
|
|
104
108
|
},
|
|
105
|
-
getComponent(componentName,
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
const version = versionHandler.getAvailableVersion(componentVersion, allVersions);
|
|
120
|
-
if (!version) {
|
|
121
|
-
return callback(resources_1.default.errors.registry.COMPONENT_VERSION_NOT_FOUND(componentName, componentVersion || '', repositorySource), undefined);
|
|
122
|
-
}
|
|
123
|
-
repository.getComponentInfo(componentName, version, (err, component) => {
|
|
124
|
-
if (err) {
|
|
125
|
-
return callback(`component not available: ${(0, error_to_string_1.default)(err)}`, null);
|
|
126
|
-
}
|
|
127
|
-
callback(null, Object.assign(component, { allVersions }));
|
|
128
|
-
});
|
|
109
|
+
async getComponent(componentName, componentVersion) {
|
|
110
|
+
const allVersions = await repository.getComponentVersions(componentName);
|
|
111
|
+
if (allVersions.length === 0) {
|
|
112
|
+
throw resources_1.default.errors.registry.COMPONENT_NOT_FOUND(componentName, repositorySource);
|
|
113
|
+
}
|
|
114
|
+
const version = versionHandler.getAvailableVersion(componentVersion, allVersions);
|
|
115
|
+
if (!version) {
|
|
116
|
+
throw resources_1.default.errors.registry.COMPONENT_VERSION_NOT_FOUND(componentName, componentVersion || '', repositorySource);
|
|
117
|
+
}
|
|
118
|
+
const component = await repository
|
|
119
|
+
.getComponentInfo(componentName, version)
|
|
120
|
+
.catch(err => {
|
|
121
|
+
throw `component not available: ${(0, error_to_string_1.default)(err)}`;
|
|
129
122
|
});
|
|
123
|
+
return Object.assign(component, { allVersions });
|
|
130
124
|
},
|
|
131
|
-
getComponentInfo(componentName, componentVersion
|
|
125
|
+
getComponentInfo(componentName, componentVersion) {
|
|
132
126
|
if (conf.local) {
|
|
133
127
|
let componentInfo;
|
|
134
128
|
if (componentName === 'oc-client') {
|
|
@@ -138,13 +132,14 @@ function repository(conf) {
|
|
|
138
132
|
componentInfo = fs_extra_1.default.readJsonSync(path_1.default.join(conf.path, `${componentName}/_package/package.json`));
|
|
139
133
|
}
|
|
140
134
|
if (componentInfo.version === componentVersion) {
|
|
141
|
-
return
|
|
135
|
+
return Promise.resolve(componentInfo);
|
|
142
136
|
}
|
|
143
137
|
else {
|
|
144
|
-
|
|
138
|
+
// eslint-disable-next-line prefer-promise-reject-errors
|
|
139
|
+
return Promise.reject('version not available');
|
|
145
140
|
}
|
|
146
141
|
}
|
|
147
|
-
cdn.getJson(getFilePath(componentName, componentVersion, 'package.json'),
|
|
142
|
+
return cdn.getJson(getFilePath(componentName, componentVersion, 'package.json'), false);
|
|
148
143
|
},
|
|
149
144
|
getComponentPath(componentName, componentVersion) {
|
|
150
145
|
const prefix = conf.local
|
|
@@ -152,106 +147,89 @@ function repository(conf) {
|
|
|
152
147
|
: `${options['path']}${options.componentsDir}/`;
|
|
153
148
|
return `${prefix}${componentName}/${componentVersion}/`;
|
|
154
149
|
},
|
|
155
|
-
getComponents(
|
|
150
|
+
async getComponents() {
|
|
156
151
|
if (conf.local) {
|
|
157
|
-
return
|
|
152
|
+
return local.getComponents();
|
|
158
153
|
}
|
|
159
|
-
|
|
154
|
+
const { components } = await componentsCache.get();
|
|
155
|
+
return Object.keys(components);
|
|
160
156
|
},
|
|
161
|
-
getComponentsDetails(
|
|
157
|
+
getComponentsDetails() {
|
|
162
158
|
if (conf.local) {
|
|
163
|
-
|
|
159
|
+
// when in local this won't get called
|
|
160
|
+
return Promise.resolve(null);
|
|
164
161
|
}
|
|
165
|
-
componentsDetails.get(
|
|
162
|
+
return componentsDetails.get();
|
|
166
163
|
},
|
|
167
|
-
getComponentVersions(componentName
|
|
164
|
+
async getComponentVersions(componentName) {
|
|
168
165
|
if (conf.local) {
|
|
169
|
-
return local.getComponentVersions(componentName
|
|
166
|
+
return local.getComponentVersions(componentName);
|
|
170
167
|
}
|
|
171
|
-
componentsCache.get(
|
|
172
|
-
|
|
173
|
-
? res.components[componentName]
|
|
174
|
-
: []);
|
|
175
|
-
});
|
|
168
|
+
const res = await componentsCache.get();
|
|
169
|
+
return res.components[componentName] ? res.components[componentName] : [];
|
|
176
170
|
},
|
|
177
|
-
getDataProvider(componentName, componentVersion
|
|
171
|
+
async getDataProvider(componentName, componentVersion) {
|
|
178
172
|
if (conf.local) {
|
|
179
|
-
return
|
|
173
|
+
return local.getDataProvider(componentName);
|
|
180
174
|
}
|
|
181
175
|
const filePath = getFilePath(componentName, componentVersion, 'server.js');
|
|
182
|
-
|
|
176
|
+
const content = await cdn.getFile(filePath);
|
|
177
|
+
return { content, filePath };
|
|
183
178
|
},
|
|
184
179
|
getStaticClientPath: () => `${options['path']}${getFilePath('oc-client', packageInfo.version, 'src/oc-client.min.js')}`,
|
|
185
180
|
getStaticClientMapPath: () => `${options['path']}${getFilePath('oc-client', packageInfo.version, 'src/oc-client.min.map')}`,
|
|
186
181
|
getStaticFilePath: (componentName, componentVersion, filePath) => `${repository.getComponentPath(componentName, componentVersion)}${conf.local ? settings_1.default.registry.localStaticRedirectorPath : ''}${filePath}`,
|
|
187
182
|
getTemplatesInfo: () => templatesInfo,
|
|
188
183
|
getTemplate: (type) => templatesHash[type],
|
|
189
|
-
init(
|
|
184
|
+
async init() {
|
|
190
185
|
if (conf.local) {
|
|
191
|
-
|
|
186
|
+
// when in local this won't get called
|
|
187
|
+
return 'ok';
|
|
192
188
|
}
|
|
193
|
-
componentsCache.load(
|
|
194
|
-
|
|
195
|
-
return callback(err, undefined);
|
|
196
|
-
}
|
|
197
|
-
componentsDetails.refresh(componentsList, err => callback(err, componentsList));
|
|
198
|
-
});
|
|
189
|
+
const componentsList = await componentsCache.load();
|
|
190
|
+
return componentsDetails.refresh(componentsList);
|
|
199
191
|
},
|
|
200
|
-
publishComponent(pkgDetails, componentName, componentVersion
|
|
192
|
+
async publishComponent(pkgDetails, componentName, componentVersion) {
|
|
201
193
|
if (conf.local) {
|
|
202
|
-
|
|
194
|
+
throw {
|
|
203
195
|
code: resources_1.default.errors.registry.LOCAL_PUBLISH_NOT_ALLOWED_CODE,
|
|
204
196
|
msg: resources_1.default.errors.registry.LOCAL_PUBLISH_NOT_ALLOWED
|
|
205
|
-
}
|
|
197
|
+
};
|
|
206
198
|
}
|
|
207
199
|
if (!validator.validateComponentName(componentName)) {
|
|
208
|
-
|
|
200
|
+
throw {
|
|
209
201
|
code: resources_1.default.errors.registry.COMPONENT_NAME_NOT_VALID_CODE,
|
|
210
202
|
msg: resources_1.default.errors.registry.COMPONENT_NAME_NOT_VALID
|
|
211
|
-
}
|
|
203
|
+
};
|
|
212
204
|
}
|
|
213
205
|
if (!validator.validateVersion(componentVersion)) {
|
|
214
|
-
|
|
206
|
+
throw {
|
|
215
207
|
code: resources_1.default.errors.registry.COMPONENT_VERSION_NOT_VALID_CODE,
|
|
216
208
|
msg: resources_1.default.errors.registry.COMPONENT_VERSION_NOT_VALID(componentVersion)
|
|
217
|
-
}
|
|
209
|
+
};
|
|
218
210
|
}
|
|
219
211
|
const validationResult = validator.validatePackageJson(Object.assign(pkgDetails, {
|
|
220
212
|
componentName,
|
|
221
213
|
customValidator: conf.publishValidation
|
|
222
214
|
}));
|
|
223
215
|
if (!validationResult.isValid) {
|
|
224
|
-
|
|
216
|
+
throw {
|
|
225
217
|
code: resources_1.default.errors.registry.COMPONENT_PUBLISHVALIDATION_FAIL_CODE,
|
|
226
218
|
msg: resources_1.default.errors.registry.COMPONENT_PUBLISHVALIDATION_FAIL(String(validationResult.error))
|
|
227
|
-
}
|
|
219
|
+
};
|
|
228
220
|
}
|
|
229
|
-
repository.getComponentVersions(componentName
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
}
|
|
242
|
-
cdn.putDir(pkgDetails.outputFolder, `${options.componentsDir}/${componentName}/${componentVersion}`, err => {
|
|
243
|
-
if (err) {
|
|
244
|
-
return callback(err, undefined);
|
|
245
|
-
}
|
|
246
|
-
componentsCache.refresh((err, componentsList) => {
|
|
247
|
-
if (err) {
|
|
248
|
-
return callback(err, undefined);
|
|
249
|
-
}
|
|
250
|
-
componentsDetails.refresh(componentsList, callback);
|
|
251
|
-
});
|
|
252
|
-
});
|
|
253
|
-
});
|
|
254
|
-
});
|
|
221
|
+
const componentVersions = await repository.getComponentVersions(componentName);
|
|
222
|
+
if (!versionHandler.validateNewVersion(componentVersion, componentVersions)) {
|
|
223
|
+
throw {
|
|
224
|
+
code: resources_1.default.errors.registry.COMPONENT_VERSION_ALREADY_FOUND_CODE,
|
|
225
|
+
msg: resources_1.default.errors.registry.COMPONENT_VERSION_ALREADY_FOUND(componentName, componentVersion, repositorySource)
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
pkgDetails.packageJson.oc.date = (0, oc_get_unix_utc_timestamp_1.default)();
|
|
229
|
+
await fs_extra_1.default.writeJson(path_1.default.join(pkgDetails.outputFolder, 'package.json'), pkgDetails.packageJson);
|
|
230
|
+
await cdn.putDir(pkgDetails.outputFolder, `${options.componentsDir}/${componentName}/${componentVersion}`);
|
|
231
|
+
const componentsList = await componentsCache.refresh();
|
|
232
|
+
return componentsDetails.refresh(componentsList);
|
|
255
233
|
}
|
|
256
234
|
};
|
|
257
235
|
return repository;
|
|
@@ -7,7 +7,6 @@ const builtin_modules_1 = __importDefault(require("builtin-modules"));
|
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const require_package_name_1 = __importDefault(require("require-package-name"));
|
|
9
9
|
const try_require_1 = __importDefault(require("try-require"));
|
|
10
|
-
const lodash_1 = __importDefault(require("lodash"));
|
|
11
10
|
const resources_1 = __importDefault(require("../../resources"));
|
|
12
11
|
const isCoreDependency = (x) => builtin_modules_1.default.includes(x);
|
|
13
12
|
const requireCoreDependency = (x) => (isCoreDependency(x) && (0, try_require_1.default)(x)) || undefined;
|
|
@@ -24,7 +23,7 @@ const throwError = (requirePath) => {
|
|
|
24
23
|
};
|
|
25
24
|
exports.default = (injectedDependencies) => (requirePath) => {
|
|
26
25
|
const moduleName = (0, require_package_name_1.default)(requirePath);
|
|
27
|
-
const isAllowed =
|
|
26
|
+
const isAllowed = injectedDependencies.includes(moduleName);
|
|
28
27
|
if (!isAllowed) {
|
|
29
28
|
return throwError(requirePath);
|
|
30
29
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { StorageAdapter } from 'oc-storage-adapters-utils';
|
|
2
|
+
declare type RemovePromiseOverload<T> = T extends {
|
|
3
|
+
(...args: infer B): void;
|
|
4
|
+
(...args: any[]): Promise<any>;
|
|
5
|
+
} ? (...args: B) => void : T;
|
|
6
|
+
declare type LegacyStorageAdapter = {
|
|
7
|
+
[P in keyof StorageAdapter]: RemovePromiseOverload<StorageAdapter[P]>;
|
|
8
|
+
};
|
|
9
|
+
export default function getPromiseBasedAdapter(adapter: StorageAdapter | LegacyStorageAdapter): StorageAdapter;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const universalify_1 = require("universalify");
|
|
4
|
+
const officialAdapters = {
|
|
5
|
+
s3: { name: 'oc-s3-storage-adapter', firstPromiseBasedVersion: '1.2.0' },
|
|
6
|
+
gs: { name: 'oc-gs-storage-adapter', firstPromiseBasedVersion: '1.1.0' },
|
|
7
|
+
'azure-blob-storage': {
|
|
8
|
+
name: 'oc-azure-storage-adapter',
|
|
9
|
+
firstPromiseBasedVersion: '0.1.0'
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
function isOfficialAdapter(adapter) {
|
|
13
|
+
return Object.keys(officialAdapters).includes(adapter.adapterType);
|
|
14
|
+
}
|
|
15
|
+
function isPromiseBased(tryFunction) {
|
|
16
|
+
try {
|
|
17
|
+
tryFunction().catch(() => {
|
|
18
|
+
// To not throw unhandled promise exceptions
|
|
19
|
+
});
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
catch (err) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function isLegacyAdapter(adapter) {
|
|
27
|
+
return !isPromiseBased(() => adapter.getFile(''));
|
|
28
|
+
}
|
|
29
|
+
function convertLegacyAdapter(adapter) {
|
|
30
|
+
return {
|
|
31
|
+
getFile: (0, universalify_1.fromCallback)(adapter.getFile),
|
|
32
|
+
getJson: (0, universalify_1.fromCallback)(adapter.getJson),
|
|
33
|
+
listSubDirectories: (0, universalify_1.fromCallback)(adapter.listSubDirectories),
|
|
34
|
+
putDir: (0, universalify_1.fromCallback)(adapter.putDir),
|
|
35
|
+
putFile: (0, universalify_1.fromCallback)(adapter.putFile),
|
|
36
|
+
putFileContent: (0, universalify_1.fromCallback)(adapter.putFileContent),
|
|
37
|
+
getUrl: adapter.getUrl,
|
|
38
|
+
maxConcurrentRequests: adapter.maxConcurrentRequests,
|
|
39
|
+
adapterType: adapter.adapterType
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function getPromiseBasedAdapter(adapter) {
|
|
43
|
+
if (isLegacyAdapter(adapter)) {
|
|
44
|
+
if (isOfficialAdapter(adapter)) {
|
|
45
|
+
const pkg = officialAdapters[adapter.adapterType];
|
|
46
|
+
process.emitWarning(`Adapters now should work with promises. Consider upgrading your package ${pkg.name} to at least version ${pkg.firstPromiseBasedVersion}`, 'DeprecationWarning');
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
process.emitWarning('Your adapter is using the old interface of working with callbacks. Consider upgrading it to work with promises, as the previous one will be deprecated.', 'DeprecationWarning');
|
|
50
|
+
}
|
|
51
|
+
return convertLegacyAdapter(adapter);
|
|
52
|
+
}
|
|
53
|
+
return adapter;
|
|
54
|
+
}
|
|
55
|
+
exports.default = getPromiseBasedAdapter;
|
package/dist/registry/index.d.ts
CHANGED
|
@@ -39,10 +39,10 @@ export default function registry(inputOptions: Input): {
|
|
|
39
39
|
};
|
|
40
40
|
}[T]) => void) => void;
|
|
41
41
|
register: (plugin: Omit<Plugin, 'callback'>, callback?: ((...args: any[]) => void) | undefined) => void;
|
|
42
|
-
start: (callback: (err:
|
|
42
|
+
start: (callback: (err: unknown, data: {
|
|
43
43
|
app: express.Express;
|
|
44
44
|
server: http.Server;
|
|
45
|
-
}) => void) => void
|
|
45
|
+
}) => void) => Promise<void>;
|
|
46
46
|
app: express.Express;
|
|
47
47
|
};
|
|
48
48
|
export {};
|
package/dist/registry/index.js
CHANGED
|
@@ -22,7 +22,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
22
22
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
const async_1 = __importDefault(require("async"));
|
|
26
25
|
const safe_1 = __importDefault(require("colors/safe"));
|
|
27
26
|
const express_1 = __importDefault(require("express"));
|
|
28
27
|
const http_1 = __importDefault(require("http"));
|
|
@@ -32,7 +31,7 @@ const events_handler_1 = __importDefault(require("./domain/events-handler"));
|
|
|
32
31
|
const middleware = __importStar(require("./middleware"));
|
|
33
32
|
const pluginsInitialiser = __importStar(require("./domain/plugins-initialiser"));
|
|
34
33
|
const repository_1 = __importDefault(require("./domain/repository"));
|
|
35
|
-
const
|
|
34
|
+
const router_1 = require("./router");
|
|
36
35
|
const options_sanitiser_1 = __importDefault(require("./domain/options-sanitiser"));
|
|
37
36
|
const validator = __importStar(require("./domain/validators"));
|
|
38
37
|
function registry(inputOptions) {
|
|
@@ -42,7 +41,7 @@ function registry(inputOptions) {
|
|
|
42
41
|
}
|
|
43
42
|
const options = (0, options_sanitiser_1.default)(inputOptions);
|
|
44
43
|
const plugins = [];
|
|
45
|
-
const app = middleware.bind((0, express_1.default)(), options);
|
|
44
|
+
const { app, router } = middleware.bind((0, express_1.default)(), options);
|
|
46
45
|
let server;
|
|
47
46
|
const repository = (0, repository_1.default)(options);
|
|
48
47
|
const close = (callback) => {
|
|
@@ -54,26 +53,15 @@ function registry(inputOptions) {
|
|
|
54
53
|
const register = (plugin, callback) => {
|
|
55
54
|
plugins.push(Object.assign(plugin, { callback }));
|
|
56
55
|
};
|
|
57
|
-
const start = (callback) => {
|
|
56
|
+
const start = async (callback) => {
|
|
57
|
+
var _a;
|
|
58
58
|
// eslint-disable-next-line no-console
|
|
59
59
|
const ok = (msg) => console.log(safe_1.default.green(msg));
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
(cb) => pluginsInitialiser.init(plugins, cb),
|
|
66
|
-
(plugins, cb) => {
|
|
67
|
-
options.plugins = plugins;
|
|
68
|
-
repository.init(cb);
|
|
69
|
-
},
|
|
70
|
-
(componentsInfo, cb) => {
|
|
71
|
-
(0, app_start_1.default)(repository, options, (err) => cb(err ? err.msg : null, componentsInfo));
|
|
72
|
-
}
|
|
73
|
-
], (err, componentsInfo) => {
|
|
74
|
-
if (err) {
|
|
75
|
-
return callback(err, undefined);
|
|
76
|
-
}
|
|
60
|
+
(0, router_1.create)(router, options, repository);
|
|
61
|
+
try {
|
|
62
|
+
options.plugins = await pluginsInitialiser.init(plugins);
|
|
63
|
+
const componentsInfo = await repository.init();
|
|
64
|
+
await (0, app_start_1.default)(repository, options);
|
|
77
65
|
server = http_1.default.createServer(app);
|
|
78
66
|
server.timeout = options.timeout;
|
|
79
67
|
if (options.keepAliveTimeout) {
|
|
@@ -88,12 +76,8 @@ function registry(inputOptions) {
|
|
|
88
76
|
if (options.verbosity) {
|
|
89
77
|
ok(`Registry started at port ${app.get('port')}`);
|
|
90
78
|
if (lodash_1.default.isObject(componentsInfo)) {
|
|
91
|
-
const componentsNumber = Object.keys(
|
|
92
|
-
|
|
93
|
-
componentsInfo.components).length;
|
|
94
|
-
const componentsReleases = lodash_1.default.reduce(
|
|
95
|
-
// @ts-ignore
|
|
96
|
-
componentsInfo.components, (memo, component) => parseInt(memo, 10) + component.length);
|
|
79
|
+
const componentsNumber = Object.keys(componentsInfo.components).length;
|
|
80
|
+
const componentsReleases = Object.values(componentsInfo.components).reduce((acc, component) => acc + component.length, 0);
|
|
97
81
|
ok(`Registry serving ${componentsNumber} components for a total of ${componentsReleases} releases.`);
|
|
98
82
|
}
|
|
99
83
|
}
|
|
@@ -107,7 +91,10 @@ function registry(inputOptions) {
|
|
|
107
91
|
});
|
|
108
92
|
callback(error, undefined);
|
|
109
93
|
});
|
|
110
|
-
}
|
|
94
|
+
}
|
|
95
|
+
catch (err) {
|
|
96
|
+
callback(((_a = err) === null || _a === void 0 ? void 0 : _a.msg) || err, undefined);
|
|
97
|
+
}
|
|
111
98
|
};
|
|
112
99
|
return {
|
|
113
100
|
close,
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
import { Express } from 'express';
|
|
1
|
+
import express, { Express } from 'express';
|
|
2
|
+
import Router from 'express-promise-router';
|
|
2
3
|
import { Config } from '../../types';
|
|
3
|
-
export declare const bind: (app: Express, options: Config) =>
|
|
4
|
+
export declare const bind: (app: Express, options: Config) => {
|
|
5
|
+
app: Express;
|
|
6
|
+
router: express.Router;
|
|
7
|
+
};
|
|
@@ -7,6 +7,7 @@ exports.bind = void 0;
|
|
|
7
7
|
const express_1 = __importDefault(require("express"));
|
|
8
8
|
const errorhandler_1 = __importDefault(require("errorhandler"));
|
|
9
9
|
const morgan_1 = __importDefault(require("morgan"));
|
|
10
|
+
const express_promise_router_1 = __importDefault(require("express-promise-router"));
|
|
10
11
|
const base_url_handler_1 = __importDefault(require("./base-url-handler"));
|
|
11
12
|
const cors_1 = __importDefault(require("./cors"));
|
|
12
13
|
const discovery_handler_1 = __importDefault(require("./discovery-handler"));
|
|
@@ -21,6 +22,7 @@ const bodyParserUrlEncodedArgument = {
|
|
|
21
22
|
const bind = (app, options) => {
|
|
22
23
|
app.set('port', options.port);
|
|
23
24
|
app.set('json spaces', 0);
|
|
25
|
+
app.set('etag', 'strong');
|
|
24
26
|
app.use((_req, res, next) => {
|
|
25
27
|
res.conf = options;
|
|
26
28
|
next();
|
|
@@ -42,6 +44,8 @@ const bind = (app, options) => {
|
|
|
42
44
|
if (options.local) {
|
|
43
45
|
app.use((0, errorhandler_1.default)());
|
|
44
46
|
}
|
|
45
|
-
|
|
47
|
+
const router = (0, express_promise_router_1.default)();
|
|
48
|
+
app.use(router);
|
|
49
|
+
return { app, router };
|
|
46
50
|
};
|
|
47
51
|
exports.bind = bind;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Router } from 'express';
|
|
2
2
|
import { Config, Repository } from '../types';
|
|
3
|
-
export declare function create(app:
|
|
3
|
+
export declare function create(app: Router, conf: Config, repository: Repository): void;
|
package/dist/registry/router.js
CHANGED