@tai42/studio-sdk 15.0.0 → 16.0.1
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/components/explorer-body.d.ts +49 -0
- package/dist/components/explorer-body.d.ts.map +1 -0
- package/dist/components/explorer-body.js +67 -0
- package/dist/components/explorer-body.js.map +1 -0
- package/dist/components/explorer-page-size.d.ts +4 -0
- package/dist/components/explorer-page-size.d.ts.map +1 -0
- package/dist/components/explorer-page-size.js +36 -0
- package/dist/components/explorer-page-size.js.map +1 -0
- package/dist/components/explorer-tag-filter.d.ts +17 -0
- package/dist/components/explorer-tag-filter.d.ts.map +1 -0
- package/dist/components/explorer-tag-filter.js +29 -0
- package/dist/components/explorer-tag-filter.js.map +1 -0
- package/dist/components/explorer-tags.d.ts +22 -0
- package/dist/components/explorer-tags.d.ts.map +1 -0
- package/dist/components/explorer-tags.js +51 -0
- package/dist/components/explorer-tags.js.map +1 -0
- package/dist/components/explorer-view.d.ts +3 -17
- package/dist/components/explorer-view.d.ts.map +1 -1
- package/dist/components/explorer-view.js +53 -170
- package/dist/components/explorer-view.js.map +1 -1
- package/dist/components/extension-combo-builder.d.ts +0 -5
- package/dist/components/extension-combo-builder.d.ts.map +1 -1
- package/dist/components/extension-combo-builder.js +4 -42
- package/dist/components/extension-combo-builder.js.map +1 -1
- package/dist/components/extension-combo-parts.d.ts +44 -0
- package/dist/components/extension-combo-parts.d.ts.map +1 -0
- package/dist/components/extension-combo-parts.js +57 -0
- package/dist/components/extension-combo-parts.js.map +1 -0
- package/dist/components/fleet-report.d.ts.map +1 -1
- package/dist/components/fleet-report.js +51 -37
- package/dist/components/fleet-report.js.map +1 -1
- package/dist/components/icons/chrome-marks.d.ts +50 -0
- package/dist/components/icons/chrome-marks.d.ts.map +1 -0
- package/dist/components/icons/chrome-marks.js +51 -0
- package/dist/components/icons/chrome-marks.js.map +1 -0
- package/dist/components/icons/icon-frame.d.ts +29 -0
- package/dist/components/icons/icon-frame.d.ts.map +1 -0
- package/dist/components/icons/icon-frame.js +19 -0
- package/dist/components/icons/icon-frame.js.map +1 -0
- package/dist/components/icons/index.d.ts +40 -0
- package/dist/components/icons/index.d.ts.map +1 -0
- package/dist/components/icons/index.js +6 -0
- package/dist/components/icons/index.js.map +1 -0
- package/dist/components/icons/nav-map.d.ts +14 -0
- package/dist/components/icons/nav-map.d.ts.map +1 -0
- package/dist/components/icons/nav-map.js +28 -0
- package/dist/components/icons/nav-map.js.map +1 -0
- package/dist/components/icons/nav-marks.d.ts +44 -0
- package/dist/components/icons/nav-marks.d.ts.map +1 -0
- package/dist/components/icons/nav-marks.js +45 -0
- package/dist/components/icons/nav-marks.js.map +1 -0
- package/dist/components/icons/status-marks.d.ts +21 -0
- package/dist/components/icons/status-marks.d.ts.map +1 -0
- package/dist/components/icons/status-marks.js +22 -0
- package/dist/components/icons/status-marks.js.map +1 -0
- package/dist/components/icons/theme-marks.d.ts +9 -0
- package/dist/components/icons/theme-marks.d.ts.map +1 -0
- package/dist/components/icons/theme-marks.js +10 -0
- package/dist/components/icons/theme-marks.js.map +1 -0
- package/dist/components/json-diff.d.ts.map +1 -1
- package/dist/components/json-diff.js +1 -3
- package/dist/components/json-diff.js.map +1 -1
- package/dist/components/json-tree-context.d.ts +13 -0
- package/dist/components/json-tree-context.d.ts.map +1 -0
- package/dist/components/json-tree-context.js +15 -0
- package/dist/components/json-tree-context.js.map +1 -0
- package/dist/components/json-tree-model.d.ts +56 -0
- package/dist/components/json-tree-model.d.ts.map +1 -0
- package/dist/components/json-tree-model.js +125 -0
- package/dist/components/json-tree-model.js.map +1 -0
- package/dist/components/json-tree-nodes.d.ts +30 -0
- package/dist/components/json-tree-nodes.d.ts.map +1 -0
- package/dist/components/json-tree-nodes.js +118 -0
- package/dist/components/json-tree-nodes.js.map +1 -0
- package/dist/components/json-tree.d.ts.map +1 -1
- package/dist/components/json-tree.js +7 -295
- package/dist/components/json-tree.js.map +1 -1
- package/dist/components/json-value-format.d.ts +20 -0
- package/dist/components/json-value-format.d.ts.map +1 -0
- package/dist/components/json-value-format.js +63 -0
- package/dist/components/json-value-format.js.map +1 -0
- package/dist/components/markdown-blocks.d.ts +38 -0
- package/dist/components/markdown-blocks.d.ts.map +1 -0
- package/dist/components/markdown-blocks.js +168 -0
- package/dist/components/markdown-blocks.js.map +1 -0
- package/dist/components/markdown-inline.d.ts +24 -0
- package/dist/components/markdown-inline.d.ts.map +1 -0
- package/dist/components/markdown-inline.js +257 -0
- package/dist/components/markdown-inline.js.map +1 -0
- package/dist/components/markdown.d.ts +3 -52
- package/dist/components/markdown.d.ts.map +1 -1
- package/dist/components/markdown.js +4 -376
- package/dist/components/markdown.js.map +1 -1
- package/dist/components/observer-registry.d.ts +38 -0
- package/dist/components/observer-registry.d.ts.map +1 -0
- package/dist/components/observer-registry.js +131 -0
- package/dist/components/observer-registry.js.map +1 -0
- package/dist/components/overflow-measure.d.ts +38 -0
- package/dist/components/overflow-measure.d.ts.map +1 -0
- package/dist/components/overflow-measure.js +54 -0
- package/dist/components/overflow-measure.js.map +1 -0
- package/dist/components/prose-regions.d.ts +81 -0
- package/dist/components/prose-regions.d.ts.map +1 -0
- package/dist/components/prose-regions.js +128 -0
- package/dist/components/prose-regions.js.map +1 -0
- package/dist/components/scroll-region.d.ts.map +1 -1
- package/dist/components/scroll-region.js +3 -298
- package/dist/components/scroll-region.js.map +1 -1
- package/dist/components/tab-stop-parse.d.ts +53 -0
- package/dist/components/tab-stop-parse.d.ts.map +1 -0
- package/dist/components/tab-stop-parse.js +202 -0
- package/dist/components/tab-stop-parse.js.map +1 -0
- package/dist/components/templated-text-field.d.ts.map +1 -1
- package/dist/components/templated-text-field.js +10 -148
- package/dist/components/templated-text-field.js.map +1 -1
- package/dist/components/templated-text-kwargs-editor.d.ts +24 -0
- package/dist/components/templated-text-kwargs-editor.d.ts.map +1 -0
- package/dist/components/templated-text-kwargs-editor.js +48 -0
- package/dist/components/templated-text-kwargs-editor.js.map +1 -0
- package/dist/components/templated-text-kwargs.d.ts +37 -0
- package/dist/components/templated-text-kwargs.d.ts.map +1 -0
- package/dist/components/templated-text-kwargs.js +66 -0
- package/dist/components/templated-text-kwargs.js.map +1 -0
- package/dist/components/templated-text-source.d.ts +33 -0
- package/dist/components/templated-text-source.d.ts.map +1 -0
- package/dist/components/templated-text-source.js +53 -0
- package/dist/components/templated-text-source.js.map +1 -0
- package/dist/components/tool-picker-parts.d.ts +39 -0
- package/dist/components/tool-picker-parts.d.ts.map +1 -0
- package/dist/components/tool-picker-parts.js +87 -0
- package/dist/components/tool-picker-parts.js.map +1 -0
- package/dist/components/tool-picker.d.ts +1 -2
- package/dist/components/tool-picker.d.ts.map +1 -1
- package/dist/components/tool-picker.js +4 -66
- package/dist/components/tool-picker.js.map +1 -1
- package/dist/components/version-history-panel.d.ts.map +1 -1
- package/dist/components/version-history-panel.js +7 -34
- package/dist/components/version-history-panel.js.map +1 -1
- package/dist/components/version-history-rows.d.ts +48 -0
- package/dist/components/version-history-rows.d.ts.map +1 -0
- package/dist/components/version-history-rows.js +51 -0
- package/dist/components/version-history-rows.js.map +1 -0
- package/dist/guards.d.ts +6 -0
- package/dist/guards.d.ts.map +1 -0
- package/dist/guards.js +8 -0
- package/dist/guards.js.map +1 -0
- package/dist/hooks/interactions-connection.d.ts +43 -0
- package/dist/hooks/interactions-connection.d.ts.map +1 -0
- package/dist/hooks/interactions-connection.js +171 -0
- package/dist/hooks/interactions-connection.js.map +1 -0
- package/dist/hooks/interactions-stream.d.ts +80 -0
- package/dist/hooks/interactions-stream.d.ts.map +1 -0
- package/dist/hooks/interactions-stream.js +233 -0
- package/dist/hooks/interactions-stream.js.map +1 -0
- package/dist/hooks/useApi.d.ts +2409 -2293
- package/dist/hooks/useApi.d.ts.map +1 -1
- package/dist/hooks/useSse.d.ts +3 -6
- package/dist/hooks/useSse.d.ts.map +1 -1
- package/dist/hooks/useSse.js +38 -451
- package/dist/hooks/useSse.js.map +1 -1
- package/dist/navigation/app-link.d.ts +25 -0
- package/dist/navigation/app-link.d.ts.map +1 -0
- package/dist/navigation/app-link.js +33 -0
- package/dist/navigation/app-link.js.map +1 -0
- package/dist/navigation/context.d.ts +3 -20
- package/dist/navigation/context.d.ts.map +1 -1
- package/dist/navigation/context.js +7 -267
- package/dist/navigation/context.js.map +1 -1
- package/dist/navigation/entry-state.d.ts +23 -0
- package/dist/navigation/entry-state.d.ts.map +1 -0
- package/dist/navigation/entry-state.js +39 -0
- package/dist/navigation/entry-state.js.map +1 -0
- package/dist/navigation/guard-registry.d.ts +30 -0
- package/dist/navigation/guard-registry.d.ts.map +1 -0
- package/dist/navigation/guard-registry.js +46 -0
- package/dist/navigation/guard-registry.js.map +1 -0
- package/dist/navigation/guarded-navigation.d.ts +24 -0
- package/dist/navigation/guarded-navigation.d.ts.map +1 -0
- package/dist/navigation/guarded-navigation.js +102 -0
- package/dist/navigation/guarded-navigation.js.map +1 -0
- package/dist/navigation/index.d.ts +3 -2
- package/dist/navigation/index.d.ts.map +1 -1
- package/dist/navigation/index.js +2 -1
- package/dist/navigation/index.js.map +1 -1
- package/dist/navigation/types.d.ts +8 -11
- package/dist/navigation/types.d.ts.map +1 -1
- package/dist/navigation/use-back-forward-guard.d.ts +5 -0
- package/dist/navigation/use-back-forward-guard.d.ts.map +1 -0
- package/dist/navigation/use-back-forward-guard.js +82 -0
- package/dist/navigation/use-back-forward-guard.js.map +1 -0
- package/dist/plugin/registry.d.ts +6 -15
- package/dist/plugin/registry.d.ts.map +1 -1
- package/dist/plugin/registry.js +83 -75
- package/dist/plugin/registry.js.map +1 -1
- package/dist/schema-editor/SchemaEditor.d.ts +8 -1
- package/dist/schema-editor/SchemaEditor.d.ts.map +1 -1
- package/dist/schema-editor/SchemaEditor.js +2 -2
- package/dist/schema-editor/SchemaEditor.js.map +1 -1
- package/dist/schema-form/SecretRefField.d.ts +2 -3
- package/dist/schema-form/SecretRefField.d.ts.map +1 -1
- package/dist/schema-form/SecretRefField.js +23 -12
- package/dist/schema-form/SecretRefField.js.map +1 -1
- package/dist/schema-form/classify.d.ts +1 -122
- package/dist/schema-form/classify.d.ts.map +1 -1
- package/dist/schema-form/classify.js +174 -237
- package/dist/schema-form/classify.js.map +1 -1
- package/dist/schema-form/default-value.d.ts.map +1 -1
- package/dist/schema-form/default-value.js +42 -19
- package/dist/schema-form/default-value.js.map +1 -1
- package/dist/schema-form/enum-field.d.ts +1 -1
- package/dist/schema-form/enum-field.d.ts.map +1 -1
- package/dist/schema-form/field-model.d.ts +121 -0
- package/dist/schema-form/field-model.d.ts.map +1 -0
- package/dist/schema-form/field-model.js +2 -0
- package/dist/schema-form/field-model.js.map +1 -0
- package/dist/schema-form/field-node.d.ts.map +1 -1
- package/dist/schema-form/field-node.js +25 -14
- package/dist/schema-form/field-node.js.map +1 -1
- package/dist/schema-form/media-field.d.ts +1 -1
- package/dist/schema-form/media-field.d.ts.map +1 -1
- package/dist/schema-form/media-field.js +47 -28
- package/dist/schema-form/media-field.js.map +1 -1
- package/dist/schema-form/string-annotations.d.ts +20 -0
- package/dist/schema-form/string-annotations.d.ts.map +1 -0
- package/dist/schema-form/string-annotations.js +105 -0
- package/dist/schema-form/string-annotations.js.map +1 -0
- package/dist/schema-form/string-field.d.ts +1 -1
- package/dist/schema-form/string-field.d.ts.map +1 -1
- package/dist/schema-form/union-field.d.ts +1 -1
- package/dist/schema-form/union-field.d.ts.map +1 -1
- package/dist/schema-form/union-field.js.map +1 -1
- package/dist/schema-form/union.d.ts +1 -1
- package/dist/schema-form/union.d.ts.map +1 -1
- package/dist/schema-form/validate.d.ts.map +1 -1
- package/dist/schema-form/validate.js +126 -105
- package/dist/schema-form/validate.js.map +1 -1
- package/dist/state-binding/AdapterMapping.d.ts.map +1 -1
- package/dist/state-binding/AdapterMapping.js +0 -0
- package/dist/state-binding/AdapterMapping.js.map +1 -1
- package/dist/state-binding/StateAttachRow.d.ts.map +1 -1
- package/dist/state-binding/StateAttachRow.js +52 -36
- package/dist/state-binding/StateAttachRow.js.map +1 -1
- package/dist/state-binding/adapter-mapping-row.d.ts +17 -0
- package/dist/state-binding/adapter-mapping-row.d.ts.map +1 -0
- package/dist/state-binding/adapter-mapping-row.js +87 -0
- package/dist/state-binding/adapter-mapping-row.js.map +1 -0
- package/dist/structured-output/StructuredOutput.d.ts.map +1 -1
- package/dist/structured-output/StructuredOutput.js +1 -3
- package/dist/structured-output/StructuredOutput.js.map +1 -1
- package/package.json +2 -2
- package/src/components/explorer-body.tsx +239 -0
- package/src/components/explorer-page-size.ts +39 -0
- package/src/components/explorer-tag-filter.tsx +80 -0
- package/src/components/explorer-tags.ts +64 -0
- package/src/components/explorer-view.tsx +114 -366
- package/src/components/extension-combo-builder.tsx +35 -152
- package/src/components/extension-combo-parts.tsx +237 -0
- package/src/components/fleet-report.tsx +97 -54
- package/src/components/icons/chrome-marks.tsx +195 -0
- package/src/components/icons/icon-frame.tsx +50 -0
- package/src/components/icons/index.ts +84 -0
- package/src/components/icons/nav-map.ts +55 -0
- package/src/components/icons/nav-marks.tsx +205 -0
- package/src/components/icons/status-marks.tsx +46 -0
- package/src/components/icons/theme-marks.tsx +33 -0
- package/src/components/json-diff.tsx +1 -4
- package/src/components/json-tree-context.ts +26 -0
- package/src/components/json-tree-model.ts +139 -0
- package/src/components/json-tree-nodes.tsx +224 -0
- package/src/components/json-tree.tsx +15 -434
- package/src/components/json-value-format.ts +64 -0
- package/src/components/markdown-blocks.ts +198 -0
- package/src/components/markdown-inline.tsx +365 -0
- package/src/components/markdown.tsx +5 -471
- package/src/components/observer-registry.ts +139 -0
- package/src/components/overflow-measure.ts +69 -0
- package/src/components/prose-regions.ts +153 -0
- package/src/components/scroll-region.tsx +20 -360
- package/src/components/tab-stop-parse.ts +217 -0
- package/src/components/templated-text-field.tsx +38 -330
- package/src/components/templated-text-kwargs-editor.tsx +147 -0
- package/src/components/templated-text-kwargs.ts +92 -0
- package/src/components/templated-text-source.tsx +226 -0
- package/src/components/tool-picker-parts.tsx +184 -0
- package/src/components/tool-picker.tsx +22 -114
- package/src/components/version-history-panel.tsx +38 -142
- package/src/components/version-history-rows.tsx +220 -0
- package/src/guards.ts +7 -0
- package/src/hooks/interactions-connection.ts +227 -0
- package/src/hooks/interactions-stream.ts +274 -0
- package/src/hooks/useSse.ts +50 -477
- package/src/navigation/app-link.tsx +70 -0
- package/src/navigation/context.tsx +11 -330
- package/src/navigation/entry-state.ts +42 -0
- package/src/navigation/guard-registry.ts +65 -0
- package/src/navigation/guarded-navigation.ts +147 -0
- package/src/navigation/index.ts +2 -2
- package/src/navigation/types.ts +8 -11
- package/src/navigation/use-back-forward-guard.ts +90 -0
- package/src/plugin/registry.ts +111 -90
- package/src/schema-editor/SchemaEditor.tsx +9 -1
- package/src/schema-form/SecretRefField.tsx +121 -71
- package/src/schema-form/classify.ts +244 -395
- package/src/schema-form/default-value.ts +48 -17
- package/src/schema-form/enum-field.tsx +1 -1
- package/src/schema-form/field-model.ts +133 -0
- package/src/schema-form/field-node.tsx +94 -38
- package/src/schema-form/media-field.tsx +134 -65
- package/src/schema-form/string-annotations.ts +111 -0
- package/src/schema-form/string-field.tsx +1 -1
- package/src/schema-form/union-field.tsx +2 -1
- package/src/schema-form/union.ts +1 -1
- package/src/schema-form/validate.ts +184 -103
- package/src/state-binding/AdapterMapping.tsx +0 -0
- package/src/state-binding/StateAttachRow.tsx +222 -147
- package/src/state-binding/adapter-mapping-row.tsx +232 -0
- package/src/structured-output/StructuredOutput.tsx +1 -4
- package/dist/components/icons.d.ts +0 -160
- package/dist/components/icons.d.ts.map +0 -1
- package/dist/components/icons.js +0 -160
- package/dist/components/icons.js.map +0 -1
- package/src/components/icons.tsx +0 -586
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* shapeless one is edited as the JSON it is rather than dead-ending on a badge.
|
|
9
9
|
*/
|
|
10
10
|
import { isNullSchema, resolveRef, scalarLabel, typeList, unionMembers, variantLabel, variantTag, } from './resolve';
|
|
11
|
+
import { expressionAnnotation, mediaUpload } from './string-annotations';
|
|
11
12
|
function firstString(...values) {
|
|
12
13
|
for (const value of values) {
|
|
13
14
|
if (typeof value === 'string' && value.length > 0)
|
|
@@ -15,89 +16,6 @@ function firstString(...values) {
|
|
|
15
16
|
}
|
|
16
17
|
return undefined;
|
|
17
18
|
}
|
|
18
|
-
/**
|
|
19
|
-
* Detect the media-upload annotations on a (ref-resolved) string schema. A field
|
|
20
|
-
* opts into the upload control when it carries `contentEncoding: "base64"` plus a
|
|
21
|
-
* `contentMediaType`, OR `format: "data-url"`. Anything else is a plain string.
|
|
22
|
-
*/
|
|
23
|
-
function mediaUpload(schema) {
|
|
24
|
-
const mediaType = typeof schema.contentMediaType === 'string' ? schema.contentMediaType : undefined;
|
|
25
|
-
const maxBytes = typeof schema.contentMaxBytes === 'number' && schema.contentMaxBytes > 0
|
|
26
|
-
? schema.contentMaxBytes
|
|
27
|
-
: undefined;
|
|
28
|
-
if (schema.format === 'data-url') {
|
|
29
|
-
return { encoding: 'data-url', mediaType, maxBytes };
|
|
30
|
-
}
|
|
31
|
-
if (schema.contentEncoding === 'base64' && mediaType !== undefined) {
|
|
32
|
-
return { encoding: 'base64', mediaType, maxBytes };
|
|
33
|
-
}
|
|
34
|
-
return undefined;
|
|
35
|
-
}
|
|
36
|
-
const EXPRESSION_KEYWORD = 'x-tai42-expression';
|
|
37
|
-
/** A parsed-JSON plain object (arrays and `null` are `typeof 'object'` too). */
|
|
38
|
-
function isRecord(value) {
|
|
39
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Detect the `x-tai42-expression` annotation on a (ref-resolved) string schema,
|
|
43
|
-
* mirroring {@link mediaUpload}: a well-formed annotation opts the field into the
|
|
44
|
-
* jq expression editor; anything else — absent, non-object, unknown language, or
|
|
45
|
-
* any wrongly-typed member — yields `undefined`, so the field renders EXACTLY as
|
|
46
|
-
* the plain string input it is today. Malformed payloads NEVER throw: a bad
|
|
47
|
-
* annotation is a server-side authoring bug, and degrading to the ordinary text
|
|
48
|
-
* box keeps the form usable while staying byte-identical to the unannotated
|
|
49
|
-
* rendering.
|
|
50
|
-
*/
|
|
51
|
-
function expressionAnnotation(schema) {
|
|
52
|
-
const raw = schema[EXPRESSION_KEYWORD];
|
|
53
|
-
if (!isRecord(raw))
|
|
54
|
-
return undefined;
|
|
55
|
-
// The language gate doubles as the forward-compatibility valve: a future
|
|
56
|
-
// language this client does not understand degrades to a plain string field.
|
|
57
|
-
if (raw.language !== 'jq')
|
|
58
|
-
return undefined;
|
|
59
|
-
const { label, blurb, returns } = raw;
|
|
60
|
-
if (label !== undefined && typeof label !== 'string')
|
|
61
|
-
return undefined;
|
|
62
|
-
if (blurb !== undefined && typeof blurb !== 'string')
|
|
63
|
-
return undefined;
|
|
64
|
-
if (returns !== undefined && typeof returns !== 'string')
|
|
65
|
-
return undefined;
|
|
66
|
-
let keys;
|
|
67
|
-
if (raw.keys !== undefined) {
|
|
68
|
-
if (!Array.isArray(raw.keys))
|
|
69
|
-
return undefined;
|
|
70
|
-
keys = [];
|
|
71
|
-
for (const entry of raw.keys) {
|
|
72
|
-
if (!isRecord(entry) || typeof entry.name !== 'string' || typeof entry.gloss !== 'string') {
|
|
73
|
-
return undefined;
|
|
74
|
-
}
|
|
75
|
-
keys.push({ name: entry.name, gloss: entry.gloss });
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
let caveats;
|
|
79
|
-
if (raw.caveats !== undefined) {
|
|
80
|
-
if (!Array.isArray(raw.caveats))
|
|
81
|
-
return undefined;
|
|
82
|
-
caveats = [];
|
|
83
|
-
for (const entry of raw.caveats) {
|
|
84
|
-
if (typeof entry !== 'string')
|
|
85
|
-
return undefined;
|
|
86
|
-
caveats.push(entry);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
// `sample` is any JSON — including `null` — so presence is tracked, not typed.
|
|
90
|
-
return {
|
|
91
|
-
language: 'jq',
|
|
92
|
-
label,
|
|
93
|
-
blurb,
|
|
94
|
-
keys,
|
|
95
|
-
returns,
|
|
96
|
-
caveats,
|
|
97
|
-
hasSample: 'sample' in raw,
|
|
98
|
-
sample: raw.sample,
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
19
|
/**
|
|
102
20
|
* Land a shape the form has no structured editor for on the free-form JSON
|
|
103
21
|
* fallback (a mono JSON textarea) rather than a dead badge — a field is never
|
|
@@ -108,111 +26,167 @@ function expressionAnnotation(schema) {
|
|
|
108
26
|
function jsonFallback(schema, jsonType, reason, title, description, nullable = false) {
|
|
109
27
|
return { model: { kind: 'json', jsonType, reason }, nullable, schema, title, description };
|
|
110
28
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
29
|
+
// const pins a single value. Null-acceptance is fully decidable here: the one
|
|
30
|
+
// permitted value either IS null or it is not. Without this, a `const: null`
|
|
31
|
+
// field would seed to null and then fail the validator's upstream "must not be
|
|
32
|
+
// null" gate before the equality check ever ran — permanently invalid.
|
|
33
|
+
function classifyConst(resolved, title, description) {
|
|
34
|
+
return {
|
|
35
|
+
model: { kind: 'const', value: resolved.const },
|
|
36
|
+
nullable: resolved.const === null,
|
|
37
|
+
schema: resolved,
|
|
38
|
+
title,
|
|
39
|
+
description,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
// enum → a fixed choice list.
|
|
43
|
+
function classifyEnum(resolved, title, description) {
|
|
44
|
+
const enumValues = resolved.enum ?? [];
|
|
45
|
+
const options = enumValues.map((value) => ({ value, label: scalarLabel(value) }));
|
|
46
|
+
const nullable = enumValues.some((value) => value === null);
|
|
47
|
+
return { model: { kind: 'enum', options }, nullable, schema: resolved, title, description };
|
|
48
|
+
}
|
|
49
|
+
// anyOf/oneOf union normalization.
|
|
50
|
+
function classifyUnion(resolved, members, root, title, description) {
|
|
51
|
+
const nonNull = members.filter((member) => !isNullSchema(resolveRef(member, root)));
|
|
52
|
+
const nullable = nonNull.length !== members.length;
|
|
53
|
+
const soleNonNull = nonNull[0];
|
|
54
|
+
if (soleNonNull === undefined) {
|
|
55
|
+
// Every member is `null` — degenerate, but `null` is still valid, so edit
|
|
56
|
+
// it as JSON (nullable) rather than dead-ending on a badge.
|
|
57
|
+
return jsonFallback(resolved, 'any', 'union with no non-null members', title, description, true);
|
|
132
58
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
const options = resolved.enum.map((value) => ({
|
|
136
|
-
value,
|
|
137
|
-
label: scalarLabel(value),
|
|
138
|
-
}));
|
|
139
|
-
const nullable = resolved.enum.some((value) => value === null);
|
|
140
|
-
return { model: { kind: 'enum', options }, nullable, schema: resolved, title, description };
|
|
59
|
+
if (nonNull.length === 1) {
|
|
60
|
+
return classifySoleUnionMember(soleNonNull, resolved, root, nullable, title, description);
|
|
141
61
|
}
|
|
142
|
-
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
model,
|
|
171
|
-
nullable: nullable || inner.nullable,
|
|
172
|
-
schema: inner.schema,
|
|
173
|
-
title: title ?? inner.title,
|
|
174
|
-
description: description ?? inner.description,
|
|
175
|
-
};
|
|
62
|
+
const discriminator = resolved.discriminator?.propertyName;
|
|
63
|
+
const variants = nonNull.map((member, index) => {
|
|
64
|
+
const tag = discriminator === undefined ? undefined : variantTag(member, discriminator, root);
|
|
65
|
+
return { label: variantLabel(member, index, tag, root), tag, schema: member };
|
|
66
|
+
});
|
|
67
|
+
return {
|
|
68
|
+
model: { kind: 'union', variants, discriminator },
|
|
69
|
+
nullable,
|
|
70
|
+
schema: resolved,
|
|
71
|
+
title,
|
|
72
|
+
description,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
// A null-union of exactly one non-null member: delegate to that member.
|
|
76
|
+
function classifySoleUnionMember(soleNonNull, resolved, root, nullable, title, description) {
|
|
77
|
+
const inner = classifySchema(soleNonNull, root);
|
|
78
|
+
// Media annotations (`contentEncoding`/`contentMediaType`/`format: data-url`)
|
|
79
|
+
// that land on the OUTER null-union wrapper of an OPTIONAL field would
|
|
80
|
+
// otherwise be lost when delegating to the inner string member, silently
|
|
81
|
+
// degrading an optional upload field to a plain text box. Re-detect them on
|
|
82
|
+
// the wrapper and attach to the inner string model. The expression
|
|
83
|
+
// annotation gets the same treatment for the same reason: an optional
|
|
84
|
+
// annotated field must keep its editor door.
|
|
85
|
+
const model = inner.model.kind === 'string'
|
|
86
|
+
? {
|
|
87
|
+
...inner.model,
|
|
88
|
+
media: inner.model.media ?? mediaUpload(resolved),
|
|
89
|
+
expression: inner.model.expression ?? expressionAnnotation(resolved),
|
|
176
90
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
91
|
+
: inner.model;
|
|
92
|
+
return {
|
|
93
|
+
model,
|
|
94
|
+
nullable: nullable || inner.nullable,
|
|
95
|
+
schema: inner.schema,
|
|
96
|
+
title: title ?? inner.title,
|
|
97
|
+
description: description ?? inner.description,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
// allOf: Pydantic wraps a single $ref this way; a multi-member intersection is
|
|
101
|
+
// not a form-renderable construct.
|
|
102
|
+
function classifyAllOf(resolved, root, title, description) {
|
|
103
|
+
const allOf = resolved.allOf ?? [];
|
|
104
|
+
const soleAllOf = allOf[0];
|
|
105
|
+
if (allOf.length === 1 && soleAllOf !== undefined) {
|
|
106
|
+
const inner = classifySchema(soleAllOf, root);
|
|
182
107
|
return {
|
|
183
|
-
model:
|
|
184
|
-
nullable,
|
|
185
|
-
schema:
|
|
186
|
-
title,
|
|
187
|
-
description,
|
|
108
|
+
model: inner.model,
|
|
109
|
+
nullable: inner.nullable,
|
|
110
|
+
schema: inner.schema,
|
|
111
|
+
title: title ?? inner.title,
|
|
112
|
+
description: description ?? inner.description,
|
|
188
113
|
};
|
|
189
114
|
}
|
|
190
|
-
//
|
|
191
|
-
//
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
115
|
+
// Whether the intersection accepts `null` is not statically decidable here
|
|
116
|
+
// (it does iff EVERY member does), and the json escape hatch only enforces
|
|
117
|
+
// what it KNOWS — so stay permissive like `jsonType: 'any'` itself and let
|
|
118
|
+
// the server-side contract be the authority, rather than rejecting a null
|
|
119
|
+
// the schema may well permit (e.g. an intersection of open schemas).
|
|
120
|
+
return jsonFallback(resolved, 'any', 'allOf intersection of multiple schemas', title, description, true);
|
|
121
|
+
}
|
|
122
|
+
function classifyString(resolved, title, description, nullable) {
|
|
123
|
+
return {
|
|
124
|
+
model: {
|
|
125
|
+
kind: 'string',
|
|
126
|
+
format: resolved.format,
|
|
127
|
+
media: mediaUpload(resolved),
|
|
128
|
+
expression: expressionAnnotation(resolved),
|
|
129
|
+
},
|
|
130
|
+
nullable,
|
|
131
|
+
schema: resolved,
|
|
132
|
+
title,
|
|
133
|
+
description,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
function classifyArray(resolved, title, description, nullable) {
|
|
137
|
+
if (resolved.items === undefined) {
|
|
138
|
+
// A bare array with no item schema: no per-item editor to build, but the
|
|
139
|
+
// value is still a JSON array — edit it whole as free-form JSON.
|
|
140
|
+
return jsonFallback(resolved, 'array', 'array without an items schema', title, description, nullable);
|
|
141
|
+
}
|
|
142
|
+
return {
|
|
143
|
+
model: { kind: 'array', items: resolved.items },
|
|
144
|
+
nullable,
|
|
145
|
+
schema: resolved,
|
|
146
|
+
title,
|
|
147
|
+
description,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
function classifyObject(resolved, title, description, nullable) {
|
|
151
|
+
if (resolved.properties === undefined) {
|
|
152
|
+
// A free-form object typed by a VALUE SCHEMA (`additionalProperties` is a
|
|
153
|
+
// schema, not `false`/`true`/absent) is a string→X map — renderable as
|
|
154
|
+
// key/value rows. A boolean/absent `additionalProperties` carries no value
|
|
155
|
+
// type to build an entry editor from, so it falls through to the free-form
|
|
156
|
+
// JSON editor (constrained to a JSON object).
|
|
157
|
+
// Read as `unknown`: the value is parsed JSON, where `additionalProperties:
|
|
158
|
+
// null` is possible and `typeof null === 'object'` would otherwise classify
|
|
159
|
+
// it as a record with a `null` value schema.
|
|
160
|
+
const additional = resolved.additionalProperties;
|
|
161
|
+
if (typeof additional === 'object' && additional !== null) {
|
|
196
162
|
return {
|
|
197
|
-
model:
|
|
198
|
-
nullable
|
|
199
|
-
schema:
|
|
200
|
-
title
|
|
201
|
-
description
|
|
163
|
+
model: { kind: 'record', values: additional },
|
|
164
|
+
nullable,
|
|
165
|
+
schema: resolved,
|
|
166
|
+
title,
|
|
167
|
+
description,
|
|
202
168
|
};
|
|
203
169
|
}
|
|
204
|
-
|
|
205
|
-
// (it does iff EVERY member does), and the json escape hatch only enforces
|
|
206
|
-
// what it KNOWS — so stay permissive like `jsonType: 'any'` itself and let
|
|
207
|
-
// the server-side contract be the authority, rather than rejecting a null
|
|
208
|
-
// the schema may well permit (e.g. an intersection of open schemas).
|
|
209
|
-
return jsonFallback(resolved, 'any', 'allOf intersection of multiple schemas', title, description, true);
|
|
170
|
+
return jsonFallback(resolved, 'object', 'free-form object with no property schema', title, description, nullable);
|
|
210
171
|
}
|
|
211
|
-
|
|
172
|
+
const properties = Object.entries(resolved.properties);
|
|
173
|
+
const required = new Set(resolved.required ?? []);
|
|
174
|
+
return {
|
|
175
|
+
model: { kind: 'object', properties, required },
|
|
176
|
+
nullable,
|
|
177
|
+
schema: resolved,
|
|
178
|
+
title,
|
|
179
|
+
description,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
// Type-driven classification: a single non-null JSON type maps to its structured
|
|
183
|
+
// editor; no type, several types, or an unrecognized one lands on the JSON fallback.
|
|
184
|
+
function classifyByType(resolved, title, description) {
|
|
212
185
|
const types = typeList(resolved);
|
|
213
186
|
const nonNullTypes = types.filter((type) => type !== 'null');
|
|
214
187
|
const nullableByType = nonNullTypes.length !== types.length;
|
|
215
|
-
|
|
188
|
+
const type = nonNullTypes[0];
|
|
189
|
+
if (nonNullTypes.length === 0 || type === undefined) {
|
|
216
190
|
// No `type` at all (an open `{}` schema, or `type: "null"` alone) accepts any
|
|
217
191
|
// JSON — the classic "any" field. Edit it as free-form JSON. Nullable is
|
|
218
192
|
// always true here: `type: "null"` declares it, and an open schema with no
|
|
@@ -223,24 +197,9 @@ export function classifySchema(raw, root) {
|
|
|
223
197
|
if (nonNullTypes.length > 1) {
|
|
224
198
|
return jsonFallback(resolved, 'any', `multiple JSON types (${nonNullTypes.join(', ')}) without a discriminator`, title, description, nullableByType);
|
|
225
199
|
}
|
|
226
|
-
const type = nonNullTypes[0];
|
|
227
|
-
if (type === undefined) {
|
|
228
|
-
return jsonFallback(resolved, 'any', 'schema declares no renderable type', title, description, nullableByType);
|
|
229
|
-
}
|
|
230
200
|
switch (type) {
|
|
231
201
|
case 'string':
|
|
232
|
-
return
|
|
233
|
-
model: {
|
|
234
|
-
kind: 'string',
|
|
235
|
-
format: resolved.format,
|
|
236
|
-
media: mediaUpload(resolved),
|
|
237
|
-
expression: expressionAnnotation(resolved),
|
|
238
|
-
},
|
|
239
|
-
nullable: nullableByType,
|
|
240
|
-
schema: resolved,
|
|
241
|
-
title,
|
|
242
|
-
description,
|
|
243
|
-
};
|
|
202
|
+
return classifyString(resolved, title, description, nullableByType);
|
|
244
203
|
case 'number':
|
|
245
204
|
return {
|
|
246
205
|
model: { kind: 'number', integer: false },
|
|
@@ -265,54 +224,32 @@ export function classifySchema(raw, root) {
|
|
|
265
224
|
title,
|
|
266
225
|
description,
|
|
267
226
|
};
|
|
268
|
-
case 'array':
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
return jsonFallback(resolved, 'array', 'array without an items schema', title, description, nullableByType);
|
|
273
|
-
}
|
|
274
|
-
return {
|
|
275
|
-
model: { kind: 'array', items: resolved.items },
|
|
276
|
-
nullable: nullableByType,
|
|
277
|
-
schema: resolved,
|
|
278
|
-
title,
|
|
279
|
-
description,
|
|
280
|
-
};
|
|
281
|
-
}
|
|
282
|
-
case 'object': {
|
|
283
|
-
if (resolved.properties === undefined) {
|
|
284
|
-
// A free-form object typed by a VALUE SCHEMA (`additionalProperties` is a
|
|
285
|
-
// schema, not `false`/`true`/absent) is a string→X map — renderable as
|
|
286
|
-
// key/value rows. A boolean/absent `additionalProperties` carries no value
|
|
287
|
-
// type to build an entry editor from, so it falls through to the free-form
|
|
288
|
-
// JSON editor (constrained to a JSON object).
|
|
289
|
-
// Read as `unknown`: the value is parsed JSON, where `additionalProperties:
|
|
290
|
-
// null` is possible and `typeof null === 'object'` would otherwise classify
|
|
291
|
-
// it as a record with a `null` value schema.
|
|
292
|
-
const additional = resolved.additionalProperties;
|
|
293
|
-
if (typeof additional === 'object' && additional !== null) {
|
|
294
|
-
return {
|
|
295
|
-
model: { kind: 'record', values: additional },
|
|
296
|
-
nullable: nullableByType,
|
|
297
|
-
schema: resolved,
|
|
298
|
-
title,
|
|
299
|
-
description,
|
|
300
|
-
};
|
|
301
|
-
}
|
|
302
|
-
return jsonFallback(resolved, 'object', 'free-form object with no property schema', title, description, nullableByType);
|
|
303
|
-
}
|
|
304
|
-
const properties = Object.entries(resolved.properties);
|
|
305
|
-
const required = new Set(resolved.required ?? []);
|
|
306
|
-
return {
|
|
307
|
-
model: { kind: 'object', properties, required },
|
|
308
|
-
nullable: nullableByType,
|
|
309
|
-
schema: resolved,
|
|
310
|
-
title,
|
|
311
|
-
description,
|
|
312
|
-
};
|
|
313
|
-
}
|
|
227
|
+
case 'array':
|
|
228
|
+
return classifyArray(resolved, title, description, nullableByType);
|
|
229
|
+
case 'object':
|
|
230
|
+
return classifyObject(resolved, title, description, nullableByType);
|
|
314
231
|
default:
|
|
315
232
|
return jsonFallback(resolved, 'any', `unrecognized type "${String(type)}"`, title, description, nullableByType);
|
|
316
233
|
}
|
|
317
234
|
}
|
|
235
|
+
/**
|
|
236
|
+
* Classify a schema node (resolving `$ref` first). `wrapper` metadata (a
|
|
237
|
+
* ref-site title/description) is threaded down so a `{ $ref, title }` or a
|
|
238
|
+
* null-union wrapper keeps its property-level label.
|
|
239
|
+
*/
|
|
240
|
+
export function classifySchema(raw, root) {
|
|
241
|
+
const resolved = resolveRef(raw, root);
|
|
242
|
+
const title = firstString(raw.title, resolved.title);
|
|
243
|
+
const description = firstString(raw.description, resolved.description);
|
|
244
|
+
if ('const' in resolved)
|
|
245
|
+
return classifyConst(resolved, title, description);
|
|
246
|
+
if (resolved.enum !== undefined)
|
|
247
|
+
return classifyEnum(resolved, title, description);
|
|
248
|
+
const members = unionMembers(resolved);
|
|
249
|
+
if (members !== undefined)
|
|
250
|
+
return classifyUnion(resolved, members, root, title, description);
|
|
251
|
+
if (resolved.allOf !== undefined)
|
|
252
|
+
return classifyAllOf(resolved, root, title, description);
|
|
253
|
+
return classifyByType(resolved, title, description);
|
|
254
|
+
}
|
|
318
255
|
//# sourceMappingURL=classify.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"classify.js","sourceRoot":"","sources":["../../src/schema-form/classify.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EACL,YAAY,EACZ,UAAU,EACV,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,UAAU,GAEX,MAAM,WAAW,CAAC;
|
|
1
|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,GAAG,WAAW,CAAC,GAAG,CAAC,WAAW,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;IAEvE,IAAI,OAAO,IAAI,QAAQ;QAAE,OAAO,aAAa,CAAC,QAAQ,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC;IAC5E,IAAI,QAAQ,CAAC,IAAI,KAAK,SAAS;QAAE,OAAO,YAAY,CAAC,QAAQ,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC;IACnF,MAAM,OAAO,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC;IACvC,IAAI,OAAO,KAAK,SAAS;QAAE,OAAO,aAAa,CAAC,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC;IAC7F,IAAI,QAAQ,CAAC,KAAK,KAAK,SAAS;QAAE,OAAO,aAAa,CAAC,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC;IAC3F,OAAO,cAAc,CAAC,QAAQ,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC;AACtD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default-value.d.ts","sourceRoot":"","sources":["../../src/schema-form/default-value.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"default-value.d.ts","sourceRoot":"","sources":["../../src/schema-form/default-value.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAc1C;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,GAAE,UAAmB,GAAG,OAAO,CAE5F;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,GAAE,UAAmB,GAAG,OAAO,CAE7F"}
|
|
@@ -46,6 +46,45 @@ export function defaultValueForSchema(schema, root = schema) {
|
|
|
46
46
|
export function skeletonValueForSchema(schema, root = schema) {
|
|
47
47
|
return seedValue(schema, root, true);
|
|
48
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Seed an object's required nested structure and any optional property that
|
|
51
|
+
* carries an explicit default. A required property recurses; an optional one is
|
|
52
|
+
* materialized only when it declares a `default`, so its own required children
|
|
53
|
+
* never raise errors on a field the user did not opt into.
|
|
54
|
+
*/
|
|
55
|
+
function seedObject(model, root, mintScalars) {
|
|
56
|
+
const result = {};
|
|
57
|
+
for (const [name, propSchema] of model.properties) {
|
|
58
|
+
if (model.required.has(name)) {
|
|
59
|
+
const seeded = seedValue(propSchema, root, mintScalars);
|
|
60
|
+
if (seeded !== undefined)
|
|
61
|
+
result[name] = seeded;
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
const propClassified = classifySchema(propSchema, root);
|
|
65
|
+
const propDefault = explicitDefault(propSchema, propClassified.schema);
|
|
66
|
+
if (propDefault.present)
|
|
67
|
+
result[name] = propDefault.value;
|
|
68
|
+
}
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The empty value a required scalar mints in a committed skeleton: strings `''`,
|
|
73
|
+
* numbers `0`, booleans `false`. Absent (left value-less) on the default path,
|
|
74
|
+
* where a fresh form should flag the missing required scalar instead.
|
|
75
|
+
*/
|
|
76
|
+
function seedScalar(kind, mintScalars) {
|
|
77
|
+
if (!mintScalars)
|
|
78
|
+
return undefined;
|
|
79
|
+
switch (kind) {
|
|
80
|
+
case 'string':
|
|
81
|
+
return '';
|
|
82
|
+
case 'number':
|
|
83
|
+
return 0;
|
|
84
|
+
case 'boolean':
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
49
88
|
/**
|
|
50
89
|
* The shared seeding walk. `mintScalars` distinguishes the two entry points
|
|
51
90
|
* above: `false` leaves value-less required scalars absent; `true` mints their
|
|
@@ -60,32 +99,16 @@ function seedValue(schema, root, mintScalars) {
|
|
|
60
99
|
switch (model.kind) {
|
|
61
100
|
case 'const':
|
|
62
101
|
return model.value;
|
|
63
|
-
case 'object':
|
|
64
|
-
|
|
65
|
-
for (const [name, propSchema] of model.properties) {
|
|
66
|
-
if (model.required.has(name)) {
|
|
67
|
-
const seeded = seedValue(propSchema, root, mintScalars);
|
|
68
|
-
if (seeded !== undefined)
|
|
69
|
-
result[name] = seeded;
|
|
70
|
-
continue;
|
|
71
|
-
}
|
|
72
|
-
const propClassified = classifySchema(propSchema, root);
|
|
73
|
-
const propDefault = explicitDefault(propSchema, propClassified.schema);
|
|
74
|
-
if (propDefault.present)
|
|
75
|
-
result[name] = propDefault.value;
|
|
76
|
-
}
|
|
77
|
-
return result;
|
|
78
|
-
}
|
|
102
|
+
case 'object':
|
|
103
|
+
return seedObject(model, root, mintScalars);
|
|
79
104
|
case 'array':
|
|
80
105
|
return [];
|
|
81
106
|
case 'record':
|
|
82
107
|
return {};
|
|
83
108
|
case 'string':
|
|
84
|
-
return mintScalars ? '' : undefined;
|
|
85
109
|
case 'number':
|
|
86
|
-
return mintScalars ? 0 : undefined;
|
|
87
110
|
case 'boolean':
|
|
88
|
-
return mintScalars
|
|
111
|
+
return seedScalar(model.kind, mintScalars);
|
|
89
112
|
case 'enum':
|
|
90
113
|
case 'union':
|
|
91
114
|
case 'json':
|