@ts-cloud/core 0.5.34 → 0.6.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.
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Deployment-mode detection: the single source of truth for whether a project
3
+ * is a SERVER deployment (`infrastructure.compute` - an EC2/Fargate box) or a
4
+ * SERVERLESS deployment (`environments.<env>.app` - Lambda functions).
5
+ *
6
+ * The two are mutually exclusive: a project may not declare both a server and a
7
+ * serverless app. {@link detectDeploymentTargets} reports what is configured and
8
+ * {@link resolveDeploymentMode} picks the effective mode (honoring an explicit
9
+ * `config.mode`); {@link deploymentCoexistenceError} returns a message when both
10
+ * are configured so callers can abort with a clear contract.
11
+ */
12
+ import type { CloudConfig, DeploymentMode } from './types';
13
+ export interface DeploymentTargets {
14
+ /** A server box is configured (`infrastructure.compute`). */
15
+ server: boolean;
16
+ /** A serverless Lambda app is configured (`environments.<env>.app`). */
17
+ serverless: boolean;
18
+ }
19
+ /** What deployment targets the config declares. Pure and side-effect free. */
20
+ export declare function detectDeploymentTargets(config: Pick<CloudConfig, 'infrastructure' | 'environments'>): DeploymentTargets;
21
+ /**
22
+ * The effective deployment mode. An explicit `config.mode` wins (it pins the
23
+ * detection); otherwise a configured serverless app implies `serverless`, and a
24
+ * configured compute box (or nothing else) implies `server`. When both targets
25
+ * are configured this still returns a value, but {@link deploymentCoexistenceError}
26
+ * is non-null and callers should abort first.
27
+ */
28
+ export declare function resolveDeploymentMode(config: Pick<CloudConfig, 'infrastructure' | 'environments' | 'mode'>): DeploymentMode;
29
+ /**
30
+ * A human-readable error when a project declares BOTH a server and a serverless
31
+ * app (they cannot coexist), or when an explicit `config.mode` contradicts the
32
+ * configured resources. Returns null when the config is consistent.
33
+ */
34
+ export declare function deploymentCoexistenceError(config: Pick<CloudConfig, 'infrastructure' | 'environments' | 'mode'>): string | null;
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@
2
2
  * ts-cloud Core - CloudFormation Generator Engine
3
3
  */
4
4
  export * from './types';
5
+ export * from './deployment-mode';
5
6
  export * from './drivers';
6
7
  export * from './template-builder';
7
8
  export { validateTemplate, validateTemplateSize, validateResourceLimits, type ValidationResult, } from './template-validator';
package/dist/index.js CHANGED
@@ -1075,6 +1075,31 @@ var RealtimePresets = {
1075
1075
  }
1076
1076
  }
1077
1077
  };
1078
+ // src/deployment-mode.ts
1079
+ function detectDeploymentTargets(config) {
1080
+ const server = config.infrastructure?.compute != null;
1081
+ const serverless = Object.values(config.environments ?? {}).some((env) => env?.app != null);
1082
+ return { server, serverless };
1083
+ }
1084
+ function resolveDeploymentMode(config) {
1085
+ if (config.mode === "server" || config.mode === "serverless")
1086
+ return config.mode;
1087
+ const { serverless } = detectDeploymentTargets(config);
1088
+ return serverless ? "serverless" : "server";
1089
+ }
1090
+ function deploymentCoexistenceError(config) {
1091
+ const { server, serverless } = detectDeploymentTargets(config);
1092
+ if (server && serverless) {
1093
+ return "A project cannot be both a server and a serverless deployment. " + "Found `infrastructure.compute` (server) AND `environments.<env>.app` (serverless Lambda). " + "Keep one: remove `infrastructure.compute` for a serverless app, or remove `environments.<env>.app` for a server.";
1094
+ }
1095
+ if (config.mode === "server" && serverless && !server) {
1096
+ return "Config sets `mode: 'server'` but declares a serverless app (`environments.<env>.app`). " + "Remove the app or change the mode.";
1097
+ }
1098
+ if (config.mode === "serverless" && server && !serverless) {
1099
+ return "Config sets `mode: 'serverless'` but declares a server (`infrastructure.compute`). " + "Remove the compute block or change the mode.";
1100
+ }
1101
+ return null;
1102
+ }
1078
1103
  // src/drivers/types.ts
1079
1104
  function resolveCloudProvider(config) {
1080
1105
  if (config.cloud?.provider)
@@ -20694,7 +20719,7 @@ function createFullStackAppPreset(options) {
20694
20719
  slug,
20695
20720
  region: "us-east-1"
20696
20721
  },
20697
- mode: "hybrid",
20722
+ mode: "server",
20698
20723
  environments: {
20699
20724
  production: {
20700
20725
  type: "production",
@@ -25165,9 +25190,8 @@ var cloud_config_schema_default = {
25165
25190
  },
25166
25191
  mode: {
25167
25192
  type: "string",
25168
- description: "Deployment mode",
25169
- enum: ["server", "serverless", "hybrid"],
25170
- default: "serverless"
25193
+ description: "Deployment mode (server and serverless are mutually exclusive; auto-detected when omitted)",
25194
+ enum: ["server", "serverless"]
25171
25195
  },
25172
25196
  environments: {
25173
25197
  type: "object",
@@ -25729,8 +25753,8 @@ function validateAgainstSchema(config) {
25729
25753
  if (config.project?.region && !validRegions.includes(config.project.region)) {
25730
25754
  errors.push(`Invalid region: ${config.project.region}. Must be one of: ${validRegions.join(", ")}`);
25731
25755
  }
25732
- if (config.mode && !["server", "serverless", "hybrid"].includes(config.mode)) {
25733
- errors.push("Invalid mode: must be one of server, serverless, or hybrid");
25756
+ if (config.mode && !["server", "serverless"].includes(config.mode)) {
25757
+ errors.push("Invalid mode: must be one of server or serverless");
25734
25758
  }
25735
25759
  return {
25736
25760
  valid: errors.length === 0,
@@ -47184,6 +47208,7 @@ export {
47184
47208
  resolveQueueNames,
47185
47209
  resolveProjectStackName,
47186
47210
  resolveManagementDashboardSite,
47211
+ resolveDeploymentMode,
47187
47212
  resolveDeployBucketName,
47188
47213
  resolveDashboardDomain,
47189
47214
  resolveCredentials,
@@ -47323,6 +47348,8 @@ export {
47323
47348
  diffTemplates,
47324
47349
  detectServiceRegion,
47325
47350
  detectMisconfigurations,
47351
+ detectDeploymentTargets,
47352
+ deploymentCoexistenceError,
47326
47353
  defaultLocalConfig,
47327
47354
  databaseUserManager,
47328
47355
  crossRegionReferenceManager,
package/dist/types.d.ts CHANGED
@@ -138,11 +138,13 @@ export interface ProjectConfig {
138
138
  }
139
139
  /**
140
140
  * Deployment mode (optional)
141
- * @deprecated Mode is now auto-detected from your infrastructure configuration.
142
- * Simply define the resources you need (functions, servers, storage, etc.) and
143
- * ts-cloud will deploy them accordingly. No need to specify a mode.
141
+ * A project deploys as EITHER a server (`infrastructure.compute` - an EC2/Fargate
142
+ * box, Forge-style) OR serverless (`environments.<env>.app` - Lambda functions,
143
+ * Vapor-style). The two are mutually exclusive and cannot coexist in one project;
144
+ * ts-cloud auto-detects the mode from your config. Setting `mode` explicitly is
145
+ * optional and only pins the auto-detection.
144
146
  */
145
- export type DeploymentMode = 'server' | 'serverless' | 'hybrid';
147
+ export type DeploymentMode = 'server' | 'serverless';
146
148
  export type EnvironmentType = 'production' | 'staging' | 'development';
147
149
  export interface EnvironmentConfig {
148
150
  type: EnvironmentType;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ts-cloud/core",
3
- "version": "0.5.34",
3
+ "version": "0.6.0",
4
4
  "type": "module",
5
5
  "description": "Core CloudFormation generation library for ts-cloud",
6
6
  "author": "Chris Breuer <chris@stacksjs.com>",
@@ -31,7 +31,7 @@
31
31
  "typecheck": "tsc --noEmit"
32
32
  },
33
33
  "dependencies": {
34
- "@ts-cloud/aws-types": "0.5.34"
34
+ "@ts-cloud/aws-types": "0.6.0"
35
35
  },
36
36
  "devDependencies": {
37
37
  "typescript": "^5.9.3"