mlform 0.1.19 → 0.1.22

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 (110) hide show
  1. package/README.md +2 -2
  2. package/dist/{builtins-6Cv46IXP.js → builtins-B2U_ViF6.js} +12 -14
  3. package/dist/mlform/builtins.mjs +1 -1
  4. package/dist/mlform/kit.mjs +6 -8
  5. package/dist/mlform/primitives.mjs +1 -1
  6. package/dist/mlform/runtime.mjs +3 -3
  7. package/dist/mlform/schema.mjs +2 -2
  8. package/dist/mlform/transport.mjs +2 -2
  9. package/dist/{primitives-BNBNG2Aa.js → primitives-ljp3c5R8.js} +11 -54
  10. package/dist/{runtime-Eo_q4pgg.js → runtime-C9ZioNpI.js} +405 -683
  11. package/dist/schema-CiCjXECD.js +350 -0
  12. package/dist/transport-KUB3zfW9.js +65 -0
  13. package/dist/types/src/kit/constants.d.ts +0 -1
  14. package/dist/types/src/kit/kinds/define-report-kind.d.ts +1 -3
  15. package/dist/types/src/primitives/components/form-root-state.d.ts +0 -4
  16. package/dist/types/src/primitives/components/submit-button.d.ts +0 -4
  17. package/dist/types/src/primitives/controller-types.d.ts +9 -23
  18. package/dist/types/src/runtime/errors.d.ts +0 -1
  19. package/dist/types/src/runtime/index.d.ts +1 -2
  20. package/dist/types/src/runtime/reports/controller.d.ts +1 -2
  21. package/dist/types/src/runtime/state/engine.d.ts +1 -5
  22. package/dist/types/src/runtime/submission/create-submitter.d.ts +1 -1
  23. package/dist/types/src/runtime/submission/index.d.ts +1 -0
  24. package/dist/types/src/runtime/submission/reports.d.ts +1 -2
  25. package/dist/types/src/runtime/submission/request.d.ts +2 -18
  26. package/dist/types/src/runtime/submission/transport-response.d.ts +2 -0
  27. package/dist/types/src/runtime/submission/types.d.ts +2 -23
  28. package/dist/types/src/runtime/types/behavior.d.ts +1 -7
  29. package/dist/types/src/runtime/types/form.d.ts +1 -14
  30. package/dist/types/src/runtime/types/report.d.ts +1 -1
  31. package/dist/types/src/runtime/types/transport.d.ts +5 -16
  32. package/dist/types/src/schema/index.d.ts +1 -0
  33. package/dist/types/src/schema/mapped-to.d.ts +13 -1
  34. package/dist/types/src/schema/normalize.d.ts +5 -0
  35. package/dist/types/src/schema/report-context.d.ts +2 -2
  36. package/dist/types/src/schema/types/report.d.ts +5 -11
  37. package/dist/types/src/schema/types/submit.d.ts +28 -11
  38. package/dist/types/src/schema/validation.d.ts +25 -0
  39. package/dist/types/src/transport/errors.d.ts +1 -28
  40. package/dist/types/src/transport/fanout.d.ts +17 -0
  41. package/dist/types/src/transport/index.d.ts +4 -10
  42. package/dist/types/src/transport/request-runner.d.ts +3 -2
  43. package/dist/types/src/transport/types.d.ts +18 -0
  44. package/package.json +1 -1
  45. package/dist/schema-CNKKJZRx.js +0 -173
  46. package/dist/transport-Cloa_erk.js +0 -2154
  47. package/dist/types/src/runtime/submission/field-updates.d.ts +0 -14
  48. package/dist/types/src/runtime/submission/pending-patches.d.ts +0 -2
  49. package/dist/types/src/runtime/submission/report-updates.d.ts +0 -16
  50. package/dist/types/src/runtime/submission/stream-events.d.ts +0 -13
  51. package/dist/types/src/runtime/submission/stream-progress.d.ts +0 -4
  52. package/dist/types/src/transport/capabilities.d.ts +0 -7
  53. package/dist/types/src/transport/clone.d.ts +0 -6
  54. package/dist/types/src/transport/composition/fallback.d.ts +0 -2
  55. package/dist/types/src/transport/composition/fanout-helpers.d.ts +0 -2
  56. package/dist/types/src/transport/composition/fanout-options.d.ts +0 -9
  57. package/dist/types/src/transport/composition/fanout.d.ts +0 -2
  58. package/dist/types/src/transport/composition/hedged.d.ts +0 -2
  59. package/dist/types/src/transport/composition/index.d.ts +0 -8
  60. package/dist/types/src/transport/composition/load-balancing.d.ts +0 -2
  61. package/dist/types/src/transport/composition/pipeline.d.ts +0 -2
  62. package/dist/types/src/transport/composition/quorum-fanout.d.ts +0 -2
  63. package/dist/types/src/transport/composition/racing.d.ts +0 -2
  64. package/dist/types/src/transport/composition/routing.d.ts +0 -3
  65. package/dist/types/src/transport/constants.d.ts +0 -34
  66. package/dist/types/src/transport/internal-core.d.ts +0 -21
  67. package/dist/types/src/transport/internal-errors.d.ts +0 -21
  68. package/dist/types/src/transport/internal-request.d.ts +0 -21
  69. package/dist/types/src/transport/internal-routing.d.ts +0 -25
  70. package/dist/types/src/transport/internal-sse.d.ts +0 -14
  71. package/dist/types/src/transport/internal-stream.d.ts +0 -13
  72. package/dist/types/src/transport/internal.d.ts +0 -6
  73. package/dist/types/src/transport/middleware/auth.d.ts +0 -2
  74. package/dist/types/src/transport/middleware/cache.d.ts +0 -2
  75. package/dist/types/src/transport/middleware/circuit-breaker.d.ts +0 -2
  76. package/dist/types/src/transport/middleware/dedup.d.ts +0 -2
  77. package/dist/types/src/transport/middleware/index.d.ts +0 -12
  78. package/dist/types/src/transport/middleware/logging.d.ts +0 -2
  79. package/dist/types/src/transport/middleware/metrics.d.ts +0 -2
  80. package/dist/types/src/transport/middleware/pipe.d.ts +0 -2
  81. package/dist/types/src/transport/middleware/rate-limit.d.ts +0 -2
  82. package/dist/types/src/transport/middleware/retry.d.ts +0 -2
  83. package/dist/types/src/transport/middleware/timeout.d.ts +0 -2
  84. package/dist/types/src/transport/middleware/tracing.d.ts +0 -2
  85. package/dist/types/src/transport/middleware/transform.d.ts +0 -3
  86. package/dist/types/src/transport/policy-context.d.ts +0 -3
  87. package/dist/types/src/transport/protocols/graphql.d.ts +0 -2
  88. package/dist/types/src/transport/protocols/grpc.d.ts +0 -5
  89. package/dist/types/src/transport/protocols/index.d.ts +0 -5
  90. package/dist/types/src/transport/protocols/json.d.ts +0 -2
  91. package/dist/types/src/transport/protocols/sse.d.ts +0 -2
  92. package/dist/types/src/transport/protocols/websocket.d.ts +0 -2
  93. package/dist/types/src/transport/runtime.d.ts +0 -4
  94. package/dist/types/src/transport/state/cache-store.d.ts +0 -2
  95. package/dist/types/src/transport/state/circuit-breaker.d.ts +0 -2
  96. package/dist/types/src/transport/state/health.d.ts +0 -2
  97. package/dist/types/src/transport/state/index.d.ts +0 -5
  98. package/dist/types/src/transport/state/rate-limiter.d.ts +0 -2
  99. package/dist/types/src/transport/state/session.d.ts +0 -2
  100. package/dist/types/src/transport/types/capabilities.d.ts +0 -35
  101. package/dist/types/src/transport/types/core.d.ts +0 -74
  102. package/dist/types/src/transport/types/events.d.ts +0 -50
  103. package/dist/types/src/transport/types/index.d.ts +0 -7
  104. package/dist/types/src/transport/types/middleware.d.ts +0 -3
  105. package/dist/types/src/transport/types/options-http.d.ts +0 -85
  106. package/dist/types/src/transport/types/options-middleware.d.ts +0 -96
  107. package/dist/types/src/transport/types/options-routing.d.ts +0 -82
  108. package/dist/types/src/transport/types/options.d.ts +0 -3
  109. package/dist/types/src/transport/types/session.d.ts +0 -48
  110. package/dist/types/src/transport/types/state.d.ts +0 -46
@@ -1,14 +1,9 @@
1
1
  import { NormalizedFormSchema } from '../../../schema';
2
- import { InternalFieldState, EngineStore } from '../state';
3
- import { FormHooks, FormValidationResult, InactiveFieldPolicy, SubmissionProgressState, SubmitOptions, SubmitResult, Transport, TransportStreamEvent } from '../types';
2
+ import { EngineStore } from '../state';
3
+ import { FormHooks, FormValidationResult, InactiveFieldPolicy, SubmitOptions, SubmitResult, Transport } from '../types';
4
4
  import { buildSubmissionValueRecords, SubmissionValueRecords } from './request';
5
5
  import { SubmissionReport } from './reports';
6
6
  export type SubmissionField = Parameters<typeof buildSubmissionValueRecords>[0][number];
7
- export type LiveSubmissionField = SubmissionField & {
8
- coerceValue(value: unknown): unknown;
9
- commitState(state: InternalFieldState): void;
10
- };
11
- export type LiveSubmissionReport = SubmissionReport;
12
7
  export type SyncDerivedFieldStateOptions = {
13
8
  values?: Record<string, unknown>;
14
9
  preserveValidationErrors?: boolean;
@@ -34,7 +29,6 @@ export type CreateFormSubmitterOptions = {
34
29
  shouldResetInactiveFields: () => boolean;
35
30
  resolveInactiveFieldPolicy: (field: SubmissionField) => InactiveFieldPolicy;
36
31
  inactiveFieldPolicy?: InactiveFieldPolicy;
37
- onRemoteFieldUpdate?: (fieldId: string) => Promise<void>;
38
32
  beforeSubmitRecords?: (records: SubmissionValueRecords) => Promise<void>;
39
33
  };
40
34
  export type FormSubmitter = {
@@ -42,18 +36,3 @@ export type FormSubmitter = {
42
36
  abort(reason?: string): void;
43
37
  reset(): void;
44
38
  };
45
- export type SubmissionMaps = {
46
- fieldMap: Map<string, LiveSubmissionField>;
47
- reportMap: Map<string, LiveSubmissionReport>;
48
- };
49
- export type SubmissionRuntime = {
50
- store: EngineStore;
51
- maps: SubmissionMaps;
52
- onRemoteFieldUpdate?: (fieldId: string) => Promise<void>;
53
- };
54
- export type StreamApplyContext = {
55
- records: SubmissionValueRecords;
56
- backend: string | undefined;
57
- };
58
- export type StreamProgressHandler = (progress: SubmissionProgressState, submissionRequestId: number, lifecycleVersion: number) => void;
59
- export type StreamEventApplier = (event: TransportStreamEvent, context: StreamApplyContext) => Promise<void>;
@@ -1,21 +1,15 @@
1
- import { Registry } from '../../../schema';
2
- import { SubmissionInputRecord } from '../../../transport';
1
+ import { Registry, SubmissionInputRecord } from '../../../schema';
3
2
  import { FieldHandle } from './field';
4
3
  import { FormStatus } from './form';
5
4
  type MaybePromise<T> = T | PromiseLike<T>;
6
5
  export interface RuntimeBehaviorValueChangeEvent {
7
6
  fieldId: string;
8
- source: "local" | "remote";
9
7
  values: Record<string, unknown>;
10
8
  }
11
9
  export interface RuntimeBehaviorSubmissionRecords {
12
10
  inputs: SubmissionInputRecord[];
13
11
  displayValues: Record<string, unknown>;
14
12
  modelValues: Record<string, unknown>;
15
- values: Record<string, unknown>;
16
- fieldValues: Record<string, unknown>;
17
- serializedValues: Record<string, unknown>;
18
- serializedFieldValues: Record<string, unknown>;
19
13
  }
20
14
  export interface RuntimeBehaviorContext {
21
15
  readonly registry: Registry;
@@ -1,6 +1,6 @@
1
1
  import { FieldConfig, FieldStateSnapshot, FormSchema, InactiveFieldPolicy, NormalizedFieldConfig, NormalizedReportConfig, Registry, ReportConfig, ReportStateSnapshot, SelectorSubscriptionOptions } from '../../../schema';
2
2
  import { RuntimeBehavior } from './behavior';
3
- import { AfterSubmitContext, BeforeSubmitContext, SubmitErrorContext, SubmitOptions, SubmitResult, Transport, TransportStreamEvent } from './transport';
3
+ import { AfterSubmitContext, BeforeSubmitContext, SubmitErrorContext, SubmitOptions, SubmitResult, Transport } from './transport';
4
4
  import { FieldController } from './field';
5
5
  import { ReportController } from './report';
6
6
  type MaybePromise<T> = T | PromiseLike<T>;
@@ -10,18 +10,6 @@ export interface FormValidationResult {
10
10
  fields: Record<string, string[]>;
11
11
  formErrors: string[];
12
12
  }
13
- export interface SubmissionProgressState {
14
- loaded?: number;
15
- total?: number;
16
- message?: string;
17
- meta: Record<string, unknown>;
18
- chunkCount: number;
19
- sessionState?: "opening" | "open" | "closing" | "closed";
20
- bufferedMessages?: number;
21
- sessionMessageCount?: number;
22
- lastSessionMessageType?: string;
23
- lastEventType?: TransportStreamEvent["type"];
24
- }
25
13
  export interface FormState {
26
14
  status: FormStatus;
27
15
  submitCount: number;
@@ -30,7 +18,6 @@ export interface FormState {
30
18
  touched: boolean;
31
19
  values: Record<string, unknown>;
32
20
  reportStates: Record<string, ReportStateSnapshot>;
33
- submissionProgress: SubmissionProgressState | null;
34
21
  errors: {
35
22
  form: string[];
36
23
  fields: Record<string, string[]>;
@@ -1,5 +1,5 @@
1
1
  import { NormalizedReportConfig as SchemaNormalizedReportConfig, ReportDefinition as SchemaReportDefinition, ReportStateSnapshot } from '../../../schema';
2
- export type { BaseReportConfig, PartialReportUpdatePolicy, ReportConfig, ReportFetchContext, ReportFetchFactory, ReportFetchRequest, ReportFetchStatus, ReportFetchTransport, ReportPayloadContext, ReportPayloadValidationPolicy, ReportResolveContext, ReportStateSnapshot, ReportStatus, } from '../../../schema';
2
+ export type { BaseReportConfig, ReportConfig, ReportFetchContext, ReportFetchFactory, ReportFetchRequest, ReportFetchStatus, ReportFetchTransport, ReportPayloadContext, ReportPayloadValidationPolicy, ReportResolveContext, ReportStateSnapshot, ReportStatus, } from '../../../schema';
3
3
  export interface ReportHandle {
4
4
  readonly id: string;
5
5
  readonly kind: string;
@@ -1,12 +1,13 @@
1
- import { SubmitRequest as BaseSubmitRequest, Transport as BaseTransport, SubmissionInputRecord, TransportStreamEvent as BaseTransportStreamEvent } from '../../../transport';
2
- import { SubmitResult as SchemaSubmitResult } from '../../../schema';
1
+ import { SubmitRequest as BaseSubmitRequest, Transport as BaseTransport } from '../../../transport';
2
+ import { SubmissionInputRecord, SubmitResult as SchemaSubmitResult } from '../../../schema';
3
3
  import { NormalizedFieldConfig } from './field';
4
4
  import { NormalizedReportConfig, ReportStateSnapshot } from './report';
5
- export type { CapabilityRequirement, CircuitBreakerSharedState, CircuitBreakerStateSnapshot, RateLimitLeaseRequest, SharedRateLimiter, SharedRateLimiterLease, SubmissionInputRecord, SubmitRequestMetadata, SubmitRequestTransportContext, TransportAuthKind, TransportBackpressureMode, TransportCacheEntry, TransportCacheStore, TransportCapabilities, TransportCollection, TransportConsistency, TransportDeliveryMode, TransportHealthSnapshot, TransportHealthState, TransportPolicyContext, TransportResponse, TransportSession, TransportSessionCloseEvent, TransportSessionErrorEvent, TransportSessionEvent, TransportSessionMessage, TransportSessionMessageEvent, TransportSessionMetaEvent, TransportSessionProgressEvent, TransportSessionResultEvent, TransportStreamChunkEvent, TransportStreamErrorEvent, TransportStreamMetaEvent, TransportStreamProgressEvent, TransportStreamReportPatchEvent, TransportStreamReportReplaceEvent, } from '../../../transport';
5
+ export type { SubmissionInputRecord } from '../../../schema';
6
+ export type { ReportContext, ReportResult, ReportResultContext } from '../../../schema';
7
+ export type { TransportResponse } from '../../../transport';
6
8
  export type SubmitRequest = BaseSubmitRequest<NormalizedFieldConfig, NormalizedReportConfig>;
7
9
  export type SubmitResult = SchemaSubmitResult<ReportStateSnapshot>;
8
10
  export type Transport = BaseTransport<NormalizedFieldConfig, NormalizedReportConfig>;
9
- export type TransportStreamEvent = BaseTransportStreamEvent;
10
11
  export interface SubmitOptions {
11
12
  signal?: AbortSignal;
12
13
  backend?: string;
@@ -16,10 +17,6 @@ export interface BeforeSubmitContext {
16
17
  inputs: SubmissionInputRecord[];
17
18
  displayValues: Record<string, unknown>;
18
19
  modelValues: Record<string, unknown>;
19
- values: Record<string, unknown>;
20
- fieldValues: Record<string, unknown>;
21
- serializedValues: Record<string, unknown>;
22
- serializedFieldValues: Record<string, unknown>;
23
20
  submitCount: number;
24
21
  signal: AbortSignal;
25
22
  }
@@ -28,10 +25,6 @@ export interface AfterSubmitContext {
28
25
  inputs: SubmissionInputRecord[];
29
26
  displayValues: Record<string, unknown>;
30
27
  modelValues: Record<string, unknown>;
31
- values: Record<string, unknown>;
32
- fieldValues: Record<string, unknown>;
33
- serializedValues: Record<string, unknown>;
34
- serializedFieldValues: Record<string, unknown>;
35
28
  submitCount: number;
36
29
  result: SubmitResult;
37
30
  }
@@ -40,10 +33,6 @@ export interface SubmitErrorContext {
40
33
  inputs: SubmissionInputRecord[];
41
34
  displayValues: Record<string, unknown>;
42
35
  modelValues: Record<string, unknown>;
43
- values: Record<string, unknown>;
44
- fieldValues: Record<string, unknown>;
45
- serializedValues: Record<string, unknown>;
46
- serializedFieldValues: Record<string, unknown>;
47
36
  submitCount: number;
48
37
  error: unknown;
49
38
  }
@@ -3,6 +3,7 @@ export * from './mapped-to';
3
3
  export * from './normalize';
4
4
  export * from './onehot-display';
5
5
  export * from './report-context';
6
+ export * from './validation';
6
7
  export { createReportFetchRequest } from './report-fetch-request';
7
8
  export * from './registry';
8
9
  export type * from './types/field';
@@ -1,12 +1,24 @@
1
+ import { ReportResult } from './types/submit';
1
2
  export type MappedToTarget = string | number;
2
3
  export type MappedTo = MappedToTarget | Record<string, MappedToTarget | null | undefined>;
4
+ export type MappedToRoute = {
5
+ backend: string;
6
+ mappedTo: MappedToTarget;
7
+ };
3
8
  export declare const resolveMappedTo: (mappedTo: MappedTo | undefined, backend: string | undefined) => MappedToTarget | undefined;
4
9
  export declare const mappedToKey: (target: MappedToTarget) => string;
5
10
  export declare const resolveMappedTargets: (mappedTo: MappedTo | undefined, backend: string | undefined) => MappedToTarget[];
11
+ export declare const resolveMappedRoutes: (mappedTo: MappedTo | undefined, backend: string | undefined) => MappedToRoute[];
12
+ export declare const resolveMappedReportResult: (report: {
13
+ mappedTo?: MappedTo;
14
+ }, result: {
15
+ backend?: string;
16
+ reports: readonly ReportResult[];
17
+ }) => ReportResult | undefined;
6
18
  export declare const resolveMappedReportPayload: (report: {
7
19
  id?: string;
8
20
  mappedTo?: MappedTo;
9
21
  }, result: {
10
22
  backend?: string;
11
- reports: readonly unknown[];
23
+ reports: readonly ReportResult[];
12
24
  }) => unknown;
@@ -1,2 +1,7 @@
1
1
  import { FormSchema, NormalizedFormSchema, Registry } from './index';
2
+ export declare class SchemaNormalizationError extends Error {
3
+ readonly path: readonly (string | number)[];
4
+ readonly code: "invalid-config" | "unknown-kind";
5
+ constructor(message: string, path: readonly (string | number)[], code?: "invalid-config" | "unknown-kind");
6
+ }
2
7
  export declare const normalizeSchema: (schema: FormSchema, registry: Registry) => NormalizedFormSchema;
@@ -2,7 +2,7 @@ import { MappedTo } from './mapped-to';
2
2
  import { NormalizedReportConfig } from './types/report';
3
3
  import { ReportContext, SubmitResult } from './types/submit';
4
4
  type ReportContextSource = Pick<SubmitResult, "backend"> & {
5
- reportContexts?: Record<string, ReportContext>;
5
+ reportContexts: Record<string, ReportContext>;
6
6
  };
7
7
  type ReportContextLookup = string | number | {
8
8
  id?: string;
@@ -12,6 +12,6 @@ type ReportContextLookup = string | number | {
12
12
  mappedTo?: MappedTo;
13
13
  };
14
14
  };
15
- export declare const createReportContexts: (reports: readonly NormalizedReportConfig[], result: Pick<SubmitResult, "backend" | "displayValues" | "modelValues" | "serializedValues" | "reports" | "meta" | "raw">) => Record<string, ReportContext>;
15
+ export declare const createReportContexts: (reports: readonly NormalizedReportConfig[], result: Pick<SubmitResult, "backend" | "displayValues" | "modelValues" | "reports" | "meta" | "raw">) => Record<string, ReportContext>;
16
16
  export declare const getReportContext: (source: ReportContextSource, lookup: ReportContextLookup) => ReportContext | undefined;
17
17
  export {};
@@ -2,10 +2,9 @@ import { ZodType } from 'zod';
2
2
  import { MaybePromise } from './field';
3
3
  import { MappedTo } from '../mapped-to';
4
4
  import { ReportContext, SubmitResult, SubmissionInputRecord } from './submit';
5
- export type ReportStatus = "idle" | "loading" | "ready" | "error";
5
+ export type ReportStatus = "idle" | "loading" | "ready" | "skipped" | "error";
6
6
  export type ReportFetchStatus = ReportStatus;
7
7
  export type ReportPayloadValidationPolicy = "report-error" | "fail-submit";
8
- export type PartialReportUpdatePolicy = "trust" | "validate" | "defer";
9
8
  export interface BaseReportConfig {
10
9
  id?: string;
11
10
  kind: string;
@@ -36,16 +35,12 @@ export interface ReportResolveContext<TConfig extends ReportConfig = ReportConfi
36
35
  export interface ReportFetchRequest {
37
36
  reportId: string;
38
37
  backend?: string;
39
- inputs?: SubmissionInputRecord[];
40
- displayValues?: Record<string, unknown>;
41
- modelValues?: Record<string, unknown>;
42
- values: Record<string, unknown>;
43
- fieldValues: Record<string, unknown>;
44
- serializedValues: Record<string, unknown>;
45
- serializedFieldValues: Record<string, unknown>;
38
+ inputs: SubmissionInputRecord[];
39
+ displayValues: Record<string, unknown>;
40
+ modelValues: Record<string, unknown>;
46
41
  reports: readonly unknown[];
47
42
  reportContext?: ReportContext;
48
- reportContexts?: Record<string, ReportContext>;
43
+ reportContexts: Record<string, ReportContext>;
49
44
  meta: Record<string, unknown>;
50
45
  raw: unknown;
51
46
  signal?: AbortSignal;
@@ -63,7 +58,6 @@ export interface ReportDefinition<TConfig extends ReportConfig = ReportConfig> {
63
58
  schema: ZodType<TConfig>;
64
59
  payloadSchema?: ZodType<unknown>;
65
60
  payloadValidationPolicy?: ReportPayloadValidationPolicy;
66
- partialUpdatePolicy?: PartialReportUpdatePolicy;
67
61
  clonePayload?: (payload: unknown, config: TConfig) => unknown;
68
62
  fetch?: ReportFetchFactory<TConfig>;
69
63
  resolvePayload?: (config: TConfig, context: ReportPayloadContext<TConfig>) => MaybePromise<unknown>;
@@ -1,4 +1,4 @@
1
- import { MappedTo } from '../mapped-to';
1
+ import { MappedTo, MappedToTarget } from '../mapped-to';
2
2
  export interface SubmissionInputRecord {
3
3
  fieldId: string;
4
4
  displayKey?: string;
@@ -20,22 +20,39 @@ export interface ReportContext {
20
20
  backend?: string;
21
21
  displayValues: Record<string, unknown>;
22
22
  modelValues: Record<string, unknown>;
23
- reports: readonly unknown[];
23
+ reports: readonly ReportResult[];
24
24
  meta: Record<string, unknown>;
25
25
  raw: unknown;
26
26
  }
27
- export interface SubmitResult<TReportState = unknown> {
28
- backend?: string;
29
- inputs?: SubmissionInputRecord[];
27
+ export interface ReportResultContext {
30
28
  displayValues?: Record<string, unknown>;
31
29
  modelValues?: Record<string, unknown>;
32
- values: Record<string, unknown>;
33
- fieldValues: Record<string, unknown>;
34
- serializedValues: Record<string, unknown>;
35
- serializedFieldValues: Record<string, unknown>;
36
- reports: readonly unknown[];
37
- reportContexts?: Record<string, ReportContext>;
30
+ meta?: Record<string, unknown>;
31
+ raw?: unknown;
32
+ }
33
+ interface BaseReportResult {
34
+ backend: string;
35
+ mappedTo: MappedToTarget;
36
+ context?: ReportResultContext;
37
+ }
38
+ export type ReportResult = (BaseReportResult & {
39
+ status: "pending";
40
+ }) | (BaseReportResult & {
41
+ status: "ready";
42
+ payload: unknown;
43
+ }) | (BaseReportResult & {
44
+ status: "skipped";
45
+ reason?: string;
46
+ });
47
+ export interface SubmitResult<TReportState = unknown> {
48
+ backend?: string;
49
+ inputs: SubmissionInputRecord[];
50
+ displayValues: Record<string, unknown>;
51
+ modelValues: Record<string, unknown>;
52
+ reports: readonly ReportResult[];
53
+ reportContexts: Record<string, ReportContext>;
38
54
  reportStates: Record<string, TReportState>;
39
55
  meta: Record<string, unknown>;
40
56
  raw: unknown;
41
57
  }
58
+ export {};
@@ -0,0 +1,25 @@
1
+ import { NormalizedFormSchema, Registry } from './index';
2
+ export type SchemaIssuePath = readonly (string | number)[];
3
+ export type SchemaValidationIssue = {
4
+ path: SchemaIssuePath;
5
+ message: string;
6
+ code: "invalid-schema" | "unknown-kind" | "invalid-config";
7
+ };
8
+ export type UnknownSchemaKind = {
9
+ section: "fields" | "reports";
10
+ index: number;
11
+ kind: string;
12
+ path: SchemaIssuePath;
13
+ };
14
+ export type SchemaValidationResult = {
15
+ success: true;
16
+ data: NormalizedFormSchema;
17
+ issues: readonly [];
18
+ } | {
19
+ success: false;
20
+ issues: readonly SchemaValidationIssue[];
21
+ };
22
+ export type SchemaJsonSchema = Record<string, unknown>;
23
+ export declare const findUnknownKinds: (schema: unknown, registry: Registry) => UnknownSchemaKind[];
24
+ export declare const validateSchema: (schema: unknown, registry: Registry) => SchemaValidationResult;
25
+ export declare const toSchemaJsonSchema: (registry: Registry) => SchemaJsonSchema;
@@ -1,35 +1,8 @@
1
1
  export declare const transportErrorCodes: {
2
- readonly TIMEOUT: "TIMEOUT";
3
- readonly AUTH_FAILED: "AUTH_FAILED";
4
- readonly RATE_LIMITED: "RATE_LIMITED";
5
- readonly OPEN_CIRCUIT: "OPEN_CIRCUIT";
6
- readonly PARSE_FAILED: "PARSE_FAILED";
7
- readonly UPSTREAM_5XX: "UPSTREAM_5XX";
8
2
  readonly ABORTED: "ABORTED";
9
- readonly CAPABILITY_MISMATCH: "CAPABILITY_MISMATCH";
10
- readonly PAYLOAD_TOO_LARGE: "PAYLOAD_TOO_LARGE";
11
- readonly SESSION_RESULT_MISSING: "SESSION_RESULT_MISSING";
12
- readonly GRAPHQL_ERROR: "GRAPHQL_ERROR";
13
- readonly WEBSOCKET_BUFFER_OVERFLOW: "WEBSOCKET_BUFFER_OVERFLOW";
14
- readonly POLICY_STORE_CONFLICT: "POLICY_STORE_CONFLICT";
15
- readonly QUORUM_NOT_REACHED: "QUORUM_NOT_REACHED";
16
3
  };
17
4
  export type TransportErrorCode = (typeof transportErrorCodes)[keyof typeof transportErrorCodes] | (string & {});
18
5
  export declare class TransportError extends Error {
19
- readonly cause: unknown;
20
- readonly source?: string;
21
- readonly status?: number;
22
6
  readonly code?: TransportErrorCode;
23
- readonly retryable?: boolean;
24
- readonly details?: unknown;
25
- readonly response?: unknown;
26
- constructor(message: string, options?: {
27
- cause?: unknown;
28
- source?: string;
29
- status?: number;
30
- code?: TransportErrorCode;
31
- retryable?: boolean;
32
- details?: unknown;
33
- response?: unknown;
34
- });
7
+ constructor(message: string, code?: TransportErrorCode);
35
8
  }
@@ -0,0 +1,17 @@
1
+ import { SubmitRequest, Transport } from './types';
2
+ export type FanoutOutcome<TTarget, TValue> = {
3
+ target: TTarget;
4
+ status: "fulfilled";
5
+ value: TValue;
6
+ } | {
7
+ target: TTarget;
8
+ status: "rejected";
9
+ reason: unknown;
10
+ };
11
+ export type CreateFanoutTransportOptions<TTarget, TValue> = {
12
+ targets: readonly TTarget[];
13
+ submit: (target: TTarget, request: SubmitRequest) => Promise<TValue>;
14
+ merge: (outcomes: readonly FanoutOutcome<TTarget, TValue>[], request: SubmitRequest) => unknown;
15
+ failurePolicy?: "collect" | "fail-fast";
16
+ };
17
+ export declare const createFanoutTransport: <TTarget, TValue>(options: CreateFanoutTransportOptions<TTarget, TValue>) => Transport;
@@ -1,11 +1,5 @@
1
- export * from './types';
2
- export { TransportError, transportErrorCodes, type TransportErrorCode } from './errors';
3
- export { transportDefaults, transportErrorMessages } from './constants';
4
- export { assertPayloadWithinLimits, assertTransportCapabilities, cloneCapabilities, inferTransportCapabilities, mergeTransportCapabilities, normalizeTransportCapabilities, } from './capabilities';
5
- export { getTransportPolicyContext, withTransportPolicyContext } from './policy-context';
1
+ export { TransportError, transportErrorCodes } from './errors';
6
2
  export { createTransportRequestRunner, extractErrorMessage } from './request-runner';
7
- export type { TransportRequestOutcome, TransportRequestRunner } from './request-runner';
8
- export * from './protocols';
9
- export * from './middleware';
10
- export * from './composition';
11
- export * from './state';
3
+ export { createFanoutTransport } from './fanout';
4
+ export type { CreateFanoutTransportOptions, FanoutOutcome } from './fanout';
5
+ export type { SubmitRequest, Transport, TransportResponse } from './types';
@@ -1,4 +1,4 @@
1
- export type TransportRequestOutcome<TResult> = {
1
+ type TransportRequestOutcome<TResult> = {
2
2
  status: "completed";
3
3
  value: TResult;
4
4
  } | {
@@ -8,9 +8,10 @@ export type TransportRequestOutcome<TResult> = {
8
8
  error: unknown;
9
9
  message: string;
10
10
  };
11
- export type TransportRequestRunner = {
11
+ type TransportRequestRunner = {
12
12
  run<TResult>(submit: (signal: AbortSignal | undefined) => Promise<TResult>, signals?: readonly (AbortSignal | undefined)[]): Promise<TransportRequestOutcome<TResult>>;
13
13
  abort(reason?: unknown): void;
14
14
  };
15
15
  export declare const extractErrorMessage: (error: unknown) => string;
16
16
  export declare const createTransportRequestRunner: () => TransportRequestRunner;
17
+ export {};
@@ -0,0 +1,18 @@
1
+ import { ReportResult, SubmissionInputRecord } from '../../schema';
2
+ export interface SubmitRequest<TField extends Record<string, unknown> = Record<string, unknown>, TReport extends Record<string, unknown> = Record<string, unknown>> {
3
+ backend?: string;
4
+ inputs: SubmissionInputRecord[];
5
+ displayValues: Record<string, unknown>;
6
+ modelValues: Record<string, unknown>;
7
+ fields: readonly TField[];
8
+ reports: readonly TReport[];
9
+ signal?: AbortSignal;
10
+ }
11
+ export interface TransportResponse {
12
+ reports?: readonly ReportResult[];
13
+ meta?: Record<string, unknown>;
14
+ raw?: unknown;
15
+ }
16
+ export interface Transport<TField extends Record<string, unknown> = Record<string, unknown>, TReport extends Record<string, unknown> = Record<string, unknown>> {
17
+ submit: (request: SubmitRequest<TField, TReport>) => Promise<unknown>;
18
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mlform",
3
- "version": "0.1.19",
3
+ "version": "0.1.22",
4
4
  "private": false,
5
5
  "description": "Composable form generation utilities for machine learning backend integration",
6
6
  "keywords": [
@@ -1,173 +0,0 @@
1
- //#region src/schema/ids.ts
2
- var e = (e) => e.trim().toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "") || "item", t = (e, t) => {
3
- if (typeof e == "string" || typeof e == "number") return e;
4
- if (e) return (t ? e[t] : void 0) ?? e.default ?? void 0;
5
- }, n = (e) => String(e), r = (e, r) => {
6
- let i = t(e, r);
7
- if (r !== void 0 || typeof e != "object" || !e) return i === void 0 ? [] : [i];
8
- let a = /* @__PURE__ */ new Set();
9
- return Object.values(e).filter((e) => {
10
- if (typeof e != "string" && typeof e != "number") return !1;
11
- let t = n(e);
12
- return a.has(t) ? !1 : (a.add(t), !0);
13
- });
14
- }, i = (e, t) => {
15
- let r = n(e), i = t.reports.filter((e) => typeof e == "object" && !!e && !Array.isArray(e) && n(e.mappedTo ?? "") === r);
16
- if (i.length > 1) throw Error(`Duplicate report payload for mappedTo "${r}".`);
17
- let a = i[0];
18
- if (!a) return;
19
- if ("payload" in a) return a.payload;
20
- let { id: o, kind: s, mappedTo: c, ...l } = a;
21
- return l;
22
- }, a = (e, t) => {
23
- let n = r(e.mappedTo, t.backend);
24
- if (n.length !== 0) for (let e of n) {
25
- let n = i(e, t);
26
- if (n !== void 0) return n;
27
- }
28
- }, o = class extends Error {
29
- constructor(e) {
30
- super(e), this.name = "RegistryError";
31
- }
32
- }, s = class {
33
- fieldDefinitions = /* @__PURE__ */ new Map();
34
- reportDefinitions = /* @__PURE__ */ new Map();
35
- registerField(e) {
36
- if (this.fieldDefinitions.has(e.kind)) throw new o(`Field kind "${e.kind}" is already registered.`);
37
- return this.fieldDefinitions.set(e.kind, e), this;
38
- }
39
- unregisterField(e) {
40
- return this.fieldDefinitions.delete(e), this;
41
- }
42
- registerReport(e) {
43
- if (this.reportDefinitions.has(e.kind)) throw new o(`Report kind "${e.kind}" is already registered.`);
44
- return this.reportDefinitions.set(e.kind, e), this;
45
- }
46
- unregisterReport(e) {
47
- return this.reportDefinitions.delete(e), this;
48
- }
49
- getField(e) {
50
- return this.fieldDefinitions.get(e);
51
- }
52
- getReport(e) {
53
- return this.reportDefinitions.get(e);
54
- }
55
- listFields() {
56
- return Array.from(this.fieldDefinitions.values());
57
- }
58
- listReports() {
59
- return Array.from(this.reportDefinitions.values());
60
- }
61
- }, c = () => new s(), l = (e) => e, u = (e) => e, d = (e, t, n, r) => {
62
- if (typeof n != "object" || !n) throw Error(`Series field "${e}" requires "${t}" configuration.`);
63
- let i = "kind" in n && typeof n.kind == "string" ? n.kind : "";
64
- if (i.length === 0) throw Error(`Series field "${e}" requires "${t}.kind".`);
65
- if (i === "series") throw Error(`Series field "${e}" cannot nest series in "${t}".`);
66
- if (!r.getField(i)) throw new o(`Series field "${e}" uses unknown sub-field kind "${i}" in "${t}".`);
67
- }, f = (e, t) => {
68
- if (e.kind === "series" && (d(e.label, "field1", e.field1, t), d(e.label, "field2", e.field2, t), typeof e.minPoints == "number" && typeof e.maxPoints == "number" && e.minPoints > e.maxPoints)) throw Error(`Series field "${e.label}" requires minPoints to be less than or equal to maxPoints.`);
69
- }, p = (t, n, r, i) => {
70
- let a = e((t ?? n) || i);
71
- if (t) {
72
- if (r.has(a)) throw Error(`Duplicate explicit id "${a}" in schema.`);
73
- return r.add(a), a;
74
- }
75
- let o = a, s = 2;
76
- for (; r.has(o);) o = `${a}-${s}`, s += 1;
77
- return r.add(o), o;
78
- }, m = (e, t, n, r) => {
79
- let i = n.getField(e.kind);
80
- if (!i) throw new o(`Unknown field kind "${e.kind}".`);
81
- let a = i.schema.parse(e);
82
- return f(a, n), {
83
- ...a,
84
- id: p(a.id, a.label, r, `field-${t + 1}`)
85
- };
86
- }, h = (e, t, n, r) => {
87
- let i = n.getReport(e.kind);
88
- if (!i) throw new o(`Unknown report kind "${e.kind}".`);
89
- let a = i.schema.parse(e), s = p(a.id, a.label ?? a.kind, r, `report-${t + 1}`);
90
- return {
91
- ...a,
92
- id: s
93
- };
94
- }, g = (e) => {
95
- let r = e.mappedTo;
96
- return typeof r == "string" || typeof r == "number" ? [["default", n(r)]] : r ? Object.keys(r).map((e) => {
97
- let i = t(r, e === "default" ? void 0 : e);
98
- return i === void 0 ? null : [e, n(i)];
99
- }).filter((e) => e !== null) : [];
100
- }, _ = (e) => {
101
- let t = /* @__PURE__ */ new Map();
102
- for (let n of e) for (let [e, r] of g(n)) {
103
- let i = `${e}:${r}`, a = t.get(i);
104
- if (a) throw Error(`Duplicate report mappedTo "${r}" for backend "${e}" in "${a}" and "${n.id}".`);
105
- t.set(i, n.id);
106
- }
107
- }, v = (e, t) => {
108
- let n = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set(), i = (e.reports ?? []).map((e, n) => h(e, n, t, r));
109
- return _(i), {
110
- fields: e.fields.map((e, r) => m(e, r, t, n)),
111
- reports: i
112
- };
113
- }, y = (e) => e === 1 || e === "1" || e === !0, b = (e, r, i = {}) => {
114
- if (e.kind !== "onehot-category" || !Array.isArray(e.options)) return;
115
- let a = /* @__PURE__ */ new Set(), o;
116
- for (let s of e.options) {
117
- let c = t(s.mappedTo, i.backend);
118
- if (c === void 0) throw Error(`onehot-category "${e.id ?? e.kind}": option "${s.value}" has no mappedTo.`);
119
- let l = n(c);
120
- if (a.has(l)) throw Error(`onehot-category "${e.id ?? e.kind}": duplicate mappedTo "${l}".`);
121
- if (a.add(l), y(r[l])) {
122
- if (o !== void 0) throw Error(`onehot-category "${e.id ?? e.kind}": multiple selected mapped values.`);
123
- o = s.value;
124
- }
125
- }
126
- return o;
127
- }, x = (e) => {
128
- if (typeof e == "string") return e;
129
- if (typeof e != "number") return e.id ?? e.config?.id;
130
- }, S = (e, r) => {
131
- if (typeof e == "string" || typeof e == "number") return String(e);
132
- let i = t(e.mappedTo ?? e.config?.mappedTo, r);
133
- return i === void 0 ? void 0 : n(i);
134
- }, C = (e, r) => Object.fromEntries(e.map((e) => {
135
- let i = t(e.mappedTo, r.backend);
136
- return [e.id, {
137
- reportId: e.id,
138
- kind: e.kind,
139
- label: e.label,
140
- mappedTo: e.mappedTo,
141
- target: i,
142
- targetKey: i === void 0 ? void 0 : n(i),
143
- backend: r.backend,
144
- displayValues: r.displayValues ?? {},
145
- modelValues: r.modelValues ?? r.serializedValues,
146
- reports: r.reports,
147
- meta: r.meta,
148
- raw: r.raw
149
- }];
150
- })), w = (e, t) => {
151
- let n = e.reportContexts ?? {}, r = x(t);
152
- if (r && n[r]) return n[r];
153
- let i = S(t, e.backend);
154
- if (i !== void 0) return Object.values(n).find((e) => e.targetKey === i);
155
- }, T = (e, t = {}) => ({
156
- reportId: t.reportId ?? "",
157
- backend: e.backend,
158
- inputs: e.inputs ?? [],
159
- displayValues: e.displayValues ?? {},
160
- modelValues: e.modelValues ?? e.serializedValues,
161
- values: e.values,
162
- fieldValues: e.fieldValues,
163
- serializedValues: e.serializedValues,
164
- serializedFieldValues: e.serializedFieldValues,
165
- reports: e.reports,
166
- reportContext: t.reportId === void 0 ? void 0 : w(e, t.reportId),
167
- reportContexts: e.reportContexts ?? {},
168
- meta: e.meta,
169
- raw: e.raw,
170
- signal: t.signal
171
- });
172
- //#endregion
173
- export { v as a, l as c, a as d, r as f, b as i, u as l, e as m, C as n, o, t as p, w as r, c as s, T as t, n as u };