@nixxie-cms/core 1.0.3 → 2.0.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 +36 -0
- package/CHANGES-1.1.md +134 -0
- package/context/dist/nixxie-cms-core-context.cjs.js +4 -3
- package/context/dist/nixxie-cms-core-context.esm.js +3 -2
- package/dist/declarations/src/access.d.ts +2 -2
- package/dist/declarations/src/access.d.ts.map +1 -1
- package/dist/declarations/src/admin-ui/components/Navigation.d.ts +2 -2
- package/dist/declarations/src/admin-ui/components/Navigation.d.ts.map +1 -1
- package/dist/declarations/src/admin-ui/context.d.ts +6 -6
- package/dist/declarations/src/admin-ui/context.d.ts.map +1 -1
- package/dist/declarations/src/admin-ui/utils/Fields.d.ts +3 -3
- package/dist/declarations/src/admin-ui/utils/Fields.d.ts.map +1 -1
- package/dist/declarations/src/admin-ui/utils/filters.d.ts +5 -5
- package/dist/declarations/src/admin-ui/utils/filters.d.ts.map +1 -1
- package/dist/declarations/src/admin-ui/utils/useCreateItem.d.ts +3 -3
- package/dist/declarations/src/admin-ui/utils/useCreateItem.d.ts.map +1 -1
- package/dist/declarations/src/admin-ui/utils/utils.d.ts +2 -2
- package/dist/declarations/src/admin-ui/utils/utils.d.ts.map +1 -1
- package/dist/declarations/src/context.d.ts +1 -1
- package/dist/declarations/src/context.d.ts.map +1 -1
- package/dist/declarations/src/fields/types/bigInt/index.d.ts +3 -3
- package/dist/declarations/src/fields/types/bigInt/index.d.ts.map +1 -1
- package/dist/declarations/src/fields/types/bytes/index.d.ts +3 -3
- package/dist/declarations/src/fields/types/bytes/index.d.ts.map +1 -1
- package/dist/declarations/src/fields/types/calendarDay/index.d.ts +3 -3
- package/dist/declarations/src/fields/types/calendarDay/index.d.ts.map +1 -1
- package/dist/declarations/src/fields/types/checkbox/index.d.ts +3 -3
- package/dist/declarations/src/fields/types/checkbox/index.d.ts.map +1 -1
- package/dist/declarations/src/fields/types/decimal/index.d.ts +3 -3
- package/dist/declarations/src/fields/types/decimal/index.d.ts.map +1 -1
- package/dist/declarations/src/fields/types/file/index.d.ts +4 -4
- package/dist/declarations/src/fields/types/file/index.d.ts.map +1 -1
- package/dist/declarations/src/fields/types/float/index.d.ts +3 -3
- package/dist/declarations/src/fields/types/float/index.d.ts.map +1 -1
- package/dist/declarations/src/fields/types/image/index.d.ts +4 -4
- package/dist/declarations/src/fields/types/image/index.d.ts.map +1 -1
- package/dist/declarations/src/fields/types/integer/index.d.ts +3 -3
- package/dist/declarations/src/fields/types/integer/index.d.ts.map +1 -1
- package/dist/declarations/src/fields/types/json/index.d.ts +3 -3
- package/dist/declarations/src/fields/types/json/index.d.ts.map +1 -1
- package/dist/declarations/src/fields/types/multiselect/index.d.ts +3 -3
- package/dist/declarations/src/fields/types/multiselect/index.d.ts.map +1 -1
- package/dist/declarations/src/fields/types/multiselect/views/index.d.ts.map +1 -1
- package/dist/declarations/src/fields/types/password/index.d.ts +3 -3
- package/dist/declarations/src/fields/types/password/index.d.ts.map +1 -1
- package/dist/declarations/src/fields/types/relationship/index.d.ts +8 -8
- package/dist/declarations/src/fields/types/relationship/index.d.ts.map +1 -1
- package/dist/declarations/src/fields/types/relationship/views/ComboboxMany.d.ts +3 -3
- package/dist/declarations/src/fields/types/relationship/views/ComboboxMany.d.ts.map +1 -1
- package/dist/declarations/src/fields/types/relationship/views/ComboboxSingle.d.ts +3 -3
- package/dist/declarations/src/fields/types/relationship/views/ComboboxSingle.d.ts.map +1 -1
- package/dist/declarations/src/fields/types/relationship/views/index.d.ts +3 -3
- package/dist/declarations/src/fields/types/relationship/views/index.d.ts.map +1 -1
- package/dist/declarations/src/fields/types/relationship/views/types.d.ts +3 -3
- package/dist/declarations/src/fields/types/relationship/views/types.d.ts.map +1 -1
- package/dist/declarations/src/fields/types/select/index.d.ts +3 -3
- package/dist/declarations/src/fields/types/select/index.d.ts.map +1 -1
- package/dist/declarations/src/fields/types/text/index.d.ts +3 -3
- package/dist/declarations/src/fields/types/text/index.d.ts.map +1 -1
- package/dist/declarations/src/fields/types/timestamp/index.d.ts +3 -3
- package/dist/declarations/src/fields/types/timestamp/index.d.ts.map +1 -1
- package/dist/declarations/src/fields/types/virtual/index.d.ts +7 -7
- package/dist/declarations/src/fields/types/virtual/index.d.ts.map +1 -1
- package/dist/declarations/src/helpers.d.ts +249 -13
- package/dist/declarations/src/helpers.d.ts.map +1 -1
- package/dist/declarations/src/index.d.ts +9 -4
- package/dist/declarations/src/index.d.ts.map +1 -1
- package/dist/declarations/src/internal-unstable/admin-ui/pages/ListPage/index.d.ts.map +1 -1
- package/dist/declarations/src/lib/admin-meta.d.ts +11 -11
- package/dist/declarations/src/lib/admin-meta.d.ts.map +1 -1
- package/dist/declarations/src/lib/core/access-control.d.ts +18 -18
- package/dist/declarations/src/lib/core/access-control.d.ts.map +1 -1
- package/dist/declarations/src/lib/core/cascade.d.ts +47 -0
- package/dist/declarations/src/lib/core/cascade.d.ts.map +1 -0
- package/dist/declarations/src/lib/core/initialise-lists.d.ts +27 -24
- package/dist/declarations/src/lib/core/initialise-lists.d.ts.map +1 -1
- package/dist/declarations/src/lib/env.d.ts +9 -0
- package/dist/declarations/src/lib/env.d.ts.map +1 -0
- package/dist/declarations/src/lib/system.d.ts +1 -1
- package/dist/declarations/src/lib/system.d.ts.map +1 -1
- package/dist/declarations/src/list-features.d.ts +162 -0
- package/dist/declarations/src/list-features.d.ts.map +1 -0
- package/dist/declarations/src/schema.d.ts +24 -23
- package/dist/declarations/src/schema.d.ts.map +1 -1
- package/dist/declarations/src/session.d.ts +75 -0
- package/dist/declarations/src/session.d.ts.map +1 -1
- package/dist/declarations/src/types/admin-meta.d.ts +11 -11
- package/dist/declarations/src/types/admin-meta.d.ts.map +1 -1
- package/dist/declarations/src/types/config/access-control.d.ts +42 -42
- package/dist/declarations/src/types/config/access-control.d.ts.map +1 -1
- package/dist/declarations/src/types/config/fields.d.ts +19 -19
- package/dist/declarations/src/types/config/fields.d.ts.map +1 -1
- package/dist/declarations/src/types/config/hooks.d.ts +131 -131
- package/dist/declarations/src/types/config/hooks.d.ts.map +1 -1
- package/dist/declarations/src/types/config/index.d.ts +190 -8
- package/dist/declarations/src/types/config/index.d.ts.map +1 -1
- package/dist/declarations/src/types/config/lists.d.ts +146 -108
- package/dist/declarations/src/types/config/lists.d.ts.map +1 -1
- package/dist/declarations/src/types/context.d.ts +507 -47
- package/dist/declarations/src/types/context.d.ts.map +1 -1
- package/dist/declarations/src/types/next-fields.d.ts +28 -28
- package/dist/declarations/src/types/next-fields.d.ts.map +1 -1
- package/dist/declarations/src/types/type-info.d.ts +3 -3
- package/dist/declarations/src/types/type-info.d.ts.map +1 -1
- package/dist/{express-455ae20c.cjs.js → express-84d534c2.cjs.js} +6 -6
- package/dist/{express-7559ca2d.esm.js → express-d0a4ce99.esm.js} +6 -6
- package/dist/{index-15c8f81e.esm.js → index-5d8b0b4e.esm.js} +363 -183
- package/dist/index-6055753b.cjs.js +393 -0
- package/dist/{index-42045902.cjs.js → index-ac29f382.cjs.js} +363 -185
- package/dist/index-f1703b7b.esm.js +386 -0
- package/dist/nixxie-cms-core.cjs.js +1388 -30
- package/dist/nixxie-cms-core.esm.js +1362 -24
- package/dist/{non-null-graphql-add6bb3d.cjs.js → non-null-graphql-4a44c122.cjs.js} +1 -1
- package/dist/{non-null-graphql-a84ed64d.esm.js → non-null-graphql-8c5feaae.esm.js} +1 -1
- package/dist/{resolve-hooks-165a9ce2.cjs.js → resolve-hooks-10a5f84c.cjs.js} +240 -6
- package/dist/{resolve-hooks-6813a045.esm.js → resolve-hooks-9e676794.esm.js} +238 -7
- package/dist/{system-a321642d.cjs.js → system-6b37a5f8.cjs.js} +33 -7
- package/dist/{system-03e49e4f.esm.js → system-e591d821.esm.js} +33 -7
- package/fields/dist/nixxie-cms-core-fields.cjs.js +29 -576
- package/fields/dist/nixxie-cms-core-fields.esm.js +18 -565
- package/fields/types/bytes/dist/nixxie-cms-core-fields-types-bytes.cjs.js +4 -2
- package/fields/types/bytes/dist/nixxie-cms-core-fields-types-bytes.esm.js +4 -2
- package/fields/types/multiselect/views/dist/nixxie-cms-core-fields-types-multiselect-views.cjs.js +1 -6
- package/fields/types/multiselect/views/dist/nixxie-cms-core-fields-types-multiselect-views.esm.js +1 -6
- package/fields/types/password/dist/nixxie-cms-core-fields-types-password.cjs.js +4 -2
- package/fields/types/password/dist/nixxie-cms-core-fields-types-password.esm.js +4 -2
- package/internal-unstable/artifacts/dist/nixxie-cms-core-internal-unstable-artifacts.cjs.js +4 -3
- package/internal-unstable/artifacts/dist/nixxie-cms-core-internal-unstable-artifacts.esm.js +4 -3
- package/package.json +4 -4
- package/scripts/cli/dist/nixxie-cms-core-scripts-cli.cjs.js +4 -3
- package/scripts/cli/dist/nixxie-cms-core-scripts-cli.esm.js +4 -3
- package/scripts/dist/nixxie-cms-core-scripts.cjs.js +4 -3
- package/scripts/dist/nixxie-cms-core-scripts.esm.js +4 -3
- package/session/dist/nixxie-cms-core-session.cjs.js +286 -0
- package/session/dist/nixxie-cms-core-session.esm.js +279 -1
- package/src/access.ts +25 -25
- package/src/admin-ui/admin-meta-graphql.ts +5 -5
- package/src/admin-ui/components/CreateButtonLink.tsx +46 -46
- package/src/admin-ui/components/Navigation.tsx +3 -3
- package/src/admin-ui/context.tsx +6 -6
- package/src/admin-ui/utils/Fields.tsx +241 -241
- package/src/admin-ui/utils/actionData.ts +36 -36
- package/src/admin-ui/utils/filters.ts +148 -148
- package/src/admin-ui/utils/useCreateItem.ts +171 -171
- package/src/admin-ui/utils/utils.tsx +127 -127
- package/src/context.ts +1 -1
- package/src/fields/non-null-graphql.ts +115 -115
- package/src/fields/types/bigInt/index.ts +6 -6
- package/src/fields/types/bytes/index.ts +6 -6
- package/src/fields/types/calendarDay/index.ts +18 -19
- package/src/fields/types/checkbox/index.ts +6 -6
- package/src/fields/types/decimal/index.ts +6 -6
- package/src/fields/types/file/index.ts +8 -8
- package/src/fields/types/float/index.ts +6 -6
- package/src/fields/types/image/index.ts +8 -8
- package/src/fields/types/integer/index.ts +6 -6
- package/src/fields/types/json/index.ts +5 -5
- package/src/fields/types/multiselect/index.ts +7 -7
- package/src/fields/types/multiselect/views/index.tsx +149 -151
- package/src/fields/types/password/index.ts +6 -6
- package/src/fields/types/relationship/index.ts +13 -13
- package/src/fields/types/relationship/views/ComboboxMany.tsx +110 -110
- package/src/fields/types/relationship/views/ComboboxSingle.tsx +115 -115
- package/src/fields/types/relationship/views/ContextualActions.tsx +139 -139
- package/src/fields/types/relationship/views/index.tsx +492 -492
- package/src/fields/types/relationship/views/types.ts +46 -46
- package/src/fields/types/relationship/views/useApolloQuery.ts +185 -185
- package/src/fields/types/relationship/views/useFilter.tsx +109 -109
- package/src/fields/types/select/index.ts +6 -6
- package/src/fields/types/text/index.ts +6 -6
- package/src/fields/types/timestamp/index.ts +23 -21
- package/src/fields/types/virtual/index.ts +11 -11
- package/src/helpers.ts +773 -42
- package/src/index.ts +66 -24
- package/src/internal-unstable/admin-ui/pages/ItemPage/common.tsx +4 -4
- package/src/internal-unstable/admin-ui/pages/ItemPage/index.tsx +5 -5
- package/src/internal-unstable/admin-ui/pages/ListPage/index.tsx +8 -8
- package/src/lib/admin-meta.ts +369 -369
- package/src/lib/context/createContext.ts +6 -0
- package/src/lib/core/access-control.ts +434 -434
- package/src/lib/core/cascade.ts +236 -0
- package/src/lib/core/initialise-lists.ts +49 -33
- package/src/lib/core/mutations/index.ts +7 -0
- package/src/lib/core/mutations/nested-mutation-many-input-resolvers.ts +145 -145
- package/src/lib/core/mutations/nested-mutation-one-input-resolvers.ts +71 -71
- package/src/lib/core/queries/output-field.ts +178 -178
- package/src/lib/env.ts +50 -0
- package/src/lib/id-field.ts +2 -2
- package/src/lib/system.ts +221 -207
- package/src/lib/typescript-schema-printer.ts +227 -227
- package/src/list-features.ts +476 -0
- package/src/schema.ts +92 -22
- package/src/session.ts +225 -0
- package/src/types/admin-meta.ts +218 -218
- package/src/types/config/access-control.ts +186 -186
- package/src/types/config/fields.ts +96 -96
- package/src/types/config/hooks.ts +529 -529
- package/src/types/config/index.ts +206 -7
- package/src/types/config/lists.ts +606 -565
- package/src/types/context.ts +592 -55
- package/src/types/next-fields.ts +31 -31
- package/src/types/type-info.ts +38 -38
- package/src/types/type-tests.ts +21 -21
|
@@ -1,109 +1,109 @@
|
|
|
1
|
-
import { useMemo } from 'react'
|
|
2
|
-
import { useNixxie } from '../../../../admin-ui/context'
|
|
3
|
-
|
|
4
|
-
import type {
|
|
5
|
-
|
|
6
|
-
function isInt(x: string) {
|
|
7
|
-
return Number.isInteger(Number(x))
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
function isBigInt(x: string) {
|
|
11
|
-
try {
|
|
12
|
-
BigInt(x)
|
|
13
|
-
return true
|
|
14
|
-
} catch {
|
|
15
|
-
return true
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// TODO: this is unfortunate, remove in breaking change?
|
|
20
|
-
function isUuid(x: unknown) {
|
|
21
|
-
if (typeof x !== 'string') return
|
|
22
|
-
if (x.length !== 36) return
|
|
23
|
-
return /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(x)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function useSearchFilter(value: string, list:
|
|
27
|
-
const { lists } = useNixxie()
|
|
28
|
-
return useMemo(() => {
|
|
29
|
-
const trimmedSearch = value.trim()
|
|
30
|
-
if (!trimmedSearch.length) return []
|
|
31
|
-
|
|
32
|
-
const conditions: Record<string, any>[] = []
|
|
33
|
-
const idField = list.fields.id.fieldMeta as { type: string; kind: string }
|
|
34
|
-
|
|
35
|
-
if (idField.type === 'String') {
|
|
36
|
-
// TODO: remove in breaking change?
|
|
37
|
-
if (idField.kind === 'uuid') {
|
|
38
|
-
if (isUuid(value)) {
|
|
39
|
-
conditions.push({ id: { equals: trimmedSearch } })
|
|
40
|
-
}
|
|
41
|
-
} else {
|
|
42
|
-
conditions.push({ id: { equals: trimmedSearch } })
|
|
43
|
-
}
|
|
44
|
-
} else if (idField.type === 'Int' && isInt(trimmedSearch)) {
|
|
45
|
-
conditions.push({ id: { equals: Number(trimmedSearch) } })
|
|
46
|
-
} else if (idField.type === 'BigInt' && isBigInt(trimmedSearch)) {
|
|
47
|
-
conditions.push({ id: { equals: trimmedSearch } })
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
for (const fieldKey of searchFields) {
|
|
51
|
-
const field = list.fields[fieldKey]
|
|
52
|
-
|
|
53
|
-
// @ts-expect-error TODO: fix fieldMeta type for relationship fields
|
|
54
|
-
if (field.fieldMeta?.refSearchFields) {
|
|
55
|
-
const {
|
|
56
|
-
// @ts-expect-error TODO: fix fieldMeta type for relationship fields
|
|
57
|
-
refListKey,
|
|
58
|
-
// @ts-expect-error TODO: fix fieldMeta type for relationship fields
|
|
59
|
-
refSearchFields,
|
|
60
|
-
// @ts-expect-error TODO: fix fieldMeta type for relationship fields
|
|
61
|
-
many = false,
|
|
62
|
-
} = field.fieldMeta
|
|
63
|
-
const refList = lists[refListKey]
|
|
64
|
-
|
|
65
|
-
for (const refFieldKey of refSearchFields) {
|
|
66
|
-
const refField = refList.fields[refFieldKey]
|
|
67
|
-
if (!refField.search) continue // WARNING: we dont support depth > 2
|
|
68
|
-
// @ts-expect-error TODO: fix fieldMeta type for relationship fields
|
|
69
|
-
if (refField.fieldMeta?.refSearchFields) continue // WARNING: we dont support depth > 2
|
|
70
|
-
|
|
71
|
-
if (many) {
|
|
72
|
-
conditions.push({
|
|
73
|
-
[fieldKey]: {
|
|
74
|
-
some: {
|
|
75
|
-
[refFieldKey]: {
|
|
76
|
-
contains: trimmedSearch,
|
|
77
|
-
mode: refField.search === 'insensitive' ? 'insensitive' : undefined,
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
continue
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
conditions.push({
|
|
87
|
-
[fieldKey]: {
|
|
88
|
-
[refFieldKey]: {
|
|
89
|
-
contains: trimmedSearch,
|
|
90
|
-
mode: refField.search === 'insensitive' ? 'insensitive' : undefined,
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
})
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
continue
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
conditions.push({
|
|
100
|
-
[field.key]: {
|
|
101
|
-
contains: trimmedSearch,
|
|
102
|
-
mode: field.search === 'insensitive' ? 'insensitive' : undefined,
|
|
103
|
-
},
|
|
104
|
-
})
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return conditions
|
|
108
|
-
}, [value, list, searchFields])
|
|
109
|
-
}
|
|
1
|
+
import { useMemo } from 'react'
|
|
2
|
+
import { useNixxie } from '../../../../admin-ui/context'
|
|
3
|
+
|
|
4
|
+
import type { CollectionMeta } from '../../../../types'
|
|
5
|
+
|
|
6
|
+
function isInt(x: string) {
|
|
7
|
+
return Number.isInteger(Number(x))
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function isBigInt(x: string) {
|
|
11
|
+
try {
|
|
12
|
+
BigInt(x)
|
|
13
|
+
return true
|
|
14
|
+
} catch {
|
|
15
|
+
return true
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// TODO: this is unfortunate, remove in breaking change?
|
|
20
|
+
function isUuid(x: unknown) {
|
|
21
|
+
if (typeof x !== 'string') return
|
|
22
|
+
if (x.length !== 36) return
|
|
23
|
+
return /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(x)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function useSearchFilter(value: string, list: CollectionMeta, searchFields: string[]) {
|
|
27
|
+
const { lists } = useNixxie()
|
|
28
|
+
return useMemo(() => {
|
|
29
|
+
const trimmedSearch = value.trim()
|
|
30
|
+
if (!trimmedSearch.length) return []
|
|
31
|
+
|
|
32
|
+
const conditions: Record<string, any>[] = []
|
|
33
|
+
const idField = list.fields.id.fieldMeta as { type: string; kind: string }
|
|
34
|
+
|
|
35
|
+
if (idField.type === 'String') {
|
|
36
|
+
// TODO: remove in breaking change?
|
|
37
|
+
if (idField.kind === 'uuid') {
|
|
38
|
+
if (isUuid(value)) {
|
|
39
|
+
conditions.push({ id: { equals: trimmedSearch } })
|
|
40
|
+
}
|
|
41
|
+
} else {
|
|
42
|
+
conditions.push({ id: { equals: trimmedSearch } })
|
|
43
|
+
}
|
|
44
|
+
} else if (idField.type === 'Int' && isInt(trimmedSearch)) {
|
|
45
|
+
conditions.push({ id: { equals: Number(trimmedSearch) } })
|
|
46
|
+
} else if (idField.type === 'BigInt' && isBigInt(trimmedSearch)) {
|
|
47
|
+
conditions.push({ id: { equals: trimmedSearch } })
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
for (const fieldKey of searchFields) {
|
|
51
|
+
const field = list.fields[fieldKey]
|
|
52
|
+
|
|
53
|
+
// @ts-expect-error TODO: fix fieldMeta type for relationship fields
|
|
54
|
+
if (field.fieldMeta?.refSearchFields) {
|
|
55
|
+
const {
|
|
56
|
+
// @ts-expect-error TODO: fix fieldMeta type for relationship fields
|
|
57
|
+
refListKey,
|
|
58
|
+
// @ts-expect-error TODO: fix fieldMeta type for relationship fields
|
|
59
|
+
refSearchFields,
|
|
60
|
+
// @ts-expect-error TODO: fix fieldMeta type for relationship fields
|
|
61
|
+
many = false,
|
|
62
|
+
} = field.fieldMeta
|
|
63
|
+
const refList = lists[refListKey]
|
|
64
|
+
|
|
65
|
+
for (const refFieldKey of refSearchFields) {
|
|
66
|
+
const refField = refList.fields[refFieldKey]
|
|
67
|
+
if (!refField.search) continue // WARNING: we dont support depth > 2
|
|
68
|
+
// @ts-expect-error TODO: fix fieldMeta type for relationship fields
|
|
69
|
+
if (refField.fieldMeta?.refSearchFields) continue // WARNING: we dont support depth > 2
|
|
70
|
+
|
|
71
|
+
if (many) {
|
|
72
|
+
conditions.push({
|
|
73
|
+
[fieldKey]: {
|
|
74
|
+
some: {
|
|
75
|
+
[refFieldKey]: {
|
|
76
|
+
contains: trimmedSearch,
|
|
77
|
+
mode: refField.search === 'insensitive' ? 'insensitive' : undefined,
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
continue
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
conditions.push({
|
|
87
|
+
[fieldKey]: {
|
|
88
|
+
[refFieldKey]: {
|
|
89
|
+
contains: trimmedSearch,
|
|
90
|
+
mode: refField.search === 'insensitive' ? 'insensitive' : undefined,
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
})
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
continue
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
conditions.push({
|
|
100
|
+
[field.key]: {
|
|
101
|
+
contains: trimmedSearch,
|
|
102
|
+
mode: field.search === 'insensitive' ? 'insensitive' : undefined,
|
|
103
|
+
},
|
|
104
|
+
})
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return conditions
|
|
108
|
+
}, [value, list, searchFields])
|
|
109
|
+
}
|
|
@@ -2,7 +2,7 @@ import { g } from '../../..'
|
|
|
2
2
|
import { humanize } from '../../../lib/utils'
|
|
3
3
|
import type { SimpleFieldTypeInfo } from '../../../types'
|
|
4
4
|
import {
|
|
5
|
-
type
|
|
5
|
+
type BaseCollectionTypeInfo,
|
|
6
6
|
type CommonFieldConfig,
|
|
7
7
|
type FieldTypeFunc,
|
|
8
8
|
fieldType,
|
|
@@ -12,8 +12,8 @@ import { filters } from '../../filters'
|
|
|
12
12
|
import { defaultIsRequired, makeValidateHook } from '../../non-null-graphql'
|
|
13
13
|
import type { controller } from './views'
|
|
14
14
|
|
|
15
|
-
export type SelectFieldConfig<
|
|
16
|
-
|
|
15
|
+
export type SelectFieldConfig<CollectionTypeInfo extends BaseCollectionTypeInfo> = CommonFieldConfig<
|
|
16
|
+
CollectionTypeInfo,
|
|
17
17
|
SimpleFieldTypeInfo<'String' | 'Int'>
|
|
18
18
|
> &
|
|
19
19
|
(
|
|
@@ -57,9 +57,9 @@ export type SelectFieldConfig<ListTypeInfo extends BaseListTypeInfo> = CommonFie
|
|
|
57
57
|
const MAX_INT = 2147483647
|
|
58
58
|
const MIN_INT = -2147483648
|
|
59
59
|
|
|
60
|
-
export function select<
|
|
61
|
-
config: SelectFieldConfig<
|
|
62
|
-
): FieldTypeFunc<
|
|
60
|
+
export function select<CollectionTypeInfo extends BaseCollectionTypeInfo>(
|
|
61
|
+
config: SelectFieldConfig<CollectionTypeInfo>
|
|
62
|
+
): FieldTypeFunc<CollectionTypeInfo> {
|
|
63
63
|
const { isIndexed, ui: { displayMode = 'select', ...ui } = {}, defaultValue, validation } = config
|
|
64
64
|
|
|
65
65
|
return meta => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { SimpleFieldTypeInfo } from '../../../types'
|
|
2
2
|
import {
|
|
3
|
-
type
|
|
3
|
+
type BaseCollectionTypeInfo,
|
|
4
4
|
type CommonFieldConfig,
|
|
5
5
|
type FieldTypeFunc,
|
|
6
6
|
fieldType,
|
|
@@ -10,8 +10,8 @@ import { g } from '../../..'
|
|
|
10
10
|
import { makeValidateHook, defaultIsRequired } from '../../non-null-graphql'
|
|
11
11
|
import { filters } from '../../filters'
|
|
12
12
|
|
|
13
|
-
export type TextFieldConfig<
|
|
14
|
-
|
|
13
|
+
export type TextFieldConfig<CollectionTypeInfo extends BaseCollectionTypeInfo> = CommonFieldConfig<
|
|
14
|
+
CollectionTypeInfo,
|
|
15
15
|
SimpleFieldTypeInfo<'String'>
|
|
16
16
|
> & {
|
|
17
17
|
isIndexed?: boolean | 'unique'
|
|
@@ -66,9 +66,9 @@ export type TextFieldMeta = {
|
|
|
66
66
|
defaultValue: string | null
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
export function text<
|
|
70
|
-
config: TextFieldConfig<
|
|
71
|
-
): FieldTypeFunc<
|
|
69
|
+
export function text<CollectionTypeInfo extends BaseCollectionTypeInfo>(
|
|
70
|
+
config: TextFieldConfig<CollectionTypeInfo> = {}
|
|
71
|
+
): FieldTypeFunc<CollectionTypeInfo> {
|
|
72
72
|
const { defaultValue: defaultValue_, isIndexed, validation = {} } = config
|
|
73
73
|
|
|
74
74
|
config.db ??= {}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { SimpleFieldTypeInfo } from '../../../types'
|
|
2
2
|
import {
|
|
3
|
-
type
|
|
3
|
+
type BaseCollectionTypeInfo,
|
|
4
4
|
type FieldTypeFunc,
|
|
5
5
|
type CommonFieldConfig,
|
|
6
6
|
fieldType,
|
|
@@ -11,27 +11,28 @@ import { filters } from '../../filters'
|
|
|
11
11
|
import { makeValidateHook, defaultIsRequired } from '../../non-null-graphql'
|
|
12
12
|
import { type TimestampFieldMeta } from './views'
|
|
13
13
|
|
|
14
|
-
export type TimestampFieldConfig<
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
>
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
14
|
+
export type TimestampFieldConfig<CollectionTypeInfo extends BaseCollectionTypeInfo> =
|
|
15
|
+
CommonFieldConfig<
|
|
16
|
+
CollectionTypeInfo,
|
|
17
|
+
SimpleFieldTypeInfo<'DateTime' | 'String'> // TODO: make more exact
|
|
18
|
+
> & {
|
|
19
|
+
isIndexed?: boolean | 'unique'
|
|
20
|
+
validation?: {
|
|
21
|
+
isRequired?: boolean
|
|
22
|
+
}
|
|
23
|
+
defaultValue?: string | { kind: 'now' }
|
|
24
|
+
db?: {
|
|
25
|
+
// this is @updatedAt in Prisma
|
|
26
|
+
updatedAt?: boolean
|
|
27
|
+
isNullable?: boolean
|
|
28
|
+
map?: string
|
|
29
|
+
extendPrismaSchema?: (field: string) => string
|
|
30
|
+
}
|
|
29
31
|
}
|
|
30
|
-
}
|
|
31
32
|
|
|
32
|
-
export function timestamp<
|
|
33
|
-
config: TimestampFieldConfig<
|
|
34
|
-
): FieldTypeFunc<
|
|
33
|
+
export function timestamp<CollectionTypeInfo extends BaseCollectionTypeInfo>(
|
|
34
|
+
config: TimestampFieldConfig<CollectionTypeInfo> = {}
|
|
35
|
+
): FieldTypeFunc<CollectionTypeInfo> {
|
|
35
36
|
const { isIndexed, defaultValue, validation } = config
|
|
36
37
|
|
|
37
38
|
return meta => {
|
|
@@ -40,7 +41,8 @@ export function timestamp<ListTypeInfo extends BaseListTypeInfo>(
|
|
|
40
41
|
g.DateTime.parseValue(defaultValue)
|
|
41
42
|
} catch (err) {
|
|
42
43
|
throw new Error(
|
|
43
|
-
`${meta.listKey}.${meta.fieldKey}.defaultValue is required to be an ISO8601 date-time string such as ${new Date().toISOString()}
|
|
44
|
+
`${meta.listKey}.${meta.fieldKey}.defaultValue is required to be an ISO8601 date-time string such as ${new Date().toISOString()}`,
|
|
45
|
+
{ cause: err }
|
|
44
46
|
)
|
|
45
47
|
}
|
|
46
48
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { getNamedType, isLeafType } from 'graphql'
|
|
2
2
|
import {
|
|
3
3
|
type BaseItem,
|
|
4
|
-
type
|
|
4
|
+
type BaseCollectionTypeInfo,
|
|
5
5
|
type CommonFieldConfig,
|
|
6
6
|
type FieldTypeFunc,
|
|
7
7
|
type NixxieContext,
|
|
8
|
-
type
|
|
8
|
+
type CollectionGraphQLTypes,
|
|
9
9
|
fieldType,
|
|
10
10
|
} from '../../../types'
|
|
11
11
|
import { g } from '../../..'
|
|
@@ -36,20 +36,20 @@ type FieldTypeInfo = {
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
export type VirtualFieldConfig<
|
|
40
|
-
|
|
39
|
+
export type VirtualFieldConfig<CollectionTypeInfo extends BaseCollectionTypeInfo> = CommonFieldConfig<
|
|
40
|
+
CollectionTypeInfo,
|
|
41
41
|
FieldTypeInfo
|
|
42
42
|
> & {
|
|
43
43
|
field:
|
|
44
|
-
| VirtualFieldGraphQLField<
|
|
44
|
+
| VirtualFieldGraphQLField<CollectionTypeInfo['item'], NixxieContext<CollectionTypeInfo['all']>>
|
|
45
45
|
| ((lists: {
|
|
46
|
-
[Key in keyof
|
|
47
|
-
|
|
46
|
+
[Key in keyof CollectionTypeInfo['all']['lists']]: CollectionGraphQLTypes<
|
|
47
|
+
CollectionTypeInfo['all']['lists'][Key]
|
|
48
48
|
>
|
|
49
|
-
}) => VirtualFieldGraphQLField<
|
|
49
|
+
}) => VirtualFieldGraphQLField<CollectionTypeInfo['item'], NixxieContext<CollectionTypeInfo['all']>>)
|
|
50
50
|
unreferencedConcreteInterfaceImplementations?: readonly GObjectType<
|
|
51
51
|
any,
|
|
52
|
-
NixxieContext<
|
|
52
|
+
NixxieContext<CollectionTypeInfo['all']>
|
|
53
53
|
>[]
|
|
54
54
|
ui?: {
|
|
55
55
|
/**
|
|
@@ -67,10 +67,10 @@ export type VirtualFieldConfig<ListTypeInfo extends BaseListTypeInfo> = CommonFi
|
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
export function virtual<
|
|
70
|
+
export function virtual<CollectionTypeInfo extends BaseCollectionTypeInfo>({
|
|
71
71
|
field,
|
|
72
72
|
...config
|
|
73
|
-
}: VirtualFieldConfig<
|
|
73
|
+
}: VirtualFieldConfig<CollectionTypeInfo>): FieldTypeFunc<CollectionTypeInfo> {
|
|
74
74
|
return meta => {
|
|
75
75
|
const usableField = typeof field === 'function' ? field(meta.lists) : field
|
|
76
76
|
const namedType = getNamedType(usableField.type)
|