opacacms 0.3.11 → 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?: "default" | "link" | "destructive" | "outline" | "secondary" | "ghost" | null | undefined;
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> & {
@@ -25,6 +25,7 @@ import {
25
25
  // src/db/bun-sqlite.ts
26
26
  import fs from "node:fs/promises";
27
27
  import path from "node:path";
28
+ import { pathToFileURL } from "node:url";
28
29
  import { FileMigrationProvider, Migrator, sql } from "kysely";
29
30
  class BunSQLiteAdapter extends BaseDatabaseAdapter {
30
31
  path;
@@ -555,7 +556,7 @@ class BunSQLiteAdapter extends BaseDatabaseAdapter {
555
556
  provider: new FileMigrationProvider({
556
557
  fs,
557
558
  path,
558
- migrationFolder: path.resolve(process.cwd(), this.migrationDir)
559
+ migrationFolder: pathToFileURL(path.resolve(process.cwd(), this.migrationDir)).href
559
560
  })
560
561
  });
561
562
  const { error, results } = await migrator.migrateToLatest();
@@ -25,6 +25,7 @@ import {
25
25
  // src/db/better-sqlite.ts
26
26
  import fs from "node:fs/promises";
27
27
  import path from "node:path";
28
+ import { pathToFileURL } from "node:url";
28
29
  import {
29
30
  CompiledQuery,
30
31
  FileMigrationProvider,
@@ -548,7 +549,7 @@ class BetterSQLiteAdapter extends BaseDatabaseAdapter {
548
549
  provider: new FileMigrationProvider({
549
550
  fs,
550
551
  path,
551
- migrationFolder: path.resolve(process.cwd(), this.migrationDir)
552
+ migrationFolder: pathToFileURL(path.resolve(process.cwd(), this.migrationDir)).href
552
553
  })
553
554
  });
554
555
  const { error, results } = await migrator.migrateToLatest();
@@ -24,6 +24,7 @@ import {
24
24
  // src/db/postgres.ts
25
25
  import fs from "node:fs/promises";
26
26
  import path from "node:path";
27
+ import { pathToFileURL } from "node:url";
27
28
  import {
28
29
  CompiledQuery,
29
30
  FileMigrationProvider,
@@ -578,7 +579,7 @@ class PostgresAdapter extends BaseDatabaseAdapter {
578
579
  provider: new FileMigrationProvider({
579
580
  fs,
580
581
  path,
581
- migrationFolder: path.resolve(process.cwd(), this.migrationDir)
582
+ migrationFolder: pathToFileURL(path.resolve(process.cwd(), this.migrationDir)).href
582
583
  })
583
584
  });
584
585
  const { error, results } = await migrator.migrateToLatest();
@@ -25,6 +25,7 @@ import {
25
25
  // src/db/d1.ts
26
26
  import fs from "node:fs/promises";
27
27
  import path from "node:path";
28
+ import { pathToFileURL } from "node:url";
28
29
  import { CompiledQuery, FileMigrationProvider, Migrator } from "kysely";
29
30
  class D1Adapter extends BaseDatabaseAdapter {
30
31
  name = "d1";
@@ -574,7 +575,7 @@ class D1Adapter extends BaseDatabaseAdapter {
574
575
  provider: new FileMigrationProvider({
575
576
  fs,
576
577
  path,
577
- migrationFolder: path.resolve(process.cwd(), this.migrationDir)
578
+ migrationFolder: pathToFileURL(path.resolve(process.cwd(), this.migrationDir)).href
578
579
  })
579
580
  });
580
581
  const { error, results } = await migrator.migrateToLatest();
@@ -96,7 +96,8 @@ function createClient(configOrOptions) {
96
96
  return {
97
97
  find: async (query) => {
98
98
  await initConfig();
99
- if (engineConfig?.graphql?.enabled && !engineConfig?.rest) {
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
- if (engineConfig?.graphql?.enabled && !engineConfig?.rest) {
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
- if (engineConfig?.graphql?.enabled && !engineConfig?.rest) {
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
- if (engineConfig?.graphql?.enabled && !engineConfig?.rest) {
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
- if (engineConfig?.graphql?.enabled && !engineConfig?.rest) {
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
- if (engineConfig?.graphql?.enabled && !engineConfig?.rest) {
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
- if (engineConfig?.graphql?.enabled && !engineConfig?.rest) {
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 });
@@ -25,6 +25,7 @@ import {
25
25
  // src/db/sqlite.ts
26
26
  import fs from "node:fs/promises";
27
27
  import path from "node:path";
28
+ import { pathToFileURL } from "node:url";
28
29
  import {
29
30
  CompiledQuery,
30
31
  FileMigrationProvider,
@@ -563,7 +564,7 @@ class SQLiteAdapter extends BaseDatabaseAdapter {
563
564
  provider: new FileMigrationProvider({
564
565
  fs,
565
566
  path,
566
- migrationFolder: path.resolve(process.cwd(), this.migrationDir)
567
+ migrationFolder: pathToFileURL(path.resolve(process.cwd(), this.migrationDir)).href
567
568
  })
568
569
  });
569
570
  const { error, results } = await migrator.migrateToLatest();
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 T extends OpacaConfig<string> ? T["collections"] extends any[] ? T["collections"][number]["slug"] : string : T extends GeneratedTypes ? keyof T["collections"] : string]: {
99
+ collections: { [K in (keyof InferCollections<T> extends never ? string : keyof InferCollections<T>) & string]: {
28
100
  find: (query?: any) => Promise<{
29
- docs: (T extends GeneratedTypes ? K extends keyof T["collections"] ? T["collections"][K] : any : any)[];
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<T extends GeneratedTypes ? K extends keyof T["collections"] ? T["collections"][K] : any : any>;
106
+ findOne: (id: string) => Promise<K extends keyof InferCollections<T> ? InferCollections<T>[K] : any>;
35
107
  list: () => Promise<{
36
- docs: (T extends GeneratedTypes ? K extends keyof T["collections"] ? T["collections"][K] : any : any)[];
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<T extends GeneratedTypes ? K extends keyof T["collections"] ? T["collections"][K] : any : any>) => Promise<T extends GeneratedTypes ? K extends keyof T["collections"] ? T["collections"][K] : any : any>;
42
- update: (id: string, data: Partial<T extends GeneratedTypes ? K extends keyof T["collections"] ? T["collections"][K] : any : any>) => Promise<T extends GeneratedTypes ? K extends keyof T["collections"] ? T["collections"][K] : any : any>;
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 T extends OpacaConfig<string> ? T["globals"] extends any[] ? T["globals"][number]["slug"] : string : T extends GeneratedTypes ? keyof T["globals"] : string]: {
48
- get: () => Promise<T extends GeneratedTypes ? K extends keyof T["globals"] ? T["globals"][K] : any : any>;
49
- update: (data: Partial<T extends GeneratedTypes ? K extends keyof T["globals"] ? T["globals"][K] : any : any>) => Promise<T extends GeneratedTypes ? K extends keyof T["globals"] ? T["globals"][K] : any : any>;
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
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  OpacaError,
3
3
  createClient
4
- } from "./chunk-2fm4kv2q.js";
4
+ } from "./chunk-gj8w1r1e.js";
5
5
  import"./chunk-2vbfc4q8.js";
6
6
  import"./chunk-8sqjbsgt.js";
7
7
  export {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  BetterSQLiteAdapter,
3
3
  createBetterSQLiteAdapter
4
- } from "../chunk-ec6wz44n.js";
4
+ } from "../chunk-1vtdkx5e.js";
5
5
  import"../chunk-re459gm9.js";
6
6
  import"../chunk-s8mqwnm1.js";
7
7
  import"../chunk-q5sb5dcr.js";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  BunSQLiteAdapter,
3
3
  createBunSQLiteAdapter
4
- } from "../chunk-5a6cjmfz.js";
4
+ } from "../chunk-0njhbe4a.js";
5
5
  import"../chunk-re459gm9.js";
6
6
  import"../chunk-s8mqwnm1.js";
7
7
  import"../chunk-q5sb5dcr.js";
package/dist/db/d1.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  D1Adapter,
3
3
  createD1Adapter
4
- } from "../chunk-g7bgnpy4.js";
4
+ } from "../chunk-8hhzvesq.js";
5
5
  import"../chunk-re459gm9.js";
6
6
  import"../chunk-s8mqwnm1.js";
7
7
  import"../chunk-q5sb5dcr.js";
package/dist/db/index.js CHANGED
@@ -1,23 +1,23 @@
1
1
  import {
2
2
  D1Adapter,
3
3
  createD1Adapter
4
- } from "../chunk-g7bgnpy4.js";
4
+ } from "../chunk-8hhzvesq.js";
5
5
  import {
6
6
  PostgresAdapter,
7
7
  createPostgresAdapter
8
- } from "../chunk-5prjxes5.js";
8
+ } from "../chunk-2ec9fsgr.js";
9
9
  import {
10
10
  SQLiteAdapter,
11
11
  createSQLiteAdapter
12
- } from "../chunk-swa093n5.js";
12
+ } from "../chunk-xdmw9vzq.js";
13
13
  import {
14
14
  BunSQLiteAdapter,
15
15
  createBunSQLiteAdapter
16
- } from "../chunk-5a6cjmfz.js";
16
+ } from "../chunk-0njhbe4a.js";
17
17
  import {
18
18
  BetterSQLiteAdapter,
19
19
  createBetterSQLiteAdapter
20
- } from "../chunk-ec6wz44n.js";
20
+ } from "../chunk-1vtdkx5e.js";
21
21
  import"../chunk-re459gm9.js";
22
22
  import {
23
23
  BaseDatabaseAdapter
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  PostgresAdapter,
3
3
  createPostgresAdapter
4
- } from "../chunk-5prjxes5.js";
4
+ } from "../chunk-2ec9fsgr.js";
5
5
  import"../chunk-re459gm9.js";
6
6
  import"../chunk-s8mqwnm1.js";
7
7
  import"../chunk-q5sb5dcr.js";
package/dist/db/sqlite.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  SQLiteAdapter,
3
3
  createSQLiteAdapter
4
- } from "../chunk-swa093n5.js";
4
+ } from "../chunk-xdmw9vzq.js";
5
5
  import"../chunk-re459gm9.js";
6
6
  import"../chunk-s8mqwnm1.js";
7
7
  import"../chunk-q5sb5dcr.js";
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  OpacaError,
3
3
  createClient
4
- } from "./chunk-2fm4kv2q.js";
4
+ } from "./chunk-gj8w1r1e.js";
5
5
  import {
6
6
  defineCollection,
7
7
  defineGlobal
@@ -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
- relationship: "relationship";
8
+ slug: "slug";
9
+ date: "date";
12
10
  select: "select";
13
11
  radio: "radio";
14
- date: "date";
12
+ json: "json";
15
13
  file: "file";
16
- blocks: "blocks";
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
  }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opacacms",
3
- "version": "0.3.11",
3
+ "version": "0.3.13",
4
4
  "license": "MIT",
5
5
  "description": "OpacaCMS: A lightweight, type-safe, and developer-first Headless CMS for the edge and beyond.",
6
6
  "keywords": [