@camox/api-contract 0.48.0 → 0.51.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/drafts.js +1 -0
- package/dist/index.d.ts +1 -12745
- package/dist/locales.d.ts +25 -0
- package/dist/locales.js +29 -0
- package/dist/projects.d.ts +2 -0
- package/dist/projects.js +3 -1
- package/dist/router.d.ts +13208 -0
- package/dist/router.js +0 -0
- package/package.json +9 -1
- package/src/drafts.ts +2 -1
- package/src/index.ts +0 -3
- package/src/locales.ts +34 -0
- package/src/projects.ts +3 -0
- package/src/router.ts +5 -0
package/dist/router.js
ADDED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@camox/api-contract",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.51.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"src",
|
|
@@ -39,6 +39,14 @@
|
|
|
39
39
|
"./projects": {
|
|
40
40
|
"types": "./dist/projects.d.ts",
|
|
41
41
|
"default": "./dist/projects.js"
|
|
42
|
+
},
|
|
43
|
+
"./locales": {
|
|
44
|
+
"types": "./dist/locales.d.ts",
|
|
45
|
+
"default": "./dist/locales.js"
|
|
46
|
+
},
|
|
47
|
+
"./router": {
|
|
48
|
+
"types": "./dist/router.d.ts",
|
|
49
|
+
"default": "./dist/router.js"
|
|
42
50
|
}
|
|
43
51
|
},
|
|
44
52
|
"dependencies": {
|
package/src/drafts.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Router } from "./
|
|
1
|
+
import type { Router } from "./router.ts";
|
|
2
2
|
|
|
3
3
|
/** Request header naming the draft a request reads and writes (ADR 0011). Absent means Live. */
|
|
4
4
|
export const DRAFT_HEADER = "x-camox-draft";
|
|
@@ -147,6 +147,7 @@ const FILE_WRITES: Record<keyof Router["files"], boolean> = {
|
|
|
147
147
|
const PAGE_WRITES: Record<keyof Router["pages"], boolean> = {
|
|
148
148
|
getByPath: false,
|
|
149
149
|
getStructure: false,
|
|
150
|
+
getMarkdown: false,
|
|
150
151
|
list: false,
|
|
151
152
|
listBySlug: false,
|
|
152
153
|
get: false,
|
package/src/index.ts
CHANGED
|
@@ -4,6 +4,3 @@ export * from "./ids.ts";
|
|
|
4
4
|
export * from "./record-templates.ts";
|
|
5
5
|
export * from "./reference-query.ts";
|
|
6
6
|
export * from "./structured-data.ts";
|
|
7
|
-
export type { Router } from "../../../apps/api/src/router";
|
|
8
|
-
export type { PublishPreview } from "../../../apps/api/src/domains/drafts/publish";
|
|
9
|
-
export type { EntityKind } from "../../../apps/api/src/domains/drafts/overlay";
|
package/src/locales.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The URL names the locale (ADR 0015): a non-default locale's paths sit under its prefix
|
|
3
|
+
* (`/de/preise`), the default locale's have none. Pure, so the API, the runtime and the browser
|
|
4
|
+
* read a path the same way.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/** A locale of a project, as `locales.list` returns it. */
|
|
8
|
+
export type LocaleView = { tag: string; isDefault: boolean };
|
|
9
|
+
|
|
10
|
+
/** A runtime path split into the locale it names and the locale-relative path after its prefix. */
|
|
11
|
+
export type LocalePath = { locale: LocaleView; path: string };
|
|
12
|
+
|
|
13
|
+
/** A locale's URL prefix: its tag in lowercase. The default locale has none. */
|
|
14
|
+
export function localePrefix(locale: LocaleView): string {
|
|
15
|
+
return locale.isDefault ? "" : `/${locale.tag.toLowerCase()}`;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The locale a runtime path names, and the path after its prefix, without search or hash. A first
|
|
20
|
+
* segment that isn't a non-default locale's prefix leaves the path the default locale's. A
|
|
21
|
+
* locale's home is `/de`; `/de/` names it too.
|
|
22
|
+
*/
|
|
23
|
+
export function parseLocalePath(pathname: string, locales: readonly LocaleView[]): LocalePath {
|
|
24
|
+
const path = pathname.replace(/[?#].*$/s, "") || "/";
|
|
25
|
+
const end = path.indexOf("/", 1);
|
|
26
|
+
const segment = end === -1 ? path.slice(1) : path.slice(1, end);
|
|
27
|
+
const named = locales.find(
|
|
28
|
+
(locale) => !locale.isDefault && localePrefix(locale) === `/${segment}`,
|
|
29
|
+
);
|
|
30
|
+
if (named) return { locale: named, path: end === -1 ? "/" : path.slice(end) };
|
|
31
|
+
const fallback = locales.find((locale) => locale.isDefault);
|
|
32
|
+
if (!fallback) throw new Error("A project's locales include its default locale.");
|
|
33
|
+
return { locale: fallback, path };
|
|
34
|
+
}
|
package/src/projects.ts
CHANGED
|
@@ -42,6 +42,9 @@ export const projectSlugSchema = /* @__PURE__ */ z
|
|
|
42
42
|
"Use lowercase letters, digits and hyphens, without a hyphen at either end",
|
|
43
43
|
);
|
|
44
44
|
|
|
45
|
+
/** The address a project's website is served at: its Project Slug's `camox.site` subdomain. */
|
|
46
|
+
export const projectWebsiteUrl = (slug: string) => `https://${slug}.camox.site`;
|
|
47
|
+
|
|
45
48
|
/** Why a slug can't be given to a new project. */
|
|
46
49
|
export type UnavailableSlugReason = "invalid" | "reserved" | "taken";
|
|
47
50
|
|
package/src/router.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// The API's router and server-side types. Kept off the main entry so a site importing
|
|
2
|
+
// `camox` doesn't load the whole API's types (and packages it can't resolve).
|
|
3
|
+
export type { Router } from "../../../apps/api/src/router";
|
|
4
|
+
export type { PublishPreview } from "../../../apps/api/src/domains/drafts/publish";
|
|
5
|
+
export type { EntityKind } from "../../../apps/api/src/domains/drafts/overlay";
|