@lushly-dev/fast-element 3.0.1-preview.0 → 3.0.1-preview.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/CHANGELOG.md +12 -0
- package/dist/command/command.api.json +7857 -0
- package/dist/context/context.api.json +1084 -0
- package/dist/declarative/declarative.api.json +8130 -0
- package/dist/definition-schema/definition-schema.api.json +2689 -0
- package/dist/di/di.api.json +4945 -0
- package/dist/dts/arrays.d.ts +2 -0
- package/dist/dts/binding/binding.d.ts +59 -0
- package/dist/dts/binding/exports.d.ts +9 -0
- package/dist/dts/binding/normalize.d.ts +9 -0
- package/dist/dts/binding/one-time.d.ts +11 -0
- package/dist/dts/binding/one-way.d.ts +20 -0
- package/dist/dts/binding/signal.d.ts +36 -0
- package/dist/dts/binding/two-way.d.ts +44 -0
- package/dist/dts/command/behavior.d.ts +94 -0
- package/dist/dts/command/behaviors/confirm-behavior.d.ts +139 -0
- package/dist/dts/command/behaviors/undo-behavior.d.ts +178 -0
- package/dist/dts/command/command.d.ts +79 -0
- package/dist/dts/command/component-registry.d.ts +50 -0
- package/dist/dts/command/components/confirm-dialog.d.ts +117 -0
- package/dist/dts/command/index.d.ts +21 -0
- package/dist/dts/command/registry.d.ts +201 -0
- package/dist/dts/command/schema-validation.d.ts +45 -0
- package/dist/dts/command/types.d.ts +332 -0
- package/dist/dts/command/validation.d.ts +116 -0
- package/dist/dts/command/weak-ref.d.ts +11 -0
- package/dist/dts/components/attributes.d.ts +153 -0
- package/dist/dts/components/definition-schema-transforms.d.ts +9 -0
- package/dist/dts/components/element-controller.d.ts +349 -0
- package/dist/dts/components/element-hydration.d.ts +2 -0
- package/dist/dts/components/enable-hydration.d.ts +66 -0
- package/dist/dts/components/fast-definitions.d.ts +211 -0
- package/dist/dts/components/fast-element-registry.d.ts +23 -0
- package/dist/dts/components/fast-element.d.ts +91 -0
- package/dist/dts/components/hydration-tracker.d.ts +110 -0
- package/dist/dts/components/hydration.d.ts +52 -0
- package/dist/dts/components/schema.d.ts +205 -0
- package/dist/dts/context.d.ts +171 -0
- package/dist/dts/debug.d.ts +5 -0
- package/dist/dts/declarative/attribute-map.d.ts +58 -0
- package/dist/dts/declarative/debug.d.ts +4 -0
- package/dist/dts/declarative/index.d.ts +14 -0
- package/dist/dts/declarative/interfaces.d.ts +8 -0
- package/dist/dts/declarative/observer-map-utilities.d.ts +58 -0
- package/dist/dts/declarative/observer-map.d.ts +89 -0
- package/dist/dts/declarative/runtime.d.ts +5 -0
- package/dist/dts/declarative/syntax.d.ts +21 -0
- package/dist/dts/declarative/template-bridge.d.ts +33 -0
- package/dist/dts/declarative/template-parser.d.ts +98 -0
- package/dist/dts/declarative/template.d.ts +9 -0
- package/dist/dts/declarative/utilities.d.ts +358 -0
- package/dist/dts/definition-schema/api.d.ts +42 -0
- package/dist/dts/definition-schema/cem.d.ts +78 -0
- package/dist/dts/definition-schema/extension.d.ts +18 -0
- package/dist/dts/definition-schema/extract.d.ts +38 -0
- package/dist/dts/definition-schema/index.d.ts +9 -0
- package/dist/dts/definition-schema/storage.d.ts +35 -0
- package/dist/dts/definition-schema/types.d.ts +176 -0
- package/dist/dts/dev-mode.d.ts +13 -0
- package/dist/dts/di/di.d.ts +894 -0
- package/dist/dts/dom-policy.d.ts +101 -0
- package/dist/dts/dom.d.ts +88 -0
- package/dist/dts/hydration/diagnostics.d.ts +93 -0
- package/dist/dts/hydration/exports.d.ts +18 -0
- package/dist/dts/hydration/hydration-debugger.d.ts +35 -0
- package/dist/dts/hydration/messages.d.ts +62 -0
- package/dist/dts/hydration/runtime.d.ts +7 -0
- package/dist/dts/hydration/target-builder.d.ts +107 -0
- package/dist/dts/index.d.ts +51 -0
- package/dist/dts/index.debug.d.ts +1 -0
- package/dist/dts/index.rollup.d.ts +1 -0
- package/dist/dts/index.rollup.debug.d.ts +1 -0
- package/dist/dts/interfaces.d.ts +106 -0
- package/dist/dts/metadata.d.ts +26 -0
- package/dist/dts/observation/arrays.d.ts +248 -0
- package/dist/dts/observation/notifier.d.ts +127 -0
- package/dist/dts/observation/observable.d.ts +276 -0
- package/dist/dts/observation/update-queue.d.ts +40 -0
- package/dist/dts/observation/volatile.d.ts +9 -0
- package/dist/dts/platform.d.ts +87 -0
- package/dist/dts/registry.d.ts +2 -0
- package/dist/dts/render.d.ts +7 -0
- package/dist/dts/schema.d.ts +1 -0
- package/dist/dts/scoped/detection.d.ts +55 -0
- package/dist/dts/scoped/index.d.ts +68 -0
- package/dist/dts/scoped/mixin.d.ts +118 -0
- package/dist/dts/scoped/registry.d.ts +76 -0
- package/dist/dts/scoped/types.d.ts +48 -0
- package/dist/dts/state/exports.d.ts +3 -0
- package/dist/dts/state/reactive.d.ts +8 -0
- package/dist/dts/state/state.d.ts +141 -0
- package/dist/dts/state/visitor.d.ts +6 -0
- package/dist/dts/state/watch.d.ts +10 -0
- package/dist/dts/styles/css-directive.d.ts +50 -0
- package/dist/dts/styles/css.d.ts +34 -0
- package/dist/dts/styles/element-styles.d.ts +61 -0
- package/dist/dts/styles/host.d.ts +65 -0
- package/dist/dts/styles/style-strategy.d.ts +42 -0
- package/dist/dts/templating/children.d.ts +62 -0
- package/dist/dts/templating/compiler.d.ts +54 -0
- package/dist/dts/templating/html-binding-directive.d.ts +155 -0
- package/dist/dts/templating/html-directive.d.ts +218 -0
- package/dist/dts/templating/html.d.ts +1 -0
- package/dist/dts/templating/hydration-view.d.ts +130 -0
- package/dist/dts/templating/markup.d.ts +48 -0
- package/dist/dts/templating/node-observation.d.ts +99 -0
- package/dist/dts/templating/ref.d.ts +23 -0
- package/dist/dts/templating/render.d.ts +318 -0
- package/dist/dts/templating/repeat.d.ts +131 -0
- package/dist/dts/templating/slotted.d.ts +38 -0
- package/dist/dts/templating/template.d.ts +221 -0
- package/dist/dts/templating/view.d.ts +268 -0
- package/dist/dts/templating/when.d.ts +12 -0
- package/dist/dts/testing/exports.d.ts +3 -0
- package/dist/dts/testing/fakes.d.ts +16 -0
- package/dist/dts/testing/fixture.d.ts +84 -0
- package/dist/dts/testing/models.d.ts +20 -0
- package/dist/dts/testing/timeout.d.ts +7 -0
- package/dist/dts/trust/index.d.ts +8 -0
- package/dist/dts/trust/types.d.ts +48 -0
- package/dist/dts/trust/utils.d.ts +26 -0
- package/dist/dts/tsdoc-metadata.json +11 -0
- package/dist/dts/utilities.d.ts +76 -0
- package/dist/esm/arrays.js +1 -0
- package/dist/esm/binding/binding.js +18 -0
- package/dist/esm/binding/exports.js +6 -0
- package/dist/esm/binding/normalize.js +17 -0
- package/dist/esm/binding/one-time.js +21 -0
- package/dist/esm/binding/one-way.js +30 -0
- package/dist/esm/binding/signal.js +99 -0
- package/dist/esm/binding/two-way.js +109 -0
- package/dist/esm/command/behavior.js +155 -0
- package/dist/esm/command/behaviors/confirm-behavior.js +225 -0
- package/dist/esm/command/behaviors/undo-behavior.js +313 -0
- package/dist/esm/command/command.js +104 -0
- package/dist/esm/command/component-registry.js +107 -0
- package/dist/esm/command/components/confirm-dialog.js +370 -0
- package/dist/esm/command/index.js +22 -0
- package/dist/esm/command/registry.js +755 -0
- package/dist/esm/command/schema-validation.js +194 -0
- package/dist/esm/command/types.js +86 -0
- package/dist/esm/command/validation.js +508 -0
- package/dist/esm/command/weak-ref.js +5 -0
- package/dist/esm/components/attributes.js +219 -0
- package/dist/esm/components/definition-schema-transforms.js +23 -0
- package/dist/esm/components/element-controller.js +840 -0
- package/dist/esm/components/element-hydration.js +2 -0
- package/dist/esm/components/enable-hydration.js +123 -0
- package/dist/esm/components/fast-definitions.js +294 -0
- package/dist/esm/components/fast-element-registry.js +67 -0
- package/dist/esm/components/fast-element.js +82 -0
- package/dist/esm/components/hydration-tracker.js +211 -0
- package/dist/esm/components/hydration.js +187 -0
- package/dist/esm/components/schema.js +253 -0
- package/dist/esm/context.js +185 -0
- package/dist/esm/debug.js +71 -0
- package/dist/esm/declarative/attribute-map.js +122 -0
- package/dist/esm/declarative/debug.js +4 -0
- package/dist/esm/declarative/index.js +10 -0
- package/dist/esm/declarative/interfaces.js +9 -0
- package/dist/esm/declarative/observer-map-utilities.js +565 -0
- package/dist/esm/declarative/observer-map.js +216 -0
- package/dist/esm/declarative/runtime.js +14 -0
- package/dist/esm/declarative/syntax.js +36 -0
- package/dist/esm/declarative/template-bridge.js +160 -0
- package/dist/esm/declarative/template-parser.js +306 -0
- package/dist/esm/declarative/template.js +116 -0
- package/dist/esm/declarative/utilities.js +1069 -0
- package/dist/esm/definition-schema/api.js +129 -0
- package/dist/esm/definition-schema/cem.js +89 -0
- package/dist/esm/definition-schema/extension.js +53 -0
- package/dist/esm/definition-schema/extract.js +167 -0
- package/dist/esm/definition-schema/index.js +8 -0
- package/dist/esm/definition-schema/storage.js +58 -0
- package/dist/esm/definition-schema/types.js +8 -0
- package/dist/esm/dev-mode.js +22 -0
- package/dist/esm/di/di.js +1441 -0
- package/dist/esm/dom-policy.js +374 -0
- package/dist/esm/dom.js +101 -0
- package/dist/esm/hydration/diagnostics.js +50 -0
- package/dist/esm/hydration/exports.js +6 -0
- package/dist/esm/hydration/hydration-debugger.js +112 -0
- package/dist/esm/hydration/messages.js +84 -0
- package/dist/esm/hydration/runtime.js +33 -0
- package/dist/esm/hydration/target-builder.js +264 -0
- package/dist/esm/index.debug.js +3 -0
- package/dist/esm/index.js +49 -0
- package/dist/esm/index.rollup.debug.js +6 -0
- package/dist/esm/index.rollup.js +4 -0
- package/dist/esm/interfaces.js +55 -0
- package/dist/esm/metadata.js +57 -0
- package/dist/esm/observation/arrays.js +661 -0
- package/dist/esm/observation/notifier.js +162 -0
- package/dist/esm/observation/observable.js +324 -0
- package/dist/esm/observation/update-queue.js +56 -0
- package/dist/esm/observation/volatile.js +16 -0
- package/dist/esm/platform.js +98 -0
- package/dist/esm/registry.js +2 -0
- package/dist/esm/render.js +1 -0
- package/dist/esm/schema.js +1 -0
- package/dist/esm/scoped/detection.js +102 -0
- package/dist/esm/scoped/index.js +69 -0
- package/dist/esm/scoped/mixin.js +127 -0
- package/dist/esm/scoped/registry.js +125 -0
- package/dist/esm/scoped/types.js +4 -0
- package/dist/esm/state/exports.js +3 -0
- package/dist/esm/state/reactive.js +34 -0
- package/dist/esm/state/state.js +148 -0
- package/dist/esm/state/visitor.js +28 -0
- package/dist/esm/state/watch.js +36 -0
- package/dist/esm/styles/css-directive.js +36 -0
- package/dist/esm/styles/css.js +56 -0
- package/dist/esm/styles/element-styles.js +144 -0
- package/dist/esm/styles/host.js +1 -0
- package/dist/esm/styles/style-strategy.js +1 -0
- package/dist/esm/templating/children.js +67 -0
- package/dist/esm/templating/compiler.js +359 -0
- package/dist/esm/templating/html-binding-directive.js +288 -0
- package/dist/esm/templating/html-directive.js +113 -0
- package/dist/esm/templating/html.js +1 -0
- package/dist/esm/templating/hydration-view.js +228 -0
- package/dist/esm/templating/markup.js +83 -0
- package/dist/esm/templating/node-observation.js +84 -0
- package/dist/esm/templating/ref.js +21 -0
- package/dist/esm/templating/render.js +468 -0
- package/dist/esm/templating/repeat.js +434 -0
- package/dist/esm/templating/slotted.js +49 -0
- package/dist/esm/templating/template.js +206 -0
- package/dist/esm/templating/view.js +298 -0
- package/dist/esm/templating/when.js +22 -0
- package/dist/esm/testing/exports.js +3 -0
- package/dist/esm/testing/fakes.js +107 -0
- package/dist/esm/testing/fixture.js +86 -0
- package/dist/esm/testing/models.js +58 -0
- package/dist/esm/testing/timeout.js +24 -0
- package/dist/esm/trust/index.js +7 -0
- package/dist/esm/trust/types.js +6 -0
- package/dist/esm/trust/utils.js +126 -0
- package/dist/esm/utilities.js +140 -0
- package/dist/fast-element.api.json +26798 -0
- package/dist/fast-element.d.ts +3985 -0
- package/dist/fast-element.debug.js +7604 -0
- package/dist/fast-element.debug.min.js +3 -0
- package/dist/fast-element.js +7603 -0
- package/dist/fast-element.min.js +3 -0
- package/dist/fast-element.untrimmed.d.ts +4103 -0
- package/dist/observation/arrays/arrays.api.json +2621 -0
- package/dist/scoped/scoped.api.json +891 -0
- package/dist/trust/trust.api.json +629 -0
- package/package.json +21 -23
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A small, dependency-free JSON Schema validator for command `parameters`.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Deliberately limited to the keywords agents and command palettes actually
|
|
6
|
+
* rely on: `type`, `enum`, `const`, `required`, `properties`,
|
|
7
|
+
* `additionalProperties`, `items`, `minimum`/`maximum` (plus the numeric
|
|
8
|
+
* exclusive forms), `minLength`/`maxLength` and `minItems`/`maxItems`.
|
|
9
|
+
* Unknown keywords (including `pattern`, `$ref`, `oneOf`, ...) are ignored, so a
|
|
10
|
+
* schema that uses them is validated on a best-effort basis rather than rejected.
|
|
11
|
+
*
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
const MAX_ISSUES = 20;
|
|
15
|
+
const hasOwn = (target, key) => Object.prototype.hasOwnProperty.call(target, key);
|
|
16
|
+
function typeOf(value) {
|
|
17
|
+
if (value === null)
|
|
18
|
+
return "null";
|
|
19
|
+
if (Array.isArray(value))
|
|
20
|
+
return "array";
|
|
21
|
+
if (typeof value === "number")
|
|
22
|
+
return Number.isInteger(value) ? "integer" : "number";
|
|
23
|
+
return typeof value;
|
|
24
|
+
}
|
|
25
|
+
function matchesType(value, type) {
|
|
26
|
+
switch (type) {
|
|
27
|
+
case "string":
|
|
28
|
+
case "boolean":
|
|
29
|
+
case "undefined":
|
|
30
|
+
return typeof value === type;
|
|
31
|
+
case "number":
|
|
32
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
33
|
+
case "integer":
|
|
34
|
+
return typeof value === "number" && Number.isInteger(value);
|
|
35
|
+
case "null":
|
|
36
|
+
return value === null;
|
|
37
|
+
case "array":
|
|
38
|
+
return Array.isArray(value);
|
|
39
|
+
case "object":
|
|
40
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
41
|
+
default:
|
|
42
|
+
// Unknown type names are not enforced.
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function deepEqual(a, b) {
|
|
47
|
+
if (a === b)
|
|
48
|
+
return true;
|
|
49
|
+
if (typeof a !== "object" || typeof b !== "object" || a === null || b === null) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
if (Array.isArray(a) !== Array.isArray(b))
|
|
53
|
+
return false;
|
|
54
|
+
const aKeys = Object.keys(a);
|
|
55
|
+
if (aKeys.length !== Object.keys(b).length)
|
|
56
|
+
return false;
|
|
57
|
+
return aKeys.every(key => hasOwn(b, key) &&
|
|
58
|
+
deepEqual(a[key], b[key]));
|
|
59
|
+
}
|
|
60
|
+
function validateInto(issues, value, schema, path) {
|
|
61
|
+
if (issues.length >= MAX_ISSUES)
|
|
62
|
+
return;
|
|
63
|
+
const report = (at, message) => {
|
|
64
|
+
if (issues.length < MAX_ISSUES)
|
|
65
|
+
issues.push({ path: at, message });
|
|
66
|
+
};
|
|
67
|
+
const add = (message) => report(path, message);
|
|
68
|
+
const type = schema.type;
|
|
69
|
+
if (type !== void 0) {
|
|
70
|
+
const types = Array.isArray(type) ? type : [type];
|
|
71
|
+
if (!types.some(t => matchesType(value, t))) {
|
|
72
|
+
add(`expected ${types.join(" or ")} but received ${typeOf(value)}`);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (Array.isArray(schema.enum) && !schema.enum.some(v => deepEqual(v, value))) {
|
|
77
|
+
add(`must be one of ${JSON.stringify(schema.enum)}`);
|
|
78
|
+
}
|
|
79
|
+
if (hasOwn(schema, "const") && !deepEqual(schema.const, value)) {
|
|
80
|
+
add(`must equal ${JSON.stringify(schema.const)}`);
|
|
81
|
+
}
|
|
82
|
+
if (typeof value === "number") {
|
|
83
|
+
const { minimum, maximum, exclusiveMinimum, exclusiveMaximum } = schema;
|
|
84
|
+
if (typeof minimum === "number" && value < minimum) {
|
|
85
|
+
add(`must be >= ${minimum}`);
|
|
86
|
+
}
|
|
87
|
+
if (typeof maximum === "number" && value > maximum) {
|
|
88
|
+
add(`must be <= ${maximum}`);
|
|
89
|
+
}
|
|
90
|
+
if (typeof exclusiveMinimum === "number" && value <= exclusiveMinimum) {
|
|
91
|
+
add(`must be > ${exclusiveMinimum}`);
|
|
92
|
+
}
|
|
93
|
+
if (typeof exclusiveMaximum === "number" && value >= exclusiveMaximum) {
|
|
94
|
+
add(`must be < ${exclusiveMaximum}`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (typeof value === "string") {
|
|
98
|
+
if (typeof schema.minLength === "number" && value.length < schema.minLength) {
|
|
99
|
+
add(`must be at least ${schema.minLength} character(s)`);
|
|
100
|
+
}
|
|
101
|
+
if (typeof schema.maxLength === "number" && value.length > schema.maxLength) {
|
|
102
|
+
add(`must be at most ${schema.maxLength} character(s)`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (Array.isArray(value)) {
|
|
106
|
+
if (typeof schema.minItems === "number" && value.length < schema.minItems) {
|
|
107
|
+
add(`must contain at least ${schema.minItems} item(s)`);
|
|
108
|
+
}
|
|
109
|
+
if (typeof schema.maxItems === "number" && value.length > schema.maxItems) {
|
|
110
|
+
add(`must contain at most ${schema.maxItems} item(s)`);
|
|
111
|
+
}
|
|
112
|
+
const items = schema.items;
|
|
113
|
+
if (items !== null && typeof items === "object" && !Array.isArray(items)) {
|
|
114
|
+
for (let i = 0; i < value.length && issues.length < MAX_ISSUES; i++) {
|
|
115
|
+
validateInto(issues, value[i], items, `${path}[${i}]`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
|
|
120
|
+
const record = value;
|
|
121
|
+
const properties = schema.properties !== null && typeof schema.properties === "object"
|
|
122
|
+
? schema.properties
|
|
123
|
+
: {};
|
|
124
|
+
if (Array.isArray(schema.required)) {
|
|
125
|
+
for (const key of schema.required) {
|
|
126
|
+
if (!hasOwn(record, key) || record[key] === void 0) {
|
|
127
|
+
report(`${path}.${key}`, "is required");
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
for (const key of Object.keys(properties)) {
|
|
132
|
+
const propertySchema = properties[key];
|
|
133
|
+
if (hasOwn(record, key) &&
|
|
134
|
+
record[key] !== void 0 &&
|
|
135
|
+
propertySchema !== null &&
|
|
136
|
+
typeof propertySchema === "object") {
|
|
137
|
+
validateInto(issues, record[key], propertySchema, `${path}.${key}`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
const additional = schema.additionalProperties;
|
|
141
|
+
if (additional === false) {
|
|
142
|
+
for (const key of Object.keys(record)) {
|
|
143
|
+
if (!hasOwn(properties, key)) {
|
|
144
|
+
report(`${path}.${key}`, "is not an allowed property");
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
else if (additional !== null && typeof additional === "object") {
|
|
149
|
+
for (const key of Object.keys(record)) {
|
|
150
|
+
if (!hasOwn(properties, key)) {
|
|
151
|
+
validateInto(issues, record[key], additional, `${path}.${key}`);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Validates a value against a (basic) JSON Schema.
|
|
159
|
+
* @param value - The value to validate.
|
|
160
|
+
* @param schema - The JSON Schema.
|
|
161
|
+
* @returns The list of problems; empty when the value is valid.
|
|
162
|
+
* @internal
|
|
163
|
+
*/
|
|
164
|
+
export function validateSchema(value, schema) {
|
|
165
|
+
const issues = [];
|
|
166
|
+
validateInto(issues, value, schema, "$");
|
|
167
|
+
return issues;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Validates the arguments of a command invocation against the command's
|
|
171
|
+
* `parameters` schema.
|
|
172
|
+
*
|
|
173
|
+
* @remarks
|
|
174
|
+
* Command arguments are positional (`execute(...args)`), but the `parameters`
|
|
175
|
+
* schema describes a single structured argument, which is how every built-in
|
|
176
|
+
* command (and agent tool call) consumes input. The schema is therefore applied to
|
|
177
|
+
* `args[0]`. When no argument is supplied and the schema describes an object,
|
|
178
|
+
* an empty object is validated so `required` still fires.
|
|
179
|
+
*
|
|
180
|
+
* @internal
|
|
181
|
+
*/
|
|
182
|
+
export function validateCommandArguments(args, schema) {
|
|
183
|
+
let value = args[0];
|
|
184
|
+
if (value === void 0) {
|
|
185
|
+
const describesObject = schema.type === "object" ||
|
|
186
|
+
schema.properties !== void 0 ||
|
|
187
|
+
schema.required !== void 0;
|
|
188
|
+
if (!describesObject) {
|
|
189
|
+
return [{ path: "$", message: "a value is required" }];
|
|
190
|
+
}
|
|
191
|
+
value = {};
|
|
192
|
+
}
|
|
193
|
+
return validateSchema(value, schema);
|
|
194
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for the `command` decorator system.
|
|
3
|
+
* Enables AI agents to interact with FASTElement components through structured commands.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* This module contains types only - no runtime code.
|
|
7
|
+
* Re-exports AFD core types for ecosystem alignment.
|
|
8
|
+
* FAST-AF is an "agent runtime for Web Components".
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Standard error codes for command failures.
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
export const ErrorCodes = {
|
|
15
|
+
/** Command ID not found in registry */
|
|
16
|
+
COMMAND_NOT_FOUND: "COMMAND_NOT_FOUND",
|
|
17
|
+
/** Command is currently disabled */
|
|
18
|
+
COMMAND_DISABLED: "COMMAND_DISABLED",
|
|
19
|
+
/** Command is not exposed to the interface that invoked it */
|
|
20
|
+
COMMAND_NOT_EXPOSED: "COMMAND_NOT_EXPOSED",
|
|
21
|
+
/** Invalid parameters provided */
|
|
22
|
+
INVALID_PARAMETERS: "INVALID_PARAMETERS",
|
|
23
|
+
/** Destructive command requires confirmation but no confirmation handler is installed */
|
|
24
|
+
CONFIRMATION_REQUIRED: "CONFIRMATION_REQUIRED",
|
|
25
|
+
/** Command execution failed */
|
|
26
|
+
EXECUTION_FAILED: "EXECUTION_FAILED",
|
|
27
|
+
/** Operation timed out */
|
|
28
|
+
TIMEOUT: "TIMEOUT",
|
|
29
|
+
/** Generic internal error */
|
|
30
|
+
INTERNAL_ERROR: "INTERNAL_ERROR",
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Create a successful command result.
|
|
34
|
+
* @param data - The result data
|
|
35
|
+
* @param metadata - Optional metadata
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
38
|
+
export function success(data, metadata) {
|
|
39
|
+
return { success: true, data, metadata };
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Create a failed command result.
|
|
43
|
+
* @param error - The error information
|
|
44
|
+
* @param metadata - Optional metadata
|
|
45
|
+
* @public
|
|
46
|
+
*/
|
|
47
|
+
export function failure(error, metadata) {
|
|
48
|
+
return { success: false, error, metadata };
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Type guard for successful results.
|
|
52
|
+
* @param result - The result to check
|
|
53
|
+
* @public
|
|
54
|
+
*/
|
|
55
|
+
export function isSuccess(result) {
|
|
56
|
+
return result.success === true;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Type guard for failed results.
|
|
60
|
+
* @param result - The result to check
|
|
61
|
+
* @public
|
|
62
|
+
*/
|
|
63
|
+
export function isFailure(result) {
|
|
64
|
+
return result.success === false;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Create a CommandError object.
|
|
68
|
+
* @param code - Error code
|
|
69
|
+
* @param message - Error message
|
|
70
|
+
* @param options - Additional error options
|
|
71
|
+
* @public
|
|
72
|
+
*/
|
|
73
|
+
export function createError(code, message, options) {
|
|
74
|
+
return Object.assign({ code, message }, options);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Default expose configuration.
|
|
78
|
+
* Secure defaults: palette and agent are enabled, mcp and cli require opt-in.
|
|
79
|
+
* @public
|
|
80
|
+
*/
|
|
81
|
+
export const DEFAULT_EXPOSE_CONFIG = {
|
|
82
|
+
palette: true,
|
|
83
|
+
agent: true,
|
|
84
|
+
mcp: false,
|
|
85
|
+
cli: false,
|
|
86
|
+
};
|