@withstudiocms/sdk 0.1.0-beta.1 → 0.1.1
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/consts.d.ts +10 -1
- package/dist/consts.js +12 -3
- package/dist/context.d.ts +36 -16
- package/dist/context.js +8 -1
- package/dist/errors.d.ts +9 -0
- package/dist/errors.js +6 -0
- package/dist/index.d.ts +341 -453
- package/dist/lib/pluginUtils.d.ts +4 -3
- package/dist/lib/pluginUtils.js +17 -10
- package/dist/lib/storage-manager.d.ts +10 -0
- package/dist/lib/storage-manager.js +17 -0
- package/dist/migrations/20251025T040912_init.d.ts +17 -0
- package/dist/migrations/20251025T040912_init.js +260 -0
- package/dist/migrations/20251130T150847_drop_deprecated.d.ts +13 -0
- package/dist/migrations/20251130T150847_drop_deprecated.js +262 -0
- package/dist/migrations/20251221T002125_url-mapping.d.ts +13 -0
- package/dist/migrations/20251221T002125_url-mapping.js +228 -0
- package/dist/migrator.d.ts +25 -0
- package/dist/migrator.js +21 -0
- package/dist/modules/auth/index.d.ts +60 -104
- package/dist/modules/auth/index.js +33 -9
- package/dist/modules/config/index.d.ts +5 -5
- package/dist/modules/config/index.js +26 -7
- package/dist/modules/delete/index.d.ts +2 -1
- package/dist/modules/delete/index.js +7 -2
- package/dist/modules/diffTracking/index.d.ts +8 -8
- package/dist/modules/diffTracking/index.js +7 -6
- package/dist/modules/get/index.d.ts +116 -16
- package/dist/modules/get/index.js +135 -22
- package/dist/modules/index.d.ts +326 -446
- package/dist/modules/init/index.d.ts +9 -9
- package/dist/modules/middleware/index.d.ts +2 -2
- package/dist/modules/notificationSettings/index.d.ts +3 -3
- package/dist/modules/plugins/index.d.ts +9 -8
- package/dist/modules/plugins/index.js +17 -6
- package/dist/modules/post/index.d.ts +29 -28
- package/dist/modules/post/index.js +47 -15
- package/dist/modules/resetTokenBucket/index.d.ts +1 -1
- package/dist/modules/resetTokenBucket/index.js +5 -2
- package/dist/modules/rest_api/index.d.ts +8 -8
- package/dist/modules/rest_api/index.js +7 -3
- package/dist/modules/update/index.d.ts +25 -25
- package/dist/modules/update/index.js +28 -10
- package/dist/modules/util/collectors.d.ts +14 -150
- package/dist/modules/util/collectors.js +41 -14
- package/dist/modules/util/folderTree.d.ts +4 -4
- package/dist/modules/util/folderTree.js +1 -1
- package/dist/modules/util/getFromNPM.d.ts +13 -5
- package/dist/modules/util/getFromNPM.js +8 -2
- package/dist/modules/util/index.d.ts +30 -166
- package/dist/modules/util/users.d.ts +7 -7
- package/dist/tables.d.ts +433 -0
- package/dist/tables.js +169 -0
- package/dist/types.d.ts +6 -7
- package/package.json +17 -5
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Effect, Schema } from "@withstudiocms/effect";
|
|
2
|
+
import { DBClientLive, SDKDefaults } from "../../context.js";
|
|
2
3
|
import {
|
|
3
4
|
StudioCMSEmailVerificationTokens,
|
|
4
5
|
StudioCMSOAuthAccounts,
|
|
5
6
|
StudioCMSPermissions,
|
|
6
7
|
StudioCMSSessionTable,
|
|
7
8
|
StudioCMSUsersTable
|
|
8
|
-
} from "
|
|
9
|
-
import { DBClientLive, SDKDefaults } from "../../context.js";
|
|
9
|
+
} from "../../tables.js";
|
|
10
10
|
import {
|
|
11
11
|
AuthErrorTagsEntries
|
|
12
12
|
} from "../../types.js";
|
|
@@ -34,14 +34,22 @@ const SDKAuthModule = Effect.gen(function* () {
|
|
|
34
34
|
encoder: StudioCMSEmailVerificationTokens.Insert,
|
|
35
35
|
decoder: StudioCMSEmailVerificationTokens.Select,
|
|
36
36
|
callbackFn: (db, data) => db(
|
|
37
|
-
(client) => client.
|
|
37
|
+
(client) => client.transaction().execute(async (trx) => {
|
|
38
|
+
await trx.insertInto("StudioCMSEmailVerificationTokens").values(data).executeTakeFirstOrThrow();
|
|
39
|
+
return await trx.selectFrom("StudioCMSEmailVerificationTokens").selectAll().where("id", "=", data.id).executeTakeFirstOrThrow();
|
|
40
|
+
})
|
|
38
41
|
)
|
|
39
42
|
});
|
|
40
43
|
const _createNewOAuthAccount = withCodec({
|
|
41
44
|
encoder: StudioCMSOAuthAccounts.Insert,
|
|
42
45
|
decoder: StudioCMSOAuthAccounts.Select,
|
|
43
46
|
callbackFn: (db, data) => db(
|
|
44
|
-
(client) => client.
|
|
47
|
+
(client) => client.transaction().execute(async (trx) => {
|
|
48
|
+
await trx.insertInto("StudioCMSOAuthAccounts").values(data).executeTakeFirstOrThrow();
|
|
49
|
+
return await trx.selectFrom("StudioCMSOAuthAccounts").selectAll().where(
|
|
50
|
+
(eb) => eb.and([eb("userId", "=", data.userId), eb("provider", "=", data.provider)])
|
|
51
|
+
).executeTakeFirstOrThrow();
|
|
52
|
+
})
|
|
45
53
|
)
|
|
46
54
|
});
|
|
47
55
|
const _deleteOAuthUserAccount = withEncoder({
|
|
@@ -86,7 +94,10 @@ const SDKAuthModule = Effect.gen(function* () {
|
|
|
86
94
|
encoder: StudioCMSSessionTable.Insert,
|
|
87
95
|
decoder: StudioCMSSessionTable.Select,
|
|
88
96
|
callbackFn: (db, data) => db(
|
|
89
|
-
(client) => client.
|
|
97
|
+
(client) => client.transaction().execute(async (trx) => {
|
|
98
|
+
await trx.insertInto("StudioCMSSessionTable").values(data).executeTakeFirstOrThrow();
|
|
99
|
+
return await trx.selectFrom("StudioCMSSessionTable").selectAll().where("id", "=", data.id).executeTakeFirstOrThrow();
|
|
100
|
+
})
|
|
90
101
|
)
|
|
91
102
|
});
|
|
92
103
|
const _getUserById = withCodec({
|
|
@@ -116,21 +127,30 @@ const SDKAuthModule = Effect.gen(function* () {
|
|
|
116
127
|
}),
|
|
117
128
|
decoder: StudioCMSSessionTable.Select,
|
|
118
129
|
callbackFn: (db, { id, newDate }) => db(
|
|
119
|
-
(client) => client.
|
|
130
|
+
(client) => client.transaction().execute(async (trx) => {
|
|
131
|
+
await trx.updateTable("StudioCMSSessionTable").set({ expiresAt: newDate }).where("id", "=", id).executeTakeFirstOrThrow();
|
|
132
|
+
return await trx.selectFrom("StudioCMSSessionTable").selectAll().where("id", "=", id).executeTakeFirstOrThrow();
|
|
133
|
+
})
|
|
120
134
|
)
|
|
121
135
|
});
|
|
122
136
|
const _createNewUser = withCodec({
|
|
123
137
|
encoder: StudioCMSUsersTable.Insert,
|
|
124
138
|
decoder: StudioCMSUsersTable.Select,
|
|
125
139
|
callbackFn: (db, data) => db(
|
|
126
|
-
(client) => client.
|
|
140
|
+
(client) => client.transaction().execute(async (trx) => {
|
|
141
|
+
await trx.insertInto("StudioCMSUsersTable").values(data).executeTakeFirstOrThrow();
|
|
142
|
+
return await trx.selectFrom("StudioCMSUsersTable").selectAll().where("id", "=", data.id).executeTakeFirstOrThrow();
|
|
143
|
+
})
|
|
127
144
|
)
|
|
128
145
|
});
|
|
129
146
|
const _createUserPermission = withCodec({
|
|
130
147
|
encoder: StudioCMSPermissions.Insert,
|
|
131
148
|
decoder: StudioCMSPermissions.Select,
|
|
132
149
|
callbackFn: (db, data) => db(
|
|
133
|
-
(client) => client.
|
|
150
|
+
(client) => client.transaction().execute(async (trx) => {
|
|
151
|
+
await trx.insertInto("StudioCMSPermissions").values(data).executeTakeFirstOrThrow();
|
|
152
|
+
return await trx.selectFrom("StudioCMSPermissions").selectAll().where("user", "=", data.user).executeTakeFirstOrThrow();
|
|
153
|
+
})
|
|
134
154
|
)
|
|
135
155
|
});
|
|
136
156
|
const _updateUserData = withCodec({
|
|
@@ -140,7 +160,10 @@ const SDKAuthModule = Effect.gen(function* () {
|
|
|
140
160
|
}),
|
|
141
161
|
decoder: StudioCMSUsersTable.Select,
|
|
142
162
|
callbackFn: (db, { userId, userData }) => db(
|
|
143
|
-
(client) => client.
|
|
163
|
+
(client) => client.transaction().execute(async (trx) => {
|
|
164
|
+
await trx.updateTable("StudioCMSUsersTable").set(userData).where("id", "=", userId).executeTakeFirstOrThrow();
|
|
165
|
+
return await trx.selectFrom("StudioCMSUsersTable").selectAll().where("id", "=", userId).executeTakeFirstOrThrow();
|
|
166
|
+
})
|
|
144
167
|
)
|
|
145
168
|
});
|
|
146
169
|
const _searchForUsername = withCodec({
|
|
@@ -213,6 +236,7 @@ const SDKAuthModule = Effect.gen(function* () {
|
|
|
213
236
|
(user2) => user2 ? Effect.succeed(user2) : _createNewUser({
|
|
214
237
|
...GhostUserDefaults,
|
|
215
238
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
239
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
216
240
|
emailVerified: false
|
|
217
241
|
})
|
|
218
242
|
)
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Deepmerge, Effect } from '@withstudiocms/effect';
|
|
2
|
-
import type { DBCallbackFailure } from '@withstudiocms/kysely';
|
|
2
|
+
import type { DBCallbackFailure } from '@withstudiocms/kysely/client';
|
|
3
3
|
import type { DatabaseError } from '@withstudiocms/kysely/core/errors';
|
|
4
4
|
import { CacheService } from '../../cache.js';
|
|
5
|
-
import { DBClientLive } from '../../context.js';
|
|
5
|
+
import { DBClientLive, StorageManagerResolver } from '../../context.js';
|
|
6
6
|
import type { ConfigFinal, DynamicConfigEntry, StudioCMSMailerConfig, StudioCMSNotificationSettings, StudioCMSSiteConfig, StudioCMSTemplateConfig } from '../../types.js';
|
|
7
7
|
/**
|
|
8
8
|
* StudioCMS Configuration Modules
|
|
@@ -14,7 +14,7 @@ export declare const SDKConfigModule: Effect.Effect<{
|
|
|
14
14
|
*
|
|
15
15
|
* @returns An effect that yields the site configuration entry or undefined if not found, or a database error.
|
|
16
16
|
*/
|
|
17
|
-
get: () => Effect.Effect<DynamicConfigEntry<
|
|
17
|
+
get: <T extends StudioCMSSiteConfig>() => Effect.Effect<DynamicConfigEntry<T> | undefined, import("effect/Cause").UnknownException | DBCallbackFailure | DatabaseError, never>;
|
|
18
18
|
/**
|
|
19
19
|
* Updates the site configuration.
|
|
20
20
|
*
|
|
@@ -87,7 +87,7 @@ export declare const SDKConfigModule: Effect.Effect<{
|
|
|
87
87
|
* @param data - The new template configuration data to merge and store.
|
|
88
88
|
* @returns An effect that yields the updated template configuration entry or a database error.
|
|
89
89
|
*/
|
|
90
|
-
update: (data: ConfigFinal<StudioCMSTemplateConfig>) => Effect.Effect<DynamicConfigEntry<StudioCMSTemplateConfig>,
|
|
90
|
+
update: (data: ConfigFinal<StudioCMSTemplateConfig>) => Effect.Effect<DynamicConfigEntry<StudioCMSTemplateConfig>, DBCallbackFailure | DatabaseError | import("@withstudiocms/effect").DeepmergeError, never>;
|
|
91
91
|
/**
|
|
92
92
|
* Initializes the template configuration.
|
|
93
93
|
*
|
|
@@ -96,5 +96,5 @@ export declare const SDKConfigModule: Effect.Effect<{
|
|
|
96
96
|
*/
|
|
97
97
|
init: (data: ConfigFinal<StudioCMSTemplateConfig>) => Effect.Effect<DynamicConfigEntry<StudioCMSTemplateConfig>, DBCallbackFailure | DatabaseError, never>;
|
|
98
98
|
};
|
|
99
|
-
}, never, DBClientLive | CacheService | Deepmerge>;
|
|
99
|
+
}, never, DBClientLive | StorageManagerResolver | CacheService | Deepmerge>;
|
|
100
100
|
export default SDKConfigModule;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Deepmerge, Effect, Schema } from "@withstudiocms/effect";
|
|
2
|
-
import { StudioCMSDynamicConfigSettings } from "@withstudiocms/kysely/tables";
|
|
3
2
|
import { CacheMissError, CacheService } from "../../cache.js";
|
|
4
3
|
import { cacheKeyGetters, cacheTags } from "../../consts.js";
|
|
5
|
-
import { DBClientLive } from "../../context.js";
|
|
4
|
+
import { DBClientLive, StorageManagerResolver } from "../../context.js";
|
|
5
|
+
import { resolveStorageManagerUrls } from "../../lib/storage-manager.js";
|
|
6
|
+
import { StudioCMSDynamicConfigSettings } from "../../tables.js";
|
|
6
7
|
import {
|
|
7
8
|
MailerConfigId,
|
|
8
9
|
MailerConfigVersion,
|
|
@@ -18,16 +19,27 @@ import { castData } from "./type-utils.js";
|
|
|
18
19
|
const cacheKey = cacheKeyGetters.dynamicConfig;
|
|
19
20
|
const cacheOpts = { tags: cacheTags.dynamicConfig };
|
|
20
21
|
const SDKConfigModule = Effect.gen(function* () {
|
|
21
|
-
const [{ withCodec }, { merge }, cache] = yield* Effect.all([
|
|
22
|
+
const [{ withCodec }, { merge }, cache, smResolver] = yield* Effect.all([
|
|
22
23
|
DBClientLive,
|
|
23
24
|
Deepmerge,
|
|
24
|
-
CacheService
|
|
25
|
+
CacheService,
|
|
26
|
+
StorageManagerResolver
|
|
25
27
|
]);
|
|
28
|
+
const resolveUrls = resolveStorageManagerUrls(smResolver);
|
|
29
|
+
const resolveStorageManagerUrl = (attributes) => (obj) => resolveUrls(obj?.data, attributes).pipe(
|
|
30
|
+
Effect.map((data) => {
|
|
31
|
+
if (!data) return obj;
|
|
32
|
+
return { ...obj, data };
|
|
33
|
+
})
|
|
34
|
+
);
|
|
26
35
|
const _insert = withCodec({
|
|
27
36
|
decoder: StudioCMSDynamicConfigSettings.Select,
|
|
28
37
|
encoder: StudioCMSDynamicConfigSettings.Insert,
|
|
29
38
|
callbackFn: (db, data) => db(
|
|
30
|
-
(client) => client.
|
|
39
|
+
(client) => client.transaction().execute(async (trx) => {
|
|
40
|
+
await trx.insertInto("StudioCMSDynamicConfigSettings").values(data).executeTakeFirstOrThrow();
|
|
41
|
+
return await trx.selectFrom("StudioCMSDynamicConfigSettings").selectAll().where("id", "=", data.id).executeTakeFirstOrThrow();
|
|
42
|
+
})
|
|
31
43
|
)
|
|
32
44
|
});
|
|
33
45
|
const _select = withCodec({
|
|
@@ -41,7 +53,10 @@ const SDKConfigModule = Effect.gen(function* () {
|
|
|
41
53
|
decoder: StudioCMSDynamicConfigSettings.Select,
|
|
42
54
|
encoder: StudioCMSDynamicConfigSettings.Update,
|
|
43
55
|
callbackFn: (db, { id, data }) => db(
|
|
44
|
-
(client) => client.
|
|
56
|
+
(client) => client.transaction().execute(async (trx) => {
|
|
57
|
+
await trx.updateTable("StudioCMSDynamicConfigSettings").set({ data }).where("id", "=", id).executeTakeFirstOrThrow();
|
|
58
|
+
return await trx.selectFrom("StudioCMSDynamicConfigSettings").selectAll().where("id", "=", id).executeTakeFirstOrThrow();
|
|
59
|
+
})
|
|
45
60
|
)
|
|
46
61
|
});
|
|
47
62
|
const _tappedCacheUpdate = (fn) => Effect.fn(
|
|
@@ -74,7 +89,11 @@ const SDKConfigModule = Effect.gen(function* () {
|
|
|
74
89
|
*
|
|
75
90
|
* @returns An effect that yields the site configuration entry or undefined if not found, or a database error.
|
|
76
91
|
*/
|
|
77
|
-
get: () => get(SiteConfigId)
|
|
92
|
+
get: () => get(SiteConfigId).pipe(
|
|
93
|
+
Effect.flatMap(
|
|
94
|
+
resolveStorageManagerUrl(["siteIcon", "defaultOgImage", "loginPageCustomImage"])
|
|
95
|
+
)
|
|
96
|
+
),
|
|
78
97
|
/**
|
|
79
98
|
* Updates the site configuration.
|
|
80
99
|
*
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Effect } from '@withstudiocms/effect';
|
|
2
|
+
import CacheService from '../../cache.js';
|
|
2
3
|
import { DBClientLive, SDKDefaults } from '../../context.js';
|
|
3
4
|
/**
|
|
4
5
|
* SDKDeleteModule
|
|
@@ -136,5 +137,5 @@ export declare const SDKDeleteModule: Effect.Effect<{
|
|
|
136
137
|
status: "success" | "error";
|
|
137
138
|
message: string;
|
|
138
139
|
}, never, never>;
|
|
139
|
-
}, never, DBClientLive | SDKDefaults | import("../../
|
|
140
|
+
}, never, DBClientLive | SDKDefaults | import("../../context.js").StorageManagerResolver | CacheService | import("@withstudiocms/effect").Deepmerge>;
|
|
140
141
|
export default SDKDeleteModule;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { Effect, Schema } from "@withstudiocms/effect";
|
|
2
|
+
import CacheService from "../../cache.js";
|
|
3
|
+
import { cacheTags } from "../../consts.js";
|
|
2
4
|
import { DBClientLive, SDKDefaults } from "../../context.js";
|
|
3
5
|
import SDKClearModule from "../clear/index.js";
|
|
4
6
|
import SDKUpdateModule from "../update/index.js";
|
|
@@ -25,12 +27,13 @@ const _handleErrors = Effect.catchTags({
|
|
|
25
27
|
})
|
|
26
28
|
});
|
|
27
29
|
const SDKDeleteModule = Effect.gen(function* () {
|
|
28
|
-
const [{ withEncoder }, clear, users, update, { GhostUserDefaults }] = yield* Effect.all([
|
|
30
|
+
const [{ withEncoder }, clear, users, update, { GhostUserDefaults }, { invalidateTags }] = yield* Effect.all([
|
|
29
31
|
DBClientLive,
|
|
30
32
|
SDKClearModule,
|
|
31
33
|
SDKUsers,
|
|
32
34
|
SDKUpdateModule,
|
|
33
|
-
SDKDefaults
|
|
35
|
+
SDKDefaults,
|
|
36
|
+
CacheService
|
|
34
37
|
]);
|
|
35
38
|
const _deleteDiffTrackingByPageId = withEncoder({
|
|
36
39
|
encoder: Schema.String,
|
|
@@ -129,6 +132,7 @@ const SDKDeleteModule = Effect.gen(function* () {
|
|
|
129
132
|
);
|
|
130
133
|
const _deletePageTag = Effect.fn(
|
|
131
134
|
(id) => _deleteTagsById(id).pipe(
|
|
135
|
+
Effect.tap(() => invalidateTags(cacheTags.tags)),
|
|
132
136
|
Effect.map(() => ({
|
|
133
137
|
status: "success",
|
|
134
138
|
message: `Tag with ID ${id} has been deleted successfully`
|
|
@@ -138,6 +142,7 @@ const SDKDeleteModule = Effect.gen(function* () {
|
|
|
138
142
|
);
|
|
139
143
|
const _deletePageCategory = Effect.fn(
|
|
140
144
|
(id) => _deleteCategoriesById(id).pipe(
|
|
145
|
+
Effect.tap(() => invalidateTags(cacheTags.categories)),
|
|
141
146
|
Effect.map(() => ({
|
|
142
147
|
status: "success",
|
|
143
148
|
message: `Category with ID ${id} has been deleted successfully`
|
|
@@ -109,14 +109,14 @@ export declare const SDKDiffTrackingModule: Effect.Effect<{
|
|
|
109
109
|
start: Partial<tsPageDataSelect>;
|
|
110
110
|
end: Partial<tsPageDataSelect>;
|
|
111
111
|
};
|
|
112
|
-
}, diffLength: number) => Effect.Effect<diffReturn, import("@withstudiocms/kysely").DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError | import("../util/parsers.js").ParsersError | import("../../lib/diff.js").DiffError, never>;
|
|
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
113
|
/**
|
|
114
114
|
* Clears all diff tracking records for a given page ID.
|
|
115
115
|
*
|
|
116
116
|
* @param pageId - The ID of the page to clear diff tracking records for.
|
|
117
117
|
* @returns The number of rows affected by the delete operation.
|
|
118
118
|
*/
|
|
119
|
-
clear: (input: string) => Effect.Effect<import("kysely").DeleteResult[], import("@withstudiocms/kysely").DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError, never>;
|
|
119
|
+
clear: (input: string) => Effect.Effect<import("kysely").DeleteResult[], import("@withstudiocms/kysely/client").DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError, never>;
|
|
120
120
|
/**
|
|
121
121
|
* Utility functions for retrieving diff tracking records.
|
|
122
122
|
*/
|
|
@@ -128,11 +128,11 @@ export declare const SDKDiffTrackingModule: Effect.Effect<{
|
|
|
128
128
|
/**
|
|
129
129
|
* Retrieves all diff tracking records for a given page ID.
|
|
130
130
|
*/
|
|
131
|
-
all: (pageId: string) => Effect.Effect<diffReturn[], import("@withstudiocms/kysely").DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError | import("../util/parsers.js").ParsersError, never>;
|
|
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
132
|
/**
|
|
133
133
|
* Retrieves the latest `count` diff tracking records for a given page ID.
|
|
134
134
|
*/
|
|
135
|
-
latest: (pageId: string, count: number) => Effect.Effect<diffReturn[], import("@withstudiocms/kysely").DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError | import("../util/parsers.js").ParsersError, never>;
|
|
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
136
|
};
|
|
137
137
|
/**
|
|
138
138
|
* Retrieves all diff tracking records for a given user ID.
|
|
@@ -141,16 +141,16 @@ export declare const SDKDiffTrackingModule: Effect.Effect<{
|
|
|
141
141
|
/**
|
|
142
142
|
* Retrieves all diff tracking records for a given user ID.
|
|
143
143
|
*/
|
|
144
|
-
all: (userId: string) => Effect.Effect<diffReturn[], import("@withstudiocms/kysely").DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError | import("../util/parsers.js").ParsersError, never>;
|
|
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
145
|
/**
|
|
146
146
|
* Retrieves the latest `count` diff tracking records for a given user ID.
|
|
147
147
|
*/
|
|
148
|
-
latest: (userId: string, count: number) => Effect.Effect<diffReturn[], import("@withstudiocms/kysely").DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError | import("../util/parsers.js").ParsersError, never>;
|
|
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
149
|
};
|
|
150
150
|
/**
|
|
151
151
|
* Retrieves a single diff tracking record by its ID.
|
|
152
152
|
*/
|
|
153
|
-
single: (diffId: string) => Effect.Effect<diffReturn | undefined, import("@withstudiocms/kysely").DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError | import("../util/parsers.js").ParsersError, never>;
|
|
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
154
|
};
|
|
155
155
|
/**
|
|
156
156
|
* Reverts the page data and/or content to the state represented by the specified diff ID.
|
|
@@ -159,7 +159,7 @@ export declare const SDKDiffTrackingModule: Effect.Effect<{
|
|
|
159
159
|
* @param type - The type of revert operation: 'content', 'data', or 'both'.
|
|
160
160
|
* @returns The reverted diff tracking record with parsed metadata.
|
|
161
161
|
*/
|
|
162
|
-
revertToDiff: (id: string, type: "
|
|
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
163
|
/**
|
|
164
164
|
* Utility functions for diff tracking.
|
|
165
165
|
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Data, Effect, Schema } from "@withstudiocms/effect";
|
|
2
|
-
import { StudioCMSDiffTracking, StudioCMSPageData } from "@withstudiocms/kysely";
|
|
3
2
|
import { DBClientLive } from "../../context.js";
|
|
4
3
|
import { createTwoFilesPatch, diffHTML } from "../../lib/diff.js";
|
|
4
|
+
import { StudioCMSDiffTracking, StudioCMSPageData } from "../../tables.js";
|
|
5
5
|
import { SDKParsers } from "../util/parsers.js";
|
|
6
6
|
class DiffTrackingError extends Data.TaggedError("DiffTrackingError") {
|
|
7
7
|
}
|
|
@@ -36,7 +36,10 @@ const SDKDiffTrackingModule = Effect.gen(function* () {
|
|
|
36
36
|
encoder: StudioCMSDiffTracking.Insert,
|
|
37
37
|
decoder: StudioCMSDiffTracking.Select,
|
|
38
38
|
callbackFn: (db, diff) => db(
|
|
39
|
-
(client) => client.
|
|
39
|
+
(client) => client.transaction().execute(async (trx) => {
|
|
40
|
+
await trx.insertInto("StudioCMSDiffTracking").values(diff).executeTakeFirstOrThrow();
|
|
41
|
+
return await trx.selectFrom("StudioCMSDiffTracking").selectAll().where("id", "=", diff.id).executeTakeFirstOrThrow();
|
|
42
|
+
})
|
|
40
43
|
)
|
|
41
44
|
});
|
|
42
45
|
const clearPageDiffs = withEncoder({
|
|
@@ -111,16 +114,14 @@ const SDKDiffTrackingModule = Effect.gen(function* () {
|
|
|
111
114
|
const _revertToDiff = Effect.fn(function* (id, type) {
|
|
112
115
|
const diffEntry = yield* _selectDiffById(id);
|
|
113
116
|
if (!diffEntry) {
|
|
114
|
-
return yield*
|
|
117
|
+
return yield* new DiffTrackingError({ message: "Diff entry not found" });
|
|
115
118
|
}
|
|
116
119
|
const shouldRevertData = type === "data" || type === "both";
|
|
117
120
|
const shouldRevertContent = type === "content" || type === "both";
|
|
118
121
|
if (shouldRevertData) {
|
|
119
122
|
const pageData = diffEntry.pageMetaData;
|
|
120
123
|
if (!pageData.end.id || !pageData.start.id) {
|
|
121
|
-
return yield*
|
|
122
|
-
new DiffTrackingError({ message: "Invalid page metadata for revert" })
|
|
123
|
-
);
|
|
124
|
+
return yield* new DiffTrackingError({ message: "Invalid page metadata for revert" });
|
|
124
125
|
}
|
|
125
126
|
yield* Schema.encode(StudioCMSPageData.Select)(pageData.start).pipe(
|
|
126
127
|
Effect.flatMap(Schema.decode(StudioCMSPageData.Update)),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Effect, type ParseResult } from '@withstudiocms/effect';
|
|
2
|
-
import {
|
|
2
|
+
import type { DBCallbackFailure } from '@withstudiocms/kysely/client';
|
|
3
3
|
import type { DatabaseError } from '@withstudiocms/kysely/core/errors';
|
|
4
4
|
import CacheService from '../../cache.js';
|
|
5
5
|
import { DBClientLive, SDKDefaults } from '../../context.js';
|
|
@@ -70,10 +70,9 @@ export declare class KillSwitch {
|
|
|
70
70
|
* - GET.latestVersion()
|
|
71
71
|
* - Fetches the latest published version of StudioCMS from NPM.
|
|
72
72
|
*
|
|
73
|
-
* - GET.pages(includeDrafts?,
|
|
73
|
+
* - GET.pages(includeDrafts?, metaOnly?, paginate?)
|
|
74
74
|
* - Returns all pages (optionally paginated) and supports:
|
|
75
75
|
* - includeDrafts: include drafts when true.
|
|
76
|
-
* - hideDefaultIndex: exclude pages with slug "index" when true.
|
|
77
76
|
* - metaOnly: when true returns meta-only representations (no defaultContent / multiLangContent).
|
|
78
77
|
* - Validates pagination inputs (non-negative; default limit fallback).
|
|
79
78
|
* - Uses memoized per-page collectors and returns either CombinedPageData[] or MetaOnlyPageData[].
|
|
@@ -91,13 +90,14 @@ export declare class KillSwitch {
|
|
|
91
90
|
* - GET.packagePages(packageName, metaOnly?)
|
|
92
91
|
* - Returns pages associated with a package. If none found, returns an empty array.
|
|
93
92
|
*
|
|
94
|
-
* - GET.folderPages(idOrName, includeDrafts?,
|
|
93
|
+
* - GET.folderPages(idOrName, includeDrafts?, metaOnly?, paginate?)
|
|
95
94
|
* - Returns pages that belong to the given folder (identified by id or name).
|
|
96
95
|
* - Supports same filtering, metaOnly and pagination semantics as GET.pages.
|
|
97
96
|
*
|
|
98
|
-
* - GET.pageFolderTree(
|
|
97
|
+
* - GET.pageFolderTree(excludeDrafts?)
|
|
99
98
|
* - Returns a full folder tree structure enriched with pages placed into their folders.
|
|
100
99
|
* - Built by merging folder definitions and page data, memoized for efficiency.
|
|
100
|
+
* - Supports excluding draft pages when `excludeDrafts` is true.
|
|
101
101
|
*
|
|
102
102
|
* Implementation notes
|
|
103
103
|
* - Internal helpers:
|
|
@@ -117,7 +117,6 @@ export declare class KillSwitch {
|
|
|
117
117
|
* Example usage (conceptual)
|
|
118
118
|
* - GET.users.all() -> Effect yielding collected user list
|
|
119
119
|
* - GET.page.byId("abc") -> Effect yielding CombinedPageData | undefined
|
|
120
|
-
* - GET.pages(undefined, true) -> Effect yielding page list with default-index hidden
|
|
121
120
|
*
|
|
122
121
|
* Returns
|
|
123
122
|
* - An object (`GET`) with the described grouped read-only operations; each operation is an Effect-producing function.
|
|
@@ -177,9 +176,9 @@ export declare const SDKGetModule: Effect.Effect<{
|
|
|
177
176
|
* @returns The folder record if found, otherwise undefined.
|
|
178
177
|
*/
|
|
179
178
|
folder: (folderId: string) => Effect.Effect<{
|
|
180
|
-
readonly name: string;
|
|
181
179
|
readonly id: string;
|
|
182
|
-
readonly
|
|
180
|
+
readonly name: string;
|
|
181
|
+
readonly parent?: string | null | undefined;
|
|
183
182
|
} | undefined, DBCallbackFailure | DatabaseError, never>;
|
|
184
183
|
/**
|
|
185
184
|
* Retrieves the folder tree structure.
|
|
@@ -198,7 +197,7 @@ export declare const SDKGetModule: Effect.Effect<{
|
|
|
198
197
|
*
|
|
199
198
|
* @returns The site configuration object.
|
|
200
199
|
*/
|
|
201
|
-
siteConfig: () => Effect.Effect<import("../../types.js").DynamicConfigEntry<import("
|
|
200
|
+
siteConfig: <T extends import("../../types.js").StudioCMSSiteConfig>() => Effect.Effect<import("../../types.js").DynamicConfigEntry<T> | undefined, import("effect/Cause").UnknownException | DBCallbackFailure | DatabaseError, never>;
|
|
202
201
|
/**
|
|
203
202
|
* Retrieves the latest version of StudioCMS from NPM.
|
|
204
203
|
*
|
|
@@ -207,15 +206,15 @@ export declare const SDKGetModule: Effect.Effect<{
|
|
|
207
206
|
latestVersion: () => Effect.Effect<{
|
|
208
207
|
version: string;
|
|
209
208
|
lastCacheUpdate: Date;
|
|
210
|
-
}, import("effect/Cause").UnknownException |
|
|
209
|
+
}, import("effect/Cause").UnknownException | ParseResult.ParseError | import("../util/getFromNPM.js").GetFromNPMError, never>;
|
|
211
210
|
/**
|
|
212
211
|
* Retrieves all pages.
|
|
213
212
|
*
|
|
214
213
|
* @returns An array of page data records.
|
|
215
214
|
*/
|
|
216
215
|
pages: {
|
|
217
|
-
(includeDrafts?: boolean,
|
|
218
|
-
(includeDrafts?: boolean,
|
|
216
|
+
(includeDrafts?: boolean, metaOnly?: false, paginate?: PaginateInput): Effect.Effect<CombinedPageData[], ParseResult.ParseError | DBCallbackFailure | DatabaseError | FolderTreeError | CollectorError | PaginateError, never>;
|
|
217
|
+
(includeDrafts?: boolean, metaOnly?: true, paginate?: PaginateInput): Effect.Effect<MetaOnlyPageData[], ParseResult.ParseError | DBCallbackFailure | DatabaseError | FolderTreeError | CollectorError | PaginateError, never>;
|
|
219
218
|
};
|
|
220
219
|
/**
|
|
221
220
|
* Utilities to get pages by specific criteria.
|
|
@@ -259,14 +258,115 @@ export declare const SDKGetModule: Effect.Effect<{
|
|
|
259
258
|
* @returns An array of page data records within the specified folder.
|
|
260
259
|
*/
|
|
261
260
|
folderPages: {
|
|
262
|
-
(idOrName: string, includeDrafts?: boolean,
|
|
263
|
-
(idOrName: string, includeDrafts?: boolean,
|
|
261
|
+
(idOrName: string, includeDrafts?: boolean, metaOnly?: false, paginate?: PaginateInput): Effect.Effect<CombinedPageData[], ParseResult.ParseError | DBCallbackFailure | DatabaseError | FolderTreeError | CollectorError | PaginateError, never>;
|
|
262
|
+
(idOrName: string, includeDrafts?: boolean, metaOnly?: true, paginate?: PaginateInput): Effect.Effect<MetaOnlyPageData[], ParseResult.ParseError | DBCallbackFailure | DatabaseError | FolderTreeError | CollectorError | PaginateError, never>;
|
|
264
263
|
};
|
|
265
264
|
/**
|
|
266
265
|
* Retrieves the page folder tree structure.
|
|
267
266
|
*
|
|
268
267
|
* @returns The page folder tree structure.
|
|
269
268
|
*/
|
|
270
|
-
pageFolderTree: (
|
|
271
|
-
|
|
269
|
+
pageFolderTree: (excludeDrafts?: boolean) => Effect.Effect<import("../../types.js").FolderNode[], ParseResult.ParseError | DBCallbackFailure | import("@withstudiocms/kysely/core/errors").QueryParseError | import("@withstudiocms/kysely/core/errors").QueryError | import("@withstudiocms/kysely/core/errors").NotFoundError | FolderTreeError | CollectorError | PaginateError, never>;
|
|
270
|
+
/**
|
|
271
|
+
* Category-related GET operations.
|
|
272
|
+
*/
|
|
273
|
+
categories: {
|
|
274
|
+
/**
|
|
275
|
+
* Retrieves all categories.
|
|
276
|
+
*
|
|
277
|
+
* @returns An array of category records.
|
|
278
|
+
*/
|
|
279
|
+
getAll: () => Effect.Effect<readonly {
|
|
280
|
+
readonly id: number;
|
|
281
|
+
readonly name: string;
|
|
282
|
+
readonly description: string;
|
|
283
|
+
readonly parent?: number | null | undefined;
|
|
284
|
+
readonly slug: string;
|
|
285
|
+
readonly meta: {
|
|
286
|
+
readonly [x: string]: unknown;
|
|
287
|
+
};
|
|
288
|
+
}[], DBCallbackFailure | DatabaseError, never>;
|
|
289
|
+
/**
|
|
290
|
+
* Retrieves a category by its ID.
|
|
291
|
+
*
|
|
292
|
+
* @param categoryId - The ID of the category to fetch.
|
|
293
|
+
* @returns The category record if found, otherwise undefined.
|
|
294
|
+
*/
|
|
295
|
+
byId: (categoryId: number) => Effect.Effect<{
|
|
296
|
+
readonly id: number;
|
|
297
|
+
readonly name: string;
|
|
298
|
+
readonly description: string;
|
|
299
|
+
readonly parent?: number | null | undefined;
|
|
300
|
+
readonly slug: string;
|
|
301
|
+
readonly meta: {
|
|
302
|
+
readonly [x: string]: unknown;
|
|
303
|
+
};
|
|
304
|
+
} | undefined, DBCallbackFailure | DatabaseError, never>;
|
|
305
|
+
/**
|
|
306
|
+
* Retrieves a category by its slug.
|
|
307
|
+
*
|
|
308
|
+
* @param slug - The slug of the category to fetch.
|
|
309
|
+
* @returns The category record if found, otherwise undefined.
|
|
310
|
+
*/
|
|
311
|
+
bySlug: (slug: string) => Effect.Effect<{
|
|
312
|
+
readonly id: number;
|
|
313
|
+
readonly name: string;
|
|
314
|
+
readonly description: string;
|
|
315
|
+
readonly parent?: number | null | undefined;
|
|
316
|
+
readonly slug: string;
|
|
317
|
+
readonly meta: {
|
|
318
|
+
readonly [x: string]: unknown;
|
|
319
|
+
};
|
|
320
|
+
} | undefined, DBCallbackFailure | DatabaseError, never>;
|
|
321
|
+
};
|
|
322
|
+
/**
|
|
323
|
+
* Tag-related GET operations.
|
|
324
|
+
*/
|
|
325
|
+
tags: {
|
|
326
|
+
/**
|
|
327
|
+
* Retrieves all tags.
|
|
328
|
+
*
|
|
329
|
+
* @returns An array of tag records.
|
|
330
|
+
*/
|
|
331
|
+
getAll: () => Effect.Effect<readonly {
|
|
332
|
+
readonly id: number;
|
|
333
|
+
readonly name: string;
|
|
334
|
+
readonly description: string;
|
|
335
|
+
readonly slug: string;
|
|
336
|
+
readonly meta: {
|
|
337
|
+
readonly [x: string]: unknown;
|
|
338
|
+
};
|
|
339
|
+
}[], DBCallbackFailure | DatabaseError, never>;
|
|
340
|
+
/**
|
|
341
|
+
* Retrieves a tag by its ID.
|
|
342
|
+
*
|
|
343
|
+
* @param tagId - The ID of the tag to fetch.
|
|
344
|
+
* @returns The tag record if found, otherwise undefined.
|
|
345
|
+
*/
|
|
346
|
+
byId: (tagId: number) => Effect.Effect<{
|
|
347
|
+
readonly id: number;
|
|
348
|
+
readonly name: string;
|
|
349
|
+
readonly description: string;
|
|
350
|
+
readonly slug: string;
|
|
351
|
+
readonly meta: {
|
|
352
|
+
readonly [x: string]: unknown;
|
|
353
|
+
};
|
|
354
|
+
} | undefined, DBCallbackFailure | DatabaseError, never>;
|
|
355
|
+
/**
|
|
356
|
+
* Retrieves a tag by its slug.
|
|
357
|
+
*
|
|
358
|
+
* @param slug - The slug of the tag to fetch.
|
|
359
|
+
* @returns The tag record if found, otherwise undefined.
|
|
360
|
+
*/
|
|
361
|
+
bySlug: (slug: string) => Effect.Effect<{
|
|
362
|
+
readonly id: number;
|
|
363
|
+
readonly name: string;
|
|
364
|
+
readonly description: string;
|
|
365
|
+
readonly slug: string;
|
|
366
|
+
readonly meta: {
|
|
367
|
+
readonly [x: string]: unknown;
|
|
368
|
+
};
|
|
369
|
+
} | undefined, DBCallbackFailure | DatabaseError, never>;
|
|
370
|
+
};
|
|
371
|
+
}, never, DBClientLive | SDKDefaults | import("../../context.js").StorageManagerResolver | CacheService | import("@withstudiocms/effect").Deepmerge>;
|
|
272
372
|
export default SDKGetModule;
|