@crombolo/data 0.57.0 → 0.58.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crombolo/data",
3
- "version": "0.57.0",
3
+ "version": "0.58.0",
4
4
  "description": "Internal to crombolo, with no compatibility promise: use @crombolo/crombolo. SQLite and Postgres storage for crombolo: schema, migrations and repositories.",
5
5
  "license": "MIT",
6
6
  "author": "Crombolo",
@@ -29,7 +29,7 @@
29
29
  "access": "public"
30
30
  },
31
31
  "dependencies": {
32
- "@crombolo/core": "0.57.0",
32
+ "@crombolo/core": "0.58.0",
33
33
  "kysely": "0.29.6"
34
34
  }
35
35
  }
package/src/index.ts CHANGED
@@ -79,6 +79,7 @@ export * from './schema/content-checkpoint.ts'
79
79
  export * from './schema/content-events.ts'
80
80
  export * from './schema/content-notifications.ts'
81
81
  export * from './schema/content-seed.ts'
82
+ export * from './schema/content-type-seo.ts'
82
83
  export * from './schema/created-packages.ts'
83
84
  export * from './schema/delivery-member-tokens.ts'
84
85
  export * from './schema/diagnostics.ts'
@@ -18,6 +18,7 @@ import {
18
18
  type PropertyGroupModel,
19
19
  PropertyGroupType,
20
20
  type PropertyTypeModel,
21
+ type SeoMapping,
21
22
  type SiteSearchLevel,
22
23
  SystemNodes,
23
24
  variationFlags,
@@ -61,6 +62,23 @@ async function propertySignature(db: Db, contentTypeNodeId: number): Promise<str
61
62
  }
62
63
 
63
64
  /** How a property's site-search setting is stored: its level, or `off`. */
65
+ /** A type's search and sharing values as stored: JSON, or null when it sets none. */
66
+ function seoColumn(mapping: SeoMapping | null): string | null {
67
+ const set = Object.entries(mapping ?? {}).filter(
68
+ ([, value]) => typeof value === 'string' && value !== '',
69
+ )
70
+ return set.length > 0 ? JSON.stringify(Object.fromEntries(set)) : null
71
+ }
72
+
73
+ function seoFromColumn(value: unknown): SeoMapping | null {
74
+ if (typeof value !== 'string' || value === '') return null
75
+ try {
76
+ return JSON.parse(value) as SeoMapping
77
+ } catch {
78
+ return null
79
+ }
80
+ }
81
+
64
82
  function siteSearchColumn(value: SiteSearchLevel | false | undefined): string {
65
83
  return value === false ? 'off' : (value ?? 'normal')
66
84
  }
@@ -368,6 +386,12 @@ export class ContentTypeRepository {
368
386
  .set({ site_search: bool(aggregate.siteSearch) })
369
387
  .where('node_id', '=', nodeId)
370
388
  .execute()
389
+ if (aggregate.seo !== undefined)
390
+ await tx.q
391
+ .updateTable('content_type')
392
+ .set({ seo: seoColumn(aggregate.seo) })
393
+ .where('node_id', '=', nodeId)
394
+ .execute()
371
395
  if (aggregate.siteSettings !== undefined)
372
396
  await tx.q
373
397
  .updateTable('content_type')
@@ -689,6 +713,24 @@ export class ContentTypeRepository {
689
713
  return this.byKeys(rows.map((r) => String(r.unique_id)))
690
714
  }
691
715
 
716
+ /** Each live type's search and sharing values, by alias, for the types that set any (story 317). */
717
+ async seoMappings(): Promise<Record<string, SeoMapping>> {
718
+ const rows = await this.#db.q
719
+ .selectFrom('content_type as ct')
720
+ .innerJoin('node as n', 'n.id', 'ct.node_id')
721
+ .select(['ct.alias', 'ct.seo'])
722
+ .where('ct.retired_at', 'is', null)
723
+ .where('ct.seo', 'is not', null)
724
+ .where('n.node_object_type', '=', this.#objectType)
725
+ .execute()
726
+ const out: Record<string, SeoMapping> = {}
727
+ for (const row of rows) {
728
+ const mapping = seoFromColumn(row.seo)
729
+ if (mapping) out[String(row.alias)] = mapping
730
+ }
731
+ return out
732
+ }
733
+
692
734
  /** Every live type's alias by its key, without loading the types themselves. */
693
735
  async aliasesByKey(): Promise<Map<string, string>> {
694
736
  const rows = await this.#db.q
@@ -835,6 +877,17 @@ export class ContentTypeRepository {
835
877
  return out
836
878
  }
837
879
 
880
+ /** Sets a type's search and sharing values alone (story 317); null clears them. */
881
+ async setSeo(typeKey: string, mapping: SeoMapping | null): Promise<void> {
882
+ const node = await this.#nodes.byKey(typeKey)
883
+ if (!node || node.objectType !== this.#objectType) return
884
+ await this.#db.q
885
+ .updateTable('content_type')
886
+ .set({ seo: seoColumn(mapping) })
887
+ .where('node_id', '=', node.id)
888
+ .execute()
889
+ }
890
+
838
891
  async contentCount(typeKey: string): Promise<number> {
839
892
  const node = await this.#nodes.byKey(typeKey)
840
893
  if (!node) return 0
@@ -931,6 +984,7 @@ export class ContentTypeRepository {
931
984
  'ct.since_version',
932
985
  'ct.site_search',
933
986
  'ct.site_settings',
987
+ 'ct.seo',
934
988
  'ct.form_key',
935
989
  'ss.version as since_v',
936
990
  'ss.revision as since_r',
@@ -1063,6 +1117,7 @@ export class ContentTypeRepository {
1063
1117
  allowedInLibrary: fromDbBool(type.allow_in_library),
1064
1118
  siteSearch: fromDbBool(type.site_search),
1065
1119
  siteSettings: fromDbBool(type.site_settings),
1120
+ seo: seoFromColumn(type.seo),
1066
1121
  formKey: (type.form_key as string | null) ?? null,
1067
1122
  collectionKey: type.list_view ? normaliseUuid(String(type.list_view)) : null,
1068
1123
  cleanup: {
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Migration 070 — where a content type's search and sharing values come from
3
+ * (story 317): its `[seo]` table, kept as JSON beside the type.
4
+ */
5
+ import type { Db } from '../database.ts'
6
+ import type { Migration } from '../migrations.ts'
7
+ import { schemaOps } from '../schema-ops.ts'
8
+ import { STATE_TRUSTED_SIGNERS } from './trusted-signers.ts'
9
+
10
+ export const STATE_CONTENT_TYPE_SEO = '{7c3e15d2-0070-4a96-b2e8-5f1d0c9a7070}'
11
+
12
+ export const contentTypeSeoMigration: Migration = {
13
+ from: STATE_TRUSTED_SIGNERS,
14
+ to: STATE_CONTENT_TYPE_SEO,
15
+ name: 'AddContentTypeSeo',
16
+ kind: 'expand',
17
+ release: '0.58.0',
18
+ async up(db: Db) {
19
+ await schemaOps(db).addColumn('content_type', 'seo', db.dialect.types.text)
20
+ },
21
+ }
@@ -34,6 +34,7 @@ import { contentCheckpointMigration } from './content-checkpoint.ts'
34
34
  import { contentEditingMigration } from './content-editing.ts'
35
35
  import { contentEventsMigration } from './content-events.ts'
36
36
  import { contentNotificationsMigration } from './content-notifications.ts'
37
+ import { contentTypeSeoMigration } from './content-type-seo.ts'
37
38
  import { createdPackagesMigration } from './created-packages.ts'
38
39
  import { deliveryMemberTokensMigration } from './delivery-member-tokens.ts'
39
40
  import { diagnosticsMigration } from './diagnostics.ts'
@@ -153,4 +154,5 @@ export const cromboloPlan = new MigrationPlan([
153
154
  extensionSettingsMigration,
154
155
  bundleKindMigration,
155
156
  trustedSignersMigration,
157
+ contentTypeSeoMigration,
156
158
  ])
package/src/tables.gen.ts CHANGED
@@ -253,6 +253,7 @@ export interface CoreTables {
253
253
  node_id: Generated<number>
254
254
  prevent_cleanup: Bool
255
255
  retired_at: Timestamp | null
256
+ seo: string | null
256
257
  since_state_id: number | null
257
258
  since_version: string | null
258
259
  site_search: Default<Bool>