oc 0.50.59 → 0.50.61

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 (32) hide show
  1. package/.turbo/turbo-build.log +4 -4
  2. package/.turbo/turbo-test-silent.log +10 -7
  3. package/CHANGELOG.md +17 -0
  4. package/dist/cli/domain/ocConfig.js +8 -0
  5. package/dist/cli/facade/dev.js +3 -3
  6. package/dist/cli/facade/publish.js +2 -2
  7. package/dist/cli/facade/validate.js +2 -2
  8. package/dist/cli/logger.js +2 -2
  9. package/dist/components/oc-client/_package/package.json +4 -4
  10. package/dist/components/oc-client/_package/server.js +1 -1
  11. package/dist/components/oc-client/_package/src/oc-client.js +3 -7
  12. package/dist/components/oc-client/_package/src/oc-client.min.js +1 -1
  13. package/dist/components/oc-client/_package/src/oc-client.min.map +1 -1
  14. package/dist/components/oc-client/package-lock.json +9 -23
  15. package/dist/components/oc-client/package.json +1 -1
  16. package/dist/components/oc-client/src/oc-client.js +3 -7
  17. package/dist/components/oc-client/src/oc-client.min.js +1 -1
  18. package/dist/components/oc-client/src/oc-client.min.map +1 -1
  19. package/dist/registry/app-start.js +8 -8
  20. package/dist/registry/domain/options-sanitiser.d.ts +14 -1
  21. package/dist/registry/domain/options-sanitiser.js +24 -1
  22. package/dist/registry/domain/validators/registry-configuration.d.ts +1 -1
  23. package/dist/registry/index.d.ts +11 -6
  24. package/dist/registry/index.js +90 -32
  25. package/dist/registry/routes/helpers/get-component.js +2 -1
  26. package/dist/resources/index.js +8 -8
  27. package/dist/types.d.ts +20 -2
  28. package/dist/utils/colors.d.ts +14 -0
  29. package/dist/utils/colors.js +21 -0
  30. package/dist/utils/deprecate.d.ts +20 -0
  31. package/dist/utils/deprecate.js +21 -0
  32. package/package.json +4 -6
@@ -37,7 +37,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.default = registry;
40
- const safe_1 = __importDefault(require("colors/safe"));
40
+ const colors_1 = __importDefault(require("../utils/colors"));
41
+ const deprecate_1 = __importDefault(require("../utils/deprecate"));
41
42
  const app_start_1 = __importDefault(require("./app-start"));
42
43
  const events_handler_1 = __importDefault(require("./domain/events-handler"));
43
44
  const options_sanitiser_1 = __importDefault(require("./domain/options-sanitiser"));
@@ -47,6 +48,19 @@ const server_adapter_1 = __importDefault(require("./domain/server-adapter"));
47
48
  const validator = __importStar(require("./domain/validators"));
48
49
  const middleware = __importStar(require("./middleware"));
49
50
  const router_1 = require("./router");
51
+ const warnAboutCallback = () => (0, deprecate_1.default)({
52
+ id: 'registry-lifecycle-callbacks',
53
+ subject: 'Registry lifecycle callbacks',
54
+ replacement: 'the returned promises'
55
+ });
56
+ const toError = (error) => {
57
+ if (error instanceof Error) {
58
+ return error;
59
+ }
60
+ const errorLike = error;
61
+ const message = errorLike?.message ?? errorLike?.msg ?? error;
62
+ return new Error(String(message));
63
+ };
50
64
  function registry(inputOptions) {
51
65
  const validationResult = validator.validateRegistryConfiguration(inputOptions);
52
66
  if (!validationResult.isValid) {
@@ -57,56 +71,100 @@ function registry(inputOptions) {
57
71
  const adapter = middleware.bind((0, server_adapter_1.default)(options.server.adapter, options.server.options), options);
58
72
  const app = adapter.native();
59
73
  const repository = (0, repository_1.default)(options);
60
- const close = (callback) => {
74
+ const closePromise = () => {
61
75
  const closeMetadataStore = () => Promise.resolve(repository.close?.()).catch(() => undefined);
62
- if (adapter.isListening()) {
76
+ const closeServer = new Promise((resolve, reject) => {
77
+ if (!adapter.isListening()) {
78
+ reject('not opened');
79
+ return;
80
+ }
63
81
  adapter.close((err) => {
64
- void closeMetadataStore().finally(() => callback(err));
82
+ if (err) {
83
+ reject(err);
84
+ }
85
+ else {
86
+ resolve();
87
+ }
65
88
  });
66
- return;
89
+ });
90
+ return closeServer.finally(closeMetadataStore);
91
+ };
92
+ const close = (callback) => {
93
+ const promise = closePromise();
94
+ if (!callback) {
95
+ return promise;
67
96
  }
68
- void closeMetadataStore().finally(() => callback('not opened'));
97
+ warnAboutCallback();
98
+ const callbackPromise = promise.then(() => callback(), (error) => {
99
+ callback(error);
100
+ throw error;
101
+ });
102
+ void callbackPromise.catch(() => undefined);
103
+ return callbackPromise;
69
104
  };
70
105
  const register = (plugin, callback) => {
106
+ if (callback) {
107
+ warnAboutCallback();
108
+ }
71
109
  plugins.push(Object.assign(plugin, { callback }));
110
+ return Promise.resolve();
72
111
  };
73
- const start = async (callback) => {
74
- const ok = (msg) => console.log(safe_1.default.green(msg));
112
+ const startPromise = async () => {
113
+ const ok = (msg) => console.log(colors_1.default.green(msg));
75
114
  try {
76
115
  options.plugins = await pluginsInitialiser.init(plugins);
77
116
  (0, router_1.create)(adapter, options, repository);
78
117
  const componentsInfo = await repository.init();
79
118
  await (0, app_start_1.default)(repository, options);
80
- adapter.listen({
81
- port: options.port,
82
- timeout: options.timeout,
83
- keepAliveTimeout: options.keepAliveTimeout
84
- }, (err) => {
85
- if (err) {
86
- return callback(err);
87
- }
88
- events_handler_1.default.fire('start', {});
89
- if (options.verbosity) {
90
- ok(`Registry started at port http://localhost:${options.port}${options.prefix}`);
91
- if (componentsInfo) {
92
- const componentsNumber = Object.keys(componentsInfo.components).length;
93
- const componentsReleases = Object.values(componentsInfo.components).reduce((acc, component) => acc + Object.keys(component).length, 0);
94
- ok(`Registry serving ${componentsNumber} components for a total of ${componentsReleases} releases.`);
119
+ return await new Promise((resolve, reject) => {
120
+ adapter.listen({
121
+ port: options.port,
122
+ timeout: options.timeout,
123
+ keepAliveTimeout: options.keepAliveTimeout
124
+ }, (err) => {
125
+ if (err) {
126
+ reject(toError(err));
127
+ return;
95
128
  }
96
- }
97
- callback(null, { app, server: adapter.httpServer() });
98
- });
99
- adapter.onServerError((error) => {
100
- events_handler_1.default.fire('error', {
101
- code: 'EXPRESS_ERROR',
102
- message: error?.message ?? String(error)
129
+ events_handler_1.default.fire('start', {});
130
+ if (options.verbosity) {
131
+ ok(`Registry started at port http://localhost:${options.port}${options.prefix}`);
132
+ if (componentsInfo) {
133
+ const componentsNumber = Object.keys(componentsInfo.components).length;
134
+ const componentsReleases = Object.values(componentsInfo.components).reduce((acc, component) => acc + Object.keys(component).length, 0);
135
+ ok(`Registry serving ${componentsNumber} components for a total of ${componentsReleases} releases.`);
136
+ }
137
+ }
138
+ resolve({ app, server: adapter.httpServer() });
139
+ });
140
+ adapter.onServerError((error) => {
141
+ events_handler_1.default.fire('error', {
142
+ code: 'EXPRESS_ERROR',
143
+ message: error?.message ?? String(error)
144
+ });
145
+ reject(toError(error));
103
146
  });
104
- callback(error);
105
147
  });
106
148
  }
107
149
  catch (err) {
108
- callback(err?.msg || err);
150
+ throw toError(err);
151
+ }
152
+ };
153
+ const start = (callback) => {
154
+ const promise = startPromise();
155
+ if (!callback) {
156
+ return promise;
109
157
  }
158
+ warnAboutCallback();
159
+ const callbackPromise = promise.then((result) => {
160
+ callback(null, result);
161
+ return result;
162
+ }, (error) => {
163
+ callback(error);
164
+ throw error;
165
+ });
166
+ void callbackPromise.catch(() => undefined);
167
+ return callbackPromise;
110
168
  };
111
169
  return {
112
170
  close,
@@ -463,7 +463,8 @@ function getComponent(conf, repository) {
463
463
  const staticPath = repository
464
464
  .getStaticFilePath(component.name, component.version, '')
465
465
  .replace(/^https:/, '');
466
- if (!component.oc.files.dataProvider) {
466
+ const dataProviderDisabled = conf.dataProvider?.enabled === false;
467
+ if (dataProviderDisabled || !component.oc.files.dataProvider) {
467
468
  const { __oc_Retry, ...props } = params;
468
469
  props['_staticPath'] = staticPath;
469
470
  props['_baseUrl'] = conf.baseUrl;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const safe_1 = require("colors/safe");
3
+ const colors_1 = require("../utils/colors");
4
4
  // Kind of long multi-string messages and functions
5
5
  const validFunctionMock = `// simplified mock signature
6
6
  module.exports = (a, b) => a+b;`;
@@ -23,24 +23,24 @@ const mockPluginIsNotValid = `Looks like you are trying to register a dynamic mo
23
23
  The entry point should be a synchronous function or an object containing an asynchronous register() function and a synchronous execute() function.
24
24
  Example:
25
25
 
26
- ${(0, safe_1.yellow)(validFunctionMock)}
26
+ ${(0, colors_1.yellow)(validFunctionMock)}
27
27
 
28
- ${(0, safe_1.yellow)(validMockObject)}`;
28
+ ${(0, colors_1.yellow)(validMockObject)}`;
29
29
  const initSuccess = (componentName, componentPath) => {
30
30
  const success = `Success! Created ${componentName} at ${componentPath}`;
31
- return `${(0, safe_1.green)(success)}
31
+ return `${(0, colors_1.green)(success)}
32
32
 
33
33
  From here you can run several commands
34
34
 
35
- ${(0, safe_1.green)('oc --help')}
35
+ ${(0, colors_1.green)('oc --help')}
36
36
  To see a detailed list of all the commands available
37
37
 
38
38
  We suggest that you begin by typing:
39
39
 
40
- ${(0, safe_1.green)('oc dev . 3030')}
40
+ ${(0, colors_1.green)('oc dev . 3030')}
41
41
 
42
42
  If you have questions, issues or feedback about OpenComponents, please, join us on Gitter:
43
- ${(0, safe_1.green)('https://gitter.im/opentable/oc')}
43
+ ${(0, colors_1.green)('https://gitter.im/opentable/oc')}
44
44
 
45
45
  Happy coding
46
46
 
@@ -156,7 +156,7 @@ exports.default = {
156
156
  cleanSuccess: 'Folders removed',
157
157
  initSuccess,
158
158
  installCompiler: (compiler) => `Installing ${compiler} from npm...`,
159
- installCompilerSuccess: (template, compiler, version) => `${(0, safe_1.green)('✔')} Installed ${compiler} [${template} v${version}]`,
159
+ installCompilerSuccess: (template, compiler, version) => `${(0, colors_1.green)('✔')} Installed ${compiler} [${template} v${version}]`,
160
160
  legacyTemplateDeprecationWarning: (legacyType, newType) => `Template-type "${legacyType}" has been deprecated and is now replaced by "${newType}"`,
161
161
  CHANGES_DETECTED: (file) => `Changes detected on file: ${file}`,
162
162
  CHECKING_DEPENDENCIES: 'Ensuring dependencies are loaded...',
package/dist/types.d.ts CHANGED
@@ -239,6 +239,23 @@ export interface Config<T = any, TServerAdapter extends HttpServerAdapterFactory
239
239
  * @example ["lodash", "moment"]
240
240
  */
241
241
  dependencies: string[];
242
+ /**
243
+ * Configuration for the data provider step, i.e. the component's `server.js`
244
+ * that produces the model consumed by the view.
245
+ */
246
+ dataProvider: {
247
+ /**
248
+ * Executes the component's own data provider (`server.js`) when it has one.
249
+ *
250
+ * When `false` the registry never fetches nor runs a component's data
251
+ * provider, even if one exists in the storage: every component is served
252
+ * through the same path used by components that ship no `server.js`, i.e.
253
+ * the request parameters are passed straight through as the view model.
254
+ *
255
+ * @default true
256
+ */
257
+ enabled: boolean;
258
+ };
242
259
  /**
243
260
  * Configuration object to enable/disable the HTML discovery page and the API
244
261
  */
@@ -279,11 +296,12 @@ export interface Config<T = any, TServerAdapter extends HttpServerAdapterFactory
279
296
  secure: boolean;
280
297
  }) => boolean;
281
298
  /**
282
- * Environment variables passed to components in `context.env`.
299
+ * Environment values passed to components in `context.env` and the data
300
+ * provider's `process.env` shim.
283
301
  *
284
302
  * @default {}
285
303
  */
286
- env: Record<string, string>;
304
+ env: Record<string, any>;
287
305
  /**
288
306
  * Maximum execution time of a component’s server-side logic, expressed in
289
307
  * seconds. When the timeout elapses the registry returns a 500 error.
@@ -0,0 +1,14 @@
1
+ declare const colors: {
2
+ black: import("picocolors/types").Formatter;
3
+ red: import("picocolors/types").Formatter;
4
+ green: import("picocolors/types").Formatter;
5
+ yellow: import("picocolors/types").Formatter;
6
+ blue: import("picocolors/types").Formatter;
7
+ magenta: import("picocolors/types").Formatter;
8
+ cyan: import("picocolors/types").Formatter;
9
+ white: import("picocolors/types").Formatter;
10
+ gray: import("picocolors/types").Formatter;
11
+ grey: import("picocolors/types").Formatter;
12
+ };
13
+ export declare const black: import("picocolors/types").Formatter, red: import("picocolors/types").Formatter, green: import("picocolors/types").Formatter, yellow: import("picocolors/types").Formatter, blue: import("picocolors/types").Formatter, magenta: import("picocolors/types").Formatter, cyan: import("picocolors/types").Formatter, white: import("picocolors/types").Formatter, gray: import("picocolors/types").Formatter, grey: import("picocolors/types").Formatter;
14
+ export default colors;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.grey = exports.gray = exports.white = exports.cyan = exports.magenta = exports.blue = exports.yellow = exports.green = exports.red = exports.black = void 0;
7
+ const picocolors_1 = __importDefault(require("picocolors"));
8
+ const colors = {
9
+ black: picocolors_1.default.black,
10
+ red: picocolors_1.default.red,
11
+ green: picocolors_1.default.green,
12
+ yellow: picocolors_1.default.yellow,
13
+ blue: picocolors_1.default.blue,
14
+ magenta: picocolors_1.default.magenta,
15
+ cyan: picocolors_1.default.cyan,
16
+ white: picocolors_1.default.white,
17
+ gray: picocolors_1.default.gray,
18
+ grey: picocolors_1.default.gray
19
+ };
20
+ exports.black = colors.black, exports.red = colors.red, exports.green = colors.green, exports.yellow = colors.yellow, exports.blue = colors.blue, exports.magenta = colors.magenta, exports.cyan = colors.cyan, exports.white = colors.white, exports.gray = colors.gray, exports.grey = colors.grey;
21
+ exports.default = colors;
@@ -0,0 +1,20 @@
1
+ interface DeprecationNotice {
2
+ /** Stable identifier used to only warn once per process for this deprecation. */
3
+ id: string;
4
+ /** The option/API being removed. */
5
+ subject: string;
6
+ /** What to use instead. */
7
+ replacement: string;
8
+ }
9
+ /**
10
+ * Emits a single, consistent deprecation notice (once per process, per `id`)
11
+ * for a config option or API that will be removed in OpenComponents v1.
12
+ *
13
+ * Routes through `process.emitWarning` with type `DeprecationWarning`, so it
14
+ * honors the standard Node.js opt-out mechanisms (`--no-deprecation`, etc.)
15
+ * without needing a bespoke env var.
16
+ *
17
+ * This never changes runtime behavior - it is purely informational.
18
+ */
19
+ export default function deprecate({ id, subject, replacement }: DeprecationNotice): void;
20
+ export {};
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = deprecate;
4
+ const warned = new Set();
5
+ /**
6
+ * Emits a single, consistent deprecation notice (once per process, per `id`)
7
+ * for a config option or API that will be removed in OpenComponents v1.
8
+ *
9
+ * Routes through `process.emitWarning` with type `DeprecationWarning`, so it
10
+ * honors the standard Node.js opt-out mechanisms (`--no-deprecation`, etc.)
11
+ * without needing a bespoke env var.
12
+ *
13
+ * This never changes runtime behavior - it is purely informational.
14
+ */
15
+ function deprecate({ id, subject, replacement }) {
16
+ if (warned.has(id)) {
17
+ return;
18
+ }
19
+ warned.add(id);
20
+ process.emitWarning(`${subject} is deprecated and will be removed in OpenComponents v1 - use ${replacement} instead.`, 'DeprecationWarning');
21
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oc",
3
- "version": "0.50.59",
3
+ "version": "0.50.61",
4
4
  "description": "A framework for developing and distributing html components",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -39,7 +39,6 @@
39
39
  "devDependencies": {
40
40
  "@biomejs/biome": "^2.5.0",
41
41
  "@types/accept-language-parser": "^1.5.8",
42
- "@types/async": "^3.2.25",
43
42
  "@types/bun": "^1.3.14",
44
43
  "@types/cookie-parser": "^1.4.10",
45
44
  "@types/cross-spawn": "^6.0.6",
@@ -74,11 +73,9 @@
74
73
  "@rdevis/turbo-stream": "^2.4.1",
75
74
  "@types/lodash.isequal": "^4.5.8",
76
75
  "accept-language-parser": "^1.5.0",
77
- "async": "^3.2.6",
78
76
  "basic-auth-connect": "^1.1.0",
79
77
  "builtin-modules": "^3.3.0",
80
78
  "chokidar": "^4.0.3",
81
- "colors": "^1.4.0",
82
79
  "cookie-parser": "^1.4.7",
83
80
  "cross-spawn": "^7.0.6",
84
81
  "dependency-graph": "^1.0.0",
@@ -92,14 +89,14 @@
92
89
  "livereload": "^0.10.3",
93
90
  "lodash.isequal": "^4.5.0",
94
91
  "morgan": "^1.11.0",
95
- "multer": "^2.0.2",
92
+ "multer": "^2.2.0",
96
93
  "nice-cache": "^0.0.5",
97
94
  "oc-client": "^4.0.3",
98
95
  "oc-client-browser": "^2.1.12",
99
96
  "oc-empty-response-handler": "^1.0.2",
100
97
  "oc-get-unix-utc-timestamp": "^1.0.6",
101
98
  "oc-metadata-adapters-utils": "^0.1.1",
102
- "oc-s3-storage-adapter": "^2.2.3",
99
+ "oc-s3-storage-adapter": "^2.2.4",
103
100
  "oc-storage-adapters-utils": "^2.1.2",
104
101
  "oc-template-es6": "^2.0.0",
105
102
  "oc-template-es6-compiler": "^7.1.4",
@@ -109,6 +106,7 @@
109
106
  "oc-template-jade-compiler": "^7.5.0",
110
107
  "open": "^10.2.0",
111
108
  "parse-author": "^2.0.0",
109
+ "picocolors": "^1.1.1",
112
110
  "read": "^1.0.7",
113
111
  "require-package-name": "^2.0.1",
114
112
  "response-time": "^2.3.4",