@crombolo/data 0.51.1 → 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/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
|
)
|