@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,105 @@
|
|
|
1
|
+
import { DATA_TABLE_FIELD_TYPE_ENUMS } from '../constants/dataTable.ts';
|
|
2
|
+
|
|
3
|
+
/* Closed, code-owned semantics vocabulary a data_table_field_types row may
|
|
4
|
+
* bind to. Each key names a behavior family implemented by code
|
|
5
|
+
* (utils/dataTable.ts helpers + the storage/filter compilers); adding a
|
|
6
|
+
* semantics key is a code change, adding a column TYPE is a registry row. */
|
|
7
|
+
export const DATA_TABLE_FIELD_TYPE_SEMANTICS_KEY_ENUMS = [
|
|
8
|
+
'TEXT',
|
|
9
|
+
'ID',
|
|
10
|
+
'ID_OR_TEXT',
|
|
11
|
+
'NUMBER',
|
|
12
|
+
'BOOLEAN',
|
|
13
|
+
'DATE',
|
|
14
|
+
'WEEK',
|
|
15
|
+
'DATETIME',
|
|
16
|
+
'SELECT',
|
|
17
|
+
'SELECT_OR_TEXT',
|
|
18
|
+
'MULTI_SELECT',
|
|
19
|
+
'JSON',
|
|
20
|
+
] as const;
|
|
21
|
+
|
|
22
|
+
export type DataTableFieldTypeSemanticsKey =
|
|
23
|
+
(typeof DATA_TABLE_FIELD_TYPE_SEMANTICS_KEY_ENUMS)[number];
|
|
24
|
+
|
|
25
|
+
/* One dataTable column-type registry row facade: identity + the code-owned
|
|
26
|
+
* semantics family it binds to. Everything else about a type IS its semantics
|
|
27
|
+
* and stays code. */
|
|
28
|
+
export type DataTableFieldTypeDescriptor = {
|
|
29
|
+
key: string;
|
|
30
|
+
semanticsKey: DataTableFieldTypeSemanticsKey;
|
|
31
|
+
ordinal: number;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const FILE_CONSTANTS = {
|
|
35
|
+
keyRegex: /^[A-Z][A-Z0-9_]{0,19}$/,
|
|
36
|
+
|
|
37
|
+
/* Type keys whose semantics family differs from their own key; every other
|
|
38
|
+
* type key maps onto the identically-named semantics key. This mapping is
|
|
39
|
+
* the seed source of truth until the registry flips. */
|
|
40
|
+
semanticsOverridesByKey: {
|
|
41
|
+
PRICE: 'NUMBER',
|
|
42
|
+
WEEK_OF_MON: 'WEEK',
|
|
43
|
+
WEEK_OF_SUN: 'WEEK',
|
|
44
|
+
} as Record<string, DataTableFieldTypeSemanticsKey>,
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/*
|
|
48
|
+
* Derive the registry field-type descriptors from the current hand-maintained
|
|
49
|
+
* enum + the code-side semantics overrides above. This is the seed source of
|
|
50
|
+
* truth until the registry flips; the contract checker compares it against
|
|
51
|
+
* the live database rows and the committed generated module.
|
|
52
|
+
*/
|
|
53
|
+
export function buildDataTableFieldTypeDescriptorsFromConstants(): DataTableFieldTypeDescriptor[] {
|
|
54
|
+
return DATA_TABLE_FIELD_TYPE_ENUMS.map((key, index) => ({
|
|
55
|
+
key,
|
|
56
|
+
semanticsKey:
|
|
57
|
+
FILE_CONSTANTS.semanticsOverridesByKey[key] ||
|
|
58
|
+
(key as DataTableFieldTypeSemanticsKey),
|
|
59
|
+
ordinal: index,
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/*
|
|
64
|
+
* Validate one descriptor set: key shape, unique keys/ordinals, and semantics
|
|
65
|
+
* vocabulary membership. Returns human-readable issues; an empty array means
|
|
66
|
+
* the set is valid.
|
|
67
|
+
*/
|
|
68
|
+
export function collectDataTableFieldTypeDescriptorIssues(
|
|
69
|
+
descriptors: DataTableFieldTypeDescriptor[],
|
|
70
|
+
): string[] {
|
|
71
|
+
const issues: string[] = [];
|
|
72
|
+
const keys = new Set<string>();
|
|
73
|
+
const ordinals = new Set<number>();
|
|
74
|
+
|
|
75
|
+
if (!descriptors.length) {
|
|
76
|
+
issues.push('registry has no field type rows');
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
descriptors.forEach((descriptor) => {
|
|
80
|
+
if (keys.has(descriptor.key)) {
|
|
81
|
+
issues.push(`duplicate field type key ${descriptor.key}`);
|
|
82
|
+
}
|
|
83
|
+
keys.add(descriptor.key);
|
|
84
|
+
|
|
85
|
+
if (ordinals.has(descriptor.ordinal)) {
|
|
86
|
+
issues.push(`${descriptor.key}: duplicate ordinal ${descriptor.ordinal}`);
|
|
87
|
+
}
|
|
88
|
+
ordinals.add(descriptor.ordinal);
|
|
89
|
+
|
|
90
|
+
if (!FILE_CONSTANTS.keyRegex.test(descriptor.key)) {
|
|
91
|
+
issues.push(`${descriptor.key}: invalid field type key`);
|
|
92
|
+
}
|
|
93
|
+
if (
|
|
94
|
+
!DATA_TABLE_FIELD_TYPE_SEMANTICS_KEY_ENUMS.includes(
|
|
95
|
+
descriptor.semanticsKey,
|
|
96
|
+
)
|
|
97
|
+
) {
|
|
98
|
+
issues.push(
|
|
99
|
+
`${descriptor.key}: unknown semanticsKey ${descriptor.semanticsKey}`,
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
return issues;
|
|
105
|
+
}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import type { DataTableWriteOrderWS } from '@jsb188/app/types/app.d.ts';
|
|
2
|
+
import { DATA_TABLE_REALTIME_MAX_LOGICAL_OPERATIONS } from '../constants/dataTable.ts';
|
|
3
|
+
|
|
4
|
+
const FILE_CONSTANTS = {
|
|
5
|
+
canonicalPositiveIntegerPattern: /^[1-9]\d{0,18}$/,
|
|
6
|
+
maxCellKeyLength: 80,
|
|
7
|
+
maxIdentityLength: 200,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
/*
|
|
11
|
+
* Return the stable authority key for one DataTable cell coordinate.
|
|
12
|
+
*/
|
|
13
|
+
export function getDataTableRealtimeCellAuthorityKey(
|
|
14
|
+
dataTableRowId: string,
|
|
15
|
+
cellKey: string,
|
|
16
|
+
) {
|
|
17
|
+
return JSON.stringify(['CELL', dataTableRowId, cellKey]);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/*
|
|
21
|
+
* Return the stable authority key for one DataTable design property.
|
|
22
|
+
*/
|
|
23
|
+
export function getDataTableRealtimeDesignAuthorityKey(
|
|
24
|
+
targetType: 'CELL' | 'TABLE',
|
|
25
|
+
targetKey: string,
|
|
26
|
+
property:
|
|
27
|
+
| 'CELLS_ORDER'
|
|
28
|
+
| 'FORMAT'
|
|
29
|
+
| 'HUMAN_LABEL'
|
|
30
|
+
| 'ROW_IDENTIFIER'
|
|
31
|
+
| 'WIDTH',
|
|
32
|
+
) {
|
|
33
|
+
return JSON.stringify(['DESIGN', targetType, targetKey, property]);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/*
|
|
37
|
+
* Return the stable authority key for one DataTable row tombstone.
|
|
38
|
+
*/
|
|
39
|
+
export function getDataTableRealtimeRowAuthorityKey(dataTableRowId: string) {
|
|
40
|
+
return JSON.stringify(['ROW', dataTableRowId]);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/*
|
|
44
|
+
* Return the stable target key represented by one committed write order.
|
|
45
|
+
*/
|
|
46
|
+
export function getDataTableRealtimeWriteOrderKey(
|
|
47
|
+
order: DataTableWriteOrderWS,
|
|
48
|
+
) {
|
|
49
|
+
if (order.kind === 'CELL') {
|
|
50
|
+
return getDataTableRealtimeCellAuthorityKey(
|
|
51
|
+
order.dataTableRowId,
|
|
52
|
+
order.cellKey,
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
if (order.kind === 'DESIGN') {
|
|
56
|
+
return getDataTableRealtimeDesignAuthorityKey(
|
|
57
|
+
order.targetType,
|
|
58
|
+
order.targetKey,
|
|
59
|
+
order.property,
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
return getDataTableRealtimeRowAuthorityKey(order.dataTableRowId);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/*
|
|
66
|
+
* Return whether one unknown value is a bounded stable transport string.
|
|
67
|
+
*/
|
|
68
|
+
function dataTableRealtimeAuthorityStringIsValid(
|
|
69
|
+
value: unknown,
|
|
70
|
+
maxLength: number,
|
|
71
|
+
): value is string {
|
|
72
|
+
return (
|
|
73
|
+
typeof value === 'string' &&
|
|
74
|
+
value.length > 0 &&
|
|
75
|
+
value.length <= maxLength &&
|
|
76
|
+
value.trim() === value
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/*
|
|
81
|
+
* Normalize one exact committed write-order object without retaining extras.
|
|
82
|
+
*/
|
|
83
|
+
function normalizeDataTableRealtimeWriteOrder(
|
|
84
|
+
value: unknown,
|
|
85
|
+
): DataTableWriteOrderWS | null {
|
|
86
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
const order = value as Record<string, unknown>;
|
|
90
|
+
if (
|
|
91
|
+
typeof order.serverSeq !== 'string' ||
|
|
92
|
+
!FILE_CONSTANTS.canonicalPositiveIntegerPattern.test(order.serverSeq)
|
|
93
|
+
) {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
if (order.kind === 'CELL') {
|
|
97
|
+
if (
|
|
98
|
+
Object.keys(order).some(
|
|
99
|
+
(key) =>
|
|
100
|
+
![
|
|
101
|
+
'cellKey',
|
|
102
|
+
'dataTableRowId',
|
|
103
|
+
'kind',
|
|
104
|
+
'serverSeq',
|
|
105
|
+
'tombstone',
|
|
106
|
+
].includes(key),
|
|
107
|
+
) ||
|
|
108
|
+
!dataTableRealtimeAuthorityStringIsValid(
|
|
109
|
+
order.dataTableRowId,
|
|
110
|
+
FILE_CONSTANTS.maxIdentityLength,
|
|
111
|
+
) ||
|
|
112
|
+
!dataTableRealtimeAuthorityStringIsValid(
|
|
113
|
+
order.cellKey,
|
|
114
|
+
FILE_CONSTANTS.maxCellKeyLength,
|
|
115
|
+
) ||
|
|
116
|
+
typeof order.tombstone !== 'boolean'
|
|
117
|
+
) {
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
cellKey: order.cellKey,
|
|
122
|
+
dataTableRowId: order.dataTableRowId,
|
|
123
|
+
kind: 'CELL',
|
|
124
|
+
serverSeq: order.serverSeq,
|
|
125
|
+
tombstone: order.tombstone,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
if (order.kind === 'DESIGN') {
|
|
129
|
+
const tableProperty =
|
|
130
|
+
order.targetType === 'TABLE' &&
|
|
131
|
+
order.targetKey === '@TABLE' &&
|
|
132
|
+
(order.property === 'CELLS_ORDER' || order.property === 'ROW_IDENTIFIER');
|
|
133
|
+
const cellProperty =
|
|
134
|
+
order.targetType === 'CELL' &&
|
|
135
|
+
dataTableRealtimeAuthorityStringIsValid(
|
|
136
|
+
order.targetKey,
|
|
137
|
+
FILE_CONSTANTS.maxCellKeyLength,
|
|
138
|
+
) &&
|
|
139
|
+
(order.property === 'FORMAT' ||
|
|
140
|
+
order.property === 'HUMAN_LABEL' ||
|
|
141
|
+
order.property === 'WIDTH');
|
|
142
|
+
if (
|
|
143
|
+
Object.keys(order).some(
|
|
144
|
+
(key) =>
|
|
145
|
+
![
|
|
146
|
+
'kind',
|
|
147
|
+
'property',
|
|
148
|
+
'serverSeq',
|
|
149
|
+
'targetKey',
|
|
150
|
+
'targetType',
|
|
151
|
+
'tombstone',
|
|
152
|
+
].includes(key),
|
|
153
|
+
) ||
|
|
154
|
+
(!tableProperty && !cellProperty) ||
|
|
155
|
+
typeof order.tombstone !== 'boolean'
|
|
156
|
+
) {
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
return {
|
|
160
|
+
kind: 'DESIGN',
|
|
161
|
+
property: order.property as Extract<
|
|
162
|
+
DataTableWriteOrderWS,
|
|
163
|
+
{ kind: 'DESIGN' }
|
|
164
|
+
>['property'],
|
|
165
|
+
serverSeq: order.serverSeq,
|
|
166
|
+
targetKey: order.targetKey as string,
|
|
167
|
+
targetType: order.targetType as 'CELL' | 'TABLE',
|
|
168
|
+
tombstone: order.tombstone,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
if (
|
|
172
|
+
order.kind !== 'ROW' ||
|
|
173
|
+
Object.keys(order).some(
|
|
174
|
+
(key) =>
|
|
175
|
+
!['dataTableRowId', 'kind', 'serverSeq', 'tombstone'].includes(key),
|
|
176
|
+
) ||
|
|
177
|
+
!dataTableRealtimeAuthorityStringIsValid(
|
|
178
|
+
order.dataTableRowId,
|
|
179
|
+
FILE_CONSTANTS.maxIdentityLength,
|
|
180
|
+
) ||
|
|
181
|
+
typeof order.tombstone !== 'boolean'
|
|
182
|
+
) {
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
return {
|
|
186
|
+
dataTableRowId: order.dataTableRowId,
|
|
187
|
+
kind: 'ROW',
|
|
188
|
+
serverSeq: order.serverSeq,
|
|
189
|
+
tombstone: order.tombstone,
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/*
|
|
194
|
+
* Normalize one bounded exact array of committed DataTable write orders.
|
|
195
|
+
*/
|
|
196
|
+
export function normalizeDataTableRealtimeWriteOrders(
|
|
197
|
+
value: unknown,
|
|
198
|
+
): DataTableWriteOrderWS[] | null {
|
|
199
|
+
if (
|
|
200
|
+
!Array.isArray(value) ||
|
|
201
|
+
value.length > DATA_TABLE_REALTIME_MAX_LOGICAL_OPERATIONS
|
|
202
|
+
) {
|
|
203
|
+
return null;
|
|
204
|
+
}
|
|
205
|
+
const normalized = value.map(normalizeDataTableRealtimeWriteOrder);
|
|
206
|
+
return normalized.some((order) => !order)
|
|
207
|
+
? null
|
|
208
|
+
: (normalized as DataTableWriteOrderWS[]);
|
|
209
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
export type DataTableRealtimeSelection = readonly [
|
|
2
|
+
anchorRowId: string,
|
|
3
|
+
anchorCellKey: string,
|
|
4
|
+
rangeEndRowId: string,
|
|
5
|
+
rangeEndCellKey: string,
|
|
6
|
+
];
|
|
7
|
+
|
|
8
|
+
export type DataTableRealtimeSelectionEvent = {
|
|
9
|
+
c: string;
|
|
10
|
+
d: string;
|
|
11
|
+
q: number;
|
|
12
|
+
s: DataTableRealtimeSelection | null;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type DataTableRealtimeSelectionRequest = {
|
|
16
|
+
d: string;
|
|
17
|
+
s: DataTableRealtimeSelection | null;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const FILE_CONSTANTS = {
|
|
21
|
+
cellKeyMaxChars: 80,
|
|
22
|
+
connectionIdMaxChars: 200,
|
|
23
|
+
genericIdPattern: /^\d{1,32}$/,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/*
|
|
27
|
+
* Return whether one untrusted object has exactly the requested own keys.
|
|
28
|
+
*/
|
|
29
|
+
function hasExactDataTableRealtimeSelectionKeys(
|
|
30
|
+
value: Record<string, unknown>,
|
|
31
|
+
keys: string[],
|
|
32
|
+
) {
|
|
33
|
+
const valueKeys = Object.keys(value);
|
|
34
|
+
return (
|
|
35
|
+
valueKeys.length === keys.length &&
|
|
36
|
+
valueKeys.every((key) => keys.includes(key))
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/*
|
|
41
|
+
* Return whether one value is a bounded stable DataTable cell key.
|
|
42
|
+
*/
|
|
43
|
+
function isDataTableRealtimeSelectionCellKey(value: unknown): value is string {
|
|
44
|
+
return (
|
|
45
|
+
typeof value === 'string' &&
|
|
46
|
+
value.length > 0 &&
|
|
47
|
+
value.length <= FILE_CONSTANTS.cellKeyMaxChars &&
|
|
48
|
+
value.trim() === value
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/*
|
|
53
|
+
* Return whether one value is a compact serialized DataTable or row id.
|
|
54
|
+
*/
|
|
55
|
+
function isDataTableRealtimeSelectionGenericId(
|
|
56
|
+
value: unknown,
|
|
57
|
+
): value is string {
|
|
58
|
+
return (
|
|
59
|
+
typeof value === 'string' && FILE_CONSTANTS.genericIdPattern.test(value)
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/*
|
|
64
|
+
* Validate one constant-size DataTable range encoded as two endpoint cells.
|
|
65
|
+
*/
|
|
66
|
+
export function isExactDataTableRealtimeSelection(
|
|
67
|
+
value: unknown,
|
|
68
|
+
): value is DataTableRealtimeSelection {
|
|
69
|
+
return (
|
|
70
|
+
Array.isArray(value) &&
|
|
71
|
+
value.length === 4 &&
|
|
72
|
+
isDataTableRealtimeSelectionGenericId(value[0]) &&
|
|
73
|
+
isDataTableRealtimeSelectionCellKey(value[1]) &&
|
|
74
|
+
isDataTableRealtimeSelectionGenericId(value[2]) &&
|
|
75
|
+
isDataTableRealtimeSelectionCellKey(value[3])
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/*
|
|
80
|
+
* Validate and copy one compact selection relay request from an untrusted client.
|
|
81
|
+
*/
|
|
82
|
+
export function normalizeDataTableRealtimeSelectionRequest(
|
|
83
|
+
value: unknown,
|
|
84
|
+
): DataTableRealtimeSelectionRequest | null {
|
|
85
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
const request = value as Record<string, unknown>;
|
|
89
|
+
if (
|
|
90
|
+
!hasExactDataTableRealtimeSelectionKeys(request, ['d', 's']) ||
|
|
91
|
+
!isDataTableRealtimeSelectionGenericId(request.d) ||
|
|
92
|
+
(request.s !== null && !isExactDataTableRealtimeSelection(request.s))
|
|
93
|
+
) {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return {
|
|
98
|
+
d: request.d,
|
|
99
|
+
s: request.s === null ? null : [...request.s],
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/*
|
|
104
|
+
* Validate and copy one server-stamped compact DataTable selection event.
|
|
105
|
+
*/
|
|
106
|
+
export function normalizeDataTableRealtimeSelectionEvent(
|
|
107
|
+
value: unknown,
|
|
108
|
+
expectedDataTableId: string,
|
|
109
|
+
): DataTableRealtimeSelectionEvent | null {
|
|
110
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
const event = value as Record<string, unknown>;
|
|
114
|
+
if (
|
|
115
|
+
!hasExactDataTableRealtimeSelectionKeys(event, ['c', 'd', 'q', 's']) ||
|
|
116
|
+
event.d !== expectedDataTableId ||
|
|
117
|
+
typeof event.c !== 'string' ||
|
|
118
|
+
event.c.length < 1 ||
|
|
119
|
+
event.c.length > FILE_CONSTANTS.connectionIdMaxChars ||
|
|
120
|
+
event.c.trim() !== event.c ||
|
|
121
|
+
!Number.isSafeInteger(event.q) ||
|
|
122
|
+
Number(event.q) < 1 ||
|
|
123
|
+
(event.s !== null && !isExactDataTableRealtimeSelection(event.s))
|
|
124
|
+
) {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return {
|
|
129
|
+
c: event.c,
|
|
130
|
+
d: event.d,
|
|
131
|
+
q: event.q as number,
|
|
132
|
+
s: event.s === null ? null : [...event.s],
|
|
133
|
+
};
|
|
134
|
+
}
|