@withstudiocms/sdk 0.1.0-beta.1 → 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.
- 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,13 +1,15 @@
|
|
|
1
1
|
import { Effect, Schema } from "@withstudiocms/effect";
|
|
2
|
+
import CacheService from "../../cache.js";
|
|
3
|
+
import { cacheKeyGetters, cacheTags } from "../../consts.js";
|
|
4
|
+
import { DBClientLive, SDKDefaults } from "../../context.js";
|
|
2
5
|
import {
|
|
3
6
|
StudioCMSPageData,
|
|
7
|
+
StudioCMSPageDataCategories,
|
|
8
|
+
StudioCMSPageDataTags,
|
|
4
9
|
StudioCMSPageFolderStructure,
|
|
5
10
|
StudioCMSPermissions,
|
|
6
11
|
StudioCMSUsersTable
|
|
7
|
-
} from "
|
|
8
|
-
import CacheService from "../../cache.js";
|
|
9
|
-
import { cacheKeyGetters, cacheTags } from "../../consts.js";
|
|
10
|
-
import { DBClientLive, SDKDefaults } from "../../context.js";
|
|
12
|
+
} from "../../tables.js";
|
|
11
13
|
import SDKConfigModule from "../config/index.js";
|
|
12
14
|
import { SDKCollectors } from "../util/collectors.js";
|
|
13
15
|
import { SDKFolderTree } from "../util/folderTree.js";
|
|
@@ -183,12 +185,8 @@ const SDKGetModule = Effect.gen(function* () {
|
|
|
183
185
|
}
|
|
184
186
|
return paginate;
|
|
185
187
|
});
|
|
186
|
-
const
|
|
187
|
-
(pages, includeDrafts
|
|
188
|
-
pages.filter(
|
|
189
|
-
({ draft, slug }) => (includeDrafts || draft === false || draft === null) && (!hideDefaultIndex || slug !== "index")
|
|
190
|
-
)
|
|
191
|
-
)
|
|
188
|
+
const __filterPagesByDraft = Effect.fn(
|
|
189
|
+
(pages, includeDrafts) => Effect.succeed(pages.filter(({ draft }) => includeDrafts || draft !== true))
|
|
192
190
|
);
|
|
193
191
|
function convertCombinedPageDataToMetaOnly(data) {
|
|
194
192
|
if (Array.isArray(data)) {
|
|
@@ -200,11 +198,11 @@ const SDKGetModule = Effect.gen(function* () {
|
|
|
200
198
|
return metaOnlyData;
|
|
201
199
|
}
|
|
202
200
|
const __getPagesPossiblyPaginated = (paginate) => paginate ? validatePagination(paginate).pipe(Effect.flatMap(_getAllPagesPaginated)) : _getAllPagesBase();
|
|
203
|
-
function _getAllPages(includeDrafts = false,
|
|
201
|
+
function _getAllPages(includeDrafts = false, metaOnly = false, paginate) {
|
|
204
202
|
return __getPagesPossiblyPaginated(paginate).pipe(
|
|
205
203
|
Effect.flatMap(
|
|
206
204
|
(pagesRaw) => Effect.all({
|
|
207
|
-
pages:
|
|
205
|
+
pages: __filterPagesByDraft(pagesRaw, includeDrafts),
|
|
208
206
|
tree: GET.folderTree()
|
|
209
207
|
})
|
|
210
208
|
),
|
|
@@ -267,15 +265,14 @@ const SDKGetModule = Effect.gen(function* () {
|
|
|
267
265
|
Effect.catchTag("KillSwitch", () => Effect.succeed([]))
|
|
268
266
|
);
|
|
269
267
|
}
|
|
270
|
-
function _folderPages(idOrName, includeDrafts = false,
|
|
268
|
+
function _folderPages(idOrName, includeDrafts = false, metaOnly = false, paginate) {
|
|
271
269
|
return _getFolderByNameOrId(idOrName).pipe(
|
|
272
270
|
Effect.flatMap(
|
|
273
271
|
({ id: folderId }) => __getPagesPossiblyPaginated(paginate).pipe(
|
|
274
272
|
Effect.flatMap(
|
|
275
|
-
(pagesRaw) =>
|
|
273
|
+
(pagesRaw) => __filterPagesByDraft(
|
|
276
274
|
pagesRaw.filter((page) => page.parentFolder === folderId),
|
|
277
|
-
includeDrafts
|
|
278
|
-
hideDefaultIndex
|
|
275
|
+
includeDrafts
|
|
279
276
|
)
|
|
280
277
|
),
|
|
281
278
|
Effect.flatMap(
|
|
@@ -297,11 +294,9 @@ const SDKGetModule = Effect.gen(function* () {
|
|
|
297
294
|
)
|
|
298
295
|
);
|
|
299
296
|
}
|
|
300
|
-
const _pageFolderTree = (
|
|
301
|
-
const
|
|
302
|
-
|
|
303
|
-
_getAllPages(true, hideDefaultIndex)
|
|
304
|
-
]);
|
|
297
|
+
const _pageFolderTree = (excludeDrafts = false) => Effect.gen(function* () {
|
|
298
|
+
const includeDrafts = !excludeDrafts;
|
|
299
|
+
const [tree, pages] = yield* Effect.all([GET.folderTree(), _getAllPages(includeDrafts)]);
|
|
305
300
|
for (const page of pages) {
|
|
306
301
|
if (page.parentFolder) {
|
|
307
302
|
yield* addPageToFolderTree(tree, page.parentFolder, {
|
|
@@ -323,6 +318,74 @@ const SDKGetModule = Effect.gen(function* () {
|
|
|
323
318
|
}
|
|
324
319
|
return tree;
|
|
325
320
|
});
|
|
321
|
+
const getAllCategories = () => memoize(
|
|
322
|
+
cacheKeyGetters.categories(),
|
|
323
|
+
withDecoder({
|
|
324
|
+
decoder: Schema.Array(StudioCMSPageDataCategories.Select),
|
|
325
|
+
callbackFn: (db) => db((client) => client.selectFrom("StudioCMSPageDataCategories").selectAll().execute())
|
|
326
|
+
})(),
|
|
327
|
+
{ tags: [...cacheTags.categories, ...cacheTags.taxonomy] }
|
|
328
|
+
);
|
|
329
|
+
const getCategoryById = Effect.fn(
|
|
330
|
+
(categoryId) => memoize(
|
|
331
|
+
cacheKeyGetters.categoryById(categoryId),
|
|
332
|
+
withCodec({
|
|
333
|
+
encoder: Schema.Number,
|
|
334
|
+
decoder: Schema.UndefinedOr(StudioCMSPageDataCategories.Select),
|
|
335
|
+
callbackFn: (db, categoryId2) => db(
|
|
336
|
+
(client) => client.selectFrom("StudioCMSPageDataCategories").selectAll().where("id", "=", categoryId2).executeTakeFirst()
|
|
337
|
+
)
|
|
338
|
+
})(categoryId),
|
|
339
|
+
{ tags: [...cacheTags.categories, ...cacheTags.taxonomy] }
|
|
340
|
+
)
|
|
341
|
+
);
|
|
342
|
+
const getCategoryBySlug = Effect.fn(
|
|
343
|
+
(slug) => memoize(
|
|
344
|
+
cacheKeyGetters.categoryBySlug(slug),
|
|
345
|
+
withCodec({
|
|
346
|
+
encoder: Schema.String,
|
|
347
|
+
decoder: Schema.UndefinedOr(StudioCMSPageDataCategories.Select),
|
|
348
|
+
callbackFn: (db, slug2) => db(
|
|
349
|
+
(client) => client.selectFrom("StudioCMSPageDataCategories").selectAll().where("slug", "=", slug2).executeTakeFirst()
|
|
350
|
+
)
|
|
351
|
+
})(slug),
|
|
352
|
+
{ tags: [...cacheTags.categories, ...cacheTags.taxonomy] }
|
|
353
|
+
)
|
|
354
|
+
);
|
|
355
|
+
const getAllTags = () => memoize(
|
|
356
|
+
cacheKeyGetters.tags(),
|
|
357
|
+
withDecoder({
|
|
358
|
+
decoder: Schema.Array(StudioCMSPageDataTags.Select),
|
|
359
|
+
callbackFn: (db) => db((client) => client.selectFrom("StudioCMSPageDataTags").selectAll().execute())
|
|
360
|
+
})(),
|
|
361
|
+
{ tags: [...cacheTags.tags, ...cacheTags.taxonomy] }
|
|
362
|
+
);
|
|
363
|
+
const getTagById = Effect.fn(
|
|
364
|
+
(tagId) => memoize(
|
|
365
|
+
cacheKeyGetters.tagById(tagId),
|
|
366
|
+
withCodec({
|
|
367
|
+
encoder: Schema.Number,
|
|
368
|
+
decoder: Schema.UndefinedOr(StudioCMSPageDataTags.Select),
|
|
369
|
+
callbackFn: (db, tagId2) => db(
|
|
370
|
+
(client) => client.selectFrom("StudioCMSPageDataTags").selectAll().where("id", "=", tagId2).executeTakeFirst()
|
|
371
|
+
)
|
|
372
|
+
})(tagId),
|
|
373
|
+
{ tags: [...cacheTags.tags, ...cacheTags.taxonomy] }
|
|
374
|
+
)
|
|
375
|
+
);
|
|
376
|
+
const getTagBySlug = Effect.fn(
|
|
377
|
+
(slug) => memoize(
|
|
378
|
+
cacheKeyGetters.tagBySlug(slug),
|
|
379
|
+
withCodec({
|
|
380
|
+
encoder: Schema.String,
|
|
381
|
+
decoder: Schema.UndefinedOr(StudioCMSPageDataTags.Select),
|
|
382
|
+
callbackFn: (db, slug2) => db(
|
|
383
|
+
(client) => client.selectFrom("StudioCMSPageDataTags").selectAll().where("slug", "=", slug2).executeTakeFirst()
|
|
384
|
+
)
|
|
385
|
+
})(slug),
|
|
386
|
+
{ tags: [...cacheTags.tags, ...cacheTags.taxonomy] }
|
|
387
|
+
)
|
|
388
|
+
);
|
|
326
389
|
const GET = {
|
|
327
390
|
/**
|
|
328
391
|
* Lists of permissions categorized by user ranks.
|
|
@@ -453,7 +516,57 @@ const SDKGetModule = Effect.gen(function* () {
|
|
|
453
516
|
*
|
|
454
517
|
* @returns The page folder tree structure.
|
|
455
518
|
*/
|
|
456
|
-
pageFolderTree: _pageFolderTree
|
|
519
|
+
pageFolderTree: _pageFolderTree,
|
|
520
|
+
/**
|
|
521
|
+
* Category-related GET operations.
|
|
522
|
+
*/
|
|
523
|
+
categories: {
|
|
524
|
+
/**
|
|
525
|
+
* Retrieves all categories.
|
|
526
|
+
*
|
|
527
|
+
* @returns An array of category records.
|
|
528
|
+
*/
|
|
529
|
+
getAll: getAllCategories,
|
|
530
|
+
/**
|
|
531
|
+
* Retrieves a category by its ID.
|
|
532
|
+
*
|
|
533
|
+
* @param categoryId - The ID of the category to fetch.
|
|
534
|
+
* @returns The category record if found, otherwise undefined.
|
|
535
|
+
*/
|
|
536
|
+
byId: getCategoryById,
|
|
537
|
+
/**
|
|
538
|
+
* Retrieves a category by its slug.
|
|
539
|
+
*
|
|
540
|
+
* @param slug - The slug of the category to fetch.
|
|
541
|
+
* @returns The category record if found, otherwise undefined.
|
|
542
|
+
*/
|
|
543
|
+
bySlug: getCategoryBySlug
|
|
544
|
+
},
|
|
545
|
+
/**
|
|
546
|
+
* Tag-related GET operations.
|
|
547
|
+
*/
|
|
548
|
+
tags: {
|
|
549
|
+
/**
|
|
550
|
+
* Retrieves all tags.
|
|
551
|
+
*
|
|
552
|
+
* @returns An array of tag records.
|
|
553
|
+
*/
|
|
554
|
+
getAll: getAllTags,
|
|
555
|
+
/**
|
|
556
|
+
* Retrieves a tag by its ID.
|
|
557
|
+
*
|
|
558
|
+
* @param tagId - The ID of the tag to fetch.
|
|
559
|
+
* @returns The tag record if found, otherwise undefined.
|
|
560
|
+
*/
|
|
561
|
+
byId: getTagById,
|
|
562
|
+
/**
|
|
563
|
+
* Retrieves a tag by its slug.
|
|
564
|
+
*
|
|
565
|
+
* @param slug - The slug of the tag to fetch.
|
|
566
|
+
* @returns The tag record if found, otherwise undefined.
|
|
567
|
+
*/
|
|
568
|
+
bySlug: getTagBySlug
|
|
569
|
+
}
|
|
457
570
|
};
|
|
458
571
|
return GET;
|
|
459
572
|
});
|