@jay-framework/compiler-jay-html 0.11.0 → 0.12.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.
Files changed (3) hide show
  1. package/dist/index.d.cts +141 -3
  2. package/dist/index.js +16050 -7952
  3. package/package.json +10 -9
package/dist/index.d.cts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { JayType, WithValidations, PluginComponentResolution, JayEnumType, RefsTree, CompilerSourceFile, SourceFileFormat, JayImportLink, MainRuntimeModes, GenerateTarget, Imports } from '@jay-framework/compiler-shared';
2
2
  import { HTMLElement } from 'node-html-parser';
3
3
  import { ResolveTsConfigOptions } from '@jay-framework/compiler-analyze-exported-types';
4
+ import { Coordinate } from '@jay-framework/runtime';
4
5
 
5
6
  declare enum ContractTagType {
6
7
  data = 0,
@@ -23,20 +24,71 @@ interface ContractTag {
23
24
  async?: boolean;
24
25
  phase?: RenderingPhase;
25
26
  }
27
+ interface ContractProp {
28
+ name: string;
29
+ dataType: JayType;
30
+ required?: boolean;
31
+ description?: Array<string>;
32
+ default?: string;
33
+ }
34
+ /** URL/load params for a page (e.g. [slug]). Always string in generated type (UrlParams = Record<string, string>). Design Log #85. */
35
+ interface ContractParam {
36
+ name: string;
37
+ }
26
38
  interface Contract {
27
39
  name: string;
28
40
  tags: Array<ContractTag>;
41
+ props?: Array<ContractProp>;
42
+ /** URL/load params (e.g. slug for [slug] route). Generates Params extends UrlParams. */
43
+ params?: Array<ContractParam>;
29
44
  }
30
45
 
31
46
  declare function compileContract(contractWithValidations: WithValidations<Contract>, contractFilePath: string, jayImportResolver: JayImportResolver): Promise<WithValidations<string>>;
32
47
 
33
48
  declare function parseContract(contractYaml: string, fileName: string): WithValidations<Contract>;
34
49
 
50
+ /**
51
+ * Get the effective phase for a tag (explicit or default)
52
+ */
53
+ declare function getEffectivePhase(tag: ContractTag, parentPhase?: RenderingPhase): RenderingPhase;
54
+ /**
55
+ * Check if a tag should be included in a specific phase's ViewState
56
+ * A tag is included if its effective phase exactly matches the target phase
57
+ */
58
+ declare function isTagInPhase(tag: ContractTag, targetPhase: RenderingPhase, parentPhase?: RenderingPhase): boolean;
59
+ /**
60
+ * Validate phase constraints across the entire contract
61
+ */
62
+ declare function validateContractPhases(contract: Contract): string[];
63
+ /**
64
+ * Filter tags recursively by phase
65
+ * Returns only tags that should be included in the target phase's ViewState
66
+ */
67
+ declare function filterTagsByPhase(tags: ContractTag[], targetPhase: RenderingPhase, parentPhase?: RenderingPhase): ContractTag[];
68
+ /**
69
+ * Create a phase-specific contract
70
+ * Returns a contract with only tags that belong to the target phase
71
+ */
72
+ declare function createPhaseContract(contract: Contract, targetPhase: RenderingPhase): Contract;
73
+
35
74
  interface JayImportResolver {
36
75
  resolveLink(importingModuleDir: string, link: string): string;
76
+ /** Load a contract from an absolute file path */
37
77
  loadContract(fullPath: string): WithValidations<Contract>;
38
78
  analyzeExportedTypes(fullPath: string, options: ResolveTsConfigOptions): JayType[];
39
79
  resolvePluginComponent(pluginName: string, contractName: string, projectRoot: string): WithValidations<PluginComponentResolution>;
80
+ /**
81
+ * Load a contract from a plugin, handling both static and dynamic contracts.
82
+ * For static contracts, loads from the plugin's contract file.
83
+ * For dynamic contracts, loads from materialized location (build/materialized-contracts/).
84
+ *
85
+ * Returns the contract, path, and optional metadata (for dynamic contracts).
86
+ */
87
+ loadPluginContract(pluginName: string, contractName: string, projectRoot: string): WithValidations<{
88
+ contract: Contract;
89
+ contractPath: string;
90
+ metadata?: Record<string, unknown>;
91
+ }>;
40
92
  }
41
93
  declare const JAY_IMPORT_RESOLVER: JayImportResolver;
42
94
 
@@ -71,17 +123,38 @@ interface PhaseViewStates {
71
123
  */
72
124
  declare function contractToAllPhaseViewStates(contract: Contract, contractFilePath: string, jayImportResolver: JayImportResolver): Promise<WithValidations<PhaseViewStates>>;
73
125
 
126
+ /**
127
+ * Load a linked contract using the import resolver.
128
+ * Returns the parsed contract or null if not found/failed.
129
+ *
130
+ * @param linkPath - The link path from the contract (e.g., "./product-card")
131
+ * @param baseContractDir - Directory of the contract containing the link
132
+ * @param importResolver - Import resolver for loading contracts
133
+ */
134
+ declare function loadLinkedContract(linkPath: string, baseContractDir: string, importResolver: JayImportResolver): Contract | null;
135
+ /**
136
+ * Get the directory of a linked contract for resolving nested links.
137
+ *
138
+ * @param linkPath - The link path from the contract (e.g., "./product-card")
139
+ * @param baseContractDir - Directory of the contract containing the link
140
+ * @param importResolver - Import resolver for path resolution
141
+ */
142
+ declare function getLinkedContractDir(linkPath: string, baseContractDir: string, importResolver: JayImportResolver): string;
143
+
74
144
  interface JayHtmlNamespace {
75
145
  prefix: string;
76
146
  namespace: string;
77
147
  }
78
148
  interface JayHeadlessImports {
79
- key: string;
149
+ key?: string;
150
+ contractName: string;
80
151
  refs: RefsTree;
81
152
  rootType: JayType;
82
153
  contractLinks: JayImportLink[];
83
154
  codeLink: JayImportLink;
84
155
  contract?: Contract;
156
+ contractPath?: string;
157
+ metadata?: Record<string, unknown>;
85
158
  }
86
159
  interface JayHtmlHeadLink {
87
160
  rel: string;
@@ -138,6 +211,19 @@ declare function renderRefsType(refs: RefsTree, refsType: string, generateTarget
138
211
 
139
212
  declare function generateTypes(types: JayType): string;
140
213
 
214
+ /**
215
+ * Headless contract with its key (used for property path prefix)
216
+ */
217
+ interface HeadlessContractInfo {
218
+ /** The key attribute from the headless script tag */
219
+ key: string;
220
+ /** The parsed contract */
221
+ contract: Contract;
222
+ /** Path to the contract file (used to resolve linked sub-contracts) */
223
+ contractPath?: string;
224
+ /** Optional metadata from the generator (for dynamic contracts) */
225
+ metadata?: Record<string, unknown>;
226
+ }
141
227
  /**
142
228
  * Input for slow render transformation
143
229
  */
@@ -146,14 +232,24 @@ interface SlowRenderInput {
146
232
  jayHtmlContent: string;
147
233
  /** Slow phase view state data */
148
234
  slowViewState: Record<string, unknown>;
149
- /** Contract metadata for phase detection */
235
+ /** Contract metadata for phase detection (page's main contract) */
150
236
  contract?: Contract;
237
+ /**
238
+ * Headless component contracts, keyed by their `key` attribute.
239
+ * These contracts provide phase info for properties like `productSearch.categoryName`.
240
+ */
241
+ headlessContracts?: HeadlessContractInfo[];
151
242
  /**
152
243
  * Source directory of the original jay-html file.
153
244
  * Used to resolve relative paths (contracts, CSS, components) to absolute paths
154
245
  * so the pre-rendered file can be placed in a different directory.
155
246
  */
156
247
  sourceDir?: string;
248
+ /**
249
+ * Import resolver for loading linked sub-contracts.
250
+ * If not provided, linked sub-contracts will not be resolved.
251
+ */
252
+ importResolver?: JayImportResolver;
157
253
  }
158
254
  /**
159
255
  * Output of slow render transformation
@@ -171,9 +267,51 @@ interface SlowRenderOutput {
171
267
  * @returns The pre-rendered jay-html with slow bindings resolved
172
268
  */
173
269
  declare function slowRenderTransform(input: SlowRenderInput): WithValidations<SlowRenderOutput>;
270
+ /**
271
+ * Discovered headless component instance in pre-rendered jay-html.
272
+ * Found after Pass 1 (page bindings resolved, slow forEach unrolled).
273
+ */
274
+ interface DiscoveredHeadlessInstance {
275
+ /** Contract name from tag name (e.g., "product-card" from <jay:product-card>) */
276
+ contractName: string;
277
+ /** Props extracted from element attributes (camelCased keys, string values) */
278
+ props: Record<string, string>;
279
+ /**
280
+ * Coordinate that uniquely identifies this instance in the page tree.
281
+ * Built from ancestor slowForEach jayTrackBy values + "contractName:localIndex".
282
+ */
283
+ coordinate: Coordinate;
284
+ }
285
+ /**
286
+ * Resolved data for a headless component instance.
287
+ * Provided by the dev server after calling slowlyRender for each discovered instance.
288
+ */
289
+ interface HeadlessInstanceResolvedData {
290
+ /** Coordinate matching the discovered instance */
291
+ coordinate: Coordinate;
292
+ /** The component's contract (for phase detection) */
293
+ contract: Contract;
294
+ /** Slow phase ViewState data for this instance */
295
+ slowViewState: Record<string, unknown>;
296
+ }
297
+ /**
298
+ * Build the full coordinate key string for a <jay:xxx> element.
299
+ * Format: "jayTrackBy1/jayTrackBy2/.../contractName:ref"
300
+ *
301
+ * Uses the element's `ref` attribute if present. If the element has no ref,
302
+ * a coordinateCounters map must be provided to auto-assign an index.
303
+ */
304
+ declare function buildInstanceCoordinateKey(element: HTMLElement, contractName: string, coordinateCounters?: Map<string, number>): string;
305
+ interface HeadlessInstanceDiscoveryResult {
306
+ instances: DiscoveredHeadlessInstance[];
307
+ /** HTML with auto-generated ref attributes embedded on <jay:xxx> elements */
308
+ preRenderedJayHtml: string;
309
+ }
310
+ declare function discoverHeadlessInstances(preRenderedJayHtml: string): HeadlessInstanceDiscoveryResult;
311
+ declare function resolveHeadlessInstances(preRenderedJayHtml: string, instanceData: HeadlessInstanceResolvedData[], importResolver?: JayImportResolver): WithValidations<string>;
174
312
  /**
175
313
  * Check if a jay-html file has any slow-phase properties that can be pre-rendered
176
314
  */
177
315
  declare function hasSlowPhaseProperties(contract: Contract | undefined): boolean;
178
316
 
179
- export { type Contract, type ContractTag, ContractTagType, type EnumToImport, JAY_IMPORT_RESOLVER, type JayContractImportLink, type JayHtmlSourceFile, type JayImportResolver, type PhaseViewStates, type RenderingPhase, type SlowRenderInput, type SlowRenderOutput, compileContract, contractToAllPhaseViewStates, contractToImportsViewStateAndRefs, contractToPhaseViewState, generateElementBridgeFile, generateElementDefinitionFile, generateElementFile, generateElementFileReactTarget, generateSandboxRootFile, generateTypes, getJayHtmlImports, hasSlowPhaseProperties, parseContract, parseEnumValues, parseIsEnum, parseJayFile, renderRefsType, slowRenderTransform };
317
+ export { type Contract, type ContractParam, type ContractProp, type ContractTag, ContractTagType, type DiscoveredHeadlessInstance, type EnumToImport, type HeadlessContractInfo, type HeadlessInstanceDiscoveryResult, type HeadlessInstanceResolvedData, JAY_IMPORT_RESOLVER, type JayContractImportLink, type JayHtmlSourceFile, type JayImportResolver, type PhaseViewStates, type RenderingPhase, type SlowRenderInput, type SlowRenderOutput, buildInstanceCoordinateKey, compileContract, contractToAllPhaseViewStates, contractToImportsViewStateAndRefs, contractToPhaseViewState, createPhaseContract, discoverHeadlessInstances, filterTagsByPhase, generateElementBridgeFile, generateElementDefinitionFile, generateElementFile, generateElementFileReactTarget, generateSandboxRootFile, generateTypes, getEffectivePhase, getJayHtmlImports, getLinkedContractDir, hasSlowPhaseProperties, isTagInPhase, loadLinkedContract, parseContract, parseEnumValues, parseIsEnum, parseJayFile, renderRefsType, resolveHeadlessInstances, slowRenderTransform, validateContractPhases };