@player-tools/fluent 0.12.1--canary.241.6077

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/dist/cjs/index.cjs +2396 -0
  2. package/dist/cjs/index.cjs.map +1 -0
  3. package/dist/index.legacy-esm.js +2276 -0
  4. package/dist/index.mjs +2276 -0
  5. package/dist/index.mjs.map +1 -0
  6. package/package.json +38 -0
  7. package/src/core/base-builder/__tests__/fluent-builder-base.test.ts +2423 -0
  8. package/src/core/base-builder/__tests__/fluent-partial.test.ts +179 -0
  9. package/src/core/base-builder/__tests__/id-generator.test.ts +658 -0
  10. package/src/core/base-builder/__tests__/registry.test.ts +534 -0
  11. package/src/core/base-builder/__tests__/resolution-mixed-arrays.test.ts +319 -0
  12. package/src/core/base-builder/__tests__/resolution-pipeline.test.ts +416 -0
  13. package/src/core/base-builder/__tests__/resolution-switches.test.ts +468 -0
  14. package/src/core/base-builder/__tests__/resolution-templates.test.ts +255 -0
  15. package/src/core/base-builder/__tests__/switch.test.ts +815 -0
  16. package/src/core/base-builder/__tests__/template.test.ts +596 -0
  17. package/src/core/base-builder/__tests__/value-extraction.test.ts +200 -0
  18. package/src/core/base-builder/__tests__/value-storage.test.ts +459 -0
  19. package/src/core/base-builder/conditional/index.ts +64 -0
  20. package/src/core/base-builder/context.ts +152 -0
  21. package/src/core/base-builder/errors.ts +69 -0
  22. package/src/core/base-builder/fluent-builder-base.ts +308 -0
  23. package/src/core/base-builder/guards.ts +137 -0
  24. package/src/core/base-builder/id/generator.ts +290 -0
  25. package/src/core/base-builder/id/registry.ts +152 -0
  26. package/src/core/base-builder/index.ts +72 -0
  27. package/src/core/base-builder/resolution/path-resolver.ts +116 -0
  28. package/src/core/base-builder/resolution/pipeline.ts +103 -0
  29. package/src/core/base-builder/resolution/steps/__tests__/nested-asset-wrappers.test.ts +206 -0
  30. package/src/core/base-builder/resolution/steps/asset-id.ts +77 -0
  31. package/src/core/base-builder/resolution/steps/asset-wrappers.ts +64 -0
  32. package/src/core/base-builder/resolution/steps/builders.ts +84 -0
  33. package/src/core/base-builder/resolution/steps/mixed-arrays.ts +95 -0
  34. package/src/core/base-builder/resolution/steps/nested-asset-wrappers.ts +124 -0
  35. package/src/core/base-builder/resolution/steps/static-values.ts +35 -0
  36. package/src/core/base-builder/resolution/steps/switches.ts +71 -0
  37. package/src/core/base-builder/resolution/steps/templates.ts +40 -0
  38. package/src/core/base-builder/resolution/value-resolver.ts +333 -0
  39. package/src/core/base-builder/storage/auxiliary-storage.ts +82 -0
  40. package/src/core/base-builder/storage/value-storage.ts +282 -0
  41. package/src/core/base-builder/types.ts +266 -0
  42. package/src/core/base-builder/utils.ts +10 -0
  43. package/src/core/flow/__tests__/index.test.ts +292 -0
  44. package/src/core/flow/index.ts +118 -0
  45. package/src/core/index.ts +8 -0
  46. package/src/core/mocks/generated/action.builder.ts +92 -0
  47. package/src/core/mocks/generated/choice-item.builder.ts +120 -0
  48. package/src/core/mocks/generated/choice.builder.ts +134 -0
  49. package/src/core/mocks/generated/collection.builder.ts +93 -0
  50. package/src/core/mocks/generated/field-collection.builder.ts +86 -0
  51. package/src/core/mocks/generated/index.ts +10 -0
  52. package/src/core/mocks/generated/info.builder.ts +64 -0
  53. package/src/core/mocks/generated/input.builder.ts +63 -0
  54. package/src/core/mocks/generated/overview-collection.builder.ts +65 -0
  55. package/src/core/mocks/generated/splash-collection.builder.ts +93 -0
  56. package/src/core/mocks/generated/text.builder.ts +47 -0
  57. package/src/core/mocks/index.ts +1 -0
  58. package/src/core/mocks/types/action.ts +92 -0
  59. package/src/core/mocks/types/choice.ts +129 -0
  60. package/src/core/mocks/types/collection.ts +140 -0
  61. package/src/core/mocks/types/info.ts +7 -0
  62. package/src/core/mocks/types/input.ts +7 -0
  63. package/src/core/mocks/types/text.ts +5 -0
  64. package/src/core/schema/__tests__/index.test.ts +127 -0
  65. package/src/core/schema/index.ts +195 -0
  66. package/src/core/schema/types.ts +7 -0
  67. package/src/core/switch/__tests__/index.test.ts +156 -0
  68. package/src/core/switch/index.ts +81 -0
  69. package/src/core/tagged-template/README.md +448 -0
  70. package/src/core/tagged-template/__tests__/extract-bindings-from-schema.test.ts +207 -0
  71. package/src/core/tagged-template/__tests__/index.test.ts +190 -0
  72. package/src/core/tagged-template/__tests__/schema-std-integration.test.ts +580 -0
  73. package/src/core/tagged-template/binding.ts +95 -0
  74. package/src/core/tagged-template/expression.ts +92 -0
  75. package/src/core/tagged-template/extract-bindings-from-schema.ts +120 -0
  76. package/src/core/tagged-template/index.ts +5 -0
  77. package/src/core/tagged-template/std.ts +472 -0
  78. package/src/core/tagged-template/types.ts +123 -0
  79. package/src/core/template/__tests__/index.test.ts +380 -0
  80. package/src/core/template/index.ts +196 -0
  81. package/src/core/utils/index.ts +160 -0
  82. package/src/fp/README.md +411 -0
  83. package/src/fp/__tests__/index.test.ts +1178 -0
  84. package/src/fp/index.ts +386 -0
  85. package/src/gen/common.ts +15 -0
  86. package/src/index.ts +5 -0
  87. package/src/types.ts +203 -0
  88. package/types/core/base-builder/conditional/index.d.ts +21 -0
  89. package/types/core/base-builder/context.d.ts +39 -0
  90. package/types/core/base-builder/errors.d.ts +45 -0
  91. package/types/core/base-builder/fluent-builder-base.d.ts +147 -0
  92. package/types/core/base-builder/guards.d.ts +58 -0
  93. package/types/core/base-builder/id/generator.d.ts +69 -0
  94. package/types/core/base-builder/id/registry.d.ts +93 -0
  95. package/types/core/base-builder/index.d.ts +9 -0
  96. package/types/core/base-builder/resolution/path-resolver.d.ts +15 -0
  97. package/types/core/base-builder/resolution/pipeline.d.ts +27 -0
  98. package/types/core/base-builder/resolution/steps/asset-id.d.ts +14 -0
  99. package/types/core/base-builder/resolution/steps/asset-wrappers.d.ts +14 -0
  100. package/types/core/base-builder/resolution/steps/builders.d.ts +14 -0
  101. package/types/core/base-builder/resolution/steps/mixed-arrays.d.ts +14 -0
  102. package/types/core/base-builder/resolution/steps/nested-asset-wrappers.d.ts +14 -0
  103. package/types/core/base-builder/resolution/steps/static-values.d.ts +14 -0
  104. package/types/core/base-builder/resolution/steps/switches.d.ts +15 -0
  105. package/types/core/base-builder/resolution/steps/templates.d.ts +14 -0
  106. package/types/core/base-builder/resolution/value-resolver.d.ts +62 -0
  107. package/types/core/base-builder/storage/auxiliary-storage.d.ts +50 -0
  108. package/types/core/base-builder/storage/value-storage.d.ts +82 -0
  109. package/types/core/base-builder/types.d.ts +183 -0
  110. package/types/core/base-builder/utils.d.ts +2 -0
  111. package/types/core/flow/index.d.ts +23 -0
  112. package/types/core/index.d.ts +8 -0
  113. package/types/core/mocks/index.d.ts +2 -0
  114. package/types/core/mocks/types/action.d.ts +58 -0
  115. package/types/core/mocks/types/choice.d.ts +95 -0
  116. package/types/core/mocks/types/collection.d.ts +102 -0
  117. package/types/core/mocks/types/info.d.ts +7 -0
  118. package/types/core/mocks/types/input.d.ts +7 -0
  119. package/types/core/mocks/types/text.d.ts +5 -0
  120. package/types/core/schema/index.d.ts +34 -0
  121. package/types/core/schema/types.d.ts +5 -0
  122. package/types/core/switch/index.d.ts +21 -0
  123. package/types/core/tagged-template/binding.d.ts +19 -0
  124. package/types/core/tagged-template/expression.d.ts +11 -0
  125. package/types/core/tagged-template/extract-bindings-from-schema.d.ts +7 -0
  126. package/types/core/tagged-template/index.d.ts +6 -0
  127. package/types/core/tagged-template/std.d.ts +174 -0
  128. package/types/core/tagged-template/types.d.ts +69 -0
  129. package/types/core/template/index.d.ts +97 -0
  130. package/types/core/utils/index.d.ts +47 -0
  131. package/types/fp/index.d.ts +149 -0
  132. package/types/gen/common.d.ts +6 -0
  133. package/types/index.d.ts +3 -0
  134. package/types/types.d.ts +163 -0
@@ -0,0 +1,47 @@
1
+ import type { TextAsset } from "../types/text.js";
2
+ import { type FluentBuilder, type BaseBuildContext, type FluentPartial, FluentBuilderBase, createInspectMethod, type TaggedTemplateValue } from "../../../gen/common.js";
3
+
4
+ export interface TextAssetBuilderMethods {
5
+ /** A unique identifier for this asset */
6
+ withId(value: string | TaggedTemplateValue<string>): TextAssetBuilder;
7
+ /** Sets the value property */
8
+ withValue(value: string | TaggedTemplateValue<string>): TextAssetBuilder;
9
+ }
10
+
11
+ /**
12
+ * A builder for TextAsset
13
+ */
14
+ export class TextAssetBuilder extends FluentBuilderBase<TextAsset> implements TextAssetBuilderMethods, FluentBuilder<TextAsset, BaseBuildContext> {
15
+ private static readonly defaults: Record<string, unknown> = {"type":"text","id":"","value":""};
16
+
17
+ /** A unique identifier for this asset */
18
+ withId(value: string | TaggedTemplateValue<string>): TextAssetBuilder {
19
+ return this.set("id", value);
20
+ }
21
+
22
+ /** Sets the value property */
23
+ withValue(value: string | TaggedTemplateValue<string>): TextAssetBuilder {
24
+ return this.set("value", value);
25
+ }
26
+
27
+ /**
28
+ * Builds the final TextAsset object
29
+ * @param context - Optional build context for nested builders
30
+ */
31
+ build(context?: BaseBuildContext): TextAsset {
32
+ return this.buildWithDefaults(TextAssetBuilder.defaults, context);
33
+ }
34
+
35
+ [Symbol.for("nodejs.util.inspect.custom")](): string {
36
+ return createInspectMethod("TextAssetBuilder", this.values);
37
+ }
38
+ }
39
+
40
+ /**
41
+ * Creates a new TextAsset builder
42
+ * @param initial Optional initial values
43
+ * @returns A fluent builder for TextAsset
44
+ */
45
+ export function text(initial?: FluentPartial<TextAsset>): TextAssetBuilder {
46
+ return new TextAssetBuilder(initial);
47
+ }
@@ -0,0 +1 @@
1
+ export * from "./generated";
@@ -0,0 +1,92 @@
1
+ import type {
2
+ Asset,
3
+ AssetWrapper,
4
+ Binding,
5
+ Expression,
6
+ } from "@player-ui/types";
7
+
8
+ export interface SimpleModifier<Type extends string> {
9
+ /** THe mofifier type */
10
+ type: Type;
11
+ }
12
+
13
+ export const ActionRoles = [
14
+ "primary",
15
+ "secondary",
16
+ "tertiary",
17
+ "upsell",
18
+ "back",
19
+ "link",
20
+ "inline-link",
21
+ "tertiary-button",
22
+ ] as const;
23
+
24
+ export type ActionRole = (typeof ActionRoles)[number];
25
+
26
+ /**
27
+ * User actions can be represented in several places.
28
+ * Each view typically has one or more actions that allow the user to navigate away from that view.
29
+ * In addition, several asset types can have actions that apply to that asset only.
30
+ */
31
+ export interface ActionAsset<AnyAsset extends Asset = Asset>
32
+ extends Asset<"action"> {
33
+ /** The transition value of the action in the state machine */
34
+ value?: string;
35
+
36
+ /** A text-like asset for the action's label */
37
+ label?: AssetWrapper<AnyAsset>;
38
+
39
+ /** An optional expression to execute before transitioning */
40
+ exp?: Expression;
41
+
42
+ /** An optional string that describes the action for screen-readers */
43
+ accessibility?: string;
44
+
45
+ /** An optional confirmation dialog to show before executing the action */
46
+ confirmation?: {
47
+ /** message asking for confirmation */
48
+ message: string;
49
+ /** label for the confirm button */
50
+ affirmativeLabel: string;
51
+ /** label for the deny button */
52
+ negativeLabel?: string;
53
+ };
54
+
55
+ /** Additional optional data to assist with the action interactions on the page */
56
+ metaData?: ActionMetaData;
57
+
58
+ /** Triggers the listed bindings to be validated */
59
+ validate?: Array<Binding> | Binding;
60
+ }
61
+
62
+ export interface ActionMetaData {
63
+ // Can't pull from @cg-player/types b/c of circular dependencies
64
+ /** beacon to send when the action runs */
65
+ beacon?: string | Record<string, unknown>;
66
+
67
+ /**
68
+ * A semantic hint to render the action in different user contexts
69
+ */
70
+ role?: ActionRole;
71
+
72
+ /** Force transition to the next view without checking for validation TODO need to update this to support an expression */
73
+ skipValidation?: boolean;
74
+
75
+ /** Size of the button */
76
+ size?: "small" | "medium" | "large";
77
+
78
+ /** true to indicate the button should be disabled */
79
+ disabled?: boolean;
80
+
81
+ /** true to indicate that the button label should be hidden */
82
+ hideLabel?: boolean;
83
+
84
+ /** true to indicate that the button icon should be hidden */
85
+ hideIcon?: boolean;
86
+
87
+ /** true to indicate that the action should display as a button instead of a link */
88
+ showAsButton?: boolean;
89
+
90
+ /** true to indicate to take container width, responsive: Full Width on mobile */
91
+ fullWidth?: boolean | "responsive";
92
+ }
@@ -0,0 +1,129 @@
1
+ import type { Asset, AssetWrapper, Binding } from "@player-ui/types";
2
+
3
+ export const ALL_CATEGORIES = ["recommended"] as const;
4
+
5
+ export type ChoiceItemCategory = (typeof ALL_CATEGORIES)[number];
6
+
7
+ /** Any modifier that can appear on a choice */
8
+ export type ChoiceModifier = {
9
+ /** The default type */
10
+ type: "tag";
11
+
12
+ /** A compact modifier renders a radio button as a dropdown */
13
+ value: "compact";
14
+ };
15
+
16
+ /** Optional tag to set choice as readonly */
17
+ export type ChoiceInputModifier = {
18
+ /** The default type */
19
+ type: "input";
20
+
21
+ /** modifier to set the choices to readonly */
22
+ value: "readonly";
23
+ };
24
+
25
+ export type ChoiceItemMetadata = {
26
+ /** optional category for the choice item to determine its purpose:
27
+ * recommended: this choice item is recommended for the user over or in addition to other items
28
+ */
29
+ category?: ChoiceItemCategory;
30
+ };
31
+
32
+ export interface ChoiceItem<AnyAsset extends Asset = Asset> {
33
+ /** The id associated with the choice item */
34
+ id: string;
35
+
36
+ /** The id used for replay tests. */
37
+ automationId?: string;
38
+
39
+ /** The label describing the choice. */
40
+ label?: AssetWrapper<AnyAsset>;
41
+
42
+ /** The icon describing the choice. */
43
+ icon?: AssetWrapper<AnyAsset>;
44
+
45
+ /** The help for the choice. */
46
+ help?: AssetWrapper<AnyAsset>;
47
+
48
+ /** Support the legacy choiceHelp prop. No storybook docs for this; deprecated in favour of the "help" field. */
49
+ choiceHelp?: AssetWrapper<AnyAsset>;
50
+
51
+ /** The description of the choice. */
52
+ description?: AssetWrapper<AnyAsset>;
53
+
54
+ /** The footer of the choice. */
55
+ footer?: AssetWrapper<AnyAsset>;
56
+
57
+ /**
58
+ * The value to set when this choice is selected
59
+ */
60
+ value?: string | number | boolean | null;
61
+
62
+ /** The details shown when a user selects the choice item */
63
+ choiceDetail?: AssetWrapper<AnyAsset>;
64
+ /**
65
+ * Any modifiers for the current item. No storybook docs for this as "readonly" (the only modifier) shouldn't be used anymore.
66
+ */
67
+ modifiers?: Array<ChoiceInputModifier>;
68
+
69
+ /** MetaData for the choiceItem */
70
+ metaData?: ChoiceItemMetadata;
71
+ }
72
+
73
+ export interface ChoiceMetaData {
74
+ /** Display the asset a little differently based on the role, monthselector only applies to multiselect asset */
75
+ role?: "tiles" | "monthselector"; // problem with Omit again, can't omit metaData on choiceProps and redefine it
76
+
77
+ /** used to set tiles to jumbo manually */
78
+ tileSize?: "jumbo" | undefined;
79
+
80
+ /** should The placeholder be disabled or not */
81
+ placeholderSelectable?: boolean;
82
+ }
83
+
84
+ /**
85
+ * Choice assets are more specific type of data collection element
86
+ * where user is presented with a number of predefined choices and
87
+ * asked to select a single answer.
88
+ */
89
+ export interface ChoiceAsset<AnyAsset extends Asset = Asset>
90
+ extends Asset<"choice"> {
91
+ /** The binding used to keep track of the selected Choice */
92
+ binding: Binding;
93
+
94
+ /** The choiceItems used as options */
95
+ choices?: Array<ChoiceItem<AnyAsset>>;
96
+
97
+ /** The label describing the choice field. */
98
+ label?: AssetWrapper<AnyAsset>;
99
+
100
+ /** choice help providing additional info that could be helpful */
101
+ help?: AssetWrapper<AnyAsset>;
102
+
103
+ /** choice note */
104
+ note?: AssetWrapper;
105
+
106
+ /** placeholder string to show by default for the choice */
107
+ placeholder?: string;
108
+
109
+ /** any accessibility text to be added as an aria label.*/
110
+ accessibility?: string;
111
+
112
+ /** The info that appears underneath the choice */
113
+ additionalInfo?: AssetWrapper<AnyAsset>;
114
+
115
+ /** The resulting Text that appears underneath the choice */
116
+ resultText?: AssetWrapper<AnyAsset>;
117
+
118
+ /** */
119
+ modifiers?: Array<ChoiceModifier | ChoiceInputModifier>;
120
+
121
+ /** Additional metaData for the Choice */
122
+ metaData?: ChoiceMetaData;
123
+
124
+ /** The main action associated with choices */
125
+ action?: AssetWrapper<AnyAsset>;
126
+
127
+ /** The main image associated with choices */
128
+ image?: AssetWrapper<AnyAsset>;
129
+ }
@@ -0,0 +1,140 @@
1
+ import type { Asset, AssetWrapper } from "@player-ui/types";
2
+ import { ActionAsset } from "./action";
3
+
4
+ /** A Modifier to apply 'highlight' styling to the collection */
5
+ export interface CalloutModifier {
6
+ /** the type of modifier */
7
+ type: "callout";
8
+ /** specification on why the callout needs to be highlighted--this determines the coloring */
9
+ value: "support" | "legal";
10
+ }
11
+ export interface TagModifier {
12
+ /** the type of modifier */
13
+ type: "tag";
14
+ /** the value for the tag */
15
+ value: "block";
16
+ }
17
+ export interface CollectionMetaData {
18
+ /** the role of the collection */
19
+ role?:
20
+ | "section"
21
+ | "ocr-surface"
22
+ | "ocr-instructions-lighting"
23
+ | "ocr-instructions-positioning"
24
+ | "swd-head-start-text"
25
+ | "premium"
26
+ | "address";
27
+ }
28
+ /**
29
+ * A collection is a group of assets
30
+ *
31
+ * @asset
32
+ */
33
+ export interface Collection<AnyAsset extends Asset = Asset>
34
+ extends Asset<"collection"> {
35
+ /** The collection items to show */
36
+ values?: Array<AssetWrapper<AnyAsset>>;
37
+
38
+ /** The additional information to show */
39
+ additionalInfo?: AssetWrapper<AnyAsset>;
40
+
41
+ /** The result text to show */
42
+ resultText?: AssetWrapper<AnyAsset> | Array<AssetWrapper<AnyAsset>>;
43
+
44
+ /** The label defining the collection */
45
+ label?: AssetWrapper<AnyAsset>;
46
+
47
+ /** Actions attached to the collection */
48
+ actions?: Array<AssetWrapper<ActionAsset>>;
49
+
50
+ /** Extra data associated with the collection */
51
+ metaData?: CollectionMetaData;
52
+
53
+ /** Ways to modify how the component looks */
54
+ modifiers?: Array<CalloutModifier | TagModifier>;
55
+ }
56
+
57
+ export interface FieldCollectionMetaData {
58
+ /** the role of the field collection */
59
+ role?: "section" | "address" | "name" | "phone";
60
+ }
61
+ /**
62
+ * A field collection is a group of field assets
63
+ *
64
+ * @asset
65
+ */
66
+ export interface FieldCollection<AnyAsset extends Asset = Asset>
67
+ extends Asset<"fieldCollection"> {
68
+ /** The collection items to show */
69
+ values?: Array<AssetWrapper<AnyAsset>>;
70
+
71
+ /** The additional information to show */
72
+ additionalInfo?: AssetWrapper<AnyAsset>;
73
+
74
+ /** The result text to show */
75
+ resultText?: AssetWrapper<AnyAsset>;
76
+
77
+ /** The label defining the collection */
78
+ label?: AssetWrapper<AnyAsset>;
79
+
80
+ /** Extra data associated with the collection */
81
+ metaData?: FieldCollectionMetaData;
82
+
83
+ /** Actions attached to the collection */
84
+ actions?: Array<AssetWrapper<ActionAsset>>;
85
+ }
86
+ /**
87
+ * The OverviewCollection asset
88
+ *
89
+ * @asset
90
+ */
91
+ export interface OverviewCollection<AnyAsset extends Asset = Asset>
92
+ extends Asset<"overviewCollection"> {
93
+ /** The collection items to show */
94
+ values?: Array<AssetWrapper<AnyAsset>>;
95
+
96
+ /** The label defining the collection */
97
+ label?: AssetWrapper<AnyAsset>;
98
+
99
+ /** Actions attached to the collection */
100
+ actions?: Array<AssetWrapper<ActionAsset>>;
101
+ }
102
+
103
+ /**
104
+ * SplashCollection asset is very similar to the basic Collection, which is a group of assets.
105
+ * It can also contain an image. It is intended to display read-only data.
106
+ */
107
+ export interface SplashCollection<AnyAsset extends Asset = Asset>
108
+ extends Asset<"splashCollection"> {
109
+ /** Extra data associated with the Asset */
110
+ metaData?: {
111
+ /** Changes the style slightly */
112
+ role?: "promotional";
113
+ };
114
+
115
+ /** Asset container for an image */
116
+ splash?: AssetWrapper<AnyAsset>;
117
+
118
+ /** Label, typically a single text asset */
119
+ label?: AssetWrapper<AnyAsset>;
120
+
121
+ /** Array of assets, typically text assets */
122
+ values?: Array<AssetWrapper<AnyAsset>>;
123
+
124
+ /** @deprecated additionalInfo in splash collection is no longer supported */
125
+ additionalInfo?: AssetWrapper<AnyAsset>;
126
+
127
+ /** @deprecated resultText in splash collection is no longer supported */
128
+ resultText?: AssetWrapper<AnyAsset>;
129
+
130
+ /** @deprecated actions in splash collection is no longer supported */
131
+ actions?: Array<AssetWrapper<ActionAsset>>;
132
+ }
133
+
134
+ export type CollectionType =
135
+ | Collection
136
+ | FieldCollection
137
+ | OverviewCollection
138
+ | SplashCollection;
139
+
140
+ export type CollectionValue = AssetWrapper<Asset<string>>;
@@ -0,0 +1,7 @@
1
+ import type { Asset, AssetWrapper } from "@player-ui/types";
2
+
3
+ export interface InfoAsset extends Asset<"info"> {
4
+ primaryInfo: Array<AssetWrapper<Asset>>;
5
+ title?: AssetWrapper<Asset>;
6
+ subtitle?: AssetWrapper<Asset>;
7
+ }
@@ -0,0 +1,7 @@
1
+ import type { Asset, AssetWrapper } from "@player-ui/types";
2
+
3
+ export interface InputAsset extends Asset<"input"> {
4
+ binding: string;
5
+ label: AssetWrapper<Asset>;
6
+ placeholder?: string;
7
+ }
@@ -0,0 +1,5 @@
1
+ import type { Asset } from "@player-ui/types";
2
+
3
+ export interface TextAsset extends Asset<"text"> {
4
+ value: string;
5
+ }
@@ -0,0 +1,127 @@
1
+ import { test, expect } from "vitest";
2
+ import { SchemaGenerator } from "..";
3
+
4
+ const BasicDataType = {
5
+ type: "StringType",
6
+ };
7
+
8
+ test("generates proper schema", () => {
9
+ const schemaGenerator = new SchemaGenerator();
10
+
11
+ expect(
12
+ schemaGenerator.toSchema({
13
+ foo: {
14
+ bar: {
15
+ baz: BasicDataType,
16
+ },
17
+ },
18
+ other: [
19
+ {
20
+ item1: BasicDataType,
21
+ },
22
+ ],
23
+ }),
24
+ ).toStrictEqual({
25
+ ROOT: {
26
+ foo: {
27
+ type: "fooType",
28
+ },
29
+ other: {
30
+ type: "otherType",
31
+ isArray: true,
32
+ },
33
+ },
34
+ fooType: {
35
+ bar: {
36
+ type: "barType",
37
+ },
38
+ },
39
+ barType: {
40
+ baz: {
41
+ type: "StringType",
42
+ },
43
+ },
44
+ otherType: {
45
+ item1: {
46
+ type: "StringType",
47
+ },
48
+ },
49
+ });
50
+ });
51
+
52
+ test("Edge Case - two artificial array nodes", () => {
53
+ const schemaGenerator = new SchemaGenerator();
54
+
55
+ expect(
56
+ schemaGenerator.toSchema({
57
+ foo: {
58
+ bar: [
59
+ {
60
+ baa: BasicDataType,
61
+ },
62
+ ],
63
+ },
64
+ other: {
65
+ bar: [
66
+ {
67
+ bab: BasicDataType,
68
+ },
69
+ ],
70
+ },
71
+ another: {
72
+ bar: [
73
+ {
74
+ bac: BasicDataType,
75
+ },
76
+ ],
77
+ },
78
+ }),
79
+ ).toMatchInlineSnapshot(`
80
+ {
81
+ "ROOT": {
82
+ "another": {
83
+ "type": "anotherType",
84
+ },
85
+ "foo": {
86
+ "type": "fooType",
87
+ },
88
+ "other": {
89
+ "type": "otherType",
90
+ },
91
+ },
92
+ "anotherType": {
93
+ "bar": {
94
+ "isArray": true,
95
+ "type": "barType",
96
+ },
97
+ },
98
+ "barType": {
99
+ "bac": {
100
+ "type": "StringType",
101
+ },
102
+ },
103
+ "barType2": {
104
+ "bab": {
105
+ "type": "StringType",
106
+ },
107
+ },
108
+ "barType3": {
109
+ "baa": {
110
+ "type": "StringType",
111
+ },
112
+ },
113
+ "fooType": {
114
+ "bar": {
115
+ "isArray": true,
116
+ "type": "barType3",
117
+ },
118
+ },
119
+ "otherType": {
120
+ "bar": {
121
+ "isArray": true,
122
+ "type": "barType2",
123
+ },
124
+ },
125
+ }
126
+ `);
127
+ });