@marianmeres/collection-types 1.6.0 → 1.7.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/dist/linked-assets.d.ts +183 -0
- package/dist/linked-assets.js +14 -0
- package/dist/mod.d.ts +1 -0
- package/dist/mod.js +2 -0
- package/dist/schema.d.ts +27 -4
- package/package.json +1 -1
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Linked Assets Configuration Types
|
|
3
|
+
*
|
|
4
|
+
* Types for the linked assets feature - a configuration-driven system
|
|
5
|
+
* for displaying assets that are implicitly linked via metadata matching
|
|
6
|
+
* rather than explicit relation records.
|
|
7
|
+
*
|
|
8
|
+
* Used by:
|
|
9
|
+
* - Joy admin (frontend configuration consumption)
|
|
10
|
+
* - Backend (configuration storage and bootstrap)
|
|
11
|
+
*
|
|
12
|
+
* @module linked-assets
|
|
13
|
+
*/
|
|
14
|
+
import type { MaybeLocalized } from "./utils.js";
|
|
15
|
+
/**
|
|
16
|
+
* Comparison operators supported for matching conditions.
|
|
17
|
+
* Maps to @marianmeres/condition-builder OPERATOR enum.
|
|
18
|
+
*/
|
|
19
|
+
export type LinkedAssetOperator = "eq" | "neq" | "lt" | "lte" | "gt" | "gte" | "like" | "ilike" | "in" | "nin" | "?" | "descendant";
|
|
20
|
+
/**
|
|
21
|
+
* Value source: where to get the value for matching.
|
|
22
|
+
* - "literal": use the value as-is
|
|
23
|
+
* - "model_field": extract from current model's data using dot-path
|
|
24
|
+
*/
|
|
25
|
+
export type LinkedAssetValueSource = "literal" | "model_field";
|
|
26
|
+
/**
|
|
27
|
+
* A single matching condition for linked assets.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* // Match assets where data.custom.sku equals model's sku field
|
|
31
|
+
* {
|
|
32
|
+
* asset_field: "data.custom.sku",
|
|
33
|
+
* operator: "eq",
|
|
34
|
+
* value_source: "model_field",
|
|
35
|
+
* value: "sku"
|
|
36
|
+
* }
|
|
37
|
+
*/
|
|
38
|
+
export interface LinkedAssetCondition {
|
|
39
|
+
/**
|
|
40
|
+
* The field path on the asset model to match against.
|
|
41
|
+
* Examples: "type", "data.custom.sku", "folder", "tags"
|
|
42
|
+
*/
|
|
43
|
+
asset_field: string;
|
|
44
|
+
/** Comparison operator */
|
|
45
|
+
operator: LinkedAssetOperator;
|
|
46
|
+
/** How to interpret the value */
|
|
47
|
+
value_source: LinkedAssetValueSource;
|
|
48
|
+
/**
|
|
49
|
+
* The value to match:
|
|
50
|
+
* - If value_source is "literal": the actual value to compare
|
|
51
|
+
* - If value_source is "model_field": dot-path to model field
|
|
52
|
+
*/
|
|
53
|
+
value: string | number | boolean;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Upload configuration for linked assets.
|
|
57
|
+
* When present, enables file upload capability.
|
|
58
|
+
*/
|
|
59
|
+
export interface LinkedAssetUploadConfig {
|
|
60
|
+
/**
|
|
61
|
+
* Auto-populate custom fields from parent model during upload.
|
|
62
|
+
* Key: asset field path (e.g., "custom.sku")
|
|
63
|
+
* Value: model field path (e.g., "sku")
|
|
64
|
+
*/
|
|
65
|
+
auto_fill_custom: Record<string, string>;
|
|
66
|
+
/**
|
|
67
|
+
* Asset type to use for uploads.
|
|
68
|
+
* @default asset_query.type
|
|
69
|
+
*/
|
|
70
|
+
type?: string;
|
|
71
|
+
/**
|
|
72
|
+
* Accepted file types (MIME patterns).
|
|
73
|
+
* @default "image/*"
|
|
74
|
+
*/
|
|
75
|
+
accept?: string;
|
|
76
|
+
/**
|
|
77
|
+
* Maximum number of files (-1 for unlimited).
|
|
78
|
+
* @default -1
|
|
79
|
+
*/
|
|
80
|
+
cardinality?: number;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Unlink configuration for linked assets.
|
|
84
|
+
* Defines how to remove the link between asset and parent model.
|
|
85
|
+
*/
|
|
86
|
+
export interface LinkedAssetUnlinkConfig {
|
|
87
|
+
/**
|
|
88
|
+
* Which custom field to clear when unlinking.
|
|
89
|
+
* Should match a key from upload.auto_fill_custom.
|
|
90
|
+
*/
|
|
91
|
+
field: string;
|
|
92
|
+
/**
|
|
93
|
+
* Require confirmation before unlinking.
|
|
94
|
+
* @default true
|
|
95
|
+
*/
|
|
96
|
+
confirm?: boolean;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Asset query configuration within a rule.
|
|
100
|
+
*/
|
|
101
|
+
export interface LinkedAssetQueryConfig {
|
|
102
|
+
/**
|
|
103
|
+
* Asset domain to query.
|
|
104
|
+
* @default "asset"
|
|
105
|
+
*/
|
|
106
|
+
domain?: string;
|
|
107
|
+
/**
|
|
108
|
+
* Asset entity/collection to query.
|
|
109
|
+
* @default "asset"
|
|
110
|
+
*/
|
|
111
|
+
entity?: string;
|
|
112
|
+
/**
|
|
113
|
+
* Asset type filter (e.g., "product-image").
|
|
114
|
+
* If specified, adds `type:eq:<value>` to conditions.
|
|
115
|
+
*/
|
|
116
|
+
type?: string;
|
|
117
|
+
/**
|
|
118
|
+
* Conditions to build the asset query.
|
|
119
|
+
* Combined with AND logic.
|
|
120
|
+
*/
|
|
121
|
+
conditions: LinkedAssetCondition[];
|
|
122
|
+
/**
|
|
123
|
+
* Always include these base conditions.
|
|
124
|
+
* @default [{ asset_field: "is_enabled", operator: "eq", value_source: "literal", value: true }]
|
|
125
|
+
*/
|
|
126
|
+
base_conditions?: LinkedAssetCondition[];
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Match context configuration.
|
|
130
|
+
* Defines when a rule should be applied.
|
|
131
|
+
*/
|
|
132
|
+
export interface LinkedAssetMatchConfig {
|
|
133
|
+
/** Domain to match (e.g., "product") */
|
|
134
|
+
domain?: string;
|
|
135
|
+
/** Entity/collection to match (e.g., "product", "category") */
|
|
136
|
+
entity?: string;
|
|
137
|
+
/** Type to match (e.g., "default", "variant") */
|
|
138
|
+
type?: string;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* A single linked assets rule configuration.
|
|
142
|
+
* Defines when and how to show/manage linked assets for a specific model context.
|
|
143
|
+
*/
|
|
144
|
+
export interface LinkedAssetRule {
|
|
145
|
+
/** Unique identifier for this rule */
|
|
146
|
+
id: string;
|
|
147
|
+
/** Human-readable label (supports localization) */
|
|
148
|
+
label: MaybeLocalized<string>;
|
|
149
|
+
/** Optional description */
|
|
150
|
+
description?: MaybeLocalized<string>;
|
|
151
|
+
/** When to apply this rule (AND logic, omitted = any) */
|
|
152
|
+
match: LinkedAssetMatchConfig;
|
|
153
|
+
/** Asset query configuration */
|
|
154
|
+
asset_query: LinkedAssetQueryConfig;
|
|
155
|
+
/** Upload configuration - enables CRUD mode when present */
|
|
156
|
+
upload?: LinkedAssetUploadConfig;
|
|
157
|
+
/** Unlink configuration - defines how to remove links */
|
|
158
|
+
unlink?: LinkedAssetUnlinkConfig;
|
|
159
|
+
/**
|
|
160
|
+
* Whether this rule is enabled.
|
|
161
|
+
* @default true
|
|
162
|
+
*/
|
|
163
|
+
enabled?: boolean;
|
|
164
|
+
/**
|
|
165
|
+
* Sort order when multiple rules match (lower = earlier).
|
|
166
|
+
* @default 0
|
|
167
|
+
*/
|
|
168
|
+
order?: number;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* The complete linked assets configuration structure.
|
|
172
|
+
* Stored as the value of the `__joy_linked_assets__` config record.
|
|
173
|
+
*/
|
|
174
|
+
export interface LinkedAssetsConfig {
|
|
175
|
+
/**
|
|
176
|
+
* Schema version for future migrations.
|
|
177
|
+
*/
|
|
178
|
+
version: number;
|
|
179
|
+
/**
|
|
180
|
+
* Array of linked asset rules.
|
|
181
|
+
*/
|
|
182
|
+
rules: LinkedAssetRule[];
|
|
183
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Linked Assets Configuration Types
|
|
3
|
+
*
|
|
4
|
+
* Types for the linked assets feature - a configuration-driven system
|
|
5
|
+
* for displaying assets that are implicitly linked via metadata matching
|
|
6
|
+
* rather than explicit relation records.
|
|
7
|
+
*
|
|
8
|
+
* Used by:
|
|
9
|
+
* - Joy admin (frontend configuration consumption)
|
|
10
|
+
* - Backend (configuration storage and bootstrap)
|
|
11
|
+
*
|
|
12
|
+
* @module linked-assets
|
|
13
|
+
*/
|
|
14
|
+
export {};
|
package/dist/mod.d.ts
CHANGED
package/dist/mod.js
CHANGED
|
@@ -29,5 +29,7 @@ export * from "./schema.js";
|
|
|
29
29
|
export * from "./api.js";
|
|
30
30
|
// Assets
|
|
31
31
|
export * from "./asset.js";
|
|
32
|
+
// Linked Assets (metadata-based linking configuration)
|
|
33
|
+
export * from "./linked-assets.js";
|
|
32
34
|
// Adapter (database layer)
|
|
33
35
|
export * from "./adapter.js";
|
package/dist/schema.d.ts
CHANGED
|
@@ -4,17 +4,21 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import type { MaybeLocalized } from "./utils.js";
|
|
6
6
|
/** HTML field type for UI rendering */
|
|
7
|
-
export type SchemaHtmlType = "text" | "textarea" | "wysiwyg" | "number" | "boolean" | "select" | "multiselect" | "date" | "datetime" | "time" | "color" | "relation" | "asset" | "json" | "code" | "keyvalues";
|
|
7
|
+
export type SchemaHtmlType = "text" | "textarea" | "wysiwyg" | "number" | "boolean" | "checkbox" | "parent" | "object" | "select" | "multiselect" | "date" | "datetime" | "time" | "color" | "relation" | "asset" | "json" | "code" | "keyvalues";
|
|
8
8
|
/** Configuration for relation-type fields in schema */
|
|
9
9
|
export interface RelationTypeConfig {
|
|
10
10
|
relation_type: string;
|
|
11
11
|
domain?: string;
|
|
12
12
|
entity?: string;
|
|
13
13
|
cardinality?: number;
|
|
14
|
+
/** Entity type filter (e.g., "default", "top") */
|
|
15
|
+
type?: string;
|
|
16
|
+
/** Allow unknown relations */
|
|
17
|
+
allow_unknown?: boolean;
|
|
14
18
|
}
|
|
15
19
|
/** Configuration for asset-type fields in schema */
|
|
16
20
|
export interface AssetTypeConfig {
|
|
17
|
-
accept?: string[];
|
|
21
|
+
accept?: string | string[];
|
|
18
22
|
maxSize?: number;
|
|
19
23
|
variants?: string[];
|
|
20
24
|
}
|
|
@@ -35,13 +39,32 @@ export interface KeyValuesConfig {
|
|
|
35
39
|
}
|
|
36
40
|
/** Configuration for _html schema keyword */
|
|
37
41
|
export interface SchemaHtmlConfig {
|
|
38
|
-
type
|
|
42
|
+
/** Field type for UI rendering */
|
|
43
|
+
type?: SchemaHtmlType;
|
|
44
|
+
/** Type-specific configuration */
|
|
39
45
|
_type_config?: RelationTypeConfig | AssetTypeConfig | SelectConfig | KeyValuesConfig;
|
|
46
|
+
/** Display label (can be localized) */
|
|
47
|
+
label?: MaybeLocalized<string>;
|
|
48
|
+
/** Display description (can be localized) */
|
|
49
|
+
description?: MaybeLocalized<string>;
|
|
50
|
+
/** Fieldset grouping label (can be localized) */
|
|
51
|
+
_fieldset?: MaybeLocalized<string>;
|
|
52
|
+
/** Order in model form */
|
|
53
|
+
_model_form_order?: number;
|
|
54
|
+
/** Order in data table */
|
|
55
|
+
_data_table_order?: number;
|
|
56
|
+
/** Number of textarea rows */
|
|
40
57
|
rows?: number;
|
|
58
|
+
/** Input placeholder text */
|
|
41
59
|
placeholder?: string;
|
|
60
|
+
/** Help text */
|
|
42
61
|
help?: string;
|
|
62
|
+
/** Read-only field */
|
|
43
63
|
readonly?: boolean;
|
|
64
|
+
/** Hidden field */
|
|
44
65
|
hidden?: boolean;
|
|
66
|
+
/** UI-specific default (distinct from _default) (typically JSON serialized) */
|
|
67
|
+
_default?: string;
|
|
45
68
|
}
|
|
46
69
|
/**
|
|
47
70
|
* Custom JSON Schema keywords for collection system.
|
|
@@ -51,7 +74,7 @@ export interface CustomSchemaKeywords {
|
|
|
51
74
|
/** Default value for property */
|
|
52
75
|
_default?: unknown;
|
|
53
76
|
/** UI hint configuration object */
|
|
54
|
-
_html?: SchemaHtmlConfig
|
|
77
|
+
_html?: SchemaHtmlConfig;
|
|
55
78
|
/** Property title for display (can be localized) */
|
|
56
79
|
_title?: MaybeLocalized<string>;
|
|
57
80
|
/** Property description for display (can be localized) */
|