@decohere/core 0.0.1-dev.20261106.228 → 0.0.1-dev.20261107.250

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,37 @@
1
+ /** Which environment a process with no NODE_ENV, and a package, are for. */ export const DEFAULT_CONFIG_ENV = "production";
2
+ const NAME = /^[A-Za-z0-9_-]+$/;
3
+ const CONFIG_FILE = /^config(?:\.[A-Za-z0-9_-]+){0,2}\.yaml$/;
4
+ /** A valid app or environment name: it fills one part of a config file's name. */ export function isConfigNamePart(name) {
5
+ return NAME.test(name);
6
+ }
7
+ /** True when a file fits `config.{optional app}.{optional env}.yaml`. */ export function isConfigFileName(fileName) {
8
+ return CONFIG_FILE.test(fileName);
9
+ }
10
+ /**
11
+ * The config files for these apps and environments, later ones winning:
12
+ * `config.yaml`, `config.<app>.yaml`, `config.<env>.yaml`, `config.<app>.<env>.yaml`.
13
+ *
14
+ * Names are built from what's given and never parsed, so `config.dev.yaml` can't be misread.
15
+ *
16
+ * @throws if a name can't be part of a file name, or an app has the same name as an environment,
17
+ * since `config.<name>.yaml` would then mean both.
18
+ */ export function configFileNames(apps, envs) {
19
+ for (const name of [
20
+ ...apps,
21
+ ...envs
22
+ ]){
23
+ if (!isConfigNamePart(name)) {
24
+ throw new Error(`${JSON.stringify(name)} can't name a config file: use letters, digits, "-" and "_"`);
25
+ }
26
+ }
27
+ const clash = apps.find((app)=>envs.includes(app));
28
+ if (clash != null) {
29
+ throw new Error(`"${clash}" is both an app and an environment, so config.${clash}.yaml would mean both`);
30
+ }
31
+ return [
32
+ "config.yaml",
33
+ ...apps.map((app)=>`config.${app}.yaml`),
34
+ ...envs.map((env)=>`config.${env}.yaml`),
35
+ ...apps.flatMap((app)=>envs.map((env)=>`config.${app}.${env}.yaml`))
36
+ ];
37
+ }
@@ -1 +1,2 @@
1
+ export * from "./config-files.js";
1
2
  export * from "./configuration.types.js";
@@ -23,6 +23,17 @@ const DEFAULT_SHUTDOWN_SIGNALS = [
23
23
  ];
24
24
  const DEFAULT_SHUTDOWN_TIMEOUT_MS = 10_000;
25
25
  export class ApiConfiguration {
26
+ static schema = {
27
+ type: "object",
28
+ additionalProperties: false,
29
+ properties: {
30
+ port: {
31
+ type: "integer",
32
+ minimum: 0,
33
+ maximum: 65535
34
+ }
35
+ }
36
+ };
26
37
  port;
27
38
  }
28
39
  export class App {
@@ -3,3 +3,10 @@ export const Environments = {
3
3
  development: "development"
4
4
  };
5
5
  export const DefaultEnvironment = Environments.development;
6
+ /**
7
+ * True only when NODE_ENV says development: `development` or `dev`. Anything else, unset, staging or
8
+ * a typo included, isn't. Use it to refuse settings that are unsafe outside development.
9
+ */ export function isDevelopmentEnv(nodeEnv = process.env.NODE_ENV) {
10
+ const env = nodeEnv?.toLowerCase();
11
+ return env === "development" || env === "dev";
12
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decohere/core",
3
- "version": "0.0.1-dev.20261106.228",
3
+ "version": "0.0.1-dev.20261107.250",
4
4
  "description": "The runtime base every Decohere package builds on: reflection, composition, configuration types, extensibility, collections, objects, caching on a Map, and basic file IO. No side effects on import.",
5
5
  "keywords": [
6
6
  "typescript",
@@ -68,7 +68,7 @@
68
68
  "test": "echo \"Error: no test specified\" && exit 1"
69
69
  },
70
70
  "dependencies": {
71
- "@decohere/scribe": "0.0.1-dev.20261106.228",
71
+ "@decohere/scribe": "0.0.1-dev.20261107.250",
72
72
  "reflect-metadata": "^0.2.2"
73
73
  },
74
74
  "devDependencies": {}
@@ -0,0 +1,16 @@
1
+ /** Which environment a process with no NODE_ENV, and a package, are for. */
2
+ export declare const DEFAULT_CONFIG_ENV = "production";
3
+ /** A valid app or environment name: it fills one part of a config file's name. */
4
+ export declare function isConfigNamePart(name: string): boolean;
5
+ /** True when a file fits `config.{optional app}.{optional env}.yaml`. */
6
+ export declare function isConfigFileName(fileName: string): boolean;
7
+ /**
8
+ * The config files for these apps and environments, later ones winning:
9
+ * `config.yaml`, `config.<app>.yaml`, `config.<env>.yaml`, `config.<app>.<env>.yaml`.
10
+ *
11
+ * Names are built from what's given and never parsed, so `config.dev.yaml` can't be misread.
12
+ *
13
+ * @throws if a name can't be part of a file name, or an app has the same name as an environment,
14
+ * since `config.<name>.yaml` would then mean both.
15
+ */
16
+ export declare function configFileNames(apps: readonly string[], envs: readonly string[]): string[];
@@ -1 +1,2 @@
1
+ export * from "./config-files.js";
1
2
  export * from "./configuration.types.js";
@@ -2,6 +2,17 @@ import { type LifetimeScope } from "../composition/index.js";
2
2
  import { type IConfigurationService } from "../configuration/index.js";
3
3
  import type { HostedServiceHost } from "./hosted-service-host.js";
4
4
  export declare class ApiConfiguration {
5
+ static schema: {
6
+ type: string;
7
+ additionalProperties: boolean;
8
+ properties: {
9
+ port: {
10
+ type: string;
11
+ minimum: number;
12
+ maximum: number;
13
+ };
14
+ };
15
+ };
5
16
  port: number;
6
17
  }
7
18
  export type AppServerStartOptions = {
@@ -4,3 +4,8 @@ export declare const Environments: {
4
4
  development: "development";
5
5
  };
6
6
  export declare const DefaultEnvironment: "development";
7
+ /**
8
+ * True only when NODE_ENV says development: `development` or `dev`. Anything else, unset, staging or
9
+ * a typo included, isn't. Use it to refuse settings that are unsafe outside development.
10
+ */
11
+ export declare function isDevelopmentEnv(nodeEnv?: string | undefined): boolean;