@starlightcms/js-sdk 4.0.0-beta.2 → 4.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +397 -0
- package/dist/index.d.cts +5087 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +5087 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +391 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +18 -13
- package/dist/cjs/client.d.ts +0 -42
- package/dist/cjs/client.d.ts.map +0 -1
- package/dist/cjs/client.js +0 -145
- package/dist/cjs/client.js.map +0 -1
- package/dist/cjs/errors.d.ts +0 -40
- package/dist/cjs/errors.d.ts.map +0 -1
- package/dist/cjs/errors.js +0 -18
- package/dist/cjs/errors.js.map +0 -1
- package/dist/cjs/index.d.ts +0 -29
- package/dist/cjs/index.d.ts.map +0 -1
- package/dist/cjs/index.js +0 -47
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/instances/Collection/index.d.ts +0 -5
- package/dist/cjs/instances/Collection/index.d.ts.map +0 -1
- package/dist/cjs/instances/Collection/index.js +0 -14
- package/dist/cjs/instances/Collection/index.js.map +0 -1
- package/dist/cjs/instances/Collection/types.d.ts +0 -79
- package/dist/cjs/instances/Collection/types.d.ts.map +0 -1
- package/dist/cjs/instances/Collection/types.js +0 -3
- package/dist/cjs/instances/Collection/types.js.map +0 -1
- package/dist/cjs/instances/Form/index.d.ts +0 -5
- package/dist/cjs/instances/Form/index.d.ts.map +0 -1
- package/dist/cjs/instances/Form/index.js +0 -14
- package/dist/cjs/instances/Form/index.js.map +0 -1
- package/dist/cjs/instances/Form/types.d.ts +0 -46
- package/dist/cjs/instances/Form/types.d.ts.map +0 -1
- package/dist/cjs/instances/Form/types.js +0 -3
- package/dist/cjs/instances/Form/types.js.map +0 -1
- package/dist/cjs/instances/Model/index.d.ts +0 -5
- package/dist/cjs/instances/Model/index.d.ts.map +0 -1
- package/dist/cjs/instances/Model/index.js +0 -34
- package/dist/cjs/instances/Model/index.js.map +0 -1
- package/dist/cjs/instances/Model/types.d.ts +0 -102
- package/dist/cjs/instances/Model/types.d.ts.map +0 -1
- package/dist/cjs/instances/Model/types.js +0 -3
- package/dist/cjs/instances/Model/types.js.map +0 -1
- package/dist/cjs/instances/ModelCategory/index.d.ts +0 -5
- package/dist/cjs/instances/ModelCategory/index.d.ts.map +0 -1
- package/dist/cjs/instances/ModelCategory/index.js +0 -14
- package/dist/cjs/instances/ModelCategory/index.js.map +0 -1
- package/dist/cjs/instances/ModelCategory/types.d.ts +0 -76
- package/dist/cjs/instances/ModelCategory/types.d.ts.map +0 -1
- package/dist/cjs/instances/ModelCategory/types.js +0 -3
- package/dist/cjs/instances/ModelCategory/types.js.map +0 -1
- package/dist/cjs/selectors/Collection/index.d.ts +0 -5
- package/dist/cjs/selectors/Collection/index.d.ts.map +0 -1
- package/dist/cjs/selectors/Collection/index.js +0 -26
- package/dist/cjs/selectors/Collection/index.js.map +0 -1
- package/dist/cjs/selectors/Collection/types.d.ts +0 -98
- package/dist/cjs/selectors/Collection/types.d.ts.map +0 -1
- package/dist/cjs/selectors/Collection/types.js +0 -3
- package/dist/cjs/selectors/Collection/types.js.map +0 -1
- package/dist/cjs/selectors/Entry/index.d.ts +0 -5
- package/dist/cjs/selectors/Entry/index.d.ts.map +0 -1
- package/dist/cjs/selectors/Entry/index.js +0 -14
- package/dist/cjs/selectors/Entry/index.js.map +0 -1
- package/dist/cjs/selectors/Entry/types.d.ts +0 -138
- package/dist/cjs/selectors/Entry/types.d.ts.map +0 -1
- package/dist/cjs/selectors/Entry/types.js +0 -3
- package/dist/cjs/selectors/Entry/types.js.map +0 -1
- package/dist/cjs/selectors/Form/index.d.ts +0 -4
- package/dist/cjs/selectors/Form/index.d.ts.map +0 -1
- package/dist/cjs/selectors/Form/index.js +0 -18
- package/dist/cjs/selectors/Form/index.js.map +0 -1
- package/dist/cjs/selectors/Form/types.d.ts +0 -22
- package/dist/cjs/selectors/Form/types.d.ts.map +0 -1
- package/dist/cjs/selectors/Form/types.js +0 -3
- package/dist/cjs/selectors/Form/types.js.map +0 -1
- package/dist/cjs/selectors/Media/index.d.ts +0 -5
- package/dist/cjs/selectors/Media/index.d.ts.map +0 -1
- package/dist/cjs/selectors/Media/index.js +0 -14
- package/dist/cjs/selectors/Media/index.js.map +0 -1
- package/dist/cjs/selectors/Media/types.d.ts +0 -49
- package/dist/cjs/selectors/Media/types.d.ts.map +0 -1
- package/dist/cjs/selectors/Media/types.js +0 -3
- package/dist/cjs/selectors/Media/types.js.map +0 -1
- package/dist/cjs/selectors/Model/index.d.ts +0 -5
- package/dist/cjs/selectors/Model/index.d.ts.map +0 -1
- package/dist/cjs/selectors/Model/index.js +0 -26
- package/dist/cjs/selectors/Model/index.js.map +0 -1
- package/dist/cjs/selectors/Model/types.d.ts +0 -78
- package/dist/cjs/selectors/Model/types.d.ts.map +0 -1
- package/dist/cjs/selectors/Model/types.js +0 -3
- package/dist/cjs/selectors/Model/types.js.map +0 -1
- package/dist/cjs/selectors/ModelCategory/index.d.ts +0 -5
- package/dist/cjs/selectors/ModelCategory/index.d.ts.map +0 -1
- package/dist/cjs/selectors/ModelCategory/index.js +0 -26
- package/dist/cjs/selectors/ModelCategory/index.js.map +0 -1
- package/dist/cjs/selectors/ModelCategory/types.d.ts +0 -87
- package/dist/cjs/selectors/ModelCategory/types.d.ts.map +0 -1
- package/dist/cjs/selectors/ModelCategory/types.js +0 -3
- package/dist/cjs/selectors/ModelCategory/types.js.map +0 -1
- package/dist/cjs/selectors/Search/index.d.ts +0 -5
- package/dist/cjs/selectors/Search/index.d.ts.map +0 -1
- package/dist/cjs/selectors/Search/index.js +0 -11
- package/dist/cjs/selectors/Search/index.js.map +0 -1
- package/dist/cjs/selectors/Search/types.d.ts +0 -90
- package/dist/cjs/selectors/Search/types.d.ts.map +0 -1
- package/dist/cjs/selectors/Search/types.js +0 -3
- package/dist/cjs/selectors/Search/types.js.map +0 -1
- package/dist/cjs/selectors/Singleton/index.d.ts +0 -5
- package/dist/cjs/selectors/Singleton/index.d.ts.map +0 -1
- package/dist/cjs/selectors/Singleton/index.js +0 -14
- package/dist/cjs/selectors/Singleton/index.js.map +0 -1
- package/dist/cjs/selectors/Singleton/types.d.ts +0 -64
- package/dist/cjs/selectors/Singleton/types.d.ts.map +0 -1
- package/dist/cjs/selectors/Singleton/types.js +0 -3
- package/dist/cjs/selectors/Singleton/types.js.map +0 -1
- package/dist/cjs/types/entities.d.ts +0 -362
- package/dist/cjs/types/entities.d.ts.map +0 -1
- package/dist/cjs/types/entities.js +0 -3
- package/dist/cjs/types/entities.js.map +0 -1
- package/dist/cjs/types/fields.d.ts +0 -123
- package/dist/cjs/types/fields.d.ts.map +0 -1
- package/dist/cjs/types/fields.js +0 -3
- package/dist/cjs/types/fields.js.map +0 -1
- package/dist/cjs/types/groups.d.ts +0 -30
- package/dist/cjs/types/groups.d.ts.map +0 -1
- package/dist/cjs/types/groups.js +0 -3
- package/dist/cjs/types/groups.js.map +0 -1
- package/dist/cjs/types/index.d.ts +0 -629
- package/dist/cjs/types/index.d.ts.map +0 -1
- package/dist/cjs/types/index.js +0 -24
- package/dist/cjs/types/index.js.map +0 -1
- package/dist/cjs/types/instances.d.ts +0 -4
- package/dist/cjs/types/instances.d.ts.map +0 -1
- package/dist/cjs/types/instances.js +0 -3
- package/dist/cjs/types/instances.js.map +0 -1
- package/dist/cjs/types/selectors.d.ts +0 -8
- package/dist/cjs/types/selectors.d.ts.map +0 -1
- package/dist/cjs/types/selectors.js +0 -3
- package/dist/cjs/types/selectors.js.map +0 -1
- package/dist/cjs/types/utilities.d.ts +0 -83
- package/dist/cjs/types/utilities.d.ts.map +0 -1
- package/dist/cjs/types/utilities.js +0 -3
- package/dist/cjs/types/utilities.js.map +0 -1
- package/dist/cjs/types/visual.d.ts +0 -185
- package/dist/cjs/types/visual.d.ts.map +0 -1
- package/dist/cjs/types/visual.js +0 -3
- package/dist/cjs/types/visual.js.map +0 -1
- package/dist/cjs/utils/image.d.ts +0 -72
- package/dist/cjs/utils/image.d.ts.map +0 -1
- package/dist/cjs/utils/image.js +0 -101
- package/dist/cjs/utils/image.js.map +0 -1
- package/dist/cjs/utils/index.d.ts +0 -2
- package/dist/cjs/utils/index.d.ts.map +0 -1
- package/dist/cjs/utils/index.js +0 -18
- package/dist/cjs/utils/index.js.map +0 -1
- package/dist/esm/client.d.ts +0 -42
- package/dist/esm/client.d.ts.map +0 -1
- package/dist/esm/client.js +0 -139
- package/dist/esm/client.js.map +0 -1
- package/dist/esm/errors.d.ts +0 -40
- package/dist/esm/errors.d.ts.map +0 -1
- package/dist/esm/errors.js +0 -14
- package/dist/esm/errors.js.map +0 -1
- package/dist/esm/index.d.ts +0 -29
- package/dist/esm/index.d.ts.map +0 -1
- package/dist/esm/index.js +0 -29
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/instances/Collection/index.d.ts +0 -5
- package/dist/esm/instances/Collection/index.d.ts.map +0 -1
- package/dist/esm/instances/Collection/index.js +0 -11
- package/dist/esm/instances/Collection/index.js.map +0 -1
- package/dist/esm/instances/Collection/types.d.ts +0 -79
- package/dist/esm/instances/Collection/types.d.ts.map +0 -1
- package/dist/esm/instances/Collection/types.js +0 -2
- package/dist/esm/instances/Collection/types.js.map +0 -1
- package/dist/esm/instances/Form/index.d.ts +0 -5
- package/dist/esm/instances/Form/index.d.ts.map +0 -1
- package/dist/esm/instances/Form/index.js +0 -11
- package/dist/esm/instances/Form/index.js.map +0 -1
- package/dist/esm/instances/Form/types.d.ts +0 -46
- package/dist/esm/instances/Form/types.d.ts.map +0 -1
- package/dist/esm/instances/Form/types.js +0 -2
- package/dist/esm/instances/Form/types.js.map +0 -1
- package/dist/esm/instances/Model/index.d.ts +0 -5
- package/dist/esm/instances/Model/index.d.ts.map +0 -1
- package/dist/esm/instances/Model/index.js +0 -28
- package/dist/esm/instances/Model/index.js.map +0 -1
- package/dist/esm/instances/Model/types.d.ts +0 -102
- package/dist/esm/instances/Model/types.d.ts.map +0 -1
- package/dist/esm/instances/Model/types.js +0 -2
- package/dist/esm/instances/Model/types.js.map +0 -1
- package/dist/esm/instances/ModelCategory/index.d.ts +0 -5
- package/dist/esm/instances/ModelCategory/index.d.ts.map +0 -1
- package/dist/esm/instances/ModelCategory/index.js +0 -11
- package/dist/esm/instances/ModelCategory/index.js.map +0 -1
- package/dist/esm/instances/ModelCategory/types.d.ts +0 -76
- package/dist/esm/instances/ModelCategory/types.d.ts.map +0 -1
- package/dist/esm/instances/ModelCategory/types.js +0 -2
- package/dist/esm/instances/ModelCategory/types.js.map +0 -1
- package/dist/esm/selectors/Collection/index.d.ts +0 -5
- package/dist/esm/selectors/Collection/index.d.ts.map +0 -1
- package/dist/esm/selectors/Collection/index.js +0 -20
- package/dist/esm/selectors/Collection/index.js.map +0 -1
- package/dist/esm/selectors/Collection/types.d.ts +0 -98
- package/dist/esm/selectors/Collection/types.d.ts.map +0 -1
- package/dist/esm/selectors/Collection/types.js +0 -2
- package/dist/esm/selectors/Collection/types.js.map +0 -1
- package/dist/esm/selectors/Entry/index.d.ts +0 -5
- package/dist/esm/selectors/Entry/index.d.ts.map +0 -1
- package/dist/esm/selectors/Entry/index.js +0 -11
- package/dist/esm/selectors/Entry/index.js.map +0 -1
- package/dist/esm/selectors/Entry/types.d.ts +0 -138
- package/dist/esm/selectors/Entry/types.d.ts.map +0 -1
- package/dist/esm/selectors/Entry/types.js +0 -2
- package/dist/esm/selectors/Entry/types.js.map +0 -1
- package/dist/esm/selectors/Form/index.d.ts +0 -4
- package/dist/esm/selectors/Form/index.d.ts.map +0 -1
- package/dist/esm/selectors/Form/index.js +0 -12
- package/dist/esm/selectors/Form/index.js.map +0 -1
- package/dist/esm/selectors/Form/types.d.ts +0 -22
- package/dist/esm/selectors/Form/types.d.ts.map +0 -1
- package/dist/esm/selectors/Form/types.js +0 -2
- package/dist/esm/selectors/Form/types.js.map +0 -1
- package/dist/esm/selectors/Media/index.d.ts +0 -5
- package/dist/esm/selectors/Media/index.d.ts.map +0 -1
- package/dist/esm/selectors/Media/index.js +0 -11
- package/dist/esm/selectors/Media/index.js.map +0 -1
- package/dist/esm/selectors/Media/types.d.ts +0 -49
- package/dist/esm/selectors/Media/types.d.ts.map +0 -1
- package/dist/esm/selectors/Media/types.js +0 -2
- package/dist/esm/selectors/Media/types.js.map +0 -1
- package/dist/esm/selectors/Model/index.d.ts +0 -5
- package/dist/esm/selectors/Model/index.d.ts.map +0 -1
- package/dist/esm/selectors/Model/index.js +0 -20
- package/dist/esm/selectors/Model/index.js.map +0 -1
- package/dist/esm/selectors/Model/types.d.ts +0 -78
- package/dist/esm/selectors/Model/types.d.ts.map +0 -1
- package/dist/esm/selectors/Model/types.js +0 -2
- package/dist/esm/selectors/Model/types.js.map +0 -1
- package/dist/esm/selectors/ModelCategory/index.d.ts +0 -5
- package/dist/esm/selectors/ModelCategory/index.d.ts.map +0 -1
- package/dist/esm/selectors/ModelCategory/index.js +0 -20
- package/dist/esm/selectors/ModelCategory/index.js.map +0 -1
- package/dist/esm/selectors/ModelCategory/types.d.ts +0 -87
- package/dist/esm/selectors/ModelCategory/types.d.ts.map +0 -1
- package/dist/esm/selectors/ModelCategory/types.js +0 -2
- package/dist/esm/selectors/ModelCategory/types.js.map +0 -1
- package/dist/esm/selectors/Search/index.d.ts +0 -5
- package/dist/esm/selectors/Search/index.d.ts.map +0 -1
- package/dist/esm/selectors/Search/index.js +0 -8
- package/dist/esm/selectors/Search/index.js.map +0 -1
- package/dist/esm/selectors/Search/types.d.ts +0 -90
- package/dist/esm/selectors/Search/types.d.ts.map +0 -1
- package/dist/esm/selectors/Search/types.js +0 -2
- package/dist/esm/selectors/Search/types.js.map +0 -1
- package/dist/esm/selectors/Singleton/index.d.ts +0 -5
- package/dist/esm/selectors/Singleton/index.d.ts.map +0 -1
- package/dist/esm/selectors/Singleton/index.js +0 -11
- package/dist/esm/selectors/Singleton/index.js.map +0 -1
- package/dist/esm/selectors/Singleton/types.d.ts +0 -64
- package/dist/esm/selectors/Singleton/types.d.ts.map +0 -1
- package/dist/esm/selectors/Singleton/types.js +0 -2
- package/dist/esm/selectors/Singleton/types.js.map +0 -1
- package/dist/esm/types/entities.d.ts +0 -362
- package/dist/esm/types/entities.d.ts.map +0 -1
- package/dist/esm/types/entities.js +0 -2
- package/dist/esm/types/entities.js.map +0 -1
- package/dist/esm/types/fields.d.ts +0 -123
- package/dist/esm/types/fields.d.ts.map +0 -1
- package/dist/esm/types/fields.js +0 -2
- package/dist/esm/types/fields.js.map +0 -1
- package/dist/esm/types/groups.d.ts +0 -30
- package/dist/esm/types/groups.d.ts.map +0 -1
- package/dist/esm/types/groups.js +0 -2
- package/dist/esm/types/groups.js.map +0 -1
- package/dist/esm/types/index.d.ts +0 -629
- package/dist/esm/types/index.d.ts.map +0 -1
- package/dist/esm/types/index.js +0 -8
- package/dist/esm/types/index.js.map +0 -1
- package/dist/esm/types/instances.d.ts +0 -4
- package/dist/esm/types/instances.d.ts.map +0 -1
- package/dist/esm/types/instances.js +0 -2
- package/dist/esm/types/instances.js.map +0 -1
- package/dist/esm/types/selectors.d.ts +0 -8
- package/dist/esm/types/selectors.d.ts.map +0 -1
- package/dist/esm/types/selectors.js +0 -2
- package/dist/esm/types/selectors.js.map +0 -1
- package/dist/esm/types/utilities.d.ts +0 -83
- package/dist/esm/types/utilities.d.ts.map +0 -1
- package/dist/esm/types/utilities.js +0 -2
- package/dist/esm/types/utilities.js.map +0 -1
- package/dist/esm/types/visual.d.ts +0 -185
- package/dist/esm/types/visual.d.ts.map +0 -1
- package/dist/esm/types/visual.js +0 -2
- package/dist/esm/types/visual.js.map +0 -1
- package/dist/esm/utils/image.d.ts +0 -72
- package/dist/esm/utils/image.d.ts.map +0 -1
- package/dist/esm/utils/image.js +0 -96
- package/dist/esm/utils/image.js.map +0 -1
- package/dist/esm/utils/index.d.ts +0 -2
- package/dist/esm/utils/index.d.ts.map +0 -1
- package/dist/esm/utils/index.js +0 -2
- package/dist/esm/utils/index.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAWA,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA;AACxB,cAAc,UAAU,CAAA;AACxB,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,UAAU,CAAA","sourcesContent":["import { CollectionEntityTypes, SerializedData } from './entities'\nimport { DynamicModelSelector } from '../selectors/Model'\nimport { DynamicModelInstance } from '../instances/Model'\nimport { SingletonSelector } from '../selectors/Singleton'\nimport { DynamicCollectionSelector } from '../selectors/Collection'\nimport { MediaSelector } from '../selectors/Media'\nimport { SearchSelector } from '../selectors/Search'\nimport { CollectionInstance } from '../instances/Collection'\nimport { FormInstance } from '../instances/Form'\nimport { DynamicFormSelector } from '../selectors/Form/types'\n\nexport * from './entities'\nexport * from './fields'\nexport * from './groups'\nexport * from './instances'\nexport * from './selectors'\nexport * from './utilities'\nexport * from './visual'\n\n/**\n * This is a utility type that allows any string to be used as a URL, but\n * provides a default one which can be used by IDEs to provide auto-completion.\n * The default URL points to version 2 of the Query API.\n */\nexport type BaseUrl = 'https://query.starlightcms.io/v2' | string\n\n/**\n * The available options to configure a {@link StarlightClient}.\n *\n * `workspace` is required when creating new clients or configuring the\n * {@apilink default | default client}.\n * @group Client\n */\nexport type StarlightConfig = {\n /**\n * The ID of the workspace that the client should use to request data.\n *\n * Note: the current APIs only support using workspace IDs as identifiers,\n * and **not** slugs. Slug support will be added in the future. You can find\n * the workspace ID in the left-side menu on the Starlight interface or below\n * the workspace name in the workspace list.\n */\n workspace?: string\n /**\n * The Starlight Query API URL, including the version, and without a trailing\n * slash. Defaults to the production Query API URL.\n *\n * You only need to set this if you're not using Starlight's production APIs.\n */\n baseUrl?: BaseUrl\n /**\n * When true, logs all API requests in the console. Defaults to false.\n */\n debug?: boolean\n}\n\n/**\n * The Starlight client is the main entry point for any requests you might want\n * to make to Starlight's APIs.\n *\n * There's two ways of interacting with a client: using the\n * {@apilink default | default client} exported by the SDK or creating a new\n * client instance using the\n * {@apilink makeStarlightClient | makeStarlightClient function}. Follow the\n * provided links to learn how to use each method.\n *\n * Either way you choose to interact, all clients expose the same methods and\n * accessors that provide ways to request data. These methods and accessors\n * return Selector or Instance objects, which are documented in the sections\n * of the same name found in this API's sidebar.\n *\n * @group Client\n */\nexport interface StarlightClient<\n D extends WorkspaceModelDefinition = DefaultModelDefinition,\n> {\n /**\n * Updates the client configuration. See {@link StarlightConfig} to see all\n * the available options.\n *\n * If you want to use the {@apilink default | default SDK client}, you need to\n * set its workspace using this method in your application. You should run\n * this method only once, and as soon as possible in your application\n * lifecycle. For instance, when using React:\n *\n * ```js\n * // src/index.js\n * import { createRoot } from \"react-dom/client\"\n * import Starlight from '@starlightcms/js-sdk'\n * import MyApp from './MyApp.js'\n *\n * // We only need to run this once. In this case, we're\n * // running it before initializing our React app.\n * Starlight.configure({\n * workspace: '1234567890'\n * })\n *\n * const rootElement = document.getElementById(\"root\")\n * const root = createRoot(rootElement)\n *\n * root.render(<MyApp />)\n * ```\n *\n * @param config A configuration object. See {@link StarlightConfig} to view\n * all available options.\n * @category Other Methods\n */\n configure(config: StarlightConfig): void\n\n /**\n * Logs a message (or any kind of data, really) into the console if the debug\n * configuration is true. Uses `console.log` internally.\n *\n * This function's type definition is the same as the `console.log` function.\n *\n * @param message The data that will be logged.\n * @param optionalParams Additional data to be logged or string substitutions.\n * @see [MDN documentation on console.log](https://developer.mozilla.org/en-US/docs/web/api/console/log)\n * @internal\n */\n log(message?: unknown, ...optionalParams: unknown[]): void\n\n /**\n * Returns the base API URL for requests, including the configured workspace.\n * Doesn't include a trailing slash.\n *\n * @internal\n */\n getBaseUrl(): string\n\n /**\n * Returns a Promise that results in a response or throws a StarlightError.\n * The response will be the parsed JSON data sent by the API.\n *\n * This method is used internally by all Selectors and Instances to request\n * data to Starlight's Query API, but it can also be used standalone if\n * desired.\n *\n * This method automatically prefixes the given path with the API URL, but it\n * doesn't include a trailing slash, so be sure to include one at the start\n * of your path.\n *\n * @param path The path to GET. Will be prefixed with the API URL. Must start\n * with a forward slash (/).\n * @param params An optional object of values that will be converted to a\n * string and passed as GET params.\n * @param options An optional configuration object passed to the fetch method.\n * Check [MDN documentation on fetch](https://developer.mozilla.org/en-US/docs/Web/API/fetch)\n * to see the available options.\n * @typeParam T - The shape of the expected response on success. Client\n * methods generally pass {@link StarlightItemResponse} or\n * {@link StarlightListResponse} types here.\n * @throws {@link StarlightError} on any errors.\n * @category Other Methods\n */\n get<T = Record<string, unknown>>(\n path: string,\n params?: BaseRequestParameters,\n options?: RequestInit,\n ): Promise<T>\n\n /**\n * Returns a {@link DynamicModelSelector}, which is a {@link ModelSelector}\n * with support for creating {@apilink ModelInstance | ModelInstances} using the dynamic syntax.\n *\n * This is an accessor, which means that it should be used just like a common\n * object parameter. For instance:\n *\n * ```ts\n * import Starlight from '@starlightcms/js-sdk'\n *\n * const response = await Starlight.models.list()\n * ```\n *\n * See {@link DynamicModelSelector} for more info.\n *\n * @category Selector Accessors\n */\n get models(): DynamicModelSelector<D>\n\n /**\n * Returns a {@link DynamicModelInstance}, which is a\n * {@link ModelInstance} with support for creating\n * {@apilink ModelCategoryInstance | ModelCategoryInstances} using the dynamic syntax. For instance:\n *\n * ```ts\n * import Starlight from '@starlightcms/js-sdk'\n *\n * const response = await Starlight.model('posts').entries.list()\n * ```\n *\n * See {@link DynamicModelInstance} for more info.\n *\n * @category Instance Methods\n */\n model<S extends keyof D>(slug: S): DynamicModelInstance<D[S]>\n\n /**\n * Returns a {@link DynamicFormSelector}, which provides support for creating\n * {@apilink FormInstance | FormInstances} using the dynamic syntax.\n *\n * This is an accessor, which means that it should be used just like a common\n * object parameter. For instance:\n *\n * ```ts\n * import Starlight from '@starlightcms/js-sdk'\n *\n * const response = await Starlight.forms.signup.get()\n * ```\n *\n * See {@link DynamicFormSelector} for more info.\n *\n * @category Selector Accessors\n */\n get forms(): DynamicFormSelector\n\n /**\n * Returns a {@link FormInstance}, which provides methods to retrieve basic information\n * about a Starlight form and its schema. For instance:\n *\n * ```ts\n * import Starlight from '@starlightcms/js-sdk'\n *\n * const response = await Starlight.form('signup').schema()\n * ```\n *\n * See {@link FormInstance} for more info.\n *\n * @category Instance Methods\n */\n form(slug: string | number): FormInstance\n\n /**\n * Returns a {@link SingletonSelector}.\n *\n * This is an accessor, which means that it should be used just like a common\n * object parameter. For instance:\n *\n * ```ts\n * import Starlight from '@starlightcms/js-sdk'\n *\n * const response = await Starlight.singletons.list()\n * ```\n *\n * See {@link SingletonSelector} for more info.\n *\n * @category Selector Accessors\n */\n get singletons(): SingletonSelector\n\n /**\n * Returns a {@link DynamicCollectionSelector}, which is a\n * {@link CollectionSelector} with support for creating\n * {@apilink CollectionInstance | CollectionInstances} using the dynamic syntax.\n *\n * This is an accessor, which means that it should be used just like a common\n * object parameter. For instance:\n *\n * ```ts\n * import Starlight from '@starlightcms/js-sdk'\n *\n * const response = await Starlight.collections.list()\n * ```\n *\n * See {@link DynamicCollectionSelector} for more info.\n *\n * @category Selector Accessors\n */\n get collections(): DynamicCollectionSelector\n\n /**\n * Returns a {@link CollectionInstance}. For instance:\n *\n * ```ts\n * import Starlight from '@starlightcms/js-sdk'\n *\n * const response = await Starlight.collection('featured-posts').items()\n * ```\n *\n * See {@link CollectionInstance} for more info.\n *\n * @example Typing the returned CollectionInstance.\n * ```ts\n * import Starlight, { MediaObject } from '@starlightcms/js-sdk'\n *\n * const response = await Starlight.collection<MediaObject>('carousel-images').items()\n * ```\n *\n * @typeParam T - The type of entity this Collection holds. You can pass this\n * type parameter to correctly type the response of the\n * {@apilink CollectionInstance.items} method.\n * @category Instance Methods\n */\n collection<T extends CollectionEntityTypes>(\n slug: string | number,\n ): CollectionInstance<T>\n\n /**\n * Returns a {@link MediaSelector}.\n *\n * This is an accessor, which means that it should be used just like a common\n * object parameter. For instance:\n *\n * ```ts\n * import Starlight from '@starlightcms/js-sdk'\n *\n * const response = await Starlight.media.list()\n * ```\n *\n * See {@link MediaSelector} for more info.\n *\n * @category Selector Accessors\n */\n get media(): MediaSelector\n\n /**\n * Returns a {@link SearchSelector}.\n *\n * This is an accessor, which means that it should be used just like a common\n * object parameter. For instance:\n *\n * ```ts\n * import Starlight from '@starlightcms/js-sdk'\n *\n * const response = await Starlight.search.entries()\n * ```\n *\n * See {@link SearchSelector} for more info.\n *\n * @category Selector Accessors\n */\n get search(): SearchSelector\n}\n\n/**\n * This type adds support for the dynamic syntax to the StarlightClient\n * interface, which allows users to create\n * {@apilink DynamicModelInstance| DynamicModelInstances} dynamically.\n * See {@link StarlightClient} to learn which methods it provides. Also see\n * {@doclink requests-and-responses#dynamic-syntax | Dynamic Instances}\n * documentation to learn more about the dynamic syntax.\n *\n *\n * This allows TypeScript to correctly type all models defined by the user\n * in the DefaultModelDefinition type, aside from letting the user using any\n * \"unknown\" model slug, which is provided by the WorkspaceModelDefinition type.\n *\n * This type is only aware of the DefaultModelDefinition type because the\n * StarlightClient uses it by default when no model definition type is passed.\n *\n * @group Client\n */\nexport type DynamicStarlightClient<T extends WorkspaceModelDefinition> =\n StarlightClient<T> & {\n [K in keyof T]: DynamicModelInstance<T[K]>\n }\n\n/**\n * This interface represents an API response that returns a single entity, like\n * a single {@link Entry} or a single {@link MediaObject}, for instance.\n *\n * It contains only one field: `data`. This field type is generic and\n * depends on the kind of request that was made to the API.\n *\n * All SDK request methods that returna single entity\n * will return this interface.\n *\n * @group Client\n */\nexport interface StarlightItemResponse<T> {\n /**\n * The entity returned by the API request. Its type depends on which request\n * was made. SDK methods will generally type this parameter automatically.\n */\n data: T\n}\n\n/**\n * This interface represents an API response that returns a list of entities,\n * like a list of {@apilink Entry | Entries} or a list of items from a\n * {@link Collection}.\n *\n * It contains a `data` parameter, which is an array of items with a generic\n * type that depends on the kind of request that was made, and two metadata\n * objects: `links` and `meta`. Metadata is useful for pagination.\n *\n * All SDK request methods that return a list of entities will return this\n * interface.\n *\n * @group Client\n */\nexport interface StarlightListResponse<T> {\n /**\n * The list of entities returned by the API request. Its type depends on which\n * request was made. SDK methods will generally type\n * this parameter automatically.\n */\n data: T[]\n /**\n * An object containing useful links for easier pagination. All links points\n * to the same list requested, but with a varying `page` parameter.\n */\n links: {\n /**\n * A link for the first page of the list.\n */\n first: string\n /**\n * A link for the last page of the list.\n */\n last: string\n /**\n * A link to the previous page of the list, if there's any.\n */\n prev?: string\n /**\n * A link to the next page of the list, if there's any.\n */\n next?: string\n }\n /**\n * An object with useful metadata related to the current list. It can be used\n * in applications to create pagination logic and interfaces.\n *\n * `from` and `to` are indexes indicating which items start and finish the\n * current page of the list. For instance, in a list with 100 items with 15\n * items per page, on the first page, `from` and `to` will be `1` and `15`\n * respectively.\n */\n meta: {\n /**\n * The number of the current page.\n */\n current_page: number\n /**\n * The number of the last page for the current list.\n */\n last_page: number\n /**\n * The index of the first item on this page out of all list items.\n */\n from: number\n /**\n * The index of the last item on this page out of all list items.\n */\n to: number\n /**\n * The number of items per page.\n */\n per_page: number\n /**\n * The total number of items in the current list.\n */\n total: number\n }\n}\n\n/**\n * The DefaultModelDefinition type is used to correctly type Entry data when\n * requesting it using a StarlightClient.\n *\n * Without using a DefaultModelDefinition, Entry data will be typed as a\n * \"generic\" JS object which can hold any kind of data:\n *\n * ```ts\n * import Starlight from '@starlightcms/js-sdk'\n *\n * // response type will be StarlightItemResponse<Entry> on request success.\n * const response = await Starlight.posts.entries.get('hello-world')\n *\n * // helloWorld type is Entry<Record<string, unknown>>. This means that\n * // `data` can hold anything, which is not type-safe.\n * const helloWorld = response.data\n * ```\n *\n * One way of safely adding type information to Entry objects is by passing a\n * data definition type to the EntrySelector when requesting something:\n *\n * ```ts\n * import Starlight, { Group, VisualField, MediaField } from '@starlightcms/js-sdk'\n *\n * type PostFields = {\n * info: Group<{\n * featured_image: MediaField\n * content: VisualField\n * }>\n * }\n *\n * // response type will now be StarlightItemResponse<Entry<PostsFields>>.\n * const response = await Starlight.posts.entries<PostFields>.get('hello-world')\n *\n * // Now, helloWorld type is Entry<PostsFields>.\n * const helloWorld = response.data\n *\n * // Which means we can safely access its data, and IDEs will\n * // auto-complete the data field name below:\n * console.log(helloWorld.data.info.featured_image)\n * ```\n *\n * Note that we used **Groups** and **Fields** to define our data shape. We\n * recommend using these types, which are exported by this SDK, because they map\n * to the group and field types available in the Starlight admin when creating\n * models, and should simplify the type definition process. All available Group\n * and Field types are documented in the\n * {@apilink BooleanField | Data Fields} and\n * {@apilink Group | Data Groups} sections of this API.\n *\n * However, passing model definition types around your application is not ideal,\n * and actually unnecessary. Using the `DefaultModelDefinition` type, all model\n * definitions can be automatically inferred.\n *\n * To get started, you need to create a\n * [type declaration file](https://www.typescriptlang.org/docs/handbook/declaration-files/introduction.html)\n * in which you'll define all your types. You can name it anything and place it\n * anywhere inside your project, but we recommend naming it `starlight.d.ts` and\n * placing it in the root folder of your source code, so it can be easily\n * imported later in your application if you ever need to reference these types.\n *\n * In this file, you can place all your model type definitions (including type\n * definitions for Singleton data, if you want!). Finally, you just need to\n * add a \"module definition block\" that will tell the SDK which types you expect\n * to receive when requesting models.\n *\n * Here's a complete exemple defining two models, Posts and Magazines:\n *\n * ```ts\n * import {\n * Group,\n * RepeaterGroup,\n * StringField,\n * VisualField,\n * MediaField\n * } from '@starlightcms/js-sdk'\n *\n * type PostFields = {\n * info: Group<{\n * featured_image: MediaField\n * content: VisualField\n * }>\n * }\n *\n * type MagazineFields = {\n * info: Group<{\n * cover_image: MediaField\n * content: VisualField\n * }>\n * page_previews: RepeaterGroup<{\n * image: MediaField\n * description: StringField\n * }>\n * metadata: Group<{\n * issue_number: StringField\n * issue_year: StringField\n * }>\n * }\n *\n * declare module '@starlightcms/js-sdk' {\n * export interface DefaultModelDefinition {\n * // Notice how each key in this interface is a Model slug!\n * posts: PostFields\n * magazines: MagazineFields\n * }\n * }\n * ```\n *\n * After creating this file, types should be automatically inferred without the\n * need to pass them around:\n *\n * ```ts\n * import Starlight from '@starlightcms/js-sdk'\n *\n * // response type will be StarlightItemResponse<Entry<PostsFields>>,\n * // which was implicitly inferred by the SDK because of the `posts`\n * // property we added to the `DefaultModelDefinition` above.\n * const response = await Starlight.posts.entries.get('hello-world')\n *\n * // helloWorld type is Entry<PostsFields>\n * const helloWorld = response.data\n *\n * // Auto-complete will work just as before when we explicitly type the Entry!\n * console.log(helloWorld.data.info.featured_image)\n * ```\n *\n * @group Client\n */\n// eslint-disable-next-line @typescript-eslint/no-empty-object-type\nexport interface DefaultModelDefinition extends WorkspaceModelDefinition {}\n\n/**\n * This type is only used as a base for the DefaultModelDefinition type.\n *\n * @internal\n */\nexport interface WorkspaceModelDefinition {\n [slug: string]: SerializedData\n}\n\n/**\n * An object that accepts any string, number and boolean values.\n * Used as the base for most request parameter interfaces in the SDK.\n *\n * @group Request Parameters\n */\nexport interface BaseRequestParameters {\n [key: string]: string | number | boolean | undefined\n}\n\n/**\n * Request parameters used by most SDK `list()` methods.\n *\n * @group Request Parameters\n */\nexport interface ListRequestParameters extends BaseRequestParameters {\n /**\n * The page requested.\n */\n page?: number\n /**\n * The limit of items per page.\n */\n limit?: number\n /**\n * A search query string.\n *\n * For instance, searching for \"out\" will match both \"check out!\" and\n * \"about us\". Search is not case-sensitive.\n */\n query?: string\n}\n\n/**\n * Request parameters used by most SDK methods that support advanced querying.\n *\n * @group Request Parameters\n */\nexport interface QueryableRequestParameters {\n /**\n * A search query string that matches a specific word within boundaries.\n * Search is not case-sensitive.\n *\n * For instance, searching for \"phone\" will match \"This is my phone!\"\n * but won't match \"This is my telephone!\".\n */\n 'query:word'?: string\n /**\n * A comma-separated list of fields to look up on when searching using\n * `query` or `query:word`. If undefined, all text fields will be searched on,\n * including Visual Editor fields. Search is not case-sensitive.\n *\n * For instance, to limit search on the \"content\" and \"summary\" fields of a\n * model, pass `'content,summary'`.\n */\n fields?: string\n /**\n * If defined, removes the given item from the list. Useful to create \"related\n * posts\" lists.\n *\n * Note: this field only accepts IDs, and not slugs. Only one ID is allowed.\n */\n except?: number\n}\n"]}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export { CollectionInstance, ListCollectionItemsParams, } from '../instances/Collection';
|
|
2
|
-
export { DynamicModelInstance, ModelInstance } from '../instances/Model';
|
|
3
|
-
export { ModelCategoryInstance, ModelCategoryEntryListParams, } from '../instances/ModelCategory';
|
|
4
|
-
//# sourceMappingURL=instances.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"instances.d.ts","sourceRoot":"","sources":["../../../src/types/instances.ts"],"names":[],"mappings":"AACA,OAAO,EACL,kBAAkB,EAClB,yBAAyB,GAC1B,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AACxE,OAAO,EACL,qBAAqB,EACrB,4BAA4B,GAC7B,MAAM,4BAA4B,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"instances.js","sourceRoot":"","sources":["../../../src/types/instances.ts"],"names":[],"mappings":"","sourcesContent":["// Instance types are exported here so they are visible in the API docs.\nexport {\n CollectionInstance,\n ListCollectionItemsParams,\n} from '../instances/Collection'\nexport { DynamicModelInstance, ModelInstance } from '../instances/Model'\nexport {\n ModelCategoryInstance,\n ModelCategoryEntryListParams,\n} from '../instances/ModelCategory'\n"]}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export { ModelCategorySelector, DynamicModelCategorySelector, ListModelCategoriesOptions, } from '../selectors/ModelCategory';
|
|
2
|
-
export { ModelSelector, DynamicModelSelector } from '../selectors/Model';
|
|
3
|
-
export { CollectionSelector, DynamicCollectionSelector, ListCollectionsParams, } from '../selectors/Collection';
|
|
4
|
-
export { EntrySelector, ListEntriesParams } from '../selectors/Entry';
|
|
5
|
-
export { MediaSelector } from '../selectors/Media';
|
|
6
|
-
export { SearchSelector, SearchEntriesParams } from '../selectors/Search';
|
|
7
|
-
export { SingletonSelector } from '../selectors/Singleton';
|
|
8
|
-
//# sourceMappingURL=selectors.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"selectors.d.ts","sourceRoot":"","sources":["../../../src/types/selectors.ts"],"names":[],"mappings":"AACA,OAAO,EACL,qBAAqB,EACrB,4BAA4B,EAC5B,0BAA0B,GAC3B,MAAM,4BAA4B,CAAA;AACnC,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAA;AACxE,OAAO,EACL,kBAAkB,EAClB,yBAAyB,EACzB,qBAAqB,GACtB,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AACzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"selectors.js","sourceRoot":"","sources":["../../../src/types/selectors.ts"],"names":[],"mappings":"","sourcesContent":["// Selector types are exported here so they are visible in the API docs.\nexport {\n ModelCategorySelector,\n DynamicModelCategorySelector,\n ListModelCategoriesOptions,\n} from '../selectors/ModelCategory'\nexport { ModelSelector, DynamicModelSelector } from '../selectors/Model'\nexport {\n CollectionSelector,\n DynamicCollectionSelector,\n ListCollectionsParams,\n} from '../selectors/Collection'\nexport { EntrySelector, ListEntriesParams } from '../selectors/Entry'\nexport { MediaSelector } from '../selectors/Media'\nexport { SearchSelector, SearchEntriesParams } from '../selectors/Search'\nexport { SingletonSelector } from '../selectors/Singleton'\n"]}
|
|
@@ -1,83 +0,0 @@
|
|
|
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>;
|
|
49
|
-
/**
|
|
50
|
-
* Returns the item type of the given Repeater Group.
|
|
51
|
-
*
|
|
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
|
-
* ```
|
|
79
|
-
*
|
|
80
|
-
* @group Utility Types
|
|
81
|
-
*/
|
|
82
|
-
export type GetRepeaterItem<Repeater extends RepeaterGroup<Record<string, unknown>>> = Repeater extends readonly (infer ItemType)[] ? ItemType : never;
|
|
83
|
-
//# sourceMappingURL=utilities.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
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"]}
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* All supported block types.
|
|
3
|
-
*
|
|
4
|
-
* @group Visual Data Blocks
|
|
5
|
-
* @internal
|
|
6
|
-
*/
|
|
7
|
-
export type BlockType = 'paragraph' | 'quote' | 'header' | 'image' | 'raw' | 'list' | 'video';
|
|
8
|
-
/**
|
|
9
|
-
* Represents the possible block widths, used by some blocks.
|
|
10
|
-
*
|
|
11
|
-
* @group Visual Data Blocks
|
|
12
|
-
* @internal
|
|
13
|
-
*/
|
|
14
|
-
type BlockWidth = 'auto' | 'justify' | 'max' | string;
|
|
15
|
-
/**
|
|
16
|
-
* Alignable block type extension
|
|
17
|
-
*
|
|
18
|
-
* @group Visual Data Blocks
|
|
19
|
-
* @internal
|
|
20
|
-
*/
|
|
21
|
-
export type AlignableBlock<Base> = Base & {
|
|
22
|
-
alignment: Alignment;
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
* Represents the possible alignments, used by some blocks.
|
|
26
|
-
*
|
|
27
|
-
* @group Visual Data Blocks
|
|
28
|
-
* @internal
|
|
29
|
-
*/
|
|
30
|
-
export type Alignment = 'start' | 'center' | 'end' | 'justify';
|
|
31
|
-
/**
|
|
32
|
-
* Stretchable block type extension
|
|
33
|
-
*
|
|
34
|
-
* @group Visual Data Blocks
|
|
35
|
-
* @internal
|
|
36
|
-
*/
|
|
37
|
-
export type StretchableBlock<Base> = Base & {
|
|
38
|
-
isStretched: boolean;
|
|
39
|
-
};
|
|
40
|
-
/**
|
|
41
|
-
* Base interface for types that represent block data.
|
|
42
|
-
*
|
|
43
|
-
* @group Visual Data Blocks
|
|
44
|
-
*/
|
|
45
|
-
export interface BlockData {
|
|
46
|
-
[key: string]: unknown;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Represents a Paragraph block, which is the default block type used
|
|
50
|
-
* for text content in the Visual Editor.
|
|
51
|
-
*
|
|
52
|
-
* @group Visual Data Blocks
|
|
53
|
-
*/
|
|
54
|
-
export type ParagraphBlock = StretchableBlock<AlignableBlock<BaseParagraphBlock>>;
|
|
55
|
-
interface BaseParagraphBlock extends BlockData {
|
|
56
|
-
text: string | null;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Represents a Header block, which is used to render h1 through h6 HTML elements.
|
|
60
|
-
*
|
|
61
|
-
* @group Visual Data Blocks
|
|
62
|
-
*/
|
|
63
|
-
export type HeaderBlock = StretchableBlock<AlignableBlock<BaseHeaderBlock>>;
|
|
64
|
-
interface BaseHeaderBlock extends BlockData {
|
|
65
|
-
text: string;
|
|
66
|
-
level: number;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Represents a Quote block, which is used to render a blockquote HTML element.
|
|
70
|
-
*
|
|
71
|
-
* @group Visual Data Blocks
|
|
72
|
-
*/
|
|
73
|
-
export interface QuoteBlock extends BlockData {
|
|
74
|
-
text: string;
|
|
75
|
-
caption: string;
|
|
76
|
-
alignment: 'left' | 'center';
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Represents an image file, used in Image blocks.
|
|
80
|
-
*
|
|
81
|
-
* @group Visual Data Blocks
|
|
82
|
-
* @internal
|
|
83
|
-
*/
|
|
84
|
-
export type ImageFile = {
|
|
85
|
-
url: string;
|
|
86
|
-
variation: string;
|
|
87
|
-
width: number;
|
|
88
|
-
height: number;
|
|
89
|
-
};
|
|
90
|
-
/**
|
|
91
|
-
* Represents an Image block, which is used to render img or picture HTML elements.
|
|
92
|
-
*
|
|
93
|
-
* @group Visual Data Blocks
|
|
94
|
-
*/
|
|
95
|
-
export type ImageBlock = StretchableBlock<AlignableBlock<BaseImageBlock>>;
|
|
96
|
-
interface BaseImageBlock extends BlockData {
|
|
97
|
-
id: number | undefined;
|
|
98
|
-
url: string;
|
|
99
|
-
files: ImageFile[];
|
|
100
|
-
caption?: string;
|
|
101
|
-
alt?: string;
|
|
102
|
-
href?: string;
|
|
103
|
-
width: BlockWidth;
|
|
104
|
-
variation: string | undefined;
|
|
105
|
-
responsive: boolean;
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Represents an HTML block, which is used to render custom HTML code. Mainly
|
|
109
|
-
* used to place embeds or heavily customized content structures.
|
|
110
|
-
*
|
|
111
|
-
* @group Visual Data Blocks
|
|
112
|
-
*/
|
|
113
|
-
export type HTMLBlock = StretchableBlock<BaseHTMLBlock>;
|
|
114
|
-
interface BaseHTMLBlock extends BlockData {
|
|
115
|
-
html: string;
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Represents a list item, which is used by List blocks.
|
|
119
|
-
*
|
|
120
|
-
* @group Visual Data Blocks
|
|
121
|
-
* @internal
|
|
122
|
-
*/
|
|
123
|
-
export interface ListItem {
|
|
124
|
-
content: string;
|
|
125
|
-
items?: ListItem[];
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Represents a List block, which is used to render ol or ul HTML elements.
|
|
129
|
-
*
|
|
130
|
-
* @group Visual Data Blocks
|
|
131
|
-
*/
|
|
132
|
-
export type ListBlock = StretchableBlock<BaseListBlock>;
|
|
133
|
-
interface BaseListBlock extends BlockData {
|
|
134
|
-
style: 'ordered' | 'unordered';
|
|
135
|
-
items: ListItem[];
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Represents the current supported video services, used in Video blocks.
|
|
139
|
-
*
|
|
140
|
-
* @group Visual Data Blocks
|
|
141
|
-
* @internal
|
|
142
|
-
*/
|
|
143
|
-
export type SupportedServices = 'youtube' | 'vimeo';
|
|
144
|
-
/**
|
|
145
|
-
* Represents a Video block, which is used to render embed video elements.
|
|
146
|
-
*
|
|
147
|
-
* @group Visual Data Blocks
|
|
148
|
-
*/
|
|
149
|
-
export type VideoBlock = StretchableBlock<AlignableBlock<BaseVideoBlock>>;
|
|
150
|
-
interface BaseVideoBlock extends BlockData {
|
|
151
|
-
type: 'embed';
|
|
152
|
-
service: SupportedServices;
|
|
153
|
-
videoId: string;
|
|
154
|
-
url: string;
|
|
155
|
-
html: string;
|
|
156
|
-
width: BlockWidth;
|
|
157
|
-
caption?: string;
|
|
158
|
-
alignment: Alignment;
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* A VisualDataBlock object represents a piece of content. Each block has a
|
|
162
|
-
* specific type and some data associated with it. For instance, a Paragraph
|
|
163
|
-
* block has text data, an Image block has a file path and image metadata, etc.
|
|
164
|
-
*
|
|
165
|
-
* @group Visual Data Blocks
|
|
166
|
-
*/
|
|
167
|
-
export interface VisualDataBlock<D extends BlockData = BlockData> {
|
|
168
|
-
id: string;
|
|
169
|
-
type: BlockType;
|
|
170
|
-
data: D;
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* VisualData represents content generated by Starlight using a "Visual Editor"
|
|
174
|
-
* field. It's an object-based data representation made out of "blocks". Each
|
|
175
|
-
* block has a type string and some data associated with it.
|
|
176
|
-
*
|
|
177
|
-
* @group Visual Data Blocks
|
|
178
|
-
*/
|
|
179
|
-
export interface VisualData {
|
|
180
|
-
time?: number;
|
|
181
|
-
version?: string;
|
|
182
|
-
blocks: VisualDataBlock[];
|
|
183
|
-
}
|
|
184
|
-
export {};
|
|
185
|
-
//# sourceMappingURL=visual.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"visual.d.ts","sourceRoot":"","sources":["../../../src/types/visual.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,MAAM,SAAS,GACjB,WAAW,GACX,OAAO,GACP,QAAQ,GACR,OAAO,GACP,KAAK,GACL,MAAM,GACN,OAAO,CAAA;AAEX;;;;;GAKG;AACH,KAAK,UAAU,GAAG,MAAM,GAAG,SAAS,GAAG,KAAK,GAAG,MAAM,CAAA;AAErD;;;;;GAKG;AACH,MAAM,MAAM,cAAc,CAAC,IAAI,IAAI,IAAI,GAAG;IACxC,SAAS,EAAE,SAAS,CAAA;CACrB,CAAA;AAED;;;;;GAKG;AACH,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,QAAQ,GAAG,KAAK,GAAG,SAAS,CAAA;AAE9D;;;;;GAKG;AACH,MAAM,MAAM,gBAAgB,CAAC,IAAI,IAAI,IAAI,GAAG;IAC1C,WAAW,EAAE,OAAO,CAAA;CACrB,CAAA;AAED;;;;GAIG;AACH,MAAM,WAAW,SAAS;IACxB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AAED;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GAAG,gBAAgB,CAC3C,cAAc,CAAC,kBAAkB,CAAC,CACnC,CAAA;AAED,UAAU,kBAAmB,SAAQ,SAAS;IAC5C,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;CACpB;AAED;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG,gBAAgB,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC,CAAA;AAE3E,UAAU,eAAgB,SAAQ,SAAS;IACzC,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;CACd;AAED;;;;GAIG;AACH,MAAM,WAAW,UAAW,SAAQ,SAAS;IAC3C,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,GAAG,QAAQ,CAAA;CAC7B;AAED;;;;;GAKG;AACH,MAAM,MAAM,SAAS,GAAG;IACtB,GAAG,EAAE,MAAM,CAAA;IACX,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;CACf,CAAA;AAED;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG,gBAAgB,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC,CAAA;AAEzE,UAAU,cAAe,SAAQ,SAAS;IACxC,EAAE,EAAE,MAAM,GAAG,SAAS,CAAA;IACtB,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,SAAS,EAAE,CAAA;IAClB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,UAAU,CAAA;IACjB,SAAS,EAAE,MAAM,GAAG,SAAS,CAAA;IAC7B,UAAU,EAAE,OAAO,CAAA;CACpB;AAED;;;;;GAKG;AACH,MAAM,MAAM,SAAS,GAAG,gBAAgB,CAAC,aAAa,CAAC,CAAA;AAEvD,UAAU,aAAc,SAAQ,SAAS;IACvC,IAAI,EAAE,MAAM,CAAA;CACb;AAED;;;;;GAKG;AACH,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,CAAC,EAAE,QAAQ,EAAE,CAAA;CACnB;AAED;;;;GAIG;AACH,MAAM,MAAM,SAAS,GAAG,gBAAgB,CAAC,aAAa,CAAC,CAAA;AAEvD,UAAU,aAAc,SAAQ,SAAS;IACvC,KAAK,EAAE,SAAS,GAAG,WAAW,CAAA;IAC9B,KAAK,EAAE,QAAQ,EAAE,CAAA;CAClB;AAED;;;;;GAKG;AACH,MAAM,MAAM,iBAAiB,GAAG,SAAS,GAAG,OAAO,CAAA;AAEnD;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG,gBAAgB,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC,CAAA;AAEzE,UAAU,cAAe,SAAQ,SAAS;IACxC,IAAI,EAAE,OAAO,CAAA;IACb,OAAO,EAAE,iBAAiB,CAAA;IAC1B,OAAO,EAAE,MAAM,CAAA;IACf,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,UAAU,CAAA;IACjB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,SAAS,CAAA;CACrB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS;IAC9D,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,SAAS,CAAA;IACf,IAAI,EAAE,CAAC,CAAA;CACR;AAED;;;;;;GAMG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,eAAe,EAAE,CAAA;CAC1B"}
|
package/dist/esm/types/visual.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"visual.js","sourceRoot":"","sources":["../../../src/types/visual.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * All supported block types.\n *\n * @group Visual Data Blocks\n * @internal\n */\nexport type BlockType =\n | 'paragraph'\n | 'quote'\n | 'header'\n | 'image'\n | 'raw'\n | 'list'\n | 'video'\n\n/**\n * Represents the possible block widths, used by some blocks.\n *\n * @group Visual Data Blocks\n * @internal\n */\ntype BlockWidth = 'auto' | 'justify' | 'max' | string\n\n/**\n * Alignable block type extension\n *\n * @group Visual Data Blocks\n * @internal\n */\nexport type AlignableBlock<Base> = Base & {\n alignment: Alignment\n}\n\n/**\n * Represents the possible alignments, used by some blocks.\n *\n * @group Visual Data Blocks\n * @internal\n */\nexport type Alignment = 'start' | 'center' | 'end' | 'justify'\n\n/**\n * Stretchable block type extension\n *\n * @group Visual Data Blocks\n * @internal\n */\nexport type StretchableBlock<Base> = Base & {\n isStretched: boolean\n}\n\n/**\n * Base interface for types that represent block data.\n *\n * @group Visual Data Blocks\n */\nexport interface BlockData {\n [key: string]: unknown\n}\n\n/**\n * Represents a Paragraph block, which is the default block type used\n * for text content in the Visual Editor.\n *\n * @group Visual Data Blocks\n */\nexport type ParagraphBlock = StretchableBlock<\n AlignableBlock<BaseParagraphBlock>\n>\n\ninterface BaseParagraphBlock extends BlockData {\n text: string | null\n}\n\n/**\n * Represents a Header block, which is used to render h1 through h6 HTML elements.\n *\n * @group Visual Data Blocks\n */\nexport type HeaderBlock = StretchableBlock<AlignableBlock<BaseHeaderBlock>>\n\ninterface BaseHeaderBlock extends BlockData {\n text: string\n level: number\n}\n\n/**\n * Represents a Quote block, which is used to render a blockquote HTML element.\n *\n * @group Visual Data Blocks\n */\nexport interface QuoteBlock extends BlockData {\n text: string\n caption: string\n alignment: 'left' | 'center'\n}\n\n/**\n * Represents an image file, used in Image blocks.\n *\n * @group Visual Data Blocks\n * @internal\n */\nexport type ImageFile = {\n url: string\n variation: string\n width: number\n height: number\n}\n\n/**\n * Represents an Image block, which is used to render img or picture HTML elements.\n *\n * @group Visual Data Blocks\n */\nexport type ImageBlock = StretchableBlock<AlignableBlock<BaseImageBlock>>\n\ninterface BaseImageBlock extends BlockData {\n id: number | undefined\n url: string\n files: ImageFile[]\n caption?: string\n alt?: string\n href?: string\n width: BlockWidth\n variation: string | undefined\n responsive: boolean\n}\n\n/**\n * Represents an HTML block, which is used to render custom HTML code. Mainly\n * used to place embeds or heavily customized content structures.\n *\n * @group Visual Data Blocks\n */\nexport type HTMLBlock = StretchableBlock<BaseHTMLBlock>\n\ninterface BaseHTMLBlock extends BlockData {\n html: string\n}\n\n/**\n * Represents a list item, which is used by List blocks.\n *\n * @group Visual Data Blocks\n * @internal\n */\nexport interface ListItem {\n content: string\n items?: ListItem[]\n}\n\n/**\n * Represents a List block, which is used to render ol or ul HTML elements.\n *\n * @group Visual Data Blocks\n */\nexport type ListBlock = StretchableBlock<BaseListBlock>\n\ninterface BaseListBlock extends BlockData {\n style: 'ordered' | 'unordered'\n items: ListItem[]\n}\n\n/**\n * Represents the current supported video services, used in Video blocks.\n *\n * @group Visual Data Blocks\n * @internal\n */\nexport type SupportedServices = 'youtube' | 'vimeo'\n\n/**\n * Represents a Video block, which is used to render embed video elements.\n *\n * @group Visual Data Blocks\n */\nexport type VideoBlock = StretchableBlock<AlignableBlock<BaseVideoBlock>>\n\ninterface BaseVideoBlock extends BlockData {\n type: 'embed'\n service: SupportedServices\n videoId: string\n url: string\n html: string\n width: BlockWidth\n caption?: string\n alignment: Alignment\n}\n\n/**\n * A VisualDataBlock object represents a piece of content. Each block has a\n * specific type and some data associated with it. For instance, a Paragraph\n * block has text data, an Image block has a file path and image metadata, etc.\n *\n * @group Visual Data Blocks\n */\nexport interface VisualDataBlock<D extends BlockData = BlockData> {\n id: string\n type: BlockType\n data: D\n}\n\n/**\n * VisualData represents content generated by Starlight using a \"Visual Editor\"\n * field. It's an object-based data representation made out of \"blocks\". Each\n * block has a type string and some data associated with it.\n *\n * @group Visual Data Blocks\n */\nexport interface VisualData {\n time?: number\n version?: string\n blocks: VisualDataBlock[]\n}\n"]}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { MediaFile, MediaObject } from '../types';
|
|
2
|
-
/**
|
|
3
|
-
* Returns the given variation of the provided MediaObject.
|
|
4
|
-
*
|
|
5
|
-
* @param media The MediaObject to analyze. If undefined, the function will also
|
|
6
|
-
* return undefined.
|
|
7
|
-
* @param variation A string or array of strings with the variation name that
|
|
8
|
-
* should be returned. If an array is given, the first variation found will
|
|
9
|
-
* be returned.
|
|
10
|
-
*
|
|
11
|
-
* @returns The MediaFile of the first given variation found. If the provided
|
|
12
|
-
* variations weren't found, or if no variation parameter was provided, returns
|
|
13
|
-
* the optimized variation file (if it exists) or the original file. Returns
|
|
14
|
-
* undefined if no media object is provided.
|
|
15
|
-
*
|
|
16
|
-
* @example Getting the optimized or original file of the given MediaObject.
|
|
17
|
-
* ```ts
|
|
18
|
-
* import Starlight, { getMediaFile } from '@starlightcms/js-sdk'
|
|
19
|
-
*
|
|
20
|
-
* const response = await Starlight.posts.entries.get('foo')
|
|
21
|
-
*
|
|
22
|
-
* // `info.featured_image` is the path of an arbitrary Media content field.
|
|
23
|
-
* const file = getMediaFile(response.data.data.info.featured_image)
|
|
24
|
-
* ```
|
|
25
|
-
*
|
|
26
|
-
* @category Media Utilities
|
|
27
|
-
*/
|
|
28
|
-
export declare const getMediaFile: (media?: MediaObject, variation?: string | string[]) => MediaFile | undefined;
|
|
29
|
-
/**
|
|
30
|
-
* Returns the source URL of the optimized file (if it exists) or the original
|
|
31
|
-
* file of the given MediaObject. If the variation parameter is provided,
|
|
32
|
-
* returns the source URL of that variation instead, if it exists, but falls
|
|
33
|
-
* back to the optimized or original files if it doesn't.
|
|
34
|
-
*
|
|
35
|
-
* @param media The MediaObject to analyze. If undefined, the function will also
|
|
36
|
-
* return undefined.
|
|
37
|
-
* @param variation A string or array of strings with the variation name that
|
|
38
|
-
* should be returned. If an array is given, the first variation found will
|
|
39
|
-
* be returned.
|
|
40
|
-
*
|
|
41
|
-
* @returns The source URL of the first given variation found. If the provided
|
|
42
|
-
* variations weren't found, or if no variation parameter was provided, returns
|
|
43
|
-
* the optimized variation source URL (if it exists) or the original source URL.
|
|
44
|
-
* Returns undefined if no media object is provided.
|
|
45
|
-
*
|
|
46
|
-
* @example Getting the optimized or original source URL of the given MediaObject.
|
|
47
|
-
* ```ts
|
|
48
|
-
* import Starlight, { getMediaSource } from '@starlightcms/js-sdk'
|
|
49
|
-
*
|
|
50
|
-
* const response = await Starlight.posts.entries.get('foo')
|
|
51
|
-
*
|
|
52
|
-
* // `content.background` is the path of an arbitrary Media content field.
|
|
53
|
-
* const imageUrl = getMediaSource(response.data.data.content.background)
|
|
54
|
-
* ```
|
|
55
|
-
*
|
|
56
|
-
* @example Getting the source URL of a specific variation of the given MediaObject.
|
|
57
|
-
* ```ts
|
|
58
|
-
* import Starlight, { getMediaSource } from '@starlightcms/js-sdk'
|
|
59
|
-
*
|
|
60
|
-
* const response = await Starlight.posts.entries.get('foo')
|
|
61
|
-
*
|
|
62
|
-
* // `content.background` is the path of an arbitrary Media content field.
|
|
63
|
-
* const imageUrl = getMediaSource(
|
|
64
|
-
* response.data.data.content.background,
|
|
65
|
-
* ['large', 'medium']
|
|
66
|
-
* )
|
|
67
|
-
* ```
|
|
68
|
-
*
|
|
69
|
-
* @category Media Utilities
|
|
70
|
-
*/
|
|
71
|
-
export declare function getMediaSource(media?: MediaObject, variation?: string | string[]): string | undefined;
|
|
72
|
-
//# sourceMappingURL=image.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"image.d.ts","sourceRoot":"","sources":["../../../src/utils/image.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAejD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,YAAY,GACvB,QAAQ,WAAW,EACnB,YAAY,MAAM,GAAG,MAAM,EAAE,KAC5B,SAAS,GAAG,SAgBd,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,wBAAgB,cAAc,CAC5B,KAAK,CAAC,EAAE,WAAW,EACnB,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,sBAG9B"}
|
package/dist/esm/utils/image.js
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Returns the optimized variation file of the given MediaObject
|
|
3
|
-
* or the original file if the optimized variation doesn't exist.
|
|
4
|
-
*
|
|
5
|
-
* @param media The MediaObject to analyze.
|
|
6
|
-
*/
|
|
7
|
-
const getOptimizedOrOriginal = (media) => {
|
|
8
|
-
var _a;
|
|
9
|
-
return ((_a = media.files.find((file) => file.variation === 'optimized')) !== null && _a !== void 0 ? _a : media.files.find((file) => file.variation === 'original'));
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* Returns the given variation of the provided MediaObject.
|
|
13
|
-
*
|
|
14
|
-
* @param media The MediaObject to analyze. If undefined, the function will also
|
|
15
|
-
* return undefined.
|
|
16
|
-
* @param variation A string or array of strings with the variation name that
|
|
17
|
-
* should be returned. If an array is given, the first variation found will
|
|
18
|
-
* be returned.
|
|
19
|
-
*
|
|
20
|
-
* @returns The MediaFile of the first given variation found. If the provided
|
|
21
|
-
* variations weren't found, or if no variation parameter was provided, returns
|
|
22
|
-
* the optimized variation file (if it exists) or the original file. Returns
|
|
23
|
-
* undefined if no media object is provided.
|
|
24
|
-
*
|
|
25
|
-
* @example Getting the optimized or original file of the given MediaObject.
|
|
26
|
-
* ```ts
|
|
27
|
-
* import Starlight, { getMediaFile } from '@starlightcms/js-sdk'
|
|
28
|
-
*
|
|
29
|
-
* const response = await Starlight.posts.entries.get('foo')
|
|
30
|
-
*
|
|
31
|
-
* // `info.featured_image` is the path of an arbitrary Media content field.
|
|
32
|
-
* const file = getMediaFile(response.data.data.info.featured_image)
|
|
33
|
-
* ```
|
|
34
|
-
*
|
|
35
|
-
* @category Media Utilities
|
|
36
|
-
*/
|
|
37
|
-
export const getMediaFile = (media, variation) => {
|
|
38
|
-
if (!media)
|
|
39
|
-
return undefined;
|
|
40
|
-
if (variation) {
|
|
41
|
-
const variationArray = Array.isArray(variation) ? variation : [variation];
|
|
42
|
-
for (const variationName of variationArray) {
|
|
43
|
-
const file = media.files.find((file) => file.variation === variationName);
|
|
44
|
-
if (file) {
|
|
45
|
-
return file;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return getOptimizedOrOriginal(media);
|
|
50
|
-
};
|
|
51
|
-
/**
|
|
52
|
-
* Returns the source URL of the optimized file (if it exists) or the original
|
|
53
|
-
* file of the given MediaObject. If the variation parameter is provided,
|
|
54
|
-
* returns the source URL of that variation instead, if it exists, but falls
|
|
55
|
-
* back to the optimized or original files if it doesn't.
|
|
56
|
-
*
|
|
57
|
-
* @param media The MediaObject to analyze. If undefined, the function will also
|
|
58
|
-
* return undefined.
|
|
59
|
-
* @param variation A string or array of strings with the variation name that
|
|
60
|
-
* should be returned. If an array is given, the first variation found will
|
|
61
|
-
* be returned.
|
|
62
|
-
*
|
|
63
|
-
* @returns The source URL of the first given variation found. If the provided
|
|
64
|
-
* variations weren't found, or if no variation parameter was provided, returns
|
|
65
|
-
* the optimized variation source URL (if it exists) or the original source URL.
|
|
66
|
-
* Returns undefined if no media object is provided.
|
|
67
|
-
*
|
|
68
|
-
* @example Getting the optimized or original source URL of the given MediaObject.
|
|
69
|
-
* ```ts
|
|
70
|
-
* import Starlight, { getMediaSource } from '@starlightcms/js-sdk'
|
|
71
|
-
*
|
|
72
|
-
* const response = await Starlight.posts.entries.get('foo')
|
|
73
|
-
*
|
|
74
|
-
* // `content.background` is the path of an arbitrary Media content field.
|
|
75
|
-
* const imageUrl = getMediaSource(response.data.data.content.background)
|
|
76
|
-
* ```
|
|
77
|
-
*
|
|
78
|
-
* @example Getting the source URL of a specific variation of the given MediaObject.
|
|
79
|
-
* ```ts
|
|
80
|
-
* import Starlight, { getMediaSource } from '@starlightcms/js-sdk'
|
|
81
|
-
*
|
|
82
|
-
* const response = await Starlight.posts.entries.get('foo')
|
|
83
|
-
*
|
|
84
|
-
* // `content.background` is the path of an arbitrary Media content field.
|
|
85
|
-
* const imageUrl = getMediaSource(
|
|
86
|
-
* response.data.data.content.background,
|
|
87
|
-
* ['large', 'medium']
|
|
88
|
-
* )
|
|
89
|
-
* ```
|
|
90
|
-
*
|
|
91
|
-
* @category Media Utilities
|
|
92
|
-
*/
|
|
93
|
-
export function getMediaSource(media, variation) {
|
|
94
|
-
return media ? getMediaFile(media, variation).path : undefined;
|
|
95
|
-
}
|
|
96
|
-
//# sourceMappingURL=image.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"image.js","sourceRoot":"","sources":["../../../src/utils/image.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,sBAAsB,GAAG,CAAC,KAAkB,EAAE,EAAE;;IACpD,OAAO,CACL,MAAA,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,KAAK,WAAW,CAAC,mCACzD,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,KAAK,UAAU,CAAe,CACzE,CAAA;AACH,CAAC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,KAAmB,EACnB,SAA6B,EACN,EAAE;IACzB,IAAI,CAAC,KAAK;QAAE,OAAO,SAAS,CAAA;IAE5B,IAAI,SAAS,EAAE,CAAC;QACd,MAAM,cAAc,GAAG,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;QAEzE,KAAK,MAAM,aAAa,IAAI,cAAc,EAAE,CAAC;YAC3C,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,KAAK,aAAa,CAAC,CAAA;YAEzE,IAAI,IAAI,EAAE,CAAC;gBACT,OAAO,IAAI,CAAA;YACb,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,sBAAsB,CAAC,KAAK,CAAC,CAAA;AACtC,CAAC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,MAAM,UAAU,cAAc,CAC5B,KAAmB,EACnB,SAA6B;IAE7B,OAAO,KAAK,CAAC,CAAC,CAAC,YAAY,CAAC,KAAK,EAAE,SAAS,CAAE,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAA;AACjE,CAAC","sourcesContent":["import { MediaFile, MediaObject } from '../types'\n\n/**\n * Returns the optimized variation file of the given MediaObject\n * or the original file if the optimized variation doesn't exist.\n *\n * @param media The MediaObject to analyze.\n */\nconst getOptimizedOrOriginal = (media: MediaObject) => {\n return (\n media.files.find((file) => file.variation === 'optimized') ??\n (media.files.find((file) => file.variation === 'original') as MediaFile)\n )\n}\n\n/**\n * Returns the given variation of the provided MediaObject.\n *\n * @param media The MediaObject to analyze. If undefined, the function will also\n * return undefined.\n * @param variation A string or array of strings with the variation name that\n * should be returned. If an array is given, the first variation found will\n * be returned.\n *\n * @returns The MediaFile of the first given variation found. If the provided\n * variations weren't found, or if no variation parameter was provided, returns\n * the optimized variation file (if it exists) or the original file. Returns\n * undefined if no media object is provided.\n *\n * @example Getting the optimized or original file of the given MediaObject.\n * ```ts\n * import Starlight, { getMediaFile } from '@starlightcms/js-sdk'\n *\n * const response = await Starlight.posts.entries.get('foo')\n *\n * // `info.featured_image` is the path of an arbitrary Media content field.\n * const file = getMediaFile(response.data.data.info.featured_image)\n * ```\n *\n * @category Media Utilities\n */\nexport const getMediaFile = (\n media?: MediaObject,\n variation?: string | string[],\n): MediaFile | undefined => {\n if (!media) return undefined\n\n if (variation) {\n const variationArray = Array.isArray(variation) ? variation : [variation]\n\n for (const variationName of variationArray) {\n const file = media.files.find((file) => file.variation === variationName)\n\n if (file) {\n return file\n }\n }\n }\n\n return getOptimizedOrOriginal(media)\n}\n\n/**\n * Returns the source URL of the optimized file (if it exists) or the original\n * file of the given MediaObject. If the variation parameter is provided,\n * returns the source URL of that variation instead, if it exists, but falls\n * back to the optimized or original files if it doesn't.\n *\n * @param media The MediaObject to analyze. If undefined, the function will also\n * return undefined.\n * @param variation A string or array of strings with the variation name that\n * should be returned. If an array is given, the first variation found will\n * be returned.\n *\n * @returns The source URL of the first given variation found. If the provided\n * variations weren't found, or if no variation parameter was provided, returns\n * the optimized variation source URL (if it exists) or the original source URL.\n * Returns undefined if no media object is provided.\n *\n * @example Getting the optimized or original source URL of the given MediaObject.\n * ```ts\n * import Starlight, { getMediaSource } from '@starlightcms/js-sdk'\n *\n * const response = await Starlight.posts.entries.get('foo')\n *\n * // `content.background` is the path of an arbitrary Media content field.\n * const imageUrl = getMediaSource(response.data.data.content.background)\n * ```\n *\n * @example Getting the source URL of a specific variation of the given MediaObject.\n * ```ts\n * import Starlight, { getMediaSource } from '@starlightcms/js-sdk'\n *\n * const response = await Starlight.posts.entries.get('foo')\n *\n * // `content.background` is the path of an arbitrary Media content field.\n * const imageUrl = getMediaSource(\n * response.data.data.content.background,\n * ['large', 'medium']\n * )\n * ```\n *\n * @category Media Utilities\n */\nexport function getMediaSource(\n media?: MediaObject,\n variation?: string | string[],\n) {\n return media ? getMediaFile(media, variation)!.path : undefined\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA"}
|
package/dist/esm/utils/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA","sourcesContent":["export * from './image'\n"]}
|