@cloudnux/cli 0.17.0 → 0.19.0

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/dist/cli.mjs CHANGED
@@ -2044,11 +2044,11 @@ var require_baseGet = __commonJS({
2044
2044
  init_esm_shims();
2045
2045
  var castPath = require_castPath();
2046
2046
  var toKey = require_toKey();
2047
- function baseGet(object, path14) {
2048
- path14 = castPath(path14, object);
2049
- var index = 0, length = path14.length;
2047
+ function baseGet(object, path15) {
2048
+ path15 = castPath(path15, object);
2049
+ var index = 0, length = path15.length;
2050
2050
  while (object != null && index < length) {
2051
- object = object[toKey(path14[index++])];
2051
+ object = object[toKey(path15[index++])];
2052
2052
  }
2053
2053
  return index && index == length ? object : void 0;
2054
2054
  }
@@ -2062,8 +2062,8 @@ var require_get = __commonJS({
2062
2062
  "use strict";
2063
2063
  init_esm_shims();
2064
2064
  var baseGet = require_baseGet();
2065
- function get(object, path14, defaultValue) {
2066
- var result = object == null ? void 0 : baseGet(object, path14);
2065
+ function get(object, path15, defaultValue) {
2066
+ var result = object == null ? void 0 : baseGet(object, path15);
2067
2067
  return result === void 0 ? defaultValue : result;
2068
2068
  }
2069
2069
  module.exports = get;
@@ -2093,11 +2093,11 @@ var require_hasPath = __commonJS({
2093
2093
  var isIndex = require_isIndex();
2094
2094
  var isLength = require_isLength();
2095
2095
  var toKey = require_toKey();
2096
- function hasPath(object, path14, hasFunc) {
2097
- path14 = castPath(path14, object);
2098
- var index = -1, length = path14.length, result = false;
2096
+ function hasPath(object, path15, hasFunc) {
2097
+ path15 = castPath(path15, object);
2098
+ var index = -1, length = path15.length, result = false;
2099
2099
  while (++index < length) {
2100
- var key = toKey(path14[index]);
2100
+ var key = toKey(path15[index]);
2101
2101
  if (!(result = object != null && hasFunc(object, key))) {
2102
2102
  break;
2103
2103
  }
@@ -2120,8 +2120,8 @@ var require_hasIn = __commonJS({
2120
2120
  init_esm_shims();
2121
2121
  var baseHasIn = require_baseHasIn();
2122
2122
  var hasPath = require_hasPath();
2123
- function hasIn(object, path14) {
2124
- return object != null && hasPath(object, path14, baseHasIn);
2123
+ function hasIn(object, path15) {
2124
+ return object != null && hasPath(object, path15, baseHasIn);
2125
2125
  }
2126
2126
  module.exports = hasIn;
2127
2127
  }
@@ -2141,13 +2141,13 @@ var require_baseMatchesProperty = __commonJS({
2141
2141
  var toKey = require_toKey();
2142
2142
  var COMPARE_PARTIAL_FLAG = 1;
2143
2143
  var COMPARE_UNORDERED_FLAG = 2;
2144
- function baseMatchesProperty(path14, srcValue) {
2145
- if (isKey(path14) && isStrictComparable(srcValue)) {
2146
- return matchesStrictComparable(toKey(path14), srcValue);
2144
+ function baseMatchesProperty(path15, srcValue) {
2145
+ if (isKey(path15) && isStrictComparable(srcValue)) {
2146
+ return matchesStrictComparable(toKey(path15), srcValue);
2147
2147
  }
2148
2148
  return function(object) {
2149
- var objValue = get(object, path14);
2150
- return objValue === void 0 && objValue === srcValue ? hasIn(object, path14) : baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG);
2149
+ var objValue = get(object, path15);
2150
+ return objValue === void 0 && objValue === srcValue ? hasIn(object, path15) : baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG);
2151
2151
  };
2152
2152
  }
2153
2153
  module.exports = baseMatchesProperty;
@@ -2186,9 +2186,9 @@ var require_basePropertyDeep = __commonJS({
2186
2186
  "use strict";
2187
2187
  init_esm_shims();
2188
2188
  var baseGet = require_baseGet();
2189
- function basePropertyDeep(path14) {
2189
+ function basePropertyDeep(path15) {
2190
2190
  return function(object) {
2191
- return baseGet(object, path14);
2191
+ return baseGet(object, path15);
2192
2192
  };
2193
2193
  }
2194
2194
  module.exports = basePropertyDeep;
@@ -2204,8 +2204,8 @@ var require_property = __commonJS({
2204
2204
  var basePropertyDeep = require_basePropertyDeep();
2205
2205
  var isKey = require_isKey();
2206
2206
  var toKey = require_toKey();
2207
- function property(path14) {
2208
- return isKey(path14) ? baseProperty(toKey(path14)) : basePropertyDeep(path14);
2207
+ function property(path15) {
2208
+ return isKey(path15) ? baseProperty(toKey(path15)) : basePropertyDeep(path15);
2209
2209
  }
2210
2210
  module.exports = property;
2211
2211
  }
@@ -2306,14 +2306,14 @@ var require_baseSet = __commonJS({
2306
2306
  var isIndex = require_isIndex();
2307
2307
  var isObject = require_isObject();
2308
2308
  var toKey = require_toKey();
2309
- function baseSet(object, path14, value, customizer) {
2309
+ function baseSet(object, path15, value, customizer) {
2310
2310
  if (!isObject(object)) {
2311
2311
  return object;
2312
2312
  }
2313
- path14 = castPath(path14, object);
2314
- var index = -1, length = path14.length, lastIndex = length - 1, nested = object;
2313
+ path15 = castPath(path15, object);
2314
+ var index = -1, length = path15.length, lastIndex = length - 1, nested = object;
2315
2315
  while (nested != null && ++index < length) {
2316
- var key = toKey(path14[index]), newValue = value;
2316
+ var key = toKey(path15[index]), newValue = value;
2317
2317
  if (key === "__proto__" || key === "constructor" || key === "prototype") {
2318
2318
  return object;
2319
2319
  }
@@ -2321,7 +2321,7 @@ var require_baseSet = __commonJS({
2321
2321
  var objValue = nested[key];
2322
2322
  newValue = customizer ? customizer(objValue, key, nested) : void 0;
2323
2323
  if (newValue === void 0) {
2324
- newValue = isObject(objValue) ? objValue : isIndex(path14[index + 1]) ? [] : {};
2324
+ newValue = isObject(objValue) ? objValue : isIndex(path15[index + 1]) ? [] : {};
2325
2325
  }
2326
2326
  }
2327
2327
  assignValue(nested, key, newValue);
@@ -2344,9 +2344,9 @@ var require_basePickBy = __commonJS({
2344
2344
  function basePickBy(object, paths, predicate) {
2345
2345
  var index = -1, length = paths.length, result = {};
2346
2346
  while (++index < length) {
2347
- var path14 = paths[index], value = baseGet(object, path14);
2348
- if (predicate(value, path14)) {
2349
- baseSet(result, castPath(path14, object), value);
2347
+ var path15 = paths[index], value = baseGet(object, path15);
2348
+ if (predicate(value, path15)) {
2349
+ baseSet(result, castPath(path15, object), value);
2350
2350
  }
2351
2351
  }
2352
2352
  return result;
@@ -2479,8 +2479,8 @@ var require_pickBy = __commonJS({
2479
2479
  return [prop];
2480
2480
  });
2481
2481
  predicate = baseIteratee(predicate);
2482
- return basePickBy(object, props, function(value, path14) {
2483
- return predicate(value, path14[0]);
2482
+ return basePickBy(object, props, function(value, path15) {
2483
+ return predicate(value, path15[0]);
2484
2484
  });
2485
2485
  }
2486
2486
  module.exports = pickBy;
@@ -2493,6 +2493,7 @@ init_esm_shims();
2493
2493
  // src/config/index.ts
2494
2494
  init_esm_shims();
2495
2495
  import fs11 from "node:fs";
2496
+ import path14 from "node:path";
2496
2497
  import rechoir from "rechoir";
2497
2498
  import { extensions } from "interpret";
2498
2499
  import findUp from "findup-sync";
@@ -2556,6 +2557,7 @@ var BaseTaskManager = class {
2556
2557
  cloudProvider: this.config.cloudProvider,
2557
2558
  workingDir: path2.resolve(this.config.workingDir, this.environment),
2558
2559
  externalPackages: this.config.externalPackages,
2560
+ services: this.config.services ?? {},
2559
2561
  ...this.taskResults
2560
2562
  };
2561
2563
  delete taskParams.tasks;
@@ -2733,6 +2735,18 @@ var locateModules = {
2733
2735
  init_esm_shims();
2734
2736
  import fs4 from "node:fs/promises";
2735
2737
  import path5 from "node:path";
2738
+
2739
+ // src/task-manager/build-service-overrides.ts
2740
+ init_esm_shims();
2741
+ function buildServiceOverrides(services = {}) {
2742
+ return Object.entries(services).map(([kind, modulePath]) => ({
2743
+ kind,
2744
+ varName: kind.replace(/-([a-z])/g, (_, c) => c.toUpperCase()) + "Override",
2745
+ path: process.platform === "win32" ? modulePath.replace(/\\/g, "/") : modulePath
2746
+ }));
2747
+ }
2748
+
2749
+ // src/task-manager/tasks/transform-dev-server.ts
2736
2750
  var transformDevServer = {
2737
2751
  title: `Transform Dev Server`,
2738
2752
  skip: () => false,
@@ -2740,12 +2754,14 @@ var transformDevServer = {
2740
2754
  moduleNames,
2741
2755
  devServerTemplateFunc,
2742
2756
  workingDir,
2743
- port
2757
+ port,
2758
+ services
2744
2759
  }) => {
2745
2760
  const rendered = devServerTemplateFunc({
2746
2761
  source: "./src",
2747
2762
  moduleNames,
2748
- port
2763
+ port,
2764
+ serviceOverrides: buildServiceOverrides(services)
2749
2765
  });
2750
2766
  await fs4.mkdir(path5.join(workingDir), { recursive: true });
2751
2767
  await fs4.writeFile(path5.join(workingDir, `app.ts`), rendered, "utf-8");
@@ -2787,11 +2803,12 @@ var transformModule = {
2787
2803
  title: ({ moduleName }) => `Transform module ${moduleName}`,
2788
2804
  skip: () => false,
2789
2805
  action: async (params) => {
2790
- const { workingDir, moduleName, entrypointPath, source, moduleTemplateFunc } = params;
2806
+ const { workingDir, moduleName, entrypointPath, source, moduleTemplateFunc, services } = params;
2791
2807
  const entrypoint = await loadEntrypoint(entrypointPath);
2792
2808
  const rendered = moduleTemplateFunc({
2793
2809
  source: process.platform === "win32" ? source.replace(/\\/g, "/") : source,
2794
2810
  module: moduleName,
2811
+ serviceOverrides: buildServiceOverrides(services),
2795
2812
  ...entrypoint,
2796
2813
  ...helpers
2797
2814
  });
@@ -3033,7 +3050,7 @@ async function getPackageEntryPaths(packagePath) {
3033
3050
  }
3034
3051
  return false;
3035
3052
  }).map(([, value]) => path13.join(pkgDir, value));
3036
- exportPaths.forEach((path14) => paths.add(path14));
3053
+ exportPaths.forEach((path15) => paths.add(path15));
3037
3054
  }
3038
3055
  return Array.from(paths);
3039
3056
  }
@@ -3155,6 +3172,16 @@ function validateConfig(config2) {
3155
3172
  throw new Error(`Invalid environment configuration for "${envName}"`);
3156
3173
  }
3157
3174
  }
3175
+ if (typedConfig.services !== void 0) {
3176
+ if (typeof typedConfig.services !== "object" || typedConfig.services === null || Array.isArray(typedConfig.services)) {
3177
+ throw new Error("Config.services must be an object mapping a service kind to a module path");
3178
+ }
3179
+ for (const [kind, modulePath] of Object.entries(typedConfig.services)) {
3180
+ if (!isString(modulePath)) {
3181
+ throw new Error(`Config.services.${kind} must be a string path to a module`);
3182
+ }
3183
+ }
3184
+ }
3158
3185
  return true;
3159
3186
  }
3160
3187
 
@@ -3204,6 +3231,17 @@ async function loadConfig(configPath = null) {
3204
3231
  ...rawConfig.environments || {}
3205
3232
  }
3206
3233
  };
3234
+ if (mergedConfig.services) {
3235
+ mergedConfig.services = Object.fromEntries(
3236
+ Object.entries(mergedConfig.services).map(([kind, modulePath]) => {
3237
+ const resolvedPath = path14.resolve(process.cwd(), modulePath);
3238
+ if (!fs11.existsSync(resolvedPath)) {
3239
+ throw new Error(`Config.services.${kind} points to a module that does not exist: ${resolvedPath}`);
3240
+ }
3241
+ return [kind, resolvedPath];
3242
+ })
3243
+ );
3244
+ }
3207
3245
  if (validateConfig(mergedConfig))
3208
3246
  return mergedConfig;
3209
3247
  }
package/dist/index.mjs CHANGED
@@ -2581,6 +2581,18 @@ var locateModules = {
2581
2581
  init_esm_shims();
2582
2582
  import fs3 from "node:fs/promises";
2583
2583
  import path4 from "node:path";
2584
+
2585
+ // src/task-manager/build-service-overrides.ts
2586
+ init_esm_shims();
2587
+ function buildServiceOverrides(services = {}) {
2588
+ return Object.entries(services).map(([kind, modulePath]) => ({
2589
+ kind,
2590
+ varName: kind.replace(/-([a-z])/g, (_, c) => c.toUpperCase()) + "Override",
2591
+ path: process.platform === "win32" ? modulePath.replace(/\\/g, "/") : modulePath
2592
+ }));
2593
+ }
2594
+
2595
+ // src/task-manager/tasks/transform-dev-server.ts
2584
2596
  var transformDevServer = {
2585
2597
  title: `Transform Dev Server`,
2586
2598
  skip: () => false,
@@ -2588,12 +2600,14 @@ var transformDevServer = {
2588
2600
  moduleNames,
2589
2601
  devServerTemplateFunc,
2590
2602
  workingDir,
2591
- port
2603
+ port,
2604
+ services
2592
2605
  }) => {
2593
2606
  const rendered = devServerTemplateFunc({
2594
2607
  source: "./src",
2595
2608
  moduleNames,
2596
- port
2609
+ port,
2610
+ serviceOverrides: buildServiceOverrides(services)
2597
2611
  });
2598
2612
  await fs3.mkdir(path4.join(workingDir), { recursive: true });
2599
2613
  await fs3.writeFile(path4.join(workingDir, `app.ts`), rendered, "utf-8");
@@ -2635,11 +2649,12 @@ var transformModule = {
2635
2649
  title: ({ moduleName }) => `Transform module ${moduleName}`,
2636
2650
  skip: () => false,
2637
2651
  action: async (params) => {
2638
- const { workingDir, moduleName, entrypointPath, source, moduleTemplateFunc } = params;
2652
+ const { workingDir, moduleName, entrypointPath, source, moduleTemplateFunc, services } = params;
2639
2653
  const entrypoint = await loadEntrypoint(entrypointPath);
2640
2654
  const rendered = moduleTemplateFunc({
2641
2655
  source: process.platform === "win32" ? source.replace(/\\/g, "/") : source,
2642
2656
  module: moduleName,
2657
+ serviceOverrides: buildServiceOverrides(services),
2643
2658
  ...entrypoint,
2644
2659
  ...helpers
2645
2660
  });
@@ -10,8 +10,11 @@ import {
10
10
  } from "@cloudnux/cloud-sdk";
11
11
 
12
12
  import * as src from "../../../packages/modules/<%=module%>/src";
13
+ <%_ for(const svc of serviceOverrides){ _%>
14
+ import <%=svc.varName%> from "<%-svc.path%>";
15
+ <%_ } _%>
13
16
 
14
- useCloudProvider(awsCloudProvider);
17
+ useCloudProvider(awsCloudProvider<% if (serviceOverrides.length) { %>, { serviceFactories: { <%- serviceOverrides.map(svc => `"${svc.kind}": ${svc.varName}`).join(', ') %> } }<% } %>);
15
18
 
16
19
  const router = createRouter();
17
20
  <%_ for(var [key,entry] of Object.entries(entries)) { _%>
@@ -6,17 +6,20 @@ import { schedulerPlugin } from "@cloudnux/local-cloud-provider/schedule-plugin"
6
6
  import { devConsolePlugin } from "@cloudnux/local-cloud-provider/dev-console-plugin";
7
7
  import { websocketsPlugin } from "@cloudnux/local-cloud-provider/websocket-plugin";
8
8
  import { invokesPlugin } from "@cloudnux/local-cloud-provider/invoke-plugin";
9
+ <%_ for(const svc of serviceOverrides){ _%>
10
+ import <%=svc.varName%> from "<%-svc.path%>";
11
+ <%_ } _%>
9
12
 
10
13
  // __dirname is injected by the esbuild banner and resolves to the workingDir/env folder
11
14
  process.env.DEV_CLOUD_LOCATION_PATH ??= path.join(__dirname, '.local-location');
12
15
 
13
- useCloudProvider(localCloudProvider);
16
+ useCloudProvider(localCloudProvider<% if (serviceOverrides.length) { %>, { serviceFactories: { <%- serviceOverrides.map(svc => `"${svc.kind}": ${svc.varName}`).join(', ') %> } }<% } %>);
14
17
 
15
18
  <%_ for(const module of moduleNames){ _%>
16
19
  import <%=module%>Entries from "./<%=module%>"
17
20
  <%_ } _%>
18
21
 
19
- const router = createRouter({logger : true});
22
+ const router = createRouter();
20
23
 
21
24
  router.register(queuesPlugin, { prefix: "queues", config: { persistence: { directory: path.join(__dirname, 'queue-data') } } });
22
25
  router.register(schedulerPlugin, { prefix: "schedules", config: { persistence: { directory: path.join(__dirname, 'scheduler-data') } } });
@@ -19,8 +19,9 @@ async function entries(app: RouterInstance) {
19
19
  app.route({
20
20
  method: "<%= entry.trigger.options.method %>" as any,
21
21
  url: `/http<%= $$convertRouteParamstoFastifyRouteTemplate(entry.trigger.options.route) %>`,
22
+ config: { module: "<%=module%>" },
22
23
  handler: async (request, reply) => {
23
- await httpHandler(src["<%= entry.handler %>"], request, reply);
24
+ await httpHandler(src["<%= entry.handler %>"], request, reply);
24
25
  }
25
26
  });
26
27
  <%_ } _%>
package/dist/types.d.ts CHANGED
@@ -86,6 +86,13 @@ type Config<TTaskParams extends TaskParamBase = any> = {
86
86
  * @default: ["aws-sdk", "@aws-sdk/*"]
87
87
  */
88
88
  externalPackages: string[];
89
+ /**
90
+ * Service overrides: maps a service kind (e.g. "logger", "storage", "event-broker")
91
+ * to the path of a module whose default export is a factory function for that service.
92
+ * Paths are resolved relative to the directory the cli is invoked from.
93
+ * @default undefined
94
+ */
95
+ services?: Record<string, string>;
89
96
  };
90
97
  type Args = {
91
98
  inputs: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudnux/cli",
3
- "version": "0.17.0",
3
+ "version": "0.19.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",