@starlightcms/js-sdk 4.0.0-beta.1 → 4.0.0-beta.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.
@@ -70,4 +70,54 @@ export type TextField = string | undefined;
70
70
  * @group Data Fields
71
71
  */
72
72
  export type VisualField = VisualData | undefined;
73
+ /**
74
+ * Represents an Integer Field returned by the API.
75
+ *
76
+ * Field types are used to type Entry and Singleton objects when requesting
77
+ * them using some SDK methods. See {@apilink DefaultModelDefinition}
78
+ * for more info.
79
+ *
80
+ * @group Data Fields
81
+ */
82
+ export type IntegerField = number | undefined;
83
+ /**
84
+ * Represents a Float Field returned by the API.
85
+ *
86
+ * Field types are used to type Entry and Singleton objects when requesting
87
+ * them using some SDK methods. See {@apilink DefaultModelDefinition}
88
+ * for more info.
89
+ *
90
+ * @group Data Fields
91
+ */
92
+ export type FloatField = number | undefined;
93
+ /**
94
+ * Represents a Decimal Field returned by the API.
95
+ *
96
+ * Field types are used to type Entry and Singleton objects when requesting
97
+ * them using some SDK methods. See {@apilink DefaultModelDefinition}
98
+ * for more info.
99
+ *
100
+ * @group Data Fields
101
+ */
102
+ export type DecimalField = number | undefined;
103
+ export type SelectFieldOptions = {
104
+ /**
105
+ * Indicates if the Select Field accepts multiple selected choices.
106
+ *
107
+ * @default false
108
+ */
109
+ multiple?: boolean;
110
+ };
111
+ /**
112
+ * Represents a Select Field returned by the API.
113
+ *
114
+ * Field types are used to type Entry and Singleton objects when requesting
115
+ * them using some SDK methods. See {@apilink DefaultModelDefinition}
116
+ * for more info.
117
+ *
118
+ * @group Data Fields
119
+ */
120
+ export type SelectField<Options extends SelectFieldOptions = {
121
+ multiple: false;
122
+ }> = (Options['multiple'] extends false ? string : string | string[]) | undefined;
73
123
  //# sourceMappingURL=fields.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../../../src/types/fields.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAErC;;;;;;;;GAQG;AACH,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,SAAS,CAAA;AAE9C;;;;;;;;GAQG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,SAAS,CAAA;AAE1C;;;;;;;;GAQG;AACH,MAAM,MAAM,UAAU,GAAG,WAAW,GAAG,SAAS,CAAA;AAEhD;;;;;;;;GAQG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC,GAAG,SAAS,CAAA;AAEtD;;;;;;;;GAQG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,SAAS,CAAA;AAE5C;;;;;;;;GAQG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,SAAS,CAAA;AAE1C;;;;;;;;GAQG;AACH,MAAM,MAAM,WAAW,GAAG,UAAU,GAAG,SAAS,CAAA"}
1
+ {"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../../../src/types/fields.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAErC;;;;;;;;GAQG;AACH,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,SAAS,CAAA;AAE9C;;;;;;;;GAQG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,SAAS,CAAA;AAE1C;;;;;;;;GAQG;AACH,MAAM,MAAM,UAAU,GAAG,WAAW,GAAG,SAAS,CAAA;AAEhD;;;;;;;;GAQG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC,GAAG,SAAS,CAAA;AAEtD;;;;;;;;GAQG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,SAAS,CAAA;AAE5C;;;;;;;;GAQG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,SAAS,CAAA;AAE1C;;;;;;;;GAQG;AACH,MAAM,MAAM,WAAW,GAAG,UAAU,GAAG,SAAS,CAAA;AAEhD;;;;;;;;GAQG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,SAAS,CAAA;AAE7C;;;;;;;;GAQG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,SAAS,CAAA;AAE3C;;;;;;;;GAQG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,SAAS,CAAA;AAE7C,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;AAED;;;;;;;;GAQG;AACH,MAAM,MAAM,WAAW,CACrB,OAAO,SAAS,kBAAkB,GAAG;IAAE,QAAQ,EAAE,KAAK,CAAA;CAAE,IACtD,CAAC,OAAO,CAAC,UAAU,CAAC,SAAS,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC,GAAG,SAAS,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"fields.js","sourceRoot":"","sources":["../../../src/types/fields.ts"],"names":[],"mappings":"","sourcesContent":["import { MediaObject, Relation } from './entities'\nimport { VisualData } from './visual'\n\n/**\n * Represents a Boolean Field returned by the API.\n *\n * Field types are used to type Entry and Singleton objects when requesting\n * them using some SDK methods. See {@apilink DefaultModelDefinition}\n * for more info.\n *\n * @group Data Fields\n */\nexport type BooleanField = boolean | undefined\n\n/**\n * Represents an HTML Field returned by the API.\n *\n * Field types are used to type Entry and Singleton objects when requesting\n * them using some SDK methods. See {@apilink DefaultModelDefinition}\n * for more info.\n *\n * @group Data Fields\n */\nexport type HtmlField = string | undefined\n\n/**\n * Represents a Media Field returned by the API.\n *\n * Field types are used to type Entry and Singleton objects when requesting\n * them using some SDK methods. See {@apilink DefaultModelDefinition}\n * for more info.\n *\n * @group Data Fields\n */\nexport type MediaField = MediaObject | undefined\n\n/**\n * Represents a Relation Field returned by the API.\n *\n * Field types are used to type Entry and Singleton objects when requesting\n * them using some SDK methods. See {@apilink DefaultModelDefinition}\n * for more info.\n *\n * @group Data Fields\n */\nexport type RelationField<T> = Relation<T> | undefined\n\n/**\n * Represents a String Field returned by the API.\n *\n * Field types are used to type Entry and Singleton objects when requesting\n * them using some SDK methods. See {@apilink DefaultModelDefinition}\n * for more info.\n *\n * @group Data Fields\n */\nexport type StringField = string | undefined\n\n/**\n * Represents a Text Field returned by the API.\n *\n * Field types are used to type Entry and Singleton objects when requesting\n * them using some SDK methods. See {@apilink DefaultModelDefinition}\n * for more info.\n *\n * @group Data Fields\n */\nexport type TextField = string | undefined\n\n/**\n * Represents a Visual Field returned by the API.\n *\n * Field types are used to type Entry and Singleton objects when requesting\n * them using some SDK methods. See {@apilink DefaultModelDefinition}\n * for more info.\n *\n * @group Data Fields\n */\nexport type VisualField = VisualData | undefined\n"]}
1
+ {"version":3,"file":"fields.js","sourceRoot":"","sources":["../../../src/types/fields.ts"],"names":[],"mappings":"","sourcesContent":["import { MediaObject, Relation } from './entities'\nimport { VisualData } from './visual'\n\n/**\n * Represents a Boolean Field returned by the API.\n *\n * Field types are used to type Entry and Singleton objects when requesting\n * them using some SDK methods. See {@apilink DefaultModelDefinition}\n * for more info.\n *\n * @group Data Fields\n */\nexport type BooleanField = boolean | undefined\n\n/**\n * Represents an HTML Field returned by the API.\n *\n * Field types are used to type Entry and Singleton objects when requesting\n * them using some SDK methods. See {@apilink DefaultModelDefinition}\n * for more info.\n *\n * @group Data Fields\n */\nexport type HtmlField = string | undefined\n\n/**\n * Represents a Media Field returned by the API.\n *\n * Field types are used to type Entry and Singleton objects when requesting\n * them using some SDK methods. See {@apilink DefaultModelDefinition}\n * for more info.\n *\n * @group Data Fields\n */\nexport type MediaField = MediaObject | undefined\n\n/**\n * Represents a Relation Field returned by the API.\n *\n * Field types are used to type Entry and Singleton objects when requesting\n * them using some SDK methods. See {@apilink DefaultModelDefinition}\n * for more info.\n *\n * @group Data Fields\n */\nexport type RelationField<T> = Relation<T> | undefined\n\n/**\n * Represents a String Field returned by the API.\n *\n * Field types are used to type Entry and Singleton objects when requesting\n * them using some SDK methods. See {@apilink DefaultModelDefinition}\n * for more info.\n *\n * @group Data Fields\n */\nexport type StringField = string | undefined\n\n/**\n * Represents a Text Field returned by the API.\n *\n * Field types are used to type Entry and Singleton objects when requesting\n * them using some SDK methods. See {@apilink DefaultModelDefinition}\n * for more info.\n *\n * @group Data Fields\n */\nexport type TextField = string | undefined\n\n/**\n * Represents a Visual Field returned by the API.\n *\n * Field types are used to type Entry and Singleton objects when requesting\n * them using some SDK methods. See {@apilink DefaultModelDefinition}\n * for more info.\n *\n * @group Data Fields\n */\nexport type VisualField = VisualData | undefined\n\n/**\n * Represents an Integer Field returned by the API.\n *\n * Field types are used to type Entry and Singleton objects when requesting\n * them using some SDK methods. See {@apilink DefaultModelDefinition}\n * for more info.\n *\n * @group Data Fields\n */\nexport type IntegerField = number | undefined\n\n/**\n * Represents a Float Field returned by the API.\n *\n * Field types are used to type Entry and Singleton objects when requesting\n * them using some SDK methods. See {@apilink DefaultModelDefinition}\n * for more info.\n *\n * @group Data Fields\n */\nexport type FloatField = number | undefined\n\n/**\n * Represents a Decimal Field returned by the API.\n *\n * Field types are used to type Entry and Singleton objects when requesting\n * them using some SDK methods. See {@apilink DefaultModelDefinition}\n * for more info.\n *\n * @group Data Fields\n */\nexport type DecimalField = number | undefined\n\nexport type SelectFieldOptions = {\n /**\n * Indicates if the Select Field accepts multiple selected choices.\n *\n * @default false\n */\n multiple?: boolean\n}\n\n/**\n * Represents a Select Field returned by the API.\n *\n * Field types are used to type Entry and Singleton objects when requesting\n * them using some SDK methods. See {@apilink DefaultModelDefinition}\n * for more info.\n *\n * @group Data Fields\n */\nexport type SelectField<\n Options extends SelectFieldOptions = { multiple: false },\n> = (Options['multiple'] extends false ? string : string | string[]) | undefined\n"]}
@@ -7,7 +7,9 @@
7
7
  *
8
8
  * @group Data Groups
9
9
  */
10
- export type Group<Fields extends Record<string, unknown>> = Fields | undefined;
10
+ export type Group<Fields extends Record<string, unknown>> = {
11
+ [Property in keyof Fields]: Fields[Property];
12
+ } | undefined;
11
13
  /**
12
14
  * Represents a Repeater Group returned by the API.
13
15
  *
@@ -22,5 +24,7 @@ export type Group<Fields extends Record<string, unknown>> = Fields | undefined;
22
24
  *
23
25
  * @group Data Groups
24
26
  */
25
- export type RepeaterGroup<Fields extends Record<string, unknown>> = Fields[] | null | undefined;
27
+ export type RepeaterGroup<Fields extends Record<string, unknown>> = Array<{
28
+ [Property in keyof Fields]: Fields[Property];
29
+ }> | null | undefined;
26
30
  //# sourceMappingURL=groups.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"groups.d.ts","sourceRoot":"","sources":["../../../src/types/groups.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,MAAM,KAAK,CAAC,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,MAAM,GAAG,SAAS,CAAA;AAE9E;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,aAAa,CAAC,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAC5D,MAAM,EAAE,GACR,IAAI,GACJ,SAAS,CAAA"}
1
+ {"version":3,"file":"groups.d.ts","sourceRoot":"","sources":["../../../src/types/groups.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,MAAM,KAAK,CAAC,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IACpD;KAAG,QAAQ,IAAI,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC;CAAE,GAChD,SAAS,CAAA;AAEb;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,aAAa,CAAC,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAC5D,KAAK,CAAC;KAAG,QAAQ,IAAI,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC;CAAE,CAAC,GACvD,IAAI,GACJ,SAAS,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"groups.js","sourceRoot":"","sources":["../../../src/types/groups.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Represents a Group returned by the API.\n *\n * Group types are used to type Entry and Singleton objects when requesting\n * them using some SDK methods. See {@apilink DefaultModelDefinition}\n * for more info.\n *\n * @group Data Groups\n */\nexport type Group<Fields extends Record<string, unknown>> = Fields | undefined\n\n/**\n * Represents a Repeater Group returned by the API.\n *\n * Note that the API return empty repeaters as `null`.\n *\n * To retrieve the type of a `RepeaterGroup` item, use the\n * {@apilink RepeaterItem} utility type.\n *\n * Group types are used to type Entry and Singleton objects when requesting\n * them using some SDK methods. See {@apilink DefaultModelDefinition}\n * for more info.\n *\n * @group Data Groups\n */\nexport type RepeaterGroup<Fields extends Record<string, unknown>> =\n | Fields[]\n | null\n | undefined\n"]}
1
+ {"version":3,"file":"groups.js","sourceRoot":"","sources":["../../../src/types/groups.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Represents a Group returned by the API.\n *\n * Group types are used to type Entry and Singleton objects when requesting\n * them using some SDK methods. See {@apilink DefaultModelDefinition}\n * for more info.\n *\n * @group Data Groups\n */\nexport type Group<Fields extends Record<string, unknown>> =\n | { [Property in keyof Fields]: Fields[Property] }\n | undefined\n\n/**\n * Represents a Repeater Group returned by the API.\n *\n * Note that the API return empty repeaters as `null`.\n *\n * To retrieve the type of a `RepeaterGroup` item, use the\n * {@apilink RepeaterItem} utility type.\n *\n * Group types are used to type Entry and Singleton objects when requesting\n * them using some SDK methods. See {@apilink DefaultModelDefinition}\n * for more info.\n *\n * @group Data Groups\n */\nexport type RepeaterGroup<Fields extends Record<string, unknown>> =\n | Array<{ [Property in keyof Fields]: Fields[Property] }>\n | null\n | undefined\n"]}
@@ -1,12 +1,83 @@
1
1
  import { RepeaterGroup } from './groups';
2
+ import { Get, Paths } from 'type-fest';
3
+ /**
4
+ * Returns the type of the group or field in the given structure at the
5
+ * specified path. Use dot notation `.` to access items inside groups
6
+ * and bracket notation `[]` to access items inside repeaters.
7
+ *
8
+ * Syntax example:
9
+ * - foo
10
+ * - foo.bar
11
+ * - foo.bar[0].baz
12
+ * - foo.bar[0].baz.quo
13
+ *
14
+ * This utility is useful to get the type of a deeply nested group or field
15
+ * inside a Model, Singleton or Form structure.
16
+ *
17
+ * @example Retrieving the type of a deeply nested group or field.
18
+ * ```ts
19
+ * import { Group, StringField, GetFromStructure } from '@starlightcms/js-sdk'
20
+ *
21
+ * type ComplexModel = {
22
+ * info: Group<{
23
+ * title: StringField
24
+ * meta: Group<{
25
+ * keywords: StringField
26
+ * tags: RepeaterGroup<{
27
+ * name: StringField
28
+ * }>
29
+ * }>
30
+ * }>
31
+ * }
32
+ *
33
+ * type MetaGroupType = GetFromStructure<ComplexModel, 'info.meta'>
34
+ * // Resulting type -> Group<{ keywords: StringField, tags: RepeaterGroup<{ name: StringField }> }>
35
+ *
36
+ * type KeywordsFieldType = GetFromStructure<ComplexModel, 'info.meta.keywords'>
37
+ * // Resulting type -> StringField
38
+ *
39
+ * type TagNameFieldType = GetFromStructure<ComplexModel, 'info.meta.tags[0].name'>
40
+ * // Resulting type -> StringField
41
+ * ```
42
+ *
43
+ * @group Utility Types
44
+ */
45
+ export type GetFromStructure<Structure, Path extends Paths<Structure, {
46
+ bracketNotation: true;
47
+ maxRecursionDepth: 4;
48
+ }>> = Get<Structure, Path>;
2
49
  /**
3
50
  * Returns the item type of the given Repeater Group.
4
51
  *
5
- * For instance, given a `RepeaterGroup<Foo>`, this utility would return
6
- * the `Foo` type. This is useful to "pick" the type of the content held
7
- * by items of a Repeater Group.
52
+ * This utility is useful to get the type of the content
53
+ * held in items of a specific Repeater Group.
54
+ *
55
+ * @example Retrieving the type of a repeater item.
56
+ * ```ts
57
+ * import {
58
+ * RepeaterGroup,
59
+ * MediaField,
60
+ * StringField,
61
+ * GetRepeaterItem,
62
+ * GetFromStructure
63
+ * } from '@starlightcms/js-sdk'
64
+ *
65
+ * type SlideshowModel = {
66
+ * slides: RepeaterGroup<{
67
+ * image: MediaField
68
+ * description: StringField
69
+ * }>
70
+ * }
71
+ *
72
+ * type Slide = GetRepeaterItem<SlideshowModel['slides']>
73
+ * // Resulting type -> { image: MediaField, description: StringField }
74
+ *
75
+ * // Also works with the GetFromStructure utility
76
+ * type Slide = GetRepeaterItem<GetFromStructure<SlideshowModel, 'slides'>>
77
+ * // Resulting type -> { image: MediaField, description: StringField }
78
+ * ```
8
79
  *
9
80
  * @group Utility Types
10
81
  */
11
- export type RepeaterItem<Repeater extends RepeaterGroup<Record<string, unknown>>> = Repeater extends readonly (infer ItemType)[] ? ItemType : never;
82
+ export type GetRepeaterItem<Repeater extends RepeaterGroup<Record<string, unknown>>> = Repeater extends readonly (infer ItemType)[] ? ItemType : never;
12
83
  //# sourceMappingURL=utilities.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utilities.d.ts","sourceRoot":"","sources":["../../../src/types/utilities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAExC;;;;;;;;GAQG;AACH,MAAM,MAAM,YAAY,CACtB,QAAQ,SAAS,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,IACrD,QAAQ,SAAS,SAAS,CAAC,MAAM,QAAQ,CAAC,EAAE,GAAG,QAAQ,GAAG,KAAK,CAAA"}
1
+ {"version":3,"file":"utilities.d.ts","sourceRoot":"","sources":["../../../src/types/utilities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,WAAW,CAAA;AAEtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,MAAM,MAAM,gBAAgB,CAC1B,SAAS,EACT,IAAI,SAAS,KAAK,CAChB,SAAS,EACT;IAAE,eAAe,EAAE,IAAI,CAAC;IAAC,iBAAiB,EAAE,CAAC,CAAA;CAAE,CAChD,IACC,GAAG,CAAC,SAAS,EAAE,IAAI,CAAC,CAAA;AAExB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,MAAM,eAAe,CACzB,QAAQ,SAAS,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,IACrD,QAAQ,SAAS,SAAS,CAAC,MAAM,QAAQ,CAAC,EAAE,GAAG,QAAQ,GAAG,KAAK,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"utilities.js","sourceRoot":"","sources":["../../../src/types/utilities.ts"],"names":[],"mappings":"","sourcesContent":["import { RepeaterGroup } from './groups'\n\n/**\n * Returns the item type of the given Repeater Group.\n *\n * For instance, given a `RepeaterGroup<Foo>`, this utility would return\n * the `Foo` type. This is useful to \"pick\" the type of the content held\n * by items of a Repeater Group.\n *\n * @group Utility Types\n */\nexport type RepeaterItem<\n Repeater extends RepeaterGroup<Record<string, unknown>>,\n> = Repeater extends readonly (infer ItemType)[] ? ItemType : never\n"]}
1
+ {"version":3,"file":"utilities.js","sourceRoot":"","sources":["../../../src/types/utilities.ts"],"names":[],"mappings":"","sourcesContent":["import { RepeaterGroup } from './groups'\nimport { Get, Paths } from 'type-fest'\n\n/**\n * Returns the type of the group or field in the given structure at the\n * specified path. Use dot notation `.` to access items inside groups\n * and bracket notation `[]` to access items inside repeaters.\n *\n * Syntax example:\n * - foo\n * - foo.bar\n * - foo.bar[0].baz\n * - foo.bar[0].baz.quo\n *\n * This utility is useful to get the type of a deeply nested group or field\n * inside a Model, Singleton or Form structure.\n *\n * @example Retrieving the type of a deeply nested group or field.\n * ```ts\n * import { Group, StringField, GetFromStructure } from '@starlightcms/js-sdk'\n *\n * type ComplexModel = {\n * info: Group<{\n * title: StringField\n * meta: Group<{\n * keywords: StringField\n * tags: RepeaterGroup<{\n * name: StringField\n * }>\n * }>\n * }>\n * }\n *\n * type MetaGroupType = GetFromStructure<ComplexModel, 'info.meta'>\n * // Resulting type -> Group<{ keywords: StringField, tags: RepeaterGroup<{ name: StringField }> }>\n *\n * type KeywordsFieldType = GetFromStructure<ComplexModel, 'info.meta.keywords'>\n * // Resulting type -> StringField\n *\n * type TagNameFieldType = GetFromStructure<ComplexModel, 'info.meta.tags[0].name'>\n * // Resulting type -> StringField\n * ```\n *\n * @group Utility Types\n */\nexport type GetFromStructure<\n Structure,\n Path extends Paths<\n Structure,\n { bracketNotation: true; maxRecursionDepth: 4 }\n >,\n> = Get<Structure, Path>\n\n/**\n * Returns the item type of the given Repeater Group.\n *\n * This utility is useful to get the type of the content\n * held in items of a specific Repeater Group.\n *\n * @example Retrieving the type of a repeater item.\n * ```ts\n * import {\n * RepeaterGroup,\n * MediaField,\n * StringField,\n * GetRepeaterItem,\n * GetFromStructure\n * } from '@starlightcms/js-sdk'\n *\n * type SlideshowModel = {\n * slides: RepeaterGroup<{\n * image: MediaField\n * description: StringField\n * }>\n * }\n *\n * type Slide = GetRepeaterItem<SlideshowModel['slides']>\n * // Resulting type -> { image: MediaField, description: StringField }\n *\n * // Also works with the GetFromStructure utility\n * type Slide = GetRepeaterItem<GetFromStructure<SlideshowModel, 'slides'>>\n * // Resulting type -> { image: MediaField, description: StringField }\n * ```\n *\n * @group Utility Types\n */\nexport type GetRepeaterItem<\n Repeater extends RepeaterGroup<Record<string, unknown>>,\n> = Repeater extends readonly (infer ItemType)[] ? ItemType : never\n"]}
@@ -70,4 +70,54 @@ export type TextField = string | undefined;
70
70
  * @group Data Fields
71
71
  */
72
72
  export type VisualField = VisualData | undefined;
73
+ /**
74
+ * Represents an Integer Field returned by the API.
75
+ *
76
+ * Field types are used to type Entry and Singleton objects when requesting
77
+ * them using some SDK methods. See {@apilink DefaultModelDefinition}
78
+ * for more info.
79
+ *
80
+ * @group Data Fields
81
+ */
82
+ export type IntegerField = number | undefined;
83
+ /**
84
+ * Represents a Float Field returned by the API.
85
+ *
86
+ * Field types are used to type Entry and Singleton objects when requesting
87
+ * them using some SDK methods. See {@apilink DefaultModelDefinition}
88
+ * for more info.
89
+ *
90
+ * @group Data Fields
91
+ */
92
+ export type FloatField = number | undefined;
93
+ /**
94
+ * Represents a Decimal Field returned by the API.
95
+ *
96
+ * Field types are used to type Entry and Singleton objects when requesting
97
+ * them using some SDK methods. See {@apilink DefaultModelDefinition}
98
+ * for more info.
99
+ *
100
+ * @group Data Fields
101
+ */
102
+ export type DecimalField = number | undefined;
103
+ export type SelectFieldOptions = {
104
+ /**
105
+ * Indicates if the Select Field accepts multiple selected choices.
106
+ *
107
+ * @default false
108
+ */
109
+ multiple?: boolean;
110
+ };
111
+ /**
112
+ * Represents a Select Field returned by the API.
113
+ *
114
+ * Field types are used to type Entry and Singleton objects when requesting
115
+ * them using some SDK methods. See {@apilink DefaultModelDefinition}
116
+ * for more info.
117
+ *
118
+ * @group Data Fields
119
+ */
120
+ export type SelectField<Options extends SelectFieldOptions = {
121
+ multiple: false;
122
+ }> = (Options['multiple'] extends false ? string : string | string[]) | undefined;
73
123
  //# sourceMappingURL=fields.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../../../src/types/fields.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAErC;;;;;;;;GAQG;AACH,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,SAAS,CAAA;AAE9C;;;;;;;;GAQG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,SAAS,CAAA;AAE1C;;;;;;;;GAQG;AACH,MAAM,MAAM,UAAU,GAAG,WAAW,GAAG,SAAS,CAAA;AAEhD;;;;;;;;GAQG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC,GAAG,SAAS,CAAA;AAEtD;;;;;;;;GAQG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,SAAS,CAAA;AAE5C;;;;;;;;GAQG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,SAAS,CAAA;AAE1C;;;;;;;;GAQG;AACH,MAAM,MAAM,WAAW,GAAG,UAAU,GAAG,SAAS,CAAA"}
1
+ {"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../../../src/types/fields.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAErC;;;;;;;;GAQG;AACH,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,SAAS,CAAA;AAE9C;;;;;;;;GAQG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,SAAS,CAAA;AAE1C;;;;;;;;GAQG;AACH,MAAM,MAAM,UAAU,GAAG,WAAW,GAAG,SAAS,CAAA;AAEhD;;;;;;;;GAQG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC,GAAG,SAAS,CAAA;AAEtD;;;;;;;;GAQG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,SAAS,CAAA;AAE5C;;;;;;;;GAQG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,SAAS,CAAA;AAE1C;;;;;;;;GAQG;AACH,MAAM,MAAM,WAAW,GAAG,UAAU,GAAG,SAAS,CAAA;AAEhD;;;;;;;;GAQG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,SAAS,CAAA;AAE7C;;;;;;;;GAQG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,SAAS,CAAA;AAE3C;;;;;;;;GAQG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,SAAS,CAAA;AAE7C,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;AAED;;;;;;;;GAQG;AACH,MAAM,MAAM,WAAW,CACrB,OAAO,SAAS,kBAAkB,GAAG;IAAE,QAAQ,EAAE,KAAK,CAAA;CAAE,IACtD,CAAC,OAAO,CAAC,UAAU,CAAC,SAAS,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC,GAAG,SAAS,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"fields.js","sourceRoot":"","sources":["../../../src/types/fields.ts"],"names":[],"mappings":"","sourcesContent":["import { MediaObject, Relation } from './entities'\nimport { VisualData } from './visual'\n\n/**\n * Represents a Boolean Field returned by the API.\n *\n * Field types are used to type Entry and Singleton objects when requesting\n * them using some SDK methods. See {@apilink DefaultModelDefinition}\n * for more info.\n *\n * @group Data Fields\n */\nexport type BooleanField = boolean | undefined\n\n/**\n * Represents an HTML Field returned by the API.\n *\n * Field types are used to type Entry and Singleton objects when requesting\n * them using some SDK methods. See {@apilink DefaultModelDefinition}\n * for more info.\n *\n * @group Data Fields\n */\nexport type HtmlField = string | undefined\n\n/**\n * Represents a Media Field returned by the API.\n *\n * Field types are used to type Entry and Singleton objects when requesting\n * them using some SDK methods. See {@apilink DefaultModelDefinition}\n * for more info.\n *\n * @group Data Fields\n */\nexport type MediaField = MediaObject | undefined\n\n/**\n * Represents a Relation Field returned by the API.\n *\n * Field types are used to type Entry and Singleton objects when requesting\n * them using some SDK methods. See {@apilink DefaultModelDefinition}\n * for more info.\n *\n * @group Data Fields\n */\nexport type RelationField<T> = Relation<T> | undefined\n\n/**\n * Represents a String Field returned by the API.\n *\n * Field types are used to type Entry and Singleton objects when requesting\n * them using some SDK methods. See {@apilink DefaultModelDefinition}\n * for more info.\n *\n * @group Data Fields\n */\nexport type StringField = string | undefined\n\n/**\n * Represents a Text Field returned by the API.\n *\n * Field types are used to type Entry and Singleton objects when requesting\n * them using some SDK methods. See {@apilink DefaultModelDefinition}\n * for more info.\n *\n * @group Data Fields\n */\nexport type TextField = string | undefined\n\n/**\n * Represents a Visual Field returned by the API.\n *\n * Field types are used to type Entry and Singleton objects when requesting\n * them using some SDK methods. See {@apilink DefaultModelDefinition}\n * for more info.\n *\n * @group Data Fields\n */\nexport type VisualField = VisualData | undefined\n"]}
1
+ {"version":3,"file":"fields.js","sourceRoot":"","sources":["../../../src/types/fields.ts"],"names":[],"mappings":"","sourcesContent":["import { MediaObject, Relation } from './entities'\nimport { VisualData } from './visual'\n\n/**\n * Represents a Boolean Field returned by the API.\n *\n * Field types are used to type Entry and Singleton objects when requesting\n * them using some SDK methods. See {@apilink DefaultModelDefinition}\n * for more info.\n *\n * @group Data Fields\n */\nexport type BooleanField = boolean | undefined\n\n/**\n * Represents an HTML Field returned by the API.\n *\n * Field types are used to type Entry and Singleton objects when requesting\n * them using some SDK methods. See {@apilink DefaultModelDefinition}\n * for more info.\n *\n * @group Data Fields\n */\nexport type HtmlField = string | undefined\n\n/**\n * Represents a Media Field returned by the API.\n *\n * Field types are used to type Entry and Singleton objects when requesting\n * them using some SDK methods. See {@apilink DefaultModelDefinition}\n * for more info.\n *\n * @group Data Fields\n */\nexport type MediaField = MediaObject | undefined\n\n/**\n * Represents a Relation Field returned by the API.\n *\n * Field types are used to type Entry and Singleton objects when requesting\n * them using some SDK methods. See {@apilink DefaultModelDefinition}\n * for more info.\n *\n * @group Data Fields\n */\nexport type RelationField<T> = Relation<T> | undefined\n\n/**\n * Represents a String Field returned by the API.\n *\n * Field types are used to type Entry and Singleton objects when requesting\n * them using some SDK methods. See {@apilink DefaultModelDefinition}\n * for more info.\n *\n * @group Data Fields\n */\nexport type StringField = string | undefined\n\n/**\n * Represents a Text Field returned by the API.\n *\n * Field types are used to type Entry and Singleton objects when requesting\n * them using some SDK methods. See {@apilink DefaultModelDefinition}\n * for more info.\n *\n * @group Data Fields\n */\nexport type TextField = string | undefined\n\n/**\n * Represents a Visual Field returned by the API.\n *\n * Field types are used to type Entry and Singleton objects when requesting\n * them using some SDK methods. See {@apilink DefaultModelDefinition}\n * for more info.\n *\n * @group Data Fields\n */\nexport type VisualField = VisualData | undefined\n\n/**\n * Represents an Integer Field returned by the API.\n *\n * Field types are used to type Entry and Singleton objects when requesting\n * them using some SDK methods. See {@apilink DefaultModelDefinition}\n * for more info.\n *\n * @group Data Fields\n */\nexport type IntegerField = number | undefined\n\n/**\n * Represents a Float Field returned by the API.\n *\n * Field types are used to type Entry and Singleton objects when requesting\n * them using some SDK methods. See {@apilink DefaultModelDefinition}\n * for more info.\n *\n * @group Data Fields\n */\nexport type FloatField = number | undefined\n\n/**\n * Represents a Decimal Field returned by the API.\n *\n * Field types are used to type Entry and Singleton objects when requesting\n * them using some SDK methods. See {@apilink DefaultModelDefinition}\n * for more info.\n *\n * @group Data Fields\n */\nexport type DecimalField = number | undefined\n\nexport type SelectFieldOptions = {\n /**\n * Indicates if the Select Field accepts multiple selected choices.\n *\n * @default false\n */\n multiple?: boolean\n}\n\n/**\n * Represents a Select Field returned by the API.\n *\n * Field types are used to type Entry and Singleton objects when requesting\n * them using some SDK methods. See {@apilink DefaultModelDefinition}\n * for more info.\n *\n * @group Data Fields\n */\nexport type SelectField<\n Options extends SelectFieldOptions = { multiple: false },\n> = (Options['multiple'] extends false ? string : string | string[]) | undefined\n"]}
@@ -7,7 +7,9 @@
7
7
  *
8
8
  * @group Data Groups
9
9
  */
10
- export type Group<Fields extends Record<string, unknown>> = Fields | undefined;
10
+ export type Group<Fields extends Record<string, unknown>> = {
11
+ [Property in keyof Fields]: Fields[Property];
12
+ } | undefined;
11
13
  /**
12
14
  * Represents a Repeater Group returned by the API.
13
15
  *
@@ -22,5 +24,7 @@ export type Group<Fields extends Record<string, unknown>> = Fields | undefined;
22
24
  *
23
25
  * @group Data Groups
24
26
  */
25
- export type RepeaterGroup<Fields extends Record<string, unknown>> = Fields[] | null | undefined;
27
+ export type RepeaterGroup<Fields extends Record<string, unknown>> = Array<{
28
+ [Property in keyof Fields]: Fields[Property];
29
+ }> | null | undefined;
26
30
  //# sourceMappingURL=groups.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"groups.d.ts","sourceRoot":"","sources":["../../../src/types/groups.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,MAAM,KAAK,CAAC,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,MAAM,GAAG,SAAS,CAAA;AAE9E;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,aAAa,CAAC,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAC5D,MAAM,EAAE,GACR,IAAI,GACJ,SAAS,CAAA"}
1
+ {"version":3,"file":"groups.d.ts","sourceRoot":"","sources":["../../../src/types/groups.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,MAAM,KAAK,CAAC,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IACpD;KAAG,QAAQ,IAAI,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC;CAAE,GAChD,SAAS,CAAA;AAEb;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,aAAa,CAAC,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAC5D,KAAK,CAAC;KAAG,QAAQ,IAAI,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC;CAAE,CAAC,GACvD,IAAI,GACJ,SAAS,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"groups.js","sourceRoot":"","sources":["../../../src/types/groups.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Represents a Group returned by the API.\n *\n * Group types are used to type Entry and Singleton objects when requesting\n * them using some SDK methods. See {@apilink DefaultModelDefinition}\n * for more info.\n *\n * @group Data Groups\n */\nexport type Group<Fields extends Record<string, unknown>> = Fields | undefined\n\n/**\n * Represents a Repeater Group returned by the API.\n *\n * Note that the API return empty repeaters as `null`.\n *\n * To retrieve the type of a `RepeaterGroup` item, use the\n * {@apilink RepeaterItem} utility type.\n *\n * Group types are used to type Entry and Singleton objects when requesting\n * them using some SDK methods. See {@apilink DefaultModelDefinition}\n * for more info.\n *\n * @group Data Groups\n */\nexport type RepeaterGroup<Fields extends Record<string, unknown>> =\n | Fields[]\n | null\n | undefined\n"]}
1
+ {"version":3,"file":"groups.js","sourceRoot":"","sources":["../../../src/types/groups.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Represents a Group returned by the API.\n *\n * Group types are used to type Entry and Singleton objects when requesting\n * them using some SDK methods. See {@apilink DefaultModelDefinition}\n * for more info.\n *\n * @group Data Groups\n */\nexport type Group<Fields extends Record<string, unknown>> =\n | { [Property in keyof Fields]: Fields[Property] }\n | undefined\n\n/**\n * Represents a Repeater Group returned by the API.\n *\n * Note that the API return empty repeaters as `null`.\n *\n * To retrieve the type of a `RepeaterGroup` item, use the\n * {@apilink RepeaterItem} utility type.\n *\n * Group types are used to type Entry and Singleton objects when requesting\n * them using some SDK methods. See {@apilink DefaultModelDefinition}\n * for more info.\n *\n * @group Data Groups\n */\nexport type RepeaterGroup<Fields extends Record<string, unknown>> =\n | Array<{ [Property in keyof Fields]: Fields[Property] }>\n | null\n | undefined\n"]}
@@ -1,12 +1,83 @@
1
1
  import { RepeaterGroup } from './groups';
2
+ import { Get, Paths } from 'type-fest';
3
+ /**
4
+ * Returns the type of the group or field in the given structure at the
5
+ * specified path. Use dot notation `.` to access items inside groups
6
+ * and bracket notation `[]` to access items inside repeaters.
7
+ *
8
+ * Syntax example:
9
+ * - foo
10
+ * - foo.bar
11
+ * - foo.bar[0].baz
12
+ * - foo.bar[0].baz.quo
13
+ *
14
+ * This utility is useful to get the type of a deeply nested group or field
15
+ * inside a Model, Singleton or Form structure.
16
+ *
17
+ * @example Retrieving the type of a deeply nested group or field.
18
+ * ```ts
19
+ * import { Group, StringField, GetFromStructure } from '@starlightcms/js-sdk'
20
+ *
21
+ * type ComplexModel = {
22
+ * info: Group<{
23
+ * title: StringField
24
+ * meta: Group<{
25
+ * keywords: StringField
26
+ * tags: RepeaterGroup<{
27
+ * name: StringField
28
+ * }>
29
+ * }>
30
+ * }>
31
+ * }
32
+ *
33
+ * type MetaGroupType = GetFromStructure<ComplexModel, 'info.meta'>
34
+ * // Resulting type -> Group<{ keywords: StringField, tags: RepeaterGroup<{ name: StringField }> }>
35
+ *
36
+ * type KeywordsFieldType = GetFromStructure<ComplexModel, 'info.meta.keywords'>
37
+ * // Resulting type -> StringField
38
+ *
39
+ * type TagNameFieldType = GetFromStructure<ComplexModel, 'info.meta.tags[0].name'>
40
+ * // Resulting type -> StringField
41
+ * ```
42
+ *
43
+ * @group Utility Types
44
+ */
45
+ export type GetFromStructure<Structure, Path extends Paths<Structure, {
46
+ bracketNotation: true;
47
+ maxRecursionDepth: 4;
48
+ }>> = Get<Structure, Path>;
2
49
  /**
3
50
  * Returns the item type of the given Repeater Group.
4
51
  *
5
- * For instance, given a `RepeaterGroup<Foo>`, this utility would return
6
- * the `Foo` type. This is useful to "pick" the type of the content held
7
- * by items of a Repeater Group.
52
+ * This utility is useful to get the type of the content
53
+ * held in items of a specific Repeater Group.
54
+ *
55
+ * @example Retrieving the type of a repeater item.
56
+ * ```ts
57
+ * import {
58
+ * RepeaterGroup,
59
+ * MediaField,
60
+ * StringField,
61
+ * GetRepeaterItem,
62
+ * GetFromStructure
63
+ * } from '@starlightcms/js-sdk'
64
+ *
65
+ * type SlideshowModel = {
66
+ * slides: RepeaterGroup<{
67
+ * image: MediaField
68
+ * description: StringField
69
+ * }>
70
+ * }
71
+ *
72
+ * type Slide = GetRepeaterItem<SlideshowModel['slides']>
73
+ * // Resulting type -> { image: MediaField, description: StringField }
74
+ *
75
+ * // Also works with the GetFromStructure utility
76
+ * type Slide = GetRepeaterItem<GetFromStructure<SlideshowModel, 'slides'>>
77
+ * // Resulting type -> { image: MediaField, description: StringField }
78
+ * ```
8
79
  *
9
80
  * @group Utility Types
10
81
  */
11
- export type RepeaterItem<Repeater extends RepeaterGroup<Record<string, unknown>>> = Repeater extends readonly (infer ItemType)[] ? ItemType : never;
82
+ export type GetRepeaterItem<Repeater extends RepeaterGroup<Record<string, unknown>>> = Repeater extends readonly (infer ItemType)[] ? ItemType : never;
12
83
  //# sourceMappingURL=utilities.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utilities.d.ts","sourceRoot":"","sources":["../../../src/types/utilities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAExC;;;;;;;;GAQG;AACH,MAAM,MAAM,YAAY,CACtB,QAAQ,SAAS,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,IACrD,QAAQ,SAAS,SAAS,CAAC,MAAM,QAAQ,CAAC,EAAE,GAAG,QAAQ,GAAG,KAAK,CAAA"}
1
+ {"version":3,"file":"utilities.d.ts","sourceRoot":"","sources":["../../../src/types/utilities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,WAAW,CAAA;AAEtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,MAAM,MAAM,gBAAgB,CAC1B,SAAS,EACT,IAAI,SAAS,KAAK,CAChB,SAAS,EACT;IAAE,eAAe,EAAE,IAAI,CAAC;IAAC,iBAAiB,EAAE,CAAC,CAAA;CAAE,CAChD,IACC,GAAG,CAAC,SAAS,EAAE,IAAI,CAAC,CAAA;AAExB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,MAAM,eAAe,CACzB,QAAQ,SAAS,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,IACrD,QAAQ,SAAS,SAAS,CAAC,MAAM,QAAQ,CAAC,EAAE,GAAG,QAAQ,GAAG,KAAK,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"utilities.js","sourceRoot":"","sources":["../../../src/types/utilities.ts"],"names":[],"mappings":"","sourcesContent":["import { RepeaterGroup } from './groups'\n\n/**\n * Returns the item type of the given Repeater Group.\n *\n * For instance, given a `RepeaterGroup<Foo>`, this utility would return\n * the `Foo` type. This is useful to \"pick\" the type of the content held\n * by items of a Repeater Group.\n *\n * @group Utility Types\n */\nexport type RepeaterItem<\n Repeater extends RepeaterGroup<Record<string, unknown>>,\n> = Repeater extends readonly (infer ItemType)[] ? ItemType : never\n"]}
1
+ {"version":3,"file":"utilities.js","sourceRoot":"","sources":["../../../src/types/utilities.ts"],"names":[],"mappings":"","sourcesContent":["import { RepeaterGroup } from './groups'\nimport { Get, Paths } from 'type-fest'\n\n/**\n * Returns the type of the group or field in the given structure at the\n * specified path. Use dot notation `.` to access items inside groups\n * and bracket notation `[]` to access items inside repeaters.\n *\n * Syntax example:\n * - foo\n * - foo.bar\n * - foo.bar[0].baz\n * - foo.bar[0].baz.quo\n *\n * This utility is useful to get the type of a deeply nested group or field\n * inside a Model, Singleton or Form structure.\n *\n * @example Retrieving the type of a deeply nested group or field.\n * ```ts\n * import { Group, StringField, GetFromStructure } from '@starlightcms/js-sdk'\n *\n * type ComplexModel = {\n * info: Group<{\n * title: StringField\n * meta: Group<{\n * keywords: StringField\n * tags: RepeaterGroup<{\n * name: StringField\n * }>\n * }>\n * }>\n * }\n *\n * type MetaGroupType = GetFromStructure<ComplexModel, 'info.meta'>\n * // Resulting type -> Group<{ keywords: StringField, tags: RepeaterGroup<{ name: StringField }> }>\n *\n * type KeywordsFieldType = GetFromStructure<ComplexModel, 'info.meta.keywords'>\n * // Resulting type -> StringField\n *\n * type TagNameFieldType = GetFromStructure<ComplexModel, 'info.meta.tags[0].name'>\n * // Resulting type -> StringField\n * ```\n *\n * @group Utility Types\n */\nexport type GetFromStructure<\n Structure,\n Path extends Paths<\n Structure,\n { bracketNotation: true; maxRecursionDepth: 4 }\n >,\n> = Get<Structure, Path>\n\n/**\n * Returns the item type of the given Repeater Group.\n *\n * This utility is useful to get the type of the content\n * held in items of a specific Repeater Group.\n *\n * @example Retrieving the type of a repeater item.\n * ```ts\n * import {\n * RepeaterGroup,\n * MediaField,\n * StringField,\n * GetRepeaterItem,\n * GetFromStructure\n * } from '@starlightcms/js-sdk'\n *\n * type SlideshowModel = {\n * slides: RepeaterGroup<{\n * image: MediaField\n * description: StringField\n * }>\n * }\n *\n * type Slide = GetRepeaterItem<SlideshowModel['slides']>\n * // Resulting type -> { image: MediaField, description: StringField }\n *\n * // Also works with the GetFromStructure utility\n * type Slide = GetRepeaterItem<GetFromStructure<SlideshowModel, 'slides'>>\n * // Resulting type -> { image: MediaField, description: StringField }\n * ```\n *\n * @group Utility Types\n */\nexport type GetRepeaterItem<\n Repeater extends RepeaterGroup<Record<string, unknown>>,\n> = Repeater extends readonly (infer ItemType)[] ? ItemType : never\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@starlightcms/js-sdk",
3
- "version": "4.0.0-beta.1",
3
+ "version": "4.0.0-beta.2",
4
4
  "description": "The Starlight SDK for JavaScript",
5
5
  "main": "dist/cjs/index.js",
6
6
  "exports": {
@@ -41,6 +41,9 @@
41
41
  "url": "https://github.com/starlightcms/js-sdk/issues"
42
42
  },
43
43
  "homepage": "https://github.com/starlightcms/js-sdk#readme",
44
+ "dependencies": {
45
+ "type-fest": "5.5.0"
46
+ },
44
47
  "devDependencies": {
45
48
  "@eslint/eslintrc": "^3.3.3",
46
49
  "@eslint/js": "^9.39.2",