@yimingliao/cms 0.0.57 → 0.0.59

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.
@@ -1,4 +1,4 @@
1
- import { ADMIN_ROLES, isFileLocked, ROOT_FOLDER_ID } from '../chunk-FUAJWL2N.js';
1
+ import { ADMIN_ROLES, isFileLocked, isFolderLocked, ROOT_FOLDER_ID, ROOT_FOLDER, POST_TYPES } from '../chunk-FUAJWL2N.js';
2
2
  import { SIZE, result, mimeToExtension, classifyFileType } from '../chunk-YAUBKQVA.js';
3
3
  import jwt from 'jsonwebtoken';
4
4
  import argon2 from 'argon2';
@@ -1304,17 +1304,20 @@ function createFileQueryRepository(prisma) {
1304
1304
  // src/server/infrastructure/database/folder/command/create-folder-command-repository.ts
1305
1305
  function createFolderCommandRepository(prisma) {
1306
1306
  async function create({
1307
+ // core
1308
+ key,
1309
+ name,
1307
1310
  // ------------------------------------
1308
1311
  // relations
1309
1312
  // ------------------------------------
1310
1313
  // Folder
1311
- parentFolder,
1312
- // rest
1313
- ...params
1314
+ parentFolder
1314
1315
  }) {
1315
1316
  const created = await prisma.folder.create({
1316
1317
  data: {
1317
- ...params,
1318
+ // core
1319
+ key,
1320
+ name,
1318
1321
  // ------------------------------------------------------------------------
1319
1322
  // relations
1320
1323
  // ------------------------------------------------------------------------
@@ -1326,18 +1329,21 @@ function createFolderCommandRepository(prisma) {
1326
1329
  }
1327
1330
  async function update({
1328
1331
  id,
1332
+ // core
1333
+ key,
1334
+ name,
1329
1335
  // ------------------------------------
1330
1336
  // relations
1331
1337
  // ------------------------------------
1332
1338
  // Folder
1333
- parentFolder,
1334
- // rest
1335
- ...params
1339
+ parentFolder
1336
1340
  }) {
1337
1341
  const updated = await prisma.folder.update({
1338
1342
  where: { id },
1339
1343
  data: {
1340
- ...params,
1344
+ // core
1345
+ key,
1346
+ name,
1341
1347
  // ------------------------------------------------------------------------
1342
1348
  // relations
1343
1349
  // ------------------------------------------------------------------------
@@ -2070,7 +2076,7 @@ function createSignInAction(ctx) {
2070
2076
  useCases: { authUseCases },
2071
2077
  action: { executeAction, ipRateLimiter },
2072
2078
  http: { headers },
2073
- schemas
2079
+ schemas: { schemas }
2074
2080
  } = ctx;
2075
2081
  return executeAction(
2076
2082
  async () => {
@@ -2180,7 +2186,7 @@ function createChangePasswordAction(ctx) {
2180
2186
  action: { executeAction, ipRateLimiter },
2181
2187
  useCases: { authUseCases },
2182
2188
  middlewares: { authMiddleware },
2183
- schemas
2189
+ schemas: { schemas }
2184
2190
  } = ctx;
2185
2191
  return executeAction(
2186
2192
  async () => {
@@ -2213,7 +2219,7 @@ function createVerifyEmailAction(ctx) {
2213
2219
  repositories: { adminQueryRepository },
2214
2220
  useCases: { authUseCases },
2215
2221
  action: { executeAction, ipRateLimiter },
2216
- schemas
2222
+ schemas: { schemas }
2217
2223
  } = ctx;
2218
2224
  return executeAction(
2219
2225
  async () => {
@@ -2249,7 +2255,7 @@ function createEmailUnverifiedAction(ctx) {
2249
2255
  repositories: { adminQueryRepository },
2250
2256
  action: { executeAction, ipRateLimiter },
2251
2257
  emails: { emailVerificationEmail },
2252
- schemas
2258
+ schemas: { schemas }
2253
2259
  } = ctx;
2254
2260
  return executeAction(
2255
2261
  async (translator) => {
@@ -2285,7 +2291,7 @@ function createForgotPasswordAction(ctx) {
2285
2291
  repositories: { adminQueryRepository },
2286
2292
  action: { executeAction, ipRateLimiter },
2287
2293
  emails: { forgotPasswordEmail },
2288
- schemas
2294
+ schemas: { schemas }
2289
2295
  } = ctx;
2290
2296
  return executeAction(
2291
2297
  async (translator) => {
@@ -2335,7 +2341,7 @@ function createResetPasswordAction(ctx) {
2335
2341
  const {
2336
2342
  useCases: { authUseCases },
2337
2343
  action: { executeAction, ipRateLimiter },
2338
- schemas
2344
+ schemas: { schemas }
2339
2345
  } = ctx;
2340
2346
  return executeAction(
2341
2347
  async () => {
@@ -2400,7 +2406,7 @@ function createAdminCreateAction(ctx) {
2400
2406
  middlewares: { authMiddleware },
2401
2407
  action: { executeAction },
2402
2408
  emails: { emailVerificationEmail },
2403
- schemas
2409
+ schemas: { schemas }
2404
2410
  } = ctx;
2405
2411
  return async function adminCreateAction({
2406
2412
  formData
@@ -2481,7 +2487,7 @@ function createAdminUpdateAction(ctx) {
2481
2487
  middlewares: { authMiddleware },
2482
2488
  action: { executeAction },
2483
2489
  emails: { emailVerificationEmail },
2484
- schemas
2490
+ schemas: { schemas }
2485
2491
  } = ctx;
2486
2492
  return async function adminUpdateAction({
2487
2493
  id,
@@ -2558,11 +2564,13 @@ function createAdminDeleteAction(ctx) {
2558
2564
  function createAdminFindFullAction(ctx) {
2559
2565
  const {
2560
2566
  repositories: { adminQueryRepository },
2567
+ middlewares: { authMiddleware },
2561
2568
  action: { executeAction }
2562
2569
  } = ctx;
2563
2570
  return async function adminFindFullAction(params) {
2564
2571
  return executeAction(
2565
2572
  async () => {
2573
+ await authMiddleware.authenticate();
2566
2574
  const admin = await adminQueryRepository.findFull(params);
2567
2575
  if (!admin) throw ServerError.notFound();
2568
2576
  return {
@@ -2728,7 +2736,7 @@ function createFileCreateAction(ctx) {
2728
2736
  repositories: { folderQueryRepository, fileCommandRepository },
2729
2737
  middlewares: { authMiddleware },
2730
2738
  action: { executeAction },
2731
- schemas
2739
+ schemas: { schemas }
2732
2740
  } = ctx;
2733
2741
  return async function fileCreateAction({
2734
2742
  formData
@@ -2813,7 +2821,7 @@ function createFileUpdateAction(ctx) {
2813
2821
  repositories: { fileQueryRepository, fileCommandRepository },
2814
2822
  middlewares: { authMiddleware },
2815
2823
  action: { executeAction },
2816
- schemas
2824
+ schemas: { schemas }
2817
2825
  } = ctx;
2818
2826
  return async function fileUpdateAction({
2819
2827
  id,
@@ -3044,7 +3052,7 @@ function createFileCreateManyAction(ctx) {
3044
3052
  repositories: { fileCommandRepository },
3045
3053
  middlewares: { authMiddleware },
3046
3054
  action: { executeAction },
3047
- schemas
3055
+ schemas: { schemas }
3048
3056
  } = ctx;
3049
3057
  return async function fileCreateManyAction({
3050
3058
  formData
@@ -3092,7 +3100,7 @@ function createFilePurgeManyAction(ctx) {
3092
3100
  repositories: { fileQueryRepository, fileCommandRepository },
3093
3101
  middlewares: { authMiddleware },
3094
3102
  action: { executeAction },
3095
- schemas
3103
+ schemas: { schemas }
3096
3104
  } = ctx;
3097
3105
  return async function filePurgeManyAction({
3098
3106
  formData
@@ -3135,7 +3143,7 @@ function createFileRestoreManyAction(ctx) {
3135
3143
  repositories: { fileCommandRepository },
3136
3144
  middlewares: { authMiddleware },
3137
3145
  action: { executeAction },
3138
- schemas
3146
+ schemas: { schemas }
3139
3147
  } = ctx;
3140
3148
  return async function fileRestoreManyAction({
3141
3149
  formData
@@ -3191,7 +3199,7 @@ function createFileSoftDeleteManyAction(ctx) {
3191
3199
  repositories: { fileQueryRepository, fileCommandRepository },
3192
3200
  middlewares: { authMiddleware },
3193
3201
  action: { executeAction },
3194
- schemas
3202
+ schemas: { schemas }
3195
3203
  } = ctx;
3196
3204
  return async function fileSoftDeleteManyAction({
3197
3205
  formData
@@ -3280,6 +3288,730 @@ function createFileFindListCardsAction(ctx) {
3280
3288
  };
3281
3289
  }
3282
3290
 
3291
+ // src/server/interfaces/actions/resources/folder/commands/create/folder-create-validator.ts
3292
+ var folderCreateValidator = (schemas) => schemas.z.object({
3293
+ // core
3294
+ key: schemas.key().unique({ table: "folders", column: "key" }),
3295
+ name: schemas.pathSegment(),
3296
+ // ----------------------------------------------------------------------------
3297
+ // relations
3298
+ // ----------------------------------------------------------------------------
3299
+ // Folder
3300
+ parentFolder: schemas.z.object({ id: schemas.id().exist({ table: "folders", column: "id" }) }).nullable()
3301
+ });
3302
+ function createFolderCreateAction(ctx) {
3303
+ const {
3304
+ repositories: { folderCommandRepository },
3305
+ middlewares: { authMiddleware },
3306
+ action: { executeAction },
3307
+ schemas: { schemas }
3308
+ } = ctx;
3309
+ return async function folderCreateAction({
3310
+ formData
3311
+ }) {
3312
+ return executeAction(
3313
+ async () => {
3314
+ await authMiddleware.authenticate();
3315
+ const combinedKey = path2.join(
3316
+ formData.parentFolder?.key ?? "",
3317
+ formData.name
3318
+ );
3319
+ const { name } = await folderCreateValidator(schemas).parseAsync({
3320
+ ...formData,
3321
+ key: combinedKey
3322
+ });
3323
+ const createdFolder = await folderCommandRepository.create({
3324
+ key: combinedKey,
3325
+ name,
3326
+ parentFolder: formData.parentFolder
3327
+ });
3328
+ return {
3329
+ i18nKey: "ok.store-ok",
3330
+ data: { folder: createdFolder }
3331
+ };
3332
+ },
3333
+ { type: "command" }
3334
+ );
3335
+ };
3336
+ }
3337
+
3338
+ // src/server/interfaces/actions/resources/folder/commands/update/folder-update-validator.ts
3339
+ var folderUpdateValidator = (schemas, id) => schemas.z.object({
3340
+ // core
3341
+ key: schemas.key().unique({
3342
+ table: "folders",
3343
+ column: "key",
3344
+ excludeSelf: { name: "id", value: id }
3345
+ }),
3346
+ name: schemas.pathSegment(),
3347
+ // ----------------------------------------------------------------------------
3348
+ // relations
3349
+ // ----------------------------------------------------------------------------
3350
+ // Folder
3351
+ parentFolder: schemas.z.object({ id: schemas.id().exist({ table: "folders", column: "id" }) }).nullable()
3352
+ });
3353
+ function createFolderUpdateAction(ctx) {
3354
+ const {
3355
+ repositories: { folderCommandRepository },
3356
+ middlewares: { authMiddleware },
3357
+ action: { executeAction },
3358
+ schemas: { schemas }
3359
+ } = ctx;
3360
+ return async function folderUpdateAction({
3361
+ id,
3362
+ formData
3363
+ }) {
3364
+ return executeAction(
3365
+ async () => {
3366
+ await authMiddleware.authenticate();
3367
+ const combinedKey = path2.join(
3368
+ formData.parentFolder?.key ?? "",
3369
+ formData.name
3370
+ );
3371
+ const { name } = await folderUpdateValidator(schemas, id).parseAsync({
3372
+ ...formData,
3373
+ key: combinedKey
3374
+ });
3375
+ const updateddFolder = await folderCommandRepository.update({
3376
+ id,
3377
+ key: combinedKey,
3378
+ name,
3379
+ parentFolder: formData.parentFolder
3380
+ });
3381
+ return {
3382
+ i18nKey: "ok.update-ok",
3383
+ data: { folder: updateddFolder }
3384
+ };
3385
+ },
3386
+ { type: "command" }
3387
+ );
3388
+ };
3389
+ }
3390
+
3391
+ // src/server/interfaces/actions/resources/folder/commands/delete/create-folder-delete-action.ts
3392
+ function createFolderDeleteAction(ctx) {
3393
+ const {
3394
+ repositories: { folderQueryRepository, folderCommandRepository },
3395
+ middlewares: { authMiddleware },
3396
+ action: { executeAction }
3397
+ } = ctx;
3398
+ return async function folderDeleteAction({ id }) {
3399
+ return executeAction(
3400
+ async () => {
3401
+ await authMiddleware.authenticate();
3402
+ const foundFolder = await folderQueryRepository.findFull({ id });
3403
+ if (!foundFolder) throw ServerError.notFound();
3404
+ if (isFolderLocked(foundFolder)) {
3405
+ throw ServerError.forbidden();
3406
+ }
3407
+ await folderCommandRepository.delete({ id });
3408
+ return {
3409
+ i18nKey: "ok.destroy-ok"
3410
+ };
3411
+ },
3412
+ { type: "command" }
3413
+ );
3414
+ };
3415
+ }
3416
+
3417
+ // src/server/interfaces/actions/resources/folder/queries/create-folder-find-full-action.ts
3418
+ function createFolderFindFullAction(ctx) {
3419
+ const {
3420
+ repositories: { folderQueryRepository, fileQueryRepository },
3421
+ middlewares: { authMiddleware },
3422
+ action: { executeAction }
3423
+ } = ctx;
3424
+ return async function folderFindFullAction(params) {
3425
+ return executeAction(
3426
+ async (translator) => {
3427
+ await authMiddleware.authenticate();
3428
+ const resolvedKey = params.key || ROOT_FOLDER_ID;
3429
+ const identity = "id" in params ? params.id : resolvedKey;
3430
+ const isAtRoot = identity === ROOT_FOLDER_ID;
3431
+ let folder = ROOT_FOLDER;
3432
+ if (isAtRoot) {
3433
+ const { items: subFolders } = await folderQueryRepository.findListCards({
3434
+ parentFolderId: ROOT_FOLDER_ID
3435
+ });
3436
+ folder.subFolders = subFolders;
3437
+ const { items: files } = await fileQueryRepository.findListCards({
3438
+ locale: translator.locale,
3439
+ folderId: ROOT_FOLDER_ID
3440
+ });
3441
+ folder.files = files;
3442
+ } else {
3443
+ const found = await folderQueryRepository.findFull(params);
3444
+ if (!found) throw ServerError.notFound();
3445
+ folder = found;
3446
+ }
3447
+ return { data: { folder } };
3448
+ },
3449
+ {
3450
+ type: "query",
3451
+ key: ["file", "findFullAction", params.id, params.key]
3452
+ }
3453
+ );
3454
+ };
3455
+ }
3456
+
3457
+ // src/server/interfaces/actions/resources/folder/queries/create-folder-find-list-cards-action.ts
3458
+ function createFolderFindListCardsAction(ctx) {
3459
+ const {
3460
+ repositories: { folderQueryRepository },
3461
+ middlewares: { authMiddleware },
3462
+ action: { executeAction }
3463
+ } = ctx;
3464
+ return async function folderFindFullAction(params) {
3465
+ return executeAction(
3466
+ async () => {
3467
+ await authMiddleware.authenticate();
3468
+ const { items, total } = await folderQueryRepository.findListCards(params);
3469
+ return {
3470
+ data: { items, total }
3471
+ };
3472
+ },
3473
+ {
3474
+ type: "query",
3475
+ key: [
3476
+ "folder",
3477
+ "findListCardsAction",
3478
+ params.searchString,
3479
+ params.parentFolderId,
3480
+ ...params.folderIds ?? [],
3481
+ params.page,
3482
+ params.pageSize
3483
+ ]
3484
+ }
3485
+ );
3486
+ };
3487
+ }
3488
+
3489
+ // src/server/interfaces/actions/resources/post/commands/create/post-create-validator.ts
3490
+ var postCreateValidator = ({
3491
+ type,
3492
+ topicId,
3493
+ schemas,
3494
+ tocItemSchema
3495
+ }) => schemas.z.object({
3496
+ type: schemas.z.enum(POST_TYPES),
3497
+ // ----------------------------------------------------------------------------
3498
+ // states
3499
+ // ----------------------------------------------------------------------------
3500
+ isLocked: schemas.z.boolean(),
3501
+ isActive: schemas.z.boolean(),
3502
+ isIndexActive: schemas.z.boolean(),
3503
+ index: schemas.positiveNumber().nullable(),
3504
+ isSlugActive: schemas.z.boolean(),
3505
+ slug: schemas.slug().unique({
3506
+ table: "posts",
3507
+ column: "slug",
3508
+ scope: [
3509
+ { name: "type", value: type, cast: "PostType" },
3510
+ ...topicId ? [{ name: "topic_id", value: topicId }] : []
3511
+ // Use for: [post], [post:category]
3512
+ ]
3513
+ }).nullable(),
3514
+ isFeatured: schemas.z.boolean(),
3515
+ isShownOnHome: schemas.z.boolean(),
3516
+ // ----------------------------------------------------------------------------
3517
+ // relations
3518
+ // ----------------------------------------------------------------------------
3519
+ // Admin
3520
+ author: schemas.singleItem({ table: "admins", column: "id" }).nullable(),
3521
+ // Picked by modal
3522
+ // Post
3523
+ topicId: schemas.id().exist({ table: "posts", column: "id" }).nullable(),
3524
+ parents: schemas.multiItems({ table: "posts", column: "id" }),
3525
+ // Picked by modal
3526
+ tags: schemas.multiItems({ table: "posts", column: "id" }),
3527
+ // Picked by modal
3528
+ relatedPosts: schemas.multiItems({ table: "posts", column: "id" }),
3529
+ // Picked by modal
3530
+ // File
3531
+ coverImage: schemas.singleItem({ table: "files", column: "id" }),
3532
+ // Picked by modal
3533
+ contentImageIds: schemas.array(
3534
+ schemas.id().exist({ table: "files", column: "id" })
3535
+ ),
3536
+ // -----------------------------------------------------------------------
3537
+ // --- custom fields
3538
+ // -----------------------------------------------------------------------
3539
+ // states
3540
+ state1: schemas.z.boolean(),
3541
+ state2: schemas.z.boolean(),
3542
+ state3: schemas.z.boolean(),
3543
+ state4: schemas.z.boolean(),
3544
+ state5: schemas.z.boolean(),
3545
+ state6: schemas.z.boolean(),
3546
+ state7: schemas.z.boolean(),
3547
+ state8: schemas.z.boolean(),
3548
+ state9: schemas.z.boolean(),
3549
+ state10: schemas.z.boolean(),
3550
+ // multi images
3551
+ images1: schemas.multiItems({ table: "files", column: "id" }),
3552
+ images2: schemas.multiItems({ table: "files", column: "id" }),
3553
+ // single images
3554
+ image1: schemas.singleItem({ table: "files", column: "id" }),
3555
+ image2: schemas.singleItem({ table: "files", column: "id" }),
3556
+ image3: schemas.singleItem({ table: "files", column: "id" }),
3557
+ image4: schemas.singleItem({ table: "files", column: "id" }),
3558
+ // text
3559
+ text1: schemas.text().nullable(),
3560
+ text2: schemas.text().nullable(),
3561
+ text3: schemas.text().nullable(),
3562
+ text4: schemas.text().nullable(),
3563
+ text5: schemas.text().nullable(),
3564
+ text6: schemas.text().nullable(),
3565
+ text7: schemas.text().nullable(),
3566
+ text8: schemas.text().nullable(),
3567
+ text9: schemas.text().nullable(),
3568
+ text10: schemas.text().nullable(),
3569
+ // json array
3570
+ data1: schemas.array(schemas.z.any()),
3571
+ data2: schemas.array(schemas.z.any()),
3572
+ data3: schemas.array(schemas.z.any()),
3573
+ data4: schemas.array(schemas.z.any()),
3574
+ // ----------------------------------------------------------------------------
3575
+ // translation
3576
+ // ----------------------------------------------------------------------------
3577
+ translations: schemas.array(
3578
+ schemas.z.object({
3579
+ locale: schemas.locale(),
3580
+ // text
3581
+ title: schemas.text().nullable(),
3582
+ subtitle: schemas.text().nullable(),
3583
+ summary: schemas.text().nullable(),
3584
+ description: schemas.text().nullable(),
3585
+ content: schemas.text().nullable(),
3586
+ // better seo
3587
+ externalLinks: schemas.array(
3588
+ schemas.z.object({
3589
+ name: schemas.text(),
3590
+ href: schemas.text()
3591
+ })
3592
+ ),
3593
+ faq: schemas.array(
3594
+ schemas.z.object({
3595
+ question: schemas.text(),
3596
+ answer: schemas.text()
3597
+ })
3598
+ ),
3599
+ toc: schemas.array(tocItemSchema),
3600
+ // extra
3601
+ readTime: schemas.positiveNumber().nullable(),
3602
+ wordCount: schemas.positiveNumber(),
3603
+ // -------------------------------------------
3604
+ // --- custom fields
3605
+ // -------------------------------------------
3606
+ // text
3607
+ text1: schemas.text().nullable(),
3608
+ text2: schemas.text().nullable(),
3609
+ text3: schemas.text().nullable(),
3610
+ text4: schemas.text().nullable(),
3611
+ text5: schemas.text().nullable(),
3612
+ text6: schemas.text().nullable(),
3613
+ text7: schemas.text().nullable(),
3614
+ text8: schemas.text().nullable(),
3615
+ text9: schemas.text().nullable(),
3616
+ text10: schemas.text().nullable(),
3617
+ // json array
3618
+ data1: schemas.array(schemas.z.any()),
3619
+ data2: schemas.array(schemas.z.any()),
3620
+ data3: schemas.array(schemas.z.any()),
3621
+ data4: schemas.array(schemas.z.any())
3622
+ })
3623
+ )
3624
+ }).transform((obj) => ({
3625
+ ...obj,
3626
+ // states
3627
+ index: obj.isIndexActive ? obj.index : null,
3628
+ slug: obj.isSlugActive ? obj.slug : null,
3629
+ // translation
3630
+ translations: obj.translations.map((t) => ({
3631
+ ...t,
3632
+ readTime: t.readTime !== 0 ? t.readTime : null
3633
+ }))
3634
+ }));
3635
+
3636
+ // src/server/interfaces/actions/resources/post/commands/create/create-post-create-action.ts
3637
+ function createPostCreateAction(ctx) {
3638
+ const {
3639
+ repositories: { postCommandRepository },
3640
+ middlewares: { authMiddleware },
3641
+ action: { executeAction },
3642
+ schemas: { schemas, tocItemSchema }
3643
+ } = ctx;
3644
+ return async function postCreateAction({
3645
+ formData
3646
+ }) {
3647
+ return executeAction(
3648
+ async () => {
3649
+ await authMiddleware.authenticate();
3650
+ const validatedPayload = await postCreateValidator({
3651
+ schemas,
3652
+ tocItemSchema,
3653
+ type: formData.type,
3654
+ topicId: formData.topicId
3655
+ }).parseAsync(formData);
3656
+ const created = await postCommandRepository.create(validatedPayload);
3657
+ return {
3658
+ i18nKey: "ok.store-ok",
3659
+ data: { post: created }
3660
+ };
3661
+ },
3662
+ { type: "command" }
3663
+ );
3664
+ };
3665
+ }
3666
+
3667
+ // src/server/interfaces/actions/resources/post/commands/update/post-update-validator.ts
3668
+ var postUpdateValidator = ({
3669
+ id,
3670
+ type,
3671
+ topicId,
3672
+ schemas,
3673
+ tocItemSchema
3674
+ }) => schemas.z.object({
3675
+ type: schemas.z.enum(POST_TYPES),
3676
+ // depth: schemas.z.number().nullable(),
3677
+ // ----------------------------------------------------------------------------
3678
+ // states
3679
+ // ----------------------------------------------------------------------------
3680
+ isLocked: schemas.z.boolean(),
3681
+ isActive: schemas.z.boolean(),
3682
+ isIndexActive: schemas.z.boolean(),
3683
+ index: schemas.positiveNumber().nullable(),
3684
+ isSlugActive: schemas.z.boolean(),
3685
+ slug: schemas.slug().unique({
3686
+ table: "posts",
3687
+ column: "slug",
3688
+ scope: [
3689
+ { name: "type", value: type, cast: "PostType" },
3690
+ ...topicId ? [{ name: "topic_id", value: topicId }] : []
3691
+ // Use for: [post], [post:category]
3692
+ ],
3693
+ excludeSelf: { name: "id", value: id }
3694
+ }).nullable(),
3695
+ isFeatured: schemas.z.boolean(),
3696
+ isShownOnHome: schemas.z.boolean(),
3697
+ // ----------------------------------------------------------------------------
3698
+ // relations
3699
+ // ----------------------------------------------------------------------------
3700
+ // Admin
3701
+ author: schemas.singleItem({ table: "admins", column: "id" }),
3702
+ // Picked by modal
3703
+ // Post
3704
+ topicId: schemas.id().exist({ table: "posts", column: "id" }).nullable(),
3705
+ parents: schemas.multiItems({ table: "posts", column: "id" }),
3706
+ // Picked by modal
3707
+ tags: schemas.multiItems({ table: "posts", column: "id" }),
3708
+ // Picked by modal
3709
+ relatedPosts: schemas.multiItems({ table: "posts", column: "id" }),
3710
+ // Picked by modal
3711
+ // File
3712
+ coverImage: schemas.singleItem({ table: "files", column: "id" }),
3713
+ // Picked by modal
3714
+ contentImageIds: schemas.array(
3715
+ schemas.id().exist({ table: "files", column: "id" })
3716
+ ),
3717
+ // -----------------------------------------------------------------------
3718
+ // --- custom fields
3719
+ // -----------------------------------------------------------------------
3720
+ // states
3721
+ state1: schemas.z.boolean(),
3722
+ state2: schemas.z.boolean(),
3723
+ state3: schemas.z.boolean(),
3724
+ state4: schemas.z.boolean(),
3725
+ state5: schemas.z.boolean(),
3726
+ state6: schemas.z.boolean(),
3727
+ state7: schemas.z.boolean(),
3728
+ state8: schemas.z.boolean(),
3729
+ state9: schemas.z.boolean(),
3730
+ state10: schemas.z.boolean(),
3731
+ // multi images
3732
+ images1: schemas.multiItems({ table: "files", column: "id" }),
3733
+ images2: schemas.multiItems({ table: "files", column: "id" }),
3734
+ // single images
3735
+ image1: schemas.singleItem({ table: "files", column: "id" }),
3736
+ image2: schemas.singleItem({ table: "files", column: "id" }),
3737
+ image3: schemas.singleItem({ table: "files", column: "id" }),
3738
+ image4: schemas.singleItem({ table: "files", column: "id" }),
3739
+ // text
3740
+ text1: schemas.text().nullable(),
3741
+ text2: schemas.text().nullable(),
3742
+ text3: schemas.text().nullable(),
3743
+ text4: schemas.text().nullable(),
3744
+ text5: schemas.text().nullable(),
3745
+ text6: schemas.text().nullable(),
3746
+ text7: schemas.text().nullable(),
3747
+ text8: schemas.text().nullable(),
3748
+ text9: schemas.text().nullable(),
3749
+ text10: schemas.text().nullable(),
3750
+ // json array
3751
+ data1: schemas.array(schemas.z.any()),
3752
+ data2: schemas.array(schemas.z.any()),
3753
+ data3: schemas.array(schemas.z.any()),
3754
+ data4: schemas.array(schemas.z.any()),
3755
+ // ----------------------------------------------------------------------------
3756
+ // translation
3757
+ // ----------------------------------------------------------------------------
3758
+ translations: schemas.array(
3759
+ schemas.z.object({
3760
+ locale: schemas.locale(),
3761
+ // text
3762
+ title: schemas.text().nullable(),
3763
+ subtitle: schemas.text().nullable(),
3764
+ summary: schemas.text().nullable(),
3765
+ description: schemas.text().nullable(),
3766
+ content: schemas.text().nullable(),
3767
+ // better seo
3768
+ externalLinks: schemas.array(
3769
+ schemas.z.object({
3770
+ name: schemas.text(),
3771
+ href: schemas.text()
3772
+ })
3773
+ ),
3774
+ faq: schemas.array(
3775
+ schemas.z.object({
3776
+ question: schemas.text(),
3777
+ answer: schemas.text()
3778
+ })
3779
+ ),
3780
+ toc: schemas.array(tocItemSchema),
3781
+ // extra
3782
+ readTime: schemas.positiveNumber().nullable(),
3783
+ wordCount: schemas.positiveNumber(),
3784
+ // -------------------------------------------
3785
+ // --- custom fields
3786
+ // -------------------------------------------
3787
+ // text
3788
+ text1: schemas.text().nullable(),
3789
+ text2: schemas.text().nullable(),
3790
+ text3: schemas.text().nullable(),
3791
+ text4: schemas.text().nullable(),
3792
+ text5: schemas.text().nullable(),
3793
+ text6: schemas.text().nullable(),
3794
+ text7: schemas.text().nullable(),
3795
+ text8: schemas.text().nullable(),
3796
+ text9: schemas.text().nullable(),
3797
+ text10: schemas.text().nullable(),
3798
+ // json array
3799
+ data1: schemas.array(schemas.z.any()),
3800
+ data2: schemas.array(schemas.z.any()),
3801
+ data3: schemas.array(schemas.z.any()),
3802
+ data4: schemas.array(schemas.z.any())
3803
+ })
3804
+ )
3805
+ }).transform((obj) => ({
3806
+ ...obj,
3807
+ // states
3808
+ index: obj.isIndexActive ? obj.index : null,
3809
+ slug: obj.isSlugActive ? obj.slug : null,
3810
+ // translation
3811
+ translations: obj.translations.map((t) => ({
3812
+ ...t,
3813
+ readTime: t.readTime !== 0 ? t.readTime : null
3814
+ }))
3815
+ }));
3816
+
3817
+ // src/server/interfaces/actions/resources/post/commands/update/create-post-update-action.ts
3818
+ function createPostUpdateAction(ctx) {
3819
+ const {
3820
+ repositories: { postCommandRepository },
3821
+ middlewares: { authMiddleware },
3822
+ action: { executeAction },
3823
+ schemas: { schemas, tocItemSchema }
3824
+ } = ctx;
3825
+ return async function postUpdateAction({
3826
+ id,
3827
+ formData
3828
+ }) {
3829
+ return executeAction(
3830
+ async () => {
3831
+ await authMiddleware.authenticate();
3832
+ const validatedPayload = await postUpdateValidator({
3833
+ id,
3834
+ type: formData.type,
3835
+ topicId: formData.topicId,
3836
+ schemas,
3837
+ tocItemSchema
3838
+ }).parseAsync(formData);
3839
+ const updatedPost = await postCommandRepository.update({
3840
+ id,
3841
+ ...validatedPayload
3842
+ });
3843
+ return {
3844
+ i18nKey: "ok.update-ok",
3845
+ data: { post: updatedPost }
3846
+ };
3847
+ },
3848
+ { type: "command" }
3849
+ );
3850
+ };
3851
+ }
3852
+
3853
+ // src/server/interfaces/actions/resources/post/commands/delete/create-post-delete-action.ts
3854
+ function createPostDeleteAction(ctx) {
3855
+ const {
3856
+ repositories: { postQueryRepository, postCommandRepository },
3857
+ middlewares: { authMiddleware },
3858
+ action: { executeAction }
3859
+ } = ctx;
3860
+ return async function postDeleteAction({ id }) {
3861
+ return executeAction(
3862
+ async () => {
3863
+ await authMiddleware.authenticate();
3864
+ const post = await postQueryRepository.find({ id });
3865
+ if (!post) throw ServerError.notFound();
3866
+ await postCommandRepository.delete({ id: post.id });
3867
+ return {
3868
+ i18nKey: "ok.destroy-ok"
3869
+ };
3870
+ },
3871
+ { type: "command" }
3872
+ );
3873
+ };
3874
+ }
3875
+
3876
+ // src/server/interfaces/actions/resources/post/queries/create-post-find-action.ts
3877
+ function createPostFindAction(ctx) {
3878
+ const {
3879
+ repositories: { postQueryRepository },
3880
+ action: { executeAction }
3881
+ } = ctx;
3882
+ return async function postFindAction(params) {
3883
+ return executeAction(
3884
+ async () => {
3885
+ const found = await postQueryRepository.find(params);
3886
+ if (!found) throw ServerError.notFound();
3887
+ return {
3888
+ data: { post: found }
3889
+ };
3890
+ },
3891
+ {
3892
+ type: "query",
3893
+ key: [
3894
+ "post",
3895
+ "findAction",
3896
+ params.id,
3897
+ params.type,
3898
+ params.slug,
3899
+ params.isActive,
3900
+ params.topicSlug
3901
+ ]
3902
+ }
3903
+ );
3904
+ };
3905
+ }
3906
+
3907
+ // src/server/interfaces/actions/resources/post/queries/create-post-find-full-action.ts
3908
+ function createPostFindFullAction(ctx) {
3909
+ const {
3910
+ repositories: { postQueryRepository },
3911
+ action: { executeAction }
3912
+ } = ctx;
3913
+ return async function postFindFullAction(params) {
3914
+ return executeAction(
3915
+ async () => {
3916
+ const found = await postQueryRepository.findFull(params);
3917
+ if (!found) throw ServerError.notFound();
3918
+ return {
3919
+ data: { post: found }
3920
+ };
3921
+ },
3922
+ {
3923
+ type: "query",
3924
+ key: [
3925
+ "post",
3926
+ "findFullAction",
3927
+ params.id,
3928
+ params.type,
3929
+ params.slug,
3930
+ params.isActive,
3931
+ params.topicSlug
3932
+ ]
3933
+ }
3934
+ );
3935
+ };
3936
+ }
3937
+
3938
+ // src/server/interfaces/actions/resources/post/queries/create-post-find-list-cards-action.ts
3939
+ function createPostFindListCardsAction(ctx) {
3940
+ const {
3941
+ repositories: { postQueryRepository },
3942
+ middlewares: { authMiddleware },
3943
+ action: { executeAction }
3944
+ } = ctx;
3945
+ return async function postFindFullAction(params) {
3946
+ return executeAction(
3947
+ async ({ locale }) => {
3948
+ await authMiddleware.authenticate();
3949
+ const { items, total } = await postQueryRepository.findListCards({
3950
+ ...params,
3951
+ locale
3952
+ });
3953
+ return {
3954
+ data: { items, total }
3955
+ };
3956
+ },
3957
+ {
3958
+ type: "query",
3959
+ key: [
3960
+ "post",
3961
+ "findListCardsAction",
3962
+ params.searchString,
3963
+ params.type,
3964
+ params.isActive,
3965
+ params.isIndexActive,
3966
+ params.isSlugActive,
3967
+ params.isFeatured,
3968
+ params.isShownOnHome,
3969
+ params.state1,
3970
+ params.state2,
3971
+ params.state3,
3972
+ params.state4,
3973
+ params.state5,
3974
+ params.state6,
3975
+ params.state7,
3976
+ params.state8,
3977
+ params.state9,
3978
+ params.state10,
3979
+ params.topicId,
3980
+ params.topicSlug,
3981
+ params.categoryId,
3982
+ params.categorySlug,
3983
+ ...params.postIds ?? [],
3984
+ ...params.excludeIds ?? [],
3985
+ params.page,
3986
+ params.pageSize
3987
+ ]
3988
+ }
3989
+ );
3990
+ };
3991
+ }
3992
+
3993
+ // src/server/interfaces/actions/resources/post/queries/create-post-find-many-action.ts
3994
+ function createPostFindManyAction(ctx) {
3995
+ const {
3996
+ repositories: { postQueryRepository },
3997
+ action: { executeAction }
3998
+ } = ctx;
3999
+ return async function postFindManyAction(params) {
4000
+ return executeAction(
4001
+ async () => {
4002
+ const found = await postQueryRepository.findMany(params);
4003
+ return {
4004
+ data: { posts: found }
4005
+ };
4006
+ },
4007
+ {
4008
+ type: "query",
4009
+ key: ["post", "findManyAction", params.type, params.topicId]
4010
+ }
4011
+ );
4012
+ };
4013
+ }
4014
+
3283
4015
  // src/server/applications/auth/create-auth-use-cases.ts
3284
4016
  function createAuthUseCases({
3285
4017
  prisma,
@@ -3459,4 +4191,4 @@ function createForgotPasswordEmail({
3459
4191
  };
3460
4192
  }
3461
4193
 
3462
- export { ADMIN_ORDER_BY, ORDER_BY, POST_ORDER_BY, ServerError, createAdminCommandRepository, createAdminCreateAction, createAdminDeleteAction, createAdminFindFullAction, createAdminFindListCardsAction, createAdminQueryRepository, createAdminRefreshTokenCommandRepository, createAdminRefreshTokenDeleteAction, createAdminRefreshTokenFindManyAction, createAdminRefreshTokenQueryRepository, createAdminUpdateAction, createArgon2Service, createAuthMiddleware, createAuthUseCases, createCache, createCacheResult, createChangePasswordAction, createCookieService, createCryptoService, createEmailUnverifiedAction, createEmailVerificationEmail, createExecuteAction, createExecuteApi, createExist, createFileCommandRepository, createFileCreateAction, createFileCreateManyAction, createFileFindFullAction, createFileFindListCardsAction, createFilePurgeManyAction, createFileQueryRepository, createFileRestoreManyAction, createFileSchema, createFileSoftDeleteAction, createFileSoftDeleteManyAction, createFileUpdateAction, createFolderCommandRepository, createFolderQueryRepository, createForgotPasswordAction, createForgotPasswordEmail, createIpRateLimiter, createJwtService, createMultiFileSchema, createPostCommandRepository, createPostQueryRepository, createRenderEmailTemplate, createResetPasswordAction, createSchemas, createSendEmail, createSeoMetadataCommandRepository, createSignInAction, createSignOutAction, createTocItemSchema, createTransporter, createUnique, createVerifyAccessToken, createVerifyAction, createVerifyEmailAction, createVerifyRefreshToken, createZod, normalizeCacheKey };
4194
+ export { ADMIN_ORDER_BY, ORDER_BY, POST_ORDER_BY, ServerError, createAdminCommandRepository, createAdminCreateAction, createAdminDeleteAction, createAdminFindFullAction, createAdminFindListCardsAction, createAdminQueryRepository, createAdminRefreshTokenCommandRepository, createAdminRefreshTokenDeleteAction, createAdminRefreshTokenFindManyAction, createAdminRefreshTokenQueryRepository, createAdminUpdateAction, createArgon2Service, createAuthMiddleware, createAuthUseCases, createCache, createCacheResult, createChangePasswordAction, createCookieService, createCryptoService, createEmailUnverifiedAction, createEmailVerificationEmail, createExecuteAction, createExecuteApi, createExist, createFileCommandRepository, createFileCreateAction, createFileCreateManyAction, createFileFindFullAction, createFileFindListCardsAction, createFilePurgeManyAction, createFileQueryRepository, createFileRestoreManyAction, createFileSchema, createFileSoftDeleteAction, createFileSoftDeleteManyAction, createFileUpdateAction, createFolderCommandRepository, createFolderCreateAction, createFolderDeleteAction, createFolderFindFullAction, createFolderFindListCardsAction, createFolderQueryRepository, createFolderUpdateAction, createForgotPasswordAction, createForgotPasswordEmail, createIpRateLimiter, createJwtService, createMultiFileSchema, createPostCommandRepository, createPostCreateAction, createPostDeleteAction, createPostFindAction, createPostFindFullAction, createPostFindListCardsAction, createPostFindManyAction, createPostQueryRepository, createPostUpdateAction, createRenderEmailTemplate, createResetPasswordAction, createSchemas, createSendEmail, createSeoMetadataCommandRepository, createSignInAction, createSignOutAction, createTocItemSchema, createTransporter, createUnique, createVerifyAccessToken, createVerifyAction, createVerifyEmailAction, createVerifyRefreshToken, createZod, normalizeCacheKey };