@shaxpir/duiduidui-models 1.10.1 → 1.10.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.
|
@@ -51,11 +51,7 @@ export interface RecordTypeCondition extends BaseCondition {
|
|
|
51
51
|
type: 'record_type';
|
|
52
52
|
recordType: RecordType;
|
|
53
53
|
}
|
|
54
|
-
export
|
|
55
|
-
type: 'exclude_record_type';
|
|
56
|
-
recordType: RecordType;
|
|
57
|
-
}
|
|
58
|
-
export type AnyCondition = TagCondition | GradeCondition | ThetaCondition | TemporalCondition | CountCondition | StarredCondition | DifficultyCondition | HasTermCondition | ComponentCondition | RecordTypeCondition | ExcludeRecordTypeCondition;
|
|
54
|
+
export type AnyCondition = TagCondition | GradeCondition | ThetaCondition | TemporalCondition | CountCondition | StarredCondition | DifficultyCondition | HasTermCondition | ComponentCondition | RecordTypeCondition;
|
|
59
55
|
export interface Conditions {
|
|
60
56
|
all?: AnyCondition[];
|
|
61
57
|
any?: AnyCondition[];
|
|
@@ -97,7 +93,6 @@ export declare const Condition: {
|
|
|
97
93
|
hasAnyComponent: (components: string[]) => ComponentCondition;
|
|
98
94
|
hasAllComponents: (components: string[]) => ComponentCondition;
|
|
99
95
|
recordType: (recordType: RecordType) => RecordTypeCondition;
|
|
100
|
-
excludeRecordType: (recordType: RecordType) => ExcludeRecordTypeCondition;
|
|
101
96
|
strokes: () => RecordTypeCondition;
|
|
102
97
|
radicals: () => RecordTypeCondition;
|
|
103
98
|
characters: () => RecordTypeCondition;
|
|
@@ -154,8 +149,7 @@ export declare const Condition: {
|
|
|
154
149
|
getIncludedRecordTypes: (conditions?: Conditions) => RecordType[] | null;
|
|
155
150
|
/**
|
|
156
151
|
* Extract excluded record types from conditions.
|
|
157
|
-
* Returns an array of types to exclude based on
|
|
158
|
-
* or record_type conditions in 'none'.
|
|
152
|
+
* Returns an array of types to exclude based on record_type conditions in 'none'.
|
|
159
153
|
*/
|
|
160
154
|
getExcludedRecordTypes: (conditions?: Conditions) => RecordType[];
|
|
161
155
|
/**
|
|
@@ -163,7 +157,7 @@ export declare const Condition: {
|
|
|
163
157
|
*/
|
|
164
158
|
requiresRecordType: (conditions: Conditions | undefined, recordType: RecordType) => boolean;
|
|
165
159
|
/**
|
|
166
|
-
* Check if a specific record type is excluded
|
|
160
|
+
* Check if a specific record type is excluded (record_type in 'none' section)
|
|
167
161
|
*/
|
|
168
162
|
excludesRecordType: (conditions: Conditions | undefined, recordType: RecordType) => boolean;
|
|
169
163
|
/**
|
package/dist/models/Condition.js
CHANGED
|
@@ -47,8 +47,9 @@ exports.Condition = {
|
|
|
47
47
|
hasAnyComponent: (components) => ({ type: 'component', components, mode: 'any' }),
|
|
48
48
|
hasAllComponents: (components) => ({ type: 'component', components, mode: 'all' }),
|
|
49
49
|
// Record type conditions
|
|
50
|
+
// To include specific types: put recordType in 'all' or 'any'
|
|
51
|
+
// To exclude specific types: put recordType in 'none'
|
|
50
52
|
recordType: (recordType) => ({ type: 'record_type', recordType }),
|
|
51
|
-
excludeRecordType: (recordType) => ({ type: 'exclude_record_type', recordType }),
|
|
52
53
|
// Convenience methods for common record types
|
|
53
54
|
strokes: () => ({ type: 'record_type', recordType: 'stroke' }),
|
|
54
55
|
radicals: () => ({ type: 'record_type', recordType: 'radical' }),
|
|
@@ -187,9 +188,6 @@ exports.Condition = {
|
|
|
187
188
|
const noneRecordTypes = conditions.none
|
|
188
189
|
?.filter(c => c.type === 'record_type')
|
|
189
190
|
.map(c => c.recordType) || [];
|
|
190
|
-
const excludedRecordTypes = conditions.all
|
|
191
|
-
?.filter(c => c.type === 'exclude_record_type')
|
|
192
|
-
.map(c => c.recordType) || [];
|
|
193
191
|
// Check for multiple required record types (an item can only have one record type)
|
|
194
192
|
if (allRecordTypes.length > 1) {
|
|
195
193
|
errors.push(`Cannot require multiple record types: ${allRecordTypes.join(', ')} - an item can only have one record type`);
|
|
@@ -200,12 +198,6 @@ exports.Condition = {
|
|
|
200
198
|
errors.push(`Record type "${rt}" cannot be both required and excluded`);
|
|
201
199
|
}
|
|
202
200
|
});
|
|
203
|
-
// Check for record_type in 'all' conflicting with exclude_record_type for same type
|
|
204
|
-
allRecordTypes.forEach(rt => {
|
|
205
|
-
if (excludedRecordTypes.includes(rt)) {
|
|
206
|
-
errors.push(`Record type "${rt}" cannot be both required (record_type) and excluded (exclude_record_type)`);
|
|
207
|
-
}
|
|
208
|
-
});
|
|
209
201
|
// Check if all record types would be excluded (empty result set)
|
|
210
202
|
const effectiveTypes = exports.Condition.getEffectiveRecordTypes(conditions);
|
|
211
203
|
if (effectiveTypes.length === 0) {
|
|
@@ -242,24 +234,15 @@ exports.Condition = {
|
|
|
242
234
|
},
|
|
243
235
|
/**
|
|
244
236
|
* Extract excluded record types from conditions.
|
|
245
|
-
* Returns an array of types to exclude based on
|
|
246
|
-
* or record_type conditions in 'none'.
|
|
237
|
+
* Returns an array of types to exclude based on record_type conditions in 'none'.
|
|
247
238
|
*/
|
|
248
239
|
getExcludedRecordTypes: (conditions) => {
|
|
249
240
|
if (!conditions)
|
|
250
241
|
return [];
|
|
251
|
-
const excluded = [];
|
|
252
|
-
// Check 'all' section for exclude_record_type conditions
|
|
253
|
-
const allExclusions = conditions.all
|
|
254
|
-
?.filter(c => c.type === 'exclude_record_type')
|
|
255
|
-
.map(c => c.recordType) || [];
|
|
256
|
-
excluded.push(...allExclusions);
|
|
257
242
|
// Check 'none' section for record_type conditions (these types should be excluded)
|
|
258
|
-
|
|
243
|
+
return conditions.none
|
|
259
244
|
?.filter(c => c.type === 'record_type')
|
|
260
245
|
.map(c => c.recordType) || [];
|
|
261
|
-
excluded.push(...noneRecordTypes);
|
|
262
|
-
return [...new Set(excluded)]; // Deduplicate
|
|
263
246
|
},
|
|
264
247
|
/**
|
|
265
248
|
* Check if a specific record type is required (in 'all' section)
|
|
@@ -268,14 +251,10 @@ exports.Condition = {
|
|
|
268
251
|
return !!(conditions?.all?.some(c => c.type === 'record_type' && c.recordType === recordType));
|
|
269
252
|
},
|
|
270
253
|
/**
|
|
271
|
-
* Check if a specific record type is excluded
|
|
254
|
+
* Check if a specific record type is excluded (record_type in 'none' section)
|
|
272
255
|
*/
|
|
273
256
|
excludesRecordType: (conditions, recordType) => {
|
|
274
|
-
|
|
275
|
-
const hasExcludeCondition = conditions?.all?.some(c => c.type === 'exclude_record_type' && c.recordType === recordType);
|
|
276
|
-
// Check record_type in 'none'
|
|
277
|
-
const hasNoneCondition = conditions?.none?.some(c => c.type === 'record_type' && c.recordType === recordType);
|
|
278
|
-
return !!(hasExcludeCondition || hasNoneCondition);
|
|
257
|
+
return !!(conditions?.none?.some(c => c.type === 'record_type' && c.recordType === recordType));
|
|
279
258
|
},
|
|
280
259
|
/**
|
|
281
260
|
* Get the effective record types to query based on conditions.
|
|
@@ -129,16 +129,6 @@ exports.ConditionMatcher = {
|
|
|
129
129
|
}
|
|
130
130
|
return itemType === rtCond.recordType;
|
|
131
131
|
}
|
|
132
|
-
case 'exclude_record_type': {
|
|
133
|
-
const ertCond = condition;
|
|
134
|
-
// Try to get type directly, or derive from phrase_id
|
|
135
|
-
const itemType = item.type ?? (item.phrase_id !== undefined ? (0, RecordType_1.getRecordTypeFromId)(item.phrase_id) : null);
|
|
136
|
-
if (itemType === null) {
|
|
137
|
-
// Cannot determine type - user-created term without type, return true (don't filter out)
|
|
138
|
-
return true;
|
|
139
|
-
}
|
|
140
|
-
return itemType !== ertCond.recordType;
|
|
141
|
-
}
|
|
142
132
|
default:
|
|
143
133
|
// For unsupported conditions, default to true (don't filter out)
|
|
144
134
|
return true;
|