@jay-framework/fullstack-component 0.11.0 → 0.13.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.d.ts CHANGED
@@ -31,30 +31,30 @@ type ServiceMarkers<T extends any[]> = {
31
31
  [K in keyof T]: ServiceMarker<T[K]>;
32
32
  };
33
33
  /**
34
- * Contract metadata passed to dynamic contract components.
35
- * Contains the contract name and original YAML definition.
36
- */
37
- interface DynamicContractMetadata {
38
- contractName: string;
39
- contractYaml: string;
40
- }
41
- /**
42
- * Built-in service for dynamic contract metadata.
43
- * Used by plugin system to pass contract metadata to shared components.
34
+ * Props passed to components that work with dynamic contracts.
35
+ * The runtime automatically populates these when a headless component
36
+ * is used with a dynamic contract.
37
+ *
38
+ * @typeParam TMetadata - The metadata type from the generator (defaults to Record<string, unknown>)
44
39
  *
45
40
  * @example
46
41
  * ```typescript
47
- * export const cmsCollection = makeJayStackComponent<DynamicContract>()
48
- * .withServices(DYNAMIC_CONTRACT_SERVICE)
49
- * .withFastRender(async (props, metadata: DynamicContractMetadata) => {
50
- * // metadata.contractName contains the full contract name (e.g., "BlogPostsList")
51
- * const collectionName = deriveCollectionName(metadata.contractName);
52
- * const items = await fetchCollection(collectionName);
53
- * return partialRender({ items }, {});
42
+ * interface MyMetadata { collectionId: string }
43
+ *
44
+ * export const collectionList = makeJayStackComponent<MyContract, DynamicContractProps<MyMetadata>>()
45
+ * .withServices(MY_DATA_SERVICE)
46
+ * .withSlowlyRender(async (props, dataService) => {
47
+ * const { collectionId } = props.metadata!; // Typed correctly
48
+ * // ...
54
49
  * });
55
50
  * ```
56
51
  */
57
- declare const DYNAMIC_CONTRACT_SERVICE: ServiceMarker<DynamicContractMetadata>;
52
+ interface DynamicContractProps<TMetadata = Record<string, unknown>> {
53
+ /** Contract name (e.g., "RecipesList" or "list/recipes-list") */
54
+ contractName: string;
55
+ /** Metadata from the generator */
56
+ metadata?: TMetadata;
57
+ }
58
58
  interface PageProps {
59
59
  language: string;
60
60
  url: string;
@@ -118,11 +118,26 @@ type AnyJayStackComponentDefinition = JayStackComponentDefinition<object, object
118
118
  *
119
119
  * This avoids dependency on compiler types - generators output contract YAML,
120
120
  * which the compiler parses using its own type system.
121
+ *
122
+ * @example
123
+ * ```typescript
124
+ * return {
125
+ * name: 'RecipesList',
126
+ * yaml: buildContractYaml(schema),
127
+ * description: 'List page for recipes',
128
+ * metadata: { collectionId: 'Recipes' }, // Passed to component via props.metadata
129
+ * };
130
+ * ```
121
131
  */
122
132
  interface GeneratedContractYaml {
133
+ /** Contract name (PascalCase, e.g., "BlogPostsList") */
123
134
  name: string;
135
+ /** Contract definition in YAML format */
124
136
  yaml: string;
137
+ /** Optional description for the contract */
125
138
  description?: string;
139
+ /** Optional metadata passed to component via DynamicContractProps.metadata */
140
+ metadata?: Record<string, unknown>;
126
141
  }
127
142
  /**
128
143
  * Function that generates contracts dynamically at build time.
@@ -384,6 +399,15 @@ declare class RenderPipeline<T, TargetVS extends object = object, TargetCF exten
384
399
  isError(): boolean;
385
400
  }
386
401
 
402
+ /**
403
+ * Service resolver function type.
404
+ * Registered by stack-server-runtime to enable automatic service injection
405
+ * when actions are called from server-side code.
406
+ */
407
+ type ServiceResolver = (markers: any[]) => any[];
408
+ declare global {
409
+ var __JAY_SERVICE_RESOLVER__: ServiceResolver | undefined;
410
+ }
387
411
  /**
388
412
  * Supported HTTP methods for actions and queries.
389
413
  */
@@ -612,4 +636,4 @@ declare function makeJayInit(key?: string): JayInitBuilder<void>;
612
636
  */
613
637
  declare function isJayInit(obj: unknown): obj is JayInit<any>;
614
638
 
615
- export { ActionError, type ActionInput, type ActionOutput, type AnyFastRenderResult, type AnyJayStackComponentDefinition, type AnySlowlyRenderResult, type Builder, type CacheOptions, type ClientError4xx, type ContractGeneratorFunction, DYNAMIC_CONTRACT_SERVICE, type DynamicContractGenerator, type DynamicContractMetadata, type FastRenderResult, type GeneratedContractYaml, type HttpMethod, type JayAction, type JayActionBuilder, type JayActionDefinition, type JayInit, type JayInitBuilder, type JayInitBuilderWithServer, type JayStackComponentDefinition, type LoadParams, type PageProps, type PartialRender, type PhaseOutput, type PipelineFactory, type Redirect3xx, type RenderFast, type RenderOutcome, RenderPipeline, type RenderSlowly, type ServerError5xx, type ServiceInstances, type ServiceMarker, type ServiceMarkers, type Signals, type SlowlyRenderResult, type UrlParams, badRequest, clientError4xx, createJayService, forbidden, isJayAction, isJayInit, makeContractGenerator, makeJayAction, makeJayInit, makeJayQuery, makeJayStackComponent, notFound, partialRender, phaseOutput, redirect3xx, serverError5xx, unauthorized };
639
+ export { ActionError, type ActionInput, type ActionOutput, type AnyFastRenderResult, type AnyJayStackComponentDefinition, type AnySlowlyRenderResult, type Builder, type CacheOptions, type ClientError4xx, type ContractGeneratorFunction, type DynamicContractGenerator, type DynamicContractProps, type FastRenderResult, type GeneratedContractYaml, type HttpMethod, type JayAction, type JayActionBuilder, type JayActionDefinition, type JayInit, type JayInitBuilder, type JayInitBuilderWithServer, type JayStackComponentDefinition, type LoadParams, type PageProps, type PartialRender, type PhaseOutput, type PipelineFactory, type Redirect3xx, type RenderFast, type RenderOutcome, RenderPipeline, type RenderSlowly, type ServerError5xx, type ServiceInstances, type ServiceMarker, type ServiceMarkers, type Signals, type SlowlyRenderResult, type UrlParams, badRequest, clientError4xx, createJayService, forbidden, isJayAction, isJayInit, makeContractGenerator, makeJayAction, makeJayInit, makeJayQuery, makeJayStackComponent, notFound, partialRender, phaseOutput, redirect3xx, serverError5xx, unauthorized };
package/dist/index.js CHANGED
@@ -49,7 +49,6 @@ function partialRender(rendered, carryForward) {
49
49
  function createJayService(name) {
50
50
  return Symbol(name);
51
51
  }
52
- const DYNAMIC_CONTRACT_SERVICE = createJayService("DynamicContract");
53
52
  class BuilderImplementation {
54
53
  constructor() {
55
54
  __publicField(this, "services", []);
@@ -370,14 +369,18 @@ class JayActionBuilderImpl {
370
369
  const actionName = this._actionName;
371
370
  const method = this._method;
372
371
  const cacheOptions = this._cacheOptions;
373
- const services = this._services;
372
+ const serviceMarkers = this._services;
374
373
  const action = Object.assign(
375
- (input) => handler(input, ...[]),
374
+ (input) => {
375
+ const resolver = globalThis.__JAY_SERVICE_RESOLVER__;
376
+ const resolvedServices = resolver ? resolver(serviceMarkers) : [];
377
+ return handler(input, ...resolvedServices);
378
+ },
376
379
  {
377
380
  actionName,
378
381
  method,
379
382
  cacheOptions,
380
- services,
383
+ services: serviceMarkers,
381
384
  handler,
382
385
  _brand: "JayAction"
383
386
  }
@@ -431,7 +434,6 @@ function isJayInit(obj) {
431
434
  }
432
435
  export {
433
436
  ActionError,
434
- DYNAMIC_CONTRACT_SERVICE,
435
437
  RenderPipeline,
436
438
  badRequest,
437
439
  clientError4xx,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jay-framework/fullstack-component",
3
- "version": "0.11.0",
3
+ "version": "0.13.0",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/index.js",
@@ -26,12 +26,12 @@
26
26
  "test:watch": "vitest"
27
27
  },
28
28
  "dependencies": {
29
- "@jay-framework/component": "^0.11.0",
30
- "@jay-framework/runtime": "^0.11.0"
29
+ "@jay-framework/component": "^0.13.0",
30
+ "@jay-framework/runtime": "^0.13.0"
31
31
  },
32
32
  "devDependencies": {
33
- "@jay-framework/dev-environment": "^0.11.0",
34
- "@jay-framework/jay-cli": "^0.11.0",
33
+ "@jay-framework/dev-environment": "^0.13.0",
34
+ "@jay-framework/jay-cli": "^0.13.0",
35
35
  "@types/express": "^5.0.2",
36
36
  "@types/node": "^22.15.21",
37
37
  "nodemon": "^3.0.3",