@jsb188/mday 1.1.8 → 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.
- package/package.json +105 -35
- package/src/constants/agentDoc.ts +12 -0
- package/src/constants/agentMemory.ts +154 -0
- package/src/constants/aiChat.ts +5 -0
- package/src/constants/campaign.ts +127 -0
- package/src/constants/dataTable.ts +48 -0
- package/src/constants/dataTableFieldTypes.generated.ts +63 -0
- package/src/constants/docAccess.ts +32 -0
- package/src/constants/email.ts +44 -0
- package/src/constants/fieldDoc.ts +34 -0
- package/src/constants/graphqlReactivity.ts +113 -0
- package/src/constants/inboundContact.ts +8 -0
- package/src/constants/integration.ts +13 -0
- package/src/constants/log.ts +7 -366
- package/src/constants/logActivityGroupColors.generated.ts +19 -0
- package/src/constants/logTaxonomy.generated.ts +1103 -0
- package/src/constants/noteDoc.ts +77 -0
- package/src/constants/organization.ts +18 -11
- package/src/constants/pageRoute.ts +23 -0
- package/src/constants/schedule.ts +220 -0
- package/src/constants/scheduleRuleTemplateSeed.ts +138 -0
- package/src/constants/scheduleRuleTemplates.generated.ts +145 -0
- package/src/constants/sheet.ts +168 -0
- package/src/constants/sheetRegionSources.generated.ts +578 -0
- package/src/constants/square.ts +16 -0
- package/src/constants/storage.ts +61 -0
- package/src/constants/usage.ts +79 -0
- package/src/schemas/editLogEntry.ts +1017 -738
- package/src/schemas/fieldDocsQuery.ts +12 -0
- package/src/schemas/inboundContact.ts +77 -0
- package/src/schemas/logsQuery.ts +57 -316
- package/src/schemas/organization.ts +53 -213
- package/src/types/account.d.ts +81 -0
- package/src/types/agentDoc.d.ts +64 -0
- package/src/types/agentMemory.d.ts +74 -0
- package/src/types/campaign.d.ts +683 -0
- package/src/types/dataTable.d.ts +366 -0
- package/src/types/docAccess.d.ts +96 -0
- package/src/types/email.d.ts +142 -0
- package/src/types/fieldDoc.d.ts +273 -0
- package/src/types/inboundContact.d.ts +57 -0
- package/src/types/integration.d.ts +42 -0
- package/src/types/log.d.ts +169 -190
- package/src/types/noteDoc.d.ts +86 -0
- package/src/types/organization.d.ts +175 -76
- package/src/types/pageRoute.d.ts +48 -0
- package/src/types/schedule.d.ts +391 -0
- package/src/types/sheet.d.ts +1130 -0
- package/src/types/storage.d.ts +242 -0
- package/src/types/usage.d.ts +106 -0
- package/src/types/workflow.d.ts +305 -0
- package/src/utils/agentDoc.ts +109 -0
- package/src/utils/aiChat.ts +26 -0
- package/src/utils/campaign.ts +741 -0
- package/src/utils/campaignFormEditor.ts +871 -0
- package/src/utils/dataTable.ts +849 -0
- package/src/utils/dataTableFieldTypeRegistry.ts +105 -0
- package/src/utils/dataTableRealtimeAuthority.ts +209 -0
- package/src/utils/dataTableRealtimeSelection.ts +134 -0
- package/src/utils/dataTableRowDocument.ts +508 -0
- package/src/utils/dataTableSource.ts +230 -0
- package/src/utils/docAccess.ts +383 -0
- package/src/utils/documentName.ts +53 -0
- package/src/utils/email.ts +172 -0
- package/src/utils/fieldDoc.ts +113 -0
- package/src/utils/log.ts +173 -778
- package/src/utils/logRegistryValue.ts +90 -0
- package/src/utils/logStoreRead.ts +266 -0
- package/src/utils/logTaxonomy.ts +76 -0
- package/src/utils/logTaxonomyDisplay.ts +439 -0
- package/src/utils/noteDoc.ts +827 -0
- package/src/utils/organization.ts +683 -81
- package/src/utils/pageRoute.ts +71 -0
- package/src/utils/schedule.ts +799 -0
- package/src/utils/scheduleEvaluation.ts +1994 -0
- package/src/utils/scheduleICS.ts +246 -0
- package/src/utils/scheduleRuleTemplates.ts +188 -0
- package/src/utils/sheet.ts +4973 -0
- package/src/utils/sheetAxisMove.ts +830 -0
- package/src/utils/sheetBootstrap.ts +1769 -0
- package/src/utils/sheetCommand.ts +423 -0
- package/src/utils/sheetExport.ts +238 -0
- package/src/utils/sheetFormulaEvaluation.ts +914 -0
- package/src/utils/sheetFormulaEvaluator.ts +852 -0
- package/src/utils/sheetJournal.ts +78 -0
- package/src/utils/sheetNumberFormat.ts +1211 -0
- package/src/utils/sheetRegion.ts +374 -0
- package/src/utils/sheetRegionFilter.ts +1259 -0
- package/src/utils/sheetRegionSourceRegistry.ts +594 -0
- package/src/utils/sheetSequence.ts +148 -0
- package/src/utils/sheetSnapshot.ts +992 -0
- package/src/utils/sheetStructureEdit.ts +1284 -0
- package/src/utils/square.ts +32 -0
- package/src/utils/storage.ts +152 -0
- package/src/utils/table-route.ts +262 -0
- package/src/utils/workflow.ts +380 -0
- package/tests/dataTableFieldTypeRegistry.test.ts +110 -0
- package/tests/docAccess.test.ts +525 -0
- package/tests/editLogEntry.test.ts +112 -0
- package/tests/noteDoc.test.ts +669 -0
- package/tests/schedule.test.ts +693 -0
- package/tests/scheduleEvaluation.test.ts +1970 -0
- package/tests/scheduleICS.test.ts +208 -0
- package/tests/scheduleRuleTemplates.test.ts +176 -0
- package/tests/scheduleSweepInvariants.test.ts +428 -0
- package/tests/sheetAxisMove.test.ts +343 -0
- package/tests/sheetFormulaEvaluator.test.ts +575 -0
- package/tests/sheetRegionFilter.test.ts +1135 -0
- package/tests/sheetSequence.test.ts +41 -0
- package/tests/sheetStructureEdit.test.ts +82 -0
- package/tsconfig.json +12 -0
- package/vitest.config.ts +8 -0
- package/src/constants/log-activityTexts.ts +0 -209
- package/src/constants/product.ts +0 -66
- package/src/constants/report.ts +0 -25
- package/src/schemas/childOrganizationsQuery.ts +0 -44
- package/src/schemas/productsQuery.ts +0 -145
- package/src/schemas/reportsQuery.ts +0 -107
- package/src/types/action.d.ts +0 -42
- package/src/types/product.d.ts +0 -173
- package/src/types/report.d.ts +0 -203
- package/src/utils/product-calEvent.ts +0 -508
- package/src/utils/route-helpers.ts +0 -583
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import type { OrganizationOperationEnum } from '../types/organization.d.ts';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Pure reconstruction of a generic log `details` object from log-store rows.
|
|
5
|
+
* The output satisfies the shared LogEntryData contract: `id`/`logId` remain
|
|
6
|
+
* client-cache invariants, arrays remain arrays, and money values are decimal
|
|
7
|
+
* dollars (the store keeps BIGINT cents).
|
|
8
|
+
*
|
|
9
|
+
* Inverse of the server-side materializer (server logOps-store.ts): scalar
|
|
10
|
+
* item facts come back from the ordinal-0 ITEM row, values[] from remaining
|
|
11
|
+
* ITEM or historical MARKET_CREDIT rows, field-def-keyed scalars from
|
|
12
|
+
* log_values, and otherParty from an EXTERNAL counterparty.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export interface LogStoreValueInput {
|
|
16
|
+
fieldDefKey: string;
|
|
17
|
+
fieldType?: string | null;
|
|
18
|
+
textValue?: string | null;
|
|
19
|
+
numberValue?: number | null;
|
|
20
|
+
booleanValue?: boolean | null;
|
|
21
|
+
dateValue?: string | null;
|
|
22
|
+
datetimeValue?: string | Date | null;
|
|
23
|
+
unit?: string | null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface LogStoreItemInput {
|
|
27
|
+
kind: 'ITEM' | 'MARKET_CREDIT';
|
|
28
|
+
ordinal: number;
|
|
29
|
+
label: string;
|
|
30
|
+
quantity?: number | null;
|
|
31
|
+
unit?: string | null;
|
|
32
|
+
amountCents?: number | bigint | null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface LogStoreDetailsInput {
|
|
36
|
+
operation: OrganizationOperationEnum;
|
|
37
|
+
// GraphQL details.id and WS fragment dataIds derive from this identity.
|
|
38
|
+
detailsRowId: number | bigint | string;
|
|
39
|
+
logId: number | bigint | string;
|
|
40
|
+
activityKey: string;
|
|
41
|
+
logTypeKey?: string | null;
|
|
42
|
+
notes?: string | null;
|
|
43
|
+
translation?: string | null;
|
|
44
|
+
voided?: boolean | null;
|
|
45
|
+
referenceNumber?: string | null;
|
|
46
|
+
fieldLocation?: string | null;
|
|
47
|
+
counterparty?: { kind: string; name: string } | null;
|
|
48
|
+
values: LogStoreValueInput[];
|
|
49
|
+
items: LogStoreItemInput[];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/*
|
|
53
|
+
* Convert BIGINT cents back to decimal dollars
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
function centsToDollars(
|
|
57
|
+
cents: number | bigint | null | undefined,
|
|
58
|
+
): number | undefined {
|
|
59
|
+
if (cents === null || cents === undefined) {
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
return Number(cents) / 100;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/*
|
|
66
|
+
* Return one finite numeric value from an untrusted reconstructed store
|
|
67
|
+
* boundary so GraphQL floats and arithmetic never receive invalid numbers.
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
function toFiniteNumber(value: any): number | undefined {
|
|
71
|
+
if (value === null || value === undefined) {
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
const parsed = Number(value);
|
|
75
|
+
return Number.isFinite(parsed) ? parsed : undefined;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/*
|
|
79
|
+
* Return a GraphQL-safe ISO datetime value from a trusted log-store mirror.
|
|
80
|
+
*/
|
|
81
|
+
|
|
82
|
+
function getLogStoreDateTimeValue(
|
|
83
|
+
value: string | Date | null | undefined,
|
|
84
|
+
): string | undefined {
|
|
85
|
+
if (value instanceof Date) {
|
|
86
|
+
return Number.isFinite(value.getTime()) ? value.toISOString() : undefined;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return typeof value === 'string' && value ? value : undefined;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/*
|
|
93
|
+
* Build the metadata object from store rows; returns null when empty.
|
|
94
|
+
*/
|
|
95
|
+
|
|
96
|
+
function buildMetadataFromStore(
|
|
97
|
+
input: LogStoreDetailsInput,
|
|
98
|
+
): Record<string, any> | null {
|
|
99
|
+
const metadata: Record<string, any> = {};
|
|
100
|
+
|
|
101
|
+
const scalarItem = input.items.find(
|
|
102
|
+
(item) => item.kind === 'ITEM' && item.ordinal === 0,
|
|
103
|
+
);
|
|
104
|
+
if (scalarItem) {
|
|
105
|
+
if (scalarItem.label) {
|
|
106
|
+
metadata.item = scalarItem.label;
|
|
107
|
+
}
|
|
108
|
+
const quantity = toFiniteNumber(scalarItem.quantity);
|
|
109
|
+
if (quantity !== undefined) {
|
|
110
|
+
metadata.quantity = quantity;
|
|
111
|
+
}
|
|
112
|
+
if (scalarItem.unit != null) {
|
|
113
|
+
metadata.unit = scalarItem.unit;
|
|
114
|
+
}
|
|
115
|
+
const price = centsToDollars(scalarItem.amountCents);
|
|
116
|
+
if (price !== undefined) {
|
|
117
|
+
metadata.price = price;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const valueLines = input.items
|
|
122
|
+
.filter(
|
|
123
|
+
(item) =>
|
|
124
|
+
(item.kind === 'ITEM' && item.ordinal >= 1) ||
|
|
125
|
+
item.kind === 'MARKET_CREDIT',
|
|
126
|
+
)
|
|
127
|
+
.sort((a, b) => a.ordinal - b.ordinal)
|
|
128
|
+
.map((item) => {
|
|
129
|
+
const line: Record<string, any> = { label: item.label };
|
|
130
|
+
const amount = centsToDollars(item.amountCents);
|
|
131
|
+
if (amount !== undefined) {
|
|
132
|
+
line.value = amount;
|
|
133
|
+
}
|
|
134
|
+
const quantity = toFiniteNumber(item.quantity);
|
|
135
|
+
if (quantity !== undefined) {
|
|
136
|
+
line.quantity = quantity;
|
|
137
|
+
}
|
|
138
|
+
if (item.unit != null) {
|
|
139
|
+
line.unit = item.unit;
|
|
140
|
+
}
|
|
141
|
+
return line;
|
|
142
|
+
});
|
|
143
|
+
if (valueLines.length) {
|
|
144
|
+
metadata.values = valueLines;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
for (const value of input.values) {
|
|
148
|
+
if (value.fieldDefKey === 'concentration' && value.numberValue != null) {
|
|
149
|
+
metadata.concentration = toFiniteNumber(value.numberValue);
|
|
150
|
+
if (value.unit != null) {
|
|
151
|
+
metadata.concentrationUnit = value.unit;
|
|
152
|
+
}
|
|
153
|
+
} else if (value.fieldDefKey === 'tax' && value.numberValue != null) {
|
|
154
|
+
metadata.tax = (toFiniteNumber(value.numberValue) ?? 0) / 100;
|
|
155
|
+
} else if (value.fieldDefKey === 'flagColor' && value.textValue != null) {
|
|
156
|
+
metadata.flagColor = value.textValue;
|
|
157
|
+
} else if (value.fieldDefKey === 'quantity' && value.numberValue != null) {
|
|
158
|
+
// Label-less measurement (no scalar ITEM row); the item-row values
|
|
159
|
+
// win if both somehow exist
|
|
160
|
+
if (metadata.quantity === undefined) {
|
|
161
|
+
metadata.quantity = toFiniteNumber(value.numberValue);
|
|
162
|
+
if (value.unit != null && metadata.unit === undefined) {
|
|
163
|
+
metadata.unit = value.unit;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
} else if (value.fieldDefKey === 'unit' && value.textValue != null) {
|
|
167
|
+
// Unit-only annotation (no scalar ITEM row, no numeric quantity);
|
|
168
|
+
// an item-row or quantity-value unit wins if both somehow exist
|
|
169
|
+
if (metadata.unit === undefined) {
|
|
170
|
+
metadata.unit = value.textValue;
|
|
171
|
+
}
|
|
172
|
+
} else if (value.fieldDefKey === 'otherParty' && value.textValue != null) {
|
|
173
|
+
metadata.otherParty = value.textValue;
|
|
174
|
+
} else if (value.fieldDefKey === 'location' && value.textValue != null) {
|
|
175
|
+
metadata.location = value.textValue;
|
|
176
|
+
} else {
|
|
177
|
+
// Any field-def value maps straight onto metadata under its own key.
|
|
178
|
+
// MONEY values store BIGINT cents — read back as decimal dollars
|
|
179
|
+
const genericNumber =
|
|
180
|
+
value.fieldType === 'MONEY'
|
|
181
|
+
? centsToDollars(value.numberValue)
|
|
182
|
+
: toFiniteNumber(value.numberValue);
|
|
183
|
+
const genericValue =
|
|
184
|
+
value.textValue ??
|
|
185
|
+
genericNumber ??
|
|
186
|
+
value.booleanValue ??
|
|
187
|
+
value.dateValue ??
|
|
188
|
+
getLogStoreDateTimeValue(value.datetimeValue);
|
|
189
|
+
if (
|
|
190
|
+
genericValue !== undefined &&
|
|
191
|
+
genericValue !== null &&
|
|
192
|
+
metadata[value.fieldDefKey] === undefined
|
|
193
|
+
) {
|
|
194
|
+
metadata[value.fieldDefKey] = genericValue;
|
|
195
|
+
if (value.unit != null) {
|
|
196
|
+
metadata[`${value.fieldDefKey}Unit`] = value.unit;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Legacy fallback for rows materialized before the otherParty value
|
|
203
|
+
// existed: an EXTERNAL counterparty carries the (canonicalized) text
|
|
204
|
+
if (
|
|
205
|
+
metadata.otherParty === undefined &&
|
|
206
|
+
input.counterparty?.kind === 'EXTERNAL'
|
|
207
|
+
) {
|
|
208
|
+
metadata.otherParty = input.counterparty.name;
|
|
209
|
+
}
|
|
210
|
+
if (typeof input.voided === 'boolean') {
|
|
211
|
+
metadata.voided = input.voided;
|
|
212
|
+
}
|
|
213
|
+
if (input.referenceNumber != null) {
|
|
214
|
+
metadata.referenceNumber = input.referenceNumber;
|
|
215
|
+
}
|
|
216
|
+
if (input.fieldLocation != null) {
|
|
217
|
+
metadata.fieldLocation = input.fieldLocation;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return Object.keys(metadata).length ? metadata : null;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/*
|
|
224
|
+
* Normalize one store value into the client-facing generic-field contract.
|
|
225
|
+
*/
|
|
226
|
+
|
|
227
|
+
function mapStoreValueToLogEntryDetailsField(
|
|
228
|
+
value: LogStoreValueInput,
|
|
229
|
+
): Record<string, any> {
|
|
230
|
+
return {
|
|
231
|
+
key: value.fieldDefKey,
|
|
232
|
+
fieldType: value.fieldType ?? null,
|
|
233
|
+
textValue: value.textValue ?? null,
|
|
234
|
+
numberValue:
|
|
235
|
+
value.fieldType === 'MONEY'
|
|
236
|
+
? (centsToDollars(value.numberValue) ?? null)
|
|
237
|
+
: (toFiniteNumber(value.numberValue) ?? null),
|
|
238
|
+
booleanValue: value.booleanValue ?? null,
|
|
239
|
+
dateValue: value.dateValue ?? null,
|
|
240
|
+
datetimeValue: getLogStoreDateTimeValue(value.datetimeValue) ?? null,
|
|
241
|
+
unit: value.unit ?? null,
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/*
|
|
246
|
+
* Reconstruct the generic details object for one log from store rows.
|
|
247
|
+
*/
|
|
248
|
+
|
|
249
|
+
export function buildLogDetailsFromStore(
|
|
250
|
+
input: LogStoreDetailsInput,
|
|
251
|
+
): Record<string, any> | null {
|
|
252
|
+
const details: Record<string, any> = {
|
|
253
|
+
__table: 'log_entry_details',
|
|
254
|
+
fields: input.values.map(mapStoreValueToLogEntryDetailsField),
|
|
255
|
+
logType: input.logTypeKey ?? null,
|
|
256
|
+
id: input.detailsRowId,
|
|
257
|
+
logId: input.logId,
|
|
258
|
+
activity: input.activityKey,
|
|
259
|
+
// The store keeps NULL for an empty note; clients expect a string.
|
|
260
|
+
notes: input.notes ?? '',
|
|
261
|
+
translation: input.translation ?? null,
|
|
262
|
+
metadata: buildMetadataFromStore(input),
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
return details;
|
|
266
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import {
|
|
2
|
+
LOG_ACTIVITIES_BY_OPERATION,
|
|
3
|
+
LOG_TAXONOMY_BY_OPERATION,
|
|
4
|
+
} from '../constants/log.ts';
|
|
5
|
+
|
|
6
|
+
export interface LogTaxonomyGroup {
|
|
7
|
+
key: string;
|
|
8
|
+
label: string;
|
|
9
|
+
ordinal: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface LogTaxonomyActivity {
|
|
13
|
+
key: string;
|
|
14
|
+
groupKey: string;
|
|
15
|
+
ordinal: number;
|
|
16
|
+
agentText: string;
|
|
17
|
+
financeKind: 'NONE' | 'PURCHASE' | 'SALE';
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface LogTaxonomyOperation {
|
|
21
|
+
key: string;
|
|
22
|
+
groups: LogTaxonomyGroup[];
|
|
23
|
+
activities: LogTaxonomyActivity[];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/*
|
|
27
|
+
* Operations that carry at least one generated activity group.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
export function getLogTaxonomyOperationKeys() {
|
|
31
|
+
return Object.keys(LOG_ACTIVITIES_BY_OPERATION);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/*
|
|
35
|
+
* Derive one operation's canonical taxonomy (groups + activities with agent
|
|
36
|
+
* texts and finance kinds) from the constants. This is the single source both
|
|
37
|
+
* the registry seed generator and the registry<->constants contract checker
|
|
38
|
+
* build on; a change here must keep the generated seed byte-identical or the
|
|
39
|
+
* recorded migration checksum will drift.
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
export function deriveLogTaxonomyOperation(
|
|
43
|
+
operation: string,
|
|
44
|
+
): LogTaxonomyOperation {
|
|
45
|
+
const taxonomy =
|
|
46
|
+
LOG_TAXONOMY_BY_OPERATION[
|
|
47
|
+
operation as keyof typeof LOG_TAXONOMY_BY_OPERATION
|
|
48
|
+
];
|
|
49
|
+
if (!taxonomy) {
|
|
50
|
+
throw new Error(`Unknown log taxonomy operation: ${operation}`);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
key: operation,
|
|
55
|
+
groups: taxonomy.groups.map((group) => ({
|
|
56
|
+
key: group.key,
|
|
57
|
+
label: group.label,
|
|
58
|
+
ordinal: group.ordinal,
|
|
59
|
+
})),
|
|
60
|
+
activities: taxonomy.activities.map((activity) => ({
|
|
61
|
+
key: activity.key,
|
|
62
|
+
groupKey: activity.groupKey,
|
|
63
|
+
ordinal: activity.ordinal,
|
|
64
|
+
agentText: activity.agentText,
|
|
65
|
+
financeKind: activity.financeKind,
|
|
66
|
+
})),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/*
|
|
71
|
+
* Derive the full canonical taxonomy for every operation that has one
|
|
72
|
+
*/
|
|
73
|
+
|
|
74
|
+
export function deriveLogTaxonomyFromConstants(): LogTaxonomyOperation[] {
|
|
75
|
+
return getLogTaxonomyOperationKeys().map(deriveLogTaxonomyOperation);
|
|
76
|
+
}
|