This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This script migrates data from a Fauna database to somewhere else. | |
* How to use it: | |
* 1. Fill out the COLLECTION_NAMES array with the names of the collections you want to migrate | |
* 2. Fill out the migrateDocument function with the logic to migrate a single document | |
* 3. Make sure your FAUNA_SECRET and FAUNA_ENDPOINT variables are set up correctly | |
* 4. Run the script with `npx tsx migrate-fauna-data.ts` | |
* | |
* Please add feedback or suggestions in the comments! | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { groq } from 'next-sanity' // Replace with another library if you don't use Next.JS | |
import { client } from './client' // Replace this with wherever you have set up your client | |
/** | |
* Resolves all unresolved references when fetching from the Sanity GraphQL API. | |
* There is no native way to do this, so we have to do it manually. | |
* @param data | |
*/ | |
export const resolveSanityGraphqlReferences = async <T = unknown>( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @see https://gist.github.com/employee451/938ae007cddd9733b64acb9a958428bd | |
import { getNestedObjectKeyNames } from '@shared/helpers/getNestedObjectKeyNames' | |
type MissingKeyResult = { | |
/** The index of the object that has the missing key */ | |
missingKeyObject: number | |
/** The index of the object where the missing key comes from */ | |
missingKeyOrigin: number | |
/** Name of the key that is missing */ | |
keyName: string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Returns an array with the names of the keys of an object. | |
* Supports nested objects. | |
* | |
* @example | |
* getObjectKeyNames({ | |
* some: { | |
* nested: { | |
* value: 'string' | |
* } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type AcceptedArrayContents = string | { [key: string]: any } | |
/** | |
* Sorts an array alphabetically. If an object is provided, it sorts by the provided sortProperty. | |
* @param array | |
* @param sortProperty | |
*/ | |
const sortArrayAlphabetically = ( | |
array: AcceptedArrayContents[] = [], | |
sortProperty = '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type RetrierResponseType<DataType> = | |
| { | |
success: false | |
data?: any | |
} | |
| { | |
success: true | |
data: DataType | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @see https://gist.github.com/employee451/b4414c0cc4f5a818eea82f881c4dc227 | |
import getNestedProperty from './getNestedProperty' | |
/** | |
* Returns an array without duplicate items based on the provided object property | |
*/ | |
function removeArrayDuplicatesByProperty<ItemType = any>( | |
array: ItemType[], | |
property: string | |
): ItemType[] { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Takes an object of key-value pairs, and assembles them to a URI string | |
* @param { Object } object | |
* @returns { String } A URI string | |
*/ | |
export const objectToUriString = (object: { | |
[key: string]: string | number | null | undefined | |
}): string => | |
Object.keys(object) | |
.map((key) => key + '=' + encodeURIComponent(object[key] || '')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Safely gets a value from object using the provided path. Return `undefined` if it doesn't exist | |
* Similar to lodash.get: https://lodash.com/docs/#get | |
* | |
* @param {{}} obj - target object | |
* @param {string} path - path to a nested value | |
* @param {*} defaultValue - gets returned if path resolved to `undefined` | |
* | |
* @see https://gist.github.com/jeneg/9767afdcca45601ea44930ea03e0febf#gistcomment-1935901 | |
*/ |