simpler-forms 0.1.0-alpha.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +300 -76
- package/dist/src/casing.d.ts +43 -0
- package/dist/src/casing.js +146 -0
- package/dist/src/casing.js.map +1 -0
- package/dist/src/decorators/index.d.ts +1 -0
- package/dist/src/decorators/index.js +1 -0
- package/dist/src/decorators/index.js.map +1 -1
- package/dist/src/decorators/mapping.d.ts +17 -0
- package/dist/src/decorators/mapping.js +122 -0
- package/dist/src/decorators/mapping.js.map +1 -0
- package/dist/src/decorators/meta.d.ts +15 -5
- package/dist/src/decorators/meta.js +31 -4
- package/dist/src/decorators/meta.js.map +1 -1
- package/dist/src/decorators/shared.d.ts +2 -2
- package/dist/src/decorators/shared.js.map +1 -1
- package/dist/src/decorators/ui.d.ts +14 -12
- package/dist/src/decorators/ui.js +20 -43
- package/dist/src/decorators/ui.js.map +1 -1
- package/dist/src/emitter.d.ts +8 -0
- package/dist/src/emitter.js +55 -16
- package/dist/src/emitter.js.map +1 -1
- package/dist/src/emitters/block-ui.d.ts +14 -3
- package/dist/src/emitters/block-ui.js +81 -119
- package/dist/src/emitters/block-ui.js.map +1 -1
- package/dist/src/emitters/layout-ui.d.ts +12 -0
- package/dist/src/emitters/layout-ui.js +225 -0
- package/dist/src/emitters/layout-ui.js.map +1 -0
- package/dist/src/emitters/overlay.d.ts +10 -8
- package/dist/src/emitters/overlay.js +30 -105
- package/dist/src/emitters/overlay.js.map +1 -1
- package/dist/src/forms.d.ts +23 -0
- package/dist/src/forms.js +54 -0
- package/dist/src/forms.js.map +1 -0
- package/dist/src/index.d.ts +22 -8
- package/dist/src/index.js +17 -3
- package/dist/src/index.js.map +1 -1
- package/dist/src/layout.d.ts +50 -0
- package/dist/src/layout.js +397 -0
- package/dist/src/layout.js.map +1 -0
- package/dist/src/lib.d.ts +585 -39
- package/dist/src/lib.js +258 -15
- package/dist/src/lib.js.map +1 -1
- package/dist/src/linter.js +8 -43
- package/dist/src/linter.js.map +1 -1
- package/dist/src/mapping-from.d.ts +21 -0
- package/dist/src/mapping-from.js +169 -0
- package/dist/src/mapping-from.js.map +1 -0
- package/dist/src/mapping.d.ts +65 -0
- package/dist/src/mapping.js +209 -0
- package/dist/src/mapping.js.map +1 -0
- package/dist/src/model.d.ts +143 -23
- package/dist/src/model.js +108 -21
- package/dist/src/model.js.map +1 -1
- package/dist/src/public.d.ts +20 -4
- package/dist/src/public.js +28 -4
- package/dist/src/public.js.map +1 -1
- package/dist/src/validate.d.ts +2 -1
- package/dist/src/validate.js +208 -58
- package/dist/src/validate.js.map +1 -1
- package/lib/main.tsp +1 -0
- package/lib/mapping.tsp +173 -0
- package/lib/meta.tsp +25 -6
- package/lib/types.tsp +24 -63
- package/lib/ui.tsp +34 -17
- package/package.json +17 -11
- package/src/casing.ts +172 -0
- package/src/decorators/index.ts +1 -0
- package/src/decorators/mapping.ts +200 -0
- package/src/decorators/meta.ts +56 -13
- package/src/decorators/shared.ts +6 -1
- package/src/decorators/ui.ts +43 -59
- package/src/emitter.ts +76 -16
- package/src/emitters/block-ui.ts +83 -135
- package/src/emitters/layout-ui.ts +280 -0
- package/src/emitters/overlay.ts +43 -116
- package/src/forms.ts +82 -0
- package/src/index.ts +17 -3
- package/src/layout.ts +592 -0
- package/src/lib.ts +264 -15
- package/src/linter.ts +17 -49
- package/src/mapping-from.ts +216 -0
- package/src/mapping.ts +358 -0
- package/src/model.ts +287 -46
- package/src/public.ts +60 -6
- package/src/validate.ts +221 -60
- package/dist/src/emitters/override-condition.d.ts +0 -12
- package/dist/src/emitters/override-condition.js +0 -25
- package/dist/src/emitters/override-condition.js.map +0 -1
- package/src/emitters/override-condition.ts +0 -37
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { getNamespaceFullName, } from "@typespec/compiler";
|
|
2
|
+
import { reportDiagnostic, stateKeys } from "../lib.js";
|
|
3
|
+
import { enumName, push, set } from "./shared.js";
|
|
4
|
+
export const $targets = (ctx, target, targets) => set(ctx, stateKeys.mappingTargets, target, targets);
|
|
5
|
+
export const $transforms = (ctx, target, transforms) => set(ctx, stateKeys.mappingTransformSets, target, transforms);
|
|
6
|
+
export const $transform = (ctx, target, transform, params) => set(ctx, stateKeys.mappingTransform, target, {
|
|
7
|
+
member: transform,
|
|
8
|
+
...(params ? { params } : {}),
|
|
9
|
+
});
|
|
10
|
+
/**
|
|
11
|
+
* Accumulated rather than overwritten: one model or property carries a link per mapping.
|
|
12
|
+
* Two links for the same mapping are reported by `$onValidate`, not here, so the check sees
|
|
13
|
+
* every decorator before it decides which one is the duplicate.
|
|
14
|
+
*/
|
|
15
|
+
export const $to = (ctx, target, mapping, mappedTo) => push(ctx, stateKeys.mappedTo, target, {
|
|
16
|
+
mapping,
|
|
17
|
+
mappedTo,
|
|
18
|
+
});
|
|
19
|
+
export const $path = (ctx, target, mapping, sourcePath, mappedTo) => push(ctx, stateKeys.mappingPaths, target, {
|
|
20
|
+
mapping,
|
|
21
|
+
sourcePath,
|
|
22
|
+
mappedTo,
|
|
23
|
+
});
|
|
24
|
+
export const $match = (ctx, target, cases, fallback) => set(ctx, stateKeys.mappingMatch, target, {
|
|
25
|
+
cases: Object.fromEntries(Object.entries(cases).map(([key, value]) => [key, literal(value)])),
|
|
26
|
+
...(fallback === undefined
|
|
27
|
+
? {}
|
|
28
|
+
: {
|
|
29
|
+
default: isField(fallback)
|
|
30
|
+
? { field: fallback }
|
|
31
|
+
: { value: literal(fallback) },
|
|
32
|
+
}),
|
|
33
|
+
});
|
|
34
|
+
/** A `valueof numeric` arrives as TypeSpec's arbitrary-precision `Numeric`: as a JS number. */
|
|
35
|
+
const literal = (value) => typeof value === "object" && value !== null && "asNumber" in value
|
|
36
|
+
? (value.asNumber() ?? Number.NaN)
|
|
37
|
+
: value;
|
|
38
|
+
export const $required = (ctx, target) => ctx.program.stateSet(stateKeys.mappingRequired).add(target);
|
|
39
|
+
export const $when = (ctx, target, source, operator, value) => {
|
|
40
|
+
const name = enumName(operator);
|
|
41
|
+
const picked = source.kind === "ModelProperty" ? { source } : selection(source);
|
|
42
|
+
if (!picked) {
|
|
43
|
+
reportDiagnostic(ctx.program, {
|
|
44
|
+
code: "mapping-when-source",
|
|
45
|
+
target: ctx.getArgumentTarget(0) ?? target,
|
|
46
|
+
format: { name: target.name },
|
|
47
|
+
});
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const given = value !== undefined;
|
|
51
|
+
const fail = name === "exists"
|
|
52
|
+
? given && "exists"
|
|
53
|
+
: name === "in"
|
|
54
|
+
? !Array.isArray(value) && "in"
|
|
55
|
+
: !given && "default";
|
|
56
|
+
if (fail) {
|
|
57
|
+
reportDiagnostic(ctx.program, {
|
|
58
|
+
code: "mapping-when-value",
|
|
59
|
+
messageId: fail,
|
|
60
|
+
target: ctx.getArgumentTarget(given ? 2 : 1) ?? target,
|
|
61
|
+
format: { name: target.name, source: picked.source.name, operator: name },
|
|
62
|
+
});
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
push(ctx, stateKeys.mappingWhen, target, {
|
|
66
|
+
...picked,
|
|
67
|
+
operator: name,
|
|
68
|
+
...(given ? { value: plainValue(value) } : {}),
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
/** A condition's value as plain JSON: lists entry by entry, numbers as JS numbers, enum members as their value. */
|
|
72
|
+
function plainValue(value) {
|
|
73
|
+
if (Array.isArray(value))
|
|
74
|
+
return value.map(plainValue);
|
|
75
|
+
if (typeof value === "object" && value !== null) {
|
|
76
|
+
const v = value;
|
|
77
|
+
if (v.kind === "EnumMember")
|
|
78
|
+
return v.value ?? v.name;
|
|
79
|
+
if ("asNumber" in value)
|
|
80
|
+
return literal(value);
|
|
81
|
+
}
|
|
82
|
+
return value;
|
|
83
|
+
}
|
|
84
|
+
const isField = (value) => typeof value === "object" &&
|
|
85
|
+
value !== null &&
|
|
86
|
+
value.kind === "ModelProperty";
|
|
87
|
+
/** A source named with `Mapping.Item` or `Mapping.Slice` is stored as its field and selection. */
|
|
88
|
+
export const $from = (ctx, target, mapping, source) => push(ctx, stateKeys.mappedFrom, target, {
|
|
89
|
+
mapping,
|
|
90
|
+
...(selection(source) ?? { source }),
|
|
91
|
+
});
|
|
92
|
+
/** The field and selection `Mapping.Item<…>` or `Mapping.Slice<…>` names, or undefined for any other source. */
|
|
93
|
+
function selection(source) {
|
|
94
|
+
if (source.kind !== "Model" || !source.templateMapper || !source.namespace)
|
|
95
|
+
return undefined;
|
|
96
|
+
if (getNamespaceFullName(source.namespace) !== "SimplerForms.Mapping")
|
|
97
|
+
return undefined;
|
|
98
|
+
const [field, ...bounds] = source.templateMapper.args;
|
|
99
|
+
if (field?.entityKind !== "Type" || field.kind !== "ModelProperty")
|
|
100
|
+
return undefined;
|
|
101
|
+
const [first, second] = bounds.map(numberOf);
|
|
102
|
+
if (source.name === "Item" && first !== undefined)
|
|
103
|
+
return { source: field, select: { index: first } };
|
|
104
|
+
if (source.name === "Slice" && first !== undefined)
|
|
105
|
+
return {
|
|
106
|
+
source: field,
|
|
107
|
+
select: second === undefined
|
|
108
|
+
? { start: first }
|
|
109
|
+
: { start: first, stop: second },
|
|
110
|
+
};
|
|
111
|
+
return undefined;
|
|
112
|
+
}
|
|
113
|
+
/** The number a template's `valueof int32` argument holds, or undefined (as for `null`). */
|
|
114
|
+
function numberOf(arg) {
|
|
115
|
+
const entity = arg;
|
|
116
|
+
if (entity.entityKind === "Value" && entity.valueKind === "NumericValue")
|
|
117
|
+
return entity.value?.asNumber() ?? undefined;
|
|
118
|
+
if (entity.type?.kind === "Number")
|
|
119
|
+
return entity.type.value;
|
|
120
|
+
return undefined;
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=mapping.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapping.js","sourceRoot":"","sources":["../../../src/decorators/mapping.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,GAMrB,MAA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O,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -1,22 +1,32 @@
|
|
|
1
|
-
import type { Model, ModelProperty, Scalar } from "@typespec/compiler";
|
|
1
|
+
import type { Enum, EnumMember, Model, ModelProperty, Namespace, Scalar } from "@typespec/compiler";
|
|
2
2
|
import { type Ctx } from "./shared.js";
|
|
3
3
|
/**
|
|
4
4
|
* `@Meta.question`: the question's stable identity, the entity it is asked about, and
|
|
5
5
|
* its classification. Also establishes the JSON Schema `$id`, so this is what makes a
|
|
6
6
|
* model a question rather than an ordinary model.
|
|
7
|
+
*
|
|
8
|
+
* The entity is recorded as its name now and as the member itself for `$onValidate`, which
|
|
9
|
+
* checks it against the declared sets once every `@Meta.entities` has run.
|
|
10
|
+
*/
|
|
11
|
+
export declare const $question: (ctx: Ctx, target: Model | Scalar | Enum, meta: unknown) => void;
|
|
12
|
+
/** `@Meta.tags`: the tags the program catalogues its questions by. */
|
|
13
|
+
export declare const $tags: (ctx: Ctx, target: Namespace, tags: Enum) => void;
|
|
14
|
+
/** `@Meta.entities`: the entities the program's questions are asked about. */
|
|
15
|
+
export declare const $entities: (ctx: Ctx, target: Namespace, entities: Enum) => void;
|
|
16
|
+
/**
|
|
17
|
+
* `@Meta.form`: a form an applicant opens, and the data it submits. Publishes the model's
|
|
18
|
+
* JSON Schema, as `@Meta.question` does, so a form is a block.
|
|
7
19
|
*/
|
|
8
|
-
export declare const $question: (ctx: Ctx, target: Model | Scalar, meta: unknown) => void;
|
|
9
|
-
/** `@Meta.form`: the form's identity and the provenance of the paper form it mirrors. */
|
|
10
20
|
export declare const $form: (ctx: Ctx, target: Model, meta: unknown) => void;
|
|
11
21
|
/**
|
|
12
22
|
* `@Meta.tag`: catalogue markers. Unlike the entity, a tag also applies to a bare
|
|
13
23
|
* constrained scalar with no question identity, so it stays a decorator of its own
|
|
14
24
|
* rather than a field of the question meta.
|
|
15
25
|
*/
|
|
16
|
-
export declare const $tag: (ctx: Ctx, target: Model | Scalar, ...tags:
|
|
26
|
+
export declare const $tag: (ctx: Ctx, target: Model | Scalar | Enum, ...tags: EnumMember[]) => void;
|
|
17
27
|
/**
|
|
18
28
|
* `@Meta.role`: why a field exists in a response -- applicant input, calculated output,
|
|
19
29
|
* a value a platform supplies, a technical field, an attestation, or static content.
|
|
20
30
|
* Resolved by inheritance at emission, so a form can override a shared question's role.
|
|
21
31
|
*/
|
|
22
|
-
export declare const $role: (ctx: Ctx, target: Model | Scalar | ModelProperty, role: unknown) => void;
|
|
32
|
+
export declare const $role: (ctx: Ctx, target: Model | Scalar | Enum | ModelProperty, role: unknown) => void;
|
|
@@ -1,20 +1,44 @@
|
|
|
1
1
|
import { stateKeys } from "../lib.js";
|
|
2
|
-
import { enumName, plain, publishAs, set } from "./shared.js";
|
|
2
|
+
import { enumName, plain, publishAs, set, unwrap } from "./shared.js";
|
|
3
|
+
/** The name a declared enum member is emitted under: its string value, or its name. */
|
|
4
|
+
const memberName = (member) => typeof member.value === "string" ? member.value : member.name;
|
|
3
5
|
/**
|
|
4
6
|
* `@Meta.question`: the question's stable identity, the entity it is asked about, and
|
|
5
7
|
* its classification. Also establishes the JSON Schema `$id`, so this is what makes a
|
|
6
8
|
* model a question rather than an ordinary model.
|
|
9
|
+
*
|
|
10
|
+
* The entity is recorded as its name now and as the member itself for `$onValidate`, which
|
|
11
|
+
* checks it against the declared sets once every `@Meta.entities` has run.
|
|
7
12
|
*/
|
|
8
13
|
export const $question = (ctx, target, meta) => {
|
|
9
14
|
const m = plain(ctx, meta);
|
|
10
|
-
|
|
15
|
+
const entity = entityMember(meta);
|
|
16
|
+
if (entity) {
|
|
17
|
+
m.entity = memberName(entity);
|
|
18
|
+
set(ctx, stateKeys.entity, target, m.entity);
|
|
19
|
+
set(ctx, stateKeys.entityMember, target, entity);
|
|
20
|
+
}
|
|
21
|
+
else if (m.entity !== undefined) {
|
|
11
22
|
m.entity = enumName(m.entity);
|
|
23
|
+
}
|
|
12
24
|
if (m.classification !== undefined)
|
|
13
25
|
m.classification = enumName(m.classification);
|
|
14
26
|
set(ctx, stateKeys.questionMeta, target, m);
|
|
15
27
|
publishAs(ctx, target, m.id);
|
|
16
28
|
};
|
|
17
|
-
/**
|
|
29
|
+
/** The enum member a question meta's `entity` names, read before it is made plain. */
|
|
30
|
+
function entityMember(meta) {
|
|
31
|
+
const member = unwrap(meta?.entity);
|
|
32
|
+
return member?.kind === "EnumMember" ? member : undefined;
|
|
33
|
+
}
|
|
34
|
+
/** `@Meta.tags`: the tags the program catalogues its questions by. */
|
|
35
|
+
export const $tags = (ctx, target, tags) => set(ctx, stateKeys.tagSets, target, tags);
|
|
36
|
+
/** `@Meta.entities`: the entities the program's questions are asked about. */
|
|
37
|
+
export const $entities = (ctx, target, entities) => set(ctx, stateKeys.entitySets, target, entities);
|
|
38
|
+
/**
|
|
39
|
+
* `@Meta.form`: a form an applicant opens, and the data it submits. Publishes the model's
|
|
40
|
+
* JSON Schema, as `@Meta.question` does, so a form is a block.
|
|
41
|
+
*/
|
|
18
42
|
export const $form = (ctx, target, meta) => {
|
|
19
43
|
const m = plain(ctx, meta);
|
|
20
44
|
set(ctx, stateKeys.formMeta, target, m);
|
|
@@ -25,7 +49,10 @@ export const $form = (ctx, target, meta) => {
|
|
|
25
49
|
* constrained scalar with no question identity, so it stays a decorator of its own
|
|
26
50
|
* rather than a field of the question meta.
|
|
27
51
|
*/
|
|
28
|
-
export const $tag = (ctx, target, ...tags) =>
|
|
52
|
+
export const $tag = (ctx, target, ...tags) => {
|
|
53
|
+
set(ctx, stateKeys.tags, target, tags.map(memberName));
|
|
54
|
+
set(ctx, stateKeys.tagMembers, target, tags);
|
|
55
|
+
};
|
|
29
56
|
/**
|
|
30
57
|
* `@Meta.role`: why a field exists in a response -- applicant input, calculated output,
|
|
31
58
|
* a value a platform supplies, a technical field, an attestation, or static content.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"meta.js","sourceRoot":"","sources":["../../../src/decorators/meta.ts"],"names":[],"mappings":"
|
|
1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I,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC;IACvD,GAAG,CAAC,GAAG,EAAE,SAAS,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;AAC/C,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CACnB,GAAQ,EACR,MAA6C,EAC7C,IAAa,EACb,EAAE,CAAC,GAAG,CAAC,GAAG,EAAE,SAAS,CAAC,YAAY,EAAE,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DecoratorContext, Model, ModelProperty, Scalar, Type } from "@typespec/compiler";
|
|
1
|
+
import type { DecoratorContext, Enum, Model, ModelProperty, Scalar, Type } from "@typespec/compiler";
|
|
2
2
|
export type Ctx = DecoratorContext;
|
|
3
3
|
/**
|
|
4
4
|
* `valueof <Model>` arrives as a TypeSpec ObjectValue with parent back-references,
|
|
@@ -20,7 +20,7 @@ export declare const blockSchemaRef: (id: string) => string;
|
|
|
20
20
|
* Delegate to the stock JSON Schema library, which resolves this relative id
|
|
21
21
|
* against the namespace base and uses it for both `$id` and every `$ref` target.
|
|
22
22
|
*/
|
|
23
|
-
export declare function publishAs(ctx: Ctx, target: Model | Scalar, id: string): void;
|
|
23
|
+
export declare function publishAs(ctx: Ctx, target: Model | Scalar | Enum, id: string): void;
|
|
24
24
|
/** Peel one layer of TypeSpec value wrapping. */
|
|
25
25
|
export declare function unwrap(v: unknown): unknown;
|
|
26
26
|
/** An enum member argument arrives as the member; take its name. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../src/decorators/shared.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../src/decorators/shared.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,C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MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,CAAC,iBAAiB,CAAC,EAAE;SAC/C,CAAC,CAAC;QACH,KAAK,GAAG,KAAK,CAAC;IAChB,CAAC;IACD,IAAI,CAAC,KAAK;QAAE,OAAO,SAAS,CAAC;IAC7B,MAAM,MAAM,GAAG;QACb,QAAQ,EAAE,cAAuB;QACjC,UAAU,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC;QACzB,aAAa,EAAE,IAAI;QACnB,OAAO,EAAE,iBAAiB;KAC3B,CAAC;IACF,4BAA4B,CAAC,MAAM,EAAE,cAAc,CAAC,KAAK,CAAC,CAAC;IAC3D,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -1,28 +1,30 @@
|
|
|
1
|
-
import type { Enum, Model, ModelProperty, Scalar } from "@typespec/compiler";
|
|
1
|
+
import type { Enum, EnumMember, Model, ModelProperty, Namespace, Scalar } from "@typespec/compiler";
|
|
2
2
|
import { type Ctx } from "./shared.js";
|
|
3
|
-
export declare const $
|
|
3
|
+
export declare const $layout: (ctx: Ctx, target: Model, form: Model) => void;
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* Records the argument's syntax as well as the property it resolves to. A reference to a
|
|
6
|
+
* nested occurrence (`Form.payee::type.address`) resolves to the declaration, so the
|
|
7
|
+
* syntax is the only place the occurrence's path survives.
|
|
7
8
|
*/
|
|
8
|
-
export declare const $
|
|
9
|
-
export declare
|
|
10
|
-
name: string;
|
|
11
|
-
label?: string;
|
|
12
|
-
};
|
|
13
|
-
export declare const $overrides: (ctx: Ctx, target: Model | ModelProperty, patch: unknown) => void;
|
|
9
|
+
export declare const $field: (ctx: Ctx, target: ModelProperty, field: ModelProperty) => void;
|
|
10
|
+
export declare const $flatten: (ctx: Ctx, target: ModelProperty) => void;
|
|
14
11
|
/**
|
|
15
12
|
* A field label. Also delegated to `@summary`, which the JSON Schema emitter maps to
|
|
16
13
|
* `title` -- so the canonical schema carries the label without this library emitting
|
|
17
14
|
* any schema keyword itself.
|
|
18
15
|
*/
|
|
19
|
-
export declare const $label: (ctx: Ctx, target: Model | Scalar | ModelProperty, text: string) => void;
|
|
16
|
+
export declare const $label: (ctx: Ctx, target: Model | Scalar | Enum | ModelProperty, text: string) => void;
|
|
20
17
|
/**
|
|
21
18
|
* Secondary guidance shown with the field. Distinct from the doc comment, which is the
|
|
22
19
|
* question's own description: help text is what a form says *about asking it here*.
|
|
23
20
|
*/
|
|
24
21
|
export declare const $helpText: (ctx: Ctx, target: ModelProperty, text: string) => void;
|
|
25
|
-
export declare const $
|
|
22
|
+
export declare const $widgets: (ctx: Ctx, target: Namespace, widgets: Enum) => void;
|
|
23
|
+
/**
|
|
24
|
+
* Records the emitted name now and the member itself for `$onValidate`, which checks it
|
|
25
|
+
* against the declared sets once every `@UI.widgets` has run.
|
|
26
|
+
*/
|
|
27
|
+
export declare const $widget: (ctx: Ctx, target: ModelProperty | Scalar | Model, widget: EnumMember) => void;
|
|
26
28
|
export declare const $encodedCheckboxGroup: (ctx: Ctx, target: ModelProperty, contract: unknown) => void;
|
|
27
29
|
export declare const $order: (ctx: Ctx, target: Model, ...props: ModelProperty[]) => void;
|
|
28
30
|
export declare const $omit: (ctx: Ctx, target: ModelProperty) => void;
|
|
@@ -1,49 +1,18 @@
|
|
|
1
1
|
import { $summary } from "@typespec/compiler";
|
|
2
2
|
import { stateKeys } from "../lib.js";
|
|
3
|
-
import { condition, countCondition,
|
|
4
|
-
// ---
|
|
5
|
-
export const $
|
|
3
|
+
import { condition, countCondition, literal, negatedCondition, plain, push, set, } from "./shared.js";
|
|
4
|
+
// --- layouts --------------------------------------------------------------
|
|
5
|
+
export const $layout = (ctx, target, form) => set(ctx, stateKeys.layout, target, form);
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
7
|
+
* Records the argument's syntax as well as the property it resolves to. A reference to a
|
|
8
|
+
* nested occurrence (`Form.payee::type.address`) resolves to the declaration, so the
|
|
9
|
+
* syntax is the only place the occurrence's path survives.
|
|
9
10
|
*/
|
|
10
|
-
export const $
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return {
|
|
16
|
-
name: String(m.name),
|
|
17
|
-
label: m.value ? String(m.value) : undefined,
|
|
18
|
-
};
|
|
19
|
-
if (m.value?.name) {
|
|
20
|
-
return {
|
|
21
|
-
name: String(m.value.name),
|
|
22
|
-
label: m.value.value ? String(m.value.value) : undefined,
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return { name: String(v) };
|
|
27
|
-
}
|
|
28
|
-
// --- form-scoped overrides ------------------------------------------------
|
|
29
|
-
function overridePlain(value) {
|
|
30
|
-
const candidate = value;
|
|
31
|
-
if (candidate &&
|
|
32
|
-
typeof candidate === "object" &&
|
|
33
|
-
candidate.entityKind === "Value") {
|
|
34
|
-
return literal(candidate);
|
|
35
|
-
}
|
|
36
|
-
if (Array.isArray(value))
|
|
37
|
-
return value.map(overridePlain);
|
|
38
|
-
if (value && typeof value === "object") {
|
|
39
|
-
return Object.fromEntries(Object.entries(value).map(([key, nested]) => [
|
|
40
|
-
key,
|
|
41
|
-
overridePlain(nested),
|
|
42
|
-
]));
|
|
43
|
-
}
|
|
44
|
-
return value;
|
|
45
|
-
}
|
|
46
|
-
export const $overrides = (ctx, target, patch) => set(ctx, stateKeys.overrides, target, overridePlain(plain(ctx, patch)));
|
|
11
|
+
export const $field = (ctx, target, field) => set(ctx, stateKeys.layoutField, target, {
|
|
12
|
+
field,
|
|
13
|
+
node: ctx.getArgumentTarget(0),
|
|
14
|
+
});
|
|
15
|
+
export const $flatten = (ctx, target) => set(ctx, stateKeys.flatten, target, true);
|
|
47
16
|
// --- presentation ---------------------------------------------------------
|
|
48
17
|
/**
|
|
49
18
|
* A field label. Also delegated to `@summary`, which the JSON Schema emitter maps to
|
|
@@ -59,7 +28,15 @@ export const $label = (ctx, target, text) => {
|
|
|
59
28
|
* question's own description: help text is what a form says *about asking it here*.
|
|
60
29
|
*/
|
|
61
30
|
export const $helpText = (ctx, target, text) => set(ctx, stateKeys.helpText, target, text);
|
|
62
|
-
export const $
|
|
31
|
+
export const $widgets = (ctx, target, widgets) => set(ctx, stateKeys.widgets, target, widgets);
|
|
32
|
+
/**
|
|
33
|
+
* Records the emitted name now and the member itself for `$onValidate`, which checks it
|
|
34
|
+
* against the declared sets once every `@UI.widgets` has run.
|
|
35
|
+
*/
|
|
36
|
+
export const $widget = (ctx, target, widget) => {
|
|
37
|
+
set(ctx, stateKeys.widget, target, typeof widget.value === "string" ? widget.value : widget.name);
|
|
38
|
+
set(ctx, stateKeys.widgetMember, target, widget);
|
|
39
|
+
};
|
|
63
40
|
export const $encodedCheckboxGroup = (ctx, target, contract) => {
|
|
64
41
|
set(ctx, stateKeys.widget, target, "EncodedCheckboxGroup");
|
|
65
42
|
set(ctx, stateKeys.encodedCheckboxGroup, target, plain(ctx, contract));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ui.js","sourceRoot":"","sources":["../../../src/decorators/ui.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ui.js","sourceRoot":"","sources":["../../../src/decorators/ui.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAEL,SAAS,EACT,cAAc,EACd,OAAO,EACP,gBAAgB,EAChB,KAAK,EACL,IAAI,EACJ,GAAG,GACJ,MAAM,aAAa,CAAC;AAErB,6EAA6E;AAE7E,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,GAAQ,EAAE,MAAa,EAAE,IAAW,EAAE,EAAE,CAC9D,GAAG,CAAC,GAAG,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;AAE3C;;;;GAIG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,CA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EACR,MAAqB,EACrB,MAAqB,EACrB,OAAe,EACf,EAAE;IACF,MAAM,KAAK,GAAG,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAC3D,IAAI,KAAK;QAAE,IAAI,CAAC,GAAG,EAAE,SAAS,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;AAC7D,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,CACxC,GAAQ,EACR,MAAqB,EACrB,MAAqB,EACrB,OAAe,EACf,EAAE;IACF,MAAM,KAAK,GAAG,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAC3D,IAAI,CAAC,KAAK;QAAE,OAAO;IACnB,IAAI,CAAC,GAAG,EAAE,SAAS,CAAC,WAAW,EAAE,MAAM,EAAE;QACvC,QAAQ,EAAE,KAAK;QACf,UAAU,EAAE;YACV,KAAK;YACL,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,aAAa,EAAE,KAAK,EAAE;SACzE;KACF,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,GAAQ,EACR,MAAqB,EACrB,MAAqB,EACrB,MAAe,EACf,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,SAAS,CAAC,YAAY,EAAE,MAAM,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC"}
|
package/dist/src/emitter.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { EmitContext } from "@typespec/compiler";
|
|
2
|
+
import { type PropertyCasing } from "./casing.js";
|
|
2
3
|
export interface FormSpecOptions {
|
|
3
4
|
/**
|
|
4
5
|
* Optional base URI to make `$id` and `$ref` absolute. Omitted by default: where
|
|
@@ -6,6 +7,13 @@ export interface FormSpecOptions {
|
|
|
6
7
|
* its `@Meta.question.id`, not its URI.
|
|
7
8
|
*/
|
|
8
9
|
"base-uri"?: string;
|
|
10
|
+
/**
|
|
11
|
+
* How a property's TypeSpec name is written in every artifact: `preserve` (the default)
|
|
12
|
+
* keeps it, `snake` converts `firstName` to `first_name`. String paths in decorators are
|
|
13
|
+
* still written in TypeSpec names, and `@encodedName("application/json", ...)` overrides
|
|
14
|
+
* the casing for one property.
|
|
15
|
+
*/
|
|
16
|
+
"property-casing"?: PropertyCasing;
|
|
9
17
|
}
|
|
10
18
|
/**
|
|
11
19
|
* Wraps `@typespec/json-schema`: it owns every keyword derivable from the type graph,
|
package/dist/src/emitter.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { emitFile, resolvePath } from "@typespec/compiler";
|
|
2
2
|
import { $onEmit as emitJsonSchema, findBaseUri, getId, } from "@typespec/json-schema";
|
|
3
3
|
import { allBlocks } from "./model.js";
|
|
4
|
+
import { resolveForms } from "./forms.js";
|
|
4
5
|
import { reportDiagnostic } from "./lib.js";
|
|
5
6
|
import { blockSchemaRef } from "./decorators/index.js";
|
|
6
|
-
import { emitModelOverlay, emitSchemaOverlay } from "./emitters/overlay.js";
|
|
7
|
+
import { emitModelOverlay, emitSchemaOverlay, } from "./emitters/overlay.js";
|
|
7
8
|
import { emitBlockUi } from "./emitters/block-ui.js";
|
|
9
|
+
import { emitLayoutUi } from "./emitters/layout-ui.js";
|
|
10
|
+
import { resolveLayout } from "./layout.js";
|
|
8
11
|
import { emitBlockIndex } from "./emitters/block-index.js";
|
|
12
|
+
import { Casing } from "./casing.js";
|
|
9
13
|
const STAGING = ".json-schema";
|
|
10
14
|
/**
|
|
11
15
|
* Wraps `@typespec/json-schema`: it owns every keyword derivable from the type graph,
|
|
@@ -34,18 +38,30 @@ export async function $onEmit(context) {
|
|
|
34
38
|
if (doc.$id)
|
|
35
39
|
byId.set(doc.$id, doc);
|
|
36
40
|
}
|
|
41
|
+
// The staged schemas are an intermediate in TypeSpec names, not an artifact, so they must
|
|
42
|
+
// not be left beside the published ones.
|
|
43
|
+
await program.host.rm(stagingDir, { recursive: true });
|
|
37
44
|
const baseUri = context.options?.["base-uri"];
|
|
38
45
|
const write = (rel, value) => emitFile(program, {
|
|
39
46
|
path: resolvePath(outDir, rel),
|
|
40
47
|
content: JSON.stringify(value, null, 2) + "\n",
|
|
41
48
|
});
|
|
49
|
+
const casing = new Casing(program, context.options?.["property-casing"] ?? "preserve");
|
|
42
50
|
const blocks = allBlocks(program);
|
|
51
|
+
const { forms } = resolveForms(program);
|
|
43
52
|
const modelsByName = indexModels(program.getGlobalNamespaceType());
|
|
53
|
+
// A local model with a staged schema of its own is inlined into `$defs` with its overlay
|
|
54
|
+
// (see `resolveRefs`), so the overlays of models that use it don't repeat it.
|
|
55
|
+
const ownsDefinition = (model) => modelsByName.get(model.name) === model && byFile.has(`${model.name}.json`);
|
|
44
56
|
const refToDir = new Map(blocks.map((b) => [
|
|
45
57
|
blockSchemaRef(b.id),
|
|
46
58
|
b.kind === "question" ? `question-bank/${b.id}` : `forms/${b.id}`,
|
|
47
59
|
]));
|
|
48
60
|
for (const block of blocks) {
|
|
61
|
+
// A form that cannot be published, such as one with two layouts, writes nothing.
|
|
62
|
+
const form = forms.find((f) => f.model === block.model);
|
|
63
|
+
if (block.kind === "form" && !form)
|
|
64
|
+
continue;
|
|
49
65
|
const dir = refToDir.get(blockSchemaRef(block.id));
|
|
50
66
|
const stock = byId.get(resolvedSchemaId(program, block));
|
|
51
67
|
if (!stock) {
|
|
@@ -70,29 +86,47 @@ export async function $onEmit(context) {
|
|
|
70
86
|
from: dir,
|
|
71
87
|
program,
|
|
72
88
|
modelsByName,
|
|
89
|
+
ownsDefinition,
|
|
73
90
|
});
|
|
74
91
|
if (Object.keys(defs).length)
|
|
75
92
|
schema = { ...schema, $defs: defs };
|
|
76
93
|
// 4. Fold in the conditional requiredness only we can know about.
|
|
77
|
-
const overlay = emitSchemaOverlay(program, block);
|
|
94
|
+
const overlay = emitSchemaOverlay(program, block, ownsDefinition);
|
|
78
95
|
if (overlay)
|
|
79
96
|
schema = mergeSchema(schema, overlay);
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
"index.json": "generated",
|
|
91
|
-
},
|
|
92
|
-
});
|
|
97
|
+
const index = emitBlockIndex(program, block);
|
|
98
|
+
if (Array.isArray(index.fieldOccurrences))
|
|
99
|
+
index.fieldOccurrences = index.fieldOccurrences
|
|
100
|
+
.map((entry) => ({ ...entry, path: casing.pointer(entry.path) }))
|
|
101
|
+
.sort((a, b) => a.path.localeCompare(b.path));
|
|
102
|
+
if (block.kind === "question") {
|
|
103
|
+
await write(`${dir}/schema.json`, casing.json(schema));
|
|
104
|
+
await write(`${dir}/ui.json`, casing.json(emitBlockUi(program, block)));
|
|
105
|
+
await write(`${dir}/index.json`, index);
|
|
106
|
+
continue;
|
|
93
107
|
}
|
|
108
|
+
// A form's title is its own, in its manifest; its schema carries none.
|
|
109
|
+
const { title: _title, ...formSchema } = schema;
|
|
110
|
+
await write(`${dir}/schema.json`, casing.json(formSchema));
|
|
111
|
+
await write(`${dir}/ui.json`, casing.json(formUi(program, form)));
|
|
112
|
+
await write(`${dir}/index.json`, index);
|
|
113
|
+
await write(`${dir}/manifest.json`, {
|
|
114
|
+
contract: "resolved-form-package/v1",
|
|
115
|
+
form: form.meta,
|
|
116
|
+
artifacts: {
|
|
117
|
+
"schema.json": "generated",
|
|
118
|
+
"ui.json": "generated",
|
|
119
|
+
"index.json": "generated",
|
|
120
|
+
},
|
|
121
|
+
});
|
|
94
122
|
}
|
|
95
123
|
}
|
|
124
|
+
/** A form's UI: its layout's, or its own fields' presentation. */
|
|
125
|
+
function formUi(program, form) {
|
|
126
|
+
return form.layout
|
|
127
|
+
? emitLayoutUi(program, resolveLayout(program, form.layout, form.model)).ui
|
|
128
|
+
: emitBlockUi(program, form.block);
|
|
129
|
+
}
|
|
96
130
|
/**
|
|
97
131
|
* The `$id` the stock emitter actually wrote for a block.
|
|
98
132
|
*
|
|
@@ -144,7 +178,7 @@ function resolveRefs(node, ctx, seen = new Set()) {
|
|
|
144
178
|
seen.add(name);
|
|
145
179
|
const { $schema, $id, ...body } = target;
|
|
146
180
|
const overlay = ctx.modelsByName.has(name)
|
|
147
|
-
? emitModelOverlay(ctx.program, ctx.modelsByName.get(name))
|
|
181
|
+
? emitModelOverlay(ctx.program, ctx.modelsByName.get(name), ctx.ownsDefinition)
|
|
148
182
|
: undefined;
|
|
149
183
|
ctx.defs[name] = resolveRefs(overlay ? mergeSchema(body, overlay) : body, ctx, seen);
|
|
150
184
|
}
|
|
@@ -200,6 +234,11 @@ function mergeSchema(a, b) {
|
|
|
200
234
|
if (key === "allOf" && Array.isArray(out.allOf)) {
|
|
201
235
|
out.allOf = [...out.allOf, ...value];
|
|
202
236
|
}
|
|
237
|
+
else if (key === "required" && Array.isArray(out.required)) {
|
|
238
|
+
// Requiredness only adds: a model-level @Validation.requiredPaths keeps what the model
|
|
239
|
+
// already requires.
|
|
240
|
+
out.required = [...new Set([...out.required, ...value])];
|
|
241
|
+
}
|
|
203
242
|
else if (key === "properties" &&
|
|
204
243
|
isObject(out.properties) &&
|
|
205
244
|
isObject(value)) {
|