@jsb188/mday 1.1.10 → 1.1.11

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.
Files changed (119) hide show
  1. package/package.json +105 -54
  2. package/src/constants/agentDoc.ts +12 -0
  3. package/src/constants/agentMemory.ts +154 -0
  4. package/src/constants/aiChat.ts +5 -0
  5. package/src/constants/campaign.ts +127 -0
  6. package/src/constants/dataTable.ts +35 -9
  7. package/src/constants/dataTableFieldTypes.generated.ts +63 -0
  8. package/src/constants/docAccess.ts +32 -0
  9. package/src/constants/email.ts +20 -4
  10. package/src/constants/fieldDoc.ts +34 -0
  11. package/src/constants/graphqlReactivity.ts +113 -0
  12. package/src/constants/integration.ts +8 -9
  13. package/src/constants/log.ts +7 -410
  14. package/src/constants/logActivityGroupColors.generated.ts +19 -0
  15. package/src/constants/logTaxonomy.generated.ts +1103 -0
  16. package/src/constants/noteDoc.ts +77 -0
  17. package/src/constants/organization.ts +13 -15
  18. package/src/constants/pageRoute.ts +23 -0
  19. package/src/constants/schedule.ts +220 -0
  20. package/src/constants/scheduleRuleTemplateSeed.ts +138 -0
  21. package/src/constants/scheduleRuleTemplates.generated.ts +145 -0
  22. package/src/constants/sheet.ts +154 -6
  23. package/src/constants/sheetRegionSources.generated.ts +578 -0
  24. package/src/constants/square.ts +6 -6
  25. package/src/constants/storage.ts +56 -7
  26. package/src/constants/usage.ts +79 -0
  27. package/src/schemas/editLogEntry.ts +1010 -777
  28. package/src/schemas/fieldDocsQuery.ts +12 -0
  29. package/src/schemas/inboundContact.ts +60 -55
  30. package/src/schemas/logsQuery.ts +55 -49
  31. package/src/schemas/organization.ts +49 -46
  32. package/src/types/account.d.ts +4 -1
  33. package/src/types/agentDoc.d.ts +64 -0
  34. package/src/types/agentMemory.d.ts +74 -0
  35. package/src/types/campaign.d.ts +683 -0
  36. package/src/types/dataTable.d.ts +175 -256
  37. package/src/types/docAccess.d.ts +96 -0
  38. package/src/types/email.d.ts +83 -12
  39. package/src/types/fieldDoc.d.ts +273 -0
  40. package/src/types/inboundContact.d.ts +2 -1
  41. package/src/types/log.d.ts +209 -341
  42. package/src/types/noteDoc.d.ts +86 -0
  43. package/src/types/organization.d.ts +83 -40
  44. package/src/types/pageRoute.d.ts +48 -0
  45. package/src/types/schedule.d.ts +391 -0
  46. package/src/types/sheet.d.ts +862 -30
  47. package/src/types/storage.d.ts +206 -125
  48. package/src/types/usage.d.ts +106 -0
  49. package/src/types/workflow.d.ts +149 -18
  50. package/src/utils/agentDoc.ts +109 -0
  51. package/src/utils/aiChat.ts +26 -0
  52. package/src/utils/campaign.ts +741 -0
  53. package/src/utils/campaignFormEditor.ts +871 -0
  54. package/src/utils/dataTable.ts +425 -410
  55. package/src/utils/dataTableFieldTypeRegistry.ts +105 -0
  56. package/src/utils/dataTableRealtimeAuthority.ts +209 -0
  57. package/src/utils/dataTableRealtimeSelection.ts +134 -0
  58. package/src/utils/dataTableRowDocument.ts +508 -0
  59. package/src/utils/dataTableSource.ts +230 -0
  60. package/src/utils/docAccess.ts +383 -0
  61. package/src/utils/documentName.ts +53 -0
  62. package/src/utils/email.ts +112 -53
  63. package/src/utils/fieldDoc.ts +113 -0
  64. package/src/utils/log.ts +169 -176
  65. package/src/utils/logRegistryValue.ts +90 -0
  66. package/src/utils/logStoreRead.ts +266 -0
  67. package/src/utils/logTaxonomy.ts +76 -0
  68. package/src/utils/logTaxonomyDisplay.ts +439 -0
  69. package/src/utils/noteDoc.ts +827 -0
  70. package/src/utils/organization.ts +510 -91
  71. package/src/utils/pageRoute.ts +71 -0
  72. package/src/utils/schedule.ts +799 -0
  73. package/src/utils/scheduleEvaluation.ts +1994 -0
  74. package/src/utils/scheduleICS.ts +246 -0
  75. package/src/utils/scheduleRuleTemplates.ts +188 -0
  76. package/src/utils/sheet.ts +4842 -39
  77. package/src/utils/sheetAxisMove.ts +830 -0
  78. package/src/utils/sheetBootstrap.ts +1769 -0
  79. package/src/utils/sheetCommand.ts +423 -0
  80. package/src/utils/sheetExport.ts +238 -0
  81. package/src/utils/sheetFormulaEvaluation.ts +914 -0
  82. package/src/utils/sheetFormulaEvaluator.ts +852 -0
  83. package/src/utils/sheetJournal.ts +78 -0
  84. package/src/utils/sheetNumberFormat.ts +1211 -0
  85. package/src/utils/sheetRegion.ts +374 -0
  86. package/src/utils/sheetRegionFilter.ts +1259 -0
  87. package/src/utils/sheetRegionSourceRegistry.ts +594 -0
  88. package/src/utils/sheetSequence.ts +148 -0
  89. package/src/utils/sheetSnapshot.ts +992 -0
  90. package/src/utils/sheetStructureEdit.ts +1284 -0
  91. package/src/utils/square.ts +22 -12
  92. package/src/utils/storage.ts +152 -0
  93. package/src/utils/table-route.ts +127 -11
  94. package/src/utils/workflow.ts +191 -23
  95. package/tests/dataTableFieldTypeRegistry.test.ts +110 -0
  96. package/tests/docAccess.test.ts +525 -0
  97. package/tests/editLogEntry.test.ts +112 -0
  98. package/tests/noteDoc.test.ts +669 -0
  99. package/tests/schedule.test.ts +693 -0
  100. package/tests/scheduleEvaluation.test.ts +1970 -0
  101. package/tests/scheduleICS.test.ts +208 -0
  102. package/tests/scheduleRuleTemplates.test.ts +176 -0
  103. package/tests/scheduleSweepInvariants.test.ts +428 -0
  104. package/tests/sheetAxisMove.test.ts +343 -0
  105. package/tests/sheetFormulaEvaluator.test.ts +575 -0
  106. package/tests/sheetRegionFilter.test.ts +1135 -0
  107. package/tests/sheetSequence.test.ts +41 -0
  108. package/tests/sheetStructureEdit.test.ts +82 -0
  109. package/tsconfig.json +10 -10
  110. package/vitest.config.ts +8 -0
  111. package/src/constants/log-activityTexts.ts +0 -235
  112. package/src/constants/product.ts +0 -42
  113. package/src/constants/report.ts +0 -44
  114. package/src/schemas/productsQuery.ts +0 -53
  115. package/src/schemas/reportsQuery.ts +0 -20
  116. package/src/types/product.d.ts +0 -84
  117. package/src/types/report.d.ts +0 -290
  118. package/src/utils/product-calEvent.ts +0 -455
  119. package/src/utils/report.ts +0 -158
package/src/utils/log.ts CHANGED
@@ -1,30 +1,104 @@
1
1
  import i18n from '@jsb188/app/i18n/index.ts';
2
2
  import { formatCurrency, formatDecimal } from '@jsb188/app/utils/number.ts';
3
- import { formatReferenceNumber, joinReadable, textWithBrackets, ucFirst } from '@jsb188/app/utils/string.ts';
4
3
  import {
5
- ARABLE_ACTIVITIES_GROUPED,
6
- FARMERS_MARKET_ACTIVITIES_GROUPED,
7
- GROWER_NETWORK_ACTIVITIES_GROUPED,
8
- LIVESTOCK_ACTIVITIES_GROUPED,
9
- LOG_TYPES_BY_OPERATION
4
+ joinReadable,
5
+ textWithBrackets,
6
+ ucFirst,
7
+ } from '@jsb188/app/utils/string.ts';
8
+ import {
9
+ LOG_ACTIVITIES_BY_OPERATION,
10
+ LOG_TYPES_BY_OPERATION,
11
+ PURCHASE_ACTIVITIES,
12
+ SALE_ACTIVITIES,
10
13
  } from '../constants/log.ts';
11
- import type { LogContentName, LogEntryData, LogTypeEnum } from '../types/log.d.ts';
14
+ import { LOG_ACTIVITY_GROUP_COLORS } from '../constants/logActivityGroupColors.generated.ts';
15
+ import type {
16
+ LogContentName,
17
+ LogEntryData,
18
+ LogTypeEnum,
19
+ } from '../types/log.d.ts';
12
20
  import type { OrganizationOperationEnum } from '../types/organization.d.ts';
21
+ import type { SheetCustomRegionSourceColumnFormulaValueSourceEnum } from '../types/sheet.d.ts';
22
+ import {
23
+ getLogEntryDetailsFieldUnitByKey,
24
+ getLogEntryDetailsFieldValueByKey,
25
+ humanizeRegistryKey,
26
+ } from './logTaxonomyDisplay.ts';
27
+
28
+ const FILE_CONSTANTS = {
29
+ accountingActivities: new Set([
30
+ ...PURCHASE_ACTIVITIES,
31
+ ...SALE_ACTIVITIES,
32
+ ] as string[]),
33
+ };
34
+
35
+ type LogRegionSourceFormulaValueSource = {
36
+ accountId?: string | number | bigint | null;
37
+ childOrgId?: string | number | bigint | null;
38
+ id?: string | number | bigint | null;
39
+ inboundContactId?: string | number | bigint | null;
40
+ fieldDocId?: string | number | bigint | null;
41
+ fieldDocSubmissionId?: string | number | bigint | null;
42
+ siteId?: string | number | bigint | null;
43
+ };
44
+
45
+ /*
46
+ * Return the related record id backing one Logs custom source display column.
47
+ */
48
+ export function getLogRegionSourceCellRelatedId(
49
+ log: LogRegionSourceFormulaValueSource | null | undefined,
50
+ formulaValueSource?:
51
+ | SheetCustomRegionSourceColumnFormulaValueSourceEnum
52
+ | string
53
+ | null,
54
+ ): string | number | bigint | null {
55
+ const relatedId = {
56
+ LOG_ACCOUNT_ID: log?.accountId,
57
+ LOG_CHILD_ORGANIZATION_ID: log?.childOrgId,
58
+ LOG_ID: log?.id,
59
+ LOG_INBOUND_CONTACT_ID: log?.inboundContactId,
60
+ LOG_REPORT_ID: log?.fieldDocId,
61
+ LOG_REPORT_SUBMISSION_ID: log?.fieldDocSubmissionId,
62
+ LOG_SITE_ID: log?.siteId,
63
+ }[String(formulaValueSource || '')];
64
+
65
+ return relatedId !== null && relatedId !== undefined ? relatedId : null;
66
+ }
67
+
68
+ /*
69
+ * Return the formula comparison value backing one Logs custom source display column.
70
+ */
71
+ export function getLogRegionSourceCellFormulaValue(
72
+ log: LogRegionSourceFormulaValueSource | null | undefined,
73
+ formulaValueSource?:
74
+ | SheetCustomRegionSourceColumnFormulaValueSourceEnum
75
+ | string
76
+ | null,
77
+ ): string | null {
78
+ const formulaValue = getLogRegionSourceCellRelatedId(log, formulaValueSource);
79
+
80
+ return formulaValue !== null && formulaValue !== undefined
81
+ ? String(formulaValue)
82
+ : null;
83
+ }
84
+
85
+ /*
86
+ * Return whether one log activity uses the shared accounting metadata fields.
87
+ */
88
+ export function isAccountingLogActivity(activity?: string | null) {
89
+ return FILE_CONSTANTS.accountingActivities.has(activity || '');
90
+ }
13
91
 
14
92
  /**
15
93
  * Get content type for log by activity
16
94
  */
17
95
 
18
96
  export function getLogContentName(activity: string): LogContentName {
19
- const value = {
20
- 'SALE_PRODUCE_ORDER': 'invoice',
21
- 'OTHER_SALE_ORDER': 'invoice',
22
- 'FEED_PURCHASE': 'invoice',
23
- 'OTHER_SUPPLY_PURCHASE_ACTIVITY': 'invoice',
24
- 'MARKET_CREDIT_RECEIPT': 'receipt',
25
- }[activity as string] || 'log';
97
+ if (activity === 'MARKET_CREDIT_RECEIPT') {
98
+ return 'receipt';
99
+ }
26
100
 
27
- return value as LogContentName;
101
+ return isAccountingLogActivity(activity) ? 'invoice' : 'log';
28
102
  }
29
103
 
30
104
  /**
@@ -33,59 +107,14 @@ export function getLogContentName(activity: string): LogContentName {
33
107
  * @returns The color associated with the journal type
34
108
  */
35
109
 
36
- export function getLogCategoryColor(type: LogTypeEnum) {
37
- // Do switch operation here
38
- // switch (operation) {
39
- // case 'ARABLE':
40
- // case 'LogArable':
41
- // // ..
42
- // break;
43
- // case 'LIVESTOCK':
44
- // case 'LogLivestock':
45
- // // ..
46
- // break;
47
- // default:
48
- // }
49
-
50
- const logTypeToColor = {
51
- // #### ARABLE
52
- SEED: 'brown',
53
- PLANTING: 'amber',
54
- FIELD: 'lime',
55
- HARVEST: 'emerald',
56
- POST_HARVEST: 'cyan',
57
- SALES: 'blue',
58
- WATER: 'violet',
59
- DELETED: 'medium',
60
-
61
- // #### ARABLE - Food Safety
62
- HYGIENE: 'teal',
63
- SANITATION: 'sky',
64
- EQUIPMENT: 'indigo',
65
- BIOSECURITY: 'green',
66
- EMPLOYEE: 'yellow',
67
-
68
- // #### FARMERS_MARKET
69
- MARKET_RECEIPT: 'blue',
70
- MARKET_OPERATION: 'rose',
71
-
72
- // #### GROWER_NETWORK
73
- WORKER_PRACTICE: 'purple',
74
- PRODUCTION_INPUT: 'sky',
75
- OPERATION: 'yellow',
76
-
77
- // #### LIVESTOCK
78
- SUPPLY_PURCHASE: 'brown',
79
- LIVESTOCK_LIFE_CYCLE: 'amber',
80
- LIVESTOCK_TRACKING: 'lime',
81
- PASTURE_LAND_MANAGEMENT: 'green',
82
- LIVESTOCK_HEALTHCARE: 'teal',
83
- LIVESTOCK_SALE: 'blue',
84
- } as Record<LogTypeEnum, string>;
110
+ export function getLogCategoryColor(
111
+ type: LogTypeEnum | 'DELETED' | string | null | undefined,
112
+ ) {
113
+ if (type === 'DELETED') {
114
+ return 'medium';
115
+ }
85
116
 
86
- // Default to zinc if type is not found
87
- const color = logTypeToColor[type] || 'zinc';
88
- return color;
117
+ return type ? LOG_ACTIVITY_GROUP_COLORS[type] || 'zinc' : 'zinc';
89
118
  }
90
119
 
91
120
  /**
@@ -94,9 +123,11 @@ export function getLogCategoryColor(type: LogTypeEnum) {
94
123
  * @returns Array of log types for the operation
95
124
  */
96
125
 
97
- export function getLogTypesForOperation(operation: OrganizationOperationEnum): LogTypeEnum[] {
126
+ export function getLogTypesForOperation(
127
+ operation: OrganizationOperationEnum,
128
+ ): LogTypeEnum[] {
98
129
  const logTypes = (LOG_TYPES_BY_OPERATION[operation] || []) as LogTypeEnum[];
99
- return logTypes;
130
+ return logTypes;
100
131
  }
101
132
 
102
133
  /**
@@ -106,31 +137,15 @@ export function getLogTypesForOperation(operation: OrganizationOperationEnum): L
106
137
  * @returns The log type or null if not found
107
138
  */
108
139
 
109
- export function getLogTypeFromActivity(operation: OrganizationOperationEnum | string, activity: any): LogTypeEnum | null {
110
- let logGroup;
111
- switch (operation) {
112
- case 'ARABLE':
113
- case 'LogArable':
114
- logGroup = ARABLE_ACTIVITIES_GROUPED.find((group: any) => group[1].includes(activity));
115
- break;
116
- case 'LIVESTOCK':
117
- case 'LogLivestock':
118
- logGroup = LIVESTOCK_ACTIVITIES_GROUPED.find((group: any) => group[1].includes(activity));
119
- break;
120
- case 'FARMERS_MARKET':
121
- case 'LogFarmersMarket':
122
- logGroup = FARMERS_MARKET_ACTIVITIES_GROUPED.find((group: any) => group[1].includes(activity));
123
- break;
124
- case 'GROWER_NETWORK':
125
- case 'LogGrowerNetwork':
126
- logGroup = GROWER_NETWORK_ACTIVITIES_GROUPED.find((group: any) => group[1].includes(activity));
127
- break;
128
- default:
129
- console.warn('(!1) Cannot get log type from unknown operation type:', operation);
130
- return null;
131
- }
140
+ export function getLogTypeFromActivity(
141
+ operation: OrganizationOperationEnum | string,
142
+ activity: any,
143
+ ): LogTypeEnum | null {
144
+ const logGroup = (LOG_ACTIVITIES_BY_OPERATION[operation] || []).find(
145
+ (group: any) => group[1].includes(activity),
146
+ );
132
147
 
133
- return logGroup?.[0] as LogTypeEnum || null;
148
+ return (logGroup?.[0] as LogTypeEnum) || null;
134
149
  }
135
150
 
136
151
  /**
@@ -143,117 +158,95 @@ export function getActivityText(activity: any, tryShortForm?: boolean): string {
143
158
  if (tryShortForm && i18n.has(`log.activity_short.${activity}`)) {
144
159
  return i18n.t(`log.activity_short.${activity}`);
145
160
  }
146
- return i18n.t(`log.activity.${activity}`);
161
+ return i18n.has(`log.activity.${activity}`)
162
+ ? i18n.t(`log.activity.${activity}`)
163
+ : humanizeRegistryKey(activity);
147
164
  }
148
165
 
149
166
  /**
150
- * Get the title for log entry for each Union interface
151
- * @param details - The details Union interface for log entry
167
+ * Get the title for a generic log entry.
168
+ * @param details - The generic details interface for the log entry
152
169
  * @param isServer - True if used in server
153
- * @param logType - Use this param if this function is used in server; {d.type} will be undefined unless manually set
170
+ * @param logType - Optional group-key override for partial or form details
154
171
  * @param iface - In unique cases (such as client-side form), you can use this for interface name
155
172
  * @return The title for the log entry
156
173
  */
157
174
 
158
- export function getLogEntryTitle(d: any, isServer?: boolean, logType_?: string, iface?: string): string {
159
- const { __typename, __table, type } = d;
160
- const logType = logType_ || type;
161
- const md = isServer ? (d.metadata || {}) : d;
175
+ export function getLogEntryTitle(
176
+ d: any,
177
+ isServer?: boolean,
178
+ logType_?: string | null,
179
+ iface?: string,
180
+ ): string {
181
+ const { __typename, __table, type, logType: storedLogType } = d;
182
+ const logType = logType_ || type || storedLogType;
183
+ const md = isServer ? d.metadata || {} : d;
162
184
 
163
185
  switch (iface || __typename || __table) {
164
- case 'ARABLE':
165
- case 'logs_arable':
166
- case 'LogArable': {
167
- const quantityText = joinReadable([formatDecimal(md.quantity, true, true), md.unit], ' ', ' ');
186
+ case 'log_entry_details':
187
+ case 'LogEntryDetails': {
188
+ const quantityText = joinReadable(
189
+ [formatDecimal(md.quantity, true, true), md.unit],
190
+ ' ',
191
+ ' ',
192
+ );
168
193
 
169
194
  let titleItem = ucFirst(md.item);
170
195
  let logSpecificText = '';
171
196
 
172
197
  if (logType === 'WATER') {
173
- logSpecificText = joinReadable([md.concentration, md.concentration && md.concentrationUnit], ' ', ' ');
198
+ const concentration = getLogEntryDetailsFieldValueByKey(
199
+ md,
200
+ 'concentration',
201
+ );
202
+ logSpecificText = joinReadable(
203
+ [
204
+ concentration === null ? null : String(concentration),
205
+ concentration === null
206
+ ? null
207
+ : getLogEntryDetailsFieldUnitByKey(md, 'concentration'),
208
+ ],
209
+ ' ',
210
+ ' ',
211
+ );
174
212
  } else if (['SEED', 'SALES'].includes(logType)) {
175
213
  if (!titleItem) {
176
214
  titleItem = i18n.t('log.unknown_crop');
177
215
  }
178
- const totalPrice = (md?.values || []).reduce((sum: number, item: any) => sum + Number(item.value || 0), 0);
216
+ const totalPrice = (md?.values || []).reduce(
217
+ (sum: number, item: any) => sum + Number(item.value || 0),
218
+ 0,
219
+ );
179
220
  logSpecificText = formatCurrency(totalPrice, false);
180
221
  }
181
222
 
182
223
  // console.log(md);
183
224
  // console.log('titleItem', titleItem);
184
225
 
185
- return textWithBrackets(
186
- titleItem,
187
- [
188
- logSpecificText + (logSpecificText && quantityText ? ',' : ''),
189
- quantityText,
190
- ],
191
- );
192
- }
193
- case 'FARMERS_MARKET':
194
- case 'logs_farmers_market':
195
- case 'LogFarmersMarket': {
196
- let creditsText = '';
197
- if (Array.isArray(md.values) && md.values.length) {
198
- creditsText = md.values.map((item: any) => {
199
- return `${formatCurrency(item.value, false)} ${item.label}`;
200
- }).join(', ');
201
-
202
- const totalAmount = md.values.reduce((sum: number, item: any) => sum + Number(item.value || 0), 0);
203
- creditsText += ` = ${i18n.t('form.total')}: ${formatCurrency(totalAmount, false)}`;
204
- }
205
-
206
- const voidText = isServer && md.voided ? i18n.t('form.void').toUpperCase() : '';
207
- return `${creditsText && voidText ? '(' + voidText + ')' : voidText} ${creditsText}`.trim();
208
- }
209
- case 'GROWER_NETWORK':
210
- case 'logs_grower_network':
211
- case 'LogGrowerNetwork':
212
- return textWithBrackets(
213
- ucFirst(md.item),
214
- md.location,
215
- [' - ', ''],
216
- );
217
- case 'LIVESTOCK':
218
- case 'logs_livestock':
219
- case 'LogLivestock': {
220
- if (['SUPPLY_PURCHASE', 'LIVESTOCK_SALE'].includes(logType)) {
221
- return joinReadable(
222
- [
223
- formatReferenceNumber(md?.referenceNumber),
224
- formatCurrency((md?.values || []).reduce((sum: number, item: any) => sum + Number(item.value || 0), 0), false),
225
- ],
226
- ' - ',
227
- ' - ',
226
+ const priceText = md.price ? formatCurrency(md.price, false) : '';
227
+ if (
228
+ logType === 'MARKET_RECEIPT' &&
229
+ Array.isArray(md.values) &&
230
+ md.values.length
231
+ ) {
232
+ const creditsText = md.values
233
+ .map(
234
+ (item: any) => `${formatCurrency(item.value, false)} ${item.label}`,
235
+ )
236
+ .join(', ');
237
+ const totalAmount = md.values.reduce(
238
+ (sum: number, item: any) => sum + Number(item.value || 0),
239
+ 0,
228
240
  );
241
+ const voidText =
242
+ isServer && md.voided ? i18n.t('form.void').toUpperCase() : '';
243
+ return `${voidText ? `(${voidText}) ` : ''}${creditsText} = ${i18n.t('form.total')}: ${formatCurrency(totalAmount, false)}`;
229
244
  }
230
245
 
231
- if (isServer) {
232
- let livestockText = '';
233
- if (md.livestock) {
234
- livestockText += 'Species: ' + ucFirst(md.livestock) + '\n';
235
- }
236
- if (d.livestockGroup) {
237
- livestockText += 'Group: ' + d.livestockGroup + '\n';
238
- }
239
- if (Array.isArray(d.livestockIdentifiers) && d.livestockIdentifiers.length) {
240
- livestockText += 'Animal ID(s): ' + d.livestockIdentifiers.join(', ') + '\n';
241
- }
242
- if (d.damIdentifier) {
243
- livestockText += 'Dam ID: ' + d.damIdentifier + '\n';
244
- }
245
- return livestockText.trim();
246
- }
247
-
248
- return textWithBrackets(
249
- ucFirst(md.livestock),
250
- (d.livestockGroup ? [d.livestockGroup] : []).concat(
251
- (d.livestockIdentifiers || []).map((id: string) => `#${id}`),
252
- ).join(', ') + (
253
- d.damIdentifier ? ` (Dam: #${d.damIdentifier})` : ''
254
- ),
255
- [' - ', ''],
256
- );
246
+ return textWithBrackets(titleItem, [
247
+ logSpecificText || priceText + (priceText && quantityText ? ',' : ''),
248
+ quantityText,
249
+ ]);
257
250
  }
258
251
  default:
259
252
  }
@@ -0,0 +1,90 @@
1
+ /*
2
+ * Return whether a value is a canonical, real YYYY-MM-DD calendar date.
3
+ */
4
+
5
+ export function isCanonicalLogRegistryDate(value: unknown): value is string {
6
+ if (typeof value !== 'string' || !/^\d{4}-\d{2}-\d{2}$/.test(value)) {
7
+ return false;
8
+ }
9
+
10
+ const [year, month, day] = value.split('-').map(Number);
11
+ const parsed = new Date(Date.UTC(year, month - 1, day));
12
+ return (
13
+ parsed.getUTCFullYear() === year &&
14
+ parsed.getUTCMonth() === month - 1 &&
15
+ parsed.getUTCDate() === day
16
+ );
17
+ }
18
+
19
+ /*
20
+ * Normalize a timezone-qualified datetime value to an ISO instant.
21
+ */
22
+
23
+ export function normalizeLogRegistryDateTime(value: unknown): string | null {
24
+ if (value instanceof Date) {
25
+ return Number.isFinite(value.getTime()) ? value.toISOString() : null;
26
+ }
27
+ if (typeof value !== 'string') {
28
+ return null;
29
+ }
30
+
31
+ const match = value.match(
32
+ /^(\d{4}-\d{2}-\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.\d{3})?(Z|[+-]\d{2}:\d{2})$/,
33
+ );
34
+ if (!match || !isCanonicalLogRegistryDate(match[1])) {
35
+ return null;
36
+ }
37
+
38
+ const hour = Number(match[2]);
39
+ const minute = Number(match[3]);
40
+ const second = Number(match[4]);
41
+ const timezone = match[5];
42
+ const offsetParts =
43
+ timezone === 'Z' ? null : timezone.slice(1).split(':').map(Number);
44
+ if (
45
+ hour > 23 ||
46
+ minute > 59 ||
47
+ second > 59 ||
48
+ (offsetParts && (offsetParts[0] > 23 || offsetParts[1] > 59))
49
+ ) {
50
+ return null;
51
+ }
52
+
53
+ const parsed = new Date(value);
54
+ return Number.isFinite(parsed.getTime()) ? parsed.toISOString() : null;
55
+ }
56
+
57
+ /*
58
+ * Return whether a direct registry field value matches its declared scalar
59
+ * type and, for SELECT fields, its configured option set.
60
+ */
61
+
62
+ export function isValidLogRegistryScalarValue(
63
+ fieldType: string,
64
+ value: unknown,
65
+ options?: string[] | null,
66
+ ): boolean {
67
+ if (fieldType === 'BOOLEAN') {
68
+ return typeof value === 'boolean';
69
+ }
70
+ if (['NUMBER', 'QUANTITY', 'MONEY'].includes(fieldType)) {
71
+ return typeof value === 'number' && Number.isFinite(value);
72
+ }
73
+ if (fieldType === 'DATE') {
74
+ return isCanonicalLogRegistryDate(value);
75
+ }
76
+ if (fieldType === 'DATETIME') {
77
+ return normalizeLogRegistryDateTime(value) !== null;
78
+ }
79
+ if (fieldType === 'SELECT') {
80
+ return (
81
+ typeof value === 'string' &&
82
+ !!value.trim() &&
83
+ !!options?.includes(value.trim())
84
+ );
85
+ }
86
+ if (fieldType === 'TEXT') {
87
+ return typeof value === 'string' && !!value.trim();
88
+ }
89
+ return false;
90
+ }