@jsb188/mday 1.1.11 → 1.1.12

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 (210) hide show
  1. package/package.json +58 -23
  2. package/src/constants/agentMemory.ts +14 -45
  3. package/src/constants/agentNote.ts +212 -0
  4. package/src/constants/aiChat.ts +5 -0
  5. package/src/constants/billing.ts +126 -0
  6. package/src/constants/campaign.ts +156 -47
  7. package/src/constants/contact.ts +72 -0
  8. package/src/constants/csvExport.ts +133 -0
  9. package/src/constants/dataTable.ts +12 -38
  10. package/src/constants/dataTableFieldTypes.generated.ts +3 -7
  11. package/src/constants/docAccess.ts +3 -2
  12. package/src/constants/dt.ts +234 -0
  13. package/src/constants/email.ts +114 -12
  14. package/src/constants/fieldDoc.ts +74 -4
  15. package/src/constants/graphqlReactivity.ts +108 -25
  16. package/src/constants/log.ts +9 -0
  17. package/src/constants/logDisplay/README.md +88 -0
  18. package/src/constants/logDisplay/defaults.ts +39 -0
  19. package/src/constants/logDisplay/index.ts +27 -0
  20. package/src/constants/logDisplay/operations/arable.ts +16 -0
  21. package/src/constants/logDisplay/operations/farmersMarket.ts +10 -0
  22. package/src/constants/logDisplay/operations/foodManufacturing.ts +13 -0
  23. package/src/constants/logDisplay/shared/accounting.ts +13 -0
  24. package/src/constants/logDisplay/shared/interactions.ts +13 -0
  25. package/src/constants/logDisplay/shared/rackTemperatures.ts +42 -0
  26. package/src/constants/logTaxonomy.generated.ts +1834 -730
  27. package/src/constants/organization.ts +13 -14
  28. package/src/constants/qrCode.ts +30 -0
  29. package/src/constants/sheet.ts +65 -101
  30. package/src/constants/sms.ts +18 -0
  31. package/src/constants/storage.ts +33 -9
  32. package/src/constants/usage.ts +3 -0
  33. package/src/constants/workflowSteps.ts +60 -0
  34. package/src/schemas/editLogEntry.ts +106 -283
  35. package/src/schemas/inboundContact.ts +5 -5
  36. package/src/types/agentMemory.d.ts +38 -14
  37. package/src/types/agentNote.d.ts +443 -0
  38. package/src/types/billing.d.ts +537 -0
  39. package/src/types/campaign.d.ts +1043 -193
  40. package/src/types/contact.d.ts +15 -0
  41. package/src/types/csvExport.d.ts +213 -0
  42. package/src/types/dataAnalysis.d.ts +44 -0
  43. package/src/types/dataTable.d.ts +102 -309
  44. package/src/types/definitionElement.d.ts +35 -0
  45. package/src/types/dt.d.ts +257 -0
  46. package/src/types/email.d.ts +144 -55
  47. package/src/types/emailReplyReport.d.ts +76 -0
  48. package/src/types/fieldDoc.d.ts +579 -150
  49. package/src/types/fieldDocContract.d.ts +90 -0
  50. package/src/types/inboundContact.d.ts +8 -0
  51. package/src/types/log.d.ts +94 -3
  52. package/src/types/logDisplay.types.ts +85 -0
  53. package/src/types/organization.d.ts +8 -3
  54. package/src/types/qrCode.d.ts +96 -0
  55. package/src/types/richText.d.ts +81 -0
  56. package/src/types/sheet.d.ts +180 -463
  57. package/src/types/sms.d.ts +38 -0
  58. package/src/types/storage.d.ts +266 -27
  59. package/src/types/workflow.d.ts +196 -66
  60. package/src/utils/agentMemory.ts +15 -0
  61. package/src/utils/agentNote.ts +850 -0
  62. package/src/utils/aiChat.ts +31 -14
  63. package/src/utils/aiChatWork.ts +64 -0
  64. package/src/utils/billing.ts +37 -0
  65. package/src/utils/campaign.ts +642 -209
  66. package/src/utils/campaignAI.ts +72 -0
  67. package/src/utils/campaignAccess.ts +239 -0
  68. package/src/utils/campaignEmail.ts +601 -0
  69. package/src/utils/campaignEmailCompiler.ts +372 -0
  70. package/src/utils/campaignEmailImages.ts +60 -0
  71. package/src/utils/campaignEmailStyles.ts +544 -0
  72. package/src/utils/campaignLifecycle.ts +104 -0
  73. package/src/utils/campaignPreview.ts +285 -0
  74. package/src/utils/contact.ts +50 -0
  75. package/src/utils/csvExport.ts +19 -0
  76. package/src/utils/dataTable.ts +18 -556
  77. package/src/utils/dataTableFieldTypeRegistry.ts +1 -0
  78. package/src/utils/dataTableRelativeDate.ts +447 -0
  79. package/src/utils/definitionElement.ts +84 -0
  80. package/src/utils/email.ts +208 -1
  81. package/src/utils/emailReplyReport.test.ts +187 -0
  82. package/src/utils/emailReplyReport.ts +143 -0
  83. package/src/utils/fieldDoc.ts +81 -37
  84. package/src/utils/fieldDocAnswers.ts +128 -0
  85. package/src/utils/fieldDocDefaults.ts +36 -0
  86. package/src/utils/fieldDocProgram.ts +36 -0
  87. package/src/utils/fieldDocSummary.ts +30 -0
  88. package/src/utils/log.ts +232 -141
  89. package/src/utils/logDisplay.helpers.ts +177 -0
  90. package/src/utils/logDisplay.ts +87 -0
  91. package/src/utils/logStoreRead.ts +9 -13
  92. package/src/utils/logTaxonomy.helpers.ts +17 -0
  93. package/src/utils/logTaxonomyDisplay.ts +80 -124
  94. package/src/utils/noteDoc.ts +66 -284
  95. package/src/utils/organization.ts +117 -283
  96. package/src/utils/qrCode.helpers.ts +189 -0
  97. package/src/utils/qrCode.test.ts +519 -0
  98. package/src/utils/qrCode.ts +273 -0
  99. package/src/utils/richTextHTML.ts +385 -0
  100. package/src/utils/sheet.ts +123 -4834
  101. package/src/utils/sheetAxisMove.ts +77 -291
  102. package/src/utils/sheetBootstrap.ts +771 -1138
  103. package/src/utils/sheetCellLiteral.ts +101 -0
  104. package/src/utils/sheetCommand.ts +23 -88
  105. package/src/utils/sheetDesign.ts +705 -0
  106. package/src/utils/sheetExport.ts +17 -69
  107. package/src/utils/sheetFeatureReference.ts +183 -0
  108. package/src/utils/sheetFormulaArgs.ts +168 -0
  109. package/src/utils/sheetFormulaCompile.ts +475 -0
  110. package/src/utils/sheetFormulaConditionalAggregate.ts +254 -0
  111. package/src/utils/sheetFormulaCriteria.ts +656 -0
  112. package/src/utils/sheetFormulaDate.ts +444 -0
  113. package/src/utils/sheetFormulaEvaluation.ts +388 -403
  114. package/src/utils/sheetFormulaEvaluator.ts +589 -444
  115. package/src/utils/sheetFormulaFunctionHandlers.ts +403 -0
  116. package/src/utils/sheetFormulaLogical.ts +116 -0
  117. package/src/utils/sheetFormulaLookup.ts +488 -0
  118. package/src/utils/sheetFormulaMath.ts +48 -0
  119. package/src/utils/sheetFormulaParser.ts +729 -0
  120. package/src/utils/sheetFormulaRange.ts +330 -0
  121. package/src/utils/sheetFormulaReference.ts +703 -0
  122. package/src/utils/sheetFormulaReferenceAggregates.ts +313 -0
  123. package/src/utils/sheetFormulaReferenceDates.ts +237 -0
  124. package/src/utils/sheetFormulaReferenceLogical.ts +330 -0
  125. package/src/utils/sheetFormulaReferenceLookup.ts +341 -0
  126. package/src/utils/sheetFormulaReferenceMath.ts +95 -0
  127. package/src/utils/sheetFormulaReferenceRewrite.ts +220 -0
  128. package/src/utils/sheetFormulaReferenceText.ts +462 -0
  129. package/src/utils/sheetFormulaSyntax.ts +1027 -0
  130. package/src/utils/sheetFormulaText.ts +430 -0
  131. package/src/utils/sheetJournal.ts +140 -18
  132. package/src/utils/sheetNumberFormat.ts +68 -267
  133. package/src/utils/sheetPreview.ts +68 -0
  134. package/src/utils/sheetSequence.ts +13 -43
  135. package/src/utils/sheetSnapshot.ts +176 -429
  136. package/src/utils/sheetStructureEdit.ts +537 -907
  137. package/src/utils/sheetStructureReferences.ts +389 -0
  138. package/src/utils/storage.ts +49 -3
  139. package/src/utils/time.ts +12 -0
  140. package/src/utils/workflow.ts +199 -73
  141. package/src/utils/workflowLogFingerprint.ts +302 -0
  142. package/src/utils/workflowLogRevisionSnapshot.ts +424 -0
  143. package/src/utils/workflowProgress.ts +280 -0
  144. package/src/utils/workflowTriggers.ts +61 -0
  145. package/tests/agentNote.test.ts +395 -0
  146. package/tests/campaignAI.test.ts +119 -0
  147. package/tests/campaignAccess.test.ts +239 -0
  148. package/tests/campaignEmail.test.ts +441 -0
  149. package/tests/campaignLifecycle.test.ts +134 -0
  150. package/tests/campaignPublication.test.ts +309 -0
  151. package/tests/dataTableFieldTypeRegistry.test.ts +2 -1
  152. package/tests/dataTableRelativeDate.test.ts +412 -0
  153. package/tests/email.test.ts +39 -0
  154. package/tests/fieldDocProgram.test.ts +114 -0
  155. package/tests/logDisplay.fixtures.ts +67 -0
  156. package/tests/logDisplay.test.ts +227 -0
  157. package/tests/noteDoc.test.ts +37 -192
  158. package/tests/richTextHTML.test.ts +185 -0
  159. package/tests/sheetAxisMove.test.ts +49 -40
  160. package/tests/sheetBootstrap.test.ts +1967 -0
  161. package/tests/sheetFeatureReference.test.ts +22 -0
  162. package/tests/sheetFormulaCriteria.test.ts +269 -0
  163. package/tests/sheetFormulaEvaluator.test.ts +93 -200
  164. package/tests/sheetFormulaFunctions.test.ts +538 -0
  165. package/tests/sheetFormulaLanguage.test.ts +361 -0
  166. package/tests/sheetFormulaParity.fixtures.ts +872 -0
  167. package/tests/sheetFormulaParity.test.ts +188 -0
  168. package/tests/sheetFormulaRange.test.ts +167 -0
  169. package/tests/sheetFormulaReference.test.ts +78 -0
  170. package/tests/sheetFormulaReferenceRewrite.test.ts +117 -0
  171. package/tests/sheetFormulaTextDate.test.ts +512 -0
  172. package/tests/sheetSequence.test.ts +4 -23
  173. package/tests/sheetSnapshot.test.ts +134 -0
  174. package/tests/sheetStructureEdit.test.ts +492 -37
  175. package/tests/sheetStructureReferences.test.ts +589 -0
  176. package/tests/workflowLifecycleStatus.test.ts +60 -0
  177. package/tests/workflowLogFingerprint.test.ts +203 -0
  178. package/tests/workflowLogRevisionSnapshot.test.ts +96 -0
  179. package/tests/workflowProgress.test.ts +180 -0
  180. package/tests/workflowTriggers.test.ts +29 -0
  181. package/src/constants/agentDoc.ts +0 -12
  182. package/src/constants/logActivityGroupColors.generated.ts +0 -19
  183. package/src/constants/schedule.ts +0 -220
  184. package/src/constants/scheduleRuleTemplateSeed.ts +0 -138
  185. package/src/constants/scheduleRuleTemplates.generated.ts +0 -145
  186. package/src/constants/sheetRegionSources.generated.ts +0 -578
  187. package/src/schemas/fieldDocsQuery.ts +0 -12
  188. package/src/schemas/organization.ts +0 -68
  189. package/src/types/agentDoc.d.ts +0 -64
  190. package/src/types/noteDoc.d.ts +0 -86
  191. package/src/types/schedule.d.ts +0 -391
  192. package/src/utils/agentDoc.ts +0 -109
  193. package/src/utils/campaignFormEditor.ts +0 -871
  194. package/src/utils/dataTableRealtimeAuthority.ts +0 -209
  195. package/src/utils/dataTableRealtimeSelection.ts +0 -134
  196. package/src/utils/dataTableRowDocument.ts +0 -508
  197. package/src/utils/dataTableSource.ts +0 -230
  198. package/src/utils/schedule.ts +0 -799
  199. package/src/utils/scheduleEvaluation.ts +0 -1994
  200. package/src/utils/scheduleICS.ts +0 -246
  201. package/src/utils/scheduleRuleTemplates.ts +0 -188
  202. package/src/utils/sheetRegion.ts +0 -374
  203. package/src/utils/sheetRegionFilter.ts +0 -1259
  204. package/src/utils/sheetRegionSourceRegistry.ts +0 -594
  205. package/tests/schedule.test.ts +0 -693
  206. package/tests/scheduleEvaluation.test.ts +0 -1970
  207. package/tests/scheduleICS.test.ts +0 -208
  208. package/tests/scheduleRuleTemplates.test.ts +0 -176
  209. package/tests/scheduleSweepInvariants.test.ts +0 -428
  210. package/tests/sheetRegionFilter.test.ts +0 -1135
@@ -0,0 +1,330 @@
1
+ import type { SheetFormulaFunctionReference } from './sheetFormulaReference.ts';
2
+
3
+ /* Shared reference for the logical builtins added with formula language v4.
4
+ * Merged into SHEET_FORMULA_REFERENCE; every example is executed by the
5
+ * reference test. */
6
+
7
+ const FILE_CONSTANTS = {
8
+ logicalArgs: [
9
+ {
10
+ key: 'logical',
11
+ type: 'boolean-compatible scalar | range',
12
+ description: 'Condition, TRUE/FALSE value, number, or range; additional arguments are allowed.',
13
+ descriptionI18nKey: 'sheet_formula.arg_logical',
14
+ repeatable: true,
15
+ },
16
+ ],
17
+ logicalBehavior:
18
+ 'Every argument is evaluated. Ranges contribute their TRUE/FALSE values and numbers (nonzero is TRUE) and skip text and blanks; a blank argument is skipped; other text must read TRUE or FALSE.',
19
+ logicalError:
20
+ 'INVALID_VALUE (#VALUE!) for text that is not TRUE/FALSE, or when no TRUE/FALSE values remain. Argument errors propagate: AND(FALSE, 1/0) is #DIV/0!.',
21
+ logicalReturns: { type: 'boolean', description: 'TRUE or FALSE.' },
22
+ infoArg: {
23
+ key: 'value',
24
+ type: 'expression',
25
+ description: 'Value, cell, or formula to test.',
26
+ descriptionI18nKey: 'sheet_formula.arg_info_value',
27
+ },
28
+ infoBehavior:
29
+ 'Never returns an error for an error argument: ISBLANK, ISNUMBER and ISTEXT are FALSE for it, so ISNUMBER(SEARCH(...)) tests whether text was found.',
30
+ infoRangeError: 'INVALID_VALUE (#VALUE!) for a range.',
31
+ };
32
+
33
+ export const SHEET_FORMULA_LOGICAL_REFERENCE: Record<
34
+ 'AND' | 'IFS' | 'ISBLANK' | 'ISERROR' | 'ISNA' | 'ISNUMBER' | 'ISTEXT' | 'NOT' | 'OR' | 'SWITCH' | 'XOR',
35
+ SheetFormulaFunctionReference
36
+ > = {
37
+ AND: {
38
+ name: 'AND',
39
+ topic: 'logical',
40
+ signature: 'AND(logical, ...)',
41
+ args: FILE_CONSTANTS.logicalArgs,
42
+ description: 'Returns TRUE when every argument is TRUE.',
43
+ descriptionI18nKey: 'sheet_formula.and_description',
44
+ returns: FILE_CONSTANTS.logicalReturns,
45
+ behavior: [FILE_CONSTANTS.logicalBehavior],
46
+ errors: [FILE_CONSTANTS.logicalError],
47
+ examples: [
48
+ { formula: '=AND(2 > 1, A1)', cells: { A1: true }, expectedValue: true },
49
+ {
50
+ formula: '=AND(A1:A3)',
51
+ cells: { A1: true, A2: 'note', A3: 0 },
52
+ expectedValue: false,
53
+ },
54
+ {
55
+ formula: '=AND("maybe")',
56
+ expectedValue: '#VALUE!',
57
+ expectedErrorCode: 'INVALID_VALUE',
58
+ },
59
+ ],
60
+ },
61
+ IFS: {
62
+ name: 'IFS',
63
+ topic: 'logical',
64
+ signature: 'IFS(condition1, value1, [condition2, value2], ...)',
65
+ args: [
66
+ {
67
+ key: 'condition',
68
+ type: 'boolean-compatible scalar',
69
+ description: 'Condition checked in order.',
70
+ descriptionI18nKey: 'sheet_formula.ifs_arg_condition',
71
+ repeatable: true,
72
+ },
73
+ {
74
+ key: 'value',
75
+ type: 'expression',
76
+ description: 'Value returned, and evaluated, only when its condition is the first TRUE one.',
77
+ descriptionI18nKey: 'sheet_formula.ifs_arg_value',
78
+ repeatable: true,
79
+ },
80
+ ],
81
+ description: 'Returns the value paired with the first TRUE condition.',
82
+ descriptionI18nKey: 'sheet_formula.ifs_description',
83
+ returns: {
84
+ type: 'selected value',
85
+ description: 'The value of the first TRUE condition.',
86
+ },
87
+ behavior: [
88
+ 'Conditions are checked in order and only the selected value is evaluated. Use TRUE as the last condition for a default.',
89
+ 'Blank, zero, and FALSE are false; nonzero numbers and TRUE are true.',
90
+ ],
91
+ errors: [
92
+ 'NOT_FOUND (#N/A) when no condition is TRUE.',
93
+ 'INVALID_VALUE (#VALUE!) for a condition that is a range or text other than TRUE/FALSE.',
94
+ 'INVALID_FORMULA unless the arguments are condition/value pairs.',
95
+ ],
96
+ examples: [
97
+ {
98
+ formula: '=IFS(A1 >= 90, "A", A1 >= 80, "B", TRUE, "C")',
99
+ cells: { A1: 85 },
100
+ expectedValue: 'B',
101
+ },
102
+ {
103
+ formula: '=IFS(A1 > 1, 1/0, TRUE, 5)',
104
+ cells: { A1: 0 },
105
+ expectedValue: 5,
106
+ },
107
+ {
108
+ formula: '=IFS(A1 > 100, "big")',
109
+ cells: { A1: 5 },
110
+ expectedValue: '#N/A',
111
+ expectedErrorCode: 'NOT_FOUND',
112
+ },
113
+ ],
114
+ },
115
+ ISBLANK: {
116
+ name: 'ISBLANK',
117
+ topic: 'logical',
118
+ signature: 'ISBLANK(value)',
119
+ args: [FILE_CONSTANTS.infoArg],
120
+ description: 'Returns TRUE when a value is empty.',
121
+ descriptionI18nKey: 'sheet_formula.isblank_description',
122
+ returns: FILE_CONSTANTS.logicalReturns,
123
+ behavior: ['Empty cells and empty text are blank; 0, FALSE and spaces are not.', FILE_CONSTANTS.infoBehavior],
124
+ errors: [FILE_CONSTANTS.infoRangeError],
125
+ examples: [
126
+ { formula: '=ISBLANK(A1)', expectedValue: true },
127
+ { formula: '=ISBLANK(A1)', cells: { A1: 0 }, expectedValue: false },
128
+ ],
129
+ },
130
+ ISERROR: {
131
+ name: 'ISERROR',
132
+ topic: 'logical',
133
+ signature: 'ISERROR(value)',
134
+ args: [FILE_CONSTANTS.infoArg],
135
+ description: 'Returns TRUE when a value is any formula error.',
136
+ descriptionI18nKey: 'sheet_formula.iserror_description',
137
+ returns: FILE_CONSTANTS.logicalReturns,
138
+ behavior: ['Catches every error, including #N/A; a referenced error cell counts. Use IFERROR to replace the error instead.'],
139
+ errors: ['INVALID_FORMULA unless there is exactly one argument.'],
140
+ examples: [
141
+ { formula: '=ISERROR(1/0)', expectedValue: true },
142
+ { formula: '=ISERROR("#N/A")', expectedValue: false },
143
+ ],
144
+ },
145
+ ISNA: {
146
+ name: 'ISNA',
147
+ topic: 'logical',
148
+ signature: 'ISNA(value)',
149
+ args: [FILE_CONSTANTS.infoArg],
150
+ description: 'Returns TRUE when a value is the #N/A (not found) error.',
151
+ descriptionI18nKey: 'sheet_formula.isna_description',
152
+ returns: FILE_CONSTANTS.logicalReturns,
153
+ behavior: ['Other errors, such as #DIV/0!, are FALSE.'],
154
+ errors: ['INVALID_FORMULA unless there is exactly one argument.'],
155
+ examples: [
156
+ {
157
+ formula: '=ISNA(MATCH("z", A1:A2, 0))',
158
+ cells: { A1: 'a', A2: 'b' },
159
+ expectedValue: true,
160
+ },
161
+ { formula: '=ISNA(1/0)', expectedValue: false },
162
+ ],
163
+ },
164
+ ISNUMBER: {
165
+ name: 'ISNUMBER',
166
+ topic: 'logical',
167
+ signature: 'ISNUMBER(value)',
168
+ args: [FILE_CONSTANTS.infoArg],
169
+ description: 'Returns TRUE when a value is a number.',
170
+ descriptionI18nKey: 'sheet_formula.isnumber_description',
171
+ returns: FILE_CONSTANTS.logicalReturns,
172
+ behavior: ['Numeric text such as "5" and dates (ISO text) are not numbers.', FILE_CONSTANTS.infoBehavior],
173
+ errors: [FILE_CONSTANTS.infoRangeError],
174
+ examples: [
175
+ { formula: '=ISNUMBER(A1)', cells: { A1: 12.5 }, expectedValue: true },
176
+ {
177
+ formula: '=IF(ISNUMBER(SEARCH("vip", A1)), "VIP", "")',
178
+ cells: { A1: 'Gold VIP' },
179
+ expectedValue: 'VIP',
180
+ },
181
+ ],
182
+ },
183
+ ISTEXT: {
184
+ name: 'ISTEXT',
185
+ topic: 'logical',
186
+ signature: 'ISTEXT(value)',
187
+ args: [FILE_CONSTANTS.infoArg],
188
+ description: 'Returns TRUE when a value is nonempty text.',
189
+ descriptionI18nKey: 'sheet_formula.istext_description',
190
+ returns: FILE_CONSTANTS.logicalReturns,
191
+ behavior: [
192
+ 'ISO dates are text in this dialect, so ISTEXT("2026-01-05") is TRUE. Empty text is blank, not text.',
193
+ FILE_CONSTANTS.infoBehavior,
194
+ ],
195
+ errors: [FILE_CONSTANTS.infoRangeError],
196
+ examples: [
197
+ { formula: '=ISTEXT(A1)', cells: { A1: 'abc' }, expectedValue: true },
198
+ { formula: '=ISTEXT(12)', expectedValue: false },
199
+ ],
200
+ },
201
+ NOT: {
202
+ name: 'NOT',
203
+ topic: 'logical',
204
+ signature: 'NOT(logical)',
205
+ args: [
206
+ {
207
+ key: 'logical',
208
+ type: 'boolean-compatible scalar',
209
+ description: 'Condition or TRUE/FALSE value to reverse.',
210
+ descriptionI18nKey: 'sheet_formula.not_arg_logical',
211
+ },
212
+ ],
213
+ description: 'Reverses a TRUE/FALSE value.',
214
+ descriptionI18nKey: 'sheet_formula.not_description',
215
+ returns: FILE_CONSTANTS.logicalReturns,
216
+ behavior: ['A blank argument is FALSE, so NOT of a blank cell is TRUE.'],
217
+ errors: ['INVALID_VALUE (#VALUE!) for a range or text other than TRUE/FALSE.'],
218
+ examples: [
219
+ { formula: '=NOT(A1 > 5)', cells: { A1: 3 }, expectedValue: true },
220
+ { formula: '=NOT(A1)', expectedValue: true },
221
+ {
222
+ formula: '=NOT("maybe")',
223
+ expectedValue: '#VALUE!',
224
+ expectedErrorCode: 'INVALID_VALUE',
225
+ },
226
+ ],
227
+ },
228
+ OR: {
229
+ name: 'OR',
230
+ topic: 'logical',
231
+ signature: 'OR(logical, ...)',
232
+ args: FILE_CONSTANTS.logicalArgs,
233
+ description: 'Returns TRUE when any argument is TRUE.',
234
+ descriptionI18nKey: 'sheet_formula.or_description',
235
+ returns: FILE_CONSTANTS.logicalReturns,
236
+ behavior: [FILE_CONSTANTS.logicalBehavior],
237
+ errors: [FILE_CONSTANTS.logicalError],
238
+ examples: [
239
+ {
240
+ formula: '=OR(A1 > 5, A2 = "x")',
241
+ cells: { A1: 3, A2: 'x' },
242
+ expectedValue: true,
243
+ },
244
+ {
245
+ formula: '=OR(A1:A2)',
246
+ cells: { A1: false, A2: 0 },
247
+ expectedValue: false,
248
+ },
249
+ ],
250
+ },
251
+ SWITCH: {
252
+ name: 'SWITCH',
253
+ topic: 'logical',
254
+ signature: 'SWITCH(expression, case1, value1, [case2, value2], ..., [default])',
255
+ args: [
256
+ {
257
+ key: 'expression',
258
+ type: 'scalar',
259
+ description: 'Value compared with each case.',
260
+ descriptionI18nKey: 'sheet_formula.switch_arg_expression',
261
+ },
262
+ {
263
+ key: 'case',
264
+ type: 'scalar',
265
+ description: 'Value to compare with the expression.',
266
+ descriptionI18nKey: 'sheet_formula.switch_arg_case',
267
+ repeatable: true,
268
+ },
269
+ {
270
+ key: 'value',
271
+ type: 'expression',
272
+ description: 'Result for its case; a lone final argument is the default.',
273
+ descriptionI18nKey: 'sheet_formula.switch_arg_value',
274
+ repeatable: true,
275
+ },
276
+ ],
277
+ description: 'Returns the value of the first case equal to the expression, or the default.',
278
+ descriptionI18nKey: 'sheet_formula.switch_description',
279
+ returns: {
280
+ type: 'selected value',
281
+ description: 'The matching case value or the default.',
282
+ },
283
+ behavior: [
284
+ 'The expression is evaluated once and cases in order; only the chosen value is evaluated.',
285
+ 'Comparison ignores text case and treats a number and its numeric text as equal. A blank expression matches a blank case.',
286
+ ],
287
+ errors: [
288
+ 'NOT_FOUND (#N/A) when no case matches and there is no default.',
289
+ 'INVALID_VALUE (#VALUE!) for a range expression or case.',
290
+ 'INVALID_FORMULA with fewer than three arguments.',
291
+ ],
292
+ examples: [
293
+ {
294
+ formula: '=SWITCH(A1, "n", "North", "s", "South", "Other")',
295
+ cells: { A1: 'N' },
296
+ expectedValue: 'North',
297
+ },
298
+ {
299
+ formula: '=SWITCH(A1, "n", "North", "s", "South", "Other")',
300
+ cells: { A1: 'e' },
301
+ expectedValue: 'Other',
302
+ },
303
+ {
304
+ formula: '=SWITCH(A1, 1, "one", 2, "two")',
305
+ cells: { A1: 3 },
306
+ expectedValue: '#N/A',
307
+ expectedErrorCode: 'NOT_FOUND',
308
+ },
309
+ ],
310
+ },
311
+ XOR: {
312
+ name: 'XOR',
313
+ topic: 'logical',
314
+ signature: 'XOR(logical, ...)',
315
+ args: FILE_CONSTANTS.logicalArgs,
316
+ description: 'Returns TRUE when an odd number of arguments are TRUE.',
317
+ descriptionI18nKey: 'sheet_formula.xor_description',
318
+ returns: FILE_CONSTANTS.logicalReturns,
319
+ behavior: [FILE_CONSTANTS.logicalBehavior],
320
+ errors: [FILE_CONSTANTS.logicalError],
321
+ examples: [
322
+ { formula: '=XOR(TRUE, TRUE, TRUE)', expectedValue: true },
323
+ {
324
+ formula: '=XOR(A1:A2)',
325
+ cells: { A1: true, A2: 1 },
326
+ expectedValue: false,
327
+ },
328
+ ],
329
+ },
330
+ };
@@ -0,0 +1,341 @@
1
+ import type { SheetFormulaFunctionReference } from './sheetFormulaReference.ts';
2
+
3
+ /* Shared reference for the lookup builtins added with formula language v4.
4
+ * Merged into SHEET_FORMULA_REFERENCE; every example is executed by the
5
+ * reference test. */
6
+
7
+ const FILE_CONSTANTS = {
8
+ exactMatchBehavior:
9
+ 'Exact matches ignore text case and treat 1 and "1" as equal; a blank key never matches. A text key with * ? or ~ is a wildcard pattern.',
10
+ approximateBehavior:
11
+ 'The approximate match expects ascending keys: it returns the last key <= search_key before the first larger one, comparing only keys of the same type.',
12
+ blankResultBehavior: 'A blank result cell returns blank.',
13
+ searchKeyArg: {
14
+ key: 'search_key',
15
+ type: 'scalar',
16
+ description: 'Value to look for.',
17
+ descriptionI18nKey: 'sheet_formula.arg_search_key',
18
+ },
19
+ sortedArg: {
20
+ key: 'is_sorted',
21
+ type: 'boolean',
22
+ description: 'TRUE (default, as in Excel) for an approximate match on sorted keys; pass FALSE for an exact match.',
23
+ descriptionI18nKey: 'sheet_formula.arg_is_sorted',
24
+ optional: true,
25
+ },
26
+ tableLookupErrors: [
27
+ 'NOT_FOUND (#N/A) when the key is not found.',
28
+ 'INVALID_REFERENCE (#REF!) when index is beyond the range; INVALID_VALUE (#VALUE!) when index is below 1 or not a number.',
29
+ ],
30
+ };
31
+
32
+ export const SHEET_FORMULA_LOOKUP_REFERENCE: Record<
33
+ 'HLOOKUP' | 'INDEX' | 'MATCH' | 'UNIQUE' | 'VLOOKUP' | 'XLOOKUP',
34
+ SheetFormulaFunctionReference
35
+ > = {
36
+ HLOOKUP: {
37
+ name: 'HLOOKUP',
38
+ topic: 'lookup',
39
+ signature: 'HLOOKUP(search_key, range, index, [is_sorted])',
40
+ args: [
41
+ FILE_CONSTANTS.searchKeyArg,
42
+ {
43
+ key: 'range',
44
+ type: 'range',
45
+ description: 'Range whose first row holds the keys.',
46
+ descriptionI18nKey: 'sheet_formula.hlookup_arg_range',
47
+ },
48
+ {
49
+ key: 'index',
50
+ type: 'number',
51
+ description: '1-based row of the range to return.',
52
+ descriptionI18nKey: 'sheet_formula.hlookup_arg_index',
53
+ },
54
+ FILE_CONSTANTS.sortedArg,
55
+ ],
56
+ description: 'Finds a key in the first row of a range and returns the value from another row of the same column.',
57
+ descriptionI18nKey: 'sheet_formula.hlookup_description',
58
+ returns: { type: 'scalar', description: 'The value at the found column.' },
59
+ behavior: [FILE_CONSTANTS.exactMatchBehavior, FILE_CONSTANTS.approximateBehavior, FILE_CONSTANTS.blankResultBehavior],
60
+ errors: FILE_CONSTANTS.tableLookupErrors,
61
+ examples: [
62
+ {
63
+ formula: '=HLOOKUP("q2", A1:C2, 2, FALSE)',
64
+ cells: { A1: 'Q1', B1: 'Q2', C1: 'Q3', A2: 10, B2: 20, C2: 30 },
65
+ expectedValue: 20,
66
+ },
67
+ ],
68
+ },
69
+ INDEX: {
70
+ name: 'INDEX',
71
+ topic: 'lookup',
72
+ signature: 'INDEX(range, row, [column])',
73
+ args: [
74
+ {
75
+ key: 'range',
76
+ type: 'range',
77
+ description: 'Range or UNIQUE result to read.',
78
+ descriptionI18nKey: 'sheet_formula.index_arg_range',
79
+ },
80
+ {
81
+ key: 'row',
82
+ type: 'number',
83
+ description: '1-based row; for a one-row range, a single index is the column.',
84
+ descriptionI18nKey: 'sheet_formula.index_arg_row',
85
+ },
86
+ {
87
+ key: 'column',
88
+ type: 'number',
89
+ description: '1-based column; required when the range has several rows and columns.',
90
+ descriptionI18nKey: 'sheet_formula.index_arg_column',
91
+ optional: true,
92
+ },
93
+ ],
94
+ description: 'Returns the value at a row and column position of a range.',
95
+ descriptionI18nKey: 'sheet_formula.index_description',
96
+ returns: { type: 'scalar', description: 'The value at that position.' },
97
+ behavior: ['Row or column 0 (a whole row or column) is not supported.', FILE_CONSTANTS.blankResultBehavior],
98
+ errors: [
99
+ 'INVALID_REFERENCE (#REF!) when the position is outside the range.',
100
+ 'INVALID_VALUE (#VALUE!) for 0, negative, or non-numeric positions, or a missing column on a two-dimensional range.',
101
+ ],
102
+ examples: [
103
+ {
104
+ formula: '=INDEX(A1:B2, 2, 1)',
105
+ cells: { A1: 1, B1: 2, A2: 3, B2: 4 },
106
+ expectedValue: 3,
107
+ },
108
+ {
109
+ formula: '=INDEX(A1:C1, 3)',
110
+ cells: { A1: 'x', B1: 'y', C1: 'z' },
111
+ expectedValue: 'z',
112
+ },
113
+ {
114
+ formula: '=INDEX(A1:A2, 5)',
115
+ expectedValue: '#REF!',
116
+ expectedErrorCode: 'INVALID_REFERENCE',
117
+ },
118
+ ],
119
+ },
120
+ MATCH: {
121
+ name: 'MATCH',
122
+ topic: 'lookup',
123
+ signature: 'MATCH(search_key, range, [match_type])',
124
+ args: [
125
+ FILE_CONSTANTS.searchKeyArg,
126
+ {
127
+ key: 'range',
128
+ type: 'range',
129
+ description: 'One-row or one-column range to search.',
130
+ descriptionI18nKey: 'sheet_formula.match_arg_range',
131
+ },
132
+ {
133
+ key: 'match_type',
134
+ type: 'number',
135
+ description: '1 (default): largest value <= key in ascending data; 0: exact; -1: smallest value >= key in descending data.',
136
+ descriptionI18nKey: 'sheet_formula.match_arg_match_type',
137
+ optional: true,
138
+ },
139
+ ],
140
+ description: 'Returns the 1-based position of a key in a one-row or one-column range.',
141
+ descriptionI18nKey: 'sheet_formula.match_description',
142
+ returns: { type: 'number', description: 'Position of the match.' },
143
+ behavior: [
144
+ FILE_CONSTANTS.exactMatchBehavior,
145
+ 'The default match_type 1 expects ascending data, as in Excel; pass 0 for an exact match.',
146
+ ],
147
+ errors: ['NOT_FOUND (#N/A) when the key is not found or the range has several rows and columns.'],
148
+ examples: [
149
+ {
150
+ formula: '=MATCH("b*", A1:A3, 0)',
151
+ cells: { A1: 'apple', A2: 'Banana', A3: 'cherry' },
152
+ expectedValue: 2,
153
+ },
154
+ {
155
+ formula: '=MATCH(25, A1:A3)',
156
+ cells: { A1: 10, A2: 20, A3: 30 },
157
+ expectedValue: 2,
158
+ },
159
+ {
160
+ formula: '=MATCH("z", A1:A2, 0)',
161
+ cells: { A1: 'a', A2: 'b' },
162
+ expectedValue: '#N/A',
163
+ expectedErrorCode: 'NOT_FOUND',
164
+ },
165
+ ],
166
+ },
167
+ UNIQUE: {
168
+ name: 'UNIQUE',
169
+ topic: 'lookup',
170
+ signature: 'UNIQUE(range, [by_column], [exactly_once])',
171
+ args: [
172
+ {
173
+ key: 'range',
174
+ type: 'range',
175
+ description: 'Range whose distinct rows are kept.',
176
+ descriptionI18nKey: 'sheet_formula.unique_arg_range',
177
+ },
178
+ {
179
+ key: 'by_column',
180
+ type: 'boolean',
181
+ description: 'TRUE compares columns instead of rows. Defaults to FALSE.',
182
+ descriptionI18nKey: 'sheet_formula.unique_arg_by_column',
183
+ optional: true,
184
+ },
185
+ {
186
+ key: 'exactly_once',
187
+ type: 'boolean',
188
+ description: 'TRUE keeps only rows that appear once. Defaults to FALSE.',
189
+ descriptionI18nKey: 'sheet_formula.unique_arg_exactly_once',
190
+ optional: true,
191
+ },
192
+ ],
193
+ description: 'Returns the distinct rows of a range as a list for COUNTA, INDEX, SUM, or other functions that read ranges.',
194
+ descriptionI18nKey: 'sheet_formula.unique_description',
195
+ returns: {
196
+ type: 'array',
197
+ description: 'Distinct rows in first-seen order; it cannot be the whole formula result.',
198
+ },
199
+ behavior: [
200
+ 'Results do not spill into neighboring cells, so wrap UNIQUE, as in COUNTA(UNIQUE(A2:A100)).',
201
+ 'Rows compare ignoring text case (1 equals "1"); the first occurrence is kept. All-blank rows are ignored.',
202
+ ],
203
+ errors: [
204
+ 'INVALID_FORMULA (#ERROR!) when UNIQUE is the whole formula result.',
205
+ 'INVALID_VALUE (#VALUE!) when the first argument is not a range.',
206
+ ],
207
+ examples: [
208
+ {
209
+ formula: '=COUNTA(UNIQUE(A1:A4))',
210
+ cells: { A1: 'a', A2: 'A', A3: 'b', A4: null },
211
+ expectedValue: 2,
212
+ },
213
+ {
214
+ formula: '=INDEX(UNIQUE(A1:A3), 2)',
215
+ cells: { A1: 'x', A2: 'x', A3: 'y' },
216
+ expectedValue: 'y',
217
+ },
218
+ {
219
+ formula: '=COUNTA(UNIQUE(A1:A3, FALSE, TRUE))',
220
+ cells: { A1: 1, A2: 1, A3: 2 },
221
+ expectedValue: 1,
222
+ },
223
+ {
224
+ formula: '=UNIQUE(A1:A2)',
225
+ expectedValue: '#ERROR!',
226
+ expectedErrorCode: 'INVALID_FORMULA',
227
+ },
228
+ ],
229
+ },
230
+ VLOOKUP: {
231
+ name: 'VLOOKUP',
232
+ topic: 'lookup',
233
+ signature: 'VLOOKUP(search_key, range, index, [is_sorted])',
234
+ args: [
235
+ FILE_CONSTANTS.searchKeyArg,
236
+ {
237
+ key: 'range',
238
+ type: 'range',
239
+ description: 'Range whose first column holds the keys.',
240
+ descriptionI18nKey: 'sheet_formula.vlookup_arg_range',
241
+ },
242
+ {
243
+ key: 'index',
244
+ type: 'number',
245
+ description: '1-based column of the range to return.',
246
+ descriptionI18nKey: 'sheet_formula.vlookup_arg_index',
247
+ },
248
+ FILE_CONSTANTS.sortedArg,
249
+ ],
250
+ description: 'Finds a key in the first column of a range and returns the value from another column of the same row.',
251
+ descriptionI18nKey: 'sheet_formula.vlookup_description',
252
+ returns: { type: 'scalar', description: 'The value at the found row.' },
253
+ behavior: [FILE_CONSTANTS.exactMatchBehavior, FILE_CONSTANTS.approximateBehavior, FILE_CONSTANTS.blankResultBehavior],
254
+ errors: FILE_CONSTANTS.tableLookupErrors,
255
+ examples: [
256
+ {
257
+ formula: '=VLOOKUP("b", A1:B3, 2, FALSE)',
258
+ cells: { A1: 'a', A2: 'B', A3: 'c', B1: 1, B2: 2, B3: 3 },
259
+ expectedValue: 2,
260
+ },
261
+ {
262
+ formula: '=VLOOKUP(25, A1:B3, 2)',
263
+ cells: { A1: 0, A2: 20, A3: 50, B1: 'low', B2: 'mid', B3: 'high' },
264
+ expectedValue: 'mid',
265
+ },
266
+ {
267
+ formula: '=VLOOKUP("z", A1:B1, 2, FALSE)',
268
+ cells: { A1: 'a', B1: 1 },
269
+ expectedValue: '#N/A',
270
+ expectedErrorCode: 'NOT_FOUND',
271
+ },
272
+ ],
273
+ },
274
+ XLOOKUP: {
275
+ name: 'XLOOKUP',
276
+ topic: 'lookup',
277
+ signature: 'XLOOKUP(search_key, lookup_range, result_range, [if_not_found], [match_mode], [search_mode])',
278
+ args: [
279
+ FILE_CONSTANTS.searchKeyArg,
280
+ {
281
+ key: 'lookup_range',
282
+ type: 'range',
283
+ description: 'One-row or one-column range to search.',
284
+ descriptionI18nKey: 'sheet_formula.xlookup_arg_lookup_range',
285
+ },
286
+ {
287
+ key: 'result_range',
288
+ type: 'range',
289
+ description: 'Same-size range to return from.',
290
+ descriptionI18nKey: 'sheet_formula.xlookup_arg_result_range',
291
+ },
292
+ {
293
+ key: 'if_not_found',
294
+ type: 'expression',
295
+ description: 'Evaluated and returned only when nothing matches.',
296
+ descriptionI18nKey: 'sheet_formula.xlookup_arg_if_not_found',
297
+ optional: true,
298
+ },
299
+ {
300
+ key: 'match_mode',
301
+ type: 'number',
302
+ description: '0 exact (default), -1 or next smaller, 1 or next larger, 2 wildcard.',
303
+ descriptionI18nKey: 'sheet_formula.xlookup_arg_match_mode',
304
+ optional: true,
305
+ },
306
+ {
307
+ key: 'search_mode',
308
+ type: 'number',
309
+ description: '1 first to last (default), -1 last to first.',
310
+ descriptionI18nKey: 'sheet_formula.xlookup_arg_search_mode',
311
+ optional: true,
312
+ },
313
+ ],
314
+ description: 'Finds a key in one range and returns the value at the same position of another range.',
315
+ descriptionI18nKey: 'sheet_formula.xlookup_description',
316
+ returns: { type: 'scalar', description: 'The matching result value.' },
317
+ behavior: [
318
+ 'Exact matches ignore text case and treat 1 and "1" as equal; wildcards apply only with match_mode 2. Modes -1 and 1 need no sorting; ties go to the first position searched. Search modes 2 and -2 scan like 1 and -1.',
319
+ ],
320
+ errors: [
321
+ 'NOT_FOUND (#N/A) on a miss without if_not_found; INVALID_VALUE (#VALUE!) for ranges of different sizes, a two-dimensional range, or an unsupported mode.',
322
+ ],
323
+ examples: [
324
+ {
325
+ formula: '=XLOOKUP("b", A1:A3, B1:B3)',
326
+ cells: { A1: 'a', A2: 'B', A3: 'c', B1: 1, B2: 2, B3: 3 },
327
+ expectedValue: 2,
328
+ },
329
+ {
330
+ formula: '=XLOOKUP("z", A1:A2, B1:B2, "none")',
331
+ cells: { A1: 'a', A2: 'b', B1: 1, B2: 2 },
332
+ expectedValue: 'none',
333
+ },
334
+ {
335
+ formula: '=XLOOKUP(25, A1:A3, B1:B3, "none", -1)',
336
+ cells: { A1: 30, A2: 10, A3: 20, B1: 'c', B2: 'a', B3: 'b' },
337
+ expectedValue: 'b',
338
+ },
339
+ ],
340
+ },
341
+ };