@ecopages/core 0.2.0-beta.22 → 0.2.0-beta.24

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 (48) hide show
  1. package/package.json +13 -3
  2. package/src/adapters/abstract/application-adapter.js +3 -0
  3. package/src/adapters/bun/create-app.js +2 -0
  4. package/src/adapters/node/create-app.js +2 -0
  5. package/src/adapters/shared/server-adapter.d.ts +1 -0
  6. package/src/adapters/shared/server-adapter.js +31 -22
  7. package/src/build/app-build-manifest-runtime.js +12 -1
  8. package/src/build/dev-browser-script-cache.d.ts +34 -0
  9. package/src/build/dev-browser-script-cache.js +90 -0
  10. package/src/build/lit-static-render-worker-context.d.ts +2 -0
  11. package/src/build/lit-static-render-worker-context.js +6 -0
  12. package/src/diagnostics/request-build-dedupe.d.ts +18 -0
  13. package/src/diagnostics/request-build-dedupe.js +33 -0
  14. package/src/diagnostics/startup-trace.d.ts +25 -0
  15. package/src/diagnostics/startup-trace.js +121 -0
  16. package/src/env.d.ts +2 -0
  17. package/src/index.d.ts +1 -0
  18. package/src/index.js +4 -1
  19. package/src/plugins/integration-plugin.d.ts +8 -0
  20. package/src/plugins/processor.d.ts +6 -0
  21. package/src/plugins/processor.js +2 -1
  22. package/src/route-renderer/orchestration/page-browser-graph.service.js +15 -9
  23. package/src/route-renderer/page-loading/ecopages-virtual-imports.d.ts +6 -0
  24. package/src/route-renderer/page-loading/ecopages-virtual-imports.js +7 -2
  25. package/src/route-renderer/page-loading/module-declaration-aggregation.js +4 -0
  26. package/src/services/assets/asset-processing-service/asset-processing.service.d.ts +3 -0
  27. package/src/services/assets/asset-processing-service/asset-processing.service.js +41 -4
  28. package/src/services/assets/asset-processing-service/finalize-processed-asset.d.ts +3 -0
  29. package/src/services/assets/asset-processing-service/finalize-processed-asset.js +7 -0
  30. package/src/services/assets/asset-processing-service/grouped-content-bundles.d.ts +2 -1
  31. package/src/services/assets/asset-processing-service/grouped-content-bundles.js +20 -10
  32. package/src/services/assets/asset-processing-service/index.d.ts +1 -0
  33. package/src/services/assets/asset-processing-service/index.js +1 -0
  34. package/src/services/assets/asset-processing-service/materialize-content-script-asset.d.ts +11 -0
  35. package/src/services/assets/asset-processing-service/materialize-content-script-asset.js +17 -0
  36. package/src/services/assets/asset-processing-service/processors/script/content-script.processor.d.ts +7 -0
  37. package/src/services/assets/asset-processing-service/processors/script/content-script.processor.js +105 -79
  38. package/src/services/assets/asset-processing-service/resolve-integration-plugin.d.ts +4 -0
  39. package/src/services/assets/asset-processing-service/resolve-integration-plugin.js +17 -0
  40. package/src/services/assets/asset-processing-service/ungrouped-dependency-processing.d.ts +0 -1
  41. package/src/services/assets/asset-processing-service/ungrouped-dependency-processing.js +5 -10
  42. package/src/services/assets/browser-bundle.service.js +10 -2
  43. package/src/services/validation/schema-validation-service.d.ts +1 -4
  44. package/src/services/validation/schema-validation-service.js +12 -13
  45. package/src/services/validation/standard-schema.types.d.ts +9 -62
  46. package/src/services/validation/validate-standard-schema.d.ts +7 -0
  47. package/src/services/validation/validate-standard-schema.js +14 -0
  48. package/src/types/public-types.d.ts +2 -2
@@ -1,8 +1,8 @@
1
1
  import { fileSystem } from "@ecopages/file-system";
2
+ import { finalizeProcessedAsset } from "./finalize-processed-asset.js";
2
3
  async function processUngroupedDependency(options) {
3
4
  const {
4
5
  dep,
5
- key,
6
6
  depKey,
7
7
  getCachedAsset,
8
8
  getProcessor,
@@ -14,7 +14,7 @@ async function processUngroupedDependency(options) {
14
14
  } = options;
15
15
  const cached = getCachedAsset(dep, depKey);
16
16
  if (cached) {
17
- return { key, ...cached };
17
+ return finalizeProcessedAsset(cached, resolveProcessedAssetSrcUrl);
18
18
  }
19
19
  const processor = getProcessor(dep);
20
20
  if (!processor) {
@@ -27,14 +27,9 @@ async function processUngroupedDependency(options) {
27
27
  }
28
28
  try {
29
29
  const processed = await processor.process(dep);
30
- const srcUrl = resolveProcessedAssetSrcUrl(processed);
31
- const processedWithKey = {
32
- key,
33
- ...processed,
34
- srcUrl
35
- };
36
- setCachedAsset(dep, depKey, processedWithKey);
37
- return processedWithKey;
30
+ const finalized = finalizeProcessedAsset(processed, resolveProcessedAssetSrcUrl);
31
+ setCachedAsset(dep, depKey, finalized);
32
+ return finalized;
38
33
  } catch (error) {
39
34
  logProcessingError(dep, error);
40
35
  return null;
@@ -2,6 +2,9 @@ import { getAppBrowserBuildPlugins, getAppTranspileOptions } from "../../build/b
2
2
  import { requireBuildRuntime } from "../../build/build-runtime.js";
3
3
  import { mergeEcoBuildPlugins } from "../../build/build-manifest.js";
4
4
  import { getAppSourceTransforms } from "../../plugins/source-transform.js";
5
+ import { startupTrace } from "../../diagnostics/startup-trace.js";
6
+ import { requestBuildDedupe } from "../../diagnostics/request-build-dedupe.js";
7
+ import { createBuildOptionsDedupeKey } from "../../build/deduping-build-executor.js";
5
8
  function resolveBrowserBundleExecutor(appConfig, profile, executor) {
6
9
  const buildRuntime = requireBuildRuntime(appConfig);
7
10
  if (executor === "hmr" && (profile === "hmr-entrypoint" || profile === "hmr-runtime")) {
@@ -38,12 +41,17 @@ class BrowserBundleService {
38
41
  sourceTransforms: getAppSourceTransforms(this.appConfig)
39
42
  };
40
43
  const buildExecutor = resolveBrowserBundleExecutor(this.appConfig, profile, executor);
41
- return await buildExecutor.build(request);
44
+ const dedupeKey = createBuildOptionsDedupeKey(request);
45
+ return requestBuildDedupe.dedupeBuild(dedupeKey, async () => {
46
+ const result = await buildExecutor.build(request);
47
+ startupTrace.recordBrowserBundle(result.outputs);
48
+ return result;
49
+ });
42
50
  }
43
51
  async bundleGroupedEntries(entries, options) {
44
52
  const request = {
45
53
  ...options,
46
- entrypoints: entries.map((entry) => entry.entrypoint)
54
+ entrypoints: Object.fromEntries(entries.map((entry) => [entry.entryName, entry.entrypoint]))
47
55
  };
48
56
  return this.bundle(request);
49
57
  }
@@ -113,10 +113,7 @@ export declare class SchemaValidationService {
113
113
  validateRequest(source: ValidationSource, schemas: ValidationSchemas): Promise<ValidationResult<ValidatedData>>;
114
114
  /**
115
115
  * Validates a single value against a Standard Schema.
116
- *
117
- * @param schema - The Standard Schema validator
118
- * @param data - The data to validate
119
- * @returns Validation result with validated data or errors
120
116
  */
117
+ private mapSchemaIssue;
121
118
  private validateWithSchema;
122
119
  }
@@ -1,3 +1,4 @@
1
+ import { SchemaError, validateStandardSchema } from "./validate-standard-schema.js";
1
2
  class SchemaValidationService {
2
3
  /**
3
4
  * Validates request data against provided schemas.
@@ -65,26 +66,24 @@ class SchemaValidationService {
65
66
  }
66
67
  /**
67
68
  * Validates a single value against a Standard Schema.
68
- *
69
- * @param schema - The Standard Schema validator
70
- * @param data - The data to validate
71
- * @returns Validation result with validated data or errors
72
69
  */
70
+ mapSchemaIssue(issue) {
71
+ return {
72
+ message: issue.message,
73
+ path: issue.path?.map((p) => typeof p === "object" && "key" in p ? p.key : p)
74
+ };
75
+ }
73
76
  async validateWithSchema(schema, data) {
74
77
  try {
75
- const resultOrPromise = schema["~standard"].validate(data);
76
- const result = resultOrPromise instanceof Promise ? await resultOrPromise : resultOrPromise;
77
- if (result.issues) {
78
+ const value = await validateStandardSchema(schema, data);
79
+ return { success: true, data: value };
80
+ } catch (error) {
81
+ if (error instanceof SchemaError) {
78
82
  return {
79
83
  success: false,
80
- errors: result.issues.map((issue) => ({
81
- message: issue.message,
82
- path: issue.path?.map((p) => typeof p === "object" && "key" in p ? p.key : p)
83
- }))
84
+ errors: error.issues.map((issue) => this.mapSchemaIssue(issue))
84
85
  };
85
86
  }
86
- return { success: true, data: result.value };
87
- } catch (error) {
88
87
  return {
89
88
  success: false,
90
89
  errors: [
@@ -1,65 +1,12 @@
1
+ import type { StandardSchemaV1 } from '@standard-schema/spec';
1
2
  /**
2
- * Standard Schema interface for universal validation.
3
- * Compatible with Zod, Valibot, ArkType, Effect Schema, and other validation libraries.
4
- *
3
+ * Ecopages aliases for the official Standard Schema V1 types.
5
4
  * @see https://standardschema.dev
6
- *
7
- * @example Using with Zod
8
- * ```typescript
9
- * import { z } from 'zod';
10
- *
11
- * const bodySchema = z.object({
12
- * title: z.string().min(1),
13
- * content: z.string()
14
- * });
15
- *
16
- * app.post('/posts', async (ctx) => {
17
- * const { title, content } = ctx.body;
18
- * return ctx.json({ id: 1, title, content });
19
- * }, {
20
- * schema: { body: bodySchema }
21
- * });
22
- * ```
23
5
  */
24
- export interface StandardSchema<Input = unknown, Output = Input> {
25
- readonly '~standard': {
26
- readonly version: 1;
27
- readonly vendor: string;
28
- readonly validate: (value: unknown) => StandardSchemaResult<Output> | Promise<StandardSchemaResult<Output>>;
29
- readonly types?: {
30
- readonly input: Input;
31
- readonly output: Output;
32
- };
33
- };
34
- }
35
- /**
36
- * Result of Standard Schema validation.
37
- */
38
- export type StandardSchemaResult<Output> = StandardSchemaSuccessResult<Output> | StandardSchemaFailureResult;
39
- /**
40
- * Successful validation result.
41
- */
42
- export interface StandardSchemaSuccessResult<Output> {
43
- readonly value: Output;
44
- readonly issues?: undefined;
45
- }
46
- /**
47
- * Failed validation result.
48
- */
49
- export interface StandardSchemaFailureResult {
50
- readonly value?: undefined;
51
- readonly issues: ReadonlyArray<StandardSchemaIssue>;
52
- }
53
- /**
54
- * Validation issue details.
55
- */
56
- export interface StandardSchemaIssue {
57
- readonly message: string;
58
- readonly path?: ReadonlyArray<PropertyKey | {
59
- key: PropertyKey;
60
- }>;
61
- }
62
- /**
63
- * Infers the output type from a Standard Schema.
64
- */
65
- export type InferOutput<T extends StandardSchema> = T extends StandardSchema<any, infer O> ? O : never;
6
+ export type StandardSchema<Input = unknown, Output = Input> = StandardSchemaV1<Input, Output>;
7
+ export type StandardSchemaResult<Output> = StandardSchemaV1.Result<Output>;
8
+ export type StandardSchemaSuccessResult<Output> = StandardSchemaV1.SuccessResult<Output>;
9
+ export type StandardSchemaFailureResult = StandardSchemaV1.FailureResult;
10
+ export type StandardSchemaIssue = StandardSchemaV1.Issue;
11
+ export type InferOutput<T extends StandardSchemaV1> = StandardSchemaV1.InferOutput<T>;
12
+ export type { StandardSchemaV1 } from '@standard-schema/spec';
@@ -0,0 +1,7 @@
1
+ import type { StandardSchemaV1 } from '@standard-schema/spec';
2
+ export { SchemaError } from '@standard-schema/utils';
3
+ /**
4
+ * Validates a value with any Standard Schema-compliant validator.
5
+ * Throws {@link SchemaError} when validation fails.
6
+ */
7
+ export declare function validateStandardSchema<T>(schema: StandardSchemaV1<unknown, T>, value: unknown): Promise<T>;
@@ -0,0 +1,14 @@
1
+ import { SchemaError } from "@standard-schema/utils";
2
+ import { SchemaError as SchemaError2 } from "@standard-schema/utils";
3
+ async function validateStandardSchema(schema, value) {
4
+ const resultOrPromise = schema["~standard"].validate(value);
5
+ const result = resultOrPromise instanceof Promise ? await resultOrPromise : resultOrPromise;
6
+ if (result.issues) {
7
+ throw new SchemaError(result.issues);
8
+ }
9
+ return result.value;
10
+ }
11
+ export {
12
+ SchemaError2 as SchemaError,
13
+ validateStandardSchema
14
+ };
@@ -89,8 +89,8 @@ export interface EcopagesWebSocketHandler<TContext = unknown, TParams extends Re
89
89
  onClose?(socket: EcopagesSocket<TContext, TParams>, event: WebSocketCloseInfo): void | Promise<void>;
90
90
  onError?(socket: EcopagesSocket<TContext, TParams>, error: unknown): void | Promise<void>;
91
91
  }
92
- import type { StandardSchema, StandardSchemaResult, StandardSchemaSuccessResult, StandardSchemaFailureResult, StandardSchemaIssue, InferOutput } from '../services/validation/standard-schema.types.js';
93
- export type { StandardSchema, StandardSchemaResult, StandardSchemaSuccessResult, StandardSchemaFailureResult, StandardSchemaIssue, InferOutput, ForeignChildRuntime, };
92
+ import type { StandardSchema, StandardSchemaResult, StandardSchemaSuccessResult, StandardSchemaFailureResult, StandardSchemaIssue, InferOutput, StandardSchemaV1 } from '../services/validation/standard-schema.types.js';
93
+ export type { StandardSchema, StandardSchemaResult, StandardSchemaSuccessResult, StandardSchemaFailureResult, StandardSchemaIssue, InferOutput, StandardSchemaV1, ForeignChildRuntime, };
94
94
  export type InteractionEventsString = ScriptsInjectorInteractionEventsString;
95
95
  export type DependencyLazyTrigger = {
96
96
  'on:idle': true;