forgepress 0.0.0 → 0.0.1
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/THIRD-PARTY-LICENSES.md +97 -0
- package/dist/_chunks/client.d.mts +2 -0
- package/dist/_chunks/config.d.mts +35 -0
- package/dist/_chunks/config.mjs +37 -0
- package/dist/_chunks/entry.d.mts +194 -0
- package/dist/_chunks/error.mjs +4 -0
- package/dist/_chunks/fetch.mjs +13 -0
- package/dist/_chunks/libs/@oxc-project/types.d.mts +1297 -0
- package/dist/_chunks/libs/@rolldown/pluginutils.d.mts +62 -0
- package/dist/_chunks/libs/rolldown.d.mts +4711 -0
- package/dist/_chunks/locate.mjs +7 -0
- package/dist/_chunks/output.mjs +258 -0
- package/dist/_chunks/output2.mjs +333 -0
- package/dist/_chunks/overlay.mjs +8 -0
- package/dist/_chunks/parse.mjs +22 -0
- package/dist/_chunks/reader.mjs +23 -0
- package/dist/_chunks/reader2.mjs +849 -0
- package/dist/_chunks/references.mjs +53 -0
- package/dist/_chunks/types.d.mts +25 -0
- package/dist/_chunks/types.mjs +2 -0
- package/dist/_chunks/validate.mjs +600 -0
- package/dist/_chunks/value.mjs +17 -0
- package/dist/cli/bin.d.mts +1 -0
- package/dist/cli/bin.mjs +48 -0
- package/dist/disk/reader.d.mts +4 -0
- package/dist/disk/reader.mjs +2 -0
- package/dist/editor/index.d.mts +3 -0
- package/dist/editor/index.mjs +60643 -0
- package/dist/index.d.mts +105 -0
- package/dist/index.mjs +247 -0
- package/dist/preview/index.d.mts +5 -0
- package/dist/preview/index.mjs +244 -0
- package/dist/query/fetch.d.mts +3 -0
- package/dist/query/fetch.mjs +2 -0
- package/dist/unplugin.d.mts +18 -0
- package/dist/unplugin.mjs +501 -0
- package/package.json +82 -2
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# Licenses of Bundled Dependencies
|
|
2
|
+
|
|
3
|
+
The published artifact additionally contains code with the following licenses:
|
|
4
|
+
MIT
|
|
5
|
+
|
|
6
|
+
# Bundled Dependencies
|
|
7
|
+
|
|
8
|
+
## @oxc-project/types
|
|
9
|
+
|
|
10
|
+
License: MIT
|
|
11
|
+
By: Boshen and oxc contributors
|
|
12
|
+
Repository: https://github.com/oxc-project/oxc
|
|
13
|
+
|
|
14
|
+
> MIT License
|
|
15
|
+
>
|
|
16
|
+
> Copyright (c) 2024-present VoidZero Inc. & Contributors
|
|
17
|
+
> Copyright (c) 2023 Boshen
|
|
18
|
+
>
|
|
19
|
+
> Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
20
|
+
> of this software and associated documentation files (the "Software"), to deal
|
|
21
|
+
> in the Software without restriction, including without limitation the rights
|
|
22
|
+
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
23
|
+
> copies of the Software, and to permit persons to whom the Software is
|
|
24
|
+
> furnished to do so, subject to the following conditions:
|
|
25
|
+
>
|
|
26
|
+
> The above copyright notice and this permission notice shall be included in all
|
|
27
|
+
> copies or substantial portions of the Software.
|
|
28
|
+
>
|
|
29
|
+
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
30
|
+
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
31
|
+
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
32
|
+
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
33
|
+
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
34
|
+
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
35
|
+
> SOFTWARE.
|
|
36
|
+
|
|
37
|
+
---------------------------------------
|
|
38
|
+
|
|
39
|
+
## @rolldown/pluginutils
|
|
40
|
+
|
|
41
|
+
License: MIT
|
|
42
|
+
Repository: https://github.com/rolldown/plugins
|
|
43
|
+
|
|
44
|
+
> MIT License
|
|
45
|
+
>
|
|
46
|
+
> Copyright (c) 2026-present, rolldown/plugins repository contributors
|
|
47
|
+
>
|
|
48
|
+
> Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
49
|
+
> of this software and associated documentation files (the "Software"), to deal
|
|
50
|
+
> in the Software without restriction, including without limitation the rights
|
|
51
|
+
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
52
|
+
> copies of the Software, and to permit persons to whom the Software is
|
|
53
|
+
> furnished to do so, subject to the following conditions:
|
|
54
|
+
>
|
|
55
|
+
> The above copyright notice and this permission notice shall be included in all
|
|
56
|
+
> copies or substantial portions of the Software.
|
|
57
|
+
>
|
|
58
|
+
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
59
|
+
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
60
|
+
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
61
|
+
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
62
|
+
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
63
|
+
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
64
|
+
> SOFTWARE.
|
|
65
|
+
|
|
66
|
+
---------------------------------------
|
|
67
|
+
|
|
68
|
+
## rolldown
|
|
69
|
+
|
|
70
|
+
License: MIT
|
|
71
|
+
Repository: https://github.com/rolldown/rolldown
|
|
72
|
+
|
|
73
|
+
> MIT License
|
|
74
|
+
>
|
|
75
|
+
> Copyright (c) 2024-present VoidZero Inc. & Contributors
|
|
76
|
+
>
|
|
77
|
+
> Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
78
|
+
> of this software and associated documentation files (the "Software"), to deal
|
|
79
|
+
> in the Software without restriction, including without limitation the rights
|
|
80
|
+
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
81
|
+
> copies of the Software, and to permit persons to whom the Software is
|
|
82
|
+
> furnished to do so, subject to the following conditions:
|
|
83
|
+
>
|
|
84
|
+
> The above copyright notice and this permission notice shall be included in all
|
|
85
|
+
> copies or substantial portions of the Software.
|
|
86
|
+
>
|
|
87
|
+
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
88
|
+
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
89
|
+
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
90
|
+
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
91
|
+
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
92
|
+
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
93
|
+
> SOFTWARE.
|
|
94
|
+
>
|
|
95
|
+
> end of terms and conditions
|
|
96
|
+
>
|
|
97
|
+
> The licenses of externally maintained libraries from which parts of the Software is derived are listed [here](https://github.com/rolldown/rolldown/blob/main/THIRD-PARTY-LICENSE).
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
type ProviderType = 'github' | 'gitlab' | 'forgejo';
|
|
2
|
+
interface ProviderRepository {
|
|
3
|
+
owner: string;
|
|
4
|
+
name: string;
|
|
5
|
+
branch?: string;
|
|
6
|
+
}
|
|
7
|
+
interface ProviderConfig {
|
|
8
|
+
type: ProviderType;
|
|
9
|
+
repository: ProviderRepository;
|
|
10
|
+
base?: string;
|
|
11
|
+
url?: string;
|
|
12
|
+
clientId?: string;
|
|
13
|
+
scopes?: readonly string[];
|
|
14
|
+
redirectUri?: string;
|
|
15
|
+
commitMessage?: string;
|
|
16
|
+
}
|
|
17
|
+
interface ContentConfig {
|
|
18
|
+
indent?: number;
|
|
19
|
+
semi?: boolean;
|
|
20
|
+
}
|
|
21
|
+
export interface MediaConfig {
|
|
22
|
+
dir?: string;
|
|
23
|
+
url?: string;
|
|
24
|
+
maxSize?: number;
|
|
25
|
+
}
|
|
26
|
+
export interface OutputConfig {
|
|
27
|
+
dir?: string;
|
|
28
|
+
}
|
|
29
|
+
export interface ForgePressConfig {
|
|
30
|
+
path?: string;
|
|
31
|
+
provider?: ProviderConfig;
|
|
32
|
+
content?: ContentConfig;
|
|
33
|
+
media?: MediaConfig;
|
|
34
|
+
output?: OutputConfig;
|
|
35
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { errorMessage } from "./error.mjs";
|
|
2
|
+
import { DEFAULT_CONTENT_PATH, createPaths, resolveMedia, resolveOutput } from "./output.mjs";
|
|
3
|
+
import { existsSync } from "node:fs";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
5
|
+
import process from "node:process";
|
|
6
|
+
import { pathToFileURL } from "node:url";
|
|
7
|
+
function resolveConfig(config) {
|
|
8
|
+
return {
|
|
9
|
+
paths: createPaths(config?.path),
|
|
10
|
+
media: resolveMedia(config?.media),
|
|
11
|
+
output: resolveOutput(config?.output),
|
|
12
|
+
content: config?.content,
|
|
13
|
+
provider: config?.provider
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
const CONFIG_FILES = ["forgepress.config.mjs", "forgepress.config.js"];
|
|
17
|
+
function marks(dir, contentPath) {
|
|
18
|
+
return CONFIG_FILES.some((file) => existsSync(join(dir, file))) || existsSync(join(dir, contentPath));
|
|
19
|
+
}
|
|
20
|
+
function findRoot(start = process.cwd(), contentPath = DEFAULT_CONTENT_PATH) {
|
|
21
|
+
for (let dir = start;; dir = dirname(dir)) {
|
|
22
|
+
if (marks(dir, contentPath)) return dir;
|
|
23
|
+
if (dir === dirname(dir)) return start;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
async function loadConfig(root) {
|
|
27
|
+
for (const file of CONFIG_FILES) {
|
|
28
|
+
const path = join(root, file);
|
|
29
|
+
if (!existsSync(path)) continue;
|
|
30
|
+
try {
|
|
31
|
+
return (await import(pathToFileURL(path).href)).default;
|
|
32
|
+
} catch (cause) {
|
|
33
|
+
throw new Error(`[forgepress] could not load ${file}: ${errorMessage(cause)}`, { cause });
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export { findRoot, loadConfig, resolveConfig };
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
interface FieldBase {
|
|
2
|
+
label?: string;
|
|
3
|
+
description?: string;
|
|
4
|
+
optional?: boolean;
|
|
5
|
+
translate?: boolean;
|
|
6
|
+
}
|
|
7
|
+
type FieldOptionType = 'text' | 'number' | 'boolean' | 'collection' | 'collections';
|
|
8
|
+
interface FieldOption {
|
|
9
|
+
label: string;
|
|
10
|
+
type: FieldOptionType;
|
|
11
|
+
description?: string;
|
|
12
|
+
required?: true;
|
|
13
|
+
}
|
|
14
|
+
interface FieldTypeDefinition {
|
|
15
|
+
type: string;
|
|
16
|
+
label: string;
|
|
17
|
+
options: Record<string, FieldOption>;
|
|
18
|
+
}
|
|
19
|
+
type OptionContent<TOption extends FieldOption> = TOption['type'] extends 'number' ? number : TOption['type'] extends 'boolean' ? boolean : TOption['type'] extends 'collections' ? readonly string[] : string;
|
|
20
|
+
type RequiredOptions<TOptions> = { [TKey in keyof TOptions]: TOptions[TKey] extends {
|
|
21
|
+
required: true;
|
|
22
|
+
} ? TKey : never; }[keyof TOptions];
|
|
23
|
+
type FieldOf<TDefinition extends FieldTypeDefinition> = TDefinition extends FieldTypeDefinition ? FieldBase & {
|
|
24
|
+
type: TDefinition['type'];
|
|
25
|
+
} & { [TKey in RequiredOptions<TDefinition['options']>]: OptionContent<TDefinition['options'][TKey]>; } & { [TKey in Exclude<keyof TDefinition['options'], RequiredOptions<TDefinition['options']>>]?: OptionContent<TDefinition['options'][TKey]>; } : never;
|
|
26
|
+
declare const dynamic: {
|
|
27
|
+
readonly type: "dynamic";
|
|
28
|
+
readonly label: "Dynamic";
|
|
29
|
+
readonly options: {
|
|
30
|
+
readonly collections: {
|
|
31
|
+
readonly label: "Collections";
|
|
32
|
+
readonly type: "collections";
|
|
33
|
+
readonly required: true;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
type DynamicField = FieldOf<typeof dynamic>;
|
|
38
|
+
interface DynamicBlock<TCollectionName extends string = string> {
|
|
39
|
+
collection: TCollectionName;
|
|
40
|
+
id: string;
|
|
41
|
+
}
|
|
42
|
+
type DynamicFieldContent<TField extends DynamicField> = DynamicBlock<TField['collections'][number]>[];
|
|
43
|
+
interface MediaContent {
|
|
44
|
+
url: string;
|
|
45
|
+
alt?: string;
|
|
46
|
+
width?: number;
|
|
47
|
+
height?: number;
|
|
48
|
+
}
|
|
49
|
+
declare const image: {
|
|
50
|
+
readonly type: "image";
|
|
51
|
+
readonly label: "Image";
|
|
52
|
+
readonly options: {
|
|
53
|
+
readonly multiple: {
|
|
54
|
+
readonly label: "Multiple";
|
|
55
|
+
readonly type: "boolean";
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
type ImageField = FieldOf<typeof image>;
|
|
60
|
+
type ImageFieldContent<TField extends ImageField> = TField['multiple'] extends true ? MediaContent[] : MediaContent;
|
|
61
|
+
declare const number: {
|
|
62
|
+
readonly type: "number";
|
|
63
|
+
readonly label: "Number";
|
|
64
|
+
readonly options: {
|
|
65
|
+
readonly min: {
|
|
66
|
+
readonly label: "Minimum";
|
|
67
|
+
readonly type: "number";
|
|
68
|
+
};
|
|
69
|
+
readonly max: {
|
|
70
|
+
readonly label: "Maximum";
|
|
71
|
+
readonly type: "number";
|
|
72
|
+
};
|
|
73
|
+
readonly step: {
|
|
74
|
+
readonly label: "Step";
|
|
75
|
+
readonly type: "number";
|
|
76
|
+
};
|
|
77
|
+
readonly index: {
|
|
78
|
+
readonly label: "Indexed";
|
|
79
|
+
readonly type: "boolean";
|
|
80
|
+
readonly description: "Listed in the collection manifest, so queries can filter and sort on it without loading every entry.";
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
type NumberField = FieldOf<typeof number>;
|
|
85
|
+
type NumberFieldContent = number;
|
|
86
|
+
declare const relation: {
|
|
87
|
+
readonly type: "relation";
|
|
88
|
+
readonly label: "Relation";
|
|
89
|
+
readonly options: {
|
|
90
|
+
readonly collection: {
|
|
91
|
+
readonly label: "Collection";
|
|
92
|
+
readonly type: "collection";
|
|
93
|
+
readonly required: true;
|
|
94
|
+
};
|
|
95
|
+
readonly multiple: {
|
|
96
|
+
readonly label: "Multiple";
|
|
97
|
+
readonly type: "boolean";
|
|
98
|
+
};
|
|
99
|
+
readonly index: {
|
|
100
|
+
readonly label: "Indexed";
|
|
101
|
+
readonly type: "boolean";
|
|
102
|
+
readonly description: "Listed in the collection manifest, so queries can filter and sort on it without loading every entry.";
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
type RelationField = FieldOf<typeof relation>;
|
|
107
|
+
type RelationFieldContent<TField extends RelationField> = TField['multiple'] extends true ? string[] : string;
|
|
108
|
+
declare const richtext: {
|
|
109
|
+
readonly type: "richtext";
|
|
110
|
+
readonly label: "Rich Text";
|
|
111
|
+
readonly options: {};
|
|
112
|
+
};
|
|
113
|
+
type RichTextField = FieldOf<typeof richtext>;
|
|
114
|
+
type RichTextFieldContent = string;
|
|
115
|
+
declare const text: {
|
|
116
|
+
readonly type: "text";
|
|
117
|
+
readonly label: "Text";
|
|
118
|
+
readonly options: {
|
|
119
|
+
readonly validation: {
|
|
120
|
+
readonly label: "Validation Pattern";
|
|
121
|
+
readonly type: "text";
|
|
122
|
+
};
|
|
123
|
+
readonly index: {
|
|
124
|
+
readonly label: "Indexed";
|
|
125
|
+
readonly type: "boolean";
|
|
126
|
+
readonly description: "Listed in the collection manifest, so queries can filter and sort on it without loading every entry.";
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
type TextField = FieldOf<typeof text>;
|
|
131
|
+
type TextFieldContent = string;
|
|
132
|
+
declare const video: {
|
|
133
|
+
readonly type: "video";
|
|
134
|
+
readonly label: "Video";
|
|
135
|
+
readonly options: {
|
|
136
|
+
readonly multiple: {
|
|
137
|
+
readonly label: "Multiple";
|
|
138
|
+
readonly type: "boolean";
|
|
139
|
+
};
|
|
140
|
+
};
|
|
141
|
+
};
|
|
142
|
+
type VideoField = FieldOf<typeof video>;
|
|
143
|
+
type VideoFieldContent<TField extends VideoField> = TField['multiple'] extends true ? MediaContent[] : MediaContent;
|
|
144
|
+
type Field = TextField | RichTextField | NumberField | ImageField | VideoField | RelationField | DynamicField;
|
|
145
|
+
type FieldContent<TField extends Field> = TField extends DynamicField ? DynamicFieldContent<TField> : TField extends RelationField ? RelationFieldContent<TField> : TField extends ImageField ? ImageFieldContent<TField> : TField extends VideoField ? VideoFieldContent<TField> : TField extends TextField ? TextFieldContent : TField extends NumberField ? NumberFieldContent : TField extends RichTextField ? RichTextFieldContent : never;
|
|
146
|
+
interface Collection {
|
|
147
|
+
label?: string;
|
|
148
|
+
description?: string;
|
|
149
|
+
fields: Record<string, Field>;
|
|
150
|
+
}
|
|
151
|
+
export interface ForgePressSchema {
|
|
152
|
+
collections: Record<string, Collection>;
|
|
153
|
+
locales?: readonly string[];
|
|
154
|
+
}
|
|
155
|
+
export type SchemaLocale<TSchema extends ForgePressSchema> = TSchema['locales'] extends readonly string[] ? TSchema['locales'][number] : never;
|
|
156
|
+
export interface ForgePressSchemaRegistry {}
|
|
157
|
+
export type RegisteredSchema = ForgePressSchemaRegistry extends {
|
|
158
|
+
schema: infer TSchema extends ForgePressSchema;
|
|
159
|
+
} ? TSchema : ForgePressSchema;
|
|
160
|
+
export type EntryStatus = 'published' | 'unpublished';
|
|
161
|
+
export interface EntryMeta {
|
|
162
|
+
id: string;
|
|
163
|
+
status: EntryStatus;
|
|
164
|
+
createdAt: string;
|
|
165
|
+
updatedAt: string;
|
|
166
|
+
}
|
|
167
|
+
export interface EntryRef<TCollectionName extends string = string> {
|
|
168
|
+
collection: TCollectionName;
|
|
169
|
+
id: string;
|
|
170
|
+
}
|
|
171
|
+
export interface OutputMeta {
|
|
172
|
+
id: string;
|
|
173
|
+
createdAt: string;
|
|
174
|
+
updatedAt: string;
|
|
175
|
+
}
|
|
176
|
+
export type Entry = EntryMeta & {
|
|
177
|
+
[field: string]: unknown;
|
|
178
|
+
};
|
|
179
|
+
type Translated<TSchema extends ForgePressSchema, TContent> = [SchemaLocale<TSchema>] extends [never] ? TContent : Record<SchemaLocale<TSchema>, TContent>;
|
|
180
|
+
type PartiallyTranslated<TSchema extends ForgePressSchema, TContent> = [SchemaLocale<TSchema>] extends [never] ? TContent : Partial<Record<SchemaLocale<TSchema>, TContent>>;
|
|
181
|
+
type FieldValue<TSchema extends ForgePressSchema, TField extends Field, TOptional extends boolean> = TField extends {
|
|
182
|
+
translate: true;
|
|
183
|
+
} ? TOptional extends true ? PartiallyTranslated<TSchema, FieldContent<TField>> : Translated<TSchema, FieldContent<TField>> : FieldContent<TField>;
|
|
184
|
+
type OptionalKeys<TCollection extends Collection> = { [TKey in keyof TCollection['fields']]-?: TCollection['fields'][TKey] extends {
|
|
185
|
+
optional: true;
|
|
186
|
+
} ? TKey : never; }[keyof TCollection['fields']];
|
|
187
|
+
type RequiredKeys<TCollection extends Collection> = Exclude<keyof TCollection['fields'], OptionalKeys<TCollection>>;
|
|
188
|
+
type CollectionContent<TSchema extends ForgePressSchema, TCollection extends Collection> = EntryMeta & { [TKey in RequiredKeys<TCollection>]: FieldValue<TSchema, TCollection['fields'][TKey], false>; } & { [TKey in OptionalKeys<TCollection>]?: FieldValue<TSchema, TCollection['fields'][TKey], true>; };
|
|
189
|
+
type EntryOf<TSchema extends ForgePressSchema, TCollectionName extends keyof TSchema['collections']> = CollectionContent<TSchema, TSchema['collections'][TCollectionName]>;
|
|
190
|
+
export type ForgePressEntry<TCollectionName extends keyof RegisteredSchema['collections']> = EntryOf<RegisteredSchema, TCollectionName>;
|
|
191
|
+
type OutputValue<TField extends Field> = TField extends RelationField ? TField['multiple'] extends true ? EntryRef<TField['collection']>[] : EntryRef<TField['collection']> : FieldContent<TField>;
|
|
192
|
+
type CollectionOutput<TCollection extends Collection> = OutputMeta & { [TKey in RequiredKeys<TCollection>]: OutputValue<TCollection['fields'][TKey]>; } & { [TKey in OptionalKeys<TCollection>]?: OutputValue<TCollection['fields'][TKey]>; };
|
|
193
|
+
export type OutputOf<TSchema extends ForgePressSchema, TCollectionName extends keyof TSchema['collections']> = CollectionOutput<TSchema['collections'][TCollectionName]>;
|
|
194
|
+
export type ForgePressOutput<TCollectionName extends keyof RegisteredSchema['collections']> = OutputOf<RegisteredSchema, TCollectionName>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import "./types.mjs";
|
|
2
|
+
function fetchReader(url) {
|
|
3
|
+
const base = url.replace(/\/+$/, "");
|
|
4
|
+
return async (path) => {
|
|
5
|
+
const location = `${base}/${path}`;
|
|
6
|
+
const response = await fetch(location, path === "index.json" ? { cache: "no-cache" } : {});
|
|
7
|
+
if (response.status === 404 || response.ok && response.headers.get("content-type")?.includes("text/html")) return void 0;
|
|
8
|
+
if (!response.ok) throw new Error(`[forgepress] could not load ${location}: ${response.status} ${response.statusText}`.trim());
|
|
9
|
+
return response.json();
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
const reader = fetchReader("/content");
|
|
13
|
+
export { fetchReader, reader };
|