@vexcms/core 0.0.20 → 0.1.0-alpha.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/LICENSE +202 -0
- package/dist/.build +1 -0
- package/dist/access/buildChecks.d.ts +58 -0
- package/dist/access/buildChecks.d.ts.map +1 -0
- package/dist/access/canAccessAdminPanel.d.ts +53 -0
- package/dist/access/canAccessAdminPanel.d.ts.map +1 -0
- package/dist/access/compileConstraints.d.ts +155 -0
- package/dist/access/compileConstraints.d.ts.map +1 -0
- package/dist/access/config.d.ts +62 -0
- package/dist/access/config.d.ts.map +1 -0
- package/dist/access/constants.d.ts +95 -0
- package/dist/access/constants.d.ts.map +1 -0
- package/dist/access/constraintTypes.d.ts +337 -0
- package/dist/access/constraintTypes.d.ts.map +1 -0
- package/dist/access/createAccessQueryBuilder.d.ts +59 -0
- package/dist/access/createAccessQueryBuilder.d.ts.map +1 -0
- package/dist/access/createFilterConstraintBuilder.d.ts +26 -0
- package/dist/access/createFilterConstraintBuilder.d.ts.map +1 -0
- package/dist/access/createIndexConstraintBuilder.d.ts +40 -0
- package/dist/access/createIndexConstraintBuilder.d.ts.map +1 -0
- package/dist/access/hasPermission.d.ts +85 -0
- package/dist/access/hasPermission.d.ts.map +1 -0
- package/dist/access/index.d.ts +13 -0
- package/dist/access/index.d.ts.map +1 -0
- package/dist/access/pickQueryIndex.d.ts +42 -0
- package/dist/access/pickQueryIndex.d.ts.map +1 -0
- package/dist/access/resolveAccessRule.d.ts +85 -0
- package/dist/access/resolveAccessRule.d.ts.map +1 -0
- package/dist/access/types.d.ts +738 -0
- package/dist/access/types.d.ts.map +1 -0
- package/dist/access/validateAccessConstraints.d.ts +57 -0
- package/dist/access/validateAccessConstraints.d.ts.map +1 -0
- package/dist/api/client.d.ts +20 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/api/client.js +117 -0
- package/dist/api/client.js.map +1 -0
- package/dist/api/convex.d.ts +296 -0
- package/dist/api/convex.d.ts.map +1 -0
- package/dist/api/create/client.d.ts +50 -0
- package/dist/api/create/client.d.ts.map +1 -0
- package/dist/api/create/server.d.ts +43 -0
- package/dist/api/create/server.d.ts.map +1 -0
- package/dist/api/depth.d.ts +39 -0
- package/dist/api/depth.d.ts.map +1 -0
- package/dist/api/find/client.d.ts +90 -0
- package/dist/api/find/client.d.ts.map +1 -0
- package/dist/api/find/server.d.ts +73 -0
- package/dist/api/find/server.d.ts.map +1 -0
- package/dist/api/get/client.d.ts +56 -0
- package/dist/api/get/client.d.ts.map +1 -0
- package/dist/api/get/server.d.ts +49 -0
- package/dist/api/get/server.d.ts.map +1 -0
- package/dist/api/globals/find.client.d.ts +20 -0
- package/dist/api/globals/find.client.d.ts.map +1 -0
- package/dist/api/globals/find.server.d.ts +29 -0
- package/dist/api/globals/find.server.d.ts.map +1 -0
- package/dist/api/globals/get.client.d.ts +46 -0
- package/dist/api/globals/get.client.d.ts.map +1 -0
- package/dist/api/globals/get.server.d.ts +55 -0
- package/dist/api/globals/get.server.d.ts.map +1 -0
- package/dist/api/globals/types.d.ts +65 -0
- package/dist/api/globals/types.d.ts.map +1 -0
- package/dist/api/globals/upsert.client.d.ts +24 -0
- package/dist/api/globals/upsert.client.d.ts.map +1 -0
- package/dist/api/globals/upsert.server.d.ts +47 -0
- package/dist/api/globals/upsert.server.d.ts.map +1 -0
- package/dist/api/populate.d.ts +23 -0
- package/dist/api/populate.d.ts.map +1 -0
- package/dist/api/remove/client.d.ts +58 -0
- package/dist/api/remove/client.d.ts.map +1 -0
- package/dist/api/remove/server.d.ts +65 -0
- package/dist/api/remove/server.d.ts.map +1 -0
- package/dist/api/search/client.d.ts +58 -0
- package/dist/api/search/client.d.ts.map +1 -0
- package/dist/api/search/server.d.ts +54 -0
- package/dist/api/search/server.d.ts.map +1 -0
- package/dist/api/server.d.ts +370 -0
- package/dist/api/server.d.ts.map +1 -0
- package/dist/api/server.js +33 -0
- package/dist/api/server.js.map +1 -0
- package/dist/api/types.d.ts +525 -0
- package/dist/api/types.d.ts.map +1 -0
- package/dist/api/update/client.d.ts +53 -0
- package/dist/api/update/client.d.ts.map +1 -0
- package/dist/api/update/server.d.ts +47 -0
- package/dist/api/update/server.d.ts.map +1 -0
- package/dist/api/utils.d.ts +57 -0
- package/dist/api/utils.d.ts.map +1 -0
- package/dist/auth/mergeCollections.d.ts +28 -0
- package/dist/auth/mergeCollections.d.ts.map +1 -0
- package/dist/auth/types.d.ts +84 -0
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/chunk-2DU7JDEX.js +1877 -0
- package/dist/chunk-2DU7JDEX.js.map +1 -0
- package/dist/chunk-2IB2DCN7.js +75 -0
- package/dist/chunk-2IB2DCN7.js.map +1 -0
- package/dist/collections/config.d.ts +28 -0
- package/dist/collections/config.d.ts.map +1 -0
- package/dist/collections/constants.d.ts +27 -0
- package/dist/collections/constants.d.ts.map +1 -0
- package/dist/collections/index.d.ts +7 -0
- package/dist/collections/index.d.ts.map +1 -0
- package/dist/collections/indexFields.d.ts +20 -0
- package/dist/collections/indexFields.d.ts.map +1 -0
- package/dist/collections/interfaceGen.d.ts +59 -0
- package/dist/collections/interfaceGen.d.ts.map +1 -0
- package/dist/collections/internal/index.d.ts +2 -0
- package/dist/collections/internal/index.d.ts.map +1 -0
- package/dist/collections/types.d.ts +282 -0
- package/dist/collections/types.d.ts.map +1 -0
- package/dist/collections/utils.d.ts +71 -0
- package/dist/collections/utils.d.ts.map +1 -0
- package/dist/collections/validator.d.ts +73 -0
- package/dist/collections/validator.d.ts.map +1 -0
- package/dist/config/config.d.ts +43 -0
- package/dist/config/config.d.ts.map +1 -0
- package/dist/config/index.d.ts +5 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/sanitizeConfig.d.ts +82 -0
- package/dist/config/sanitizeConfig.d.ts.map +1 -0
- package/dist/config/types.d.ts +316 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/fields/array/config.d.ts +57 -0
- package/dist/fields/array/config.d.ts.map +1 -0
- package/dist/fields/array/index.d.ts +5 -0
- package/dist/fields/array/index.d.ts.map +1 -0
- package/dist/fields/array/inputSchema.d.ts +32 -0
- package/dist/fields/array/inputSchema.d.ts.map +1 -0
- package/dist/fields/array/types.d.ts +127 -0
- package/dist/fields/array/types.d.ts.map +1 -0
- package/dist/fields/array/validator.d.ts +30 -0
- package/dist/fields/array/validator.d.ts.map +1 -0
- package/dist/fields/baseTypes.d.ts +251 -0
- package/dist/fields/baseTypes.d.ts.map +1 -0
- package/dist/fields/blocks/config.d.ts +63 -0
- package/dist/fields/blocks/config.d.ts.map +1 -0
- package/dist/fields/blocks/index.d.ts +5 -0
- package/dist/fields/blocks/index.d.ts.map +1 -0
- package/dist/fields/blocks/inputSchema.d.ts +22 -0
- package/dist/fields/blocks/inputSchema.d.ts.map +1 -0
- package/dist/fields/blocks/types.d.ts +253 -0
- package/dist/fields/blocks/types.d.ts.map +1 -0
- package/dist/fields/blocks/validator.d.ts +32 -0
- package/dist/fields/blocks/validator.d.ts.map +1 -0
- package/dist/fields/checkbox/config.d.ts +46 -0
- package/dist/fields/checkbox/config.d.ts.map +1 -0
- package/dist/fields/checkbox/index.d.ts +5 -0
- package/dist/fields/checkbox/index.d.ts.map +1 -0
- package/dist/fields/checkbox/inputSchema.d.ts +27 -0
- package/dist/fields/checkbox/inputSchema.d.ts.map +1 -0
- package/dist/fields/checkbox/types.d.ts +67 -0
- package/dist/fields/checkbox/types.d.ts.map +1 -0
- package/dist/fields/checkbox/validator.d.ts +34 -0
- package/dist/fields/checkbox/validator.d.ts.map +1 -0
- package/dist/fields/color/config.d.ts +49 -0
- package/dist/fields/color/config.d.ts.map +1 -0
- package/dist/fields/color/convert.d.ts +72 -0
- package/dist/fields/color/convert.d.ts.map +1 -0
- package/dist/fields/color/formats.d.ts +38 -0
- package/dist/fields/color/formats.d.ts.map +1 -0
- package/dist/fields/color/index.d.ts +8 -0
- package/dist/fields/color/index.d.ts.map +1 -0
- package/dist/fields/color/inputSchema.d.ts +29 -0
- package/dist/fields/color/inputSchema.d.ts.map +1 -0
- package/dist/fields/color/types.d.ts +100 -0
- package/dist/fields/color/types.d.ts.map +1 -0
- package/dist/fields/color/utils.d.ts +100 -0
- package/dist/fields/color/utils.d.ts.map +1 -0
- package/dist/fields/color/validator.d.ts +27 -0
- package/dist/fields/color/validator.d.ts.map +1 -0
- package/dist/fields/constants.d.ts +108 -0
- package/dist/fields/constants.d.ts.map +1 -0
- package/dist/fields/date/config.d.ts +57 -0
- package/dist/fields/date/config.d.ts.map +1 -0
- package/dist/fields/date/index.d.ts +5 -0
- package/dist/fields/date/index.d.ts.map +1 -0
- package/dist/fields/date/inputSchema.d.ts +29 -0
- package/dist/fields/date/inputSchema.d.ts.map +1 -0
- package/dist/fields/date/types.d.ts +147 -0
- package/dist/fields/date/types.d.ts.map +1 -0
- package/dist/fields/date/validator.d.ts +34 -0
- package/dist/fields/date/validator.d.ts.map +1 -0
- package/dist/fields/group/config.d.ts +47 -0
- package/dist/fields/group/config.d.ts.map +1 -0
- package/dist/fields/group/index.d.ts +5 -0
- package/dist/fields/group/index.d.ts.map +1 -0
- package/dist/fields/group/inputSchema.d.ts +27 -0
- package/dist/fields/group/inputSchema.d.ts.map +1 -0
- package/dist/fields/group/types.d.ts +105 -0
- package/dist/fields/group/types.d.ts.map +1 -0
- package/dist/fields/group/validator.d.ts +41 -0
- package/dist/fields/group/validator.d.ts.map +1 -0
- package/dist/fields/index.d.ts +20 -0
- package/dist/fields/index.d.ts.map +1 -0
- package/dist/fields/inputSchemas/index.d.ts +23 -0
- package/dist/fields/inputSchemas/index.d.ts.map +1 -0
- package/dist/fields/inputSchemas/utils.d.ts +25 -0
- package/dist/fields/inputSchemas/utils.d.ts.map +1 -0
- package/dist/fields/interfaceGen.d.ts +15 -0
- package/dist/fields/interfaceGen.d.ts.map +1 -0
- package/dist/fields/number/config.d.ts +48 -0
- package/dist/fields/number/config.d.ts.map +1 -0
- package/dist/fields/number/index.d.ts +5 -0
- package/dist/fields/number/index.d.ts.map +1 -0
- package/dist/fields/number/inputSchema.d.ts +23 -0
- package/dist/fields/number/inputSchema.d.ts.map +1 -0
- package/dist/fields/number/types.d.ts +100 -0
- package/dist/fields/number/types.d.ts.map +1 -0
- package/dist/fields/number/validator.d.ts +39 -0
- package/dist/fields/number/validator.d.ts.map +1 -0
- package/dist/fields/relationship/config.d.ts +45 -0
- package/dist/fields/relationship/config.d.ts.map +1 -0
- package/dist/fields/relationship/index.d.ts +5 -0
- package/dist/fields/relationship/index.d.ts.map +1 -0
- package/dist/fields/relationship/inputSchema.d.ts +31 -0
- package/dist/fields/relationship/inputSchema.d.ts.map +1 -0
- package/dist/fields/relationship/types.d.ts +126 -0
- package/dist/fields/relationship/types.d.ts.map +1 -0
- package/dist/fields/relationship/validator.d.ts +27 -0
- package/dist/fields/relationship/validator.d.ts.map +1 -0
- package/dist/fields/select/config.d.ts +59 -0
- package/dist/fields/select/config.d.ts.map +1 -0
- package/dist/fields/select/index.d.ts +5 -0
- package/dist/fields/select/index.d.ts.map +1 -0
- package/dist/fields/select/inputSchema.d.ts +28 -0
- package/dist/fields/select/inputSchema.d.ts.map +1 -0
- package/dist/fields/select/types.d.ts +89 -0
- package/dist/fields/select/types.d.ts.map +1 -0
- package/dist/fields/select/validator.d.ts +31 -0
- package/dist/fields/select/validator.d.ts.map +1 -0
- package/dist/fields/text/config.d.ts +48 -0
- package/dist/fields/text/config.d.ts.map +1 -0
- package/dist/fields/text/index.d.ts +5 -0
- package/dist/fields/text/index.d.ts.map +1 -0
- package/dist/fields/text/inputSchema.d.ts +24 -0
- package/dist/fields/text/inputSchema.d.ts.map +1 -0
- package/dist/fields/text/types.d.ts +132 -0
- package/dist/fields/text/types.d.ts.map +1 -0
- package/dist/fields/text/validator.d.ts +39 -0
- package/dist/fields/text/validator.d.ts.map +1 -0
- package/dist/fields/types.d.ts +135 -0
- package/dist/fields/types.d.ts.map +1 -0
- package/dist/fields/upload/config.d.ts +24 -0
- package/dist/fields/upload/config.d.ts.map +1 -0
- package/dist/fields/upload/index.d.ts +5 -0
- package/dist/fields/upload/index.d.ts.map +1 -0
- package/dist/fields/upload/inputSchema.d.ts +17 -0
- package/dist/fields/upload/inputSchema.d.ts.map +1 -0
- package/dist/fields/upload/types.d.ts +78 -0
- package/dist/fields/upload/types.d.ts.map +1 -0
- package/dist/fields/upload/validator.d.ts +16 -0
- package/dist/fields/upload/validator.d.ts.map +1 -0
- package/dist/fields/url/config.d.ts +49 -0
- package/dist/fields/url/config.d.ts.map +1 -0
- package/dist/fields/url/index.d.ts +5 -0
- package/dist/fields/url/index.d.ts.map +1 -0
- package/dist/fields/url/inputSchema.d.ts +31 -0
- package/dist/fields/url/inputSchema.d.ts.map +1 -0
- package/dist/fields/url/types.d.ts +70 -0
- package/dist/fields/url/types.d.ts.map +1 -0
- package/dist/fields/url/validator.d.ts +37 -0
- package/dist/fields/url/validator.d.ts.map +1 -0
- package/dist/fields/utils.d.ts +47 -0
- package/dist/fields/utils.d.ts.map +1 -0
- package/dist/fields/validators/index.d.ts +23 -0
- package/dist/fields/validators/index.d.ts.map +1 -0
- package/dist/fields/validators/utils.d.ts +24 -0
- package/dist/fields/validators/utils.d.ts.map +1 -0
- package/dist/framework.d.ts +227 -0
- package/dist/framework.d.ts.map +1 -0
- package/dist/globals/config/config.d.ts +1 -0
- package/dist/globals/config/config.d.ts.map +1 -0
- package/dist/globals/config/types.d.ts +1 -0
- package/dist/globals/config/types.d.ts.map +1 -0
- package/dist/globals/config.d.ts +47 -0
- package/dist/globals/config.d.ts.map +1 -0
- package/dist/globals/index.d.ts +5 -0
- package/dist/globals/index.d.ts.map +1 -0
- package/dist/globals/interfaceGen.d.ts +33 -0
- package/dist/globals/interfaceGen.d.ts.map +1 -0
- package/dist/globals/types.d.ts +175 -0
- package/dist/globals/types.d.ts.map +1 -0
- package/dist/globals/utils.d.ts +37 -0
- package/dist/globals/utils.d.ts.map +1 -0
- package/dist/index.d.ts +15 -3165
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2101 -3475
- package/dist/index.js.map +1 -1
- package/dist/media/api/index.d.ts +5 -0
- package/dist/media/api/index.d.ts.map +1 -0
- package/dist/media/api/mutations.d.ts +76 -0
- package/dist/media/api/mutations.d.ts.map +1 -0
- package/dist/media/api/queries.d.ts +28 -0
- package/dist/media/api/queries.d.ts.map +1 -0
- package/dist/media/api/server.d.ts +68 -0
- package/dist/media/api/server.d.ts.map +1 -0
- package/dist/media/api/types.d.ts +171 -0
- package/dist/media/api/types.d.ts.map +1 -0
- package/dist/media/config.d.ts +25 -0
- package/dist/media/config.d.ts.map +1 -0
- package/dist/media/index.d.ts +6 -0
- package/dist/media/index.d.ts.map +1 -0
- package/dist/media/types.d.ts +332 -0
- package/dist/media/types.d.ts.map +1 -0
- package/dist/media/utils.d.ts +35 -0
- package/dist/media/utils.d.ts.map +1 -0
- package/dist/media/validators.d.ts +61 -0
- package/dist/media/validators.d.ts.map +1 -0
- package/dist/schema/generateVexSchema.d.ts +36 -0
- package/dist/schema/generateVexSchema.d.ts.map +1 -0
- package/dist/schema/index.d.ts +3 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/migrate.d.ts +73 -0
- package/dist/schema/migrate.d.ts.map +1 -0
- package/dist/types/generateVexTypes.d.ts +41 -0
- package/dist/types/generateVexTypes.d.ts.map +1 -0
- package/dist/types/generated.d.ts +382 -0
- package/dist/types/generated.d.ts.map +1 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/utils.d.ts +57 -0
- package/dist/utils.d.ts.map +1 -0
- package/package.json +67 -24
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { RelationshipFieldInput, RelationshipField } from "./types";
|
|
2
|
+
import type { CollectionSlug } from "../../types/generated";
|
|
3
|
+
import { ComponentHKT } from "../baseTypes";
|
|
4
|
+
import { BaseFieldMeta } from "../types";
|
|
5
|
+
/**
|
|
6
|
+
* Creates a relationship field with all defaults applied.
|
|
7
|
+
*
|
|
8
|
+
* Stores Convex `Id` references pointing to documents in another registered collection.
|
|
9
|
+
* The generated Convex schema **always** emits `v.array(v.id("collection"))` regardless
|
|
10
|
+
* of `hasMany` — `hasMany` is a UI-only hint that controls whether the admin picker allows
|
|
11
|
+
* one or multiple selections; it does not change the stored Convex type.
|
|
12
|
+
* A `.index("by_<fieldKey>", ["<fieldKey>"])` is auto-generated for every relationship
|
|
13
|
+
* field — no explicit `index` property needed.
|
|
14
|
+
*
|
|
15
|
+
* `TCollectionSlug` is inferred from `options.collection`. After running `vex generate`,
|
|
16
|
+
* passing an unregistered slug is a compile-time error.
|
|
17
|
+
*
|
|
18
|
+
* **Defaults applied:**
|
|
19
|
+
* - `label` — `""` (inferred from field key by `defineCollection`)
|
|
20
|
+
* - `required` — `false`
|
|
21
|
+
* - `hasMany` — `false`
|
|
22
|
+
* - `admin.hidden` — `false`
|
|
23
|
+
* - `admin.readOnly` — `false`
|
|
24
|
+
* - `admin.position` — `"main"`
|
|
25
|
+
* - `admin.width` — `"full"`
|
|
26
|
+
* - `admin.cellAlignment` — `"left"`
|
|
27
|
+
*
|
|
28
|
+
* @typeParam TCollectionSlug - Inferred from `options.collection`.
|
|
29
|
+
* @param options - Relationship field config. `collection` is required.
|
|
30
|
+
* @returns Resolved relationship field definition with all defaults applied.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* // Single reference — stores Id<"authors">
|
|
35
|
+
* author: relationship({ collection: { slug: "authors" } })
|
|
36
|
+
*
|
|
37
|
+
* // Multi-reference — stores Id<"tags">[]
|
|
38
|
+
* tags: relationship({ collection: { slug: "tags" }, hasMany: true, required: false })
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* @see {@link RelationshipFieldInput} for the full input type
|
|
42
|
+
* @see {@link RelationshipField} for the resolved output type
|
|
43
|
+
*/
|
|
44
|
+
export declare function relationship<TFieldMeta extends BaseFieldMeta = BaseFieldMeta, TCollectionSlug extends CollectionSlug = CollectionSlug, TComponent extends ComponentHKT = ComponentHKT>(options: RelationshipFieldInput<TFieldMeta, TCollectionSlug, TComponent>): RelationshipField<TFieldMeta, TCollectionSlug, TComponent>;
|
|
45
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/fields/relationship/config.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AACzE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAgB,YAAY,CAC1B,UAAU,SAAS,aAAa,GAAG,aAAa,EAChD,eAAe,SAAS,cAAc,GAAG,cAAc,EACvD,UAAU,SAAS,YAAY,GAAG,YAAY,EAE9C,OAAO,EAAE,sBAAsB,CAAC,UAAU,EAAE,eAAe,EAAE,UAAU,CAAC,GACvE,iBAAiB,CAAC,UAAU,EAAE,eAAe,EAAE,UAAU,CAAC,CA0B5D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fields/relationship/index.ts"],"names":[],"mappings":"AACA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type ZodType } from "zod";
|
|
2
|
+
import type { RelationshipField } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Builds a Zod schema for validating a relationship field value in the admin form.
|
|
5
|
+
*
|
|
6
|
+
* Convex document IDs are strings at the form boundary. Single references
|
|
7
|
+
* validate as `z.string()`. Multi-references (`hasMany: true`) validate as
|
|
8
|
+
* `z.array(z.string())` with a default of `[]`. Wraps in `.optional()` for
|
|
9
|
+
* non-required fields via `applyBaseInputSchemaMeta`.
|
|
10
|
+
*
|
|
11
|
+
* @param props - Input props.
|
|
12
|
+
* @param props.field - The resolved relationship field definition.
|
|
13
|
+
* @returns A Zod schema for the relationship value.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* // Single, optional (default)
|
|
18
|
+
* relationshipFieldToInputSchema({ field: relationship({ collection: { slug: "authors" } }) })
|
|
19
|
+
* // → z.array(z.string()).optional().default([])
|
|
20
|
+
*
|
|
21
|
+
* // Multi, required
|
|
22
|
+
* relationshipFieldToInputSchema({ field: relationship({ collection: { slug: "tags" }, hasMany: true, required: true }) })
|
|
23
|
+
* // → z.array(z.string()).default([])
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
export declare function relationshipFieldToInputSchema(props: {
|
|
29
|
+
field: RelationshipField;
|
|
30
|
+
}): ZodType;
|
|
31
|
+
//# sourceMappingURL=inputSchema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inputSchema.d.ts","sourceRoot":"","sources":["../../../src/fields/relationship/inputSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAK,KAAK,OAAO,EAAE,MAAM,KAAK,CAAC;AAEtC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAGjD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,8BAA8B,CAAC,KAAK,EAAE;IACpD,KAAK,EAAE,iBAAiB,CAAC;CAC1B,GAAG,OAAO,CAMV"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { ADMIN_FIELDS } from "../constants";
|
|
2
|
+
import { ApplyComponent, BaseField, BaseFieldInput, ComponentHKT, FieldAdminConfig, FieldAdminConfigInput } from "../baseTypes";
|
|
3
|
+
import { CollectionSlug } from "../../types/generated";
|
|
4
|
+
import { RelationshipPreviewProps } from "../../collections";
|
|
5
|
+
/**
|
|
6
|
+
* Admin configuration input specific to a relationship field instance.
|
|
7
|
+
*
|
|
8
|
+
* Extends {@link FieldAdminConfigInput} with a `components` slot that lets a
|
|
9
|
+
* single field override the preview renderer — taking precedence over the target
|
|
10
|
+
* collection's `admin.components.preview`.
|
|
11
|
+
*
|
|
12
|
+
* @typeParam TCollectionSlug - The target collection slug, inferred from the field's `collection` option.
|
|
13
|
+
* @see {@link RelationshipFieldAdminConfig} for the resolved type after defaults are applied
|
|
14
|
+
* @see {@link FieldAdminConfigInput} for the base admin properties
|
|
15
|
+
*/
|
|
16
|
+
export interface RelationshipFieldAdminInput<TCollectionSlug extends CollectionSlug = CollectionSlug, TComponent extends ComponentHKT = ComponentHKT> extends FieldAdminConfigInput {
|
|
17
|
+
/**
|
|
18
|
+
* Custom component overrides specific to this relationship field instance.
|
|
19
|
+
* These take precedence over the target collection's `admin.components`.
|
|
20
|
+
*/
|
|
21
|
+
components?: {
|
|
22
|
+
/**
|
|
23
|
+
* Per-field override for rendering this relationship's docs. Wins over
|
|
24
|
+
* the target collection's `admin.components.preview`. `TCollectionSlug` is the
|
|
25
|
+
* *target* slug (`fieldDef.collection.slug`).
|
|
26
|
+
*/
|
|
27
|
+
preview?: ApplyComponent<TComponent, RelationshipPreviewProps<TCollectionSlug>>;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Resolved admin configuration for a relationship field after defaults are applied.
|
|
32
|
+
*
|
|
33
|
+
* @typeParam TCollectionSlug - The target collection slug.
|
|
34
|
+
* @see {@link RelationshipFieldAdminInput} for the user-facing input type
|
|
35
|
+
*/
|
|
36
|
+
export interface RelationshipFieldAdminConfig<TCollectionSlug extends CollectionSlug = CollectionSlug, TComponent extends ComponentHKT = ComponentHKT> extends FieldAdminConfig {
|
|
37
|
+
/**
|
|
38
|
+
* Custom component overrides specific to this relationship field instance.
|
|
39
|
+
* These take precedence over the target collection's `admin.components`.
|
|
40
|
+
*/
|
|
41
|
+
components: {
|
|
42
|
+
/**
|
|
43
|
+
* Per-field override for rendering this relationship's docs. Wins over
|
|
44
|
+
* the target collection's `admin.components.preview`. `TCollectionSlug` is the
|
|
45
|
+
* *target* slug (`fieldDef.collection.slug`).
|
|
46
|
+
*/
|
|
47
|
+
preview?: ApplyComponent<TComponent, RelationshipPreviewProps<TCollectionSlug>>;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Configuration input for a `relationship()` field.
|
|
52
|
+
*
|
|
53
|
+
* Stores Convex `Id` references to documents in another registered collection.
|
|
54
|
+
* The Convex schema always uses `v.array(v.id("slug"))` regardless of `hasMany`.
|
|
55
|
+
* `hasMany` is a UI-only hint — `false` shows a single-selection picker,
|
|
56
|
+
* `true` shows a multi-selection picker. `TCollectionSlug` is inferred from the `collection`
|
|
57
|
+
* option — after running `vex generate`, invalid slugs are a compile-time error.
|
|
58
|
+
*
|
|
59
|
+
* **Defaults applied by `relationship()`:**
|
|
60
|
+
* ```ts
|
|
61
|
+
* {
|
|
62
|
+
* type: "relationship",
|
|
63
|
+
* label: "", // inferred from the field key by defineCollection
|
|
64
|
+
* required: false,
|
|
65
|
+
* hasMany: false, // single-select picker in the admin UI; schema is always v.array(v.id())
|
|
66
|
+
* admin: {
|
|
67
|
+
* hidden: false,
|
|
68
|
+
* readOnly: false,
|
|
69
|
+
* position: "main",
|
|
70
|
+
* width: "full",
|
|
71
|
+
* cellAlignment: "left",
|
|
72
|
+
* }
|
|
73
|
+
* }
|
|
74
|
+
*
|
|
75
|
+
* @typeParam TCollectionSlug - The target collection slug. Inferred from `collection`.
|
|
76
|
+
* Defaults to `CollectionSlug` (the full union after `vex generate`).
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```ts
|
|
80
|
+
* // Single reference
|
|
81
|
+
* author: relationship({ collection: { slug: "authors" } })
|
|
82
|
+
*
|
|
83
|
+
* // Multi-reference
|
|
84
|
+
* tags: relationship({ collection: { slug: "tags" }, hasMany: true })
|
|
85
|
+
* ```
|
|
86
|
+
*
|
|
87
|
+
* @see {@link RelationshipField} for the resolved output type
|
|
88
|
+
* @see {@link relationship} for the config function
|
|
89
|
+
* @see {@link CollectionSlug} for the valid slug union
|
|
90
|
+
*/
|
|
91
|
+
export interface RelationshipFieldInput<TFieldMeta extends {} = {}, TCollectionSlug extends CollectionSlug = CollectionSlug, TComponent extends ComponentHKT = ComponentHKT> extends BaseFieldInput<TFieldMeta> {
|
|
92
|
+
/** Target collection reference. The slug must match a registered collection in `defineConfig`. */
|
|
93
|
+
collection: {
|
|
94
|
+
/** The slug of the collection this field links to. Must be a registered collection slug. */
|
|
95
|
+
slug: TCollectionSlug;
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Whether this field stores multiple references.
|
|
99
|
+
* `false` stores a single `Id`, `true` stores `Id[]`.
|
|
100
|
+
* @defaultValue false
|
|
101
|
+
*/
|
|
102
|
+
hasMany?: boolean;
|
|
103
|
+
admin?: BaseFieldInput["admin"] & RelationshipFieldAdminInput<TCollectionSlug, TComponent>;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Resolved configuration for a `relationship()` field, after all defaults are applied.
|
|
107
|
+
*
|
|
108
|
+
* `TCollection` is the string-literal type of the target collection's slug,
|
|
109
|
+
* inferred from `RelationshipFieldInput.collection`.
|
|
110
|
+
*
|
|
111
|
+
* @typeParam TCollection - The target collection slug (inferred from input).
|
|
112
|
+
* @see {@link RelationshipFieldInput} for the user-facing input type
|
|
113
|
+
* @see {@link relationship} for the config function
|
|
114
|
+
*/
|
|
115
|
+
export interface RelationshipField<TFieldMeta extends {} = {}, TCollectionSlug extends CollectionSlug = CollectionSlug, TComponent extends ComponentHKT = ComponentHKT> extends BaseField<TFieldMeta> {
|
|
116
|
+
readonly type: typeof ADMIN_FIELDS.relationship.type;
|
|
117
|
+
/** Target collection reference. */
|
|
118
|
+
collection: {
|
|
119
|
+
/** The slug of the collection this field links to. */
|
|
120
|
+
slug: TCollectionSlug;
|
|
121
|
+
};
|
|
122
|
+
/** Whether this field stores multiple document references. */
|
|
123
|
+
hasMany: boolean;
|
|
124
|
+
admin: BaseField<TFieldMeta>["admin"] & RelationshipFieldAdminConfig<TCollectionSlug, TComponent>;
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/fields/relationship/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EACL,cAAc,EACd,SAAS,EACT,cAAc,EACd,YAAY,EACZ,gBAAgB,EAChB,qBAAqB,EACtB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAE7D;;;;;;;;;;GAUG;AACH,MAAM,WAAW,2BAA2B,CAC1C,eAAe,SAAS,cAAc,GAAG,cAAc,EACvD,UAAU,SAAS,YAAY,GAAG,YAAY,CAC9C,SAAQ,qBAAqB;IAC7B;;;OAGG;IACH,UAAU,CAAC,EAAE;QACX;;;;WAIG;QACH,OAAO,CAAC,EAAE,cAAc,CAAC,UAAU,EAAE,wBAAwB,CAAC,eAAe,CAAC,CAAC,CAAC;KACjF,CAAC;CACH;AAED;;;;;GAKG;AACH,MAAM,WAAW,4BAA4B,CAC3C,eAAe,SAAS,cAAc,GAAG,cAAc,EACvD,UAAU,SAAS,YAAY,GAAG,YAAY,CAC9C,SAAQ,gBAAgB;IACxB;;;OAGG;IACH,UAAU,EAAE;QACV;;;;WAIG;QACH,OAAO,CAAC,EAAE,cAAc,CAAC,UAAU,EAAE,wBAAwB,CAAC,eAAe,CAAC,CAAC,CAAC;KACjF,CAAC;CACH;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,MAAM,WAAW,sBAAsB,CACrC,UAAU,SAAS,EAAE,GAAG,EAAE,EAC1B,eAAe,SAAS,cAAc,GAAG,cAAc,EACvD,UAAU,SAAS,YAAY,GAAG,YAAY,CAC9C,SAAQ,cAAc,CAAC,UAAU,CAAC;IAClC,kGAAkG;IAClG,UAAU,EAAE;QACV,4FAA4F;QAC5F,IAAI,EAAE,eAAe,CAAC;KACvB,CAAC;IACF;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,cAAc,CAAC,OAAO,CAAC,GAC7B,2BAA2B,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC;CAC5D;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,iBAAiB,CAChC,UAAU,SAAS,EAAE,GAAG,EAAE,EAC1B,eAAe,SAAS,cAAc,GAAG,cAAc,EACvD,UAAU,SAAS,YAAY,GAAG,YAAY,CAC9C,SAAQ,SAAS,CAAC,UAAU,CAAC;IAC7B,QAAQ,CAAC,IAAI,EAAE,OAAO,YAAY,CAAC,YAAY,CAAC,IAAI,CAAC;IACrD,mCAAmC;IACnC,UAAU,EAAE;QACV,sDAAsD;QACtD,IAAI,EAAE,eAAe,CAAC;KACvB,CAAC;IACF,8DAA8D;IAC9D,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,SAAS,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,GACnC,4BAA4B,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC;CAC7D"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { RelationshipField } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Converts a relationship field definition to a Convex schema validator string.
|
|
4
|
+
*
|
|
5
|
+
* Emits `v.id("collection")` for single references and
|
|
6
|
+
* `v.array(v.id("collection"))` for multi-references. Wraps in `v.optional()`
|
|
7
|
+
* when `field.required` is `false`.
|
|
8
|
+
*
|
|
9
|
+
* @param props - Input props.
|
|
10
|
+
* @param props.field - The resolved relationship field definition.
|
|
11
|
+
* @returns Convex validator string.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* relationshipFieldToValidator({ field: relationship({ collection: { slug: "authors" }, required: true }) })
|
|
16
|
+
* // → 'v.array(v.id("authors"))'
|
|
17
|
+
*
|
|
18
|
+
* relationshipFieldToValidator({ field: relationship({ collection: { slug: "tags" }, hasMany: true }) })
|
|
19
|
+
* // → 'v.optional(v.array(v.id("tags")))'
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
export declare function relationshipFieldToValidator(props: {
|
|
25
|
+
field: RelationshipField;
|
|
26
|
+
}): string;
|
|
27
|
+
//# sourceMappingURL=validator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../../src/fields/relationship/validator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEjD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,4BAA4B,CAAC,KAAK,EAAE;IAClD,KAAK,EAAE,iBAAiB,CAAC;CAC1B,GAAG,MAAM,CAIT"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { BaseFieldMeta } from "../types";
|
|
2
|
+
import type { SelectFieldInput, SelectField } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Creates a select field with all defaults applied.
|
|
5
|
+
*
|
|
6
|
+
* Select fields store an array of chosen option values — suitable for status
|
|
7
|
+
* labels, categories, tags, or any enumerable choice set. Set `hasMany: false`
|
|
8
|
+
* to restrict to a single selection.
|
|
9
|
+
*
|
|
10
|
+
* Accepts {@link SelectFieldInput} (all optional) and returns {@link SelectField} with all defaults applied.
|
|
11
|
+
*
|
|
12
|
+
* **Defaults applied:**
|
|
13
|
+
* - `label` — `""` (inferred from the field key by `defineCollection`)
|
|
14
|
+
* - `required` — `false`
|
|
15
|
+
* - `defaultValue` — `[]`
|
|
16
|
+
* - `options` — `[]`
|
|
17
|
+
* - `hasMany` — `false`
|
|
18
|
+
* - `admin.hidden` — `false`
|
|
19
|
+
* - `admin.readOnly` — `false`
|
|
20
|
+
* - `admin.position` — `"main"`
|
|
21
|
+
* - `admin.width` — `"full"`
|
|
22
|
+
* - `admin.cellAlignment` — `"left"`
|
|
23
|
+
*
|
|
24
|
+
* @param options - Select field configuration. All properties are optional.
|
|
25
|
+
* @returns Resolved select field definition with all defaults applied.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* import { select, defineCollection } from '@vexcms/core'
|
|
30
|
+
*
|
|
31
|
+
* posts: defineCollection({
|
|
32
|
+
* fields: {
|
|
33
|
+
* // Single-select status field
|
|
34
|
+
* status: select({
|
|
35
|
+
* required: true,
|
|
36
|
+
* options: [
|
|
37
|
+
* { label: "Draft", value: "draft" },
|
|
38
|
+
* { label: "Published", value: "published" },
|
|
39
|
+
* ],
|
|
40
|
+
* }),
|
|
41
|
+
*
|
|
42
|
+
* // Multi-select tag field
|
|
43
|
+
* tags: select({
|
|
44
|
+
* hasMany: true,
|
|
45
|
+
* options: [
|
|
46
|
+
* { label: "News", value: "news" },
|
|
47
|
+
* { label: "Tutorial", value: "tutorial" },
|
|
48
|
+
* { label: "Release", value: "release" },
|
|
49
|
+
* ],
|
|
50
|
+
* }),
|
|
51
|
+
* }
|
|
52
|
+
* })
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* @see {@link SelectFieldInput} for the full input type
|
|
56
|
+
* @see {@link SelectField} for the resolved output type
|
|
57
|
+
*/
|
|
58
|
+
export declare function select<TFieldMeta extends BaseFieldMeta = BaseFieldMeta>(options?: SelectFieldInput<TFieldMeta>): SelectField<TFieldMeta>;
|
|
59
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/fields/select/config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,wBAAgB,MAAM,CAAC,UAAU,SAAS,aAAa,GAAG,aAAa,EACrE,OAAO,CAAC,EAAE,gBAAgB,CAAC,UAAU,CAAC,GACrC,WAAW,CAAC,UAAU,CAAC,CAuBzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fields/select/index.ts"],"names":[],"mappings":"AACA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ZodType } from "zod";
|
|
2
|
+
import { SelectField } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Builds a Zod schema for validating a select field value in the admin form.
|
|
5
|
+
*
|
|
6
|
+
* Validates that submitted values are arrays containing only defined option values.
|
|
7
|
+
* When `hasMany` is false, limits the array to a maximum of one item.
|
|
8
|
+
* Wraps in `.optional()` for non-required fields via `applyBaseInputSchemaMeta`.
|
|
9
|
+
*
|
|
10
|
+
* @param props - Input props.
|
|
11
|
+
* @param props.field - The resolved select field definition
|
|
12
|
+
* @returns A Zod array schema constrained to valid option values, with a baked-in `.default(field.defaultValue)` and optionality applied
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* const field = select({ required: true, options: [{ label: "Draft", value: "draft" }, { label: "Published", value: "published" }] })
|
|
17
|
+
* selectFieldToInputSchema({ field })
|
|
18
|
+
* // → z.array(z.enum(["draft", "published"])).default([])
|
|
19
|
+
*
|
|
20
|
+
* const singleField = select({ hasMany: false, options: [{ label: "Draft", value: "draft" }] })
|
|
21
|
+
* selectFieldToInputSchema({ field: singleField })
|
|
22
|
+
* // → z.array(z.enum(["draft"])).max(1, "Only one value may be selected.").default([])
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function selectFieldToInputSchema(props: {
|
|
26
|
+
field: SelectField;
|
|
27
|
+
}): ZodType;
|
|
28
|
+
//# sourceMappingURL=inputSchema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inputSchema.d.ts","sourceRoot":"","sources":["../../../src/fields/select/inputSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAK,OAAO,EAAE,MAAM,KAAK,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAGtC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE;IAC9C,KAAK,EAAE,WAAW,CAAC;CACpB,GAAG,OAAO,CAoBV"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { ADMIN_FIELDS } from "../constants";
|
|
2
|
+
import { BaseField, BaseFieldInput } from "../baseTypes";
|
|
3
|
+
/**
|
|
4
|
+
* Configuration input for a `select()` field.
|
|
5
|
+
*
|
|
6
|
+
* Select fields store an array of chosen option values — status labels, categories,
|
|
7
|
+
* tags, or any enumerable set. All properties are optional; unset properties fall
|
|
8
|
+
* back to the defaults listed below.
|
|
9
|
+
*
|
|
10
|
+
* **Defaults applied by `select()`:**
|
|
11
|
+
* ```ts
|
|
12
|
+
* {
|
|
13
|
+
* type: "select",
|
|
14
|
+
* label: "", // inferred from the field key by defineCollection
|
|
15
|
+
* required: false, // field is optional by default
|
|
16
|
+
* defaultValue: [], // empty selection
|
|
17
|
+
* options: [], // no options configured
|
|
18
|
+
* hasMany: false, // single-select by default
|
|
19
|
+
* admin: {
|
|
20
|
+
* hidden: false, // visible in the admin form
|
|
21
|
+
* readOnly: false, // editable by default
|
|
22
|
+
* position: "main", // placed in the main content column, not the sidebar
|
|
23
|
+
* width: "full", // spans the full form width, not half
|
|
24
|
+
* cellAlignment: "left", // aligned left in the data table column
|
|
25
|
+
* }
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* // Single-select status
|
|
32
|
+
* status: select({
|
|
33
|
+
* required: true,
|
|
34
|
+
* options: [
|
|
35
|
+
* { label: "Draft", value: "draft" },
|
|
36
|
+
* { label: "Published", value: "published" },
|
|
37
|
+
* ],
|
|
38
|
+
* })
|
|
39
|
+
*
|
|
40
|
+
* // Multi-select tags with badge colours
|
|
41
|
+
* tags: select({
|
|
42
|
+
* hasMany: true,
|
|
43
|
+
* options: [
|
|
44
|
+
* { label: "News", value: "news", badgeColor: "#3b82f6" },
|
|
45
|
+
* { label: "Tutorial", value: "tutorial", badgeColor: "#10b981" },
|
|
46
|
+
* ],
|
|
47
|
+
* })
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* @see {@link BaseFieldInput} for shared properties (`label`, `description`, `required`, `admin`, `index`)
|
|
51
|
+
*/
|
|
52
|
+
export interface SelectFieldInput<TFieldMeta extends {} = {}> extends BaseFieldInput<TFieldMeta> {
|
|
53
|
+
/**
|
|
54
|
+
* Pre-filled value shown in the admin form when creating a new field.
|
|
55
|
+
* Does not apply to database values
|
|
56
|
+
*
|
|
57
|
+
*/
|
|
58
|
+
defaultValue?: string[];
|
|
59
|
+
options?: {
|
|
60
|
+
label: string;
|
|
61
|
+
value: string;
|
|
62
|
+
badgeColor?: string;
|
|
63
|
+
}[];
|
|
64
|
+
hasMany?: boolean;
|
|
65
|
+
optionInterfaceName?: string;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Resolved configuration for a `select()` field, after all defaults are applied.
|
|
69
|
+
*
|
|
70
|
+
* This is the type that framework adapters and field components receive —
|
|
71
|
+
* `fieldDef` in `InputComponentProps<SelectField>` and `CellComponentProps<SelectField>`
|
|
72
|
+
* is this type.
|
|
73
|
+
*
|
|
74
|
+
* @see {@link SelectFieldInput} for the user-facing input type
|
|
75
|
+
* @see {@link select} for the config function that produces this type
|
|
76
|
+
*/
|
|
77
|
+
export interface SelectField<TFieldMeta extends {} = {}> extends BaseField<TFieldMeta> {
|
|
78
|
+
readonly type: typeof ADMIN_FIELDS.select.type;
|
|
79
|
+
/** Pre-filled value shown in the admin form when creating a new field. */
|
|
80
|
+
defaultValue: string[];
|
|
81
|
+
options: {
|
|
82
|
+
label: string;
|
|
83
|
+
value: string;
|
|
84
|
+
badgeColor?: string;
|
|
85
|
+
}[];
|
|
86
|
+
hasMany: boolean;
|
|
87
|
+
optionInterfaceName?: string;
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/fields/select/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEzD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,MAAM,WAAW,gBAAgB,CAC/B,UAAU,SAAS,EAAE,GAAG,EAAE,CAC1B,SAAQ,cAAc,CAAC,UAAU,CAAC;IAClC;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,OAAO,CAAC,EAAE;QACR,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,MAAM,CAAC;QACd,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,EAAE,CAAC;IACJ,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,WAAW,CAAC,UAAU,SAAS,EAAE,GAAG,EAAE,CAAE,SAAQ,SAAS,CAAC,UAAU,CAAC;IACpF,QAAQ,CAAC,IAAI,EAAE,OAAO,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC;IAC/C,0EAA0E;IAC1E,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,OAAO,EAAE;QACP,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,MAAM,CAAC;QACd,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,EAAE,CAAC;IACJ,OAAO,EAAE,OAAO,CAAC;IACjB,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { SelectField } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Converts a select field definition to a Convex schema validator string.
|
|
4
|
+
*
|
|
5
|
+
* Generates a `v.array(v.union(...))` validator where each union member is a
|
|
6
|
+
* `v.literal("value")` for each configured option. Wraps in `v.optional()`
|
|
7
|
+
* when the field is not required.
|
|
8
|
+
*
|
|
9
|
+
* This function is used by the CLI during schema generation to build the Convex schema file.
|
|
10
|
+
*
|
|
11
|
+
* @param props - selectFieldToValidator() input props
|
|
12
|
+
* @param props.field - The resolved select field definition
|
|
13
|
+
* @returns Convex value type string, e.g. `v.array(v.union(v.literal("draft"), v.literal("published")))`
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* const field1 = select({ required: true, options: [{ label: "Draft", value: "draft" }, { label: "Published", value: "published" }] })
|
|
18
|
+
* selectFieldToValidator({ field: field1 })
|
|
19
|
+
* // → 'v.array(v.union(v.literal("draft"), v.literal("published")))'
|
|
20
|
+
*
|
|
21
|
+
* const field2 = select({ required: false, options: [{ label: "Active", value: "active" }] })
|
|
22
|
+
* selectFieldToValidator({ field: field2 })
|
|
23
|
+
* // → 'v.optional(v.array(v.union(v.literal("active"))))'
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @internal - Used by schema generation, not typically called by users
|
|
27
|
+
*/
|
|
28
|
+
export declare function selectFieldToValidator(props: {
|
|
29
|
+
field: SelectField;
|
|
30
|
+
}): string;
|
|
31
|
+
//# sourceMappingURL=validator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../../src/fields/select/validator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE;IAAE,KAAK,EAAE,WAAW,CAAA;CAAE,GAAG,MAAM,CAO5E"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { BaseFieldMeta } from "../types";
|
|
2
|
+
import type { TextFieldInput, TextField } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Creates a text field with all defaults applied.
|
|
5
|
+
*
|
|
6
|
+
* Text fields store short, single-line string values.
|
|
7
|
+
* Common uses: titles, names, slugs, URLs, email addresses.
|
|
8
|
+
*
|
|
9
|
+
* Accepts {@link TextFieldInput} (all optional) and returns {@link TextField} with all defaults applied.
|
|
10
|
+
*
|
|
11
|
+
* **Defaults applied:**
|
|
12
|
+
* - `label` — `""` (inferred from the field key by `defineCollection`)
|
|
13
|
+
* - `required` — `false`
|
|
14
|
+
* - `admin.hidden` — `false`
|
|
15
|
+
* - `admin.readOnly` — `false`
|
|
16
|
+
* - `admin.position` — `"main"`
|
|
17
|
+
* - `admin.width` — `"full"`
|
|
18
|
+
* - `admin.cellAlignment` — `"left"`
|
|
19
|
+
*
|
|
20
|
+
* @param options - Text field configuration. All properties are optional.
|
|
21
|
+
* @returns Resolved text field definition with all defaults applied.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* import { text, defineCollection } from '@vexcms/core'
|
|
26
|
+
*
|
|
27
|
+
* posts: defineCollection({
|
|
28
|
+
* fields: {
|
|
29
|
+
* // Minimal — label inferred from key ("Title")
|
|
30
|
+
* title: text(),
|
|
31
|
+
*
|
|
32
|
+
* // Required slug with length validation and a database index
|
|
33
|
+
* slug: text({ required: true, min: { value: 3 }, max: { value: 100 }, index: "by_slug" }),
|
|
34
|
+
*
|
|
35
|
+
* // Author name with a placeholder hint in the admin form
|
|
36
|
+
* authorName: text({
|
|
37
|
+
* required: true,
|
|
38
|
+
* admin: { width: "half", placeholder: "e.g. Jane Smith" },
|
|
39
|
+
* }),
|
|
40
|
+
* }
|
|
41
|
+
* })
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* @see {@link TextFieldInput} for the full input type
|
|
45
|
+
* @see {@link TextField} for the resolved output type
|
|
46
|
+
*/
|
|
47
|
+
export declare function text<TFieldMeta extends BaseFieldMeta = BaseFieldMeta>(options?: TextFieldInput<TFieldMeta>): TextField<TFieldMeta>;
|
|
48
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/fields/text/config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,wBAAgB,IAAI,CAAC,UAAU,SAAS,aAAa,GAAG,aAAa,EACnE,OAAO,CAAC,EAAE,cAAc,CAAC,UAAU,CAAC,GACnC,SAAS,CAAC,UAAU,CAAC,CA0BvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fields/text/index.ts"],"names":[],"mappings":"AACA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ZodType } from "zod";
|
|
2
|
+
import { TextField } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Builds a Zod schema for validating a text field value in the admin form.
|
|
5
|
+
*
|
|
6
|
+
* Applies `min`/`max` character-length constraints when configured, then
|
|
7
|
+
* wraps in `.optional()` for non-required fields via `applyBaseInputSchemaMeta`.
|
|
8
|
+
*
|
|
9
|
+
* @param props - Input props.
|
|
10
|
+
* @param props.field - The resolved text field definition
|
|
11
|
+
* @returns A Zod string schema with length constraints, a baked-in `.default(field.defaultValue)`, and optionality applied
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const field = text({ required: true, min: { value: 3 }, max: { value: 100 } })
|
|
16
|
+
* textFieldToInputSchema({ field })
|
|
17
|
+
* // → z.string().min(3).max(100).default("")
|
|
18
|
+
* // (a configured `min` supersedes the bare `.min(1)` required check)
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare function textFieldToInputSchema(props: {
|
|
22
|
+
field: TextField;
|
|
23
|
+
}): ZodType;
|
|
24
|
+
//# sourceMappingURL=inputSchema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inputSchema.d.ts","sourceRoot":"","sources":["../../../src/fields/text/inputSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAK,OAAO,EAAE,MAAM,KAAK,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAGpC;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE;IAAE,KAAK,EAAE,SAAS,CAAA;CAAE,GAAG,OAAO,CAkC3E"}
|