@jay-framework/fullstack-component 0.15.6 → 0.16.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 +64 -1
- package/dist/index.js +38 -0
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -570,6 +570,69 @@ type ActionOutput<T> = T extends JayAction<any, infer O> ? O : never;
|
|
|
570
570
|
* Check if a value is a JayAction.
|
|
571
571
|
*/
|
|
572
572
|
declare function isJayAction(value: unknown): value is JayAction<unknown, unknown>;
|
|
573
|
+
/**
|
|
574
|
+
* A callable streaming action that returns an async iterable of chunks.
|
|
575
|
+
* Server handler is an async generator; client receives chunks via NDJSON.
|
|
576
|
+
*/
|
|
577
|
+
interface JayStreamAction<Input, Chunk> {
|
|
578
|
+
/** Call the action — returns async iterable of chunks */
|
|
579
|
+
(input: Input): AsyncIterable<Chunk>;
|
|
580
|
+
/** Unique action name for routing */
|
|
581
|
+
readonly actionName: string;
|
|
582
|
+
/** HTTP method (always POST for streaming) */
|
|
583
|
+
readonly method: 'POST';
|
|
584
|
+
/** Streaming flag */
|
|
585
|
+
readonly isStreaming: true;
|
|
586
|
+
/** Internal marker for type identification */
|
|
587
|
+
readonly _brand: 'JayStreamAction';
|
|
588
|
+
}
|
|
589
|
+
/**
|
|
590
|
+
* Internal definition for server-side registration of streaming actions.
|
|
591
|
+
*/
|
|
592
|
+
interface JayStreamActionDefinition<Input, Chunk, Services extends any[]> {
|
|
593
|
+
actionName: string;
|
|
594
|
+
method: 'POST';
|
|
595
|
+
isStreaming: true;
|
|
596
|
+
services: ServiceMarkers<Services>;
|
|
597
|
+
handler: (input: Input, ...services: Services) => AsyncIterable<Chunk>;
|
|
598
|
+
}
|
|
599
|
+
/**
|
|
600
|
+
* Builder interface for streaming actions.
|
|
601
|
+
*/
|
|
602
|
+
interface JayStreamBuilder<Services extends any[]> {
|
|
603
|
+
withServices<NewServices extends any[]>(...services: ServiceMarkers<NewServices>): JayStreamBuilder<NewServices>;
|
|
604
|
+
withHandler<I, C>(handler: (input: I, ...services: Services) => AsyncIterable<C>): JayStreamAction<I, C> & JayStreamActionDefinition<I, C, Services>;
|
|
605
|
+
}
|
|
606
|
+
/**
|
|
607
|
+
* Create a streaming action that yields chunks via an async generator.
|
|
608
|
+
* Use for paginated data, long-running operations, or any streaming response.
|
|
609
|
+
*
|
|
610
|
+
* @param name - Unique action name (e.g., 'routes.discoverParams')
|
|
611
|
+
*
|
|
612
|
+
* @example
|
|
613
|
+
* ```typescript
|
|
614
|
+
* export const discoverParams = makeJayStream('routes.discoverParams')
|
|
615
|
+
* .withServices(PRODUCTS_SERVICE)
|
|
616
|
+
* .withHandler(async function* (input: { route: string }, productsService) {
|
|
617
|
+
* let page = 1;
|
|
618
|
+
* while (true) {
|
|
619
|
+
* const products = await productsService.list({ page, pageSize: 100 });
|
|
620
|
+
* yield products.map(p => ({ slug: p.slug }));
|
|
621
|
+
* if (!products.hasMore) break;
|
|
622
|
+
* page++;
|
|
623
|
+
* }
|
|
624
|
+
* });
|
|
625
|
+
* ```
|
|
626
|
+
*/
|
|
627
|
+
declare function makeJayStream(name: string): JayStreamBuilder<[]>;
|
|
628
|
+
/**
|
|
629
|
+
* Check if a value is a JayStreamAction.
|
|
630
|
+
*/
|
|
631
|
+
declare function isJayStreamAction(value: unknown): value is JayStreamAction<unknown, unknown>;
|
|
632
|
+
/**
|
|
633
|
+
* Extract the chunk type from a JayStreamAction.
|
|
634
|
+
*/
|
|
635
|
+
type StreamChunk<T> = T extends JayStreamAction<any, infer C> ? C : never;
|
|
573
636
|
|
|
574
637
|
/**
|
|
575
638
|
* Builder for plugin/project initialization with type-safe server-to-client data flow.
|
|
@@ -673,4 +736,4 @@ declare function makeJayInit(key?: string): JayInitBuilder<void>;
|
|
|
673
736
|
*/
|
|
674
737
|
declare function isJayInit(obj: unknown): obj is JayInit<any>;
|
|
675
738
|
|
|
676
|
-
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 HeadTag, 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 RequestQuery, 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 };
|
|
739
|
+
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 HeadTag, type HttpMethod, type JayAction, type JayActionBuilder, type JayActionDefinition, type JayInit, type JayInitBuilder, type JayInitBuilderWithServer, type JayStackComponentDefinition, type JayStreamAction, type JayStreamActionDefinition, type JayStreamBuilder, type LoadParams, type PageProps, type PartialRender, type PhaseOutput, type PipelineFactory, type Redirect3xx, type RenderFast, type RenderOutcome, RenderPipeline, type RenderSlowly, type RequestQuery, type ServerError5xx, type ServiceInstances, type ServiceMarker, type ServiceMarkers, type Signals, type SlowlyRenderResult, type StreamChunk, type UrlParams, badRequest, clientError4xx, createJayService, forbidden, isJayAction, isJayInit, isJayStreamAction, makeContractGenerator, makeJayAction, makeJayInit, makeJayQuery, makeJayStackComponent, makeJayStream, notFound, partialRender, phaseOutput, redirect3xx, serverError5xx, unauthorized };
|
package/dist/index.js
CHANGED
|
@@ -411,6 +411,42 @@ function makeJayQuery(name) {
|
|
|
411
411
|
function isJayAction(value) {
|
|
412
412
|
return typeof value === "function" && value._brand === "JayAction" && typeof value.actionName === "string";
|
|
413
413
|
}
|
|
414
|
+
class JayStreamBuilderImpl {
|
|
415
|
+
constructor(_actionName) {
|
|
416
|
+
__publicField(this, "_services", []);
|
|
417
|
+
this._actionName = _actionName;
|
|
418
|
+
}
|
|
419
|
+
withServices(...services) {
|
|
420
|
+
this._services = services;
|
|
421
|
+
return this;
|
|
422
|
+
}
|
|
423
|
+
withHandler(handler) {
|
|
424
|
+
const actionName = this._actionName;
|
|
425
|
+
const serviceMarkers = this._services;
|
|
426
|
+
const action = Object.assign(
|
|
427
|
+
(input) => {
|
|
428
|
+
const resolver = globalThis.__JAY_SERVICE_RESOLVER__;
|
|
429
|
+
const resolvedServices = resolver ? resolver(serviceMarkers) : [];
|
|
430
|
+
return handler(input, ...resolvedServices);
|
|
431
|
+
},
|
|
432
|
+
{
|
|
433
|
+
actionName,
|
|
434
|
+
method: "POST",
|
|
435
|
+
isStreaming: true,
|
|
436
|
+
services: serviceMarkers,
|
|
437
|
+
handler,
|
|
438
|
+
_brand: "JayStreamAction"
|
|
439
|
+
}
|
|
440
|
+
);
|
|
441
|
+
return action;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
function makeJayStream(name) {
|
|
445
|
+
return new JayStreamBuilderImpl(name);
|
|
446
|
+
}
|
|
447
|
+
function isJayStreamAction(value) {
|
|
448
|
+
return typeof value === "function" && value._brand === "JayStreamAction" && typeof value.actionName === "string";
|
|
449
|
+
}
|
|
414
450
|
function makeJayInit(key) {
|
|
415
451
|
const resolvedKey = key ?? "__JAY_INIT_KEY__";
|
|
416
452
|
return {
|
|
@@ -455,11 +491,13 @@ export {
|
|
|
455
491
|
forbidden,
|
|
456
492
|
isJayAction,
|
|
457
493
|
isJayInit,
|
|
494
|
+
isJayStreamAction,
|
|
458
495
|
makeContractGenerator,
|
|
459
496
|
makeJayAction,
|
|
460
497
|
makeJayInit,
|
|
461
498
|
makeJayQuery,
|
|
462
499
|
makeJayStackComponent,
|
|
500
|
+
makeJayStream,
|
|
463
501
|
notFound,
|
|
464
502
|
partialRender,
|
|
465
503
|
phaseOutput,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jay-framework/fullstack-component",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.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.
|
|
30
|
-
"@jay-framework/runtime": "^0.
|
|
29
|
+
"@jay-framework/component": "^0.16.0",
|
|
30
|
+
"@jay-framework/runtime": "^0.16.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@jay-framework/dev-environment": "^0.
|
|
34
|
-
"@jay-framework/jay-cli": "^0.
|
|
33
|
+
"@jay-framework/dev-environment": "^0.16.0",
|
|
34
|
+
"@jay-framework/jay-cli": "^0.16.0",
|
|
35
35
|
"@types/express": "^5.0.2",
|
|
36
36
|
"@types/node": "^22.15.21",
|
|
37
37
|
"nodemon": "^3.0.3",
|