opacacms 0.3.12 → 0.3.13
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.
|
@@ -2,7 +2,7 @@ import { type VariantProps } from "class-variance-authority";
|
|
|
2
2
|
import type * as React from "react";
|
|
3
3
|
import "../../styles/button.scss";
|
|
4
4
|
declare const buttonVariants: (props?: ({
|
|
5
|
-
variant?: "
|
|
5
|
+
variant?: "link" | "default" | "destructive" | "outline" | "secondary" | "ghost" | null | undefined;
|
|
6
6
|
size?: "default" | "icon" | "sm" | "lg" | "icon-sm" | "icon-xs" | "icon-lg" | "xs" | null | undefined;
|
|
7
7
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
8
8
|
declare function Button({ className, variant, size, asChild, ...props }: React.ComponentProps<"button"> & VariantProps<typeof buttonVariants> & {
|
|
@@ -96,7 +96,8 @@ function createClient(configOrOptions) {
|
|
|
96
96
|
return {
|
|
97
97
|
find: async (query) => {
|
|
98
98
|
await initConfig();
|
|
99
|
-
|
|
99
|
+
const isRestDisabled = engineConfig?.rest === false || engineConfig?.rest?.enabled === false;
|
|
100
|
+
if (engineConfig?.graphql?.enabled && isRestDisabled) {
|
|
100
101
|
const selection = getSelectionSetForCollection(String(collectionSlug));
|
|
101
102
|
const limit = query?.limit ? `limit: ${query.limit}` : "";
|
|
102
103
|
const page = query?.page ? `page: ${query.page}` : "";
|
|
@@ -118,7 +119,8 @@ function createClient(configOrOptions) {
|
|
|
118
119
|
},
|
|
119
120
|
findOne: async (id) => {
|
|
120
121
|
await initConfig();
|
|
121
|
-
|
|
122
|
+
const isRestDisabled = engineConfig?.rest === false || engineConfig?.rest?.enabled === false;
|
|
123
|
+
if (engineConfig?.graphql?.enabled && isRestDisabled) {
|
|
122
124
|
const selection = getSelectionSetForCollection(String(collectionSlug));
|
|
123
125
|
const capitalizedSlug = capitalize(sanitizeGraphQLName(String(collectionSlug)));
|
|
124
126
|
const res = await client.graphql(`query getDoc($id: String!) { get${capitalizedSlug}(id: $id) { ${selection} } }`, { id });
|
|
@@ -131,7 +133,8 @@ function createClient(configOrOptions) {
|
|
|
131
133
|
},
|
|
132
134
|
create: async (data) => {
|
|
133
135
|
await initConfig();
|
|
134
|
-
|
|
136
|
+
const isRestDisabled = engineConfig?.rest === false || engineConfig?.rest?.enabled === false;
|
|
137
|
+
if (engineConfig?.graphql?.enabled && isRestDisabled) {
|
|
135
138
|
const selection = getSelectionSetForCollection(String(collectionSlug));
|
|
136
139
|
const capitalizedSlug = capitalize(sanitizeGraphQLName(String(collectionSlug)));
|
|
137
140
|
const res = await client.graphql(`mutation createDoc($data: JSON!) { create${capitalizedSlug}(data: $data) { ${selection} } }`, { data });
|
|
@@ -144,7 +147,8 @@ function createClient(configOrOptions) {
|
|
|
144
147
|
},
|
|
145
148
|
update: async (id, data) => {
|
|
146
149
|
await initConfig();
|
|
147
|
-
|
|
150
|
+
const isRestDisabled = engineConfig?.rest === false || engineConfig?.rest?.enabled === false;
|
|
151
|
+
if (engineConfig?.graphql?.enabled && isRestDisabled) {
|
|
148
152
|
const selection = getSelectionSetForCollection(String(collectionSlug));
|
|
149
153
|
const capitalizedSlug = capitalize(sanitizeGraphQLName(String(collectionSlug)));
|
|
150
154
|
const res = await client.graphql(`mutation updateDoc($id: String!, $data: JSON!) { update${capitalizedSlug}(id: $id, data: $data) { ${selection} } }`, { id, data });
|
|
@@ -157,7 +161,8 @@ function createClient(configOrOptions) {
|
|
|
157
161
|
},
|
|
158
162
|
delete: async (id) => {
|
|
159
163
|
await initConfig();
|
|
160
|
-
|
|
164
|
+
const isRestDisabled = engineConfig?.rest === false || engineConfig?.rest?.enabled === false;
|
|
165
|
+
if (engineConfig?.graphql?.enabled && isRestDisabled) {
|
|
161
166
|
const capitalizedSlug = capitalize(sanitizeGraphQLName(String(collectionSlug)));
|
|
162
167
|
const res = await client.graphql(`mutation deleteDoc($id: String!) { delete${capitalizedSlug}(id: $id) }`, { id });
|
|
163
168
|
return res.data[`delete${capitalizedSlug}`];
|
|
@@ -174,7 +179,8 @@ function createClient(configOrOptions) {
|
|
|
174
179
|
return {
|
|
175
180
|
get: async () => {
|
|
176
181
|
await initConfig();
|
|
177
|
-
|
|
182
|
+
const isRestDisabled = engineConfig?.rest === false || engineConfig?.rest?.enabled === false;
|
|
183
|
+
if (engineConfig?.graphql?.enabled && isRestDisabled) {
|
|
178
184
|
const selection = getSelectionSetForGlobal(String(globalSlug));
|
|
179
185
|
const capitalizedSlug = capitalize(sanitizeGraphQLName(String(globalSlug)));
|
|
180
186
|
const res = await client.graphql(`query getGlobal { get${capitalizedSlug} { ${selection} } }`);
|
|
@@ -184,7 +190,8 @@ function createClient(configOrOptions) {
|
|
|
184
190
|
},
|
|
185
191
|
update: async (data) => {
|
|
186
192
|
await initConfig();
|
|
187
|
-
|
|
193
|
+
const isRestDisabled = engineConfig?.rest === false || engineConfig?.rest?.enabled === false;
|
|
194
|
+
if (engineConfig?.graphql?.enabled && isRestDisabled) {
|
|
188
195
|
const selection = getSelectionSetForGlobal(String(globalSlug));
|
|
189
196
|
const capitalizedSlug = capitalize(sanitizeGraphQLName(String(globalSlug)));
|
|
190
197
|
const res = await client.graphql(`mutation updateGlobal($data: JSON!) { update${capitalizedSlug}(data: $data) { ${selection} } }`, { data });
|
package/dist/client.d.ts
CHANGED
|
@@ -1,8 +1,80 @@
|
|
|
1
|
-
import type { OpacaConfig } from "./types";
|
|
2
1
|
export interface OpacaClientOptions {
|
|
3
2
|
baseURL: string;
|
|
4
3
|
token?: string;
|
|
5
4
|
}
|
|
5
|
+
export interface OpacaAsset {
|
|
6
|
+
id: string;
|
|
7
|
+
url: string;
|
|
8
|
+
filename: string;
|
|
9
|
+
mime_type: string;
|
|
10
|
+
filesize: number;
|
|
11
|
+
alt_text?: string;
|
|
12
|
+
caption?: string;
|
|
13
|
+
[key: string]: any;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Utility types for automatic type inference from OpacaConfig
|
|
17
|
+
*/
|
|
18
|
+
type MapFieldToType<F> = F extends {
|
|
19
|
+
type: "text" | "textarea" | "richtext" | "slug" | "date" | "select" | "radio";
|
|
20
|
+
} ? string : F extends {
|
|
21
|
+
type: "number";
|
|
22
|
+
} ? number : F extends {
|
|
23
|
+
type: "boolean";
|
|
24
|
+
} ? boolean : F extends {
|
|
25
|
+
type: "json";
|
|
26
|
+
} ? any : F extends {
|
|
27
|
+
type: "file";
|
|
28
|
+
} ? OpacaAsset : F extends {
|
|
29
|
+
type: "relationship";
|
|
30
|
+
} ? F extends {
|
|
31
|
+
hasMany: true;
|
|
32
|
+
} ? any[] : any : F extends {
|
|
33
|
+
type: "array";
|
|
34
|
+
fields: infer Fs;
|
|
35
|
+
} ? Fs extends readonly any[] ? MapFieldsToType<Fs>[] : any[] : F extends {
|
|
36
|
+
type: "group";
|
|
37
|
+
fields: infer Fs;
|
|
38
|
+
} ? Fs extends readonly any[] ? MapFieldsToType<Fs> : any : F extends {
|
|
39
|
+
type: "blocks";
|
|
40
|
+
blocks: infer Bs;
|
|
41
|
+
} ? Bs extends readonly any[] ? MapBlocksToType<Bs>[] : any[] : any;
|
|
42
|
+
type MapBlocksToType<Bs extends readonly any[]> = Bs[number] extends infer B ? B extends {
|
|
43
|
+
slug: infer S;
|
|
44
|
+
fields: infer Fs;
|
|
45
|
+
} ? S extends string ? Fs extends readonly any[] ? MapFieldsToType<Fs> & {
|
|
46
|
+
blockType: S;
|
|
47
|
+
} : never : never : never : never;
|
|
48
|
+
type MapFieldsToType<Fs extends readonly any[]> = {
|
|
49
|
+
[K in Extract<Fs[number], {
|
|
50
|
+
required: true;
|
|
51
|
+
}> as K["name"]]: MapFieldToType<K>;
|
|
52
|
+
} & {
|
|
53
|
+
[K in Fs[number] as K["required"] extends true ? never : K["name"]]?: MapFieldToType<K>;
|
|
54
|
+
};
|
|
55
|
+
type InferCollectionType<C> = C extends {
|
|
56
|
+
fields: infer Fs;
|
|
57
|
+
timestamps?: infer T;
|
|
58
|
+
} ? (Fs extends readonly any[] ? MapFieldsToType<Fs> : any) & (T extends true | {
|
|
59
|
+
createdAt?: any;
|
|
60
|
+
updatedAt?: any;
|
|
61
|
+
} ? {
|
|
62
|
+
createdAt: string;
|
|
63
|
+
updatedAt: string;
|
|
64
|
+
} : {}) : any;
|
|
65
|
+
type InferGlobalType<G> = G extends {
|
|
66
|
+
fields: infer Fs;
|
|
67
|
+
} ? Fs extends readonly any[] ? MapFieldsToType<Fs> : any : any;
|
|
68
|
+
type InferCollections<T> = T extends {
|
|
69
|
+
collections: infer C;
|
|
70
|
+
} ? C extends readonly any[] ? {
|
|
71
|
+
[K in C[number] as K["slug"]]: InferCollectionType<K>;
|
|
72
|
+
} : Record<string, any> : Record<string, any>;
|
|
73
|
+
type InferGlobals<T> = T extends {
|
|
74
|
+
globals: infer G;
|
|
75
|
+
} ? G extends readonly any[] ? {
|
|
76
|
+
[K in G[number] as K["slug"]]: InferGlobalType<K>;
|
|
77
|
+
} : Record<string, any> : Record<string, any>;
|
|
6
78
|
/**
|
|
7
79
|
* A proxy-based client that provides a typed experience for interacting with the OpacaCMS API.
|
|
8
80
|
*/
|
|
@@ -24,28 +96,29 @@ export declare function createClient<T = any>(configOrOptions: T | OpacaClientOp
|
|
|
24
96
|
getSetupStatus: () => Promise<{
|
|
25
97
|
initialized: boolean;
|
|
26
98
|
}>;
|
|
27
|
-
collections: { [K in
|
|
99
|
+
collections: { [K in (keyof InferCollections<T> extends never ? string : keyof InferCollections<T>) & string]: {
|
|
28
100
|
find: (query?: any) => Promise<{
|
|
29
|
-
docs:
|
|
101
|
+
docs: K extends keyof InferCollections<T> ? InferCollections<T>[K][] : any[];
|
|
30
102
|
totalDocs: number;
|
|
31
103
|
page: number;
|
|
32
104
|
totalPages: number;
|
|
33
105
|
}>;
|
|
34
|
-
findOne: (id: string) => Promise<
|
|
106
|
+
findOne: (id: string) => Promise<K extends keyof InferCollections<T> ? InferCollections<T>[K] : any>;
|
|
35
107
|
list: () => Promise<{
|
|
36
|
-
docs:
|
|
108
|
+
docs: K extends keyof InferCollections<T> ? InferCollections<T>[K][] : any[];
|
|
37
109
|
totalDocs: number;
|
|
38
110
|
page: number;
|
|
39
111
|
totalPages: number;
|
|
40
112
|
}>;
|
|
41
|
-
create: (data: Partial<
|
|
42
|
-
update: (id: string, data: Partial<
|
|
113
|
+
create: (data: Partial<K extends keyof InferCollections<T> ? InferCollections<T>[K] : any>) => Promise<K extends keyof InferCollections<T> ? InferCollections<T>[K] : any>;
|
|
114
|
+
update: (id: string, data: Partial<K extends keyof InferCollections<T> ? InferCollections<T>[K] : any>) => Promise<K extends keyof InferCollections<T> ? InferCollections<T>[K] : any>;
|
|
43
115
|
delete: (id: string) => Promise<{
|
|
44
116
|
success: boolean;
|
|
45
117
|
}>;
|
|
46
118
|
}; };
|
|
47
|
-
globals: { [K in
|
|
48
|
-
get: () => Promise<
|
|
49
|
-
update: (data: Partial<
|
|
119
|
+
globals: { [K in (keyof InferGlobals<T> extends never ? string : keyof InferGlobals<T>) & string]: {
|
|
120
|
+
get: () => Promise<K extends keyof InferGlobals<T> ? InferGlobals<T>[K] : any>;
|
|
121
|
+
update: (data: Partial<K extends keyof InferGlobals<T> ? InferGlobals<T>[K] : any>) => Promise<any>;
|
|
50
122
|
}; };
|
|
51
123
|
};
|
|
124
|
+
export {};
|
package/dist/client.js
CHANGED
package/dist/index.js
CHANGED
package/dist/validation.d.ts
CHANGED
|
@@ -3,22 +3,22 @@ export declare const FieldTypeSchema: z.ZodEnum<{
|
|
|
3
3
|
number: "number";
|
|
4
4
|
boolean: "boolean";
|
|
5
5
|
text: "text";
|
|
6
|
-
json: "json";
|
|
7
|
-
join: "join";
|
|
8
|
-
slug: "slug";
|
|
9
6
|
textarea: "textarea";
|
|
10
7
|
richtext: "richtext";
|
|
11
|
-
|
|
8
|
+
slug: "slug";
|
|
9
|
+
date: "date";
|
|
12
10
|
select: "select";
|
|
13
11
|
radio: "radio";
|
|
14
|
-
|
|
12
|
+
json: "json";
|
|
15
13
|
file: "file";
|
|
16
|
-
|
|
14
|
+
relationship: "relationship";
|
|
15
|
+
array: "array";
|
|
17
16
|
group: "group";
|
|
17
|
+
blocks: "blocks";
|
|
18
|
+
join: "join";
|
|
18
19
|
row: "row";
|
|
19
20
|
collapsible: "collapsible";
|
|
20
21
|
tabs: "tabs";
|
|
21
|
-
array: "array";
|
|
22
22
|
virtual: "virtual";
|
|
23
23
|
ui: "ui";
|
|
24
24
|
}>;
|