@moku-labs/common 0.2.0 → 0.3.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/index.cjs CHANGED
@@ -1010,6 +1010,42 @@ function cloudflareBindings() {
1010
1010
  };
1011
1011
  }
1012
1012
  //#endregion
1013
+ //#region src/plugins/env/providers.worker.ts
1014
+ /**
1015
+ * A workerd-safe {@link EnvProvider} that returns a shallow copy of `process.env`
1016
+ * when a `process` global exists, else an empty record. Safe to evaluate at Worker
1017
+ * cold start — it never throws on a missing `process` (`typeof` of an undeclared
1018
+ * identifier is the string `"undefined"`, not a `ReferenceError`). Re-reads fresh on
1019
+ * every `load()`, so it is not a live reference.
1020
+ *
1021
+ * @returns An {@link EnvProvider} named `worker-process-env`.
1022
+ * @example
1023
+ * ```ts
1024
+ * // wire as the env provider on a Cloudflare target so `ctx.env.get("CLOUDFLARE_API_TOKEN")`
1025
+ * // resolves under Bun/Node deploy scripts, while staying safe inside the deployed Worker.
1026
+ * const provider = workerSafeProcessEnv();
1027
+ * provider.load().CLOUDFLARE_API_TOKEN;
1028
+ * ```
1029
+ */
1030
+ function workerSafeProcessEnv() {
1031
+ return {
1032
+ name: "worker-process-env",
1033
+ /**
1034
+ * Reads a shallow copy of `process.env`, or `{}` when there is no `process`
1035
+ * global (workerd without `nodejs_compat`). Never throws at cold start.
1036
+ *
1037
+ * @returns The current environment as a flat record (empty when `process` is absent).
1038
+ * @example
1039
+ * ```ts
1040
+ * workerSafeProcessEnv().load();
1041
+ * ```
1042
+ */
1043
+ load() {
1044
+ return typeof process === "undefined" ? {} : { ...process.env };
1045
+ }
1046
+ };
1047
+ }
1048
+ //#endregion
1013
1049
  //#region src/plugins/log/types.ts
1014
1050
  var types_exports$1 = /* @__PURE__ */ __exportAll({});
1015
1051
  //#endregion
@@ -1034,3 +1070,4 @@ exports.dotenv = dotenv;
1034
1070
  exports.envPlugin = envPlugin;
1035
1071
  exports.logPlugin = logPlugin;
1036
1072
  exports.processEnv = processEnv;
1073
+ exports.workerSafeProcessEnv = workerSafeProcessEnv;
package/dist/index.d.cts CHANGED
@@ -389,4 +389,23 @@ declare function processEnv(): EnvProvider;
389
389
  */
390
390
  declare function cloudflareBindings(): EnvProvider;
391
391
  //#endregion
392
- export { types_d_exports as Env, type EnvApi, type EnvConfig, type EnvProvider, type EnvState, type EnvVarSpec, type ExpectChain, types_d_exports$1 as Log, type LogApi, type LogConfig, type LogEntry, type LogLevel, type LogSink, type LogState, browserEnv, cloudflareBindings, dotenv, envPlugin, logPlugin, processEnv };
392
+ //#region src/plugins/env/providers.worker.d.ts
393
+ /**
394
+ * A workerd-safe {@link EnvProvider} that returns a shallow copy of `process.env`
395
+ * when a `process` global exists, else an empty record. Safe to evaluate at Worker
396
+ * cold start — it never throws on a missing `process` (`typeof` of an undeclared
397
+ * identifier is the string `"undefined"`, not a `ReferenceError`). Re-reads fresh on
398
+ * every `load()`, so it is not a live reference.
399
+ *
400
+ * @returns An {@link EnvProvider} named `worker-process-env`.
401
+ * @example
402
+ * ```ts
403
+ * // wire as the env provider on a Cloudflare target so `ctx.env.get("CLOUDFLARE_API_TOKEN")`
404
+ * // resolves under Bun/Node deploy scripts, while staying safe inside the deployed Worker.
405
+ * const provider = workerSafeProcessEnv();
406
+ * provider.load().CLOUDFLARE_API_TOKEN;
407
+ * ```
408
+ */
409
+ declare function workerSafeProcessEnv(): EnvProvider;
410
+ //#endregion
411
+ export { types_d_exports as Env, type EnvApi, type EnvConfig, type EnvProvider, type EnvState, type EnvVarSpec, type ExpectChain, types_d_exports$1 as Log, type LogApi, type LogConfig, type LogEntry, type LogLevel, type LogSink, type LogState, browserEnv, cloudflareBindings, dotenv, envPlugin, logPlugin, processEnv, workerSafeProcessEnv };
package/dist/index.d.mts CHANGED
@@ -389,4 +389,23 @@ declare function processEnv(): EnvProvider;
389
389
  */
390
390
  declare function cloudflareBindings(): EnvProvider;
391
391
  //#endregion
392
- export { types_d_exports as Env, type EnvApi, type EnvConfig, type EnvProvider, type EnvState, type EnvVarSpec, type ExpectChain, types_d_exports$1 as Log, type LogApi, type LogConfig, type LogEntry, type LogLevel, type LogSink, type LogState, browserEnv, cloudflareBindings, dotenv, envPlugin, logPlugin, processEnv };
392
+ //#region src/plugins/env/providers.worker.d.ts
393
+ /**
394
+ * A workerd-safe {@link EnvProvider} that returns a shallow copy of `process.env`
395
+ * when a `process` global exists, else an empty record. Safe to evaluate at Worker
396
+ * cold start — it never throws on a missing `process` (`typeof` of an undeclared
397
+ * identifier is the string `"undefined"`, not a `ReferenceError`). Re-reads fresh on
398
+ * every `load()`, so it is not a live reference.
399
+ *
400
+ * @returns An {@link EnvProvider} named `worker-process-env`.
401
+ * @example
402
+ * ```ts
403
+ * // wire as the env provider on a Cloudflare target so `ctx.env.get("CLOUDFLARE_API_TOKEN")`
404
+ * // resolves under Bun/Node deploy scripts, while staying safe inside the deployed Worker.
405
+ * const provider = workerSafeProcessEnv();
406
+ * provider.load().CLOUDFLARE_API_TOKEN;
407
+ * ```
408
+ */
409
+ declare function workerSafeProcessEnv(): EnvProvider;
410
+ //#endregion
411
+ export { types_d_exports as Env, type EnvApi, type EnvConfig, type EnvProvider, type EnvState, type EnvVarSpec, type ExpectChain, types_d_exports$1 as Log, type LogApi, type LogConfig, type LogEntry, type LogLevel, type LogSink, type LogState, browserEnv, cloudflareBindings, dotenv, envPlugin, logPlugin, processEnv, workerSafeProcessEnv };
package/dist/index.mjs CHANGED
@@ -998,10 +998,46 @@ function cloudflareBindings() {
998
998
  };
999
999
  }
1000
1000
  //#endregion
1001
+ //#region src/plugins/env/providers.worker.ts
1002
+ /**
1003
+ * A workerd-safe {@link EnvProvider} that returns a shallow copy of `process.env`
1004
+ * when a `process` global exists, else an empty record. Safe to evaluate at Worker
1005
+ * cold start — it never throws on a missing `process` (`typeof` of an undeclared
1006
+ * identifier is the string `"undefined"`, not a `ReferenceError`). Re-reads fresh on
1007
+ * every `load()`, so it is not a live reference.
1008
+ *
1009
+ * @returns An {@link EnvProvider} named `worker-process-env`.
1010
+ * @example
1011
+ * ```ts
1012
+ * // wire as the env provider on a Cloudflare target so `ctx.env.get("CLOUDFLARE_API_TOKEN")`
1013
+ * // resolves under Bun/Node deploy scripts, while staying safe inside the deployed Worker.
1014
+ * const provider = workerSafeProcessEnv();
1015
+ * provider.load().CLOUDFLARE_API_TOKEN;
1016
+ * ```
1017
+ */
1018
+ function workerSafeProcessEnv() {
1019
+ return {
1020
+ name: "worker-process-env",
1021
+ /**
1022
+ * Reads a shallow copy of `process.env`, or `{}` when there is no `process`
1023
+ * global (workerd without `nodejs_compat`). Never throws at cold start.
1024
+ *
1025
+ * @returns The current environment as a flat record (empty when `process` is absent).
1026
+ * @example
1027
+ * ```ts
1028
+ * workerSafeProcessEnv().load();
1029
+ * ```
1030
+ */
1031
+ load() {
1032
+ return typeof process === "undefined" ? {} : { ...process.env };
1033
+ }
1034
+ };
1035
+ }
1036
+ //#endregion
1001
1037
  //#region src/plugins/log/types.ts
1002
1038
  var types_exports$1 = /* @__PURE__ */ __exportAll({});
1003
1039
  //#endregion
1004
1040
  //#region src/plugins/env/types.ts
1005
1041
  var types_exports = /* @__PURE__ */ __exportAll({});
1006
1042
  //#endregion
1007
- export { types_exports as Env, types_exports$1 as Log, browserEnv, cloudflareBindings, dotenv, envPlugin, logPlugin, processEnv };
1043
+ export { types_exports as Env, types_exports$1 as Log, browserEnv, cloudflareBindings, dotenv, envPlugin, logPlugin, processEnv, workerSafeProcessEnv };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moku-labs/common",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Shared framework plugins for the Moku family, built on @moku-labs/core.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -68,7 +68,7 @@
68
68
  "registry": "https://registry.npmjs.org/"
69
69
  },
70
70
  "dependencies": {
71
- "@moku-labs/core": "0.1.4"
71
+ "@moku-labs/core": "1.5.0"
72
72
  },
73
73
  "devDependencies": {
74
74
  "@arethetypeswrong/cli": "0.18.3",