@lupinum/ginko-server 0.0.0-stage → 0.18.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/CHANGELOG.md +13 -0
- package/LICENSE +21 -0
- package/README.md +176 -2
- package/convex/_generated/api.d.ts +185 -0
- package/convex/_generated/api.js +23 -0
- package/convex/_generated/dataModel.d.ts +60 -0
- package/convex/_generated/server.d.ts +162 -0
- package/convex/_generated/server.js +101 -0
- package/convex/account.ts +110 -0
- package/convex/agent.ts +814 -0
- package/convex/auth.config.ts +4 -0
- package/convex/auth.ts +62 -0
- package/convex/backup.ts +94 -0
- package/convex/betterAuth/_generated/api.ts +56 -0
- package/convex/betterAuth/_generated/component.ts +431 -0
- package/convex/betterAuth/_generated/dataModel.ts +60 -0
- package/convex/betterAuth/_generated/server.ts +169 -0
- package/convex/betterAuth/adapter.ts +7 -0
- package/convex/betterAuth/convex.config.ts +3 -0
- package/convex/betterAuth/schema.ts +102 -0
- package/convex/betterAuth/schemaMetadata.ts +697 -0
- package/convex/betterAuth/schemaOptions.ts +13 -0
- package/convex/betterAuth/schemaPlugins.ts +13 -0
- package/convex/bundle.ts +183 -0
- package/convex/changes.ts +136 -0
- package/convex/cleanup.ts +44 -0
- package/convex/connect.ts +143 -0
- package/convex/convex.config.ts +7 -0
- package/convex/crons.ts +14 -0
- package/convex/demo.ts +72 -0
- package/convex/entries.ts +1770 -0
- package/convex/facts.ts +129 -0
- package/convex/files.ts +631 -0
- package/convex/http.ts +21 -0
- package/convex/image.ts +45 -0
- package/convex/images.ts +54 -0
- package/convex/invites.ts +227 -0
- package/convex/lib/access.ts +180 -0
- package/convex/lib/agentTools.ts +331 -0
- package/convex/lib/content.ts +317 -0
- package/convex/lib/corpus.ts +83 -0
- package/convex/lib/diff.ts +50 -0
- package/convex/lib/fail.ts +27 -0
- package/convex/lib/files.ts +70 -0
- package/convex/lib/history.ts +103 -0
- package/convex/lib/i18n.ts +52 -0
- package/convex/lib/input.ts +57 -0
- package/convex/lib/library.ts +28 -0
- package/convex/lib/lifecycle.ts +100 -0
- package/convex/lib/list.ts +112 -0
- package/convex/lib/migrations.ts +126 -0
- package/convex/lib/names.ts +56 -0
- package/convex/lib/pending.ts +84 -0
- package/convex/lib/policy.ts +155 -0
- package/convex/lib/publicness.ts +87 -0
- package/convex/lib/reminders.ts +27 -0
- package/convex/lib/search.ts +132 -0
- package/convex/lib/siteUrl.ts +95 -0
- package/convex/lib/status.ts +109 -0
- package/convex/lib/translation.ts +56 -0
- package/convex/lib/trees.ts +43 -0
- package/convex/lib/write.ts +296 -0
- package/convex/mail.ts +136 -0
- package/convex/members.ts +129 -0
- package/convex/migrations.ts +105 -0
- package/convex/navigation.ts +276 -0
- package/convex/ops.ts +50 -0
- package/convex/proposals.ts +753 -0
- package/convex/refresh.ts +163 -0
- package/convex/release.ts +435 -0
- package/convex/reminders.ts +116 -0
- package/convex/retention.ts +121 -0
- package/convex/routes/bundle.ts +62 -0
- package/convex/routes/connect.ts +80 -0
- package/convex/routes/export.ts +23 -0
- package/convex/routes/file.ts +34 -0
- package/convex/routes/key.ts +53 -0
- package/convex/routes/mcp.ts +300 -0
- package/convex/routes/release.ts +66 -0
- package/convex/routes/upload.ts +94 -0
- package/convex/schema.ts +443 -0
- package/convex/search.ts +58 -0
- package/convex/seed.ts +624 -0
- package/convex/siteDeletion.ts +78 -0
- package/convex/sites.ts +393 -0
- package/convex/tasks.ts +51 -0
- package/convex/tsconfig.json +27 -0
- package/convex/uploads.ts +429 -0
- package/convex/uploadsNode.ts +86 -0
- package/convex/views.ts +111 -0
- package/i18n/de.json +364 -0
- package/i18n/en.json +364 -0
- package/i18n/es.json +364 -0
- package/i18n/fr.json +364 -0
- package/package.json +45 -3
package/convex/facts.ts
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// Facts (`facts` in the site config, `:fact{name="…"}` in texts) as editors and agents need them: what each one
|
|
2
|
+
// shows now, which texts quote it, and a release that would leave a quote without its fact.
|
|
3
|
+
import type { Label } from '@lupinum/ginko'
|
|
4
|
+
import { effectiveProfile, factCopiesInMarkdown, factNames, factValues, msg, resolveEntry, todayIn, type FactValue, type Schema, type SchemaChange } from '@lupinum/ginko/internal'
|
|
5
|
+
import { v } from 'convex/values'
|
|
6
|
+
import type { Doc, Id } from './_generated/dataModel'
|
|
7
|
+
import { query, type QueryCtx } from './_generated/server'
|
|
8
|
+
import { actorFor } from './lib/access'
|
|
9
|
+
import type { Fields } from '@lupinum/ginko'
|
|
10
|
+
import { factQuotesOf, fieldLabelAt, markdownTextsOf, type Data } from './lib/content'
|
|
11
|
+
import { labelOf } from './entries'
|
|
12
|
+
|
|
13
|
+
/** One text that quotes a fact, in the form the Studio's "used in" list reads (UsedInList). */
|
|
14
|
+
export interface FactQuote { entry: Id<'entries'>; brick: string; title: string; paths: string[]; fieldLabels: (Label | null)[]; deleted: false; state: 'draft' | 'live' }
|
|
15
|
+
|
|
16
|
+
/** A fact for the Studio: its value (FactValue), the label of its brick and the entry the Studio links to. */
|
|
17
|
+
export type StudioFact = FactValue & { brickLabel: Label; entry: Id<'entries'> | null }
|
|
18
|
+
|
|
19
|
+
/** The single bricks' data in `locale`, as the website serves it, and their entry IDs. */
|
|
20
|
+
async function singlesIn(ctx: QueryCtx, site: Doc<'sites'>, schema: Schema, locale: string) {
|
|
21
|
+
const data: Record<string, Record<string, unknown>> = {}
|
|
22
|
+
const entries: Record<string, Id<'entries'>> = {}
|
|
23
|
+
for (const brick of new Set(factNames(schema.components).map((name) => name.split('.')[0]!))) {
|
|
24
|
+
const row = await ctx.db.query('entries').withIndex('by_site_brick_deleted', (q) => q.eq('site', site._id).eq('brick', brick).eq('deletedAt', undefined)).first()
|
|
25
|
+
if (!row || !Object.hasOwn(schema.bricks, brick)) continue
|
|
26
|
+
entries[brick] = row._id
|
|
27
|
+
data[brick] = resolveEntry(schema, brick, { id: row._id, order: row.order, data: row.data as Data, prints: row.prints }, { locale, files: () => undefined }).data
|
|
28
|
+
}
|
|
29
|
+
return { data, entries }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Every fact of the site with what it shows in `locale` (default: the main language), today. */
|
|
33
|
+
export async function factsOf(ctx: QueryCtx, site: Doc<'sites'>, locale?: string): Promise<StudioFact[]> {
|
|
34
|
+
const schema = site.schema as Schema
|
|
35
|
+
const shown = locale && schema.locales.includes(locale) ? locale : schema.locales[0]!
|
|
36
|
+
const { data, entries } = await singlesIn(ctx, site, schema, shown)
|
|
37
|
+
return factValues(schema, data, shown, todayIn(schema.timeZone)).map((fact) => ({ ...fact, brickLabel: schema.bricks[fact.brick]!.label, entry: entries[fact.brick] ?? null }))
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** A fact value written as plain text in a Markdown field: where the fact should be quoted instead. */
|
|
41
|
+
export interface FactCopyFound { path: string; text: string; fact: string }
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The fact values that `data` writes as plain text into the Markdown fields of `fields` (in the form a tool sends them
|
|
45
|
+
* or as stored), each fact once per field. Only texts with the `page` profile can quote a fact, so only those count.
|
|
46
|
+
* Reads nothing when the site has no facts or `data` no such text; `facts` lets a batch read the facts once.
|
|
47
|
+
*/
|
|
48
|
+
export async function factCopiesIn(ctx: QueryCtx, site: Doc<'sites'>, fields: Fields, data: Data, facts?: () => Promise<StudioFact[]>): Promise<FactCopyFound[]> {
|
|
49
|
+
const texts = markdownTextsOf(fields, data).filter(({ field }) => effectiveProfile(field) === 'page')
|
|
50
|
+
if (!texts.length || !factNames((site.schema as Schema).components).length) return []
|
|
51
|
+
const values = await (facts ? facts() : factsOf(ctx, site))
|
|
52
|
+
const found: FactCopyFound[] = []
|
|
53
|
+
for (const { path, text } of texts) {
|
|
54
|
+
for (const copy of factCopiesInMarkdown(text, values)) {
|
|
55
|
+
if (!found.some((f) => f.path === path && f.fact === copy.name)) found.push({ path, text: copy.text, fact: copy.name })
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return found
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** For the assistant (English): which values a write copied and how to quote them instead; '' when it copied none. */
|
|
62
|
+
export function factCopyNote<T extends FactCopyFound>(found: readonly T[], item?: (copy: T) => string): string {
|
|
63
|
+
if (!found.length) return ''
|
|
64
|
+
const shown = found.slice(0, 5).map((f) => `“${f.text}” in ${item ? `${item(f)} ` : ''}${f.path} → :fact{name="${f.fact}"}`)
|
|
65
|
+
const more = found.length > shown.length ? ` and ${found.length - shown.length} more` : ''
|
|
66
|
+
return `Note: these texts copy values the site keeps as facts: ${shown.join('; ')}${more}. Quote the fact instead, so the text stays right when the value changes.`
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* The texts that quote facts, by fact: every entry that is not removed (drafts too, they become pages), every
|
|
71
|
+
* Markdown field and language. Only `names` when given. Sites are small; this reads each brick with texts once.
|
|
72
|
+
*/
|
|
73
|
+
export async function quotesOf(ctx: QueryCtx, site: Doc<'sites'>, names?: ReadonlySet<string>): Promise<Map<string, FactQuote[]>> {
|
|
74
|
+
const schema = site.schema as Schema
|
|
75
|
+
const out = new Map<string, FactQuote[]>()
|
|
76
|
+
const hasText = (fields: Schema['bricks'][string]['fields']): boolean =>
|
|
77
|
+
Object.values(fields).some((field) => !field.retired && (field.type === 'markdown' || (field.type === 'list' && hasText(field.of))))
|
|
78
|
+
for (const [key, brick] of Object.entries(schema.bricks)) {
|
|
79
|
+
if (brick.retired || brick.source === 'files' || !hasText(brick.fields)) continue
|
|
80
|
+
const rows = await ctx.db.query('entries').withIndex('by_site_brick_deleted', (q) => q.eq('site', site._id).eq('brick', key).eq('deletedAt', undefined)).collect()
|
|
81
|
+
for (const row of rows) {
|
|
82
|
+
for (const [name, paths] of factQuotesOf(brick.fields, row.data as Data)) {
|
|
83
|
+
if (names && !names.has(name)) continue
|
|
84
|
+
const quote: FactQuote = {
|
|
85
|
+
entry: row._id, brick: key, title: labelOf(schema, key, row.data as Data), paths,
|
|
86
|
+
fieldLabels: paths.map((path) => fieldLabelAt(schema, key, path)), deleted: false, state: row.state ?? 'live',
|
|
87
|
+
}
|
|
88
|
+
out.set(name, [...(out.get(name) ?? []), quote])
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return out
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* The facts that `next` drops while texts still quote them: each would leave an empty spot on every page that shows
|
|
97
|
+
* one of those texts. A release refuses them; `pnpm local:dev` shows them as warnings (SPEC 5.3).
|
|
98
|
+
*/
|
|
99
|
+
export async function droppedFactsInUse(ctx: QueryCtx, site: Doc<'sites'>, next: Schema): Promise<SchemaChange[]> {
|
|
100
|
+
const kept = new Set(factNames(next.components))
|
|
101
|
+
const dropped = new Set(factNames((site.schema as Schema).components).filter((name) => !kept.has(name)))
|
|
102
|
+
if (!dropped.size) return []
|
|
103
|
+
const quotes = await quotesOf(ctx, site, dropped)
|
|
104
|
+
return [...quotes].map(([fact, texts]) => {
|
|
105
|
+
const described = msg('diff.factInUse', { fact, count: texts.length, texts: texts.map((t) => `„${t.title}“`).join(', ') })
|
|
106
|
+
const fix = msg('diff.fix.factInUse')
|
|
107
|
+
return { path: `facts.${fact}`, kind: 'factInUse', ...described, fix: fix.message, fixMsg: { key: fix.key } }
|
|
108
|
+
})
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** The Studio's facts: what each one shows in `locale` and where it comes from (the fact chip and its panel). */
|
|
112
|
+
export const values = query({
|
|
113
|
+
args: { site: v.string(), locale: v.optional(v.string()) },
|
|
114
|
+
handler: async (ctx, args): Promise<StudioFact[]> => {
|
|
115
|
+
const actor = await actorFor(ctx, args.site)
|
|
116
|
+
return factsOf(ctx, actor.site, args.locale)
|
|
117
|
+
},
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
/** The texts that quote the facts of `brick` (its single entry's form lists them under each fact field). */
|
|
121
|
+
export const uses = query({
|
|
122
|
+
args: { site: v.string(), brick: v.string() },
|
|
123
|
+
handler: async (ctx, args): Promise<Record<string, FactQuote[]>> => {
|
|
124
|
+
const actor = await actorFor(ctx, args.site)
|
|
125
|
+
const names = new Set(factNames((actor.site.schema as Schema).components).filter((name) => name.startsWith(`${args.brick}.`)))
|
|
126
|
+
if (!names.size) return {}
|
|
127
|
+
return Object.fromEntries(await quotesOf(ctx, actor.site, names))
|
|
128
|
+
},
|
|
129
|
+
})
|