@jay-framework/compiler-jay-html 0.12.0 → 0.14.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 +118 -3
  2. package/dist/index.js +16725 -14511
  3. package/package.json +10 -10
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { JayType, WithValidations, PluginComponentResolution, JayEnumType, RefsTree, CompilerSourceFile, SourceFileFormat, JayImportLink, MainRuntimeModes, GenerateTarget, Imports } from '@jay-framework/compiler-shared';
1
+ import { JayType, WithValidations, PluginComponentResolution, PluginManifest, JayEnumType, RefsTree, CompilerSourceFile, SourceFileFormat, JayImportLink, MainRuntimeModes, GenerateTarget, Imports, JayObjectType } 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
4
  import { Coordinate } from '@jay-framework/runtime';
@@ -80,7 +80,7 @@ interface JayImportResolver {
80
80
  /**
81
81
  * Load a contract from a plugin, handling both static and dynamic contracts.
82
82
  * For static contracts, loads from the plugin's contract file.
83
- * For dynamic contracts, loads from materialized location (build/materialized-contracts/).
83
+ * For dynamic contracts, loads from materialized location (agent-kit/materialized-contracts/).
84
84
  *
85
85
  * Returns the contract, path, and optional metadata (for dynamic contracts).
86
86
  */
@@ -89,6 +89,7 @@ interface JayImportResolver {
89
89
  contractPath: string;
90
90
  metadata?: Record<string, unknown>;
91
91
  }>;
92
+ resolvePluginManifest(pluginName: string, projectRoot: string): WithValidations<PluginManifest>;
92
93
  }
93
94
  declare const JAY_IMPORT_RESOLVER: JayImportResolver;
94
95
 
@@ -194,10 +195,54 @@ interface JayHtmlSourceFile extends CompilerSourceFile {
194
195
  declare function generateElementDefinitionFile(parsedFile: WithValidations<JayHtmlSourceFile>): WithValidations<string>;
195
196
  declare function generateElementFile(jayFile: JayHtmlSourceFile, importerMode: MainRuntimeModes): WithValidations<string>;
196
197
  declare function generateElementBridgeFile(jayFile: JayHtmlSourceFile): string;
198
+ declare function generateElementHydrateFile(jayFile: JayHtmlSourceFile, importerMode: MainRuntimeModes): WithValidations<string>;
199
+ interface ServerElementOptions {
200
+ /** Path to write debug coordinate pre-process output. When provided, the
201
+ * serialized DOM with jay-coordinate-base attributes is returned via result. */
202
+ debugCoordinatePreprocessPath?: string;
203
+ }
204
+ declare function generateServerElementFile(jayFile: JayHtmlSourceFile, _options?: ServerElementOptions): WithValidations<string>;
197
205
  declare function generateSandboxRootFile(jayFile: JayHtmlSourceFile): string;
198
206
 
199
207
  declare function generateElementFileReactTarget(jayFile: JayHtmlSourceFile, importerMode: MainRuntimeModes): WithValidations<string>;
200
208
 
209
+ /**
210
+ * Coordinate pre-processing for SSR/hydration consistency.
211
+ *
212
+ * Assigns `jay-coordinate-base` attributes to all elements that need coordinates,
213
+ * in a single pass before either server or hydrate compilation runs.
214
+ * Both compilers read this attribute instead of computing coordinates independently.
215
+ *
216
+ * See Design Log #103, #106.
217
+ */
218
+
219
+ interface AssignCoordinatesOptions {
220
+ /** Set of headless contract names (for detecting <jay:xxx> tags) */
221
+ headlessContractNames: Set<string>;
222
+ /** @internal Auto-generated ref counters for headless instances without explicit refs.
223
+ * Created automatically if not provided. */
224
+ _refCounters?: Map<string, number>;
225
+ }
226
+ interface AssignCoordinatesResult {
227
+ /** Serialized DOM with jay-coordinate-base attributes, for debug output */
228
+ debugHtml: string;
229
+ }
230
+ /**
231
+ * Assign coordinates to a full jay-html string and return the result.
232
+ * Used by the pre-render pipeline so discoverHeadlessInstances gets elements
233
+ * with jay-coordinate-base, matching the hydrate compiler's coordinate format.
234
+ */
235
+ declare function assignCoordinatesToJayHtml(jayHtml: string, headlessContractNames: Set<string>): string;
236
+ /**
237
+ * Assign `jay-coordinate-base` attributes to elements in the DOM tree.
238
+ *
239
+ * Must run after slow-render (which resolves slow conditions, unrolls slowForEach,
240
+ * and wraps multi-child headless inline templates).
241
+ *
242
+ * Mutates the DOM in place. Returns the serialized DOM for debug output.
243
+ */
244
+ declare function assignCoordinates(body: HTMLElement, options: AssignCoordinatesOptions): AssignCoordinatesResult;
245
+
201
246
  declare function parseJayFile(html: string, filename: string, filePath: string, options: ResolveTsConfigOptions, linkedContractResolver: JayImportResolver, projectRoot: string): Promise<WithValidations<JayHtmlSourceFile>>;
202
247
  declare function getJayHtmlImports(html: string): string[];
203
248
 
@@ -211,6 +256,58 @@ declare function renderRefsType(refs: RefsTree, refsType: string, generateTarget
211
256
 
212
257
  declare function generateTypes(types: JayType): string;
213
258
 
259
+ /**
260
+ * Parser for .jay-action files (compact jay-type notation).
261
+ *
262
+ * Produces JayType from the compact format used by jay-html data scripts:
263
+ * - Primitives: string, number, boolean → JayAtomicType
264
+ * - Enums: enum(a | b | c) → JayEnumType
265
+ * - Arrays: YAML list / type[] shorthand → JayArrayType
266
+ * - Objects: nested YAML maps → JayObjectType (with optionalProps tracking)
267
+ * - Optional: ? suffix on property keys → tracked in JayObjectType.optionalProps
268
+ * - Contract imports: import: block → JayImportedType
269
+ */
270
+
271
+ /**
272
+ * Parsed action definition from a .jay-action file.
273
+ * Uses JayType for the type representation.
274
+ */
275
+ interface ActionDefinition {
276
+ name: string;
277
+ description: string;
278
+ /** Import aliases: alias → contract subpath (e.g., productCard → product-card.jay-contract) */
279
+ imports: Record<string, string>;
280
+ /** Input schema as a JayObjectType. Optional props tracked in optionalProps. */
281
+ inputType: JayObjectType;
282
+ /** Output type (any JayType shape, or undefined if no output). */
283
+ outputType?: JayType;
284
+ }
285
+ /**
286
+ * Parses a .jay-action YAML string into an ActionDefinition using JayType.
287
+ */
288
+ declare function parseAction(actionYaml: string, fileName: string): WithValidations<ActionDefinition>;
289
+
290
+ /**
291
+ * Compiler for .jay-action files → .jay-action.d.ts
292
+ *
293
+ * Generates TypeScript Input/Output interfaces from JayType trees,
294
+ * including import statements for contract references (JayImportedType).
295
+ */
296
+
297
+ interface ContractImportInfo {
298
+ importPath: string;
299
+ viewStateName: string;
300
+ }
301
+ type ContractResolver = (contractSubpath: string) => ContractImportInfo | null;
302
+ /**
303
+ * Default contract resolver that derives names from the subpath.
304
+ */
305
+ declare function defaultContractResolver(contractSubpath: string): ContractImportInfo;
306
+ /**
307
+ * Compiles an ActionDefinition (with JayType) into a TypeScript .d.ts string.
308
+ */
309
+ declare function compileAction(actionWithValidations: WithValidations<ActionDefinition>, contractResolver?: ContractResolver): WithValidations<string>;
310
+
214
311
  /**
215
312
  * Headless contract with its key (used for property path prefix)
216
313
  */
@@ -302,8 +399,26 @@ interface HeadlessInstanceResolvedData {
302
399
  * a coordinateCounters map must be provided to auto-assign an index.
303
400
  */
304
401
  declare function buildInstanceCoordinateKey(element: HTMLElement, contractName: string, coordinateCounters?: Map<string, number>): string;
402
+ /**
403
+ * A headless instance found inside a preserved forEach (fast phase).
404
+ * These instances have unresolved prop bindings and need per-item rendering
405
+ * at fast phase time. They are only allowed if the component has no slow phase.
406
+ */
407
+ interface ForEachHeadlessInstance {
408
+ contractName: string;
409
+ /** The forEach attribute path on the ancestor element (e.g., "allProducts.items") */
410
+ forEachPath: string;
411
+ /** TrackBy key for the forEach (e.g., "_id") */
412
+ trackBy: string;
413
+ /** Prop bindings referencing forEach item fields (e.g., { productId: "{_id}" }) */
414
+ propBindings: Record<string, string>;
415
+ /** Coordinate suffix after trackBy values (e.g., "product-card:0") */
416
+ coordinateSuffix: string;
417
+ }
305
418
  interface HeadlessInstanceDiscoveryResult {
306
419
  instances: DiscoveredHeadlessInstance[];
420
+ /** Headless instances inside preserved forEach elements (need server-time validation) */
421
+ forEachInstances: ForEachHeadlessInstance[];
307
422
  /** HTML with auto-generated ref attributes embedded on <jay:xxx> elements */
308
423
  preRenderedJayHtml: string;
309
424
  }
@@ -314,4 +429,4 @@ declare function resolveHeadlessInstances(preRenderedJayHtml: string, instanceDa
314
429
  */
315
430
  declare function hasSlowPhaseProperties(contract: Contract | undefined): boolean;
316
431
 
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 };
432
+ export { type ActionDefinition, type AssignCoordinatesOptions, type AssignCoordinatesResult, type Contract, type ContractImportInfo, type ContractParam, type ContractProp, type ContractResolver, type ContractTag, ContractTagType, type DiscoveredHeadlessInstance, type EnumToImport, type ForEachHeadlessInstance, type HeadlessContractInfo, type HeadlessInstanceDiscoveryResult, type HeadlessInstanceResolvedData, JAY_IMPORT_RESOLVER, type JayContractImportLink, type JayHtmlSourceFile, type JayImportResolver, type PhaseViewStates, type RenderingPhase, type ServerElementOptions, type SlowRenderInput, type SlowRenderOutput, assignCoordinates, assignCoordinatesToJayHtml, buildInstanceCoordinateKey, compileAction, compileContract, contractToAllPhaseViewStates, contractToImportsViewStateAndRefs, contractToPhaseViewState, createPhaseContract, defaultContractResolver, discoverHeadlessInstances, filterTagsByPhase, generateElementBridgeFile, generateElementDefinitionFile, generateElementFile, generateElementFileReactTarget, generateElementHydrateFile, generateSandboxRootFile, generateServerElementFile, generateTypes, getEffectivePhase, getJayHtmlImports, getLinkedContractDir, hasSlowPhaseProperties, isTagInPhase, loadLinkedContract, parseAction, parseContract, parseEnumValues, parseIsEnum, parseJayFile, renderRefsType, resolveHeadlessInstances, slowRenderTransform, validateContractPhases };