veryfront 0.0.81 → 0.0.83

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 (157) hide show
  1. package/README.md +15 -1
  2. package/esm/deno.js +1 -1
  3. package/esm/proxy/cache/index.d.ts +41 -0
  4. package/esm/proxy/cache/index.d.ts.map +1 -0
  5. package/esm/proxy/cache/index.js +75 -0
  6. package/esm/proxy/cache/memory-cache.d.ts +18 -0
  7. package/esm/proxy/cache/memory-cache.d.ts.map +1 -0
  8. package/esm/proxy/cache/memory-cache.js +100 -0
  9. package/esm/proxy/cache/redis-cache.d.ts +27 -0
  10. package/esm/proxy/cache/redis-cache.d.ts.map +1 -0
  11. package/esm/proxy/cache/redis-cache.js +183 -0
  12. package/esm/proxy/cache/resilient-cache.d.ts +44 -0
  13. package/esm/proxy/cache/resilient-cache.d.ts.map +1 -0
  14. package/esm/proxy/cache/resilient-cache.js +178 -0
  15. package/esm/proxy/cache/types.d.ts +65 -0
  16. package/esm/proxy/cache/types.d.ts.map +1 -0
  17. package/esm/proxy/cache/types.js +7 -0
  18. package/esm/proxy/handler.d.ts +81 -0
  19. package/esm/proxy/handler.d.ts.map +1 -0
  20. package/esm/proxy/handler.js +417 -0
  21. package/esm/proxy/logger.d.ts +29 -0
  22. package/esm/proxy/logger.d.ts.map +1 -0
  23. package/esm/proxy/logger.js +258 -0
  24. package/esm/proxy/oauth-client.d.ts +15 -0
  25. package/esm/proxy/oauth-client.d.ts.map +1 -0
  26. package/esm/proxy/oauth-client.js +52 -0
  27. package/esm/proxy/token-manager.d.ts +59 -0
  28. package/esm/proxy/token-manager.d.ts.map +1 -0
  29. package/esm/proxy/token-manager.js +125 -0
  30. package/esm/proxy/tracing.d.ts +39 -0
  31. package/esm/proxy/tracing.d.ts.map +1 -0
  32. package/esm/proxy/tracing.js +194 -0
  33. package/esm/src/cache/backend.d.ts +22 -0
  34. package/esm/src/cache/backend.d.ts.map +1 -1
  35. package/esm/src/cache/backend.js +59 -0
  36. package/esm/src/cache/cache-key-builder.d.ts +0 -4
  37. package/esm/src/cache/cache-key-builder.d.ts.map +1 -1
  38. package/esm/src/cache/cache-key-builder.js +0 -6
  39. package/esm/src/cache/hash.d.ts +107 -0
  40. package/esm/src/cache/hash.d.ts.map +1 -0
  41. package/esm/src/cache/hash.js +166 -0
  42. package/esm/src/cache/index.d.ts +3 -0
  43. package/esm/src/cache/index.d.ts.map +1 -1
  44. package/esm/src/cache/index.js +3 -0
  45. package/esm/src/cache/module-cache.d.ts +82 -0
  46. package/esm/src/cache/module-cache.d.ts.map +1 -0
  47. package/esm/src/cache/module-cache.js +214 -0
  48. package/esm/src/cache/multi-tier.d.ts +148 -0
  49. package/esm/src/cache/multi-tier.d.ts.map +1 -0
  50. package/esm/src/cache/multi-tier.js +326 -0
  51. package/esm/src/cli/app/actions.d.ts +26 -0
  52. package/esm/src/cli/app/actions.d.ts.map +1 -0
  53. package/esm/src/cli/app/actions.js +152 -0
  54. package/esm/src/cli/app/components/inline-input.d.ts +35 -0
  55. package/esm/src/cli/app/components/inline-input.d.ts.map +1 -0
  56. package/esm/src/cli/app/components/inline-input.js +220 -0
  57. package/esm/src/cli/app/components/list-select.d.ts +69 -0
  58. package/esm/src/cli/app/components/list-select.d.ts.map +1 -0
  59. package/esm/src/cli/app/components/list-select.js +137 -0
  60. package/esm/src/cli/app/index.d.ts +45 -0
  61. package/esm/src/cli/app/index.d.ts.map +1 -0
  62. package/esm/src/cli/app/index.js +1252 -0
  63. package/esm/src/cli/app/state.d.ts +122 -0
  64. package/esm/src/cli/app/state.d.ts.map +1 -0
  65. package/esm/src/cli/app/state.js +232 -0
  66. package/esm/src/cli/app/views/dashboard.d.ts +19 -0
  67. package/esm/src/cli/app/views/dashboard.d.ts.map +1 -0
  68. package/esm/src/cli/app/views/dashboard.js +178 -0
  69. package/esm/src/cli/index/command-router.d.ts.map +1 -1
  70. package/esm/src/cli/index/command-router.js +9 -39
  71. package/esm/src/cli/index/start-handler.d.ts +3 -0
  72. package/esm/src/cli/index/start-handler.d.ts.map +1 -0
  73. package/esm/src/cli/index/start-handler.js +145 -0
  74. package/esm/src/cli/mcp/index.d.ts +11 -0
  75. package/esm/src/cli/mcp/index.d.ts.map +1 -0
  76. package/esm/src/cli/mcp/index.js +10 -0
  77. package/esm/src/cli/templates/integration-loader.d.ts.map +1 -1
  78. package/esm/src/cli/templates/integration-loader.js +2 -4
  79. package/esm/src/middleware/builtin/security/redis-rate-limit.d.ts +2 -0
  80. package/esm/src/middleware/builtin/security/redis-rate-limit.d.ts.map +1 -1
  81. package/esm/src/middleware/builtin/security/redis-rate-limit.js +23 -9
  82. package/esm/src/modules/react-loader/ssr-module-loader/cache/redis.d.ts +10 -0
  83. package/esm/src/modules/react-loader/ssr-module-loader/cache/redis.d.ts.map +1 -1
  84. package/esm/src/modules/react-loader/ssr-module-loader/cache/redis.js +30 -42
  85. package/esm/src/modules/react-loader/ssr-module-loader/loader.d.ts.map +1 -1
  86. package/esm/src/modules/react-loader/ssr-module-loader/loader.js +148 -20
  87. package/esm/src/observability/tracing/span-names.d.ts +2 -0
  88. package/esm/src/observability/tracing/span-names.d.ts.map +1 -1
  89. package/esm/src/observability/tracing/span-names.js +2 -0
  90. package/esm/src/platform/adapters/fs/cache/file-cache.d.ts.map +1 -1
  91. package/esm/src/platform/adapters/fs/cache/file-cache.js +9 -3
  92. package/esm/src/rendering/orchestrator/module-loader/cache.d.ts +10 -2
  93. package/esm/src/rendering/orchestrator/module-loader/cache.d.ts.map +1 -1
  94. package/esm/src/rendering/orchestrator/module-loader/cache.js +11 -6
  95. package/esm/src/rendering/orchestrator/module-loader/index.d.ts.map +1 -1
  96. package/esm/src/rendering/orchestrator/module-loader/index.js +72 -77
  97. package/esm/src/server/context/cache-invalidation.d.ts.map +1 -1
  98. package/esm/src/server/context/cache-invalidation.js +4 -0
  99. package/esm/src/server/handlers/dev/dashboard/api.js +4 -0
  100. package/esm/src/server/handlers/dev/projects/ui-handler.d.ts.map +1 -1
  101. package/esm/src/server/handlers/dev/projects/ui-handler.js +6 -0
  102. package/esm/src/transforms/esm/http-cache.d.ts.map +1 -1
  103. package/esm/src/transforms/esm/http-cache.js +145 -93
  104. package/esm/src/transforms/esm/transform-cache.d.ts +25 -0
  105. package/esm/src/transforms/esm/transform-cache.d.ts.map +1 -1
  106. package/esm/src/transforms/esm/transform-cache.js +45 -0
  107. package/esm/src/transforms/mdx/esm-module-loader/module-fetcher/index.d.ts.map +1 -1
  108. package/esm/src/transforms/mdx/esm-module-loader/module-fetcher/index.js +2 -36
  109. package/esm/src/utils/constants/cache.d.ts +4 -0
  110. package/esm/src/utils/constants/cache.d.ts.map +1 -1
  111. package/esm/src/utils/constants/cache.js +14 -1
  112. package/esm/src/utils/index.d.ts +1 -1
  113. package/esm/src/utils/index.d.ts.map +1 -1
  114. package/esm/src/utils/index.js +1 -1
  115. package/package.json +2 -1
  116. package/src/deno.js +1 -1
  117. package/src/proxy/cache/index.ts +93 -0
  118. package/src/proxy/cache/memory-cache.ts +120 -0
  119. package/src/proxy/cache/redis-cache.ts +203 -0
  120. package/src/proxy/cache/resilient-cache.ts +205 -0
  121. package/src/proxy/cache/types.ts +72 -0
  122. package/src/proxy/handler.ts +593 -0
  123. package/src/proxy/logger.ts +329 -0
  124. package/src/proxy/oauth-client.ts +91 -0
  125. package/src/proxy/token-manager.ts +174 -0
  126. package/src/proxy/tracing.ts +237 -0
  127. package/src/src/cache/backend.ts +65 -0
  128. package/src/src/cache/cache-key-builder.ts +0 -9
  129. package/src/src/cache/hash.ts +205 -0
  130. package/src/src/cache/index.ts +3 -0
  131. package/src/src/cache/module-cache.ts +252 -0
  132. package/src/src/cache/multi-tier.ts +462 -0
  133. package/src/src/cli/app/actions.ts +190 -0
  134. package/src/src/cli/app/components/inline-input.ts +255 -0
  135. package/src/src/cli/app/components/list-select.ts +215 -0
  136. package/src/src/cli/app/index.ts +1471 -0
  137. package/src/src/cli/app/state.ts +385 -0
  138. package/src/src/cli/app/views/dashboard.ts +212 -0
  139. package/src/src/cli/index/command-router.ts +9 -40
  140. package/src/src/cli/index/start-handler.ts +195 -0
  141. package/src/src/cli/mcp/index.ts +11 -0
  142. package/src/src/cli/templates/integration-loader.ts +2 -8
  143. package/src/src/middleware/builtin/security/redis-rate-limit.ts +24 -11
  144. package/src/src/modules/react-loader/ssr-module-loader/cache/redis.ts +36 -50
  145. package/src/src/modules/react-loader/ssr-module-loader/loader.ts +168 -25
  146. package/src/src/observability/tracing/span-names.ts +2 -0
  147. package/src/src/platform/adapters/fs/cache/file-cache.ts +9 -3
  148. package/src/src/rendering/orchestrator/module-loader/cache.ts +14 -8
  149. package/src/src/rendering/orchestrator/module-loader/index.ts +94 -89
  150. package/src/src/server/context/cache-invalidation.ts +4 -0
  151. package/src/src/server/handlers/dev/dashboard/api.ts +2 -0
  152. package/src/src/server/handlers/dev/projects/ui-handler.ts +6 -0
  153. package/src/src/transforms/esm/http-cache.ts +160 -105
  154. package/src/src/transforms/esm/transform-cache.ts +53 -0
  155. package/src/src/transforms/mdx/esm-module-loader/module-fetcher/index.ts +2 -40
  156. package/src/src/utils/constants/cache.ts +21 -1
  157. package/src/src/utils/index.ts +0 -1
@@ -156,6 +156,59 @@ export function destroyTransformCache(): void {
156
156
  localFallback.clear();
157
157
  }
158
158
 
159
+ /**
160
+ * Get the underlying distributed cache backend.
161
+ *
162
+ * This is exposed for callers that need direct access to the distributed
163
+ * cache (e.g., MDX module-fetcher that stores raw code strings instead of
164
+ * TransformCacheEntry JSON). Ensures initialization happens only once.
165
+ *
166
+ * Returns null if distributed cache is not available (memory-only mode).
167
+ */
168
+ export async function getDistributedTransformBackend(): Promise<CacheBackend | null> {
169
+ await initializeTransformCache();
170
+ if (!cacheBackend || cacheBackend.type === "memory") return null;
171
+ return cacheBackend;
172
+ }
173
+
174
+ /**
175
+ * Get a cached transform or compute it if not found.
176
+ *
177
+ * This is the preferred way to use the transform cache - it handles:
178
+ * - Cache lookup (distributed first, then local fallback)
179
+ * - Compute on miss
180
+ * - Cache storage on compute
181
+ *
182
+ * @param key - Cache key (use generateCacheKey to build it)
183
+ * @param computeFn - Function to compute the transform if not cached
184
+ * @param ttlSeconds - TTL for the cached entry
185
+ * @returns The cached or computed code
186
+ */
187
+ export async function getOrComputeTransform(
188
+ key: string,
189
+ computeFn: () => Promise<string>,
190
+ ttlSeconds: number = DEFAULT_TTL_SECONDS,
191
+ ): Promise<string> {
192
+ // Try to get from cache first
193
+ const cached = await getCachedTransformAsync(key);
194
+ if (cached) {
195
+ logger.debug("[TransformCache] Cache hit", { key });
196
+ return cached.code;
197
+ }
198
+
199
+ // Compute on miss
200
+ logger.debug("[TransformCache] Cache miss, computing", { key });
201
+ const code = await computeFn();
202
+
203
+ // Store in cache (fire-and-forget for performance)
204
+ const hash = String(Date.now()); // Simple hash for now
205
+ setCachedTransformAsync(key, code, hash, ttlSeconds).catch((error) => {
206
+ logger.debug("[TransformCache] Failed to cache computed transform", { key, error });
207
+ });
208
+
209
+ return code;
210
+ }
211
+
159
212
  export function getTransformCacheStats(): {
160
213
  fallbackEntries: number;
161
214
  maxFallbackEntries: number;
@@ -16,11 +16,9 @@ import * as dntShim from "../../../../../_dnt.shims.js";
16
16
 
17
17
  import { join, posix } from "../../../../../deps/deno.land/std@0.220.0/path/mod.js";
18
18
  import { rendererLogger as logger } from "../../../../utils/index.js";
19
- import { Singleflight } from "../../../../utils/singleflight.js";
20
19
  import { withSpan } from "../../../../observability/tracing/otlp-setup.js";
21
20
  import { SpanNames } from "../../../../observability/tracing/span-names.js";
22
21
  import type { RuntimeAdapter } from "../../../../platform/adapters/base.js";
23
- import type { CacheBackend } from "../../../../cache/backend.js";
24
22
  import { transformToESM } from "../../../esm-transform.js";
25
23
  import { TRANSFORM_CACHE_VERSION } from "../../../esm/package-registry.js";
26
24
  import { ensureHttpBundlesExist } from "../../../esm/http-cache.js";
@@ -37,48 +35,12 @@ import { hashString } from "../utils/hash.js";
37
35
  import { createStubModule } from "../utils/stub-module.js";
38
36
  import { resolveModuleFile } from "../resolution/file-finder.js";
39
37
  import { recordSSRModules } from "../../../../modules/manifest/route-module-manifest.js";
38
+ import { getDistributedTransformBackend } from "../../../esm/transform-cache.js";
40
39
  import { TRANSFORM_DISTRIBUTED_TTL_SEC } from "../../../../utils/constants/cache.js";
41
40
 
42
- /**
43
- * Distributed transform cache for cross-pod sharing.
44
- * Caches transformed module code in Redis/API so other pods don't need to re-transform.
45
- */
46
- let distributedTransformCache: CacheBackend | null | undefined;
47
- const distributedCacheInit = new Singleflight<CacheBackend | null>();
48
-
49
41
  /** TTL for cached transforms (uses centralized config) */
50
42
  const TRANSFORM_CACHE_TTL_SECONDS = TRANSFORM_DISTRIBUTED_TTL_SEC;
51
43
 
52
- function getDistributedTransformCache(): Promise<CacheBackend | null> {
53
- if (distributedTransformCache !== undefined) return Promise.resolve(distributedTransformCache);
54
-
55
- return distributedCacheInit.do("init", async () => {
56
- try {
57
- const { CacheBackends } = await import("../../../../cache/backend.js");
58
- const backend = await CacheBackends.transform();
59
-
60
- // Only use distributed cache if API or Redis (not memory - that's per-process)
61
- if (backend.type === "memory") {
62
- distributedTransformCache = null;
63
- logger.debug(`${LOG_PREFIX_MDX_LOADER} No distributed transform cache (memory only)`);
64
- return null;
65
- }
66
-
67
- distributedTransformCache = backend;
68
- logger.debug(`${LOG_PREFIX_MDX_LOADER} Distributed transform cache initialized`, {
69
- type: backend.type,
70
- });
71
- return backend;
72
- } catch (error) {
73
- logger.debug(`${LOG_PREFIX_MDX_LOADER} Failed to init distributed transform cache`, {
74
- error,
75
- });
76
- distributedTransformCache = null;
77
- return null;
78
- }
79
- });
80
- }
81
-
82
44
  /**
83
45
  * Build cache key for transformed module.
84
46
  * Includes content hash so cache invalidates when source changes.
@@ -554,7 +516,7 @@ async function doFetchAndCacheModule(
554
516
  const transformCacheKey = getTransformCacheKey(projectId, normalizedPath, contentHash);
555
517
 
556
518
  let moduleCode: string | null = null;
557
- const distributedCache = await getDistributedTransformCache();
519
+ const distributedCache = await getDistributedTransformBackend();
558
520
 
559
521
  if (distributedCache) {
560
522
  try {
@@ -13,7 +13,12 @@ function getEnvString(key: string): string | undefined {
13
13
  Deno?: { env?: { get?: (k: string) => string | undefined } };
14
14
  process?: { env?: Record<string, string | undefined> };
15
15
  };
16
- return g.Deno?.env?.get?.(key) ?? g.process?.env?.[key];
16
+ try {
17
+ return g.Deno?.env?.get?.(key) ?? g.process?.env?.[key];
18
+ } catch {
19
+ // Gracefully handle missing --allow-env permission in Deno
20
+ return undefined;
21
+ }
17
22
  }
18
23
 
19
24
  function getEnvNumber(key: string, fallback: number): number {
@@ -158,3 +163,18 @@ export const TRANSFORM_DISTRIBUTED_TTL_SEC = getEnvNumber(
158
163
  "TRANSFORM_DISTRIBUTED_TTL_SEC",
159
164
  HOURS_PER_DAY * MINUTES_PER_HOUR * SECONDS_PER_MINUTE, // 24 hours (86400)
160
165
  );
166
+
167
+ // Pod-level module cache (shared across all RenderPipeline instances)
168
+ // These caches map module paths to transformed temp file paths
169
+ export const MODULE_CACHE_MAX_ENTRIES = getEnvNumber("MODULE_CACHE_MAX_ENTRIES", 10000);
170
+ export const MODULE_CACHE_TTL_MS = getEnvNumber(
171
+ "MODULE_CACHE_TTL_MS",
172
+ 5 * MS_PER_MINUTE, // 5 minutes - short enough to pick up changes, long enough to cache
173
+ );
174
+
175
+ // ESM cache for external module mappings
176
+ export const ESM_CACHE_MAX_ENTRIES = getEnvNumber("ESM_CACHE_MAX_ENTRIES", 5000);
177
+ export const ESM_CACHE_TTL_MS = getEnvNumber(
178
+ "ESM_CACHE_TTL_MS",
179
+ 10 * MS_PER_MINUTE, // 10 minutes - external modules change less frequently
180
+ );
@@ -12,7 +12,6 @@ export {
12
12
  getContentHash,
13
13
  shortHash,
14
14
  simpleHash,
15
- simpleHash as numericHash,
16
15
  } from "./hash-utils.js";
17
16
 
18
17
  export { MemoCache, memoize, memoizeAsync, simpleHash as memoizeHash } from "./memoize.js";