@xemahq/ui-kernel 0.11.1 → 0.11.2
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/package.json +1 -2
- package/src/index.ts +0 -17
- package/src/lib/biome-host/agent-validation.ts +0 -239
- package/src/lib/biome-host/biome-builders.ts +0 -112
- package/src/lib/biome-host/biome-mode.ts +0 -6
- package/src/lib/biome-host/biome-navigation.ts +0 -37
- package/src/lib/biome-host/biome-registry.ts +0 -299
- package/src/lib/biome-host/biome-scope-hooks.ts +0 -41
- package/src/lib/biome-host/biome-scope.tsx +0 -52
- package/src/lib/biome-host/biome-scoped-query.ts +0 -134
- package/src/lib/biome-host/create-biome-orval-config.ts +0 -82
- package/src/lib/biome-host/define-web-biome.spec.ts +0 -221
- package/src/lib/biome-host/define-web-biome.ts +0 -222
- package/src/lib/biome-host/errors.ts +0 -220
- package/src/lib/biome-host/frontend-biome.ts +0 -256
- package/src/lib/biome-host/host-bridge.ts +0 -281
- package/src/lib/biome-host/host-sources.ts +0 -54
- package/src/lib/biome-host/i18n-hooks.ts +0 -51
- package/src/lib/biome-host/i18n-port.test.ts +0 -50
- package/src/lib/biome-host/i18n-port.ts +0 -96
- package/src/lib/biome-host/index.ts +0 -35
- package/src/lib/biome-host/realtime-hooks.ts +0 -75
- package/src/lib/biome-host/realtime-port.ts +0 -115
- package/src/lib/biome-host/session-contributions.ts +0 -296
- package/src/lib/biome-host/use-mutation-with-error-toast.ts +0 -90
- package/src/lib/biome-host/use-page-state.ts +0 -248
- package/src/lib/capabilities/capability-context.ts +0 -25
- package/src/lib/capabilities/capability-provider.tsx +0 -73
- package/src/lib/capabilities/index.ts +0 -17
- package/src/lib/capabilities/types.ts +0 -69
- package/src/lib/capabilities/use-capability.ts +0 -79
- package/src/lib/contribution-registry/contribution-registry.spec.ts +0 -141
- package/src/lib/contribution-registry/contribution-registry.ts +0 -204
- package/src/lib/contribution-registry/index.ts +0 -9
- package/src/lib/contribution-registry/renderable-registry.ts +0 -142
- package/src/lib/system-bus/capability-invoke.ts +0 -92
- package/src/lib/system-bus/deeplink.ts +0 -210
- package/src/lib/system-bus/enums.ts +0 -86
- package/src/lib/system-bus/host-ports.ts +0 -93
- package/src/lib/system-bus/index.ts +0 -16
- package/src/lib/system-bus/intent-registry.ts +0 -109
- package/src/lib/system-bus/intents.ts +0 -113
- package/src/lib/system-bus/palette.ts +0 -78
- package/src/lib/system-bus/system-bus-builder.ts +0 -159
- package/src/lib/system-bus/system-bus.ts +0 -37
- package/src/lib/system-bus/windows.ts +0 -51
- package/src/offline/id.ts +0 -16
- package/src/offline/index.ts +0 -54
- package/src/offline/mutation.ts +0 -75
- package/src/offline/offline-status-badge.tsx +0 -51
- package/src/offline/online-controller.ts +0 -105
- package/src/offline/outbox.test.ts +0 -172
- package/src/offline/outbox.ts +0 -348
- package/src/offline/react-hooks.ts +0 -40
- package/src/offline/react.tsx +0 -32
- package/src/offline/storage.ts +0 -112
- package/src/offline/types.ts +0 -77
- package/src/org-db/components/DbResultTable.tsx +0 -176
- package/src/org-db/index.ts +0 -1
- package/src/pdf/index.ts +0 -11
- package/src/registry/index.ts +0 -9
- package/src/registry/lib/agent-validation-host.ts +0 -36
- package/src/registry/lib/biome-slot.tsx +0 -50
- package/src/registry/lib/biomes-enabled-context.ts +0 -20
- package/src/registry/lib/extension-points.ts +0 -134
- package/src/registry/lib/primitives/SessionEventCard.tsx +0 -164
- package/src/registry/lib/primitives/SessionEventTimeline.tsx +0 -95
- package/src/registry/lib/primitives/SessionMutationBar.tsx +0 -76
- package/src/registry/lib/primitives/SessionTabbedDrawer.tsx +0 -165
- package/src/registry/lib/primitives/index.ts +0 -18
- package/src/registry/lib/session-context-builder.ts +0 -84
- package/src/registry/lib/session-context-provider.tsx +0 -33
- package/src/registry/lib/session-context.ts +0 -21
- package/src/registry/lib/session-selectors.ts +0 -272
- package/src/session/comments/CommentRail.tsx +0 -164
- package/src/session/index.ts +0 -3
- package/src/session/lib/cn.ts +0 -11
- package/src/session/shell/SessionWorkspaceShell.tsx +0 -147
- package/src/session-kit/approvals/ApprovalButton.tsx +0 -89
- package/src/session-kit/approvals/ApprovalCard.tsx +0 -341
- package/src/session-kit/approvals/ApprovalsCenter.tsx +0 -336
- package/src/session-kit/approvals/CapabilityApprovalStickyBar.tsx +0 -118
- package/src/session-kit/approvals/Obligation.tsx +0 -111
- package/src/session-kit/approvals/ScopedBody.tsx +0 -392
- package/src/session-kit/approvals/approval-icons.ts +0 -31
- package/src/session-kit/approvals/approval-model.ts +0 -204
- package/src/session-kit/approvals/index.ts +0 -22
- package/src/session-kit/approvals/obligation-display.ts +0 -100
- package/src/session-kit/approvals/risk-accent.ts +0 -47
- package/src/session-kit/approvals/scope-icons.ts +0 -19
- package/src/session-kit/combobox/Combobox.tsx +0 -358
- package/src/session-kit/combobox/use-click-outside.ts +0 -21
- package/src/session-kit/display/ContextHeader.tsx +0 -148
- package/src/session-kit/display/FileDiffCard.tsx +0 -140
- package/src/session-kit/display/MD.tsx +0 -162
- package/src/session-kit/display/MessageTurn.tsx +0 -157
- package/src/session-kit/display/ThinkingPanel.tsx +0 -81
- package/src/session-kit/display/TodoChecklist.tsx +0 -120
- package/src/session-kit/display/TokenMeter.tsx +0 -89
- package/src/session-kit/display/ToolStrip.tsx +0 -278
- package/src/session-kit/display/TypingDots.tsx +0 -24
- package/src/session-kit/index.ts +0 -44
- package/src/session-kit/lib/enums.ts +0 -66
- package/src/session-kit/lib/portal-accent.ts +0 -30
- package/src/session-kit/lib/status-dot.ts +0 -68
- package/src/session-kit/primitives/Avatar.tsx +0 -44
- package/src/session-kit/primitives/PortalGlyph.tsx +0 -51
- package/src/session-kit/primitives/RiskPill.tsx +0 -95
- package/src/session-kit/primitives/ScopeDot.tsx +0 -47
- package/src/session-kit/primitives/Segmented.tsx +0 -71
- package/src/ui/branding/app-branding-context.ts +0 -20
- package/src/ui/branding/app-branding-provider.tsx +0 -123
- package/src/ui/branding/sanitize.ts +0 -89
- package/src/ui/breakpoints.ts +0 -14
- package/src/ui/capture/document-preview.tsx +0 -166
- package/src/ui/capture/field-spec-to-zod.test.ts +0 -81
- package/src/ui/capture/field-spec-to-zod.ts +0 -174
- package/src/ui/capture/field-spec-validate.ts +0 -236
- package/src/ui/capture/field-spec.test.ts +0 -49
- package/src/ui/capture/field-spec.ts +0 -274
- package/src/ui/capture/index.ts +0 -51
- package/src/ui/capture/schema-field-input.tsx +0 -620
- package/src/ui/capture/schema-form.tsx +0 -149
- package/src/ui/capture/submit-values.test.ts +0 -70
- package/src/ui/capture/submit-values.ts +0 -63
- package/src/ui/capture/use-prefill.ts +0 -186
- package/src/ui/capture/use-schema-validation.ts +0 -145
- package/src/ui/capture/use-wizard.ts +0 -180
- package/src/ui/capture/value-format.ts +0 -32
- package/src/ui/capture/wizard.tsx +0 -105
- package/src/ui/charts/bar-chart.tsx +0 -139
- package/src/ui/charts/chart-frame.tsx +0 -125
- package/src/ui/charts/chart-types.ts +0 -52
- package/src/ui/charts/chart-utils.ts +0 -190
- package/src/ui/charts/charts.test.tsx +0 -204
- package/src/ui/charts/donut-chart.tsx +0 -129
- package/src/ui/charts/index.ts +0 -27
- package/src/ui/charts/line-chart.tsx +0 -202
- package/src/ui/charts/sparkline.tsx +0 -109
- package/src/ui/chrome/AsyncBoundary.tsx +0 -74
- package/src/ui/chrome/EmptyState.tsx +0 -257
- package/src/ui/chrome/ErrorCard.tsx +0 -63
- package/src/ui/chrome/LoadingState.tsx +0 -61
- package/src/ui/chrome/PageHeader.tsx +0 -137
- package/src/ui/chrome/RecordCardList.tsx +0 -98
- package/src/ui/chrome/StateCard.tsx +0 -150
- package/src/ui/chrome/confirm-delete-dialog.tsx +0 -59
- package/src/ui/chrome/page-shell.spec.tsx +0 -117
- package/src/ui/chrome/page-shell.tsx +0 -221
- package/src/ui/chrome/scope-badge.tsx +0 -40
- package/src/ui/chrome/status-badge.tsx +0 -79
- package/src/ui/cn.ts +0 -32
- package/src/ui/design-tokens.ts +0 -372
- package/src/ui/hooks/use-debounced-value.ts +0 -16
- package/src/ui/hooks/use-is-mobile.ts +0 -28
- package/src/ui/index.ts +0 -110
- package/src/ui/pdf/pdf-preview.tsx +0 -122
- package/src/ui/primitives/alert-dialog.tsx +0 -104
- package/src/ui/primitives/async-combobox.tsx +0 -182
- package/src/ui/primitives/badge-variants.ts +0 -21
- package/src/ui/primitives/badge.tsx +0 -25
- package/src/ui/primitives/button-variants.ts +0 -31
- package/src/ui/primitives/button.tsx +0 -29
- package/src/ui/primitives/card.tsx +0 -43
- package/src/ui/primitives/checkbox.tsx +0 -26
- package/src/ui/primitives/collapsible.tsx +0 -9
- package/src/ui/primitives/dialog.tsx +0 -103
- package/src/ui/primitives/dropdown-menu.tsx +0 -179
- package/src/ui/primitives/form-stepper.tsx +0 -94
- package/src/ui/primitives/form-stepper.types.ts +0 -15
- package/src/ui/primitives/input.tsx +0 -22
- package/src/ui/primitives/label.tsx +0 -17
- package/src/ui/primitives/overflow-tabs.tsx +0 -331
- package/src/ui/primitives/popover.tsx +0 -33
- package/src/ui/primitives/preview-device-frame.tsx +0 -213
- package/src/ui/primitives/radio-group.tsx +0 -36
- package/src/ui/primitives/resizable.tsx +0 -67
- package/src/ui/primitives/scroll-area.tsx +0 -38
- package/src/ui/primitives/select.tsx +0 -143
- package/src/ui/primitives/separator.tsx +0 -20
- package/src/ui/primitives/sheet.tsx +0 -107
- package/src/ui/primitives/skeleton.tsx +0 -99
- package/src/ui/primitives/switch.tsx +0 -27
- package/src/ui/primitives/table.tsx +0 -72
- package/src/ui/primitives/tabs.tsx +0 -53
- package/src/ui/primitives/tag-multi-select.tsx +0 -261
- package/src/ui/primitives/textarea.tsx +0 -21
- package/src/ui/primitives/tooltip.tsx +0 -30
- package/src/ui/primitives/url-preview-chrome.tsx +0 -103
- package/src/vista/GenericCatalogueSurface.tsx +0 -179
- package/src/vista/SurfaceFallbackCard.tsx +0 -109
- package/src/vista/VistaPanel.tsx +0 -163
- package/src/vista/form-payload.spec.ts +0 -139
- package/src/vista/html/CustomUiFrame.spec.tsx +0 -127
- package/src/vista/html/CustomUiFrame.tsx +0 -206
- package/src/vista/html/custom-ui-frame-bridge.spec.ts +0 -191
- package/src/vista/html/custom-ui-frame-bridge.ts +0 -98
- package/src/vista/html/custom-ui-frame-contract.ts +0 -88
- package/src/vista/html/custom-ui-intents.spec.ts +0 -135
- package/src/vista/html/custom-ui-intents.ts +0 -155
- package/src/vista/html/custom-ui-srcdoc.spec.ts +0 -151
- package/src/vista/html/custom-ui-srcdoc.ts +0 -193
- package/src/vista/html/index.ts +0 -13
- package/src/vista/index.ts +0 -52
- package/src/vista/surface-catalogue.spec.ts +0 -140
- package/src/vista/surface-catalogue.ts +0 -90
- package/src/vista/surface-icons.ts +0 -57
- package/src/vista/surface-registry.ts +0 -56
- package/src/vista/surfaces/ChartSurface.tsx +0 -34
- package/src/vista/surfaces/FilesSurface.tsx +0 -202
- package/src/vista/surfaces/FormSurface.tsx +0 -380
- package/src/vista/surfaces/HtmlSurface.tsx +0 -43
- package/src/vista/surfaces/TableSurface.tsx +0 -100
- package/src/vista/surfaces/UrlSurface.tsx +0 -40
- package/src/vista/surfaces/blob-surfaces.tsx +0 -139
- package/src/vista/surfaces/elicitation-transport.spec.ts +0 -369
- package/src/vista/surfaces/elicitation-transport.ts +0 -367
- package/src/vista/surfaces/file-surface-utils.ts +0 -69
- package/src/vista/surfaces/index.ts +0 -24
- package/src/vista/surfaces/register-surfaces.tsx +0 -139
- package/src/vista/surfaces/text-surfaces.tsx +0 -132
- package/src/vista/use-vista-tabs.ts +0 -196
- package/src/vista/vista-code-renderer-context.ts +0 -16
- package/src/vista/vista-code-renderer.tsx +0 -35
- package/src/vista/vista-file-context.ts +0 -14
- package/src/vista/vista-file-source.tsx +0 -141
- package/src/vista/vista-form-context.ts +0 -20
- package/src/vista/vista-form-host.tsx +0 -48
- package/src/vista/vista-model.ts +0 -137
- package/src/vista/vista-open-context.tsx +0 -27
- package/src/vista/vista-open-state.ts +0 -11
- package/src/vista/vista-payloads.ts +0 -635
- package/src/vista/vista-tabs-manifest.ts +0 -138
- package/src/vista/vista-tools.ts +0 -232
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
// Pure-logic proofs for the CaptureFieldSpec → zod adapter. Runs under the
|
|
2
|
-
// host-web vitest runner (this package carries no vitest dep — see tsconfig
|
|
3
|
-
// exclude), mirroring the repo convention used by i18n-port.test.ts.
|
|
4
|
-
import { describe, expect, it } from 'vitest';
|
|
5
|
-
|
|
6
|
-
import { CaptureFieldType, type CaptureFieldSpec } from './field-spec';
|
|
7
|
-
import { fieldSpecToZod, isEmptyValue } from './field-spec-to-zod';
|
|
8
|
-
|
|
9
|
-
describe('isEmptyValue', () => {
|
|
10
|
-
it('treats undefined/null/empty-string/empty-array as absent', () => {
|
|
11
|
-
expect(isEmptyValue(undefined)).toBe(true);
|
|
12
|
-
expect(isEmptyValue(null)).toBe(true);
|
|
13
|
-
expect(isEmptyValue('')).toBe(true);
|
|
14
|
-
expect(isEmptyValue([])).toBe(true);
|
|
15
|
-
expect(isEmptyValue('x')).toBe(false);
|
|
16
|
-
expect(isEmptyValue(0)).toBe(false);
|
|
17
|
-
expect(isEmptyValue(false)).toBe(false);
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
describe('fieldSpecToZod', () => {
|
|
22
|
-
const fields: CaptureFieldSpec[] = [
|
|
23
|
-
{ key: 'title', label: 'Title', type: CaptureFieldType.String, required: true },
|
|
24
|
-
{ key: 'count', label: 'Count', type: CaptureFieldType.Number, required: false, min: 0 },
|
|
25
|
-
{ key: 'status', label: 'Status', type: CaptureFieldType.Enum, enumValues: ['open', 'closed'], required: true },
|
|
26
|
-
{
|
|
27
|
-
key: 'tags',
|
|
28
|
-
label: 'Tags',
|
|
29
|
-
type: CaptureFieldType.List,
|
|
30
|
-
min: 1,
|
|
31
|
-
fields: [{ key: 'name', label: 'Name', type: CaptureFieldType.String, required: true }],
|
|
32
|
-
},
|
|
33
|
-
];
|
|
34
|
-
|
|
35
|
-
it('accepts a valid record', () => {
|
|
36
|
-
const r = fieldSpecToZod(fields).safeParse({ title: 'Hi', count: 3, status: 'open', tags: [{ name: 'a' }] });
|
|
37
|
-
expect(r.success).toBe(true);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('rejects an empty required string', () => {
|
|
41
|
-
const r = fieldSpecToZod(fields).safeParse({ title: '', status: 'open', tags: [{ name: 'a' }] });
|
|
42
|
-
expect(r.success).toBe(false);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('allows an omitted optional field', () => {
|
|
46
|
-
const r = fieldSpecToZod(fields).safeParse({ title: 'Hi', status: 'closed', tags: [{ name: 'a' }] });
|
|
47
|
-
expect(r.success).toBe(true);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('rejects an enum value outside the set', () => {
|
|
51
|
-
const r = fieldSpecToZod(fields).safeParse({ title: 'Hi', status: 'bogus', tags: [{ name: 'a' }] });
|
|
52
|
-
expect(r.success).toBe(false);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('enforces list min and nested required item fields', () => {
|
|
56
|
-
expect(fieldSpecToZod(fields).safeParse({ title: 'Hi', status: 'open', tags: [] }).success).toBe(false);
|
|
57
|
-
expect(fieldSpecToZod(fields).safeParse({ title: 'Hi', status: 'open', tags: [{ name: '' }] }).success).toBe(false);
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
describe('media fields (image/file/audio)', () => {
|
|
62
|
-
const media: CaptureFieldSpec[] = [
|
|
63
|
-
{ key: 'photo', label: 'Photo', type: CaptureFieldType.Image, required: true },
|
|
64
|
-
{ key: 'attachment', label: 'Attachment', type: CaptureFieldType.File },
|
|
65
|
-
{ key: 'memo', label: 'Voice memo', type: CaptureFieldType.Audio },
|
|
66
|
-
];
|
|
67
|
-
const dataUrl = 'data:image/png;base64,AAAA';
|
|
68
|
-
|
|
69
|
-
it('accepts a captured data-URL for a required media field', () => {
|
|
70
|
-
expect(fieldSpecToZod(media).safeParse({ photo: dataUrl }).success).toBe(true);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('rejects an empty required media field', () => {
|
|
74
|
-
expect(fieldSpecToZod(media).safeParse({ photo: '' }).success).toBe(false);
|
|
75
|
-
expect(fieldSpecToZod(media).safeParse({}).success).toBe(false);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('allows omitted optional media fields', () => {
|
|
79
|
-
expect(fieldSpecToZod(media).safeParse({ photo: dataUrl }).success).toBe(true);
|
|
80
|
-
});
|
|
81
|
-
})
|
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
2
|
-
// CaptureFieldSpec → Zod adapter
|
|
3
|
-
//
|
|
4
|
-
// Bridges the JSON-Schema-like field spec (name/type/required/enum, and the
|
|
5
|
-
// nested object/list composites) to a `zod` schema so `useSchemaValidation`
|
|
6
|
-
// works with app definitions, not only hand-written zod. Deterministic and
|
|
7
|
-
// pure — no side effects, safe to memoize on the spec identity.
|
|
8
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
9
|
-
import { z } from 'zod';
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
CaptureFieldType,
|
|
13
|
-
type CaptureFieldSpec,
|
|
14
|
-
type CaptureSchema,
|
|
15
|
-
type CaptureSection,
|
|
16
|
-
toFieldList,
|
|
17
|
-
} from './field-spec';
|
|
18
|
-
|
|
19
|
-
/** `''`, `null`, `undefined` all mean "absent" at the capture boundary. */
|
|
20
|
-
export function isEmptyValue(value: unknown): boolean {
|
|
21
|
-
return (
|
|
22
|
-
value === undefined ||
|
|
23
|
-
value === null ||
|
|
24
|
-
value === '' ||
|
|
25
|
-
(Array.isArray(value) && value.length === 0)
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function scalarSchema(field: CaptureFieldSpec): z.ZodTypeAny {
|
|
30
|
-
switch (field.type) {
|
|
31
|
-
case CaptureFieldType.Number: {
|
|
32
|
-
let s = z.number({ message: `${field.label} must be a number` });
|
|
33
|
-
if (typeof field.min === 'number') {
|
|
34
|
-
s = s.min(field.min, {
|
|
35
|
-
message: `${field.label} must be ≥ ${field.min}`,
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
if (typeof field.max === 'number') {
|
|
39
|
-
s = s.max(field.max, {
|
|
40
|
-
message: `${field.label} must be ≤ ${field.max}`,
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
return s;
|
|
44
|
-
}
|
|
45
|
-
case CaptureFieldType.Boolean:
|
|
46
|
-
return z.boolean({ message: `${field.label} must be true or false` });
|
|
47
|
-
case CaptureFieldType.Decimal:
|
|
48
|
-
// NUMERIC carried as a string to avoid float precision loss.
|
|
49
|
-
return z
|
|
50
|
-
.string()
|
|
51
|
-
.regex(/^-?\d+(\.\d+)?$/, {
|
|
52
|
-
message: `${field.label} must be a decimal number`,
|
|
53
|
-
});
|
|
54
|
-
case CaptureFieldType.Enum: {
|
|
55
|
-
const values = [...(field.enumValues ?? [])];
|
|
56
|
-
if (values.length === 0) {
|
|
57
|
-
return z.string();
|
|
58
|
-
}
|
|
59
|
-
return z.enum(values as [string, ...string[]]);
|
|
60
|
-
}
|
|
61
|
-
case CaptureFieldType.Date:
|
|
62
|
-
return z
|
|
63
|
-
.string()
|
|
64
|
-
.regex(/^\d{4}-\d{2}-\d{2}$/, {
|
|
65
|
-
message: `${field.label} must be a date`,
|
|
66
|
-
});
|
|
67
|
-
case CaptureFieldType.Datetime:
|
|
68
|
-
return z
|
|
69
|
-
.string()
|
|
70
|
-
.min(1, { message: `${field.label} must be a date/time` });
|
|
71
|
-
// string / text / user / reference — plain text.
|
|
72
|
-
default:
|
|
73
|
-
return z.string();
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/** True when `value` parses as JSON. Total — never throws. */
|
|
78
|
-
export function isParsableJson(value: string): boolean {
|
|
79
|
-
try {
|
|
80
|
-
JSON.parse(value);
|
|
81
|
-
return true;
|
|
82
|
-
} catch {
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function fieldSchema(field: CaptureFieldSpec): z.ZodTypeAny {
|
|
88
|
-
let base: z.ZodTypeAny;
|
|
89
|
-
if (field.type === CaptureFieldType.Object) {
|
|
90
|
-
base = objectSchema(field.fields ?? []);
|
|
91
|
-
} else if (field.type === CaptureFieldType.Json) {
|
|
92
|
-
// A JSON blob is carried as TEXT and validated as parseable. `''` passes
|
|
93
|
-
// the shape check so an optional blank field stays valid; requiredness is
|
|
94
|
-
// enforced by the `.min(1)` below, not by the parse rule.
|
|
95
|
-
const text = field.required
|
|
96
|
-
? z.string().min(1, { message: `${field.label} is required` })
|
|
97
|
-
: z.string();
|
|
98
|
-
base = text.refine((v) => v === '' || isParsableJson(v), {
|
|
99
|
-
message: `${field.label} must be valid JSON`,
|
|
100
|
-
});
|
|
101
|
-
} else if (field.type === CaptureFieldType.List) {
|
|
102
|
-
let arr = z.array(objectSchema(field.fields ?? []));
|
|
103
|
-
if (typeof field.min === 'number') {
|
|
104
|
-
arr = arr.min(field.min, {
|
|
105
|
-
message: `${field.label} needs at least ${field.min} item(s)`,
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
if (typeof field.max === 'number') {
|
|
109
|
-
arr = arr.max(field.max, {
|
|
110
|
-
message: `${field.label} allows at most ${field.max} item(s)`,
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
base = arr;
|
|
114
|
-
} else {
|
|
115
|
-
base = scalarSchema(field);
|
|
116
|
-
if (
|
|
117
|
-
field.required &&
|
|
118
|
-
(field.type === CaptureFieldType.String ||
|
|
119
|
-
field.type === CaptureFieldType.Text ||
|
|
120
|
-
field.type === CaptureFieldType.Email ||
|
|
121
|
-
field.type === CaptureFieldType.Url ||
|
|
122
|
-
field.type === CaptureFieldType.User ||
|
|
123
|
-
field.type === CaptureFieldType.Reference ||
|
|
124
|
-
field.type === CaptureFieldType.Datetime ||
|
|
125
|
-
// Media fields carry a data-URL string; required = a capture was made.
|
|
126
|
-
field.type === CaptureFieldType.Image ||
|
|
127
|
-
field.type === CaptureFieldType.File ||
|
|
128
|
-
field.type === CaptureFieldType.Audio)
|
|
129
|
-
) {
|
|
130
|
-
base = (base as z.ZodString).min(1, {
|
|
131
|
-
message: `${field.label} is required`,
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (!field.required) {
|
|
137
|
-
// Optional: `.optional()` makes the object KEY absent-safe (zod v4 does not
|
|
138
|
-
// infer that from a union with z.undefined()); the union additionally
|
|
139
|
-
// accepts the empty-string / null sentinels the inputs emit for "cleared".
|
|
140
|
-
return z.union([base, z.literal(''), z.null()]).optional();
|
|
141
|
-
}
|
|
142
|
-
return base;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function objectSchema(
|
|
146
|
-
fields: readonly CaptureFieldSpec[],
|
|
147
|
-
): z.ZodObject<z.ZodRawShape> {
|
|
148
|
-
const shape: Record<string, z.ZodTypeAny> = {};
|
|
149
|
-
for (const f of fields) {
|
|
150
|
-
shape[f.key] = fieldSchema(f);
|
|
151
|
-
}
|
|
152
|
-
// Non-strict: unknown keys are ignored (the server is the strict fence).
|
|
153
|
-
return z.object(shape);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Build a `zod` object schema from a capture schema (flat fields, sections, or
|
|
158
|
-
* a `CaptureSchema`). The result validates the whole values record.
|
|
159
|
-
*
|
|
160
|
-
* @example
|
|
161
|
-
* const schema = fieldSpecToZod([
|
|
162
|
-
* { key: 'title', label: 'Title', type: 'string', required: true },
|
|
163
|
-
* { key: 'tags', label: 'Tags', type: 'list', fields: [{ key: 'name', label: 'Name', type: 'string', required: true }] },
|
|
164
|
-
* ]);
|
|
165
|
-
* schema.safeParse({ title: 'Hi', tags: [{ name: 'a' }] }); // { success: true }
|
|
166
|
-
*/
|
|
167
|
-
export function fieldSpecToZod(
|
|
168
|
-
schema:
|
|
169
|
-
| CaptureSchema
|
|
170
|
-
| readonly CaptureFieldSpec[]
|
|
171
|
-
| readonly CaptureSection[],
|
|
172
|
-
): z.ZodObject<z.ZodRawShape> {
|
|
173
|
-
return objectSchema(toFieldList(schema));
|
|
174
|
-
}
|
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
2
|
-
// Total runtime validator for a `CaptureFieldSpec[]` arriving from the wire
|
|
3
|
-
//
|
|
4
|
-
// `fieldSpecToZod` validates the VALUES a form produces. This validates the
|
|
5
|
-
// SCHEMA itself, for the case where the field list is not authored in TypeScript
|
|
6
|
-
// but carried in an envelope (a Vista `form` surface payload, a biome
|
|
7
|
-
// contribution, an agent-authored capture step).
|
|
8
|
-
//
|
|
9
|
-
// Contract: TOTAL and NEVER throws — it returns the narrowed specs or `null`,
|
|
10
|
-
// exactly like the Vista payload validators, so a malformed schema degrades to
|
|
11
|
-
// a visible typed fallback instead of a half-rendered form.
|
|
12
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
13
|
-
import {
|
|
14
|
-
CaptureFieldTransform,
|
|
15
|
-
CaptureFieldType,
|
|
16
|
-
type CaptureFieldSpec,
|
|
17
|
-
} from './field-spec';
|
|
18
|
-
|
|
19
|
-
const FIELD_TYPES: ReadonlySet<string> = new Set(
|
|
20
|
-
Object.values(CaptureFieldType),
|
|
21
|
-
);
|
|
22
|
-
const TRANSFORMS: ReadonlySet<string> = new Set(
|
|
23
|
-
Object.values(CaptureFieldTransform),
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
type UnknownRecord = Readonly<Record<string, unknown>>;
|
|
27
|
-
|
|
28
|
-
function asRecord(value: unknown): UnknownRecord | null {
|
|
29
|
-
return value !== null && typeof value === 'object' && !Array.isArray(value)
|
|
30
|
-
? (value as UnknownRecord)
|
|
31
|
-
: null;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/** `undefined` passes through; a present non-string is a rejection (`null`). */
|
|
35
|
-
function optionalString(value: unknown): string | undefined | null {
|
|
36
|
-
if (value === undefined) {
|
|
37
|
-
return undefined;
|
|
38
|
-
}
|
|
39
|
-
return typeof value === 'string' ? value : null;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/** `undefined` passes through; a present non-boolean is a rejection (`null`). */
|
|
43
|
-
function optionalBoolean(value: unknown): boolean | undefined | null {
|
|
44
|
-
if (value === undefined) {
|
|
45
|
-
return undefined;
|
|
46
|
-
}
|
|
47
|
-
return typeof value === 'boolean' ? value : null;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/** `undefined` passes through; a present non-number is a rejection (`null`). */
|
|
51
|
-
function optionalNumber(value: unknown): number | undefined | null {
|
|
52
|
-
if (value === undefined) {
|
|
53
|
-
return undefined;
|
|
54
|
-
}
|
|
55
|
-
return typeof value === 'number' && Number.isFinite(value) ? value : null;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/** Narrow ONE field spec. Returns `null` for anything malformed. */
|
|
59
|
-
export function validateCaptureField(raw: unknown): CaptureFieldSpec | null {
|
|
60
|
-
const record = asRecord(raw);
|
|
61
|
-
if (record === null) {
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
|
-
if (typeof record.key !== 'string' || record.key.length === 0) {
|
|
65
|
-
return null;
|
|
66
|
-
}
|
|
67
|
-
if (typeof record.label !== 'string' || record.label.length === 0) {
|
|
68
|
-
return null;
|
|
69
|
-
}
|
|
70
|
-
if (typeof record.type !== 'string' || !FIELD_TYPES.has(record.type)) {
|
|
71
|
-
return null;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const required = optionalBoolean(record.required);
|
|
75
|
-
if (required === null) {
|
|
76
|
-
return null;
|
|
77
|
-
}
|
|
78
|
-
const isSecret = optionalBoolean(record.isSecret);
|
|
79
|
-
if (isSecret === null) {
|
|
80
|
-
return null;
|
|
81
|
-
}
|
|
82
|
-
const description = optionalString(record.description);
|
|
83
|
-
if (description === null) {
|
|
84
|
-
return null;
|
|
85
|
-
}
|
|
86
|
-
const placeholder = optionalString(record.placeholder);
|
|
87
|
-
if (placeholder === null) {
|
|
88
|
-
return null;
|
|
89
|
-
}
|
|
90
|
-
const section = optionalString(record.section);
|
|
91
|
-
if (section === null) {
|
|
92
|
-
return null;
|
|
93
|
-
}
|
|
94
|
-
const referenceEntity = optionalString(record.referenceEntity);
|
|
95
|
-
if (referenceEntity === null) {
|
|
96
|
-
return null;
|
|
97
|
-
}
|
|
98
|
-
const accept = optionalString(record.accept);
|
|
99
|
-
if (accept === null) {
|
|
100
|
-
return null;
|
|
101
|
-
}
|
|
102
|
-
const min = optionalNumber(record.min);
|
|
103
|
-
if (min === null) {
|
|
104
|
-
return null;
|
|
105
|
-
}
|
|
106
|
-
const max = optionalNumber(record.max);
|
|
107
|
-
if (max === null) {
|
|
108
|
-
return null;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
let transform: CaptureFieldTransform | undefined;
|
|
112
|
-
if (record.transform !== undefined) {
|
|
113
|
-
if (
|
|
114
|
-
typeof record.transform !== 'string' ||
|
|
115
|
-
!TRANSFORMS.has(record.transform)
|
|
116
|
-
) {
|
|
117
|
-
return null;
|
|
118
|
-
}
|
|
119
|
-
transform = record.transform as CaptureFieldTransform;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
let enumValues: readonly string[] | undefined;
|
|
123
|
-
if (record.enumValues !== undefined) {
|
|
124
|
-
if (!Array.isArray(record.enumValues)) {
|
|
125
|
-
return null;
|
|
126
|
-
}
|
|
127
|
-
if (!record.enumValues.every((v) => typeof v === 'string')) {
|
|
128
|
-
return null;
|
|
129
|
-
}
|
|
130
|
-
enumValues = record.enumValues;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
let capture: 'user' | 'environment' | undefined;
|
|
134
|
-
if (record.capture !== undefined) {
|
|
135
|
-
if (record.capture !== 'user' && record.capture !== 'environment') {
|
|
136
|
-
return null;
|
|
137
|
-
}
|
|
138
|
-
capture = record.capture;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
let fields: readonly CaptureFieldSpec[] | undefined;
|
|
142
|
-
if (record.fields !== undefined) {
|
|
143
|
-
const nested = validateCaptureFields(record.fields);
|
|
144
|
-
if (nested === null) {
|
|
145
|
-
return null;
|
|
146
|
-
}
|
|
147
|
-
fields = nested;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
const spec: {
|
|
151
|
-
key: string;
|
|
152
|
-
label: string;
|
|
153
|
-
type: CaptureFieldType;
|
|
154
|
-
required?: boolean;
|
|
155
|
-
isSecret?: boolean;
|
|
156
|
-
transform?: CaptureFieldTransform;
|
|
157
|
-
description?: string;
|
|
158
|
-
placeholder?: string;
|
|
159
|
-
section?: string;
|
|
160
|
-
referenceEntity?: string;
|
|
161
|
-
accept?: string;
|
|
162
|
-
capture?: 'user' | 'environment';
|
|
163
|
-
enumValues?: readonly string[];
|
|
164
|
-
fields?: readonly CaptureFieldSpec[];
|
|
165
|
-
min?: number;
|
|
166
|
-
max?: number;
|
|
167
|
-
} = {
|
|
168
|
-
key: record.key,
|
|
169
|
-
label: record.label,
|
|
170
|
-
type: record.type as CaptureFieldType,
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
if (required !== undefined) {
|
|
174
|
-
spec.required = required;
|
|
175
|
-
}
|
|
176
|
-
if (isSecret !== undefined) {
|
|
177
|
-
spec.isSecret = isSecret;
|
|
178
|
-
}
|
|
179
|
-
if (transform !== undefined) {
|
|
180
|
-
spec.transform = transform;
|
|
181
|
-
}
|
|
182
|
-
if (description !== undefined) {
|
|
183
|
-
spec.description = description;
|
|
184
|
-
}
|
|
185
|
-
if (placeholder !== undefined) {
|
|
186
|
-
spec.placeholder = placeholder;
|
|
187
|
-
}
|
|
188
|
-
if (section !== undefined) {
|
|
189
|
-
spec.section = section;
|
|
190
|
-
}
|
|
191
|
-
if (referenceEntity !== undefined) {
|
|
192
|
-
spec.referenceEntity = referenceEntity;
|
|
193
|
-
}
|
|
194
|
-
if (accept !== undefined) {
|
|
195
|
-
spec.accept = accept;
|
|
196
|
-
}
|
|
197
|
-
if (capture !== undefined) {
|
|
198
|
-
spec.capture = capture;
|
|
199
|
-
}
|
|
200
|
-
if (enumValues !== undefined) {
|
|
201
|
-
spec.enumValues = enumValues;
|
|
202
|
-
}
|
|
203
|
-
if (fields !== undefined) {
|
|
204
|
-
spec.fields = fields;
|
|
205
|
-
}
|
|
206
|
-
if (min !== undefined) {
|
|
207
|
-
spec.min = min;
|
|
208
|
-
}
|
|
209
|
-
if (max !== undefined) {
|
|
210
|
-
spec.max = max;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
return spec;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
* Narrow a whole field list. An EMPTY array is valid and narrows to `[]` — an
|
|
218
|
-
* empty schema is a real, meaningful state (the server is the authority on
|
|
219
|
-
* whether a form with no fields may be submitted), not a validation failure.
|
|
220
|
-
*/
|
|
221
|
-
export function validateCaptureFields(
|
|
222
|
-
raw: unknown,
|
|
223
|
-
): readonly CaptureFieldSpec[] | null {
|
|
224
|
-
if (!Array.isArray(raw)) {
|
|
225
|
-
return null;
|
|
226
|
-
}
|
|
227
|
-
const out: CaptureFieldSpec[] = [];
|
|
228
|
-
for (const entry of raw) {
|
|
229
|
-
const spec = validateCaptureField(entry);
|
|
230
|
-
if (spec === null) {
|
|
231
|
-
return null;
|
|
232
|
-
}
|
|
233
|
-
out.push(spec);
|
|
234
|
-
}
|
|
235
|
-
return out;
|
|
236
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
// Pure-logic proofs for the schema-face normalizers. Runs under host-web
|
|
2
|
-
// vitest (this package carries no vitest dep — see tsconfig exclude).
|
|
3
|
-
import { describe, expect, it } from 'vitest';
|
|
4
|
-
|
|
5
|
-
import { CaptureFieldType, groupFieldsBySection, toFieldList, toSections, type CaptureFieldSpec, type CaptureSection } from './field-spec';
|
|
6
|
-
|
|
7
|
-
const fields: CaptureFieldSpec[] = [
|
|
8
|
-
{ key: 'a', label: 'A', type: CaptureFieldType.String, section: 'one' },
|
|
9
|
-
{ key: 'b', label: 'B', type: CaptureFieldType.Number, section: 'one' },
|
|
10
|
-
{ key: 'c', label: 'C', type: CaptureFieldType.Boolean, section: 'two' },
|
|
11
|
-
];
|
|
12
|
-
|
|
13
|
-
const sections: CaptureSection[] = [
|
|
14
|
-
{ key: 's1', title: 'S1', fields: [{ key: 'a', label: 'A', type: CaptureFieldType.String }] },
|
|
15
|
-
{ key: 's2', title: 'S2', fields: [{ key: 'b', label: 'B', type: CaptureFieldType.String }] },
|
|
16
|
-
];
|
|
17
|
-
|
|
18
|
-
describe('toFieldList', () => {
|
|
19
|
-
it('returns a flat field list unchanged', () => {
|
|
20
|
-
expect(toFieldList(fields).map((f) => f.key)).toEqual(['a', 'b', 'c']);
|
|
21
|
-
});
|
|
22
|
-
it('flattens sections to their fields', () => {
|
|
23
|
-
expect(toFieldList(sections).map((f) => f.key)).toEqual(['a', 'b']);
|
|
24
|
-
});
|
|
25
|
-
it('reads the { fields } schema face', () => {
|
|
26
|
-
expect(toFieldList({ fields }).map((f) => f.key)).toEqual(['a', 'b', 'c']);
|
|
27
|
-
});
|
|
28
|
-
it('reads the { sections } schema face', () => {
|
|
29
|
-
expect(toFieldList({ sections }).map((f) => f.key)).toEqual(['a', 'b']);
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
describe('groupFieldsBySection', () => {
|
|
34
|
-
it('splits a flat list by each field section key, preserving order', () => {
|
|
35
|
-
const grouped = groupFieldsBySection(fields);
|
|
36
|
-
expect(grouped.map((s) => s.key)).toEqual(['one', 'two']);
|
|
37
|
-
expect(grouped[0]?.fields.map((f) => f.key)).toEqual(['a', 'b']);
|
|
38
|
-
expect(grouped[1]?.fields.map((f) => f.key)).toEqual(['c']);
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
describe('toSections', () => {
|
|
43
|
-
it('passes explicit sections through', () => {
|
|
44
|
-
expect(toSections(sections).map((s) => s.title)).toEqual(['S1', 'S2']);
|
|
45
|
-
});
|
|
46
|
-
it('derives sections from a flat list', () => {
|
|
47
|
-
expect(toSections(fields).map((s) => s.key)).toEqual(['one', 'two']);
|
|
48
|
-
});
|
|
49
|
-
});
|