@kyro-cms/admin 0.3.2 → 0.3.5

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.
Files changed (242) hide show
  1. package/dist/EditorClient-XEUOVAAC.js +466 -0
  2. package/dist/EditorClient-XEUOVAAC.js.map +1 -0
  3. package/dist/EditorClient-YLCGVDXY.cjs +468 -0
  4. package/dist/EditorClient-YLCGVDXY.cjs.map +1 -0
  5. package/dist/chunk-7KPIUCGT.js +384 -0
  6. package/dist/chunk-7KPIUCGT.js.map +1 -0
  7. package/dist/chunk-GOACG6R7.cjs +473 -0
  8. package/dist/chunk-GOACG6R7.cjs.map +1 -0
  9. package/dist/index.cjs +14861 -0
  10. package/dist/index.cjs.map +1 -0
  11. package/dist/index.css +1661 -0
  12. package/dist/index.css.map +1 -0
  13. package/dist/index.d.ts +563 -0
  14. package/dist/index.js +14784 -0
  15. package/dist/index.js.map +1 -0
  16. package/package.json +19 -19
  17. package/src/components/ActionBar.tsx +7 -43
  18. package/src/components/Admin.tsx +138 -277
  19. package/src/components/ApiKeysManager.tsx +428 -419
  20. package/src/components/AuditLogsPage.tsx +35 -39
  21. package/src/components/AuthBridge.tsx +51 -0
  22. package/src/components/AutoForm.tsx +495 -1230
  23. package/src/components/BrandingHub.tsx +18 -19
  24. package/src/components/BulkActionsBar.tsx +1 -1
  25. package/src/components/CreateView.tsx +22 -36
  26. package/src/components/Dashboard.tsx +60 -84
  27. package/src/components/DetailView.tsx +113 -91
  28. package/src/components/DeveloperCenter.tsx +200 -198
  29. package/src/components/FieldRenderer.tsx +206 -0
  30. package/src/components/GraphQLPlayground.tsx +340 -480
  31. package/src/components/ListView.tsx +828 -254
  32. package/src/components/LoginPage.tsx +3 -4
  33. package/src/components/MarketplaceManager.tsx +254 -0
  34. package/src/components/MediaGallery.tsx +856 -1192
  35. package/src/components/PluginsManager.tsx +277 -0
  36. package/src/components/RestPlayground.tsx +398 -560
  37. package/src/components/SessionsManager.tsx +211 -0
  38. package/src/components/Sidebar.astro +179 -151
  39. package/src/components/ThemeProvider.tsx +7 -161
  40. package/src/components/UserManagement.tsx +162 -146
  41. package/src/components/UserMenu.tsx +110 -0
  42. package/src/components/WebhookManager.tsx +305 -367
  43. package/src/components/blocks/AccordionBlock.tsx +4 -4
  44. package/src/components/blocks/ArrayBlock.tsx +3 -3
  45. package/src/components/blocks/BlockEditModal.tsx +8 -8
  46. package/src/components/blocks/BlockWrapper.tsx +61 -0
  47. package/src/components/blocks/ButtonBlock.tsx +4 -4
  48. package/src/components/blocks/ChildBlocksTree.tsx +23 -25
  49. package/src/components/blocks/CodeBlock.tsx +15 -15
  50. package/src/components/blocks/ColumnsBlock.tsx +6 -44
  51. package/src/components/blocks/DividerBlock.tsx +3 -3
  52. package/src/components/blocks/FileBlock.tsx +4 -4
  53. package/src/components/blocks/HeadingBlock.tsx +6 -38
  54. package/src/components/blocks/HeroBlock.tsx +4 -4
  55. package/src/components/blocks/ImageBlock.tsx +4 -4
  56. package/src/components/blocks/LinkBlock.tsx +4 -4
  57. package/src/components/blocks/ListBlock.tsx +3 -3
  58. package/src/components/blocks/ParagraphBlock.tsx +12 -42
  59. package/src/components/blocks/RelationshipBlock.tsx +4 -4
  60. package/src/components/blocks/RichTextBlock.tsx +4 -4
  61. package/src/components/blocks/VStackBlock.tsx +5 -37
  62. package/src/components/blocks/VideoBlock.tsx +4 -4
  63. package/src/components/blocks/types.ts +11 -0
  64. package/src/components/fields/AccordionField.tsx +1 -1
  65. package/src/components/fields/ArrayField.tsx +2 -2
  66. package/src/components/fields/ArrayLayout.tsx +93 -0
  67. package/src/components/fields/BlocksField.tsx +122 -111
  68. package/src/components/fields/ButtonField.tsx +1 -1
  69. package/src/components/fields/CheckboxField.tsx +14 -15
  70. package/src/components/fields/ChildrenField.tsx +2 -2
  71. package/src/components/fields/CodeField.tsx +3 -3
  72. package/src/components/fields/ColumnsField.tsx +2 -2
  73. package/src/components/fields/DateField.tsx +13 -26
  74. package/src/components/fields/EditorClient.tsx +26 -28
  75. package/src/components/fields/FieldLayout.tsx +52 -0
  76. package/src/components/fields/GroupLayout.tsx +35 -0
  77. package/src/components/fields/JSONField.tsx +7 -7
  78. package/src/components/fields/LinkField.tsx +1 -1
  79. package/src/components/fields/MarkdownField.tsx +1 -1
  80. package/src/components/fields/NumberField.tsx +13 -26
  81. package/src/components/fields/PortableTextField.tsx +4 -4
  82. package/src/components/fields/PortableTextRenderer.tsx +1 -1
  83. package/src/components/fields/RelationshipBlockField.tsx +31 -23
  84. package/src/components/fields/RelationshipField.tsx +14 -14
  85. package/src/components/fields/SelectField.tsx +17 -26
  86. package/src/components/fields/TabsLayout.tsx +69 -0
  87. package/src/components/fields/TextField.tsx +85 -38
  88. package/src/components/fields/UploadField.tsx +71 -41
  89. package/src/components/fields/VideoField.tsx +1 -1
  90. package/src/components/fields/extensions/blockComponents.tsx +2 -2
  91. package/src/components/fields/extensions/blocksStore.ts +207 -193
  92. package/src/components/fields/types.ts +22 -0
  93. package/src/components/layout/Layout.tsx +1 -1
  94. package/src/components/ui/ActionMenu.tsx +63 -0
  95. package/src/components/ui/Badge.tsx +59 -5
  96. package/src/components/ui/BlockDrawer.tsx +4 -5
  97. package/src/components/ui/CommandPalette.tsx +58 -36
  98. package/src/components/ui/CommandPaletteWrapper.tsx +18 -17
  99. package/src/components/ui/Dropdown.tsx +18 -16
  100. package/src/components/ui/EmptyState.tsx +25 -0
  101. package/src/components/ui/GlobalModal.tsx +49 -0
  102. package/src/components/ui/IconButton.tsx +44 -0
  103. package/src/components/ui/Modal.tsx +19 -20
  104. package/src/components/ui/PageHeader.tsx +158 -0
  105. package/src/components/ui/Pagination.tsx +61 -0
  106. package/src/components/ui/PromptModal.tsx +1 -1
  107. package/src/components/ui/SearchInput.tsx +57 -0
  108. package/src/components/ui/SeoPreview.tsx +31 -0
  109. package/src/components/ui/SessionModal.tsx +0 -0
  110. package/src/components/ui/SlidePanel.tsx +2 -0
  111. package/src/components/ui/Toast.tsx +65 -122
  112. package/src/components/ui/Toaster.tsx +18 -0
  113. package/src/components/ui/icons.tsx +112 -0
  114. package/src/components/users/UserDetail.tsx +290 -0
  115. package/src/components/users/UserForm.tsx +242 -0
  116. package/src/components/users/UsersList.tsx +338 -0
  117. package/src/env.d.ts +13 -13
  118. package/src/fields/index.ts +2 -1
  119. package/src/global.d.ts +7 -0
  120. package/src/hooks/data.ts +2 -9
  121. package/src/hooks/useAsyncData.ts +36 -0
  122. package/src/hooks/useAutoFormState.ts +527 -0
  123. package/src/hooks/useSelection.ts +49 -0
  124. package/src/hooks/useSession.ts +0 -0
  125. package/src/index.ts +11 -1
  126. package/src/integration.ts +86 -11
  127. package/src/kyro-cms.d.ts +209 -0
  128. package/src/layouts/AdminLayout.astro +128 -11
  129. package/src/layouts/AuthLayout.astro +21 -5
  130. package/src/lib/api.ts +175 -55
  131. package/src/lib/autoform-store.ts +435 -0
  132. package/src/lib/config.ts +82 -34
  133. package/src/lib/createRegistry.ts +29 -0
  134. package/src/lib/default-kyro-config.ts +4 -0
  135. package/src/lib/globals.ts +50 -0
  136. package/src/lib/media-utils.ts +18 -0
  137. package/src/lib/object-utils.ts +77 -0
  138. package/src/lib/paths.ts +61 -0
  139. package/src/lib/stores/index.ts +370 -0
  140. package/src/lib/types.ts +43 -0
  141. package/src/lib/useResourceManager.ts +105 -0
  142. package/src/pages/403.astro +67 -0
  143. package/src/pages/[collection]/[id].astro +14 -180
  144. package/src/pages/[collection]/index.astro +11 -6
  145. package/src/pages/api-explorer.astro +173 -0
  146. package/src/pages/audit/index.astro +2 -0
  147. package/src/pages/auth/login.astro +122 -0
  148. package/src/pages/auth/register.astro +167 -0
  149. package/src/pages/graphql-explorer.astro +59 -0
  150. package/src/pages/{admin/graphql.astro → graphql.astro} +51 -17
  151. package/src/pages/index.astro +577 -0
  152. package/src/pages/index_ALT.astro +3 -0
  153. package/src/pages/keys.astro +11 -0
  154. package/src/pages/marketplace.astro +11 -0
  155. package/src/pages/media.astro +3 -0
  156. package/src/pages/plugins.astro +8 -0
  157. package/src/pages/preview/[collection]/[id].astro +188 -123
  158. package/src/pages/rest-playground.astro +62 -0
  159. package/src/pages/roles/index.astro +183 -76
  160. package/src/pages/sessions.astro +8 -0
  161. package/src/pages/settings/[slug].astro +92 -114
  162. package/src/pages/settings/index.astro +5 -3
  163. package/src/pages/users/[id].astro +25 -154
  164. package/src/pages/users/index.astro +19 -130
  165. package/src/pages/users/new.astro +9 -86
  166. package/src/pages/webhooks.astro +11 -0
  167. package/src/routes.ts +80 -0
  168. package/src/styles/main.css +119 -79
  169. package/src/theme/tokens.ts +1 -0
  170. package/src/vite-env.d.ts +14 -0
  171. package/src/collections/auth/index.ts +0 -155
  172. package/src/collections/portfolio/index.ts +0 -343
  173. package/src/components/ApiExplorer.tsx +0 -325
  174. package/src/components/EnhancedListView.tsx +0 -889
  175. package/src/components/GraphQLExplorer.tsx +0 -675
  176. package/src/components/Icons.tsx +0 -23
  177. package/src/components/StatusBadge.tsx +0 -76
  178. package/src/lib/MediaService.ts +0 -541
  179. package/src/lib/auth/sqlite-adapter.ts +0 -319
  180. package/src/lib/dataStore.ts +0 -226
  181. package/src/lib/db/adapter.ts +0 -54
  182. package/src/lib/db/drizzle-mysql-adapter.ts +0 -194
  183. package/src/lib/db/drizzle-mysql-auth-adapter.ts +0 -327
  184. package/src/lib/db/drizzle-postgres-adapter.ts +0 -202
  185. package/src/lib/db/drizzle-postgres-auth-adapter.ts +0 -304
  186. package/src/lib/db/drizzle-sqlite-adapter.ts +0 -227
  187. package/src/lib/db/drizzle-sqlite-auth-adapter.ts +0 -548
  188. package/src/lib/db/index.ts +0 -449
  189. package/src/lib/db/mongodb-adapter.ts +0 -207
  190. package/src/lib/db/mongodb-auth-adapter.ts +0 -305
  191. package/src/lib/db/schema/mysql-auth.ts +0 -113
  192. package/src/lib/db/schema/mysql-content.ts +0 -20
  193. package/src/lib/db/schema/postgres-auth.ts +0 -116
  194. package/src/lib/db/schema/postgres-content.ts +0 -35
  195. package/src/lib/db/schema/postgres-media.ts +0 -52
  196. package/src/lib/db/schema/postgres-settings.ts +0 -11
  197. package/src/lib/db/schema/sqlite-auth.ts +0 -112
  198. package/src/lib/db/schema/sqlite-content.ts +0 -20
  199. package/src/lib/db/version-adapter.ts +0 -248
  200. package/src/lib/graphql/index.ts +0 -1
  201. package/src/lib/graphql/schema.ts +0 -443
  202. package/src/lib/rate-limit.ts +0 -267
  203. package/src/lib/storage.ts +0 -374
  204. package/src/lib/store.ts +0 -85
  205. package/src/middleware.ts +0 -177
  206. package/src/pages/admin/api-explorer.astro +0 -98
  207. package/src/pages/admin/graphql-explorer.astro +0 -40
  208. package/src/pages/admin/index.astro +0 -286
  209. package/src/pages/admin/keys.astro +0 -8
  210. package/src/pages/admin/rest-playground.astro +0 -44
  211. package/src/pages/admin/webhooks.astro +0 -8
  212. package/src/pages/api/[collection]/[id]/publish.ts +0 -52
  213. package/src/pages/api/[collection]/[id]/unpublish.ts +0 -42
  214. package/src/pages/api/[collection]/[id]/versions.ts +0 -66
  215. package/src/pages/api/[collection]/[id].ts +0 -213
  216. package/src/pages/api/[collection]/index.ts +0 -209
  217. package/src/pages/api/auth/[id].ts +0 -121
  218. package/src/pages/api/auth/audit-logs.ts +0 -57
  219. package/src/pages/api/auth/login.ts +0 -211
  220. package/src/pages/api/auth/logout.ts +0 -66
  221. package/src/pages/api/auth/me.ts +0 -36
  222. package/src/pages/api/auth/refresh.ts +0 -119
  223. package/src/pages/api/auth/register.ts +0 -188
  224. package/src/pages/api/auth/users.ts +0 -97
  225. package/src/pages/api/collections.ts +0 -59
  226. package/src/pages/api/globals/[slug].ts +0 -42
  227. package/src/pages/api/graphql.ts +0 -90
  228. package/src/pages/api/health.ts +0 -426
  229. package/src/pages/api/keys/[id].ts +0 -26
  230. package/src/pages/api/keys/index.ts +0 -75
  231. package/src/pages/api/media/[id].ts +0 -309
  232. package/src/pages/api/media/folders.ts +0 -609
  233. package/src/pages/api/media/index.ts +0 -146
  234. package/src/pages/api/media/resize.ts +0 -267
  235. package/src/pages/api/search.ts +0 -82
  236. package/src/pages/api/slug-availability.ts +0 -70
  237. package/src/pages/api/storage-config.ts +0 -20
  238. package/src/pages/api/storage-status.ts +0 -206
  239. package/src/pages/api/upload.ts +0 -334
  240. package/src/pages/api/webhooks/index.ts +0 -71
  241. package/src/pages/login.astro +0 -82
  242. package/src/pages/register.astro +0 -102
@@ -1,112 +0,0 @@
1
- import { sqliteTable, text, integer, index } from "drizzle-orm/sqlite-core";
2
-
3
- export const users = sqliteTable("users", {
4
- id: text("id").primaryKey(),
5
- email: text("email").notNull().unique(),
6
- passwordHash: text("password_hash").notNull(),
7
- name: text("name"),
8
- role: text("role").notNull().default("customer"),
9
- tenantId: text("tenant_id"),
10
- emailVerified: integer("email_verified", { mode: "boolean" }).default(false),
11
- locked: integer("locked", { mode: "boolean" }).default(false),
12
- lastLogin: text("last_login"),
13
- failedLoginAttempts: integer("failed_login_attempts").default(0),
14
- lockedUntil: text("locked_until"),
15
- createdAt: text("created_at").notNull(),
16
- updatedAt: text("updated_at").notNull(),
17
- });
18
-
19
- export const sessions = sqliteTable(
20
- "sessions",
21
- {
22
- id: text("id").primaryKey(),
23
- token: text("token").notNull().unique(),
24
- refreshToken: text("refresh_token"),
25
- userId: text("user_id")
26
- .notNull()
27
- .references(() => users.id, { onDelete: "cascade" }),
28
- expiresAt: text("expires_at").notNull(),
29
- createdAt: text("created_at").notNull(),
30
- },
31
- (table) => {
32
- return {
33
- userIdIdx: index("idx_sessions_user_id").on(table.userId),
34
- tokenIdx: index("idx_sessions_token").on(table.token),
35
- expiresIdx: index("idx_sessions_expires").on(table.expiresAt),
36
- };
37
- },
38
- );
39
-
40
- export const roles = sqliteTable("roles", {
41
- id: text("id").primaryKey(),
42
- name: text("name").notNull().unique(),
43
- level: integer("level").notNull().default(0),
44
- inherits: text("inherits").$type<string[]>(),
45
- permissions: text("permissions").$type<string[]>(),
46
- isSystem: integer("is_system", { mode: "boolean" }).default(false),
47
- description: text("description"),
48
- createdAt: text("created_at").notNull(),
49
- });
50
-
51
- export const auditLogs = sqliteTable(
52
- "audit_logs",
53
- {
54
- id: text("id").primaryKey(),
55
- action: text("action").notNull(),
56
- userId: text("user_id").references(() => users.id, {
57
- onDelete: "set null",
58
- }),
59
- userEmail: text("user_email"),
60
- role: text("role"),
61
- resource: text("resource").notNull(),
62
- ipAddress: text("ip_address"),
63
- userAgent: text("user_agent"),
64
- success: integer("success", { mode: "boolean" }).notNull(),
65
- error: text("error"),
66
- metadata: text("metadata").$type<Record<string, unknown>>(),
67
- createdAt: text("created_at").notNull(),
68
- },
69
- (table) => {
70
- return {
71
- userIdIdx: index("idx_audit_user_id").on(table.userId),
72
- actionIdx: index("idx_audit_action").on(table.action),
73
- createdAtIdx: index("idx_audit_created_at").on(table.createdAt),
74
- };
75
- },
76
- );
77
-
78
- export const passwordHistory = sqliteTable(
79
- "password_history",
80
- {
81
- id: text("id").primaryKey(),
82
- userId: text("user_id")
83
- .notNull()
84
- .references(() => users.id, { onDelete: "cascade" }),
85
- passwordHash: text("password_hash").notNull(),
86
- createdAt: text("created_at").notNull(),
87
- },
88
- (table) => {
89
- return {
90
- userIdIdx: index("idx_password_history_user_id").on(table.userId),
91
- };
92
- },
93
- );
94
-
95
- export const lockouts = sqliteTable("lockouts", {
96
- id: text("id").primaryKey(),
97
- userId: text("user_id")
98
- .notNull()
99
- .references(() => users.id, { onDelete: "cascade" }),
100
- ipAddress: text("ip_address"),
101
- lockedUntil: text("locked_until").notNull(),
102
- createdAt: text("created_at").notNull(),
103
- });
104
-
105
- export type User = typeof users.$inferSelect;
106
- export type NewUser = typeof users.$inferInsert;
107
- export type Session = typeof sessions.$inferSelect;
108
- export type NewSession = typeof sessions.$inferInsert;
109
- export type Role = typeof roles.$inferSelect;
110
- export type NewRole = typeof roles.$inferInsert;
111
- export type AuditLog = typeof auditLogs.$inferSelect;
112
- export type NewAuditLog = typeof auditLogs.$inferInsert;
@@ -1,20 +0,0 @@
1
- import { sqliteTable, text, integer } from "drizzle-orm/sqlite-core";
2
-
3
- export const documents = sqliteTable("documents", {
4
- id: text("id").primaryKey(),
5
- collection: text("collection").notNull(),
6
- data: text("data").notNull().$type<Record<string, unknown>>(),
7
- createdAt: text("created_at").notNull(),
8
- updatedAt: text("updated_at").notNull(),
9
- });
10
-
11
- export const globals = sqliteTable("globals", {
12
- slug: text("slug").primaryKey(),
13
- data: text("data").notNull().$type<Record<string, unknown>>(),
14
- updatedAt: text("updated_at").notNull(),
15
- });
16
-
17
- export type Document = typeof documents.$inferSelect;
18
- export type NewDocument = typeof documents.$inferInsert;
19
- export type Global = typeof globals.$inferSelect;
20
- export type NewGlobal = typeof globals.$inferInsert;
@@ -1,248 +0,0 @@
1
- import { randomUUID } from "crypto";
2
- import { diff } from "jsondiffpatch";
3
- import type {
4
- Version,
5
- VersionStatus,
6
- VersionDiff,
7
- CreateVersionOptions,
8
- PublishVersionOptions,
9
- CompareVersionsOptions,
10
- VersionHistoryOptions,
11
- VersionAdapter,
12
- } from "@kyro-cms/core";
13
- import type { DatabaseAdapter } from "./adapter.js";
14
-
15
- const VERSIONS_COLLECTION = "_versions";
16
-
17
- export class DataStoreVersionAdapter implements VersionAdapter {
18
- constructor(private db: DatabaseAdapter) {}
19
-
20
- async createVersion<T>(
21
- options: CreateVersionOptions<T>,
22
- ): Promise<Version<T>> {
23
- const latest = await this.getLatestVersion(
24
- options.collection,
25
- options.documentId,
26
- );
27
- const nextVersion = (latest?.version ?? 0) + 1;
28
-
29
- const versionDoc: Version<T> = {
30
- id: randomUUID(),
31
- collection: options.collection,
32
- documentId: options.documentId,
33
- version: nextVersion,
34
- status: options.status || "draft",
35
- data: options.data,
36
- createdBy: options.createdBy,
37
- createdAt: new Date(),
38
- changeDescription: options.changeDescription,
39
- };
40
-
41
- await this.db.create(VERSIONS_COLLECTION, versionDoc);
42
- return versionDoc;
43
- }
44
-
45
- async getVersion<T>(
46
- collection: string,
47
- versionId: string,
48
- ): Promise<Version<T> | null> {
49
- const version = await this.db.findById<Version<T>>(
50
- VERSIONS_COLLECTION,
51
- versionId,
52
- );
53
- if (!version || version.collection !== collection) return null;
54
- return version;
55
- }
56
-
57
- async getVersions<T>(options: VersionHistoryOptions): Promise<Version<T>[]> {
58
- const result = await this.db.find<Version<T>>(VERSIONS_COLLECTION, {
59
- limit: 100,
60
- });
61
- const filtered = result.docs
62
- .filter(
63
- (v: Version<T>) =>
64
- v.collection === options.collection &&
65
- v.documentId === options.documentId,
66
- )
67
- .sort((a: Version<T>, b: Version<T>) => b.version - a.version)
68
- .slice(
69
- options.offset ?? 0,
70
- (options.offset ?? 0) + (options.limit ?? 20),
71
- );
72
- return filtered;
73
- }
74
-
75
- async getLatestVersion<T>(
76
- collection: string,
77
- documentId: string,
78
- ): Promise<Version<T> | null> {
79
- const versions = await this.getVersions<T>({
80
- collection,
81
- documentId,
82
- limit: 1,
83
- });
84
- return versions.length > 0 ? versions[0] : null;
85
- }
86
-
87
- async getPublishedVersion<T>(
88
- collection: string,
89
- documentId: string,
90
- ): Promise<Version<T> | null> {
91
- const versions = await this.getVersions<T>({
92
- collection,
93
- documentId,
94
- limit: 100,
95
- });
96
- return versions.find((v: Version<T>) => v.status === "published") || null;
97
- }
98
-
99
- async publishVersion(options: PublishVersionOptions): Promise<void> {
100
- const versions = await this.getVersions({
101
- collection: options.collection,
102
- documentId: options.documentId,
103
- limit: 100,
104
- });
105
- for (const v of versions) {
106
- if (v.status === "published") {
107
- const updated = { ...v, status: "draft" as VersionStatus };
108
- await this.db.update(VERSIONS_COLLECTION, v.id, updated);
109
- }
110
- }
111
-
112
- const target = versions.find(
113
- (v: Version<unknown>) => v.id === options.versionId,
114
- );
115
- if (target) {
116
- const updated = {
117
- ...target,
118
- status: "published" as VersionStatus,
119
- publishedAt: new Date(),
120
- };
121
- await this.db.update(VERSIONS_COLLECTION, target.id, updated);
122
- }
123
- }
124
-
125
- async revertToVersion<T>(options: {
126
- collection: string;
127
- documentId: string;
128
- versionId: string;
129
- userId: string;
130
- }): Promise<Version<T>> {
131
- const target = await this.getVersion<T>(
132
- options.collection,
133
- options.versionId,
134
- );
135
- if (!target) {
136
- throw new Error("Version not found");
137
- }
138
-
139
- return this.createVersion<T>({
140
- collection: options.collection,
141
- documentId: options.documentId,
142
- data: target.data,
143
- status: "draft",
144
- createdBy: options.userId,
145
- changeDescription: `Reverted to version ${target.version}`,
146
- });
147
- }
148
-
149
- async compareVersions<T>(
150
- options: CompareVersionsOptions,
151
- ): Promise<VersionDiff[]> {
152
- const versions = await this.getVersions<T>({
153
- collection: options.collection,
154
- documentId: options.documentId,
155
- limit: 100,
156
- });
157
-
158
- const findVersion = (ref: string | number): Version<T> | undefined => {
159
- if (typeof ref === "number") {
160
- return versions.find((v) => v.version === ref);
161
- }
162
- return versions.find((v) => v.id === ref);
163
- };
164
-
165
- const versionA = findVersion(options.versionA);
166
- const versionB = findVersion(options.versionB);
167
-
168
- if (!versionA || !versionB) {
169
- throw new Error("One or both versions not found");
170
- }
171
-
172
- const delta = diff(
173
- versionA.data as Record<string, unknown>,
174
- versionB.data as Record<string, unknown>,
175
- );
176
- const diffs: VersionDiff[] = [];
177
-
178
- if (!delta) return diffs;
179
-
180
- const walkDelta = (obj: any, path: string = "") => {
181
- if (
182
- Array.isArray(obj) &&
183
- obj[0] !== undefined &&
184
- obj[1] !== undefined &&
185
- obj.length === 2 &&
186
- !Array.isArray(obj[0])
187
- ) {
188
- diffs.push({
189
- field: path || "root",
190
- oldValue: obj[0],
191
- newValue: obj[1],
192
- });
193
- return;
194
- }
195
- if (obj && typeof obj === "object" && obj._t === "a") {
196
- for (const [key, value] of Object.entries(obj)) {
197
- if (key === "_t") continue;
198
- const arrayPath = `${path}[${key.replace(/^_/, "")}]`;
199
- if (Array.isArray(value) && value.length >= 2) {
200
- diffs.push({
201
- field: arrayPath,
202
- oldValue: value[0],
203
- newValue: value[1],
204
- });
205
- } else {
206
- walkDelta(value, arrayPath);
207
- }
208
- }
209
- return;
210
- }
211
- for (const [key, value] of Object.entries(obj)) {
212
- const fullPath = path ? `${path}.${key}` : key;
213
- if (
214
- Array.isArray(value) &&
215
- value.length === 2 &&
216
- !Array.isArray(value[0]) &&
217
- !Array.isArray(value[1])
218
- ) {
219
- diffs.push({
220
- field: fullPath,
221
- oldValue: value[0],
222
- newValue: value[1],
223
- });
224
- } else if (
225
- value &&
226
- typeof value === "object" &&
227
- !Array.isArray(value)
228
- ) {
229
- walkDelta(value, fullPath);
230
- }
231
- }
232
- };
233
-
234
- walkDelta(delta);
235
- return diffs;
236
- }
237
-
238
- async deleteVersions(collection: string, documentId: string): Promise<void> {
239
- const versions = await this.getVersions({
240
- collection,
241
- documentId,
242
- limit: 100,
243
- });
244
- for (const v of versions) {
245
- await this.db.delete(VERSIONS_COLLECTION, v.id);
246
- }
247
- }
248
- }
@@ -1 +0,0 @@
1
- export { executeGraphQL, schemaString } from "./schema";