opacacms 0.1.11 → 0.1.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.
- package/dist/admin/index.js +9464 -21
- package/dist/admin/webcomponent.d.ts +1 -1
- package/dist/admin/webcomponent.js +9620 -6
- package/dist/admin.css +1 -0
- package/dist/{chunk-6dhs73zq.js → chunk-0am1m47g.js} +1 -1
- package/dist/{chunk-0nf7fe26.js → chunk-0d9aqz6z.js} +1 -1
- package/dist/{chunk-cvdd4eqh.js → chunk-2kyhqvhc.js} +5 -1
- package/dist/{chunk-gjjcc4hm.js → chunk-2z8wxx9g.js} +21 -6
- package/dist/{chunk-xg35h5a3.js → chunk-7fyepksb.js} +1 -1
- package/dist/{chunk-njytmdb4.js → chunk-pxh5encs.js} +34 -24
- package/dist/{chunk-n8aekdnr.js → chunk-qkn1ykrj.js} +33 -23
- package/dist/{chunk-kwp83w8b.js → chunk-wmvjvn7b.js} +4 -4
- package/dist/{chunk-qrt22f6e.js → chunk-wq314kkx.js} +35 -25
- package/dist/{chunk-eqtsfyjf.js → chunk-x2ejaftz.js} +52 -28
- package/dist/{chunk-6ew02s0c.js → chunk-xtwc125q.js} +18 -18
- package/dist/cli/index.js +5 -5
- package/dist/db/better-sqlite.d.ts +1 -0
- package/dist/db/better-sqlite.js +3 -3
- package/dist/db/bun-sqlite.d.ts +1 -0
- package/dist/db/bun-sqlite.js +3 -3
- package/dist/db/d1.js +3 -3
- package/dist/db/index.d.ts +3 -0
- package/dist/db/index.js +17 -13
- package/dist/db/postgres.js +3 -3
- package/dist/db/sqlite.js +3 -3
- package/dist/runtimes/bun.js +2 -2
- package/dist/runtimes/cloudflare-workers.js +2 -2
- package/dist/runtimes/next.js +2 -2
- package/dist/runtimes/node.js +2 -2
- package/dist/server.js +2 -2
- package/package.json +8 -2
- package/bun.lock +0 -34
- package/dist/admin/index.css +0 -47
- package/dist/api.d.ts +0 -6
- package/dist/api.js +0 -27
- package/dist/chunk-2zm8cy1w.js +0 -9482
- package/global.d.ts +0 -11
- package/src/admin/api-client.ts +0 -63
- package/src/admin/auth-client.ts +0 -40
- package/src/admin/custom-field.ts +0 -179
- package/src/admin/index.ts +0 -15
- package/src/admin/react.tsx +0 -72
- package/src/admin/router.ts +0 -9
- package/src/admin/stores/admin-queries.ts +0 -121
- package/src/admin/stores/auth.ts +0 -61
- package/src/admin/stores/column-visibility.ts +0 -67
- package/src/admin/stores/config.ts +0 -15
- package/src/admin/stores/media.ts +0 -95
- package/src/admin/stores/query.ts +0 -13
- package/src/admin/stores/ui.ts +0 -29
- package/src/admin/ui/admin-client.tsx +0 -283
- package/src/admin/ui/admin-layout.tsx +0 -276
- package/src/admin/ui/components/ColumnVisibilityToggle.tsx +0 -141
- package/src/admin/ui/components/DataDetailSheet.tsx +0 -141
- package/src/admin/ui/components/DataDetailView.tsx +0 -175
- package/src/admin/ui/components/Table.tsx +0 -67
- package/src/admin/ui/components/fields/ArrayField.tsx +0 -166
- package/src/admin/ui/components/fields/BlocksField.tsx +0 -202
- package/src/admin/ui/components/fields/BooleanField.tsx +0 -50
- package/src/admin/ui/components/fields/CollapsibleField.tsx +0 -75
- package/src/admin/ui/components/fields/DateField.tsx +0 -45
- package/src/admin/ui/components/fields/FileField.tsx +0 -322
- package/src/admin/ui/components/fields/GroupField.tsx +0 -50
- package/src/admin/ui/components/fields/JoinField.tsx +0 -23
- package/src/admin/ui/components/fields/NumberField.tsx +0 -46
- package/src/admin/ui/components/fields/RadioField.tsx +0 -62
- package/src/admin/ui/components/fields/RelationshipField.tsx +0 -278
- package/src/admin/ui/components/fields/RowField.tsx +0 -40
- package/src/admin/ui/components/fields/SelectField.tsx +0 -59
- package/src/admin/ui/components/fields/TabsField.tsx +0 -101
- package/src/admin/ui/components/fields/TextAreaField.tsx +0 -54
- package/src/admin/ui/components/fields/TextField.tsx +0 -49
- package/src/admin/ui/components/fields/VirtualField.tsx +0 -53
- package/src/admin/ui/components/fields/index.tsx +0 -371
- package/src/admin/ui/components/fields/richtext-editor/index.tsx +0 -211
- package/src/admin/ui/components/fields/richtext-editor/nodes/ImageComponent.tsx +0 -142
- package/src/admin/ui/components/fields/richtext-editor/nodes/ImageNode.tsx +0 -95
- package/src/admin/ui/components/fields/richtext-editor/plugins/ComponentPickerPlugin.tsx +0 -226
- package/src/admin/ui/components/fields/richtext-editor/plugins/EditableSyncPlugin.tsx +0 -16
- package/src/admin/ui/components/fields/richtext-editor/plugins/NotionToolbarPlugin.tsx +0 -184
- package/src/admin/ui/components/fields/richtext-editor/plugins/SimpleToolbarPlugin.tsx +0 -240
- package/src/admin/ui/components/fields/richtext-editor/plugins/ValueSyncPlugin.tsx +0 -40
- package/src/admin/ui/components/fields/utils.ts +0 -1
- package/src/admin/ui/components/link.tsx +0 -41
- package/src/admin/ui/components/media/AssetManagerModal.tsx +0 -334
- package/src/admin/ui/components/toast.tsx +0 -72
- package/src/admin/ui/components/ui/accordion.tsx +0 -51
- package/src/admin/ui/components/ui/alert-dialog.tsx +0 -98
- package/src/admin/ui/components/ui/blocks.tsx +0 -32
- package/src/admin/ui/components/ui/breadcrumbs.tsx +0 -59
- package/src/admin/ui/components/ui/button.tsx +0 -26
- package/src/admin/ui/components/ui/collapsible.tsx +0 -124
- package/src/admin/ui/components/ui/dialog.tsx +0 -79
- package/src/admin/ui/components/ui/group.tsx +0 -20
- package/src/admin/ui/components/ui/index.ts +0 -17
- package/src/admin/ui/components/ui/input.tsx +0 -12
- package/src/admin/ui/components/ui/join.tsx +0 -53
- package/src/admin/ui/components/ui/label.tsx +0 -11
- package/src/admin/ui/components/ui/radio-group.tsx +0 -75
- package/src/admin/ui/components/ui/relationship-detail-sheet.tsx +0 -122
- package/src/admin/ui/components/ui/relationship.tsx +0 -58
- package/src/admin/ui/components/ui/scroll-area.tsx +0 -19
- package/src/admin/ui/components/ui/select.tsx +0 -187
- package/src/admin/ui/components/ui/separator.tsx +0 -21
- package/src/admin/ui/components/ui/sheet.tsx +0 -106
- package/src/admin/ui/components/ui/tabs.tsx +0 -116
- package/src/admin/ui/components/ui/utils.ts +0 -3
- package/src/admin/ui/hooks/use-debounce.ts +0 -15
- package/src/admin/ui/styles/_locale-switcher.scss +0 -33
- package/src/admin/ui/styles/accordion.scss +0 -60
- package/src/admin/ui/styles/animations.scss +0 -41
- package/src/admin/ui/styles/asset-manager.scss +0 -547
- package/src/admin/ui/styles/badge.scss +0 -13
- package/src/admin/ui/styles/base.scss +0 -22
- package/src/admin/ui/styles/button.scss +0 -161
- package/src/admin/ui/styles/card.scss +0 -13
- package/src/admin/ui/styles/collapsible.scss +0 -75
- package/src/admin/ui/styles/data-detail.scss +0 -92
- package/src/admin/ui/styles/dialog.scss +0 -102
- package/src/admin/ui/styles/empty-state.scss +0 -22
- package/src/admin/ui/styles/group.scss +0 -19
- package/src/admin/ui/styles/index.scss +0 -33
- package/src/admin/ui/styles/input.scss +0 -80
- package/src/admin/ui/styles/label.scss +0 -12
- package/src/admin/ui/styles/layout.scss +0 -56
- package/src/admin/ui/styles/lexical.scss +0 -469
- package/src/admin/ui/styles/loading.scss +0 -102
- package/src/admin/ui/styles/media-registry.scss +0 -597
- package/src/admin/ui/styles/pagination.scss +0 -20
- package/src/admin/ui/styles/radio-group.scss +0 -66
- package/src/admin/ui/styles/row.scss +0 -17
- package/src/admin/ui/styles/scrollbar.scss +0 -36
- package/src/admin/ui/styles/select.scss +0 -121
- package/src/admin/ui/styles/separator.scss +0 -14
- package/src/admin/ui/styles/sheet.scss +0 -152
- package/src/admin/ui/styles/sidebar.scss +0 -148
- package/src/admin/ui/styles/switch.scss +0 -59
- package/src/admin/ui/styles/table.scss +0 -207
- package/src/admin/ui/styles/tabs.scss +0 -62
- package/src/admin/ui/styles/toast.scss +0 -45
- package/src/admin/ui/styles/variables.scss +0 -24
- package/src/admin/ui/views/collection-list-view.tsx +0 -720
- package/src/admin/ui/views/dashboard-view.tsx +0 -263
- package/src/admin/ui/views/document-edit-view.tsx +0 -384
- package/src/admin/ui/views/global-edit-view.tsx +0 -226
- package/src/admin/ui/views/init-view.tsx +0 -182
- package/src/admin/ui/views/login-view.tsx +0 -123
- package/src/admin/ui/views/media-registry-view.tsx +0 -1104
- package/src/admin/ui/views/settings-view.tsx +0 -729
- package/src/admin/webcomponent.tsx +0 -15
- package/src/api.ts +0 -9
- package/src/auth/index.ts +0 -194
- package/src/auth/migrations.ts +0 -87
- package/src/auth/premissions.ts +0 -46
- package/src/cli/commands/generate-types.ts +0 -116
- package/src/cli/commands/init.ts +0 -95
- package/src/cli/commands/migrate-commands.ts +0 -160
- package/src/cli/commands/seed-command.ts +0 -11
- package/src/cli/d1-mock.ts +0 -101
- package/src/cli/index.test.ts +0 -84
- package/src/cli/index.ts +0 -183
- package/src/cli/r2-mock.ts +0 -217
- package/src/cli/seeding.ts +0 -409
- package/src/client.ts +0 -181
- package/src/config-utils.ts +0 -102
- package/src/config.ts +0 -49
- package/src/db/adapter.ts +0 -53
- package/src/db/better-sqlite.ts +0 -632
- package/src/db/bun-sqlite.ts +0 -646
- package/src/db/d1.ts +0 -711
- package/src/db/index.ts +0 -6
- package/src/db/kysely/data-mapper.ts +0 -142
- package/src/db/kysely/field-mapper.ts +0 -148
- package/src/db/kysely/migration-generator.ts +0 -223
- package/src/db/kysely/query-builder.ts +0 -92
- package/src/db/kysely/schema-builder.ts +0 -439
- package/src/db/kysely/sql-utils.ts +0 -13
- package/src/db/postgres.ts +0 -621
- package/src/db/sqlite.ts +0 -660
- package/src/db/system-schema.ts +0 -121
- package/src/index.ts +0 -13
- package/src/runtimes/README.md +0 -59
- package/src/runtimes/bun.ts +0 -49
- package/src/runtimes/cloudflare-workers.ts +0 -38
- package/src/runtimes/next.ts +0 -26
- package/src/runtimes/node.ts +0 -52
- package/src/schema/collection.ts +0 -184
- package/src/schema/fields/base.ts +0 -164
- package/src/schema/fields/index.ts +0 -427
- package/src/schema/global.ts +0 -145
- package/src/schema/index.ts +0 -4
- package/src/schema/infer.ts +0 -72
- package/src/server/admin-router.ts +0 -20
- package/src/server/admin.ts +0 -142
- package/src/server/assets.ts +0 -306
- package/src/server/collection-router.ts +0 -55
- package/src/server/handlers.ts +0 -722
- package/src/server/middlewares/admin.ts +0 -27
- package/src/server/middlewares/auth.ts +0 -89
- package/src/server/middlewares/context.ts +0 -17
- package/src/server/middlewares/cors.ts +0 -24
- package/src/server/middlewares/database-init.ts +0 -74
- package/src/server/middlewares/rate-limit.ts +0 -77
- package/src/server/router.ts +0 -47
- package/src/server/setup-middlewares.ts +0 -58
- package/src/server/system-router.ts +0 -35
- package/src/server.ts +0 -9
- package/src/storage/adapters/cloudflare-r2.ts +0 -136
- package/src/storage/adapters/local.ts +0 -146
- package/src/storage/adapters/s3.ts +0 -186
- package/src/storage/errors.ts +0 -46
- package/src/storage/index.ts +0 -5
- package/src/storage/types.ts +0 -39
- package/src/types.ts +0 -577
- package/src/utils/lexical.ts +0 -37
- package/src/utils/logger.ts +0 -73
- package/src/validation.ts +0 -429
- package/src/validator.ts +0 -179
- package/test/admin-custom-field.test.ts +0 -162
- package/test/admin-react-field.test.tsx +0 -134
- package/test/api-features.test.ts +0 -78
- package/test/api.test.ts +0 -178
- package/test/auth.test.ts +0 -62
- package/test/cli-integration.test.ts +0 -148
- package/test/cli.test.ts +0 -25
- package/test/db/postgres.test.ts +0 -95
- package/test/db/sqlite-filter.test.ts +0 -53
- package/test/db/sqlite.test.ts +0 -82
- package/test/engine-features.test.ts +0 -79
- package/test/globals.test.ts +0 -74
- package/test/integration-tmp/db-app/opacacms.config.ts +0 -15
- package/test/integration-tmp/my-sqlite-app/opacacms.config.ts +0 -25
- package/test/integration-tmp/my-test-app/index.ts +0 -8
- package/test/integration-tmp/my-test-app/opacacms.config.ts +0 -16
- package/test/integration-tmp/my-test-app/package.json +0 -12
- package/test/populate.test.ts +0 -79
- package/test/runtimes.test.ts +0 -43
- package/test/schema-builder.test.ts +0 -107
- package/test/schema-features.test.ts +0 -63
- package/test/seeding.test.ts +0 -68
- package/test/storage/local.test.ts +0 -72
- package/test/storage/s3.test.ts +0 -60
- package/test/structural-data.test.ts +0 -100
- package/test/test-setup.ts +0 -11
- package/test/validation.test.ts +0 -162
- package/tsconfig.json +0 -42
package/src/client.ts
DELETED
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
import type { OpacaConfig } from "./types";
|
|
2
|
-
|
|
3
|
-
export interface OpacaClientOptions {
|
|
4
|
-
baseURL: string;
|
|
5
|
-
token?: string;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* A proxy-based client that provides a typed experience for interacting with the OpacaCMS API.
|
|
10
|
-
*/
|
|
11
|
-
export interface GeneratedTypes {
|
|
12
|
-
collections: Record<string, any>;
|
|
13
|
-
globals: Record<string, any>;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Custom error class for OpacaCMS SDK errors.
|
|
18
|
-
*/
|
|
19
|
-
export class OpacaError extends Error {
|
|
20
|
-
status: number;
|
|
21
|
-
data: any;
|
|
22
|
-
|
|
23
|
-
constructor(message: string, status: number, data: any = {}) {
|
|
24
|
-
super(message);
|
|
25
|
-
this.name = "OpacaError";
|
|
26
|
-
this.status = status;
|
|
27
|
-
this.data = data;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function createClient<T = any>(configOrOptions: T | OpacaClientOptions) {
|
|
32
|
-
const options: OpacaClientOptions = (configOrOptions as any).serverURL
|
|
33
|
-
? { baseURL: (configOrOptions as any).serverURL }
|
|
34
|
-
: (configOrOptions as OpacaClientOptions);
|
|
35
|
-
|
|
36
|
-
const baseURL = options.baseURL.replace(/\/$/, "");
|
|
37
|
-
|
|
38
|
-
const getHeaders = () => {
|
|
39
|
-
const headers: Record<string, string> = {
|
|
40
|
-
"Content-Type": "application/json",
|
|
41
|
-
};
|
|
42
|
-
if (options.token) {
|
|
43
|
-
headers.Authorization = `Bearer ${options.token}`;
|
|
44
|
-
}
|
|
45
|
-
return headers;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const fetcher = async (path: string, init?: RequestInit) => {
|
|
49
|
-
const res = await fetch(`${baseURL}${path}`, {
|
|
50
|
-
...init,
|
|
51
|
-
credentials: "include", // Required for session cookies in cross-origin environments
|
|
52
|
-
headers: {
|
|
53
|
-
...getHeaders(),
|
|
54
|
-
...init?.headers,
|
|
55
|
-
},
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
if (!res.ok) {
|
|
59
|
-
const errorData: any = await res.json().catch(() => ({}));
|
|
60
|
-
throw new OpacaError(errorData.message || `API Error: ${res.status}`, res.status, errorData);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return res.json();
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
const client = {
|
|
67
|
-
getMetadata: () => fetcher("/api/__admin/metadata"),
|
|
68
|
-
getCollections: () => fetcher("/api/__admin/collections"),
|
|
69
|
-
getSetupStatus: () => fetcher("/api/__admin/setup"),
|
|
70
|
-
|
|
71
|
-
// Legacy mapping (collections and globals)
|
|
72
|
-
collections: new Proxy({} as any, {
|
|
73
|
-
get(_, collectionSlug) {
|
|
74
|
-
return {
|
|
75
|
-
find: (query?: any) => {
|
|
76
|
-
const searchParams = new URLSearchParams();
|
|
77
|
-
if (query) {
|
|
78
|
-
Object.entries(query).forEach(([key, value]) => {
|
|
79
|
-
searchParams.append(
|
|
80
|
-
key,
|
|
81
|
-
typeof value === "object" ? JSON.stringify(value) : String(value),
|
|
82
|
-
);
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
const queryString = searchParams.toString();
|
|
86
|
-
return fetcher(`/api/${String(collectionSlug)}${queryString ? `?${queryString}` : ""}`);
|
|
87
|
-
},
|
|
88
|
-
findOne: (id: string) => fetcher(`/api/${String(collectionSlug)}/${id}`),
|
|
89
|
-
list: () => fetcher(`/api/${String(collectionSlug)}`),
|
|
90
|
-
create: (data: any) =>
|
|
91
|
-
fetcher(`/api/${String(collectionSlug)}`, {
|
|
92
|
-
method: "POST",
|
|
93
|
-
body: JSON.stringify(data),
|
|
94
|
-
}),
|
|
95
|
-
update: (id: string, data: any) =>
|
|
96
|
-
fetcher(`/api/${String(collectionSlug)}/${id}`, {
|
|
97
|
-
method: "PATCH",
|
|
98
|
-
body: JSON.stringify(data),
|
|
99
|
-
}),
|
|
100
|
-
delete: (id: string) =>
|
|
101
|
-
fetcher(`/api/${String(collectionSlug)}/${id}`, {
|
|
102
|
-
method: "DELETE",
|
|
103
|
-
}),
|
|
104
|
-
};
|
|
105
|
-
},
|
|
106
|
-
}),
|
|
107
|
-
|
|
108
|
-
globals: new Proxy({} as any, {
|
|
109
|
-
get(_, globalSlug) {
|
|
110
|
-
return {
|
|
111
|
-
get: () => fetcher(`/api/globals/${String(globalSlug)}`),
|
|
112
|
-
update: (data: any) =>
|
|
113
|
-
fetcher(`/api/globals/${String(globalSlug)}`, {
|
|
114
|
-
method: "PATCH",
|
|
115
|
-
body: JSON.stringify(data),
|
|
116
|
-
}),
|
|
117
|
-
};
|
|
118
|
-
},
|
|
119
|
-
}),
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
// Infer types based on whether T is an OpacaConfig or GeneratedTypes interface
|
|
123
|
-
type TCollections = T extends OpacaConfig
|
|
124
|
-
? T["collections"] extends any[]
|
|
125
|
-
? T["collections"][number]["slug"]
|
|
126
|
-
: string
|
|
127
|
-
: T extends GeneratedTypes
|
|
128
|
-
? keyof T["collections"]
|
|
129
|
-
: string;
|
|
130
|
-
|
|
131
|
-
type TGlobals = T extends OpacaConfig
|
|
132
|
-
? T["globals"] extends any[]
|
|
133
|
-
? T["globals"][number]["slug"]
|
|
134
|
-
: string
|
|
135
|
-
: T extends GeneratedTypes
|
|
136
|
-
? keyof T["globals"]
|
|
137
|
-
: string;
|
|
138
|
-
|
|
139
|
-
type GetCollectionItem<K> = T extends GeneratedTypes
|
|
140
|
-
? K extends keyof T["collections"]
|
|
141
|
-
? T["collections"][K]
|
|
142
|
-
: any
|
|
143
|
-
: any;
|
|
144
|
-
type GetGlobalItem<K> = T extends GeneratedTypes
|
|
145
|
-
? K extends keyof T["globals"]
|
|
146
|
-
? T["globals"][K]
|
|
147
|
-
: any
|
|
148
|
-
: any;
|
|
149
|
-
|
|
150
|
-
return client as any as {
|
|
151
|
-
getMetadata: () => Promise<any>;
|
|
152
|
-
getCollections: () => Promise<any[]>;
|
|
153
|
-
getSetupStatus: () => Promise<{ initialized: boolean }>;
|
|
154
|
-
collections: {
|
|
155
|
-
[K in TCollections]: {
|
|
156
|
-
find: (query?: any) => Promise<{
|
|
157
|
-
docs: GetCollectionItem<K>[];
|
|
158
|
-
totalDocs: number;
|
|
159
|
-
page: number;
|
|
160
|
-
totalPages: number;
|
|
161
|
-
}>;
|
|
162
|
-
findOne: (id: string) => Promise<GetCollectionItem<K>>;
|
|
163
|
-
list: () => Promise<{
|
|
164
|
-
docs: GetCollectionItem<K>[];
|
|
165
|
-
totalDocs: number;
|
|
166
|
-
page: number;
|
|
167
|
-
totalPages: number;
|
|
168
|
-
}>;
|
|
169
|
-
create: (data: Partial<GetCollectionItem<K>>) => Promise<GetCollectionItem<K>>;
|
|
170
|
-
update: (id: string, data: Partial<GetCollectionItem<K>>) => Promise<GetCollectionItem<K>>;
|
|
171
|
-
delete: (id: string) => Promise<{ success: boolean }>;
|
|
172
|
-
};
|
|
173
|
-
};
|
|
174
|
-
globals: {
|
|
175
|
-
[K in TGlobals]: {
|
|
176
|
-
get: () => Promise<GetGlobalItem<K>>;
|
|
177
|
-
update: (data: Partial<GetGlobalItem<K>>) => Promise<GetGlobalItem<K>>;
|
|
178
|
-
};
|
|
179
|
-
};
|
|
180
|
-
};
|
|
181
|
-
}
|
package/src/config-utils.ts
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { getSystemCollections } from "./db/system-schema";
|
|
2
|
-
import type { Field, OpacaConfig, SerializableCollection, SerializableConfig } from "./types";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Sanitizes the OpacaConfig to ensure it's safe to pass to Client Components or over the API.
|
|
6
|
-
* Strips out functions (hooks, access) and the database adapter.
|
|
7
|
-
*/
|
|
8
|
-
export function sanitizeConfig(config: OpacaConfig): SerializableConfig {
|
|
9
|
-
const collections = [...config.collections];
|
|
10
|
-
|
|
11
|
-
// Auto-inject system collections (auth + assets) if relevant features are enabled
|
|
12
|
-
const supportsAuth =
|
|
13
|
-
config.db.name === "sqlite" || config.db.name === "postgres" || config.db.name === "d1";
|
|
14
|
-
|
|
15
|
-
const systemCollections = getSystemCollections();
|
|
16
|
-
|
|
17
|
-
for (const systemCol of systemCollections) {
|
|
18
|
-
const isAsset = systemCol.slug === "_opaca_assets";
|
|
19
|
-
const isAuth = ["_users", "_sessions", "_accounts", "_verifications", "_api_keys"].includes(
|
|
20
|
-
systemCol.slug,
|
|
21
|
-
);
|
|
22
|
-
|
|
23
|
-
if ((isAsset && config.storages) || (isAuth && supportsAuth)) {
|
|
24
|
-
if (!collections.find((col) => col.slug === systemCol.slug)) {
|
|
25
|
-
collections.push({
|
|
26
|
-
...systemCol,
|
|
27
|
-
admin: true,
|
|
28
|
-
} as any);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const sanitizeField = (f: Field): SerializableCollection["fields"][number] => ({
|
|
34
|
-
name: f.name,
|
|
35
|
-
type: f.type,
|
|
36
|
-
label: f.label,
|
|
37
|
-
required: f.required,
|
|
38
|
-
unique: f.unique,
|
|
39
|
-
defaultValue: (f as any).defaultValue,
|
|
40
|
-
localized: f.localized,
|
|
41
|
-
admin: f.admin
|
|
42
|
-
? {
|
|
43
|
-
description: f.admin.description,
|
|
44
|
-
hidden: f.admin.hidden,
|
|
45
|
-
readOnly: f.admin.readOnly,
|
|
46
|
-
components: f.admin.components,
|
|
47
|
-
}
|
|
48
|
-
: undefined,
|
|
49
|
-
options: (f as any).options,
|
|
50
|
-
fields: (f as any).fields ? (f as any).fields.map(sanitizeField) : undefined,
|
|
51
|
-
relationTo: (f as any).relationTo,
|
|
52
|
-
displayField: (f as any).displayField,
|
|
53
|
-
collection: (f as any).collection,
|
|
54
|
-
on: (f as any).on,
|
|
55
|
-
blocks: (f as any).blocks
|
|
56
|
-
? (f as any).blocks.map((b: any) => ({
|
|
57
|
-
slug: b.slug,
|
|
58
|
-
label: b.label,
|
|
59
|
-
fields: b.fields.map(sanitizeField),
|
|
60
|
-
}))
|
|
61
|
-
: undefined,
|
|
62
|
-
tabs: (f as any).tabs
|
|
63
|
-
? (f as any).tabs.map((t: any) => ({
|
|
64
|
-
label: t.label,
|
|
65
|
-
fields: t.fields.map(sanitizeField),
|
|
66
|
-
}))
|
|
67
|
-
: undefined,
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
return {
|
|
71
|
-
appName: config.appName,
|
|
72
|
-
serverURL: config.serverURL,
|
|
73
|
-
collections: collections.map((col) => ({
|
|
74
|
-
slug: col.slug,
|
|
75
|
-
apiPath: col.apiPath,
|
|
76
|
-
label: col.label,
|
|
77
|
-
icon: col.icon,
|
|
78
|
-
admin: col.admin,
|
|
79
|
-
hidden: col.hidden,
|
|
80
|
-
fields: col.fields.map(sanitizeField),
|
|
81
|
-
timestamps: col.timestamps,
|
|
82
|
-
auth: col.auth,
|
|
83
|
-
versions: col.versions,
|
|
84
|
-
})),
|
|
85
|
-
globals: config.globals?.map((g) => ({
|
|
86
|
-
slug: g.slug,
|
|
87
|
-
label: g.label,
|
|
88
|
-
icon: g.icon,
|
|
89
|
-
fields: g.fields.map(sanitizeField),
|
|
90
|
-
})),
|
|
91
|
-
storages: config.storages
|
|
92
|
-
? Object.keys(config.storages).reduce(
|
|
93
|
-
(acc, key) => {
|
|
94
|
-
(acc as Record<string, unknown>)[key] = {};
|
|
95
|
-
return acc;
|
|
96
|
-
},
|
|
97
|
-
{} as Record<string, unknown>,
|
|
98
|
-
)
|
|
99
|
-
: {},
|
|
100
|
-
i18n: config.i18n,
|
|
101
|
-
};
|
|
102
|
-
}
|
package/src/config.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Helper to define the OpacaCMS configuration with full type safety.
|
|
3
|
-
*/
|
|
4
|
-
import type { Collection, OpacaConfig } from "./types";
|
|
5
|
-
import { OpacaConfigSchema } from "./validation";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Recursively builds any object that has a .build() method.
|
|
9
|
-
* This is used to normalize Fluent API builders into plain objects.
|
|
10
|
-
*/
|
|
11
|
-
function recursivelyBuild(obj: any): any {
|
|
12
|
-
if (!obj || typeof obj !== "object") return obj;
|
|
13
|
-
|
|
14
|
-
// If it has a build method, it's one of our builders
|
|
15
|
-
if (typeof obj.build === "function") {
|
|
16
|
-
return recursivelyBuild(obj.build());
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// If it's an array, build its elements
|
|
20
|
-
if (Array.isArray(obj)) {
|
|
21
|
-
return obj.map(recursivelyBuild);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// If it's not a plain object (e.g., an instance of a DatabaseAdapter), return as is
|
|
25
|
-
if (obj.constructor !== Object) {
|
|
26
|
-
return obj;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// It's a plain object, build its properties
|
|
30
|
-
const built: any = {};
|
|
31
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
32
|
-
built[key] = recursivelyBuild(value);
|
|
33
|
-
}
|
|
34
|
-
return built;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Helper logic to infer slugs from collections.
|
|
39
|
-
*/
|
|
40
|
-
export function defineConfig<const TCollections extends readonly Collection[]>(
|
|
41
|
-
config: OpacaConfig<TCollections[number]["slug"]> & { collections: TCollections },
|
|
42
|
-
): OpacaConfig<TCollections[number]["slug"]> {
|
|
43
|
-
const builtConfig = recursivelyBuild(config);
|
|
44
|
-
const result = OpacaConfigSchema.safeParse(builtConfig);
|
|
45
|
-
if (!result.success) {
|
|
46
|
-
throw new Error(`Invalid OpacaCMS Configuration: ${result.error.message}`);
|
|
47
|
-
}
|
|
48
|
-
return builtConfig;
|
|
49
|
-
}
|
package/src/db/adapter.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import type { Collection, DatabaseAdapter, FindOptions, Global, PaginatedResult } from "../types";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* BaseDatabaseAdapter is an abstract class that implements the DatabaseAdapter interface.
|
|
5
|
-
* It provides a foundation for database adapters and enforces the implementation of required methods.
|
|
6
|
-
*/
|
|
7
|
-
export abstract class BaseDatabaseAdapter implements DatabaseAdapter {
|
|
8
|
-
abstract name: string;
|
|
9
|
-
public get raw(): unknown {
|
|
10
|
-
return undefined;
|
|
11
|
-
}
|
|
12
|
-
public get db(): unknown {
|
|
13
|
-
return undefined;
|
|
14
|
-
}
|
|
15
|
-
abstract connect(): Promise<void>;
|
|
16
|
-
abstract disconnect(): Promise<void>;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Execute a raw SQL query directly on the database.
|
|
20
|
-
*/
|
|
21
|
-
abstract unsafe(sql: string, params?: any[]): Promise<any>;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Count documents in a collection.
|
|
25
|
-
*/
|
|
26
|
-
abstract count(collection: string, query?: any): Promise<number>;
|
|
27
|
-
|
|
28
|
-
abstract create<T extends object>(collection: string, data: Partial<T>): Promise<T>;
|
|
29
|
-
abstract find<T extends object>(
|
|
30
|
-
collection: string,
|
|
31
|
-
query?: any,
|
|
32
|
-
options?: FindOptions,
|
|
33
|
-
): Promise<PaginatedResult<T>>;
|
|
34
|
-
abstract findOne<T extends object>(collection: string, query: any): Promise<T | null>;
|
|
35
|
-
abstract update<T extends object>(collection: string, query: any, data: Partial<T>): Promise<T>;
|
|
36
|
-
abstract updateMany?<T extends object>(
|
|
37
|
-
collection: string,
|
|
38
|
-
query: any,
|
|
39
|
-
data: Partial<T>,
|
|
40
|
-
): Promise<number>;
|
|
41
|
-
abstract delete(collection: string, query: any): Promise<boolean>;
|
|
42
|
-
abstract deleteMany?(collection: string, query: any): Promise<number>;
|
|
43
|
-
|
|
44
|
-
abstract findGlobal?<T extends object>(slug: string): Promise<T | null>;
|
|
45
|
-
abstract updateGlobal?<T extends object>(slug: string, data: Partial<T>): Promise<T>;
|
|
46
|
-
|
|
47
|
-
abstract migrate(collections: Collection[], globals?: Global[]): Promise<void>;
|
|
48
|
-
|
|
49
|
-
public push?: boolean;
|
|
50
|
-
public pushDestructive?: boolean;
|
|
51
|
-
public migrationDir?: string;
|
|
52
|
-
public runMigrations?(): Promise<void>;
|
|
53
|
-
}
|