@withstudiocms/sdk 0.0.0-beta.0 → 0.1.0

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 (85) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +21 -0
  3. package/dist/cache.d.ts +109 -0
  4. package/dist/cache.js +94 -0
  5. package/dist/consts.d.ts +37 -0
  6. package/dist/consts.js +35 -0
  7. package/dist/context.d.ts +208 -0
  8. package/dist/context.js +40 -0
  9. package/dist/errors.d.ts +9 -0
  10. package/dist/errors.js +6 -0
  11. package/dist/index.d.ts +1024 -0
  12. package/dist/index.js +24 -0
  13. package/dist/lib/diff.d.ts +39 -0
  14. package/dist/lib/diff.js +29 -0
  15. package/dist/lib/logger.d.ts +31 -0
  16. package/dist/lib/logger.js +131 -0
  17. package/dist/lib/pluginUtils.d.ts +222 -0
  18. package/dist/lib/pluginUtils.js +87 -0
  19. package/dist/lib/storage-manager.d.ts +10 -0
  20. package/dist/lib/storage-manager.js +17 -0
  21. package/dist/migrations/20251025T040912_init.d.ts +17 -0
  22. package/dist/migrations/20251025T040912_init.js +260 -0
  23. package/dist/migrations/20251130T150847_drop_deprecated.d.ts +13 -0
  24. package/dist/migrations/20251130T150847_drop_deprecated.js +262 -0
  25. package/dist/migrations/20251221T002125_url-mapping.d.ts +13 -0
  26. package/dist/migrations/20251221T002125_url-mapping.js +228 -0
  27. package/dist/migrator.d.ts +25 -0
  28. package/dist/migrator.js +21 -0
  29. package/dist/modules/auth/index.d.ts +419 -0
  30. package/dist/modules/auth/index.js +436 -0
  31. package/dist/modules/clear/index.d.ts +72 -0
  32. package/dist/modules/clear/index.js +52 -0
  33. package/dist/modules/config/consts.d.ts +32 -0
  34. package/dist/modules/config/consts.js +18 -0
  35. package/dist/modules/config/index.d.ts +100 -0
  36. package/dist/modules/config/index.js +224 -0
  37. package/dist/modules/config/templates/mailer.d.ts +36 -0
  38. package/dist/modules/config/templates/mailer.js +218 -0
  39. package/dist/modules/config/type-utils.d.ts +13 -0
  40. package/dist/modules/config/type-utils.js +11 -0
  41. package/dist/modules/delete/index.d.ts +141 -0
  42. package/dist/modules/delete/index.js +279 -0
  43. package/dist/modules/diffTracking/index.d.ts +188 -0
  44. package/dist/modules/diffTracking/index.js +277 -0
  45. package/dist/modules/get/index.d.ts +372 -0
  46. package/dist/modules/get/index.js +579 -0
  47. package/dist/modules/index.d.ts +883 -0
  48. package/dist/modules/index.js +37 -0
  49. package/dist/modules/init/index.d.ts +60 -0
  50. package/dist/modules/init/index.js +38 -0
  51. package/dist/modules/middleware/index.d.ts +56 -0
  52. package/dist/modules/middleware/index.js +50 -0
  53. package/dist/modules/notificationSettings/index.d.ts +57 -0
  54. package/dist/modules/notificationSettings/index.js +39 -0
  55. package/dist/modules/plugins/index.d.ts +167 -0
  56. package/dist/modules/plugins/index.js +272 -0
  57. package/dist/modules/post/index.d.ts +306 -0
  58. package/dist/modules/post/index.js +337 -0
  59. package/dist/modules/resetTokenBucket/index.d.ts +91 -0
  60. package/dist/modules/resetTokenBucket/index.js +96 -0
  61. package/dist/modules/rest_api/index.d.ts +92 -0
  62. package/dist/modules/rest_api/index.js +117 -0
  63. package/dist/modules/update/index.d.ts +184 -0
  64. package/dist/modules/update/index.js +192 -0
  65. package/dist/modules/util/collectors.d.ts +125 -0
  66. package/dist/modules/util/collectors.js +168 -0
  67. package/dist/modules/util/folderTree.d.ts +100 -0
  68. package/dist/modules/util/folderTree.js +176 -0
  69. package/dist/modules/util/generators.d.ts +83 -0
  70. package/dist/modules/util/generators.js +106 -0
  71. package/dist/modules/util/getFromNPM.d.ts +199 -0
  72. package/dist/modules/util/getFromNPM.js +106 -0
  73. package/dist/modules/util/index.d.ts +100 -0
  74. package/dist/modules/util/index.js +20 -0
  75. package/dist/modules/util/parsers.d.ts +60 -0
  76. package/dist/modules/util/parsers.js +43 -0
  77. package/dist/modules/util/slugify.d.ts +22 -0
  78. package/dist/modules/util/slugify.js +19 -0
  79. package/dist/modules/util/users.d.ts +99 -0
  80. package/dist/modules/util/users.js +78 -0
  81. package/dist/tables.d.ts +433 -0
  82. package/dist/tables.js +169 -0
  83. package/dist/types.d.ts +359 -0
  84. package/dist/types.js +10 -0
  85. package/package.json +67 -7
@@ -0,0 +1,141 @@
1
+ import { Effect } from '@withstudiocms/effect';
2
+ import CacheService from '../../cache.js';
3
+ import { DBClientLive, SDKDefaults } from '../../context.js';
4
+ /**
5
+ * SDKDeleteModule
6
+ *
7
+ * Effect generator that builds and returns the Delete API for the StudioCMS SDK.
8
+ *
9
+ * This module wires together low-level database delete operations, input validation
10
+ * (via encoders), cache clearing and higher-level helpers to provide a cohesive
11
+ * deletion surface for pages, page content, tags, categories, permissions, diff
12
+ * tracking, folders and users.
13
+ *
14
+ * Remarks
15
+ * - All low-level DB deletes are wrapped with a validation encoder (withEncoder)
16
+ * and execute the underlying query using executeTakeFirstOrThrow; absent rows
17
+ * will surface as errors which are handled by the module's error pipeline.
18
+ * - High-level helpers compose these low-level operations into meaningful flows:
19
+ * - Page deletion clears diff tracking, page content and page data, then clears relevant caches.
20
+ * - Folder deletion triggers subsequent updates to folder list and folder tree views.
21
+ * - User deletion clears user references and prevents deletion of the platform
22
+ * "ghost" (internal) user.
23
+ * - The module uses a shared error handler (_handleErrors) to normalize errors into
24
+ * DeletionResponse values where possible.
25
+ *
26
+ * Error handling
27
+ * - DB-level errors (not found / constraint failures) thrown by executeTakeFirstOrThrow
28
+ * are propagated into the module's error-handling pipeline and converted into
29
+ * DeletionResponse values by _handleErrors.
30
+ * - Ghost user protection surfaces a GhostUserError that is caught and turned into
31
+ * an appropriate DeletionResponse explaining that the internal user cannot be deleted.
32
+ * - Folder update failures are specially caught and returned with an explanatory message.
33
+ *
34
+ * Side effects
35
+ * - Cache/derived-data clearing routines are invoked where appropriate (e.g. page cache
36
+ * clearing after deleting page content).
37
+ * - Folder deletion triggers background updates to folder list and folder tree.
38
+ *
39
+ * Returns
40
+ * - An Effect that, when executed, yields an object containing the DELETE API
41
+ * described above. Each method itself is an Effect producing a DeletionResponse
42
+ * describing success or a mapped error.
43
+ *
44
+ * Example
45
+ * - const deleteModule = yield* SDKDeleteModule;
46
+ * - yield* deleteModule.page('page-id-123') // returns a DeletionResponse effect
47
+ */
48
+ export declare const SDKDeleteModule: Effect.Effect<{
49
+ /**
50
+ * Deletes a page by its ID.
51
+ *
52
+ * @param id - The ID of the page to delete.
53
+ * @returns An effect that resolves to a success or error message.
54
+ */
55
+ page: (id: string) => Effect.Effect<{
56
+ status: "success" | "error";
57
+ message: string;
58
+ }, never, never>;
59
+ /**
60
+ * Deletes page content by its ID.
61
+ *
62
+ * @param id - The ID of the page content to delete.
63
+ * @returns An effect that resolves to a success or error message.
64
+ */
65
+ pageContent: (id: string) => Effect.Effect<{
66
+ status: "success" | "error";
67
+ message: string;
68
+ }, never, never>;
69
+ /**
70
+ * Deletes page content for a specific language by its ID and language.
71
+ *
72
+ * @param id - The ID of the page content to delete.
73
+ * @param lang - The language of the page content to delete.
74
+ * @returns An effect that resolves to a success or error message.
75
+ */
76
+ pageContentLang: (id: string, lang: string) => Effect.Effect<{
77
+ status: "success" | "error";
78
+ message: string;
79
+ }, never, never>;
80
+ /**
81
+ * Deletes a tag by its ID.
82
+ *
83
+ * @param id - The ID of the tag to delete.
84
+ * @returns An effect that resolves to a success or error message.
85
+ */
86
+ tags: (id: number) => Effect.Effect<{
87
+ status: "success" | "error";
88
+ message: string;
89
+ }, never, never>;
90
+ /**
91
+ * Deletes a category by its ID.
92
+ *
93
+ * @param id - The ID of the category to delete.
94
+ * @returns An effect that resolves to a success or error message.
95
+ */
96
+ categories: (id: number) => Effect.Effect<{
97
+ status: "success" | "error";
98
+ message: string;
99
+ }, never, never>;
100
+ /**
101
+ * Deletes permissions for a specific user by their ID.
102
+ *
103
+ * @param userId - The ID of the user whose permissions to delete.
104
+ * @returns An effect that resolves to a success or error message.
105
+ */
106
+ permissions: (userId: string) => Effect.Effect<{
107
+ status: "success" | "error";
108
+ message: string;
109
+ }, never, never>;
110
+ /**
111
+ * Deletes diff tracking entry by diff ID.
112
+ *
113
+ * @param id - The ID of the diff tracking entry to be deleted.
114
+ * @returns An effect that represents the deletion operation.
115
+ */
116
+ diffTracking: (id: string) => Effect.Effect<{
117
+ status: "success" | "error";
118
+ message: string;
119
+ }, never, never>;
120
+ /**
121
+ * Deletes a folder by its ID.
122
+ *
123
+ * @param folderId - The ID of the folder to delete.
124
+ * @returns An effect that resolves to a success or error message.
125
+ */
126
+ folder: (folderId: string) => Effect.Effect<{
127
+ status: "success" | "error";
128
+ message: string;
129
+ }, never, never>;
130
+ /**
131
+ * Deletes a user by their ID.
132
+ *
133
+ * @param userId - The ID of the user to delete.
134
+ * @returns An effect that resolves to a success or error message.
135
+ */
136
+ user: (userId: string) => Effect.Effect<{
137
+ status: "success" | "error";
138
+ message: string;
139
+ }, never, never>;
140
+ }, never, DBClientLive | SDKDefaults | import("../../context.js").StorageManagerResolver | CacheService | import("@withstudiocms/effect").Deepmerge>;
141
+ export default SDKDeleteModule;
@@ -0,0 +1,279 @@
1
+ import { Effect, Schema } from "@withstudiocms/effect";
2
+ import CacheService from "../../cache.js";
3
+ import { cacheTags } from "../../consts.js";
4
+ import { DBClientLive, SDKDefaults } from "../../context.js";
5
+ import SDKClearModule from "../clear/index.js";
6
+ import SDKUpdateModule from "../update/index.js";
7
+ import { SDKUsers } from "../util/users.js";
8
+ class GhostUserError {
9
+ _tag = "GhostUserError";
10
+ }
11
+ const _handleErrors = Effect.catchTags({
12
+ DBCallbackFailure: (cause) => Effect.succeed({
13
+ status: "error",
14
+ message: cause.message
15
+ }),
16
+ NotFoundError: () => Effect.succeed({
17
+ status: "error",
18
+ message: "database entry not found"
19
+ }),
20
+ QueryError: (cause) => Effect.succeed({
21
+ status: "error",
22
+ message: cause.message
23
+ }),
24
+ QueryParseError: (cause) => Effect.succeed({
25
+ status: "error",
26
+ message: cause.message
27
+ })
28
+ });
29
+ const SDKDeleteModule = Effect.gen(function* () {
30
+ const [{ withEncoder }, clear, users, update, { GhostUserDefaults }, { invalidateTags }] = yield* Effect.all([
31
+ DBClientLive,
32
+ SDKClearModule,
33
+ SDKUsers,
34
+ SDKUpdateModule,
35
+ SDKDefaults,
36
+ CacheService
37
+ ]);
38
+ const _deleteDiffTrackingByPageId = withEncoder({
39
+ encoder: Schema.String,
40
+ callbackFn: (db, pageId) => db(
41
+ (client) => client.deleteFrom("StudioCMSDiffTracking").where("pageId", "=", pageId).executeTakeFirstOrThrow()
42
+ )
43
+ });
44
+ const _deleteDiffTrackingByDiffId = withEncoder({
45
+ encoder: Schema.String,
46
+ callbackFn: (db, diffId) => db(
47
+ (client) => client.deleteFrom("StudioCMSDiffTracking").where("id", "=", diffId).executeTakeFirstOrThrow()
48
+ )
49
+ });
50
+ const _deletePageContentByPageId = withEncoder({
51
+ encoder: Schema.String,
52
+ callbackFn: (db, pageId) => db(
53
+ (client) => client.deleteFrom("StudioCMSPageContent").where("contentId", "=", pageId).executeTakeFirstOrThrow()
54
+ )
55
+ });
56
+ const _deletePageDataById = withEncoder({
57
+ encoder: Schema.String,
58
+ callbackFn: (db, pageId) => db(
59
+ (client) => client.deleteFrom("StudioCMSPageData").where("id", "=", pageId).executeTakeFirstOrThrow()
60
+ )
61
+ });
62
+ const _deletePageContentLangByIdAndLang = withEncoder({
63
+ encoder: Schema.Struct({
64
+ id: Schema.String,
65
+ lang: Schema.String
66
+ }),
67
+ callbackFn: (db, { id, lang }) => db(
68
+ (client) => client.deleteFrom("StudioCMSPageContent").where((eb) => eb.and([eb("contentId", "=", id), eb("contentLang", "=", lang)])).executeTakeFirstOrThrow()
69
+ )
70
+ });
71
+ const _deleteTagsById = withEncoder({
72
+ encoder: Schema.Number,
73
+ callbackFn: (db, id) => db(
74
+ (client) => client.deleteFrom("StudioCMSPageDataTags").where("id", "=", id).executeTakeFirstOrThrow()
75
+ )
76
+ });
77
+ const _deleteCategoriesById = withEncoder({
78
+ encoder: Schema.Number,
79
+ callbackFn: (db, id) => db(
80
+ (client) => client.deleteFrom("StudioCMSPageDataCategories").where("id", "=", id).executeTakeFirstOrThrow()
81
+ )
82
+ });
83
+ const _deletePermissionDataByUserId = withEncoder({
84
+ encoder: Schema.String,
85
+ callbackFn: (db, userId) => db(
86
+ (client) => client.deleteFrom("StudioCMSPermissions").where("user", "=", userId).executeTakeFirstOrThrow()
87
+ )
88
+ });
89
+ const _deleteFolderById = withEncoder({
90
+ encoder: Schema.String,
91
+ callbackFn: (db, folderId) => db(
92
+ (client) => client.deleteFrom("StudioCMSPageFolderStructure").where("id", "=", folderId).executeTakeFirstOrThrow()
93
+ )
94
+ });
95
+ const _deleteUserById = withEncoder({
96
+ encoder: Schema.String,
97
+ callbackFn: (db, userId) => db(
98
+ (client) => client.deleteFrom("StudioCMSUsersTable").where("id", "=", userId).executeTakeFirstOrThrow()
99
+ )
100
+ });
101
+ const _deletePageById = Effect.fn(
102
+ (id) => _deleteDiffTrackingByPageId(id).pipe(
103
+ Effect.flatMap(() => _deletePageContentByPageId(id)),
104
+ Effect.flatMap(() => _deletePageDataById(id)),
105
+ Effect.flatMap(() => clear.page.byId(id)),
106
+ Effect.map(() => ({
107
+ status: "success",
108
+ message: `Page with ID ${id} has been deleted successfully`
109
+ })),
110
+ _handleErrors
111
+ )
112
+ );
113
+ const _deletePageContent = Effect.fn(
114
+ (id) => _deletePageContentByPageId(id).pipe(
115
+ Effect.flatMap(() => clear.page.byId(id)),
116
+ Effect.map(() => ({
117
+ status: "success",
118
+ message: `Page content with ID ${id} has been deleted successfully`
119
+ })),
120
+ _handleErrors
121
+ )
122
+ );
123
+ const _deletePageContentLang = Effect.fn(
124
+ (id, lang) => _deletePageContentLangByIdAndLang({ id, lang }).pipe(
125
+ Effect.flatMap(() => clear.page.byId(id)),
126
+ Effect.map(() => ({
127
+ status: "success",
128
+ message: `Page content with ID ${id} and language ${lang} has been deleted successfully`
129
+ })),
130
+ _handleErrors
131
+ )
132
+ );
133
+ const _deletePageTag = Effect.fn(
134
+ (id) => _deleteTagsById(id).pipe(
135
+ Effect.tap(() => invalidateTags(cacheTags.tags)),
136
+ Effect.map(() => ({
137
+ status: "success",
138
+ message: `Tag with ID ${id} has been deleted successfully`
139
+ })),
140
+ _handleErrors
141
+ )
142
+ );
143
+ const _deletePageCategory = Effect.fn(
144
+ (id) => _deleteCategoriesById(id).pipe(
145
+ Effect.tap(() => invalidateTags(cacheTags.categories)),
146
+ Effect.map(() => ({
147
+ status: "success",
148
+ message: `Category with ID ${id} has been deleted successfully`
149
+ })),
150
+ _handleErrors
151
+ )
152
+ );
153
+ const _deletePermission = Effect.fn(
154
+ (userId) => _deletePermissionDataByUserId(userId).pipe(
155
+ Effect.map(() => ({
156
+ status: "success",
157
+ message: `Permissions for user with ID ${userId} have been deleted successfully`
158
+ })),
159
+ _handleErrors
160
+ )
161
+ );
162
+ const _deleteDiffTracking = Effect.fn(
163
+ (id) => _deleteDiffTrackingByDiffId(id).pipe(
164
+ Effect.map(() => ({
165
+ status: "success",
166
+ message: `Diff tracking entry with ID ${id} has been deleted successfully`
167
+ })),
168
+ _handleErrors
169
+ )
170
+ );
171
+ const _deleteFolder = Effect.fn(
172
+ (folderId) => _deleteFolderById(folderId).pipe(
173
+ Effect.tap(() => Effect.all([update.folderList, update.folderTree])),
174
+ Effect.map(() => ({
175
+ status: "success",
176
+ message: `Folder with ID ${folderId} has been deleted successfully`
177
+ })),
178
+ Effect.catchTag(
179
+ "FolderTreeError",
180
+ (cause) => Effect.succeed({
181
+ status: "error",
182
+ message: `Failed to update folder tree after deleting folder with ID ${folderId}: ${cause.message}`
183
+ })
184
+ ),
185
+ _handleErrors
186
+ )
187
+ );
188
+ const _isNotGhostUser = (userId) => userId !== GhostUserDefaults.id ? Effect.fail(new GhostUserError()) : Effect.succeed(false);
189
+ const _deleteUser = Effect.fn(
190
+ (userId) => _isNotGhostUser(userId).pipe(
191
+ Effect.flatMap(() => users.clearUserReferences(userId)),
192
+ Effect.flatMap(() => _deleteUserById(userId)),
193
+ Effect.map(() => ({
194
+ status: "success",
195
+ message: `User with ID ${userId} has been deleted successfully`
196
+ })),
197
+ Effect.catchTag(
198
+ "GhostUserError",
199
+ () => Effect.succeed({
200
+ status: "error",
201
+ message: `User with ID ${userId} is an internal user and cannot be deleted.`
202
+ })
203
+ ),
204
+ _handleErrors
205
+ )
206
+ );
207
+ const DELETE = {
208
+ /**
209
+ * Deletes a page by its ID.
210
+ *
211
+ * @param id - The ID of the page to delete.
212
+ * @returns An effect that resolves to a success or error message.
213
+ */
214
+ page: _deletePageById,
215
+ /**
216
+ * Deletes page content by its ID.
217
+ *
218
+ * @param id - The ID of the page content to delete.
219
+ * @returns An effect that resolves to a success or error message.
220
+ */
221
+ pageContent: _deletePageContent,
222
+ /**
223
+ * Deletes page content for a specific language by its ID and language.
224
+ *
225
+ * @param id - The ID of the page content to delete.
226
+ * @param lang - The language of the page content to delete.
227
+ * @returns An effect that resolves to a success or error message.
228
+ */
229
+ pageContentLang: _deletePageContentLang,
230
+ /**
231
+ * Deletes a tag by its ID.
232
+ *
233
+ * @param id - The ID of the tag to delete.
234
+ * @returns An effect that resolves to a success or error message.
235
+ */
236
+ tags: _deletePageTag,
237
+ /**
238
+ * Deletes a category by its ID.
239
+ *
240
+ * @param id - The ID of the category to delete.
241
+ * @returns An effect that resolves to a success or error message.
242
+ */
243
+ categories: _deletePageCategory,
244
+ /**
245
+ * Deletes permissions for a specific user by their ID.
246
+ *
247
+ * @param userId - The ID of the user whose permissions to delete.
248
+ * @returns An effect that resolves to a success or error message.
249
+ */
250
+ permissions: _deletePermission,
251
+ /**
252
+ * Deletes diff tracking entry by diff ID.
253
+ *
254
+ * @param id - The ID of the diff tracking entry to be deleted.
255
+ * @returns An effect that represents the deletion operation.
256
+ */
257
+ diffTracking: _deleteDiffTracking,
258
+ /**
259
+ * Deletes a folder by its ID.
260
+ *
261
+ * @param folderId - The ID of the folder to delete.
262
+ * @returns An effect that resolves to a success or error message.
263
+ */
264
+ folder: _deleteFolder,
265
+ /**
266
+ * Deletes a user by their ID.
267
+ *
268
+ * @param userId - The ID of the user to delete.
269
+ * @returns An effect that resolves to a success or error message.
270
+ */
271
+ user: _deleteUser
272
+ };
273
+ return DELETE;
274
+ });
275
+ var delete_default = SDKDeleteModule;
276
+ export {
277
+ SDKDeleteModule,
278
+ delete_default as default
279
+ };
@@ -0,0 +1,188 @@
1
+ import { Effect } from '@withstudiocms/effect';
2
+ import { DBClientLive } from '../../context.js';
3
+ import type { diffReturn, tsPageDataSelect } from '../../types.js';
4
+ declare const DiffTrackingError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
5
+ readonly _tag: "DiffTrackingError";
6
+ } & Readonly<A>;
7
+ /**
8
+ * DiffTrackingError
9
+ *
10
+ * Represents an error specific to the Diff Tracking module.
11
+ *
12
+ * This error extends from `Data.TaggedError` with the tag `'DiffTrackingError'`
13
+ * and includes a `message` property to provide additional context about the issue.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * throw new DiffTrackingError({ message: 'Diff entry not found' });
18
+ * ```
19
+ *
20
+ * @property message - A descriptive message providing context about the error.
21
+ */
22
+ export declare class DiffTrackingError extends DiffTrackingError_base<{
23
+ message: string;
24
+ }> {
25
+ }
26
+ /**
27
+ * SDKDiffTrackingModule
28
+ *
29
+ * Effect-based module that provides diff-tracking persistence and utilities for StudioCMS pages.
30
+ *
31
+ * Overview
32
+ * - Exposes a diffTracking API for creating, querying, reverting and clearing page diffs.
33
+ * - Built on top of an Effect runtime and a database client layer with schema codecs/encoders.
34
+ * - Uses unified diffs (created via createTwoFilesPatch), persists them to the StudioCMSDiffTracking table,
35
+ * and post-processes records with a `fixDiff` parser to attach parsed metadata/structures.
36
+ *
37
+ * Public API (returned object)
38
+ * - insert(userId, pageId, data, diffLength): Effect
39
+ * Creates a unified diff between data.content.start and data.content.end, persists a new diff record,
40
+ * enforces a maximum number of diffs per page (diffLength) by removing oldest entries, and returns
41
+ * the stored diff record after parsing (via fixDiff).
42
+ *
43
+ * - clear(pageId): Effect
44
+ * Deletes all diff tracking records for the provided pageId.
45
+ *
46
+ * - get
47
+ * - byPageId.all(pageId): Effect
48
+ * Returns all diffs for the page (ordered by timestamp ascending) with parsed metadata.
49
+ * - byPageId.latest(pageId, count): Effect
50
+ * Returns the latest `count` diffs for the page (after parsing).
51
+ * - byUserId.all(userId): Effect
52
+ * Returns all diffs authored by the user with parsed metadata.
53
+ * - byUserId.latest(userId, count): Effect
54
+ * Returns the latest `count` diffs authored by the user.
55
+ * - single(diffId): Effect
56
+ * Returns a single diff by id with parsed metadata, or undefined if not found.
57
+ *
58
+ * - revertToDiff(id, type): Effect
59
+ * Reverts a page to the state represented by the diff with the given id. `type` controls what is reverted:
60
+ * 'content' | 'data' | 'both'.
61
+ * Behavior:
62
+ * - Validates that the diff entry exists; fails with DiffTrackingError if not found.
63
+ * - When reverting data, decodes/encodes page metadata with configured schemas and updates StudioCMSPageData.
64
+ * If required IDs are missing in metadata, fails with DiffTrackingError.
65
+ * - When reverting content, writes the saved pageContentStart back to StudioCMSPageContent.
66
+ * - Deletes all diffs that were created after the reverted diff to preserve a linear history.
67
+ * - Returns the reverted diff entry after parsing.
68
+ *
69
+ * - utils
70
+ * - getMetaDataDifferences(obj1, obj2): Effect
71
+ * Compares two metadata objects and returns an array of differences:
72
+ * { label: string, previous: unknown, current: unknown }.
73
+ * Ignores a small set of blacklisted fields (publishedAt, updatedAt, authorId, contributorIds),
74
+ * maps known metadata keys to friendly labels, and performs array-aware comparison to avoid
75
+ * spurious diffs for deeply-equal arrays.
76
+ * - getDiffHTML(diff: string): string
77
+ * Converts a unified diff string into an HTML representation for display.
78
+ *
79
+ * Implementation notes
80
+ * - Database interactions use withCodec/withEncoder wrappers to validate/encode inputs and decode outputs.
81
+ * - insert generates a new UUID for the diff id using crypto.randomUUID().
82
+ * - Query ordering for lists is ascending by timestamp; "latest" helpers slice results accordingly.
83
+ * - All public functions return Effect-based values; callers must run/interpret these via the project's Effect runtime.
84
+ *
85
+ * Error handling
86
+ * - Domain errors (e.g. missing diff entry or invalid metadata for revert) are signaled with DiffTrackingError.
87
+ * - Database errors and codec/schema errors are propagated as failures of the returned Effects.
88
+ *
89
+ * Concurrency and retention
90
+ * - insert enforces retention by deleting the oldest diffs when the per-page count would exceed diffLength.
91
+ * - revertToDiff prunes any diffs that occurred after the reverted entry to maintain a consistent history.
92
+ */
93
+ export declare const SDKDiffTrackingModule: Effect.Effect<{
94
+ /**
95
+ * Inserts a new diff tracking record into the database.
96
+ *
97
+ * @param userId - The ID of the user making the change.
98
+ * @param pageId - The ID of the page being changed.
99
+ * @param data - An object containing the start and end content and metadata.
100
+ * @param diffLength - The maximum number of diffs to retain for the page.
101
+ * @returns The inserted diff tracking record with parsed metadata.
102
+ */
103
+ insert: (userId: string, pageId: string, data: {
104
+ content: {
105
+ start: string;
106
+ end: string;
107
+ };
108
+ metaData: {
109
+ start: Partial<tsPageDataSelect>;
110
+ end: Partial<tsPageDataSelect>;
111
+ };
112
+ }, diffLength: number) => Effect.Effect<diffReturn, import("@withstudiocms/kysely/client").DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError | import("../util/parsers.js").ParsersError | import("../../lib/diff.js").DiffError, never>;
113
+ /**
114
+ * Clears all diff tracking records for a given page ID.
115
+ *
116
+ * @param pageId - The ID of the page to clear diff tracking records for.
117
+ * @returns The number of rows affected by the delete operation.
118
+ */
119
+ clear: (input: string) => Effect.Effect<import("kysely").DeleteResult[], import("@withstudiocms/kysely/client").DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError, never>;
120
+ /**
121
+ * Utility functions for retrieving diff tracking records.
122
+ */
123
+ get: {
124
+ /**
125
+ * Retrieves all diff tracking records for a given page ID.
126
+ */
127
+ byPageId: {
128
+ /**
129
+ * Retrieves all diff tracking records for a given page ID.
130
+ */
131
+ all: (pageId: string) => Effect.Effect<diffReturn[], import("@withstudiocms/kysely/client").DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError | import("../util/parsers.js").ParsersError, never>;
132
+ /**
133
+ * Retrieves the latest `count` diff tracking records for a given page ID.
134
+ */
135
+ latest: (pageId: string, count: number) => Effect.Effect<diffReturn[], import("@withstudiocms/kysely/client").DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError | import("../util/parsers.js").ParsersError, never>;
136
+ };
137
+ /**
138
+ * Retrieves all diff tracking records for a given user ID.
139
+ */
140
+ byUserId: {
141
+ /**
142
+ * Retrieves all diff tracking records for a given user ID.
143
+ */
144
+ all: (userId: string) => Effect.Effect<diffReturn[], import("@withstudiocms/kysely/client").DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError | import("../util/parsers.js").ParsersError, never>;
145
+ /**
146
+ * Retrieves the latest `count` diff tracking records for a given user ID.
147
+ */
148
+ latest: (userId: string, count: number) => Effect.Effect<diffReturn[], import("@withstudiocms/kysely/client").DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError | import("../util/parsers.js").ParsersError, never>;
149
+ };
150
+ /**
151
+ * Retrieves a single diff tracking record by its ID.
152
+ */
153
+ single: (diffId: string) => Effect.Effect<diffReturn | undefined, import("@withstudiocms/kysely/client").DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError | import("../util/parsers.js").ParsersError, never>;
154
+ };
155
+ /**
156
+ * Reverts the page data and/or content to the state represented by the specified diff ID.
157
+ *
158
+ * @param id - The ID of the diff tracking record to revert to.
159
+ * @param type - The type of revert operation: 'content', 'data', or 'both'.
160
+ * @returns The reverted diff tracking record with parsed metadata.
161
+ */
162
+ revertToDiff: (id: string, type: "content" | "data" | "both") => Effect.Effect<diffReturn, import("effect/ParseResult").ParseError | import("@withstudiocms/kysely/client").DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError | import("../util/parsers.js").ParsersError | DiffTrackingError, never>;
163
+ /**
164
+ * Utility functions for diff tracking.
165
+ */
166
+ utils: {
167
+ /**
168
+ * Compares two metadata objects and returns the differences.
169
+ *
170
+ * @param obj1 - The first metadata object to compare.
171
+ * @param obj2 - The second metadata object to compare.
172
+ * @returns An array of differences, each containing the label, previous value, and current value.
173
+ */
174
+ getMetaDataDifferences: <T extends Record<string, unknown>>(obj1: T, obj2: T) => Effect.Effect<{
175
+ label: string;
176
+ previous: unknown;
177
+ current: unknown;
178
+ }[], never, never>;
179
+ /**
180
+ * Generates the HTML representation of a unified diff string.
181
+ *
182
+ * @param diff - The unified diff string to convert to HTML.
183
+ * @returns The HTML representation of the diff.
184
+ */
185
+ getDiffHTML: (diff: string, options?: import("diff2html").Diff2HtmlConfig | undefined) => Effect.Effect<string, import("../../lib/diff.js").DiffError, never>;
186
+ };
187
+ }, never, DBClientLive>;
188
+ export default SDKDiffTrackingModule;