Skip to content

Commit

Permalink
style: update eslint config (#343)
Browse files Browse the repository at this point in the history
* style: update eslint config

* style: run prettier

* style: run prettier

* style: run prettier

---------

Co-authored-by: lihbr <lihbr@users.noreply.github.com>
  • Loading branch information
lihbr and lihbr authored Jul 24, 2024
1 parent 3bcf410 commit ed5a90e
Show file tree
Hide file tree
Showing 297 changed files with 5,613 additions and 5,654 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module.exports = {
],
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/explicit-module-boundary-types": "error",
"@typescript-eslint/consistent-type-imports": "error",
"tsdoc/syntax": "warn",
},
};
}
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"importOrderGroupNamespaceSpecifiers": true,
"printWidth": 80,
"useTabs": true,
"semi": true,
"semi": false,
"singleQuote": false,
"quoteProps": "as-needed",
"jsxSingleQuote": false,
Expand Down
16 changes: 8 additions & 8 deletions .size-limit.cjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const pkg = require("./package.json");
const pkg = require("./package.json")

function getObjectValues(input, acc = []) {
if (typeof input === "string") {
return input;
return input
} else {
return [
...acc,
...Object.values(input).flatMap((value) => getObjectValues(value)),
];
]
}
}

Expand All @@ -16,15 +16,15 @@ module.exports = [
]
.sort()
.filter((path) => {
return path && path !== "./package.json" && !path.endsWith(".d.ts");
return path && path !== "./package.json" && !path.endsWith(".d.ts")
})
.map((path) => {
return {
path,
modifyEsbuildConfig(config) {
config.platform = "node";
config.platform = "node"

return config;
return config
},
};
});
}
})
3 changes: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ npm run release:alpha
```

[^1]: This package is maintained by the DevX team. Prismic employees can ask for help or a review in the [#team-devx](https://prismic-team.slack.com/archives/C014VAACCQL) Slack channel.

[^2]: Prismic employees are highly encouraged to discuss changes with the DevX team in the [#team-devx](https://prismic-team.slack.com/archives/C014VAACCQL) Slack channel before starting.

[^3]: Code should be reviewed by the DevX team before merging. Prismic employees can request a review in the [#team-devx](https://prismic-team.slack.com/archives/CPG31MDL1) Slack channel.

[^4]: Prismic employees can ask the DevX team for [npm](https://www.npmjs.com) publish access.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ The official JavaScript + TypeScript client library for [Prismic][prismic].
- Built for browser and server usage.

```typescript
import * as prismic from "@prismicio/client";
import * as prismic from "@prismicio/client"

// Create a client
const client = prismic.createClient("my-repository");
const client = prismic.createClient("my-repository")

// Then query for your content
const blogPosts = await client.getAllByType("blog_post");
const blogPosts = await client.getAllByType("blog_post")
```

## Install
Expand Down
28 changes: 14 additions & 14 deletions examples/custom-query-caching/index.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
import * as prismic from "@prismicio/client";
import fetch from "node-fetch";
import QuickLRU from "quick-lru";
import * as prismic from "@prismicio/client"
import fetch from "node-fetch"
import QuickLRU from "quick-lru"

const cache = new QuickLRU({
maxSize: 1000, // 1000 entries
});
})

const client = prismic.createClient("qwerty", {
fetch: async (url, options) => {
// The cache key contains the requested URL and headers
const key = JSON.stringify({ url, options });
const key = JSON.stringify({ url, options })

if (cache.has(key)) {
// If the cache contains a value for the key, return it
return cache.get(key).clone();
return cache.get(key).clone()
} else {
// Otherwise, make the network request
const res = await fetch(url, options);
const res = await fetch(url, options)

if (res.ok) {
// If the request was successful, save it to the cache
cache.set(key, res.clone());
cache.set(key, res.clone())
}

return res;
return res
}
},
});
})

const homepage = await client.getByUID("page", "home");
console.info("First uncached result: ", homepage);
const homepage = await client.getByUID("page", "home")
console.info("First uncached result: ", homepage)
// => The `page` document with a UID of `home`

const homepageFetchedAgain = await client.getByUID("page", "home");
console.info("Second cached result: ", homepageFetchedAgain);
const homepageFetchedAgain = await client.getByUID("page", "home")
console.info("Second cached result: ", homepageFetchedAgain)
// => This call will use the cache rather than make another network request.
42 changes: 21 additions & 21 deletions examples/custom-query-timeout/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as prismic from "@prismicio/client";
import * as prismic from "@prismicio/client"
// AbortController was added in node v14.17.0 globally. If you are using a node
// version >=14.17.0, or are not in a node environment, remove this line.
import { AbortController } from "abort-controller";
import fetch, { AbortError } from "node-fetch";
import { AbortController } from "abort-controller"
import fetch, { AbortError } from "node-fetch"

// A global timeout can be implemented like the following. This timeout will
// apply to all network requests made by the client.
Expand All @@ -11,59 +11,59 @@ const client = prismic.createClient("qwerty", {
// Create an AbortController. This will be used to cancel the
// `fetch()` request if it does not resolve within the given
// timespan.
const controller = new AbortController();
const controller = new AbortController()

// After 1ms, cancel the `fetch()` request.
// 1ms is used to force a timeout. In a real-world scenario,
// something like 3000ms is more appropriate.
const timeoutId = setTimeout(() => controller.abort(), 1);
const timeoutId = setTimeout(() => controller.abort(), 1)

// Fetch the requested URL with the AbortController. If
// `controller.abort()` is called, the `fetch()` request will
// be cancelled.
const res = await fetch(url, {
signal: controller.signal,
...options,
});
})

// We must stop the timeout once the `fetch()` request is
// complete.
clearTimeout(timeoutId);
clearTimeout(timeoutId)

return res;
return res
},
});
})

// This query will throw if it does not resolve within the timeout duration.
const articles = await client.getAllByType("article");
console.info(articles);
const articles = await client.getAllByType("article")
console.info(articles)
// => A list of all `article` documents

// If you want to handle timeouts, you can check the error's type.
try {
const articles = await client.getAllByType("article");
console.info(articles);
const articles = await client.getAllByType("article")
console.info(articles)
} catch (error) {
if (error instanceof AbortError) {
console.error("The request timed out.");
console.error("The request timed out.")
} else {
throw error;
throw error
}
}

// You can also set timeouts for individual client methods by passing an
// AbortController signal to the method.
try {
const controller = new AbortController();
setTimeout(() => controller.abort(), 1);
const controller = new AbortController()
setTimeout(() => controller.abort(), 1)
const articles = await client.getAllByType("article", {
signal: controller.signal,
});
console.info(articles);
})
console.info(articles)
} catch (error) {
if (error instanceof AbortError) {
console.error("The request timed out.");
console.error("The request timed out.")
} else {
throw error;
throw error
}
}
22 changes: 11 additions & 11 deletions examples/query-multiple-languages/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as prismic from "@prismicio/client";
import fetch from "node-fetch";
import * as prismic from "@prismicio/client"
import fetch from "node-fetch"

const client = prismic.createClient("qwerty", {
fetch,
Expand All @@ -8,22 +8,22 @@ const client = prismic.createClient("qwerty", {
defaultParams: {
lang: "en-us",
},
});
})

// This will fetch Article documents with the `en-us` lang.
const articlesDefaultLanguage = await client.getAllByType("article");
console.info("articlesDefaultLanguage: ", articlesDefaultLanguage);
const articlesDefaultLanguage = await client.getAllByType("article")
console.info("articlesDefaultLanguage: ", articlesDefaultLanguage)

// This will also fetch Article documents with the `en-us` lang.
const articlesEnglish = await client.getAllByType("article", { lang: "en-us" });
console.info("articlesEnglish: ", articlesEnglish);
const articlesEnglish = await client.getAllByType("article", { lang: "en-us" })
console.info("articlesEnglish: ", articlesEnglish)

// This will fetch Article documents with the `fr-fr` lang.
const articlesFrench = await client.getAllByType("article", { lang: "fr-fr" });
console.info("articlesFrench: ", articlesFrench);
const articlesFrench = await client.getAllByType("article", { lang: "fr-fr" })
console.info("articlesFrench: ", articlesFrench)

// This will fetch Article documents with any language.
const articlesAllLanguages = await client.getAllByType("article", {
lang: "*",
});
console.info("articlesAllLanguages: ", articlesAllLanguages);
})
console.info("articlesAllLanguages: ", articlesAllLanguages)
30 changes: 15 additions & 15 deletions examples/query-using-refs/index.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
import * as prismic from "@prismicio/client";
import fetch from "node-fetch";
import * as prismic from "@prismicio/client"
import fetch from "node-fetch"

const client = prismic.createClient("qwerty", {
fetch,
});
})

// By default, the client will fetch the latest published content from the repository.
// This means content is fetched from the "master ref".
const homepage = await client.getByUID("page", "home");
console.info(homepage);
const homepage = await client.getByUID("page", "home")
console.info(homepage)

// We can get a list of all refs in a repository.
const refs = await client.getRefs();
console.info(refs);
const refs = await client.getRefs()
console.info(refs)

// Or we can get a specific ref by its label.
// If we have an ID instead, `client.getRefByID` can be used.
const ref = await client.getRefByLabel("My Specific Ref");
const ref = await client.getRefByLabel("My Specific Ref")

// If we want to query content from a specific ref, we can tell the client to
// make all future queries use that ref.
client.queryContentFromRef(ref.ref);
client.queryContentFromRef(ref.ref)

// Now queries will fetch content from the "My Specific Ref" ref.
const aboutPage = await client.getByUID("page", "about");
console.info(aboutPage);
const aboutPage = await client.getByUID("page", "about")
console.info(aboutPage)

// We can also override the ref on a per-query basis.
const otherRef = await client.getRefByLabel("My Other Ref");
const otherRef = await client.getRefByLabel("My Other Ref")
const contactPage = await client.getByUID("page", "contact", {
ref: otherRef.ref,
});
console.info(contactPage);
})
console.info(contactPage)

// We can change back to fetching the latest content with the following function.
client.queryLatestContent();
client.queryLatestContent()
32 changes: 16 additions & 16 deletions examples/query-using-releases/index.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
import * as prismic from "@prismicio/client";
import fetch from "node-fetch";
import * as prismic from "@prismicio/client"
import fetch from "node-fetch"

const client = prismic.createClient("qwerty", {
fetch,
});
})

// By default, the client will fetch the latest published content from the repository.
// This means content is fetched from the "master ref".
const homepage = await client.getByUID("page", "home");
console.info(homepage);
const homepage = await client.getByUID("page", "home")
console.info(homepage)

// We can get a list of all releases in a repository.
const releases = await client.getReleases();
console.info(releases);
const releases = await client.getReleases()
console.info(releases)

// Or we can get a specific release by its label.
// If we have an ID instead, `client.getReleaseByID` can be used.
const release = await client.getReleaseByLabel("My Specific Release");
console.info(release);
const release = await client.getReleaseByLabel("My Specific Release")
console.info(release)

// We can tell the client to make all queries point to a released called "My Release".
// We could also use `client.queryContentFromReleaseByID` if we have an ID instead.
client.queryContentFromReleaseByLabel("My Release");
client.queryContentFromReleaseByLabel("My Release")

// Now queries will fetch content from "My Release".
const aboutPage = await client.getByUID("page", "about");
console.info(aboutPage);
const aboutPage = await client.getByUID("page", "about")
console.info(aboutPage)

// We can also override the release on a per-query basis.
const otherRelease = await client.getReleaseByLabel("My Other Release");
const otherRelease = await client.getReleaseByLabel("My Other Release")
const contactPage = await client.getByUID("page", "contact", {
ref: otherRelease.ref,
});
console.info(contactPage);
})
console.info(contactPage)

// We can change back to fetching the latest content with the following function.
client.queryLatestContent();
client.queryLatestContent()
10 changes: 5 additions & 5 deletions examples/server-usage/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as prismic from "@prismicio/client";
import fetch from "node-fetch";
import * as prismic from "@prismicio/client"
import fetch from "node-fetch"

const client = prismic.createClient("qwerty", {
// Here, we provide a way for the client to make network requests.
// `node-fetch` is a Node.js fetch-compatible package.
fetch,
});
})

const homepage = await client.getByUID("page", "home");
console.info(homepage);
const homepage = await client.getByUID("page", "home")
console.info(homepage)
// => The `page` document with a UID of `home`
Loading

0 comments on commit ed5a90e

Please sign in to comment.