@starlightcms/js-sdk 0.9.0 → 0.10.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.
Files changed (115) hide show
  1. package/dist/cjs/client.d.ts +41 -2
  2. package/dist/cjs/client.d.ts.map +1 -1
  3. package/dist/cjs/client.js +39 -0
  4. package/dist/cjs/client.js.map +1 -1
  5. package/dist/cjs/errors.d.ts +12 -0
  6. package/dist/cjs/errors.d.ts.map +1 -1
  7. package/dist/cjs/errors.js +7 -0
  8. package/dist/cjs/errors.js.map +1 -1
  9. package/dist/cjs/index.d.ts +21 -1
  10. package/dist/cjs/index.d.ts.map +1 -1
  11. package/dist/cjs/index.js +20 -0
  12. package/dist/cjs/index.js.map +1 -1
  13. package/dist/cjs/instances/Collection/index.d.ts +2 -2
  14. package/dist/cjs/instances/Collection/index.d.ts.map +1 -1
  15. package/dist/cjs/instances/Collection/index.js.map +1 -1
  16. package/dist/cjs/instances/Collection/types.d.ts +49 -5
  17. package/dist/cjs/instances/Collection/types.d.ts.map +1 -1
  18. package/dist/cjs/instances/Collection/types.js.map +1 -1
  19. package/dist/cjs/instances/Model/index.d.ts +3 -3
  20. package/dist/cjs/instances/Model/index.d.ts.map +1 -1
  21. package/dist/cjs/instances/Model/index.js.map +1 -1
  22. package/dist/cjs/instances/Model/types.d.ts +3 -3
  23. package/dist/cjs/instances/Model/types.js.map +1 -1
  24. package/dist/cjs/selectors/Collection/index.d.ts +3 -3
  25. package/dist/cjs/selectors/Collection/index.js.map +1 -1
  26. package/dist/cjs/selectors/Collection/types.d.ts +2 -2
  27. package/dist/cjs/selectors/Collection/types.d.ts.map +1 -1
  28. package/dist/cjs/selectors/Collection/types.js.map +1 -1
  29. package/dist/cjs/selectors/Model/index.d.ts +3 -3
  30. package/dist/cjs/selectors/Model/index.js.map +1 -1
  31. package/dist/cjs/selectors/Model/types.d.ts +3 -3
  32. package/dist/cjs/selectors/Model/types.js.map +1 -1
  33. package/dist/cjs/selectors/ModelCategory/index.d.ts +3 -3
  34. package/dist/cjs/selectors/ModelCategory/index.js.map +1 -1
  35. package/dist/cjs/selectors/ModelCategory/types.d.ts +1 -1
  36. package/dist/cjs/selectors/ModelCategory/types.js.map +1 -1
  37. package/dist/cjs/types/entities.d.ts +158 -0
  38. package/dist/cjs/types/entities.d.ts.map +1 -1
  39. package/dist/cjs/types/entities.js.map +1 -1
  40. package/dist/cjs/types/fields.d.ts +63 -0
  41. package/dist/cjs/types/fields.d.ts.map +1 -1
  42. package/dist/cjs/types/fields.js.map +1 -1
  43. package/dist/cjs/types/index.d.ts +424 -11
  44. package/dist/cjs/types/index.d.ts.map +1 -1
  45. package/dist/cjs/types/index.js +2 -0
  46. package/dist/cjs/types/index.js.map +1 -1
  47. package/dist/cjs/types/instances.d.ts +4 -0
  48. package/dist/cjs/types/instances.d.ts.map +1 -0
  49. package/dist/cjs/types/instances.js +3 -0
  50. package/dist/cjs/types/instances.js.map +1 -0
  51. package/dist/cjs/types/selectors.d.ts +8 -0
  52. package/dist/cjs/types/selectors.d.ts.map +1 -0
  53. package/dist/cjs/types/selectors.js +3 -0
  54. package/dist/cjs/types/selectors.js.map +1 -0
  55. package/dist/cjs/types/visual.d.ts +69 -0
  56. package/dist/cjs/types/visual.d.ts.map +1 -1
  57. package/dist/cjs/types/visual.js.map +1 -1
  58. package/dist/esm/client.d.ts +41 -2
  59. package/dist/esm/client.d.ts.map +1 -1
  60. package/dist/esm/client.js +39 -0
  61. package/dist/esm/client.js.map +1 -1
  62. package/dist/esm/errors.d.ts +12 -0
  63. package/dist/esm/errors.d.ts.map +1 -1
  64. package/dist/esm/errors.js +7 -0
  65. package/dist/esm/errors.js.map +1 -1
  66. package/dist/esm/index.d.ts +21 -1
  67. package/dist/esm/index.d.ts.map +1 -1
  68. package/dist/esm/index.js +20 -0
  69. package/dist/esm/index.js.map +1 -1
  70. package/dist/esm/instances/Collection/index.d.ts +2 -2
  71. package/dist/esm/instances/Collection/index.d.ts.map +1 -1
  72. package/dist/esm/instances/Collection/index.js.map +1 -1
  73. package/dist/esm/instances/Collection/types.d.ts +49 -5
  74. package/dist/esm/instances/Collection/types.d.ts.map +1 -1
  75. package/dist/esm/instances/Collection/types.js.map +1 -1
  76. package/dist/esm/instances/Model/index.d.ts +3 -3
  77. package/dist/esm/instances/Model/index.d.ts.map +1 -1
  78. package/dist/esm/instances/Model/index.js.map +1 -1
  79. package/dist/esm/instances/Model/types.d.ts +3 -3
  80. package/dist/esm/instances/Model/types.js.map +1 -1
  81. package/dist/esm/selectors/Collection/index.d.ts +3 -3
  82. package/dist/esm/selectors/Collection/index.js.map +1 -1
  83. package/dist/esm/selectors/Collection/types.d.ts +2 -2
  84. package/dist/esm/selectors/Collection/types.d.ts.map +1 -1
  85. package/dist/esm/selectors/Collection/types.js.map +1 -1
  86. package/dist/esm/selectors/Model/index.d.ts +3 -3
  87. package/dist/esm/selectors/Model/index.js.map +1 -1
  88. package/dist/esm/selectors/Model/types.d.ts +3 -3
  89. package/dist/esm/selectors/Model/types.js.map +1 -1
  90. package/dist/esm/selectors/ModelCategory/index.d.ts +3 -3
  91. package/dist/esm/selectors/ModelCategory/index.js.map +1 -1
  92. package/dist/esm/selectors/ModelCategory/types.d.ts +1 -1
  93. package/dist/esm/selectors/ModelCategory/types.js.map +1 -1
  94. package/dist/esm/types/entities.d.ts +158 -0
  95. package/dist/esm/types/entities.d.ts.map +1 -1
  96. package/dist/esm/types/entities.js.map +1 -1
  97. package/dist/esm/types/fields.d.ts +63 -0
  98. package/dist/esm/types/fields.d.ts.map +1 -1
  99. package/dist/esm/types/fields.js.map +1 -1
  100. package/dist/esm/types/index.d.ts +424 -11
  101. package/dist/esm/types/index.d.ts.map +1 -1
  102. package/dist/esm/types/index.js +2 -0
  103. package/dist/esm/types/index.js.map +1 -1
  104. package/dist/esm/types/instances.d.ts +4 -0
  105. package/dist/esm/types/instances.d.ts.map +1 -0
  106. package/dist/esm/types/instances.js +2 -0
  107. package/dist/esm/types/instances.js.map +1 -0
  108. package/dist/esm/types/selectors.d.ts +8 -0
  109. package/dist/esm/types/selectors.d.ts.map +1 -0
  110. package/dist/esm/types/selectors.js +2 -0
  111. package/dist/esm/types/selectors.js.map +1 -0
  112. package/dist/esm/types/visual.d.ts +69 -0
  113. package/dist/esm/types/visual.d.ts.map +1 -1
  114. package/dist/esm/types/visual.js.map +1 -1
  115. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/selectors/Model/index.ts"],"names":[],"mappings":"AAQA,OAAO,iBAAiB,MAAM,uBAAuB,CAAA;AAErD,MAAM,CAAC,OAAO,UAAU,iBAAiB,CACvC,MAAuB;IAEvB,MAAM,WAAW,GAAkB;QACjC,IAAI;YACF,OAAO,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;QAC9B,CAAC;QAED,GAAG,CAAC,IAAI;YACN,OAAO,MAAM,CAAC,GAAG,CAAC,WAAW,IAAI,EAAE,CAAC,CAAA;QACtC,CAAC;KACF,CAAA;IAED,OAAO,IAAI,KAAK,CAAC,WAAW,EAAE;QAC5B,GAAG,CAAC,MAAM,EAAE,IAAI;YACd,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE;gBAC1D,OAAO,iBAAiB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;aACvC;YAED,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;QAClC,CAAC;KACF,CAA4B,CAAA;AAC/B,CAAC","sourcesContent":["import {\n Model,\n StarlightClient,\n StarlightItemResponse,\n StarlightListResponse,\n WorkspaceModelDefinition,\n} from '../../types'\nimport { ModelSelector, ProxiedModelSelector } from './types'\nimport makeModelInstance from '../../instances/Model'\n\nexport default function makeModelSelector<D extends WorkspaceModelDefinition>(\n client: StarlightClient\n): ProxiedModelSelector<D> {\n const modelClient: ModelSelector = {\n list(): Promise<StarlightListResponse<Model>> {\n return client.get('/models')\n },\n\n get(slug): Promise<StarlightItemResponse<Model>> {\n return client.get(`/models/${slug}`)\n },\n }\n\n return new Proxy(modelClient, {\n get(target, prop) {\n if (typeof prop === 'string' && !Reflect.has(target, prop)) {\n return makeModelInstance(client, prop)\n }\n\n return Reflect.get(target, prop)\n },\n }) as ProxiedModelSelector<D>\n}\n\nexport { ModelSelector, ProxiedModelSelector }\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/selectors/Model/index.ts"],"names":[],"mappings":"AAQA,OAAO,iBAAiB,MAAM,uBAAuB,CAAA;AAErD,MAAM,CAAC,OAAO,UAAU,iBAAiB,CACvC,MAAuB;IAEvB,MAAM,WAAW,GAAkB;QACjC,IAAI;YACF,OAAO,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;QAC9B,CAAC;QAED,GAAG,CAAC,IAAI;YACN,OAAO,MAAM,CAAC,GAAG,CAAC,WAAW,IAAI,EAAE,CAAC,CAAA;QACtC,CAAC;KACF,CAAA;IAED,OAAO,IAAI,KAAK,CAAC,WAAW,EAAE;QAC5B,GAAG,CAAC,MAAM,EAAE,IAAI;YACd,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE;gBAC1D,OAAO,iBAAiB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;aACvC;YAED,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;QAClC,CAAC;KACF,CAA4B,CAAA;AAC/B,CAAC","sourcesContent":["import {\n Model,\n StarlightClient,\n StarlightItemResponse,\n StarlightListResponse,\n WorkspaceModelDefinition,\n} from '../../types'\nimport { ModelSelector, DynamicModelSelector } from './types'\nimport makeModelInstance from '../../instances/Model'\n\nexport default function makeModelSelector<D extends WorkspaceModelDefinition>(\n client: StarlightClient\n): DynamicModelSelector<D> {\n const modelClient: ModelSelector = {\n list(): Promise<StarlightListResponse<Model>> {\n return client.get('/models')\n },\n\n get(slug): Promise<StarlightItemResponse<Model>> {\n return client.get(`/models/${slug}`)\n },\n }\n\n return new Proxy(modelClient, {\n get(target, prop) {\n if (typeof prop === 'string' && !Reflect.has(target, prop)) {\n return makeModelInstance(client, prop)\n }\n\n return Reflect.get(target, prop)\n },\n }) as DynamicModelSelector<D>\n}\n\nexport { ModelSelector, DynamicModelSelector }\n"]}
@@ -1,10 +1,10 @@
1
1
  import { Model, StarlightItemResponse, StarlightListResponse, WorkspaceModelDefinition } from '../../types';
2
- import { ProxiedModelInstance } from '../../instances/Model';
2
+ import { DynamicModelInstance } from '../../instances/Model';
3
3
  export interface ModelSelector {
4
4
  list(): Promise<StarlightListResponse<Model>>;
5
5
  get(slug: string): Promise<StarlightItemResponse<Model>>;
6
6
  }
7
- export declare type ProxiedModelSelector<T extends WorkspaceModelDefinition> = ModelSelector & {
8
- [K in keyof T]: ProxiedModelInstance<T[K]>;
7
+ export declare type DynamicModelSelector<T extends WorkspaceModelDefinition> = ModelSelector & {
8
+ [K in keyof T]: DynamicModelInstance<T[K]>;
9
9
  };
10
10
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/selectors/Model/types.ts"],"names":[],"mappings":"","sourcesContent":["import {\n Model,\n StarlightItemResponse,\n StarlightListResponse,\n WorkspaceModelDefinition,\n} from '../../types'\nimport { ProxiedModelInstance } from '../../instances/Model'\n\nexport interface ModelSelector {\n list(): Promise<StarlightListResponse<Model>>\n get(slug: string): Promise<StarlightItemResponse<Model>>\n}\n\nexport type ProxiedModelSelector<T extends WorkspaceModelDefinition> =\n ModelSelector & {\n [K in keyof T]: ProxiedModelInstance<T[K]>\n }\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/selectors/Model/types.ts"],"names":[],"mappings":"","sourcesContent":["import {\n Model,\n StarlightItemResponse,\n StarlightListResponse,\n WorkspaceModelDefinition,\n} from '../../types'\nimport { DynamicModelInstance } from '../../instances/Model'\n\nexport interface ModelSelector {\n list(): Promise<StarlightListResponse<Model>>\n get(slug: string): Promise<StarlightItemResponse<Model>>\n}\n\nexport type DynamicModelSelector<T extends WorkspaceModelDefinition> =\n ModelSelector & {\n [K in keyof T]: DynamicModelInstance<T[K]>\n }\n"]}
@@ -1,5 +1,5 @@
1
1
  import { SerializedData, StarlightClient } from '../../types';
2
- import { ModelCategorySelector, ProxiedModelCategorySelector } from './types';
3
- export default function makeModelCategorySelector<D extends SerializedData>(client: StarlightClient, model: string): ProxiedModelCategorySelector<D>;
4
- export { ModelCategorySelector, ProxiedModelCategorySelector };
2
+ import { ModelCategorySelector, DynamicModelCategorySelector } from './types';
3
+ export default function makeModelCategorySelector<D extends SerializedData>(client: StarlightClient, model: string): DynamicModelCategorySelector<D>;
4
+ export { ModelCategorySelector, DynamicModelCategorySelector };
5
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/selectors/ModelCategory/index.ts"],"names":[],"mappings":"AAQA,OAAO,yBAAyB,MAAM,+BAA+B,CAAA;AAErE,MAAM,CAAC,OAAO,UAAU,yBAAyB,CAC/C,MAAuB,EACvB,KAAa;IAEb,MAAM,QAAQ,GAA0B;QACtC,IAAI,CAAC,OAAO;YACV,OAAO,MAAM,CAAC,GAAG,CAAC,WAAW,KAAK,aAAa,EAAE,OAAO,CAAC,CAAA;QAC3D,CAAC;QAED,GAAG,CAAC,IAAI;YACN,OAAO,MAAM,CAAC,GAAG,CAAC,WAAW,KAAK,eAAe,IAAI,EAAE,CAAC,CAAA;QAC1D,CAAC;KACF,CAAA;IAED,OAAO,IAAI,KAAK,CAAC,QAAQ,EAAE;QACzB,GAAG,CAAC,MAAM,EAAE,IAAI;YACd,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE;gBAC1D,OAAO,yBAAyB,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,CAAA;aACtD;YAED,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;QAClC,CAAC;KACF,CAAoC,CAAA;AACvC,CAAC","sourcesContent":["import {\n ModelCategory,\n SerializedData,\n StarlightClient,\n StarlightItemResponse,\n StarlightListResponse,\n} from '../../types'\nimport { ModelCategorySelector, ProxiedModelCategorySelector } from './types'\nimport makeModelCategoryInstance from '../../instances/ModelCategory'\n\nexport default function makeModelCategorySelector<D extends SerializedData>(\n client: StarlightClient,\n model: string\n): ProxiedModelCategorySelector<D> {\n const selector: ModelCategorySelector = {\n list(options): Promise<StarlightListResponse<ModelCategory>> {\n return client.get(`/models/${model}/categories`, options)\n },\n\n get(slug): Promise<StarlightItemResponse<ModelCategory>> {\n return client.get(`/models/${model}/categories/${slug}`)\n },\n }\n\n return new Proxy(selector, {\n get(target, prop) {\n if (typeof prop === 'string' && !Reflect.has(target, prop)) {\n return makeModelCategoryInstance(client, model, prop)\n }\n\n return Reflect.get(target, prop)\n },\n }) as ProxiedModelCategorySelector<D>\n}\n\nexport { ModelCategorySelector, ProxiedModelCategorySelector }\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/selectors/ModelCategory/index.ts"],"names":[],"mappings":"AAQA,OAAO,yBAAyB,MAAM,+BAA+B,CAAA;AAErE,MAAM,CAAC,OAAO,UAAU,yBAAyB,CAC/C,MAAuB,EACvB,KAAa;IAEb,MAAM,QAAQ,GAA0B;QACtC,IAAI,CAAC,OAAO;YACV,OAAO,MAAM,CAAC,GAAG,CAAC,WAAW,KAAK,aAAa,EAAE,OAAO,CAAC,CAAA;QAC3D,CAAC;QAED,GAAG,CAAC,IAAI;YACN,OAAO,MAAM,CAAC,GAAG,CAAC,WAAW,KAAK,eAAe,IAAI,EAAE,CAAC,CAAA;QAC1D,CAAC;KACF,CAAA;IAED,OAAO,IAAI,KAAK,CAAC,QAAQ,EAAE;QACzB,GAAG,CAAC,MAAM,EAAE,IAAI;YACd,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE;gBAC1D,OAAO,yBAAyB,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,CAAA;aACtD;YAED,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;QAClC,CAAC;KACF,CAAoC,CAAA;AACvC,CAAC","sourcesContent":["import {\n ModelCategory,\n SerializedData,\n StarlightClient,\n StarlightItemResponse,\n StarlightListResponse,\n} from '../../types'\nimport { ModelCategorySelector, DynamicModelCategorySelector } from './types'\nimport makeModelCategoryInstance from '../../instances/ModelCategory'\n\nexport default function makeModelCategorySelector<D extends SerializedData>(\n client: StarlightClient,\n model: string\n): DynamicModelCategorySelector<D> {\n const selector: ModelCategorySelector = {\n list(options): Promise<StarlightListResponse<ModelCategory>> {\n return client.get(`/models/${model}/categories`, options)\n },\n\n get(slug): Promise<StarlightItemResponse<ModelCategory>> {\n return client.get(`/models/${model}/categories/${slug}`)\n },\n }\n\n return new Proxy(selector, {\n get(target, prop) {\n if (typeof prop === 'string' && !Reflect.has(target, prop)) {\n return makeModelCategoryInstance(client, model, prop)\n }\n\n return Reflect.get(target, prop)\n },\n }) as DynamicModelCategorySelector<D>\n}\n\nexport { ModelCategorySelector, DynamicModelCategorySelector }\n"]}
@@ -10,7 +10,7 @@ export interface ModelCategorySelector {
10
10
  list(options?: ListModelCategoriesOptions): Promise<StarlightListResponse<ModelCategory>>;
11
11
  get(slug: string): Promise<StarlightItemResponse<ModelCategory>>;
12
12
  }
13
- export declare type ProxiedModelCategorySelector<D extends SerializedData> = ModelCategorySelector & {
13
+ export declare type DynamicModelCategorySelector<D extends SerializedData> = ModelCategorySelector & {
14
14
  [slug: string]: ModelCategoryInstance<D>;
15
15
  };
16
16
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/selectors/ModelCategory/types.ts"],"names":[],"mappings":"","sourcesContent":["import {\n ModelCategory,\n SerializedData,\n StarlightItemResponse,\n StarlightListResponse,\n} from '../../types'\nimport { ModelCategoryInstance } from '../../instances/ModelCategory'\n\nexport type ListModelCategoriesOptions = {\n query?: string\n page?: number\n limit?: number\n order?: 'title:asc' | 'title:desc' | 'entry_count:asc' | 'entry_count:desc'\n}\n\nexport interface ModelCategorySelector {\n list(\n options?: ListModelCategoriesOptions\n ): Promise<StarlightListResponse<ModelCategory>>\n get(slug: string): Promise<StarlightItemResponse<ModelCategory>>\n}\n\nexport type ProxiedModelCategorySelector<D extends SerializedData> =\n ModelCategorySelector & {\n [slug: string]: ModelCategoryInstance<D>\n }\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/selectors/ModelCategory/types.ts"],"names":[],"mappings":"","sourcesContent":["import {\n ModelCategory,\n SerializedData,\n StarlightItemResponse,\n StarlightListResponse,\n} from '../../types'\nimport { ModelCategoryInstance } from '../../instances/ModelCategory'\n\nexport type ListModelCategoriesOptions = {\n query?: string\n page?: number\n limit?: number\n order?: 'title:asc' | 'title:desc' | 'entry_count:asc' | 'entry_count:desc'\n}\n\nexport interface ModelCategorySelector {\n list(\n options?: ListModelCategoriesOptions\n ): Promise<StarlightListResponse<ModelCategory>>\n get(slug: string): Promise<StarlightItemResponse<ModelCategory>>\n}\n\nexport type DynamicModelCategorySelector<D extends SerializedData> =\n ModelCategorySelector & {\n [slug: string]: ModelCategoryInstance<D>\n }\n"]}
@@ -1,13 +1,28 @@
1
+ /**
2
+ * Base interface used by all entities returned by the API.
3
+ *
4
+ * @internal
5
+ */
1
6
  interface StarlightEntity {
2
7
  id: number;
3
8
  created_at: string;
4
9
  updated_at?: string;
5
10
  }
11
+ /**
12
+ * Represents a Model Category entity returned by the API.
13
+ *
14
+ * @group API Entities
15
+ */
6
16
  export interface ModelCategory extends StarlightEntity {
7
17
  title: string;
8
18
  slug: string;
9
19
  entry_count?: number;
10
20
  }
21
+ /**
22
+ * Represents a Media File entity returned by the API.
23
+ *
24
+ * @group API Entities
25
+ */
11
26
  export interface MediaFile extends StarlightEntity {
12
27
  variation: string;
13
28
  path: string;
@@ -16,6 +31,11 @@ export interface MediaFile extends StarlightEntity {
16
31
  filesize: number;
17
32
  meta?: Record<string, unknown>;
18
33
  }
34
+ /**
35
+ * Represents a Media Object entity returned by the API.
36
+ *
37
+ * @group API Entities
38
+ */
19
39
  export interface MediaObject extends StarlightEntity {
20
40
  name: string;
21
41
  extension: string;
@@ -24,19 +44,84 @@ export interface MediaObject extends StarlightEntity {
24
44
  alt?: string;
25
45
  description?: string;
26
46
  }
47
+ /**
48
+ * Represents an Author entity returned by the API.
49
+ *
50
+ * @group API Entities
51
+ */
27
52
  export interface Author {
28
53
  id: number;
29
54
  name: string;
30
55
  }
56
+ /**
57
+ * Represents a Model entity returned by the API.
58
+ *
59
+ * @group API Entities
60
+ */
31
61
  export interface Model extends StarlightEntity {
32
62
  title: string;
33
63
  slug: string;
34
64
  entry_count?: number;
35
65
  }
66
+ /**
67
+ * Represents content data returned by either an Entry or
68
+ * Singleton entity from the API.
69
+ */
36
70
  export declare type SerializedData = Record<string, unknown> | undefined;
71
+ /**
72
+ * Utility type that creates a string map of all fields of the given
73
+ * SerializedData type with the `field` suffix. This is only useful to create
74
+ * request methods that support field querying using the "field:foo" syntax.
75
+ *
76
+ * @internal
77
+ */
37
78
  export declare type ModelFieldOptions<D extends SerializedData> = {
38
79
  [K in keyof D as `field:${string & K}`]?: string;
39
80
  };
81
+ /**
82
+ * Represents an Entry entity returned by the API.
83
+ *
84
+ * An Entry's `data` field can be further typed by passing an object-like
85
+ * structure as the D generic type. This is useful to provide type-safety to
86
+ * your application, since the `data` field is a generic JS object by default.
87
+ *
88
+ * It's recommended to use the Field types provided by this SDK to type your
89
+ * entities using a type definition file on your project. For instance:
90
+ *
91
+ * ```ts
92
+ * // starlight.d.ts file
93
+ * import { VisualField, MediaField } from '@starlightcms/js-sdk'
94
+ *
95
+ * type PostFields = {
96
+ * featured_image: MediaField
97
+ * content: VisualField
98
+ * }
99
+ *
100
+ * declare module '@starlightcms/js-sdk' {
101
+ * export interface DefaultModelDefinition {
102
+ * posts: PostFields
103
+ * }
104
+ * }
105
+ * ```
106
+ *
107
+ * You can place this type definition file anywhere in your repository, but it's
108
+ * good practice to place it at the same level as your root index.ts file. Then,
109
+ * in your files, all SDK calls will correctly type `posts`:
110
+ *
111
+ * ```ts
112
+ * import Starlight from '@starlightcms/js-sdk'
113
+ *
114
+ * // response type will be StarlightItemResponse<Entry<PostFields>> on request success
115
+ * const response = await Starlight.posts.entries.get('hello-world')
116
+ *
117
+ * // helloWorld type is Entry<PostFields>
118
+ * const helloWorld = response.data
119
+ * ```
120
+ *
121
+ * See {@apilink DefaultModelDefinition} for more info.
122
+ *
123
+ * @group API Entities
124
+ */
40
125
  export interface Entry<D extends SerializedData> extends Omit<StarlightEntity, 'created_at'> {
41
126
  title: string;
42
127
  slug: string;
@@ -46,21 +131,94 @@ export interface Entry<D extends SerializedData> extends Omit<StarlightEntity, '
46
131
  category: ModelCategory | null;
47
132
  published_at: string | null;
48
133
  }
134
+ /**
135
+ * Represents a Singleton entity returned by the API.
136
+ *
137
+ * A Singleton's `data` field can be further typed by passing an object-like
138
+ * structure as the D generic type. This is useful to provide type-safety to
139
+ * your application, since the `data` field is a generic JS object by default.
140
+ *
141
+ * It's recommended to use the Field types provided by this SDK to type your
142
+ * Singletons. For instance:
143
+ *
144
+ * ```ts
145
+ * import { StringField, VisualField, MediaField } from '@starlightcms/js-sdk'
146
+ *
147
+ * type HomeFields = {
148
+ * site_title: StringField
149
+ * hero_image: MediaField
150
+ * hero_content: VisualField
151
+ * }
152
+ *
153
+ * // response type will be StarlightItemResponse<Singleton<HomeFields>> on request success
154
+ * const response = Starlight.singletons.get<HomeFields>('home')
155
+ *
156
+ * // home type is Singleton<HomeFields>
157
+ * const home = response.data
158
+ * ```
159
+ *
160
+ * You could also place all your Singleton field types in the same type
161
+ * definition file used to configure Entry fields, which makes it easier to
162
+ * import these types in other files on your project. See
163
+ * {@apilink DefaultModelDefinition} for more info.
164
+ *
165
+ * @group API Entities
166
+ */
49
167
  export interface Singleton<D extends SerializedData> extends Omit<StarlightEntity, 'created_at'> {
50
168
  title: string;
51
169
  slug: string;
52
170
  data: D;
53
171
  published_at: string | null;
54
172
  }
173
+ /**
174
+ * Currently supported Collection types. This type is mainly used to provide
175
+ * autocompletion on IDEs, since it lets users use any string as well as the
176
+ * known supported types.
177
+ *
178
+ * @internal
179
+ */
55
180
  export declare type CollectionTypes = 'entry' | 'singleton' | 'media' | string;
181
+ /**
182
+ * Currently supported Collection entities. This type is mainly used to infer
183
+ * the collection type string (see {@link CollectionTypes}) from the type of
184
+ * entity that that Collection holds.
185
+ *
186
+ * @internal
187
+ */
188
+ export declare type CollectionEntityTypes = Entry<never> | Singleton<never> | MediaObject | unknown;
189
+ /**
190
+ * Infers a Collection type from an entity type. See {@link CollectionTypes} and
191
+ * {@link CollectionEntityTypes} to know more.
192
+ *
193
+ * @internal
194
+ */
195
+ export declare type CollectionTypeMapper<T extends CollectionEntityTypes> = T extends Entry<any> ? 'entry' : T extends Singleton<any> ? 'singleton' : T extends MediaObject ? 'media' : string;
196
+ /**
197
+ * Represents a Collection entity returned by the API.
198
+ *
199
+ * @group API Entities
200
+ */
56
201
  export interface Collection<T extends CollectionTypes = string> extends StarlightEntity {
57
202
  title: string;
58
203
  slug: string;
59
204
  type: T;
60
205
  item_count?: number;
61
206
  }
207
+ /**
208
+ * Currently supported Relation types.
209
+ */
62
210
  declare type RelationTypes = Entry<never> | Singleton<never> | MediaObject | Collection | unknown;
211
+ /**
212
+ * Represents a Relation entity returned by the API.
213
+ *
214
+ * @group API Entities
215
+ */
63
216
  export interface Relation<T extends RelationTypes> {
217
+ /**
218
+ * The relation type, which is always a string. If the `object` field of this
219
+ * Relation is an Entry, type will be `entry`, if it's a Singleton, type will
220
+ * be `singleton`, and so on.
221
+ */
64
222
  type: T extends Entry<never> ? 'entry' : T extends Singleton<never> ? 'singleton' : T extends MediaObject ? 'media' : T extends Collection ? 'collection' : string;
65
223
  id: number;
66
224
  object: T;
@@ -1 +1 @@
1
- {"version":3,"file":"entities.d.ts","sourceRoot":"","sources":["../../../src/types/entities.ts"],"names":[],"mappings":"AAAA,UAAU,eAAe;IACvB,EAAE,EAAE,MAAM,CAAA;IACV,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAED,MAAM,WAAW,aAAc,SAAQ,eAAe;IACpD,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAED,MAAM,WAAW,SAAU,SAAQ,eAAe;IAChD,SAAS,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAC/B;AAED,MAAM,WAAW,WAAY,SAAQ,eAAe;IAClD,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,SAAS,EAAE,CAAA;IAClB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAED,MAAM,WAAW,MAAM;IACrB,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;CACb;AAED,MAAM,WAAW,KAAM,SAAQ,eAAe;IAC5C,KAAK,EAAE,MAAM,C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ts"],"names":[],"mappings":"","sourcesContent":["interface StarlightEntity {\n id: number\n created_at: string\n updated_at?: string\n}\n\nexport interface ModelCategory extends StarlightEntity {\n title: string\n slug: string\n entry_count?: number\n}\n\nexport interface MediaFile extends StarlightEntity {\n variation: string\n path: string\n mime: string\n background_color?: string\n filesize: number\n meta?: Record<string, unknown>\n}\n\nexport interface MediaObject extends StarlightEntity {\n name: string\n extension: string\n mime: string\n files: MediaFile[]\n alt?: string\n description?: string\n}\n\nexport interface Author {\n id: number\n name: string\n}\n\nexport interface Model extends StarlightEntity {\n title: string\n slug: string\n entry_count?: number\n}\n\nexport type SerializedData = Record<string, unknown> | undefined\n\nexport type ModelFieldOptions<D extends SerializedData> = {\n [K in keyof D as `field:${string & K}`]?: string\n}\n\nexport interface Entry<D extends SerializedData>\n extends Omit<StarlightEntity, 'created_at'> {\n title: string\n slug: string\n data: D\n author: Author\n model?: Model\n category: ModelCategory | null\n published_at: string | null\n}\n\nexport interface Singleton<D extends SerializedData>\n extends Omit<StarlightEntity, 'created_at'> {\n title: string\n slug: string\n data: D\n published_at: string | null\n}\n\nexport type CollectionTypes = 'entry' | 'singleton' | 'media' | string\n\nexport interface Collection<T extends CollectionTypes = string>\n extends StarlightEntity {\n title: string\n slug: string\n type: T\n item_count?: number\n}\n\ntype RelationTypes =\n | Entry<never>\n | Singleton<never>\n | MediaObject\n | Collection\n | unknown\n\nexport interface Relation<T extends RelationTypes> {\n type: T extends Entry<never>\n ? 'entry'\n : T extends Singleton<never>\n ? 'singleton'\n : T extends MediaObject\n ? 'media'\n : T extends Collection\n ? 'collection'\n : string\n id: number\n object: T\n}\n"]}
1
+ {"version":3,"file":"entities.js","sourceRoot":"","sources":["../../../src/types/entities.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Base interface used by all entities returned by the API.\n *\n * @internal\n */\ninterface StarlightEntity {\n id: number\n created_at: string\n updated_at?: string\n}\n\n/**\n * Represents a Model Category entity returned by the API.\n *\n * @group API Entities\n */\nexport interface ModelCategory extends StarlightEntity {\n title: string\n slug: string\n entry_count?: number\n}\n\n/**\n * Represents a Media File entity returned by the API.\n *\n * @group API Entities\n */\nexport interface MediaFile extends StarlightEntity {\n variation: string\n path: string\n mime: string\n background_color?: string\n filesize: number\n meta?: Record<string, unknown>\n}\n\n/**\n * Represents a Media Object entity returned by the API.\n *\n * @group API Entities\n */\nexport interface MediaObject extends StarlightEntity {\n name: string\n extension: string\n mime: string\n files: MediaFile[]\n alt?: string\n description?: string\n}\n\n/**\n * Represents an Author entity returned by the API.\n *\n * @group API Entities\n */\nexport interface Author {\n id: number\n name: string\n}\n\n/**\n * Represents a Model entity returned by the API.\n *\n * @group API Entities\n */\nexport interface Model extends StarlightEntity {\n title: string\n slug: string\n entry_count?: number\n}\n\n/**\n * Represents content data returned by either an Entry or\n * Singleton entity from the API.\n */\nexport type SerializedData = Record<string, unknown> | undefined\n\n/**\n * Utility type that creates a string map of all fields of the given\n * SerializedData type with the `field` suffix. This is only useful to create\n * request methods that support field querying using the \"field:foo\" syntax.\n *\n * @internal\n */\nexport type ModelFieldOptions<D extends SerializedData> = {\n [K in keyof D as `field:${string & K}`]?: string\n}\n\n/**\n * Represents an Entry entity returned by the API.\n *\n * An Entry's `data` field can be further typed by passing an object-like\n * structure as the D generic type. This is useful to provide type-safety to\n * your application, since the `data` field is a generic JS object by default.\n *\n * It's recommended to use the Field types provided by this SDK to type your\n * entities using a type definition file on your project. For instance:\n *\n * ```ts\n * // starlight.d.ts file\n * import { VisualField, MediaField } from '@starlightcms/js-sdk'\n *\n * type PostFields = {\n * featured_image: MediaField\n * content: VisualField\n * }\n *\n * declare module '@starlightcms/js-sdk' {\n * export interface DefaultModelDefinition {\n * posts: PostFields\n * }\n * }\n * ```\n *\n * You can place this type definition file anywhere in your repository, but it's\n * good practice to place it at the same level as your root index.ts file. Then,\n * in your files, all SDK calls will correctly type `posts`:\n *\n * ```ts\n * import Starlight from '@starlightcms/js-sdk'\n *\n * // response type will be StarlightItemResponse<Entry<PostFields>> on request success\n * const response = await Starlight.posts.entries.get('hello-world')\n *\n * // helloWorld type is Entry<PostFields>\n * const helloWorld = response.data\n * ```\n *\n * See {@apilink DefaultModelDefinition} for more info.\n *\n * @group API Entities\n */\nexport interface Entry<D extends SerializedData>\n extends Omit<StarlightEntity, 'created_at'> {\n title: string\n slug: string\n data: D\n author: Author\n model?: Model\n category: ModelCategory | null\n published_at: string | null\n}\n\n/**\n * Represents a Singleton entity returned by the API.\n *\n * A Singleton's `data` field can be further typed by passing an object-like\n * structure as the D generic type. This is useful to provide type-safety to\n * your application, since the `data` field is a generic JS object by default.\n *\n * It's recommended to use the Field types provided by this SDK to type your\n * Singletons. For instance:\n *\n * ```ts\n * import { StringField, VisualField, MediaField } from '@starlightcms/js-sdk'\n *\n * type HomeFields = {\n * site_title: StringField\n * hero_image: MediaField\n * hero_content: VisualField\n * }\n *\n * // response type will be StarlightItemResponse<Singleton<HomeFields>> on request success\n * const response = Starlight.singletons.get<HomeFields>('home')\n *\n * // home type is Singleton<HomeFields>\n * const home = response.data\n * ```\n *\n * You could also place all your Singleton field types in the same type\n * definition file used to configure Entry fields, which makes it easier to\n * import these types in other files on your project. See\n * {@apilink DefaultModelDefinition} for more info.\n *\n * @group API Entities\n */\nexport interface Singleton<D extends SerializedData>\n extends Omit<StarlightEntity, 'created_at'> {\n title: string\n slug: string\n data: D\n published_at: string | null\n}\n\n/**\n * Currently supported Collection types. This type is mainly used to provide\n * autocompletion on IDEs, since it lets users use any string as well as the\n * known supported types.\n *\n * @internal\n */\nexport type CollectionTypes = 'entry' | 'singleton' | 'media' | string\n\n/**\n * Currently supported Collection entities. This type is mainly used to infer\n * the collection type string (see {@link CollectionTypes}) from the type of\n * entity that that Collection holds.\n *\n * @internal\n */\nexport type CollectionEntityTypes =\n | Entry<never>\n | Singleton<never>\n | MediaObject\n | unknown\n\n/**\n * Infers a Collection type from an entity type. See {@link CollectionTypes} and\n * {@link CollectionEntityTypes} to know more.\n *\n * @internal\n */\nexport type CollectionTypeMapper<T extends CollectionEntityTypes> =\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Entry<any>\n ? 'entry'\n : T extends Singleton<any> // eslint-disable-line @typescript-eslint/no-explicit-any\n ? 'singleton'\n : T extends MediaObject\n ? 'media'\n : string\n\n/**\n * Represents a Collection entity returned by the API.\n *\n * @group API Entities\n */\nexport interface Collection<T extends CollectionTypes = string>\n extends StarlightEntity {\n title: string\n slug: string\n type: T\n item_count?: number\n}\n\n/**\n * Currently supported Relation types.\n */\ntype RelationTypes =\n | Entry<never>\n | Singleton<never>\n | MediaObject\n | Collection\n | unknown\n\n/**\n * Represents a Relation entity returned by the API.\n *\n * @group API Entities\n */\nexport interface Relation<T extends RelationTypes> {\n /**\n * The relation type, which is always a string. If the `object` field of this\n * Relation is an Entry, type will be `entry`, if it's a Singleton, type will\n * be `singleton`, and so on.\n */\n type: T extends Entry<never>\n ? 'entry'\n : T extends Singleton<never>\n ? 'singleton'\n : T extends MediaObject\n ? 'media'\n : T extends Collection\n ? 'collection'\n : string\n id: number\n object: T\n}\n"]}
@@ -1,10 +1,73 @@
1
1
  import { MediaObject, Relation } from './entities';
2
2
  import { VisualData } from './visual';
3
+ /**
4
+ * Represents a Boolean Field returned by the API.
5
+ *
6
+ * Field types are used to type Entry and Singleton objects when requesting
7
+ * them using some SDK methods. See {@apilink DefaultModelDefinition}
8
+ * for more info.
9
+ *
10
+ * @group Data Fields
11
+ */
3
12
  export declare type BooleanField = boolean;
13
+ /**
14
+ * Represents a HTML Field returned by the API.
15
+ *
16
+ * Field types are used to type Entry and Singleton objects when requesting
17
+ * them using some SDK methods. See {@apilink DefaultModelDefinition}
18
+ * for more info.
19
+ *
20
+ * @group Data Fields
21
+ */
4
22
  export declare type HtmlField = string;
23
+ /**
24
+ * Represents a Media Field returned by the API.
25
+ *
26
+ * Field types are used to type Entry and Singleton objects when requesting
27
+ * them using some SDK methods. See {@apilink DefaultModelDefinition}
28
+ * for more info.
29
+ *
30
+ * @group Data Fields
31
+ */
5
32
  export declare type MediaField = MediaObject;
33
+ /**
34
+ * Represents a Relation Field returned by the API.
35
+ *
36
+ * Field types are used to type Entry and Singleton objects when requesting
37
+ * them using some SDK methods. See {@apilink DefaultModelDefinition}
38
+ * for more info.
39
+ *
40
+ * @group Data Fields
41
+ */
6
42
  export declare type RelationField<T> = Relation<T>;
43
+ /**
44
+ * Represents a String Field returned by the API.
45
+ *
46
+ * Field types are used to type Entry and Singleton objects when requesting
47
+ * them using some SDK methods. See {@apilink DefaultModelDefinition}
48
+ * for more info.
49
+ *
50
+ * @group Data Fields
51
+ */
7
52
  export declare type StringField = string;
53
+ /**
54
+ * Represents a Text Field returned by the API.
55
+ *
56
+ * Field types are used to type Entry and Singleton objects when requesting
57
+ * them using some SDK methods. See {@apilink DefaultModelDefinition}
58
+ * for more info.
59
+ *
60
+ * @group Data Fields
61
+ */
8
62
  export declare type TextField = string;
63
+ /**
64
+ * Represents a Visual Field returned by the API.
65
+ *
66
+ * Field types are used to type Entry and Singleton objects when requesting
67
+ * them using some SDK methods. See {@apilink DefaultModelDefinition}
68
+ * for more info.
69
+ *
70
+ * @group Data Fields
71
+ */
9
72
  export declare type VisualField = VisualData;
10
73
  //# 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,oBAAY,YAAY,GAAG,OAAO,CAAA;AAElC,oBAAY,SAAS,GAAG,MAAM,CAAA;AAE9B,oBAAY,UAAU,GAAG,WAAW,CAAA;AAEpC,oBAAY,aAAa,CAAC,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC,CAAA;AAE1C,oBAAY,WAAW,GAAG,MAAM,CAAA;AAEhC,oBAAY,SAAS,GAAG,MAAM,CAAA;AAE9B,oBAAY,WAAW,GAAG,UAAU,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,oBAAY,YAAY,GAAG,OAAO,CAAA;AAElC;;;;;;;;GAQG;AACH,oBAAY,SAAS,GAAG,MAAM,CAAA;AAE9B;;;;;;;;GAQG;AACH,oBAAY,UAAU,GAAG,WAAW,CAAA;AAEpC;;;;;;;;GAQG;AACH,oBAAY,aAAa,CAAC,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC,CAAA;AAE1C;;;;;;;;GAQG;AACH,oBAAY,WAAW,GAAG,MAAM,CAAA;AAEhC;;;;;;;;GAQG;AACH,oBAAY,SAAS,GAAG,MAAM,CAAA;AAE9B;;;;;;;;GAQG;AACH,oBAAY,WAAW,GAAG,UAAU,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\nexport type BooleanField = boolean\n\nexport type HtmlField = string\n\nexport type MediaField = MediaObject\n\nexport type RelationField<T> = Relation<T>\n\nexport type StringField = string\n\nexport type TextField = string\n\nexport type VisualField = VisualData\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\n\n/**\n * Represents a 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\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\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>\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\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\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\n"]}