New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@hv/datoloader

Package Overview
Dependencies
Maintainers
0
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hv/datoloader

Dato Loader ===========

latest
npmnpm
Version
3.0.2
Version published
Maintainers
0
Created
Source

Dato Loader

Downloads all data from DatoCMS. Data will be simplified. Typescript can be generated.

Usage

import { writeFile } from 'fs/promises';
import { Loader, generateTypescript } from '@hv/datoloader';

const loader = new Loader(process.env.DATO_API_KEY, {
	onUpdate,
	languages: { de: ['en'] },
});
loader.start();

async function onUpdate(data) {
	await writeFile('data.json', JSON.stringify(data, null, 2));
	await writeFile('data.ts', generateTypescript(firstLang));
}

Options:

export interface Options {
	onUpdate: (payload: Result) => void | null
	watch: boolean // keep watching for changes, onUpdate will be called again
	changeKey: (key: string) => string // how to change the keys of the data (default: camelcase)
	languages?: string[] | { [language: string]: string[] } // langauge: fallbackLanguages
	itemVersion: boolean // include item version?
	itemCreatedAt: boolean // include item createdAt?
	itemUpdatedAt: boolean // include item updatedAt?
	environment?: string
	draft?: boolean
	headers?: Record<string, string>
}

Please note that the resulting data will be simplified to someting like this:

{
  "de": {
    "itemType": {
      "anotherBlock": {
        "fields": {
          "title": {
            "type": "string",
            "localized": false,
            "required": false
          }
        }
      }
    },
    "site": {
      "name": "Boilerplate",
      ...
    },
    "upload": {
      "54053638": {
        "_id": "54053638",
        "size": 9207613,
        "width": 3840,
        "height": 2160,
        "url": "https://www.datocms-assets.com/99255/1682668783-weitsicht-3840x2160.png",
        ...
      }
    },
    "item": {
      "146161091": {
        "_id": "146161091",
        "_type": "anotherBlock",
        "title": "Just Another",
        "_updatedAt": "2023-04-28T08:02:27.684Z",
        "_createdAt": "2023-04-28T08:02:27.680Z",
        "_version": 267617551
      }
    }
  }
}

Later, you can use the generated data and typescript like this:

import { readFile } from 'fs/promises';
import { Result, resolve } from '@hv/datoloader';

export async function loadData() {
	const data = JSON.parse(await readFile('data.json'));
	return resolve(data) as Result;
}

Resolving will link actual items to their references. So anything like items: ["23434232", "23423423"] will be resolved to items: [{_id: "23434232", ...}, {_id: "23423423", ...}].

FAQs

Package last updated on 25 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts