@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.
- package/package.json +58 -23
- package/src/constants/agentMemory.ts +14 -45
- package/src/constants/agentNote.ts +212 -0
- package/src/constants/aiChat.ts +5 -0
- package/src/constants/billing.ts +126 -0
- package/src/constants/campaign.ts +156 -47
- package/src/constants/contact.ts +72 -0
- package/src/constants/csvExport.ts +133 -0
- package/src/constants/dataTable.ts +12 -38
- package/src/constants/dataTableFieldTypes.generated.ts +3 -7
- package/src/constants/docAccess.ts +3 -2
- package/src/constants/dt.ts +234 -0
- package/src/constants/email.ts +114 -12
- package/src/constants/fieldDoc.ts +74 -4
- package/src/constants/graphqlReactivity.ts +108 -25
- package/src/constants/log.ts +9 -0
- package/src/constants/logDisplay/README.md +88 -0
- package/src/constants/logDisplay/defaults.ts +39 -0
- package/src/constants/logDisplay/index.ts +27 -0
- package/src/constants/logDisplay/operations/arable.ts +16 -0
- package/src/constants/logDisplay/operations/farmersMarket.ts +10 -0
- package/src/constants/logDisplay/operations/foodManufacturing.ts +13 -0
- package/src/constants/logDisplay/shared/accounting.ts +13 -0
- package/src/constants/logDisplay/shared/interactions.ts +13 -0
- package/src/constants/logDisplay/shared/rackTemperatures.ts +42 -0
- package/src/constants/logTaxonomy.generated.ts +1834 -730
- package/src/constants/organization.ts +13 -14
- package/src/constants/qrCode.ts +30 -0
- package/src/constants/sheet.ts +65 -101
- package/src/constants/sms.ts +18 -0
- package/src/constants/storage.ts +33 -9
- package/src/constants/usage.ts +3 -0
- package/src/constants/workflowSteps.ts +60 -0
- package/src/schemas/editLogEntry.ts +106 -283
- package/src/schemas/inboundContact.ts +5 -5
- package/src/types/agentMemory.d.ts +38 -14
- package/src/types/agentNote.d.ts +443 -0
- package/src/types/billing.d.ts +537 -0
- package/src/types/campaign.d.ts +1043 -193
- package/src/types/contact.d.ts +15 -0
- package/src/types/csvExport.d.ts +213 -0
- package/src/types/dataAnalysis.d.ts +44 -0
- package/src/types/dataTable.d.ts +102 -309
- package/src/types/definitionElement.d.ts +35 -0
- package/src/types/dt.d.ts +257 -0
- package/src/types/email.d.ts +144 -55
- package/src/types/emailReplyReport.d.ts +76 -0
- package/src/types/fieldDoc.d.ts +579 -150
- package/src/types/fieldDocContract.d.ts +90 -0
- package/src/types/inboundContact.d.ts +8 -0
- package/src/types/log.d.ts +94 -3
- package/src/types/logDisplay.types.ts +85 -0
- package/src/types/organization.d.ts +8 -3
- package/src/types/qrCode.d.ts +96 -0
- package/src/types/richText.d.ts +81 -0
- package/src/types/sheet.d.ts +180 -463
- package/src/types/sms.d.ts +38 -0
- package/src/types/storage.d.ts +266 -27
- package/src/types/workflow.d.ts +196 -66
- package/src/utils/agentMemory.ts +15 -0
- package/src/utils/agentNote.ts +850 -0
- package/src/utils/aiChat.ts +31 -14
- package/src/utils/aiChatWork.ts +64 -0
- package/src/utils/billing.ts +37 -0
- package/src/utils/campaign.ts +642 -209
- package/src/utils/campaignAI.ts +72 -0
- package/src/utils/campaignAccess.ts +239 -0
- package/src/utils/campaignEmail.ts +601 -0
- package/src/utils/campaignEmailCompiler.ts +372 -0
- package/src/utils/campaignEmailImages.ts +60 -0
- package/src/utils/campaignEmailStyles.ts +544 -0
- package/src/utils/campaignLifecycle.ts +104 -0
- package/src/utils/campaignPreview.ts +285 -0
- package/src/utils/contact.ts +50 -0
- package/src/utils/csvExport.ts +19 -0
- package/src/utils/dataTable.ts +18 -556
- package/src/utils/dataTableFieldTypeRegistry.ts +1 -0
- package/src/utils/dataTableRelativeDate.ts +447 -0
- package/src/utils/definitionElement.ts +84 -0
- package/src/utils/email.ts +208 -1
- package/src/utils/emailReplyReport.test.ts +187 -0
- package/src/utils/emailReplyReport.ts +143 -0
- package/src/utils/fieldDoc.ts +81 -37
- package/src/utils/fieldDocAnswers.ts +128 -0
- package/src/utils/fieldDocDefaults.ts +36 -0
- package/src/utils/fieldDocProgram.ts +36 -0
- package/src/utils/fieldDocSummary.ts +30 -0
- package/src/utils/log.ts +232 -141
- package/src/utils/logDisplay.helpers.ts +177 -0
- package/src/utils/logDisplay.ts +87 -0
- package/src/utils/logStoreRead.ts +9 -13
- package/src/utils/logTaxonomy.helpers.ts +17 -0
- package/src/utils/logTaxonomyDisplay.ts +80 -124
- package/src/utils/noteDoc.ts +66 -284
- package/src/utils/organization.ts +117 -283
- package/src/utils/qrCode.helpers.ts +189 -0
- package/src/utils/qrCode.test.ts +519 -0
- package/src/utils/qrCode.ts +273 -0
- package/src/utils/richTextHTML.ts +385 -0
- package/src/utils/sheet.ts +123 -4834
- package/src/utils/sheetAxisMove.ts +77 -291
- package/src/utils/sheetBootstrap.ts +771 -1138
- package/src/utils/sheetCellLiteral.ts +101 -0
- package/src/utils/sheetCommand.ts +23 -88
- package/src/utils/sheetDesign.ts +705 -0
- package/src/utils/sheetExport.ts +17 -69
- package/src/utils/sheetFeatureReference.ts +183 -0
- package/src/utils/sheetFormulaArgs.ts +168 -0
- package/src/utils/sheetFormulaCompile.ts +475 -0
- package/src/utils/sheetFormulaConditionalAggregate.ts +254 -0
- package/src/utils/sheetFormulaCriteria.ts +656 -0
- package/src/utils/sheetFormulaDate.ts +444 -0
- package/src/utils/sheetFormulaEvaluation.ts +388 -403
- package/src/utils/sheetFormulaEvaluator.ts +589 -444
- package/src/utils/sheetFormulaFunctionHandlers.ts +403 -0
- package/src/utils/sheetFormulaLogical.ts +116 -0
- package/src/utils/sheetFormulaLookup.ts +488 -0
- package/src/utils/sheetFormulaMath.ts +48 -0
- package/src/utils/sheetFormulaParser.ts +729 -0
- package/src/utils/sheetFormulaRange.ts +330 -0
- package/src/utils/sheetFormulaReference.ts +703 -0
- package/src/utils/sheetFormulaReferenceAggregates.ts +313 -0
- package/src/utils/sheetFormulaReferenceDates.ts +237 -0
- package/src/utils/sheetFormulaReferenceLogical.ts +330 -0
- package/src/utils/sheetFormulaReferenceLookup.ts +341 -0
- package/src/utils/sheetFormulaReferenceMath.ts +95 -0
- package/src/utils/sheetFormulaReferenceRewrite.ts +220 -0
- package/src/utils/sheetFormulaReferenceText.ts +462 -0
- package/src/utils/sheetFormulaSyntax.ts +1027 -0
- package/src/utils/sheetFormulaText.ts +430 -0
- package/src/utils/sheetJournal.ts +140 -18
- package/src/utils/sheetNumberFormat.ts +68 -267
- package/src/utils/sheetPreview.ts +68 -0
- package/src/utils/sheetSequence.ts +13 -43
- package/src/utils/sheetSnapshot.ts +176 -429
- package/src/utils/sheetStructureEdit.ts +537 -907
- package/src/utils/sheetStructureReferences.ts +389 -0
- package/src/utils/storage.ts +49 -3
- package/src/utils/time.ts +12 -0
- package/src/utils/workflow.ts +199 -73
- package/src/utils/workflowLogFingerprint.ts +302 -0
- package/src/utils/workflowLogRevisionSnapshot.ts +424 -0
- package/src/utils/workflowProgress.ts +280 -0
- package/src/utils/workflowTriggers.ts +61 -0
- package/tests/agentNote.test.ts +395 -0
- package/tests/campaignAI.test.ts +119 -0
- package/tests/campaignAccess.test.ts +239 -0
- package/tests/campaignEmail.test.ts +441 -0
- package/tests/campaignLifecycle.test.ts +134 -0
- package/tests/campaignPublication.test.ts +309 -0
- package/tests/dataTableFieldTypeRegistry.test.ts +2 -1
- package/tests/dataTableRelativeDate.test.ts +412 -0
- package/tests/email.test.ts +39 -0
- package/tests/fieldDocProgram.test.ts +114 -0
- package/tests/logDisplay.fixtures.ts +67 -0
- package/tests/logDisplay.test.ts +227 -0
- package/tests/noteDoc.test.ts +37 -192
- package/tests/richTextHTML.test.ts +185 -0
- package/tests/sheetAxisMove.test.ts +49 -40
- package/tests/sheetBootstrap.test.ts +1967 -0
- package/tests/sheetFeatureReference.test.ts +22 -0
- package/tests/sheetFormulaCriteria.test.ts +269 -0
- package/tests/sheetFormulaEvaluator.test.ts +93 -200
- package/tests/sheetFormulaFunctions.test.ts +538 -0
- package/tests/sheetFormulaLanguage.test.ts +361 -0
- package/tests/sheetFormulaParity.fixtures.ts +872 -0
- package/tests/sheetFormulaParity.test.ts +188 -0
- package/tests/sheetFormulaRange.test.ts +167 -0
- package/tests/sheetFormulaReference.test.ts +78 -0
- package/tests/sheetFormulaReferenceRewrite.test.ts +117 -0
- package/tests/sheetFormulaTextDate.test.ts +512 -0
- package/tests/sheetSequence.test.ts +4 -23
- package/tests/sheetSnapshot.test.ts +134 -0
- package/tests/sheetStructureEdit.test.ts +492 -37
- package/tests/sheetStructureReferences.test.ts +589 -0
- package/tests/workflowLifecycleStatus.test.ts +60 -0
- package/tests/workflowLogFingerprint.test.ts +203 -0
- package/tests/workflowLogRevisionSnapshot.test.ts +96 -0
- package/tests/workflowProgress.test.ts +180 -0
- package/tests/workflowTriggers.test.ts +29 -0
- package/src/constants/agentDoc.ts +0 -12
- package/src/constants/logActivityGroupColors.generated.ts +0 -19
- package/src/constants/schedule.ts +0 -220
- package/src/constants/scheduleRuleTemplateSeed.ts +0 -138
- package/src/constants/scheduleRuleTemplates.generated.ts +0 -145
- package/src/constants/sheetRegionSources.generated.ts +0 -578
- package/src/schemas/fieldDocsQuery.ts +0 -12
- package/src/schemas/organization.ts +0 -68
- package/src/types/agentDoc.d.ts +0 -64
- package/src/types/noteDoc.d.ts +0 -86
- package/src/types/schedule.d.ts +0 -391
- package/src/utils/agentDoc.ts +0 -109
- package/src/utils/campaignFormEditor.ts +0 -871
- package/src/utils/dataTableRealtimeAuthority.ts +0 -209
- package/src/utils/dataTableRealtimeSelection.ts +0 -134
- package/src/utils/dataTableRowDocument.ts +0 -508
- package/src/utils/dataTableSource.ts +0 -230
- package/src/utils/schedule.ts +0 -799
- package/src/utils/scheduleEvaluation.ts +0 -1994
- package/src/utils/scheduleICS.ts +0 -246
- package/src/utils/scheduleRuleTemplates.ts +0 -188
- package/src/utils/sheetRegion.ts +0 -374
- package/src/utils/sheetRegionFilter.ts +0 -1259
- package/src/utils/sheetRegionSourceRegistry.ts +0 -594
- package/tests/schedule.test.ts +0 -693
- package/tests/scheduleEvaluation.test.ts +0 -1970
- package/tests/scheduleICS.test.ts +0 -208
- package/tests/scheduleRuleTemplates.test.ts +0 -176
- package/tests/scheduleSweepInvariants.test.ts +0 -428
- package/tests/sheetRegionFilter.test.ts +0 -1135
|
@@ -1,594 +0,0 @@
|
|
|
1
|
-
import type { DataTableFieldTypeEnum } from '../types/dataTable.d.ts';
|
|
2
|
-
import {
|
|
3
|
-
SHEET_CUSTOM_REGION_SOURCE_CHILD_ORGANIZATION_COLUMNS,
|
|
4
|
-
SHEET_CUSTOM_REGION_SOURCE_CHILD_ORGANIZATIONS,
|
|
5
|
-
SHEET_CUSTOM_REGION_SOURCE_LOG_COLUMNS,
|
|
6
|
-
SHEET_CUSTOM_REGION_SOURCE_LOGS,
|
|
7
|
-
} from '../constants/sheet.ts';
|
|
8
|
-
import { DATA_TABLE_FIELD_TYPE_ENUMS } from '../constants/dataTable.ts';
|
|
9
|
-
|
|
10
|
-
/* Reach descriptor: the CONSTRAINED vocabulary a registry row may use to bind
|
|
11
|
-
* one field to SQL. Rows never carry free-form SQL; the server compiler quotes
|
|
12
|
-
* every identifier and rejects anything outside this grammar (error 20077). */
|
|
13
|
-
export type SheetRegionSourceReach =
|
|
14
|
-
| {
|
|
15
|
-
kind: 'COLUMN';
|
|
16
|
-
column: string;
|
|
17
|
-
render: SheetRegionSourceReachRender;
|
|
18
|
-
}
|
|
19
|
-
| {
|
|
20
|
-
kind: 'JOINED_COLUMN';
|
|
21
|
-
join: string;
|
|
22
|
-
column: string;
|
|
23
|
-
render: SheetRegionSourceReachRender;
|
|
24
|
-
}
|
|
25
|
-
| {
|
|
26
|
-
kind: 'PERSON_NAME';
|
|
27
|
-
join: string;
|
|
28
|
-
firstNameColumn: string;
|
|
29
|
-
lastNameColumn: string;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
/* Render vocabulary compiled by code (adding a render kind is a code change):
|
|
33
|
-
* RAW → "a"."col"; TEXT_ID → "a"."col"::text; COALESCE_TEXT →
|
|
34
|
-
* COALESCE("a"."col", ''); DATE/DATETIME → reserved, compile like RAW. */
|
|
35
|
-
export type SheetRegionSourceReachRender =
|
|
36
|
-
| 'RAW'
|
|
37
|
-
| 'TEXT_ID'
|
|
38
|
-
| 'COALESCE_TEXT'
|
|
39
|
-
| 'DATE'
|
|
40
|
-
| 'DATETIME';
|
|
41
|
-
|
|
42
|
-
/* One queryable field of a region source kind (registry row facade). */
|
|
43
|
-
export type SheetRegionSourceFieldDescriptor = {
|
|
44
|
-
key: string;
|
|
45
|
-
labelKey: string;
|
|
46
|
-
fieldType: DataTableFieldTypeEnum | null;
|
|
47
|
-
formulaValueSource: string | null;
|
|
48
|
-
relatedTable: string | null;
|
|
49
|
-
width: number;
|
|
50
|
-
ordinal: number;
|
|
51
|
-
filterable: boolean;
|
|
52
|
-
sortable: boolean;
|
|
53
|
-
reach: SheetRegionSourceReach | null;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
/* One join of a region source kind. Compilation is always equality-only
|
|
57
|
-
* LEFT OUTER JOIN; fromJoinKey null anchors on the kind's baseTable. */
|
|
58
|
-
export type SheetRegionSourceJoinDescriptor = {
|
|
59
|
-
key: string;
|
|
60
|
-
table: string;
|
|
61
|
-
fromJoinKey: string | null;
|
|
62
|
-
fromColumn: string;
|
|
63
|
-
toColumn: string;
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
/* One region source kind: identity, fetch strategy, client metadata keys,
|
|
67
|
-
* joins, and fields. Everything here is registry DATA; handlers, semantics,
|
|
68
|
-
* and label resolution stay code. */
|
|
69
|
-
export type SheetRegionSourceKindDescriptor = {
|
|
70
|
-
key: string;
|
|
71
|
-
fetchStrategy: 'SQL' | 'DIRECTORY';
|
|
72
|
-
baseTable: string | null;
|
|
73
|
-
titleKey: string;
|
|
74
|
-
appRoute: string | null;
|
|
75
|
-
revisionSourceKey: string;
|
|
76
|
-
/* Staged-launch gate: a disabled kind is fully recognized by durable data
|
|
77
|
-
* paths (revision types, event validation, existing-region rendering) but
|
|
78
|
-
* refuses NEW region creation until the flip + regenerate + deploy. The
|
|
79
|
-
* contract checker freshness-normalizes this flag, so a live flip alone
|
|
80
|
-
* never fails the contract. */
|
|
81
|
-
enabled: boolean;
|
|
82
|
-
joins: SheetRegionSourceJoinDescriptor[];
|
|
83
|
-
fields: SheetRegionSourceFieldDescriptor[];
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
const FILE_CONSTANTS = {
|
|
87
|
-
identRegex: /^[A-Za-z_][A-Za-z0-9_]{0,62}$/,
|
|
88
|
-
renderKinds: ['RAW', 'TEXT_ID', 'COALESCE_TEXT', 'DATE', 'DATETIME'],
|
|
89
|
-
maxJoinsPerKind: 12,
|
|
90
|
-
maxFieldsPerKind: 40,
|
|
91
|
-
maxJoinChainDepth: 2,
|
|
92
|
-
|
|
93
|
-
/* Base-table columns that are immutable/PK id-like: they can never change
|
|
94
|
-
* on an existing row, so invalidation-map derivation emits NO entry for
|
|
95
|
-
* them (matches the deliberate absence of an `id` key in the historical
|
|
96
|
-
* hand-written realtime map). */
|
|
97
|
-
immutableBaseColumns: ['id'],
|
|
98
|
-
|
|
99
|
-
/* LOGS joins, mirroring the historical getLogRegionSourcePageJoinStatement
|
|
100
|
-
* order (site, counterparty, childOrg, inboundContact, fieldDoc,
|
|
101
|
-
* fieldDocSubmission, accountProfile). */
|
|
102
|
-
logsJoins: [
|
|
103
|
-
{
|
|
104
|
-
key: 'site',
|
|
105
|
-
table: 'organization_sites',
|
|
106
|
-
fromJoinKey: null,
|
|
107
|
-
fromColumn: 'siteId',
|
|
108
|
-
toColumn: 'id',
|
|
109
|
-
},
|
|
110
|
-
{
|
|
111
|
-
key: 'counterparty',
|
|
112
|
-
table: 'counterparties',
|
|
113
|
-
fromJoinKey: null,
|
|
114
|
-
fromColumn: 'counterpartyId',
|
|
115
|
-
toColumn: 'id',
|
|
116
|
-
},
|
|
117
|
-
{
|
|
118
|
-
key: 'childOrg',
|
|
119
|
-
table: 'organizations',
|
|
120
|
-
fromJoinKey: 'counterparty',
|
|
121
|
-
fromColumn: 'linkedOrgId',
|
|
122
|
-
toColumn: 'id',
|
|
123
|
-
},
|
|
124
|
-
{
|
|
125
|
-
key: 'inboundContact',
|
|
126
|
-
table: 'inbound_contacts',
|
|
127
|
-
fromJoinKey: 'counterparty',
|
|
128
|
-
fromColumn: 'inboundContactId',
|
|
129
|
-
toColumn: 'id',
|
|
130
|
-
},
|
|
131
|
-
{
|
|
132
|
-
key: 'fieldDoc',
|
|
133
|
-
table: 'field_docs',
|
|
134
|
-
fromJoinKey: null,
|
|
135
|
-
fromColumn: 'fieldDocId',
|
|
136
|
-
toColumn: 'id',
|
|
137
|
-
},
|
|
138
|
-
{
|
|
139
|
-
key: 'fieldDocSubmission',
|
|
140
|
-
table: 'field_doc_submissions',
|
|
141
|
-
fromJoinKey: null,
|
|
142
|
-
fromColumn: 'fieldDocSubmissionId',
|
|
143
|
-
toColumn: 'id',
|
|
144
|
-
},
|
|
145
|
-
{
|
|
146
|
-
key: 'accountProfile',
|
|
147
|
-
table: 'account_profiles',
|
|
148
|
-
fromJoinKey: null,
|
|
149
|
-
fromColumn: 'accountId',
|
|
150
|
-
toColumn: 'accountId',
|
|
151
|
-
},
|
|
152
|
-
] as SheetRegionSourceJoinDescriptor[],
|
|
153
|
-
|
|
154
|
-
/* LOGS reach per field key, mirroring the historical per-cellKey SQL
|
|
155
|
-
* expressions (getLogRegionSourceSQLExpression). */
|
|
156
|
-
logsReachByKey: {
|
|
157
|
-
id: { kind: 'COLUMN', column: 'id', render: 'TEXT_ID' },
|
|
158
|
-
summary: { kind: 'COLUMN', column: 'summary', render: 'COALESCE_TEXT' },
|
|
159
|
-
date: { kind: 'COLUMN', column: 'date', render: 'RAW' },
|
|
160
|
-
createdAt: { kind: 'COLUMN', column: 'createdAt', render: 'RAW' },
|
|
161
|
-
childOrgId: {
|
|
162
|
-
kind: 'JOINED_COLUMN',
|
|
163
|
-
join: 'counterparty',
|
|
164
|
-
column: 'linkedOrgId',
|
|
165
|
-
render: 'TEXT_ID',
|
|
166
|
-
},
|
|
167
|
-
childOrgName: {
|
|
168
|
-
kind: 'JOINED_COLUMN',
|
|
169
|
-
join: 'childOrg',
|
|
170
|
-
column: 'name',
|
|
171
|
-
render: 'COALESCE_TEXT',
|
|
172
|
-
},
|
|
173
|
-
siteId: { kind: 'COLUMN', column: 'siteId', render: 'TEXT_ID' },
|
|
174
|
-
siteName: {
|
|
175
|
-
kind: 'JOINED_COLUMN',
|
|
176
|
-
join: 'site',
|
|
177
|
-
column: 'name',
|
|
178
|
-
render: 'COALESCE_TEXT',
|
|
179
|
-
},
|
|
180
|
-
inboundContactId: {
|
|
181
|
-
kind: 'JOINED_COLUMN',
|
|
182
|
-
join: 'counterparty',
|
|
183
|
-
column: 'inboundContactId',
|
|
184
|
-
render: 'TEXT_ID',
|
|
185
|
-
},
|
|
186
|
-
inboundContactEmail: {
|
|
187
|
-
kind: 'JOINED_COLUMN',
|
|
188
|
-
join: 'inboundContact',
|
|
189
|
-
column: 'email',
|
|
190
|
-
render: 'COALESCE_TEXT',
|
|
191
|
-
},
|
|
192
|
-
inboundContactPhone: {
|
|
193
|
-
kind: 'JOINED_COLUMN',
|
|
194
|
-
join: 'inboundContact',
|
|
195
|
-
column: 'phone',
|
|
196
|
-
render: 'COALESCE_TEXT',
|
|
197
|
-
},
|
|
198
|
-
fieldDocId: { kind: 'COLUMN', column: 'fieldDocId', render: 'TEXT_ID' },
|
|
199
|
-
fieldDocName: {
|
|
200
|
-
kind: 'JOINED_COLUMN',
|
|
201
|
-
join: 'fieldDoc',
|
|
202
|
-
column: 'title',
|
|
203
|
-
render: 'COALESCE_TEXT',
|
|
204
|
-
},
|
|
205
|
-
fieldDocSubmissionId: {
|
|
206
|
-
kind: 'COLUMN',
|
|
207
|
-
column: 'fieldDocSubmissionId',
|
|
208
|
-
render: 'TEXT_ID',
|
|
209
|
-
},
|
|
210
|
-
fieldDocSubmissionPeriod: {
|
|
211
|
-
kind: 'JOINED_COLUMN',
|
|
212
|
-
join: 'fieldDocSubmission',
|
|
213
|
-
column: 'period',
|
|
214
|
-
render: 'RAW',
|
|
215
|
-
},
|
|
216
|
-
accountId: { kind: 'COLUMN', column: 'accountId', render: 'TEXT_ID' },
|
|
217
|
-
accountPersonName: {
|
|
218
|
-
kind: 'PERSON_NAME',
|
|
219
|
-
join: 'accountProfile',
|
|
220
|
-
firstNameColumn: 'firstName',
|
|
221
|
-
lastNameColumn: 'lastName',
|
|
222
|
-
},
|
|
223
|
-
} as Record<string, SheetRegionSourceReach>,
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
/* Loose column shape shared by the two hand-maintained constants arrays. */
|
|
227
|
-
type SheetRegionSourceConstantColumn = {
|
|
228
|
-
key: string;
|
|
229
|
-
labelKey: string;
|
|
230
|
-
fieldType?: DataTableFieldTypeEnum | null;
|
|
231
|
-
formulaValueSource?: string | null;
|
|
232
|
-
relatedTable?: string | null;
|
|
233
|
-
width: number;
|
|
234
|
-
};
|
|
235
|
-
|
|
236
|
-
/*
|
|
237
|
-
* Map one constants column entry onto a registry field descriptor.
|
|
238
|
-
*/
|
|
239
|
-
function buildSheetRegionSourceFieldDescriptor(
|
|
240
|
-
column: SheetRegionSourceConstantColumn,
|
|
241
|
-
ordinal: number,
|
|
242
|
-
options: {
|
|
243
|
-
filterable: boolean;
|
|
244
|
-
sortable: boolean;
|
|
245
|
-
reach: SheetRegionSourceReach | null;
|
|
246
|
-
},
|
|
247
|
-
): SheetRegionSourceFieldDescriptor {
|
|
248
|
-
return {
|
|
249
|
-
key: column.key,
|
|
250
|
-
labelKey: column.labelKey,
|
|
251
|
-
fieldType: column.fieldType || null,
|
|
252
|
-
formulaValueSource: column.formulaValueSource || null,
|
|
253
|
-
relatedTable: column.relatedTable || null,
|
|
254
|
-
width: column.width,
|
|
255
|
-
ordinal,
|
|
256
|
-
filterable: options.filterable,
|
|
257
|
-
sortable: options.sortable,
|
|
258
|
-
reach: options.reach,
|
|
259
|
-
};
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
/*
|
|
263
|
-
* Derive the registry kind descriptors from the current hand-maintained
|
|
264
|
-
* constants plus the code-side reach/join tables above. This is the seed
|
|
265
|
-
* source of truth until the registry flips; the contract checker compares it
|
|
266
|
-
* against the live database rows and the committed generated modules.
|
|
267
|
-
*/
|
|
268
|
-
export function buildSheetRegionSourceDescriptorsFromConstants(): SheetRegionSourceKindDescriptor[] {
|
|
269
|
-
return [
|
|
270
|
-
{
|
|
271
|
-
key: SHEET_CUSTOM_REGION_SOURCE_CHILD_ORGANIZATIONS,
|
|
272
|
-
fetchStrategy: 'DIRECTORY',
|
|
273
|
-
baseTable: null,
|
|
274
|
-
titleKey: 'form.vendors',
|
|
275
|
-
appRoute: '/app/vendors',
|
|
276
|
-
revisionSourceKey: SHEET_CUSTOM_REGION_SOURCE_CHILD_ORGANIZATIONS,
|
|
277
|
-
// Both legacy kinds are live in production, so they derive enabled
|
|
278
|
-
enabled: true,
|
|
279
|
-
joins: [],
|
|
280
|
-
// DIRECTORY hydration ignores region filter/sort today; the seeded
|
|
281
|
-
// flags preserve that asymmetry (normalization forces null filter/sort)
|
|
282
|
-
fields: SHEET_CUSTOM_REGION_SOURCE_CHILD_ORGANIZATION_COLUMNS.map(
|
|
283
|
-
(column, index) =>
|
|
284
|
-
buildSheetRegionSourceFieldDescriptor(
|
|
285
|
-
column as SheetRegionSourceConstantColumn,
|
|
286
|
-
index,
|
|
287
|
-
{
|
|
288
|
-
filterable: false,
|
|
289
|
-
sortable: false,
|
|
290
|
-
reach: null,
|
|
291
|
-
},
|
|
292
|
-
),
|
|
293
|
-
),
|
|
294
|
-
},
|
|
295
|
-
{
|
|
296
|
-
key: SHEET_CUSTOM_REGION_SOURCE_LOGS,
|
|
297
|
-
fetchStrategy: 'SQL',
|
|
298
|
-
baseTable: 'logs',
|
|
299
|
-
titleKey: 'log.logs',
|
|
300
|
-
appRoute: '/app/logs',
|
|
301
|
-
revisionSourceKey: SHEET_CUSTOM_REGION_SOURCE_LOGS,
|
|
302
|
-
enabled: true,
|
|
303
|
-
joins: FILE_CONSTANTS.logsJoins.map((join) => ({ ...join })),
|
|
304
|
-
fields: SHEET_CUSTOM_REGION_SOURCE_LOG_COLUMNS.map((column, index) =>
|
|
305
|
-
buildSheetRegionSourceFieldDescriptor(
|
|
306
|
-
column as SheetRegionSourceConstantColumn,
|
|
307
|
-
index,
|
|
308
|
-
{
|
|
309
|
-
filterable: true,
|
|
310
|
-
sortable: true,
|
|
311
|
-
reach: FILE_CONSTANTS.logsReachByKey[column.key] || null,
|
|
312
|
-
},
|
|
313
|
-
),
|
|
314
|
-
),
|
|
315
|
-
},
|
|
316
|
-
];
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
/*
|
|
320
|
-
* Return whether one value is a valid quoted-identifier candidate.
|
|
321
|
-
*/
|
|
322
|
-
function isSheetRegionSourceIdent(value: unknown): value is string {
|
|
323
|
-
return typeof value === 'string' && FILE_CONSTANTS.identRegex.test(value);
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
/*
|
|
327
|
-
* Collect grammar issues for one field's reach descriptor.
|
|
328
|
-
*/
|
|
329
|
-
function collectSheetRegionSourceReachIssues(
|
|
330
|
-
kind: SheetRegionSourceKindDescriptor,
|
|
331
|
-
fieldKey: string,
|
|
332
|
-
reach: SheetRegionSourceReach,
|
|
333
|
-
): string[] {
|
|
334
|
-
const issues: string[] = [];
|
|
335
|
-
const joinKeys = new Set(kind.joins.map((join) => join.key));
|
|
336
|
-
const label = `${kind.key}.${fieldKey}`;
|
|
337
|
-
|
|
338
|
-
if (reach.kind === 'COLUMN') {
|
|
339
|
-
if (!isSheetRegionSourceIdent(reach.column)) {
|
|
340
|
-
issues.push(`${label}: COLUMN reach has an invalid column identifier`);
|
|
341
|
-
}
|
|
342
|
-
if (!FILE_CONSTANTS.renderKinds.includes(reach.render)) {
|
|
343
|
-
issues.push(`${label}: COLUMN reach has an unknown render kind`);
|
|
344
|
-
}
|
|
345
|
-
} else if (reach.kind === 'JOINED_COLUMN') {
|
|
346
|
-
if (!joinKeys.has(reach.join)) {
|
|
347
|
-
issues.push(
|
|
348
|
-
`${label}: JOINED_COLUMN reach references unknown join ${reach.join}`,
|
|
349
|
-
);
|
|
350
|
-
}
|
|
351
|
-
if (!isSheetRegionSourceIdent(reach.column)) {
|
|
352
|
-
issues.push(
|
|
353
|
-
`${label}: JOINED_COLUMN reach has an invalid column identifier`,
|
|
354
|
-
);
|
|
355
|
-
}
|
|
356
|
-
if (!FILE_CONSTANTS.renderKinds.includes(reach.render)) {
|
|
357
|
-
issues.push(`${label}: JOINED_COLUMN reach has an unknown render kind`);
|
|
358
|
-
}
|
|
359
|
-
} else if (reach.kind === 'PERSON_NAME') {
|
|
360
|
-
if (!joinKeys.has(reach.join)) {
|
|
361
|
-
issues.push(
|
|
362
|
-
`${label}: PERSON_NAME reach references unknown join ${reach.join}`,
|
|
363
|
-
);
|
|
364
|
-
}
|
|
365
|
-
if (
|
|
366
|
-
!isSheetRegionSourceIdent(reach.firstNameColumn) ||
|
|
367
|
-
!isSheetRegionSourceIdent(reach.lastNameColumn)
|
|
368
|
-
) {
|
|
369
|
-
issues.push(
|
|
370
|
-
`${label}: PERSON_NAME reach has an invalid name column identifier`,
|
|
371
|
-
);
|
|
372
|
-
}
|
|
373
|
-
} else {
|
|
374
|
-
issues.push(`${label}: unknown reach kind`);
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
return issues;
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
/*
|
|
381
|
-
* Collect join-graph issues (identifiers, chain anchoring, chain depth) for
|
|
382
|
-
* one kind descriptor.
|
|
383
|
-
*/
|
|
384
|
-
function collectSheetRegionSourceJoinIssues(
|
|
385
|
-
kind: SheetRegionSourceKindDescriptor,
|
|
386
|
-
): string[] {
|
|
387
|
-
const issues: string[] = [];
|
|
388
|
-
const joinKeys = new Set<string>();
|
|
389
|
-
|
|
390
|
-
if (kind.joins.length > FILE_CONSTANTS.maxJoinsPerKind) {
|
|
391
|
-
issues.push(
|
|
392
|
-
`${kind.key}: exceeds the ${FILE_CONSTANTS.maxJoinsPerKind}-join budget`,
|
|
393
|
-
);
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
kind.joins.forEach((join) => {
|
|
397
|
-
if (joinKeys.has(join.key)) {
|
|
398
|
-
issues.push(`${kind.key}: duplicate join key ${join.key}`);
|
|
399
|
-
}
|
|
400
|
-
joinKeys.add(join.key);
|
|
401
|
-
|
|
402
|
-
if (
|
|
403
|
-
!isSheetRegionSourceIdent(join.key) ||
|
|
404
|
-
!isSheetRegionSourceIdent(join.table)
|
|
405
|
-
) {
|
|
406
|
-
issues.push(`${kind.key}.${join.key}: invalid join/table identifier`);
|
|
407
|
-
}
|
|
408
|
-
if (
|
|
409
|
-
!isSheetRegionSourceIdent(join.fromColumn) ||
|
|
410
|
-
!isSheetRegionSourceIdent(join.toColumn)
|
|
411
|
-
) {
|
|
412
|
-
issues.push(`${kind.key}.${join.key}: invalid join column identifier`);
|
|
413
|
-
}
|
|
414
|
-
});
|
|
415
|
-
|
|
416
|
-
kind.joins.forEach((join) => {
|
|
417
|
-
let depth = 1;
|
|
418
|
-
let current: SheetRegionSourceJoinDescriptor | undefined = join;
|
|
419
|
-
const visited = new Set<string>([join.key]);
|
|
420
|
-
while (current?.fromJoinKey) {
|
|
421
|
-
const parent = kind.joins.find(
|
|
422
|
-
(candidate) => candidate.key === current?.fromJoinKey,
|
|
423
|
-
);
|
|
424
|
-
if (!parent) {
|
|
425
|
-
issues.push(
|
|
426
|
-
`${kind.key}.${join.key}: chains off unknown join ${current.fromJoinKey}`,
|
|
427
|
-
);
|
|
428
|
-
break;
|
|
429
|
-
}
|
|
430
|
-
if (visited.has(parent.key)) {
|
|
431
|
-
issues.push(`${kind.key}.${join.key}: join chain cycle`);
|
|
432
|
-
break;
|
|
433
|
-
}
|
|
434
|
-
visited.add(parent.key);
|
|
435
|
-
depth += 1;
|
|
436
|
-
current = parent;
|
|
437
|
-
}
|
|
438
|
-
if (depth > FILE_CONSTANTS.maxJoinChainDepth) {
|
|
439
|
-
issues.push(
|
|
440
|
-
`${kind.key}.${join.key}: join chain deeper than ${FILE_CONSTANTS.maxJoinChainDepth}`,
|
|
441
|
-
);
|
|
442
|
-
}
|
|
443
|
-
});
|
|
444
|
-
|
|
445
|
-
return issues;
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
/*
|
|
449
|
-
* Validate one descriptor set: grammar, identifier regex, join budgets,
|
|
450
|
-
* strategy/reach coherence, unique keys, and fieldType vocabulary. Returns
|
|
451
|
-
* human-readable issues; an empty array means the set is valid.
|
|
452
|
-
*/
|
|
453
|
-
export function collectSheetRegionSourceDescriptorIssues(
|
|
454
|
-
kinds: SheetRegionSourceKindDescriptor[],
|
|
455
|
-
): string[] {
|
|
456
|
-
const issues: string[] = [];
|
|
457
|
-
const kindKeys = new Set<string>();
|
|
458
|
-
|
|
459
|
-
kinds.forEach((kind) => {
|
|
460
|
-
if (kindKeys.has(kind.key)) {
|
|
461
|
-
issues.push(`duplicate kind key ${kind.key}`);
|
|
462
|
-
}
|
|
463
|
-
kindKeys.add(kind.key);
|
|
464
|
-
|
|
465
|
-
if (!isSheetRegionSourceIdent(kind.key)) {
|
|
466
|
-
issues.push(`${kind.key}: invalid kind key identifier`);
|
|
467
|
-
}
|
|
468
|
-
if (kind.fetchStrategy !== 'SQL' && kind.fetchStrategy !== 'DIRECTORY') {
|
|
469
|
-
issues.push(`${kind.key}: unknown fetchStrategy`);
|
|
470
|
-
}
|
|
471
|
-
if ((kind.fetchStrategy === 'SQL') !== Boolean(kind.baseTable)) {
|
|
472
|
-
issues.push(
|
|
473
|
-
`${kind.key}: baseTable is required exactly for SQL-strategy kinds`,
|
|
474
|
-
);
|
|
475
|
-
}
|
|
476
|
-
if (kind.baseTable && !isSheetRegionSourceIdent(kind.baseTable)) {
|
|
477
|
-
issues.push(`${kind.key}: invalid baseTable identifier`);
|
|
478
|
-
}
|
|
479
|
-
if (!kind.titleKey) {
|
|
480
|
-
issues.push(`${kind.key}: missing titleKey`);
|
|
481
|
-
}
|
|
482
|
-
if (!kind.revisionSourceKey) {
|
|
483
|
-
issues.push(`${kind.key}: missing revisionSourceKey`);
|
|
484
|
-
}
|
|
485
|
-
if (kind.fields.length > FILE_CONSTANTS.maxFieldsPerKind) {
|
|
486
|
-
issues.push(
|
|
487
|
-
`${kind.key}: exceeds the ${FILE_CONSTANTS.maxFieldsPerKind}-field budget`,
|
|
488
|
-
);
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
issues.push(...collectSheetRegionSourceJoinIssues(kind));
|
|
492
|
-
|
|
493
|
-
const fieldKeys = new Set<string>();
|
|
494
|
-
kind.fields.forEach((field) => {
|
|
495
|
-
if (fieldKeys.has(field.key)) {
|
|
496
|
-
issues.push(`${kind.key}: duplicate field key ${field.key}`);
|
|
497
|
-
}
|
|
498
|
-
fieldKeys.add(field.key);
|
|
499
|
-
|
|
500
|
-
if (!isSheetRegionSourceIdent(field.key)) {
|
|
501
|
-
issues.push(`${kind.key}.${field.key}: invalid field key identifier`);
|
|
502
|
-
}
|
|
503
|
-
if (!field.labelKey) {
|
|
504
|
-
issues.push(`${kind.key}.${field.key}: missing labelKey`);
|
|
505
|
-
}
|
|
506
|
-
if (
|
|
507
|
-
field.fieldType !== null &&
|
|
508
|
-
!DATA_TABLE_FIELD_TYPE_ENUMS.includes(field.fieldType)
|
|
509
|
-
) {
|
|
510
|
-
issues.push(
|
|
511
|
-
`${kind.key}.${field.key}: unknown fieldType ${field.fieldType}`,
|
|
512
|
-
);
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
// Reach descriptors bind fields to EXISTING fieldType semantics; they
|
|
516
|
-
// are required exactly for SQL-strategy kinds (DIRECTORY fields are
|
|
517
|
-
// client metadata hydrated by a code-registered strategy)
|
|
518
|
-
if (kind.fetchStrategy === 'SQL' && !field.reach) {
|
|
519
|
-
issues.push(
|
|
520
|
-
`${kind.key}.${field.key}: SQL-strategy field is missing its reach descriptor`,
|
|
521
|
-
);
|
|
522
|
-
}
|
|
523
|
-
if (kind.fetchStrategy === 'DIRECTORY' && field.reach) {
|
|
524
|
-
issues.push(
|
|
525
|
-
`${kind.key}.${field.key}: DIRECTORY-strategy field must not carry a reach descriptor`,
|
|
526
|
-
);
|
|
527
|
-
}
|
|
528
|
-
if (field.reach) {
|
|
529
|
-
issues.push(
|
|
530
|
-
...collectSheetRegionSourceReachIssues(kind, field.key, field.reach),
|
|
531
|
-
);
|
|
532
|
-
}
|
|
533
|
-
});
|
|
534
|
-
});
|
|
535
|
-
|
|
536
|
-
return issues;
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
/*
|
|
540
|
-
* Return the base-table column one field's reach anchors on: its own column
|
|
541
|
-
* for COLUMN reach, otherwise the join-chain root's fromColumn.
|
|
542
|
-
*/
|
|
543
|
-
export function getSheetRegionSourceReachBaseColumn(
|
|
544
|
-
kind: SheetRegionSourceKindDescriptor,
|
|
545
|
-
reach: SheetRegionSourceReach,
|
|
546
|
-
): string | null {
|
|
547
|
-
if (reach.kind === 'COLUMN') {
|
|
548
|
-
return reach.column;
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
let joinKey: string | null = reach.join;
|
|
552
|
-
let rootJoin: SheetRegionSourceJoinDescriptor | undefined;
|
|
553
|
-
const visited = new Set<string>();
|
|
554
|
-
while (joinKey && !visited.has(joinKey)) {
|
|
555
|
-
visited.add(joinKey);
|
|
556
|
-
rootJoin = kind.joins.find((join) => join.key === joinKey);
|
|
557
|
-
joinKey = rootJoin?.fromJoinKey || null;
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
return rootJoin?.fromColumn || null;
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
/*
|
|
564
|
-
* Derive the base-table column → derived cellKeys realtime invalidation map
|
|
565
|
-
* for one kind (replaces the historical hand-written map). Immutable/PK
|
|
566
|
-
* id-like base columns emit NO entry: they can never change on an existing
|
|
567
|
-
* row, so no write to them can invalidate a rendered cell.
|
|
568
|
-
*/
|
|
569
|
-
export function getSheetRegionSourceCellKeysByBaseColumn(
|
|
570
|
-
kind: SheetRegionSourceKindDescriptor,
|
|
571
|
-
): Record<string, string[]> {
|
|
572
|
-
const cellKeysByBaseColumn: Record<string, string[]> = {};
|
|
573
|
-
|
|
574
|
-
kind.fields.forEach((field) => {
|
|
575
|
-
if (!field.reach) {
|
|
576
|
-
return;
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
const baseColumn = getSheetRegionSourceReachBaseColumn(kind, field.reach);
|
|
580
|
-
if (
|
|
581
|
-
!baseColumn ||
|
|
582
|
-
FILE_CONSTANTS.immutableBaseColumns.includes(baseColumn)
|
|
583
|
-
) {
|
|
584
|
-
return;
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
cellKeysByBaseColumn[baseColumn] = [
|
|
588
|
-
...(cellKeysByBaseColumn[baseColumn] || []),
|
|
589
|
-
field.key,
|
|
590
|
-
];
|
|
591
|
-
});
|
|
592
|
-
|
|
593
|
-
return cellKeysByBaseColumn;
|
|
594
|
-
}
|