@adatechnology/content-module 0.1.0 → 0.2.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/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { PostStatus, TagCount, ContentModuleConfig, ClockPort, ContentHooks, ContentImageStoragePort, LoggerPort, ContentFeedConfig, SitemapEntry, PostEventType, Post, CreatePostInput, UpdatePostInput, PublishPostInput, ListPostsQuery, Paginated, PostSummary, PublicPost, ListPublishedPostsQuery, PublicPostSummary } from '@adatechnology/content-contracts';
1
+ import { PostStatus, PostSortField, PostCounts, TagCount, ContentModuleConfig, ClockPort, ContentHooks, ContentImageStoragePort, LoggerPort, ContentFeedConfig, SitemapEntry, PostEventType, Post, CreatePostInput, UpdatePostInput, PublishPostInput, ListPostsQuery, Paginated, PostSummary, PublicPost, ListPublishedPostsQuery, PublicPostSummary, RecurrenceRule, CreateRecurrenceInput, UpdateRecurrenceInput, RepublishPostInput, SaveAsTemplateInput, CreateFromTemplateInput, RecurrenceFrequency } from '@adatechnology/content-contracts';
2
2
  import * as drizzle_orm_pg_core from 'drizzle-orm/pg-core';
3
3
  import { PgDatabase, PgQueryResultHKT } from 'drizzle-orm/pg-core';
4
4
  import * as drizzle_orm from 'drizzle-orm';
@@ -75,6 +75,25 @@ declare const posts: drizzle_orm_pg_core.PgTableWithColumns<{
75
75
  }, {}, {
76
76
  length: 120;
77
77
  }>;
78
+ shortId: drizzle_orm_pg_core.PgColumn<{
79
+ name: "short_id";
80
+ tableName: "posts";
81
+ dataType: "string";
82
+ columnType: "PgVarchar";
83
+ data: string;
84
+ driverParam: string;
85
+ notNull: true;
86
+ hasDefault: false;
87
+ isPrimaryKey: false;
88
+ isAutoincrement: false;
89
+ hasRuntimeDefault: false;
90
+ enumValues: [string, ...string[]];
91
+ baseColumn: never;
92
+ identity: undefined;
93
+ generated: undefined;
94
+ }, {}, {
95
+ length: 6;
96
+ }>;
78
97
  title: drizzle_orm_pg_core.PgColumn<{
79
98
  name: "title";
80
99
  tableName: "posts";
@@ -211,6 +230,25 @@ declare const posts: drizzle_orm_pg_core.PgTableWithColumns<{
211
230
  }, {}, {}, drizzle_orm.ColumnBuilderExtraConfig>;
212
231
  size: undefined;
213
232
  }>;
233
+ tagLabels: drizzle_orm_pg_core.PgColumn<{
234
+ name: "tag_labels";
235
+ tableName: "posts";
236
+ dataType: "json";
237
+ columnType: "PgJsonb";
238
+ data: Record<string, string>;
239
+ driverParam: unknown;
240
+ notNull: true;
241
+ hasDefault: true;
242
+ isPrimaryKey: false;
243
+ isAutoincrement: false;
244
+ hasRuntimeDefault: false;
245
+ enumValues: undefined;
246
+ baseColumn: never;
247
+ identity: undefined;
248
+ generated: undefined;
249
+ }, {}, {
250
+ $type: Record<string, string>;
251
+ }>;
214
252
  status: drizzle_orm_pg_core.PgColumn<{
215
253
  name: "status";
216
254
  tableName: "posts";
@@ -230,6 +268,23 @@ declare const posts: drizzle_orm_pg_core.PgTableWithColumns<{
230
268
  }, {}, {
231
269
  length: 12;
232
270
  }>;
271
+ isTemplate: drizzle_orm_pg_core.PgColumn<{
272
+ name: "is_template";
273
+ tableName: "posts";
274
+ dataType: "boolean";
275
+ columnType: "PgBoolean";
276
+ data: boolean;
277
+ driverParam: boolean;
278
+ notNull: true;
279
+ hasDefault: true;
280
+ isPrimaryKey: false;
281
+ isAutoincrement: false;
282
+ hasRuntimeDefault: false;
283
+ enumValues: undefined;
284
+ baseColumn: never;
285
+ identity: undefined;
286
+ generated: undefined;
287
+ }, {}, {}>;
233
288
  publishedAt: drizzle_orm_pg_core.PgColumn<{
234
289
  name: "published_at";
235
290
  tableName: "posts";
@@ -379,6 +434,187 @@ declare const posts: drizzle_orm_pg_core.PgTableWithColumns<{
379
434
  }>;
380
435
  type PostRow = typeof posts.$inferSelect;
381
436
  type NewPostRow = typeof posts.$inferInsert;
437
+ declare const recurrenceRules: drizzle_orm_pg_core.PgTableWithColumns<{
438
+ name: "recurrence_rules";
439
+ schema: "content";
440
+ columns: {
441
+ id: drizzle_orm_pg_core.PgColumn<{
442
+ name: "id";
443
+ tableName: "recurrence_rules";
444
+ dataType: "string";
445
+ columnType: "PgUUID";
446
+ data: string;
447
+ driverParam: string;
448
+ notNull: true;
449
+ hasDefault: true;
450
+ isPrimaryKey: true;
451
+ isAutoincrement: false;
452
+ hasRuntimeDefault: false;
453
+ enumValues: undefined;
454
+ baseColumn: never;
455
+ identity: undefined;
456
+ generated: undefined;
457
+ }, {}, {}>;
458
+ companyId: drizzle_orm_pg_core.PgColumn<{
459
+ name: "company_id";
460
+ tableName: "recurrence_rules";
461
+ dataType: "string";
462
+ columnType: "PgUUID";
463
+ data: string;
464
+ driverParam: string;
465
+ notNull: true;
466
+ hasDefault: false;
467
+ isPrimaryKey: false;
468
+ isAutoincrement: false;
469
+ hasRuntimeDefault: false;
470
+ enumValues: undefined;
471
+ baseColumn: never;
472
+ identity: undefined;
473
+ generated: undefined;
474
+ }, {}, {}>;
475
+ templateId: drizzle_orm_pg_core.PgColumn<{
476
+ name: "template_id";
477
+ tableName: "recurrence_rules";
478
+ dataType: "string";
479
+ columnType: "PgUUID";
480
+ data: string;
481
+ driverParam: string;
482
+ notNull: true;
483
+ hasDefault: false;
484
+ isPrimaryKey: false;
485
+ isAutoincrement: false;
486
+ hasRuntimeDefault: false;
487
+ enumValues: undefined;
488
+ baseColumn: never;
489
+ identity: undefined;
490
+ generated: undefined;
491
+ }, {}, {}>;
492
+ frequency: drizzle_orm_pg_core.PgColumn<{
493
+ name: "frequency";
494
+ tableName: "recurrence_rules";
495
+ dataType: "string";
496
+ columnType: "PgVarchar";
497
+ data: string;
498
+ driverParam: string;
499
+ notNull: true;
500
+ hasDefault: false;
501
+ isPrimaryKey: false;
502
+ isAutoincrement: false;
503
+ hasRuntimeDefault: false;
504
+ enumValues: [string, ...string[]];
505
+ baseColumn: never;
506
+ identity: undefined;
507
+ generated: undefined;
508
+ }, {}, {
509
+ length: 10;
510
+ }>;
511
+ anchorDay: drizzle_orm_pg_core.PgColumn<{
512
+ name: "anchor_day";
513
+ tableName: "recurrence_rules";
514
+ dataType: "number";
515
+ columnType: "PgInteger";
516
+ data: number;
517
+ driverParam: string | number;
518
+ notNull: true;
519
+ hasDefault: false;
520
+ isPrimaryKey: false;
521
+ isAutoincrement: false;
522
+ hasRuntimeDefault: false;
523
+ enumValues: undefined;
524
+ baseColumn: never;
525
+ identity: undefined;
526
+ generated: undefined;
527
+ }, {}, {}>;
528
+ isActive: drizzle_orm_pg_core.PgColumn<{
529
+ name: "is_active";
530
+ tableName: "recurrence_rules";
531
+ dataType: "boolean";
532
+ columnType: "PgBoolean";
533
+ data: boolean;
534
+ driverParam: boolean;
535
+ notNull: true;
536
+ hasDefault: true;
537
+ isPrimaryKey: false;
538
+ isAutoincrement: false;
539
+ hasRuntimeDefault: false;
540
+ enumValues: undefined;
541
+ baseColumn: never;
542
+ identity: undefined;
543
+ generated: undefined;
544
+ }, {}, {}>;
545
+ nextRunAt: drizzle_orm_pg_core.PgColumn<{
546
+ name: "next_run_at";
547
+ tableName: "recurrence_rules";
548
+ dataType: "date";
549
+ columnType: "PgTimestamp";
550
+ data: Date;
551
+ driverParam: string;
552
+ notNull: true;
553
+ hasDefault: false;
554
+ isPrimaryKey: false;
555
+ isAutoincrement: false;
556
+ hasRuntimeDefault: false;
557
+ enumValues: undefined;
558
+ baseColumn: never;
559
+ identity: undefined;
560
+ generated: undefined;
561
+ }, {}, {}>;
562
+ lastRunAt: drizzle_orm_pg_core.PgColumn<{
563
+ name: "last_run_at";
564
+ tableName: "recurrence_rules";
565
+ dataType: "date";
566
+ columnType: "PgTimestamp";
567
+ data: Date;
568
+ driverParam: string;
569
+ notNull: false;
570
+ hasDefault: false;
571
+ isPrimaryKey: false;
572
+ isAutoincrement: false;
573
+ hasRuntimeDefault: false;
574
+ enumValues: undefined;
575
+ baseColumn: never;
576
+ identity: undefined;
577
+ generated: undefined;
578
+ }, {}, {}>;
579
+ lastPostId: drizzle_orm_pg_core.PgColumn<{
580
+ name: "last_post_id";
581
+ tableName: "recurrence_rules";
582
+ dataType: "string";
583
+ columnType: "PgUUID";
584
+ data: string;
585
+ driverParam: string;
586
+ notNull: false;
587
+ hasDefault: false;
588
+ isPrimaryKey: false;
589
+ isAutoincrement: false;
590
+ hasRuntimeDefault: false;
591
+ enumValues: undefined;
592
+ baseColumn: never;
593
+ identity: undefined;
594
+ generated: undefined;
595
+ }, {}, {}>;
596
+ createdAt: drizzle_orm_pg_core.PgColumn<{
597
+ name: "created_at";
598
+ tableName: "recurrence_rules";
599
+ dataType: "date";
600
+ columnType: "PgTimestamp";
601
+ data: Date;
602
+ driverParam: string;
603
+ notNull: true;
604
+ hasDefault: true;
605
+ isPrimaryKey: false;
606
+ isAutoincrement: false;
607
+ hasRuntimeDefault: false;
608
+ enumValues: undefined;
609
+ baseColumn: never;
610
+ identity: undefined;
611
+ generated: undefined;
612
+ }, {}, {}>;
613
+ };
614
+ dialect: "pg";
615
+ }>;
616
+ type RecurrenceRow = typeof recurrenceRules.$inferSelect;
617
+ type NewRecurrenceRow = typeof recurrenceRules.$inferInsert;
382
618
 
383
619
  /**
384
620
  * Copyright (c) 2026 Ada Technology. MIT License.
@@ -393,8 +629,12 @@ type PostAdminListQuery = {
393
629
  readonly page: number;
394
630
  readonly pageSize: number;
395
631
  readonly status?: PostStatus;
396
- readonly tag?: string;
632
+ /** Basta o post ter UMA das tags. */
633
+ readonly tags?: readonly string[];
397
634
  readonly search?: string;
635
+ readonly isTemplate?: boolean;
636
+ readonly sort?: PostSortField;
637
+ readonly order?: 'asc' | 'desc';
398
638
  readonly now: Date;
399
639
  };
400
640
  type PostPublicListQuery = {
@@ -418,6 +658,26 @@ interface PostStorePort {
418
658
  readonly companyId: string;
419
659
  readonly slug: string;
420
660
  }): Promise<PostRow | undefined>;
661
+ findByShortId(params: {
662
+ readonly companyId: string;
663
+ readonly shortId: string;
664
+ }): Promise<PostRow | undefined>;
665
+ findPublicByShortId(params: {
666
+ readonly companyId: string;
667
+ readonly shortId: string;
668
+ readonly now: Date;
669
+ }): Promise<PostRow | undefined>;
670
+ /** Post público que já teve este slug (link antigo). */
671
+ findPublicByFormerSlug(params: {
672
+ readonly companyId: string;
673
+ readonly slug: string;
674
+ readonly now: Date;
675
+ }): Promise<PostRow | undefined>;
676
+ recordFormerSlug(params: {
677
+ readonly companyId: string;
678
+ readonly postId: string;
679
+ readonly slug: string;
680
+ }): Promise<void>;
421
681
  findPublicBySlug(params: {
422
682
  readonly companyId: string;
423
683
  readonly slug: string;
@@ -430,13 +690,57 @@ interface PostStorePort {
430
690
  }): Promise<PostRow | undefined>;
431
691
  listForAdmin(query: PostAdminListQuery): Promise<PostPage>;
432
692
  listPublic(query: PostPublicListQuery): Promise<PostPage>;
693
+ countByStatus(params: {
694
+ readonly companyId: string;
695
+ readonly now: Date;
696
+ }): Promise<PostCounts>;
697
+ /**
698
+ * Marca como publicado (sem tocar `updated_at`) até `limit` posts agendados vencidos, de qualquer
699
+ * empresa, e devolve só o que ESTA chamada marcou. Atômico e seguro com execuções concorrentes
700
+ * (`FOR UPDATE SKIP LOCKED` no Postgres): dois ciclos nunca marcam nem notificam o mesmo post.
701
+ */
702
+ claimDueScheduled(params: {
703
+ readonly now: Date;
704
+ readonly limit: number;
705
+ }): Promise<readonly PostRow[]>;
433
706
  listTags(params: {
434
707
  readonly companyId: string;
435
708
  readonly publicAt?: Date;
436
709
  }): Promise<readonly TagCount[]>;
437
710
  }
711
+ /** Persistência das regras de recorrência. Mesma regra: toda operação do painel recebe `companyId`. */
712
+ interface RecurrenceStorePort {
713
+ create(values: NewRecurrenceRow): Promise<RecurrenceRow>;
714
+ findById(params: {
715
+ readonly companyId: string;
716
+ readonly id: string;
717
+ }): Promise<RecurrenceRow | undefined>;
718
+ list(params: {
719
+ readonly companyId: string;
720
+ }): Promise<readonly RecurrenceRow[]>;
721
+ update(params: {
722
+ readonly companyId: string;
723
+ readonly id: string;
724
+ readonly values: Partial<NewRecurrenceRow>;
725
+ }): Promise<RecurrenceRow | undefined>;
726
+ remove(params: {
727
+ readonly companyId: string;
728
+ readonly id: string;
729
+ }): Promise<boolean>;
730
+ /**
731
+ * Trava (`FOR UPDATE SKIP LOCKED`) até `limit` regras ativas vencidas, de qualquer empresa, e roda
732
+ * `handle` para cada uma na mesma transação: o que `handle` devolver vira o novo estado da regra.
733
+ * Falha em `handle` desfaz só a regra dela e a deixa vencida para o próximo ciclo.
734
+ */
735
+ processDue(params: {
736
+ readonly now: Date;
737
+ readonly limit: number;
738
+ readonly handle: (rule: RecurrenceRow) => Promise<Partial<NewRecurrenceRow>>;
739
+ }): Promise<number>;
740
+ }
438
741
  type ContentDependencies = {
439
742
  readonly posts: PostStorePort;
743
+ readonly recurrences: RecurrenceStorePort;
440
744
  readonly config: ContentModuleConfig;
441
745
  readonly clock: ClockPort;
442
746
  readonly hooks?: ContentHooks;
@@ -495,10 +799,13 @@ declare abstract class PostUseCaseBase {
495
799
  protected now(): Date;
496
800
  protected findOrFail(reference: PostReference): Promise<PostRow>;
497
801
  protected save(reference: PostReference, values: Partial<NewPostRow>, event: PostEventType): Promise<Post>;
802
+ /** Id curto livre na empresa; a colisão (~1 em 2 bilhões) só repete o sorteio. */
803
+ protected generateShortId(companyId: string): Promise<string>;
498
804
  protected readingTime(body: string): number;
499
805
  protected assertSlugAvailable(companyId: string, slug: string, ownId?: string): Promise<void>;
500
806
  /** `titulo`, `titulo-2`, `titulo-3`… Sequencial de propósito: cada tentativa depende da anterior. */
501
807
  protected generateSlug(companyId: string, title: string): Promise<string>;
808
+ protected uniqueSlug(companyId: string, base: string): Promise<string>;
502
809
  }
503
810
  declare class CreatePostUseCase extends PostUseCaseBase {
504
811
  execute(params: {
@@ -545,6 +852,11 @@ declare class ListPostsUseCase extends PostUseCaseBase {
545
852
  declare class GetPublishedPostBySlugUseCase {
546
853
  private readonly dependencies;
547
854
  constructor(dependencies: ContentDependencies);
855
+ /**
856
+ * `slug` aceita o endereço canônico `<shortId>-<slug>`, o slug atual e slug antigo. O id curto
857
+ * manda: título/slug editado depois não quebra link compartilhado. O host compara `buildPostRef`
858
+ * do resultado com o pedido e redireciona (301) quando forem diferentes.
859
+ */
548
860
  execute(params: {
549
861
  readonly companyId: string;
550
862
  readonly slug: string;
@@ -572,6 +884,121 @@ declare class ListTagsUseCase {
572
884
  }): Promise<readonly TagCount[]>;
573
885
  }
574
886
 
887
+ /**
888
+ * Copyright (c) 2026 Ada Technology. MIT License.
889
+ *
890
+ * Regras de recorrência do painel: cada regra publica, na frequência escolhida, um post novo copiado
891
+ * de um modelo. Quem executa é o `publishDue`.
892
+ */
893
+
894
+ declare abstract class RecurrenceUseCaseBase {
895
+ protected readonly dependencies: ContentDependencies;
896
+ constructor(dependencies: ContentDependencies);
897
+ protected toRule(row: RecurrenceRow): Promise<RecurrenceRule>;
898
+ protected findOrFail(params: {
899
+ companyId: string;
900
+ id: string;
901
+ }): Promise<RecurrenceRow>;
902
+ }
903
+ declare class CreateRecurrenceUseCase extends RecurrenceUseCaseBase {
904
+ execute(params: {
905
+ readonly companyId: string;
906
+ readonly input: CreateRecurrenceInput;
907
+ }): Promise<RecurrenceRule>;
908
+ }
909
+ declare class ListRecurrencesUseCase extends RecurrenceUseCaseBase {
910
+ execute(params: {
911
+ readonly companyId: string;
912
+ }): Promise<readonly RecurrenceRule[]>;
913
+ }
914
+ declare class UpdateRecurrenceUseCase extends RecurrenceUseCaseBase {
915
+ /** Pausar/retomar e remarcar a próxima execução. */
916
+ execute(params: {
917
+ readonly companyId: string;
918
+ readonly id: string;
919
+ readonly input: UpdateRecurrenceInput;
920
+ }): Promise<RecurrenceRule>;
921
+ }
922
+ declare class RemoveRecurrenceUseCase extends RecurrenceUseCaseBase {
923
+ /** Apaga só a regra: os posts que ela já publicou continuam no ar. */
924
+ execute(params: {
925
+ readonly companyId: string;
926
+ readonly id: string;
927
+ }): Promise<void>;
928
+ }
929
+
930
+ /**
931
+ * Copyright (c) 2026 Ada Technology. MIT License.
932
+ *
933
+ * Republicar e publicar no horário. `publishDue` é o que o host chama num intervalo: marca como
934
+ * publicado o que estava agendado e já venceu, e materializa as recorrências vencidas.
935
+ */
936
+
937
+ declare class RepublishPostUseCase extends PostUseCaseBase {
938
+ /**
939
+ * Muda a data de um post JÁ publicado, mantendo o MESMO endereço. É a opção segura para SEO: o
940
+ * link antigo (compartilhado, indexado, com backlinks) continua valendo e não nasce conteúdo
941
+ * duplicado. Data futura é recusada — o post sairia do ar até lá e o leitor veria 404.
942
+ */
943
+ execute(params: PostReference & {
944
+ readonly input?: RepublishPostInput;
945
+ }): Promise<Post>;
946
+ }
947
+ type PublishDueResult = {
948
+ readonly published: number;
949
+ readonly materialized: number;
950
+ };
951
+ declare class PublishDueUseCase extends PostUseCaseBase {
952
+ /**
953
+ * Idempotente e seguro com várias instâncias chamando ao mesmo tempo: cada post/regra é reclamado
954
+ * por uma só execução. Sem trabalho vencido, não faz nada. `now` existe para teste e reprocesso.
955
+ */
956
+ execute(params?: {
957
+ readonly now?: Date;
958
+ readonly limit?: number;
959
+ }): Promise<PublishDueResult>;
960
+ private materializeRecurrences;
961
+ /** Um post publicado agora a partir do modelo; a regra avança para a próxima data futura. */
962
+ private materialize;
963
+ }
964
+
965
+ /**
966
+ * Copyright (c) 2026 Ada Technology. MIT License.
967
+ *
968
+ * Modelos de post: salvar um post como modelo e criar um post novo a partir de um modelo. Modelo é
969
+ * post com `isTemplate`: nunca vai ao ar, não aparece na lista de posts e não tem endereço público.
970
+ */
971
+
972
+ declare abstract class TemplateUseCaseBase extends PostUseCaseBase {
973
+ protected insertCopy(params: {
974
+ readonly companyId: string;
975
+ readonly slug: string;
976
+ readonly title: string;
977
+ readonly source: PostRow;
978
+ readonly isTemplate: boolean;
979
+ readonly status?: string;
980
+ readonly publishedAt?: Date;
981
+ }): Promise<Post>;
982
+ }
983
+ declare class SaveAsTemplateUseCase extends TemplateUseCaseBase {
984
+ /** Copia o post (qualquer status) para um modelo. O original não muda. */
985
+ execute(params: PostReference & {
986
+ readonly input?: SaveAsTemplateInput;
987
+ }): Promise<Post>;
988
+ }
989
+ declare class CreateFromTemplateUseCase extends TemplateUseCaseBase {
990
+ /** Cria um RASCUNHO novo com o conteúdo do modelo, pronto para editar e publicar. */
991
+ execute(params: PostReference & {
992
+ readonly input?: CreateFromTemplateInput;
993
+ }): Promise<Post>;
994
+ }
995
+ declare class CountPostsUseCase extends PostUseCaseBase {
996
+ /** Números das abas do painel, numa consulta só. */
997
+ execute(params: {
998
+ readonly companyId: string;
999
+ }): Promise<PostCounts>;
1000
+ }
1001
+
575
1002
  /**
576
1003
  * Copyright (c) 2026 Ada Technology. MIT License.
577
1004
  *
@@ -609,6 +1036,7 @@ type ContentModuleProviders = {
609
1036
  readonly logger?: LoggerPort;
610
1037
  /** Troca a persistência (ex.: dublê em memória num teste do host). Padrão: Drizzle sobre `db`. */
611
1038
  readonly postStore?: PostStorePort;
1039
+ readonly recurrenceStore?: RecurrenceStorePort;
612
1040
  };
613
1041
  type CreateContentModuleParams = {
614
1042
  readonly db?: ContentDatabase;
@@ -628,6 +1056,16 @@ type ContentModule = {
628
1056
  readonly getPublishedPostBySlug: GetPublishedPostBySlugUseCase;
629
1057
  readonly listPublishedPosts: ListPublishedPostsUseCase;
630
1058
  readonly listTags: ListTagsUseCase;
1059
+ readonly countPosts: CountPostsUseCase;
1060
+ readonly saveAsTemplate: SaveAsTemplateUseCase;
1061
+ readonly createFromTemplate: CreateFromTemplateUseCase;
1062
+ readonly republishPost: RepublishPostUseCase;
1063
+ readonly createRecurrence: CreateRecurrenceUseCase;
1064
+ readonly listRecurrences: ListRecurrencesUseCase;
1065
+ readonly updateRecurrence: UpdateRecurrenceUseCase;
1066
+ readonly removeRecurrence: RemoveRecurrenceUseCase;
1067
+ /** O host chama num intervalo (ver `startContentScheduler`): publica o agendado vencido e as recorrências. */
1068
+ readonly publishDue: PublishDueUseCase;
631
1069
  /** Capacidade por ausência: sem `providers.imageStorage`, não existe. */
632
1070
  readonly uploadCoverImage?: UploadCoverImageUseCase;
633
1071
  /** Sem `config.feed`, feed e sitemap não existem. */
@@ -701,6 +1139,25 @@ declare class PostRepository implements PostStorePort {
701
1139
  slug: string;
702
1140
  now: Date;
703
1141
  }): Promise<PostRow | undefined>;
1142
+ findByShortId(params: {
1143
+ companyId: string;
1144
+ shortId: string;
1145
+ }): Promise<PostRow | undefined>;
1146
+ findPublicByShortId(params: {
1147
+ companyId: string;
1148
+ shortId: string;
1149
+ now: Date;
1150
+ }): Promise<PostRow | undefined>;
1151
+ findPublicByFormerSlug(params: {
1152
+ companyId: string;
1153
+ slug: string;
1154
+ now: Date;
1155
+ }): Promise<PostRow | undefined>;
1156
+ recordFormerSlug(params: {
1157
+ companyId: string;
1158
+ postId: string;
1159
+ slug: string;
1160
+ }): Promise<void>;
704
1161
  update(params: {
705
1162
  companyId: string;
706
1163
  id: string;
@@ -708,12 +1165,47 @@ declare class PostRepository implements PostStorePort {
708
1165
  }): Promise<PostRow | undefined>;
709
1166
  listForAdmin(query: PostAdminListQuery): Promise<PostPage>;
710
1167
  listPublic(query: PostPublicListQuery): Promise<PostPage>;
1168
+ countByStatus(params: {
1169
+ companyId: string;
1170
+ now: Date;
1171
+ }): Promise<PostCounts>;
1172
+ claimDueScheduled(params: {
1173
+ now: Date;
1174
+ limit: number;
1175
+ }): Promise<readonly PostRow[]>;
711
1176
  listTags(params: {
712
1177
  companyId: string;
713
1178
  publicAt?: Date;
714
1179
  }): Promise<readonly TagCount[]>;
715
1180
  }
716
1181
 
1182
+ declare class RecurrenceRepository implements RecurrenceStorePort {
1183
+ private readonly db;
1184
+ constructor(db: ContentDatabase);
1185
+ create(values: NewRecurrenceRow): Promise<RecurrenceRow>;
1186
+ findById(params: {
1187
+ companyId: string;
1188
+ id: string;
1189
+ }): Promise<RecurrenceRow | undefined>;
1190
+ list(params: {
1191
+ companyId: string;
1192
+ }): Promise<readonly RecurrenceRow[]>;
1193
+ update(params: {
1194
+ companyId: string;
1195
+ id: string;
1196
+ values: Partial<NewRecurrenceRow>;
1197
+ }): Promise<RecurrenceRow | undefined>;
1198
+ remove(params: {
1199
+ companyId: string;
1200
+ id: string;
1201
+ }): Promise<boolean>;
1202
+ processDue(params: {
1203
+ now: Date;
1204
+ limit: number;
1205
+ handle: (rule: RecurrenceRow) => Promise<Partial<NewRecurrenceRow>>;
1206
+ }): Promise<number>;
1207
+ }
1208
+
717
1209
  /**
718
1210
  * Copyright (c) 2026 Ada Technology. MIT License.
719
1211
  */
@@ -740,4 +1232,55 @@ declare function createInMemoryPostStore(seed?: PostRow[]): PostStorePort & {
740
1232
  readonly rows: PostRow[];
741
1233
  };
742
1234
 
743
- export { ArchivePostUseCase, BuildFeedUseCase, CONTENT_MIGRATIONS_TABLE, COVER_IMAGE, type ContentDatabase, type ContentDependencies, type ContentModule, type ContentModuleProviders, type CreateContentModuleParams, type CreateContentRoutesParams, CreatePostUseCase, type DrizzleMigrateFunction, FEED_FORMAT, type FeedFormat, GetPostUseCase, GetPublishedPostBySlugUseCase, ListPostsUseCase, ListPublishedPostsUseCase, ListSitemapEntriesUseCase, ListTagsUseCase, type NewPostRow, type PostAdminListQuery, type PostPage, type PostPublicListQuery, type PostReference, PostRepository, type PostRow, type PostStorePort, type PublicCompanyResolverPort, PublishPostUseCase, type RunContentMigrationsParams, TAG_SCOPE, type TagScope, UnpublishPostUseCase, UpdatePostUseCase, type UploadCoverImageParams, type UploadCoverImageResult, UploadCoverImageUseCase, contentMigrationsFolder, contentSchema, createContentModule, createContentRoutes, createInMemoryPostStore, posts, runContentMigrations };
1235
+ /**
1236
+ * Copyright (c) 2026 Ada Technology. MIT License.
1237
+ *
1238
+ * Datas da recorrência, sempre em UTC: o instante de cada execução não depende do fuso do servidor.
1239
+ */
1240
+
1241
+ declare function nextOccurrence(params: {
1242
+ frequency: RecurrenceFrequency;
1243
+ from: Date;
1244
+ anchorDay: number;
1245
+ }): Date;
1246
+ /**
1247
+ * Primeira ocorrência estritamente depois de `now`. Servidor parado três semanas publica UM post ao
1248
+ * voltar, não três: as ocorrências perdidas são puladas, nunca emitidas em rajada.
1249
+ */
1250
+ declare function nextOccurrenceAfter(params: {
1251
+ frequency: RecurrenceFrequency;
1252
+ from: Date;
1253
+ anchorDay: number;
1254
+ now: Date;
1255
+ }): Date;
1256
+
1257
+ /**
1258
+ * Copyright (c) 2026 Ada Technology. MIT License.
1259
+ */
1260
+
1261
+ declare const DEFAULT_SCHEDULER_INTERVAL_MS = 60000;
1262
+ type StartContentSchedulerParams = {
1263
+ readonly module: ContentModule;
1264
+ /** Padrão: 1 minuto. */
1265
+ readonly intervalMs?: number;
1266
+ readonly logger?: LoggerPort;
1267
+ };
1268
+ /**
1269
+ * Chama `publishDue` num intervalo, com guarda de execução única neste processo: se um ciclo ainda
1270
+ * está rodando, o próximo tick é pulado em vez de empilhar. Entre instâncias, quem garante é o
1271
+ * `FOR UPDATE SKIP LOCKED` do store. Erro de um ciclo é logado e o seguinte tenta de novo.
1272
+ * Devolve a função que para o agendador (chame no desligamento).
1273
+ */
1274
+ declare function startContentScheduler(params: StartContentSchedulerParams): () => void;
1275
+
1276
+ /**
1277
+ * Copyright (c) 2026 Ada Technology. MIT License.
1278
+ *
1279
+ * Dublê em memória do `RecurrenceStorePort`: mesmas regras, sem transação (o teste é de um processo só).
1280
+ */
1281
+
1282
+ declare function createInMemoryRecurrenceStore(): RecurrenceStorePort & {
1283
+ readonly rows: RecurrenceRow[];
1284
+ };
1285
+
1286
+ export { ArchivePostUseCase, BuildFeedUseCase, CONTENT_MIGRATIONS_TABLE, COVER_IMAGE, type ContentDatabase, type ContentDependencies, type ContentModule, type ContentModuleProviders, CountPostsUseCase, type CreateContentModuleParams, type CreateContentRoutesParams, CreateFromTemplateUseCase, CreatePostUseCase, CreateRecurrenceUseCase, DEFAULT_SCHEDULER_INTERVAL_MS, type DrizzleMigrateFunction, FEED_FORMAT, type FeedFormat, GetPostUseCase, GetPublishedPostBySlugUseCase, ListPostsUseCase, ListPublishedPostsUseCase, ListRecurrencesUseCase, ListSitemapEntriesUseCase, ListTagsUseCase, type NewPostRow, type NewRecurrenceRow, type PostAdminListQuery, type PostPage, type PostPublicListQuery, type PostReference, PostRepository, type PostRow, type PostStorePort, type PublicCompanyResolverPort, type PublishDueResult, PublishDueUseCase, PublishPostUseCase, RecurrenceRepository, type RecurrenceRow, type RecurrenceStorePort, RemoveRecurrenceUseCase, RepublishPostUseCase, type RunContentMigrationsParams, SaveAsTemplateUseCase, type StartContentSchedulerParams, TAG_SCOPE, type TagScope, UnpublishPostUseCase, UpdatePostUseCase, UpdateRecurrenceUseCase, type UploadCoverImageParams, type UploadCoverImageResult, UploadCoverImageUseCase, contentMigrationsFolder, contentSchema, createContentModule, createContentRoutes, createInMemoryPostStore, createInMemoryRecurrenceStore, nextOccurrence, nextOccurrenceAfter, posts, recurrenceRules, runContentMigrations, startContentScheduler };