@crombolo/data 0.51.0 → 0.52.2
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.
|
|
3
|
+
"version": "0.52.2",
|
|
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",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"access": "public"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@crombolo/core": "0.
|
|
31
|
+
"@crombolo/core": "0.52.2",
|
|
32
32
|
"kysely": "0.29.6"
|
|
33
33
|
}
|
|
34
34
|
}
|
package/src/cluster.ts
CHANGED
|
@@ -9,10 +9,16 @@ import { sql } from './query.ts'
|
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* `views` is a code change, not a data one: a template was written, so every
|
|
12
|
-
* node has to look at its views tree again.
|
|
13
|
-
* published cache; this one makes a node take a new snapshot.
|
|
12
|
+
* node has to look at its views tree again. `schema` and `content` invalidate
|
|
13
|
+
* the published cache; this one makes a node take a new snapshot. `public-files`
|
|
14
|
+
* is a site's `public/` folder changed by something a watcher cannot see, so a
|
|
15
|
+
* node lists it again (story 285).
|
|
14
16
|
*/
|
|
15
|
-
export type CacheInstructionKind = 'schema' | 'content' | 'components'
|
|
17
|
+
export type CacheInstructionKind = 'schema' | 'content' | 'components' | 'public-files'
|
|
18
|
+
|
|
19
|
+
/** Kinds about a site's files, not published content: they move no checkpoint. */
|
|
20
|
+
const isFileChange = (kind: CacheInstructionKind) =>
|
|
21
|
+
kind === 'components' || kind === 'public-files'
|
|
16
22
|
|
|
17
23
|
export interface CacheInstruction {
|
|
18
24
|
id: number
|
|
@@ -65,7 +71,7 @@ export function instructionEffects(
|
|
|
65
71
|
kind: CacheInstructionKind,
|
|
66
72
|
payload: Record<string, unknown>,
|
|
67
73
|
): InstructionEffects {
|
|
68
|
-
if (kind
|
|
74
|
+
if (isFileChange(kind)) return { pages: false, media: 'keep' }
|
|
69
75
|
if (kind === 'schema') return { pages: true, media: 'clear' }
|
|
70
76
|
const fields = Object.keys(payload)
|
|
71
77
|
const keys = strings(payload.media)
|
|
@@ -123,7 +129,7 @@ export async function appendCacheInstruction(
|
|
|
123
129
|
instruction: { kind: CacheInstructionKind; payload?: Record<string, unknown>; by?: string },
|
|
124
130
|
): Promise<number | null> {
|
|
125
131
|
return db.transaction(async (tx) => {
|
|
126
|
-
const checkpoint = instruction.kind
|
|
132
|
+
const checkpoint = isFileChange(instruction.kind) ? null : await advanceCheckpoint(tx)
|
|
127
133
|
await tx.q
|
|
128
134
|
.insertInto('cache_instruction')
|
|
129
135
|
.values({
|
|
@@ -223,6 +229,15 @@ export async function latestCacheInstructionId(db: Db): Promise<number> {
|
|
|
223
229
|
return Number(row?.n ?? 0)
|
|
224
230
|
}
|
|
225
231
|
|
|
232
|
+
/** The oldest instruction still held, or undefined when there are none. */
|
|
233
|
+
export async function oldestCacheInstructionId(db: Db): Promise<number | undefined> {
|
|
234
|
+
const row = await db.q
|
|
235
|
+
.selectFrom('cache_instruction')
|
|
236
|
+
.select((eb) => eb.fn.min('id').as('n'))
|
|
237
|
+
.executeTakeFirst()
|
|
238
|
+
return row?.n === null || row?.n === undefined ? undefined : Number(row.n)
|
|
239
|
+
}
|
|
240
|
+
|
|
226
241
|
export async function cacheInstructionsAfter(db: Db, afterId: number): Promise<CacheInstruction[]> {
|
|
227
242
|
const rows = await db.q
|
|
228
243
|
.selectFrom('cache_instruction')
|
package/src/content-query.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* properties".
|
|
8
8
|
*/
|
|
9
9
|
import {
|
|
10
|
+
dateFromText,
|
|
10
11
|
ObjectTypes,
|
|
11
12
|
STORAGE_COLUMN,
|
|
12
13
|
type StartNodes,
|
|
@@ -130,8 +131,8 @@ export function parseContentQuery(body: unknown): ParsedQuery {
|
|
|
130
131
|
const out: { from?: Date; to?: Date } = {}
|
|
131
132
|
for (const end of ['from', 'to'] as const) {
|
|
132
133
|
if (value[end] === undefined) continue
|
|
133
|
-
const date = typeof value[end] === 'string' ?
|
|
134
|
-
if (!date
|
|
134
|
+
const date = typeof value[end] === 'string' ? dateFromText(value[end] as string) : undefined
|
|
135
|
+
if (!date) problems.push(`"${field}.${end}" must be a date.`)
|
|
135
136
|
else out[end] = date
|
|
136
137
|
}
|
|
137
138
|
return out
|
|
@@ -633,8 +634,8 @@ function comparable(value: unknown, storage: ValueStorageTypeName, alias: string
|
|
|
633
634
|
return n
|
|
634
635
|
}
|
|
635
636
|
if (storage === 'Date') {
|
|
636
|
-
const date =
|
|
637
|
-
if (
|
|
637
|
+
const date = dateFromText(String(value))
|
|
638
|
+
if (!date) throw new ContentQueryRefused(`"${alias}" compares dates.`)
|
|
638
639
|
return DbDate.toDb(date)
|
|
639
640
|
}
|
|
640
641
|
if (typeof value === 'object') throw new ContentQueryRefused(`"${alias}" compares text.`)
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
type DocumentValue,
|
|
15
15
|
type DocumentVariant,
|
|
16
16
|
type DocumentVersionSummary,
|
|
17
|
+
dateFromText,
|
|
17
18
|
variesByCulture as flagVariesByCulture,
|
|
18
19
|
type MediaItemAccess,
|
|
19
20
|
normaliseUuid,
|
|
@@ -2420,12 +2421,8 @@ export class DocumentRepository {
|
|
|
2420
2421
|
if (value instanceof Date) return DbDate.toDb(value)
|
|
2421
2422
|
// The date pickers send wall-clock time with no zone ("2026-01-02 03:04:05");
|
|
2422
2423
|
// it is kept as that wall-clock time, not shifted by the server's zone.
|
|
2423
|
-
const
|
|
2424
|
-
|
|
2425
|
-
const date = new Date(
|
|
2426
|
-
naive ? `${text.replace(' ', 'T')}${text.length === 10 ? 'T00:00:00' : ''}Z` : text,
|
|
2427
|
-
)
|
|
2428
|
-
return Number.isNaN(date.getTime()) ? null : DbDate.toDb(date)
|
|
2424
|
+
const date = dateFromText(String(value))
|
|
2425
|
+
return date ? DbDate.toDb(date) : null
|
|
2429
2426
|
}
|
|
2430
2427
|
default:
|
|
2431
2428
|
return typeof value === 'string' ? value : JSON.stringify(value)
|
|
@@ -34,7 +34,8 @@ export function normaliseDomainName(name: string): string {
|
|
|
34
34
|
.toLowerCase()
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
/** A hostname with an optional path, or a path alone, which answers on any hostname. */
|
|
38
|
+
const VALID_DOMAIN = /^(?:[a-z0-9.-]+(:\d+)?(\/[a-z0-9._~%-]+)*|(\/[a-z0-9._~%-]+)+)$/i
|
|
38
39
|
|
|
39
40
|
export class DomainRepository {
|
|
40
41
|
#db: Db
|
|
@@ -65,6 +65,8 @@ export interface FormEntryQuery {
|
|
|
65
65
|
/** Only the entries that came through this Library form; `null` for those that came through none. */
|
|
66
66
|
libraryKey?: string | null
|
|
67
67
|
state?: FormEntryState
|
|
68
|
+
/** Only the entries filled in in this language. */
|
|
69
|
+
culture?: string
|
|
68
70
|
/** Inclusive; the entries view defaults to the last month. */
|
|
69
71
|
from?: Date
|
|
70
72
|
to?: Date
|
|
@@ -185,6 +187,19 @@ export class FormEntryRepository {
|
|
|
185
187
|
return hydrate(row, (await this.#valuesFor([id])).get(id) ?? [])
|
|
186
188
|
}
|
|
187
189
|
|
|
190
|
+
/** The languages a form's entries were filled in. */
|
|
191
|
+
async languages(formKey: string): Promise<string[]> {
|
|
192
|
+
const rows = await this.#db.q
|
|
193
|
+
.selectFrom('form_entry')
|
|
194
|
+
.select('culture')
|
|
195
|
+
.distinct()
|
|
196
|
+
.where('form_key', '=', formKey)
|
|
197
|
+
.where('culture', 'is not', null)
|
|
198
|
+
.orderBy('culture')
|
|
199
|
+
.execute()
|
|
200
|
+
return rows.flatMap((row) => (row.culture ? [row.culture] : []))
|
|
201
|
+
}
|
|
202
|
+
|
|
188
203
|
async list(query: FormEntryQuery): Promise<{ total: number; items: FormEntry[] }> {
|
|
189
204
|
const search = query.search ? `%${query.search.toLowerCase()}%` : undefined
|
|
190
205
|
const matching = this.#db.q
|
|
@@ -196,6 +211,7 @@ export class FormEntryRepository {
|
|
|
196
211
|
: q.where('library_key', '=', query.libraryKey as string),
|
|
197
212
|
)
|
|
198
213
|
.$if(Boolean(query.state), (q) => q.where('state', '=', query.state as FormEntryState))
|
|
214
|
+
.$if(Boolean(query.culture), (q) => q.where('culture', '=', query.culture as string))
|
|
199
215
|
.$if(Boolean(query.from), (q) =>
|
|
200
216
|
q.where('create_date', '>=', DbDate.toDb(query.from as Date)),
|
|
201
217
|
)
|