@withstudiocms/sdk 0.0.0-beta.0 → 0.1.0-beta.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/LICENSE +21 -0
- package/README.md +21 -0
- package/dist/cache.d.ts +109 -0
- package/dist/cache.js +94 -0
- package/dist/consts.d.ts +28 -0
- package/dist/consts.js +26 -0
- package/dist/context.d.ts +188 -0
- package/dist/context.js +33 -0
- package/dist/index.d.ts +1136 -0
- package/dist/index.js +24 -0
- package/dist/lib/diff.d.ts +39 -0
- package/dist/lib/diff.js +29 -0
- package/dist/lib/logger.d.ts +31 -0
- package/dist/lib/logger.js +131 -0
- package/dist/lib/pluginUtils.d.ts +221 -0
- package/dist/lib/pluginUtils.js +80 -0
- package/dist/modules/auth/index.d.ts +463 -0
- package/dist/modules/auth/index.js +412 -0
- package/dist/modules/clear/index.d.ts +72 -0
- package/dist/modules/clear/index.js +52 -0
- package/dist/modules/config/consts.d.ts +32 -0
- package/dist/modules/config/consts.js +18 -0
- package/dist/modules/config/index.d.ts +100 -0
- package/dist/modules/config/index.js +205 -0
- package/dist/modules/config/templates/mailer.d.ts +36 -0
- package/dist/modules/config/templates/mailer.js +218 -0
- package/dist/modules/config/type-utils.d.ts +13 -0
- package/dist/modules/config/type-utils.js +11 -0
- package/dist/modules/delete/index.d.ts +140 -0
- package/dist/modules/delete/index.js +274 -0
- package/dist/modules/diffTracking/index.d.ts +188 -0
- package/dist/modules/diffTracking/index.js +276 -0
- package/dist/modules/get/index.d.ts +272 -0
- package/dist/modules/get/index.js +466 -0
- package/dist/modules/index.d.ts +1003 -0
- package/dist/modules/index.js +37 -0
- package/dist/modules/init/index.d.ts +60 -0
- package/dist/modules/init/index.js +38 -0
- package/dist/modules/middleware/index.d.ts +56 -0
- package/dist/modules/middleware/index.js +50 -0
- package/dist/modules/notificationSettings/index.d.ts +57 -0
- package/dist/modules/notificationSettings/index.js +39 -0
- package/dist/modules/plugins/index.d.ts +166 -0
- package/dist/modules/plugins/index.js +261 -0
- package/dist/modules/post/index.d.ts +305 -0
- package/dist/modules/post/index.js +305 -0
- package/dist/modules/resetTokenBucket/index.d.ts +91 -0
- package/dist/modules/resetTokenBucket/index.js +93 -0
- package/dist/modules/rest_api/index.d.ts +92 -0
- package/dist/modules/rest_api/index.js +113 -0
- package/dist/modules/update/index.d.ts +184 -0
- package/dist/modules/update/index.js +174 -0
- package/dist/modules/util/collectors.d.ts +261 -0
- package/dist/modules/util/collectors.js +141 -0
- package/dist/modules/util/folderTree.d.ts +100 -0
- package/dist/modules/util/folderTree.js +176 -0
- package/dist/modules/util/generators.d.ts +83 -0
- package/dist/modules/util/generators.js +106 -0
- package/dist/modules/util/getFromNPM.d.ts +191 -0
- package/dist/modules/util/getFromNPM.js +100 -0
- package/dist/modules/util/index.d.ts +236 -0
- package/dist/modules/util/index.js +20 -0
- package/dist/modules/util/parsers.d.ts +60 -0
- package/dist/modules/util/parsers.js +43 -0
- package/dist/modules/util/slugify.d.ts +22 -0
- package/dist/modules/util/slugify.js +19 -0
- package/dist/modules/util/users.d.ts +99 -0
- package/dist/modules/util/users.js +78 -0
- package/dist/types.d.ts +360 -0
- package/dist/types.js +10 -0
- package/package.json +55 -7
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { Effect, Schema } from "@withstudiocms/effect";
|
|
2
|
+
import { StudioCMSAPIKeys, StudioCMSPermissions } from "@withstudiocms/kysely";
|
|
3
|
+
import { DBClientLive } from "../../context.js";
|
|
4
|
+
import { SDKGenerators } from "../util/generators.js";
|
|
5
|
+
const SDKRestAPIModule = Effect.gen(function* () {
|
|
6
|
+
const [{ withCodec, withEncoder }, { generateToken }] = yield* Effect.all([
|
|
7
|
+
DBClientLive,
|
|
8
|
+
SDKGenerators
|
|
9
|
+
]);
|
|
10
|
+
const _getTokensForUser = withCodec({
|
|
11
|
+
encoder: Schema.String,
|
|
12
|
+
decoder: Schema.Array(StudioCMSAPIKeys.Select),
|
|
13
|
+
callbackFn: (db, userId) => db(
|
|
14
|
+
(client) => client.selectFrom("StudioCMSAPIKeys").selectAll().where("userId", "=", userId).execute()
|
|
15
|
+
)
|
|
16
|
+
});
|
|
17
|
+
const _newToken = withCodec({
|
|
18
|
+
encoder: StudioCMSAPIKeys.Insert,
|
|
19
|
+
decoder: StudioCMSAPIKeys.Select,
|
|
20
|
+
callbackFn: (db, tokenData) => db(
|
|
21
|
+
(client) => client.insertInto("StudioCMSAPIKeys").values(tokenData).returningAll().executeTakeFirstOrThrow()
|
|
22
|
+
)
|
|
23
|
+
});
|
|
24
|
+
const _deleteToken = withEncoder({
|
|
25
|
+
encoder: Schema.Struct({
|
|
26
|
+
userId: Schema.String,
|
|
27
|
+
tokenId: Schema.String
|
|
28
|
+
}),
|
|
29
|
+
callbackFn: (db, { userId, tokenId }) => db(
|
|
30
|
+
(client) => client.deleteFrom("StudioCMSAPIKeys").where("userId", "=", userId).where("id", "=", tokenId).execute()
|
|
31
|
+
)
|
|
32
|
+
});
|
|
33
|
+
const _getByKey = withCodec({
|
|
34
|
+
encoder: Schema.String,
|
|
35
|
+
decoder: Schema.UndefinedOr(StudioCMSAPIKeys.Select),
|
|
36
|
+
callbackFn: (db, key) => db(
|
|
37
|
+
(client) => client.selectFrom("StudioCMSAPIKeys").selectAll().where("key", "=", key).executeTakeFirst()
|
|
38
|
+
)
|
|
39
|
+
});
|
|
40
|
+
const _getKeyPermissions = withCodec({
|
|
41
|
+
encoder: Schema.String,
|
|
42
|
+
decoder: Schema.UndefinedOr(StudioCMSPermissions.Select),
|
|
43
|
+
callbackFn: (db, userId) => db(
|
|
44
|
+
(client) => client.selectFrom("StudioCMSPermissions").selectAll().where("user", "=", userId).executeTakeFirst()
|
|
45
|
+
)
|
|
46
|
+
});
|
|
47
|
+
const _createNewTokenForUser = Effect.fn(
|
|
48
|
+
(userId, description) => generateToken(userId, true).pipe(
|
|
49
|
+
Effect.flatMap(
|
|
50
|
+
(key) => _newToken({
|
|
51
|
+
id: crypto.randomUUID(),
|
|
52
|
+
key,
|
|
53
|
+
userId,
|
|
54
|
+
description
|
|
55
|
+
})
|
|
56
|
+
)
|
|
57
|
+
)
|
|
58
|
+
);
|
|
59
|
+
const _verifyToken = Effect.fn(
|
|
60
|
+
(key) => Effect.gen(function* () {
|
|
61
|
+
const apiKeyRecord = yield* _getByKey(key);
|
|
62
|
+
if (!apiKeyRecord) return false;
|
|
63
|
+
const permissionsRecord = yield* _getKeyPermissions(apiKeyRecord.userId);
|
|
64
|
+
if (!permissionsRecord) return false;
|
|
65
|
+
return {
|
|
66
|
+
userId: apiKeyRecord.userId,
|
|
67
|
+
key: apiKeyRecord.key,
|
|
68
|
+
rank: permissionsRecord.rank
|
|
69
|
+
};
|
|
70
|
+
})
|
|
71
|
+
);
|
|
72
|
+
const tokens = {
|
|
73
|
+
/**
|
|
74
|
+
* Retrieves all API tokens for a specific user.
|
|
75
|
+
*
|
|
76
|
+
* @param userId - The ID of the user whose tokens are to be retrieved.
|
|
77
|
+
* @returns An Effect that resolves to an array of API keys for the user.
|
|
78
|
+
* @throws {LibSQLDatabaseError} If a database error occurs during the operation.
|
|
79
|
+
*/
|
|
80
|
+
get: _getTokensForUser,
|
|
81
|
+
/**
|
|
82
|
+
* Creates a new API token for a user with the specified description.
|
|
83
|
+
*
|
|
84
|
+
* @param userId - The ID of the user for whom to create the token.
|
|
85
|
+
* @param description - A description for the API key.
|
|
86
|
+
* @returns An Effect that resolves to the created API key record.
|
|
87
|
+
* @throws {LibSQLDatabaseError} If a database error occurs during the operation.
|
|
88
|
+
*/
|
|
89
|
+
new: _createNewTokenForUser,
|
|
90
|
+
/**
|
|
91
|
+
* Deletes an API token for a user by its ID.
|
|
92
|
+
*
|
|
93
|
+
* @param userId - The ID of the user whose token is to be deleted.
|
|
94
|
+
* @param tokenId - The ID of the API token to delete.
|
|
95
|
+
* @returns An Effect that resolves when the token is successfully deleted.
|
|
96
|
+
* @throws {LibSQLDatabaseError} If a database error occurs during the operation.
|
|
97
|
+
*/
|
|
98
|
+
delete: _deleteToken,
|
|
99
|
+
/**
|
|
100
|
+
* Verifies an API token and retrieves associated user information.
|
|
101
|
+
*
|
|
102
|
+
* @param key - The API token to verify.
|
|
103
|
+
* @returns An Effect that resolves to user information if the token is valid, or false if invalid.
|
|
104
|
+
*/
|
|
105
|
+
verify: _verifyToken
|
|
106
|
+
};
|
|
107
|
+
return { tokens };
|
|
108
|
+
});
|
|
109
|
+
var rest_api_default = SDKRestAPIModule;
|
|
110
|
+
export {
|
|
111
|
+
SDKRestAPIModule,
|
|
112
|
+
rest_api_default as default
|
|
113
|
+
};
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { Effect } from '@withstudiocms/effect';
|
|
2
|
+
import { StudioCMSPageContent, StudioCMSPageData } from '@withstudiocms/kysely';
|
|
3
|
+
import CacheService from '../../cache.js';
|
|
4
|
+
import { DBClientLive } from '../../context.js';
|
|
5
|
+
/**
|
|
6
|
+
* CombinedPageUpdateData
|
|
7
|
+
*
|
|
8
|
+
* Type representing the combined data required to update both page data and page content.
|
|
9
|
+
*/
|
|
10
|
+
type CombinedPageUpdateData = {
|
|
11
|
+
pageData: (typeof StudioCMSPageData.Update)['Type'];
|
|
12
|
+
pageContent: (typeof StudioCMSPageContent.Update)['Type'];
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* SDKUpdateModule
|
|
16
|
+
*
|
|
17
|
+
* Effect generator that constructs and returns the SDK "UPDATE" module containing all update-related operations
|
|
18
|
+
* for the StudioCMS domain. Each operation is implemented as an Effect and typically combines:
|
|
19
|
+
* - a DB update operation (wrapped with a codec for runtime encode/decode/validation),
|
|
20
|
+
* - optional cache invalidation or cache refresh,
|
|
21
|
+
* - and retrieval of the fresh resource via the GET module when appropriate.
|
|
22
|
+
*
|
|
23
|
+
* @module SDKUpdateModule
|
|
24
|
+
*
|
|
25
|
+
* @remarks
|
|
26
|
+
* - Dependencies resolved by the generator: DBClientLive, CacheService, SDKClearModule, SDKGetModule, SDKConfigModule.
|
|
27
|
+
* - DB operations are created via withCodec with corresponding encoder/decoder codecs (e.g. StudioCMSPageContent, StudioCMSPageData, StudioCMSPermissions, etc.).
|
|
28
|
+
* - Cache-related operations include clearing/invalidation of folder tree/list caches, page-specific cache deletion, and npm package cache tag invalidation.
|
|
29
|
+
* - Composite helpers coordinate multi-step flows, e.g. updating page content + page data + deleting the page cache, then returning the fresh page via GET.
|
|
30
|
+
* - All operations are effectful and intended to be executed inside the Effect runtime; callers should compose and run them using the Effect primitives provided by the environment.
|
|
31
|
+
*
|
|
32
|
+
* @returns {{
|
|
33
|
+
* pageContent: Effect, tags: Effect, categories: Effect, permissions: Effect,
|
|
34
|
+
* folderTree: Effect, folderList: Effect, folder: Effect,
|
|
35
|
+
* latestVersion: Effect, siteConfig: Effect,
|
|
36
|
+
* page: { byId: Effect, bySlug: Effect }
|
|
37
|
+
* }}
|
|
38
|
+
* An object exposing update operations:
|
|
39
|
+
* - pageContent, tags, categories, permissions: DB update Effects returning the updated record.
|
|
40
|
+
* - folderTree, folderList: Effects that refresh corresponding caches.
|
|
41
|
+
* - folder: updates a folder entry and invalidates/refreshes folder caches.
|
|
42
|
+
* - latestVersion: invalidates npm package cache tags and fetches the latest package version.
|
|
43
|
+
* - siteConfig: forwards to CONFIG.siteConfig.update.
|
|
44
|
+
* - page.byId: updates page data and content, deletes the page cache, refreshes folder caches, then returns the updated page.
|
|
45
|
+
* - page.bySlug: resolves the page id by slug and delegates to page.byId.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* // Typical usage inside an Effect:
|
|
49
|
+
* // yield* Effect.flatMap(UPDATE.page.byId('pageId', combinedPageUpdateData))
|
|
50
|
+
*
|
|
51
|
+
* @threadSafety
|
|
52
|
+
* Effects encapsulate async side effects; callers should treat composite updates as atomic logical operations but not assume cross-operation DB transactions unless provided by the DB client.
|
|
53
|
+
*
|
|
54
|
+
* @errors
|
|
55
|
+
* - DB client errors (e.g. executeTakeFirstOrThrow) propagate as Effect failures.
|
|
56
|
+
* - Codec validation errors are raised if supplied data does not conform to the expected codec schemas.
|
|
57
|
+
*
|
|
58
|
+
* @see SDKGetModule for read operations
|
|
59
|
+
* @see SDKClearModule for explicit cache clearing operations
|
|
60
|
+
*/
|
|
61
|
+
export declare const SDKUpdateModule: Effect.Effect<{
|
|
62
|
+
/**
|
|
63
|
+
* Update Page Content
|
|
64
|
+
*
|
|
65
|
+
* @param data - The page content data to update.
|
|
66
|
+
* @returns The updated page content.
|
|
67
|
+
*/
|
|
68
|
+
pageContent: (input: {
|
|
69
|
+
readonly id: string;
|
|
70
|
+
readonly contentId: string;
|
|
71
|
+
readonly contentLang: string;
|
|
72
|
+
readonly content: string;
|
|
73
|
+
}) => Effect.Effect<{
|
|
74
|
+
readonly id: string;
|
|
75
|
+
readonly contentId: string;
|
|
76
|
+
readonly contentLang: string;
|
|
77
|
+
readonly content: string;
|
|
78
|
+
}, import("@withstudiocms/kysely").DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError, never>;
|
|
79
|
+
/**
|
|
80
|
+
* Update Tag
|
|
81
|
+
*
|
|
82
|
+
* @param data - The tag data to update.
|
|
83
|
+
* @returns The updated tag.
|
|
84
|
+
*/
|
|
85
|
+
tags: (input: {
|
|
86
|
+
readonly name: string;
|
|
87
|
+
readonly id: number;
|
|
88
|
+
readonly description: string;
|
|
89
|
+
readonly slug: string;
|
|
90
|
+
readonly meta: string;
|
|
91
|
+
}) => Effect.Effect<{
|
|
92
|
+
readonly name: string;
|
|
93
|
+
readonly id: number;
|
|
94
|
+
readonly description: string;
|
|
95
|
+
readonly slug: string;
|
|
96
|
+
readonly meta: {
|
|
97
|
+
readonly [x: string]: unknown;
|
|
98
|
+
};
|
|
99
|
+
}, import("@withstudiocms/kysely").DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError, never>;
|
|
100
|
+
/**
|
|
101
|
+
* Update Category
|
|
102
|
+
*
|
|
103
|
+
* @param data - The category data to update.
|
|
104
|
+
* @returns The updated category.
|
|
105
|
+
*/
|
|
106
|
+
categories: (input: {
|
|
107
|
+
readonly parent?: number | null | undefined;
|
|
108
|
+
readonly name: string;
|
|
109
|
+
readonly id: number;
|
|
110
|
+
readonly description: string;
|
|
111
|
+
readonly slug: string;
|
|
112
|
+
readonly meta: string;
|
|
113
|
+
}) => Effect.Effect<{
|
|
114
|
+
readonly name: string;
|
|
115
|
+
readonly id: number;
|
|
116
|
+
readonly parent: number | null | undefined;
|
|
117
|
+
readonly description: string;
|
|
118
|
+
readonly slug: string;
|
|
119
|
+
readonly meta: {
|
|
120
|
+
readonly [x: string]: unknown;
|
|
121
|
+
};
|
|
122
|
+
}, import("@withstudiocms/kysely").DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError, never>;
|
|
123
|
+
/**
|
|
124
|
+
* Update Permissions
|
|
125
|
+
*
|
|
126
|
+
* @param data - The permissions data to update.
|
|
127
|
+
* @returns The updated permissions.
|
|
128
|
+
*/
|
|
129
|
+
permissions: (input: {
|
|
130
|
+
readonly user: string;
|
|
131
|
+
readonly rank: "owner" | "admin" | "editor" | "visitor" | "unknown";
|
|
132
|
+
}) => Effect.Effect<{
|
|
133
|
+
readonly user: string;
|
|
134
|
+
readonly rank: "owner" | "admin" | "editor" | "visitor" | "unknown";
|
|
135
|
+
}, import("@withstudiocms/kysely").DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError, never>;
|
|
136
|
+
/**
|
|
137
|
+
* Update Folder Tree Cache
|
|
138
|
+
*/
|
|
139
|
+
folderTree: Effect.Effect<import("../../types.js").FolderNode[], import("@withstudiocms/kysely").DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError | import("../util/folderTree.js").FolderTreeError, never>;
|
|
140
|
+
/**
|
|
141
|
+
* Update Folder List Cache
|
|
142
|
+
*/
|
|
143
|
+
folderList: Effect.Effect<import("../../types.js").FolderListItem[], import("@withstudiocms/kysely").DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError, never>;
|
|
144
|
+
/**
|
|
145
|
+
* Update Folder Entry and Invalidate Related Caches
|
|
146
|
+
*
|
|
147
|
+
* @param data - The folder entry data to update.
|
|
148
|
+
* @returns The updated folder entry.
|
|
149
|
+
*/
|
|
150
|
+
folder: (data: {
|
|
151
|
+
readonly name: string;
|
|
152
|
+
readonly id: string;
|
|
153
|
+
readonly parent: string | null | undefined;
|
|
154
|
+
}) => Effect.Effect<{
|
|
155
|
+
readonly name: string;
|
|
156
|
+
readonly id: string;
|
|
157
|
+
readonly parent: string | null | undefined;
|
|
158
|
+
}, import("@withstudiocms/kysely").DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError | import("../util/folderTree.js").FolderTreeError, never>;
|
|
159
|
+
/**
|
|
160
|
+
* Update Latest NPM Package Version
|
|
161
|
+
*/
|
|
162
|
+
latestVersion: () => Effect.Effect<{
|
|
163
|
+
version: string;
|
|
164
|
+
lastCacheUpdate: Date;
|
|
165
|
+
}, import("effect/Cause").UnknownException | Error | import("effect/ParseResult").ParseError, never>;
|
|
166
|
+
/**
|
|
167
|
+
* Update Site Configuration
|
|
168
|
+
*/
|
|
169
|
+
siteConfig: (data: import("../../types.js").ConfigFinal<import("../../types.js").StudioCMSSiteConfig>) => Effect.Effect<import("../../types.js").DynamicConfigEntry<import("../../types.js").StudioCMSSiteConfig>, import("@withstudiocms/kysely").DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError, never>;
|
|
170
|
+
/**
|
|
171
|
+
* Page Operations
|
|
172
|
+
*/
|
|
173
|
+
page: {
|
|
174
|
+
/**
|
|
175
|
+
* Update Page by ID
|
|
176
|
+
*/
|
|
177
|
+
byId: (pageId: string, data: CombinedPageUpdateData) => Effect.Effect<import("../../types.js").CombinedPageData | undefined, import("effect/ParseResult").ParseError | import("@withstudiocms/kysely").DBCallbackFailure | import("@withstudiocms/kysely/core/errors").QueryParseError | import("@withstudiocms/kysely/core/errors").QueryError | import("@withstudiocms/kysely/core/errors").NotFoundError | import("../util/folderTree.js").FolderTreeError | import("../util/collectors.js").CollectorError | import("../get/index.js").PaginateError, never>;
|
|
178
|
+
/**
|
|
179
|
+
* Update Page by Slug
|
|
180
|
+
*/
|
|
181
|
+
bySlug: (slug: string, data: CombinedPageUpdateData) => Effect.Effect<import("../../types.js").CombinedPageData | undefined, import("effect/ParseResult").ParseError | import("@withstudiocms/kysely").DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError | import("../util/folderTree.js").FolderTreeError | import("../util/collectors.js").CollectorError | import("../get/index.js").PaginateError, never>;
|
|
182
|
+
};
|
|
183
|
+
}, never, DBClientLive | import("../../context.js").SDKDefaults | CacheService | import("@withstudiocms/effect").Deepmerge>;
|
|
184
|
+
export default SDKUpdateModule;
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { Effect, Schema } from "@withstudiocms/effect";
|
|
2
|
+
import {
|
|
3
|
+
StudioCMSPageContent,
|
|
4
|
+
StudioCMSPageData,
|
|
5
|
+
StudioCMSPageDataCategories,
|
|
6
|
+
StudioCMSPageDataTags,
|
|
7
|
+
StudioCMSPageFolderStructure,
|
|
8
|
+
StudioCMSPermissions
|
|
9
|
+
} from "@withstudiocms/kysely";
|
|
10
|
+
import CacheService from "../../cache.js";
|
|
11
|
+
import { cacheKeyGetters, cacheTags } from "../../consts.js";
|
|
12
|
+
import { DBClientLive } from "../../context.js";
|
|
13
|
+
import SDKClearModule from "../clear/index.js";
|
|
14
|
+
import SDKConfigModule from "../config/index.js";
|
|
15
|
+
import SDKGetModule from "../get/index.js";
|
|
16
|
+
const SDKUpdateModule = Effect.gen(function* () {
|
|
17
|
+
const [{ withCodec }, CACHE, CLEAR, GET, CONFIG] = yield* Effect.all([
|
|
18
|
+
DBClientLive,
|
|
19
|
+
CacheService,
|
|
20
|
+
SDKClearModule,
|
|
21
|
+
SDKGetModule,
|
|
22
|
+
SDKConfigModule
|
|
23
|
+
]);
|
|
24
|
+
const _updatePageContent = withCodec({
|
|
25
|
+
encoder: StudioCMSPageContent.Update,
|
|
26
|
+
decoder: StudioCMSPageContent.Select,
|
|
27
|
+
callbackFn: (db, data) => db(
|
|
28
|
+
(client) => client.updateTable("StudioCMSPageContent").set(data).where("id", "=", data.id).returningAll().executeTakeFirstOrThrow()
|
|
29
|
+
)
|
|
30
|
+
});
|
|
31
|
+
const _updateTag = withCodec({
|
|
32
|
+
encoder: StudioCMSPageDataTags.Update,
|
|
33
|
+
decoder: StudioCMSPageDataTags.Select,
|
|
34
|
+
callbackFn: (db, data) => db(
|
|
35
|
+
(client) => client.updateTable("StudioCMSPageDataTags").set(data).where("id", "=", data.id).returningAll().executeTakeFirstOrThrow()
|
|
36
|
+
)
|
|
37
|
+
});
|
|
38
|
+
const _updateCategory = withCodec({
|
|
39
|
+
encoder: StudioCMSPageDataCategories.Update,
|
|
40
|
+
decoder: StudioCMSPageDataCategories.Select,
|
|
41
|
+
callbackFn: (db, data) => db(
|
|
42
|
+
(client) => client.updateTable("StudioCMSPageDataCategories").set(data).where("id", "=", data.id).returningAll().executeTakeFirstOrThrow()
|
|
43
|
+
)
|
|
44
|
+
});
|
|
45
|
+
const _updatePermission = withCodec({
|
|
46
|
+
encoder: StudioCMSPermissions.Update,
|
|
47
|
+
decoder: StudioCMSPermissions.Select,
|
|
48
|
+
callbackFn: (db, data) => db(
|
|
49
|
+
(client) => client.updateTable("StudioCMSPermissions").set(data).where("user", "=", data.user).returningAll().executeTakeFirstOrThrow()
|
|
50
|
+
)
|
|
51
|
+
});
|
|
52
|
+
const _updateFolderEntry = withCodec({
|
|
53
|
+
encoder: StudioCMSPageFolderStructure.Update,
|
|
54
|
+
decoder: StudioCMSPageFolderStructure.Select,
|
|
55
|
+
callbackFn: (db, data) => db(
|
|
56
|
+
(client) => client.updateTable("StudioCMSPageFolderStructure").set(data).where("id", "=", data.id).returningAll().executeTakeFirstOrThrow()
|
|
57
|
+
)
|
|
58
|
+
});
|
|
59
|
+
const _updatePageDataEntry = withCodec({
|
|
60
|
+
encoder: StudioCMSPageData.Update,
|
|
61
|
+
decoder: StudioCMSPageData.Select,
|
|
62
|
+
callbackFn: (db, data) => db(
|
|
63
|
+
(client) => client.updateTable("StudioCMSPageData").set(data).where("id", "=", data.id).returningAll().executeTakeFirstOrThrow()
|
|
64
|
+
)
|
|
65
|
+
});
|
|
66
|
+
const _findPageDataBySlug = withCodec({
|
|
67
|
+
encoder: Schema.String,
|
|
68
|
+
decoder: StudioCMSPageData.Select,
|
|
69
|
+
callbackFn: (db, slug) => db(
|
|
70
|
+
(client) => client.selectFrom("StudioCMSPageData").where("slug", "=", slug).selectAll().executeTakeFirstOrThrow()
|
|
71
|
+
)
|
|
72
|
+
});
|
|
73
|
+
const _updateFolderTree = CLEAR.folderTree.pipe(Effect.flatMap(GET.folderTree));
|
|
74
|
+
const _updateFolderList = CLEAR.folderList.pipe(Effect.flatMap(GET.folderList));
|
|
75
|
+
const _updateFolderEntryAndInvalidate = Effect.fn(
|
|
76
|
+
(data) => _updateFolderEntry(data).pipe(
|
|
77
|
+
Effect.flatMap((src) => _updateFolderTree.pipe(Effect.as(src))),
|
|
78
|
+
Effect.flatMap((src) => _updateFolderList.pipe(Effect.as(src)))
|
|
79
|
+
)
|
|
80
|
+
);
|
|
81
|
+
const _updateLatestVersion = Effect.fn(
|
|
82
|
+
() => CACHE.invalidateTags(cacheTags.npmPackage).pipe(Effect.flatMap(GET.latestVersion))
|
|
83
|
+
);
|
|
84
|
+
const _updateFolderTreeAndList = Effect.all([_updateFolderTree, _updateFolderList]);
|
|
85
|
+
const _updatePageById = Effect.fn(
|
|
86
|
+
(pageId, data) => Effect.all([
|
|
87
|
+
_updatePageDataEntry(data.pageData),
|
|
88
|
+
_updatePageContent(data.pageContent),
|
|
89
|
+
CACHE.delete(cacheKeyGetters.page(pageId))
|
|
90
|
+
]).pipe(
|
|
91
|
+
Effect.tap(() => _updateFolderTreeAndList),
|
|
92
|
+
Effect.flatMap(() => GET.page.byId(pageId))
|
|
93
|
+
)
|
|
94
|
+
);
|
|
95
|
+
const _findPageIdBySlug = Effect.fn(
|
|
96
|
+
(slug) => _findPageDataBySlug(slug).pipe(Effect.map(({ id }) => id))
|
|
97
|
+
);
|
|
98
|
+
const _updatePageByIdPiped = (data) => Effect.fn((id) => _updatePageById(id, data));
|
|
99
|
+
const _updatePageBySlug = Effect.fn(
|
|
100
|
+
(slug, data) => _findPageIdBySlug(slug).pipe(Effect.flatMap(_updatePageByIdPiped(data)))
|
|
101
|
+
);
|
|
102
|
+
const UPDATE = {
|
|
103
|
+
/**
|
|
104
|
+
* Update Page Content
|
|
105
|
+
*
|
|
106
|
+
* @param data - The page content data to update.
|
|
107
|
+
* @returns The updated page content.
|
|
108
|
+
*/
|
|
109
|
+
pageContent: _updatePageContent,
|
|
110
|
+
/**
|
|
111
|
+
* Update Tag
|
|
112
|
+
*
|
|
113
|
+
* @param data - The tag data to update.
|
|
114
|
+
* @returns The updated tag.
|
|
115
|
+
*/
|
|
116
|
+
tags: _updateTag,
|
|
117
|
+
/**
|
|
118
|
+
* Update Category
|
|
119
|
+
*
|
|
120
|
+
* @param data - The category data to update.
|
|
121
|
+
* @returns The updated category.
|
|
122
|
+
*/
|
|
123
|
+
categories: _updateCategory,
|
|
124
|
+
/**
|
|
125
|
+
* Update Permissions
|
|
126
|
+
*
|
|
127
|
+
* @param data - The permissions data to update.
|
|
128
|
+
* @returns The updated permissions.
|
|
129
|
+
*/
|
|
130
|
+
permissions: _updatePermission,
|
|
131
|
+
/**
|
|
132
|
+
* Update Folder Tree Cache
|
|
133
|
+
*/
|
|
134
|
+
folderTree: _updateFolderTree,
|
|
135
|
+
/**
|
|
136
|
+
* Update Folder List Cache
|
|
137
|
+
*/
|
|
138
|
+
folderList: _updateFolderList,
|
|
139
|
+
/**
|
|
140
|
+
* Update Folder Entry and Invalidate Related Caches
|
|
141
|
+
*
|
|
142
|
+
* @param data - The folder entry data to update.
|
|
143
|
+
* @returns The updated folder entry.
|
|
144
|
+
*/
|
|
145
|
+
folder: _updateFolderEntryAndInvalidate,
|
|
146
|
+
/**
|
|
147
|
+
* Update Latest NPM Package Version
|
|
148
|
+
*/
|
|
149
|
+
latestVersion: _updateLatestVersion,
|
|
150
|
+
/**
|
|
151
|
+
* Update Site Configuration
|
|
152
|
+
*/
|
|
153
|
+
siteConfig: CONFIG.siteConfig.update,
|
|
154
|
+
/**
|
|
155
|
+
* Page Operations
|
|
156
|
+
*/
|
|
157
|
+
page: {
|
|
158
|
+
/**
|
|
159
|
+
* Update Page by ID
|
|
160
|
+
*/
|
|
161
|
+
byId: _updatePageById,
|
|
162
|
+
/**
|
|
163
|
+
* Update Page by Slug
|
|
164
|
+
*/
|
|
165
|
+
bySlug: _updatePageBySlug
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
return UPDATE;
|
|
169
|
+
});
|
|
170
|
+
var update_default = SDKUpdateModule;
|
|
171
|
+
export {
|
|
172
|
+
SDKUpdateModule,
|
|
173
|
+
update_default as default
|
|
174
|
+
};
|