@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.
Files changed (123) hide show
  1. package/package.json +105 -35
  2. package/src/constants/agentDoc.ts +12 -0
  3. package/src/constants/agentMemory.ts +154 -0
  4. package/src/constants/aiChat.ts +5 -0
  5. package/src/constants/campaign.ts +127 -0
  6. package/src/constants/dataTable.ts +48 -0
  7. package/src/constants/dataTableFieldTypes.generated.ts +63 -0
  8. package/src/constants/docAccess.ts +32 -0
  9. package/src/constants/email.ts +44 -0
  10. package/src/constants/fieldDoc.ts +34 -0
  11. package/src/constants/graphqlReactivity.ts +113 -0
  12. package/src/constants/inboundContact.ts +8 -0
  13. package/src/constants/integration.ts +13 -0
  14. package/src/constants/log.ts +7 -366
  15. package/src/constants/logActivityGroupColors.generated.ts +19 -0
  16. package/src/constants/logTaxonomy.generated.ts +1103 -0
  17. package/src/constants/noteDoc.ts +77 -0
  18. package/src/constants/organization.ts +18 -11
  19. package/src/constants/pageRoute.ts +23 -0
  20. package/src/constants/schedule.ts +220 -0
  21. package/src/constants/scheduleRuleTemplateSeed.ts +138 -0
  22. package/src/constants/scheduleRuleTemplates.generated.ts +145 -0
  23. package/src/constants/sheet.ts +168 -0
  24. package/src/constants/sheetRegionSources.generated.ts +578 -0
  25. package/src/constants/square.ts +16 -0
  26. package/src/constants/storage.ts +61 -0
  27. package/src/constants/usage.ts +79 -0
  28. package/src/schemas/editLogEntry.ts +1017 -738
  29. package/src/schemas/fieldDocsQuery.ts +12 -0
  30. package/src/schemas/inboundContact.ts +77 -0
  31. package/src/schemas/logsQuery.ts +57 -316
  32. package/src/schemas/organization.ts +53 -213
  33. package/src/types/account.d.ts +81 -0
  34. package/src/types/agentDoc.d.ts +64 -0
  35. package/src/types/agentMemory.d.ts +74 -0
  36. package/src/types/campaign.d.ts +683 -0
  37. package/src/types/dataTable.d.ts +366 -0
  38. package/src/types/docAccess.d.ts +96 -0
  39. package/src/types/email.d.ts +142 -0
  40. package/src/types/fieldDoc.d.ts +273 -0
  41. package/src/types/inboundContact.d.ts +57 -0
  42. package/src/types/integration.d.ts +42 -0
  43. package/src/types/log.d.ts +169 -190
  44. package/src/types/noteDoc.d.ts +86 -0
  45. package/src/types/organization.d.ts +175 -76
  46. package/src/types/pageRoute.d.ts +48 -0
  47. package/src/types/schedule.d.ts +391 -0
  48. package/src/types/sheet.d.ts +1130 -0
  49. package/src/types/storage.d.ts +242 -0
  50. package/src/types/usage.d.ts +106 -0
  51. package/src/types/workflow.d.ts +305 -0
  52. package/src/utils/agentDoc.ts +109 -0
  53. package/src/utils/aiChat.ts +26 -0
  54. package/src/utils/campaign.ts +741 -0
  55. package/src/utils/campaignFormEditor.ts +871 -0
  56. package/src/utils/dataTable.ts +849 -0
  57. package/src/utils/dataTableFieldTypeRegistry.ts +105 -0
  58. package/src/utils/dataTableRealtimeAuthority.ts +209 -0
  59. package/src/utils/dataTableRealtimeSelection.ts +134 -0
  60. package/src/utils/dataTableRowDocument.ts +508 -0
  61. package/src/utils/dataTableSource.ts +230 -0
  62. package/src/utils/docAccess.ts +383 -0
  63. package/src/utils/documentName.ts +53 -0
  64. package/src/utils/email.ts +172 -0
  65. package/src/utils/fieldDoc.ts +113 -0
  66. package/src/utils/log.ts +173 -778
  67. package/src/utils/logRegistryValue.ts +90 -0
  68. package/src/utils/logStoreRead.ts +266 -0
  69. package/src/utils/logTaxonomy.ts +76 -0
  70. package/src/utils/logTaxonomyDisplay.ts +439 -0
  71. package/src/utils/noteDoc.ts +827 -0
  72. package/src/utils/organization.ts +683 -81
  73. package/src/utils/pageRoute.ts +71 -0
  74. package/src/utils/schedule.ts +799 -0
  75. package/src/utils/scheduleEvaluation.ts +1994 -0
  76. package/src/utils/scheduleICS.ts +246 -0
  77. package/src/utils/scheduleRuleTemplates.ts +188 -0
  78. package/src/utils/sheet.ts +4973 -0
  79. package/src/utils/sheetAxisMove.ts +830 -0
  80. package/src/utils/sheetBootstrap.ts +1769 -0
  81. package/src/utils/sheetCommand.ts +423 -0
  82. package/src/utils/sheetExport.ts +238 -0
  83. package/src/utils/sheetFormulaEvaluation.ts +914 -0
  84. package/src/utils/sheetFormulaEvaluator.ts +852 -0
  85. package/src/utils/sheetJournal.ts +78 -0
  86. package/src/utils/sheetNumberFormat.ts +1211 -0
  87. package/src/utils/sheetRegion.ts +374 -0
  88. package/src/utils/sheetRegionFilter.ts +1259 -0
  89. package/src/utils/sheetRegionSourceRegistry.ts +594 -0
  90. package/src/utils/sheetSequence.ts +148 -0
  91. package/src/utils/sheetSnapshot.ts +992 -0
  92. package/src/utils/sheetStructureEdit.ts +1284 -0
  93. package/src/utils/square.ts +32 -0
  94. package/src/utils/storage.ts +152 -0
  95. package/src/utils/table-route.ts +262 -0
  96. package/src/utils/workflow.ts +380 -0
  97. package/tests/dataTableFieldTypeRegistry.test.ts +110 -0
  98. package/tests/docAccess.test.ts +525 -0
  99. package/tests/editLogEntry.test.ts +112 -0
  100. package/tests/noteDoc.test.ts +669 -0
  101. package/tests/schedule.test.ts +693 -0
  102. package/tests/scheduleEvaluation.test.ts +1970 -0
  103. package/tests/scheduleICS.test.ts +208 -0
  104. package/tests/scheduleRuleTemplates.test.ts +176 -0
  105. package/tests/scheduleSweepInvariants.test.ts +428 -0
  106. package/tests/sheetAxisMove.test.ts +343 -0
  107. package/tests/sheetFormulaEvaluator.test.ts +575 -0
  108. package/tests/sheetRegionFilter.test.ts +1135 -0
  109. package/tests/sheetSequence.test.ts +41 -0
  110. package/tests/sheetStructureEdit.test.ts +82 -0
  111. package/tsconfig.json +12 -0
  112. package/vitest.config.ts +8 -0
  113. package/src/constants/log-activityTexts.ts +0 -209
  114. package/src/constants/product.ts +0 -66
  115. package/src/constants/report.ts +0 -25
  116. package/src/schemas/childOrganizationsQuery.ts +0 -44
  117. package/src/schemas/productsQuery.ts +0 -145
  118. package/src/schemas/reportsQuery.ts +0 -107
  119. package/src/types/action.d.ts +0 -42
  120. package/src/types/product.d.ts +0 -173
  121. package/src/types/report.d.ts +0 -203
  122. package/src/utils/product-calEvent.ts +0 -508
  123. package/src/utils/route-helpers.ts +0 -583
@@ -1,224 +1,175 @@
1
- import type { AccountObj } from '@jsb188/app/types/account.d';
2
- import type { ActionTaskGQL, ActionTaskObj } from '@jsb188/mday/types/action.d';
3
- import type { OrganizationOperationEnum } from '../types/organization.d';
4
- import {
5
- LOG_ACTION_STATUS_ENUMS,
6
- LOG_ARABLE_ACTIVITY_ENUMS,
7
- LOG_FARMERS_MARKET_ACTIVITY_ENUMS,
8
- LOG_LIVESTOCK_ACTIVITY_ENUMS,
9
- LOG_SORT_ENUMS
10
- } from '../constants/log';
1
+ import { REQUEST_SOURCE_ENUMS } from '@jsb188/app/constants/agent.ts';
2
+ import type { LabelAndValue } from '@jsb188/app/types/other.d.ts';
3
+ import { LOG_SORT_ENUMS } from '../constants/log.ts';
4
+ import type { OrganizationOperationEnum } from '../types/organization.d.ts';
5
+ import type { AccountObj } from './account.d.ts';
6
+ import type { StorageGQL } from './storage.d.ts';
11
7
 
12
8
  /**
13
9
  * Enums
14
10
  */
15
11
 
16
- export type LogActionStatusEnum = (typeof LOG_ACTION_STATUS_ENUMS)[number];
17
- export type LogContentName = 'log' | 'ai_task' | 'invoice' | 'receipt'; // For UI visuals, client-side only
18
- export type LogSortEnum = typeof LOG_SORT_ENUMS[number];
12
+ export type LogContentName = 'log' | 'invoice' | 'receipt'; // For UI visuals, client-side only
13
+ export type LogSortEnum = (typeof LOG_SORT_ENUMS)[number];
14
+ export type RequestSourceEnum = (typeof REQUEST_SOURCE_ENUMS)[number];
19
15
 
20
- /**
21
- * Arable
22
- */
23
-
24
- export type LogArableTypeEnum =
25
- | 'SEED'
26
- | 'PLANTING'
27
- | 'FIELD'
28
- | 'HARVEST'
29
- | 'POST_HARVEST'
30
- | 'SALES'
31
- | 'WATER'
32
- | 'HYGIENE'
33
- | 'SANITATION'
34
- | 'EQUIPMENTS'
35
- | 'BIOSECURITY'
36
- | 'EMPLOYEES';
37
- export type LogArableActivityEnum = typeof LOG_ARABLE_ACTIVITY_ENUMS[number];
38
-
39
- /**
40
- * Farmers Market
41
- */
42
-
43
- export type LogFarmersMarketTypeEnum = 'MARKET_RECEIPTS' | 'MARKET_OPERATIONS';
44
- export type LogFarmersMarketActivityEnum = typeof LOG_FARMERS_MARKET_ACTIVITY_ENUMS[number];
45
-
46
- /**
47
- * Livestock
48
- */
49
-
50
- export type LogLivestockTypeEnum =
51
- | 'SUPPLY_PURCHASE'
52
- | 'LIVESTOCK_LIFE_CYCLE'
53
- | 'LIVESTOCK_TRACKING'
54
- | 'PASTURE_LAND_MANAGEMENT'
55
- | 'LIVESTOCK_HEALTHCARE'
56
- | 'LIVESTOCK_SALE';
57
- export type LogLivestockActivityEnum = typeof LOG_LIVESTOCK_ACTIVITY_ENUMS[number];
58
-
59
- /**
60
- * All log types/activities Union
61
- */
62
-
63
- export type LogTypeEnum = LogArableTypeEnum | LogFarmersMarketTypeEnum | LogLivestockTypeEnum | 'AI_TASK';
64
- export type LogActivityEnum = LogArableActivityEnum | LogFarmersMarketActivityEnum | LogLivestockActivityEnum;
16
+ // Activity and group keys are registry data and can be extended per organization.
17
+ export type LogTypeEnum = string;
18
+ export type LogActivityEnum = string;
65
19
 
66
20
  /**
67
- * Log metadata
21
+ * Shared log details fields
68
22
  */
69
23
 
70
- interface LogDetailsGQLBase {
71
- __typename: string;
72
- id: string;
73
- type: any;
74
- activity: any;
75
- notes: string;
76
- }
77
-
78
- interface LogMetadataBase {
79
- __before: any;
80
- childOrg: never;
81
- childOrgId: never;
82
- referenceNumber: never;
83
-
84
- recurFromLogId?: number;
85
- recurredCount?: number;
86
- summary?: string;
24
+ export interface LogDetailsBase {
25
+ id: number | bigint;
26
+ childOrg?: {
27
+ id: number | bigint;
28
+ name: string;
29
+ operation?: OrganizationOperationEnum | null;
30
+ };
31
+ childOrgId?: number | bigint | null;
32
+ fieldDocId?: number | bigint | null;
33
+ fieldDocSubmissionId?: number | bigint | null;
34
+ siteId?: number | bigint | null;
35
+ site?: {
36
+ id: number | bigint;
37
+ name: string;
38
+ };
39
+ location?: {
40
+ name: string;
41
+ } | null;
42
+ notes: string | null;
43
+ translation: string | null;
87
44
  }
88
45
 
89
- interface LabelValueObj {
90
- label: string;
91
- value: string;
92
- quantity?: number;
46
+ // All operations use one registry-driven details shape.
47
+ export interface LogEntryDetailsData extends LogDetailsBase {
48
+ __table: 'log_entry_details';
49
+ activity: string;
50
+ logType?: string | null;
51
+ fields?: LogEntryDetailsFieldGQL[] | null;
52
+ metadata?: Record<string, any> | null;
93
53
  }
94
54
 
95
- /**
96
- * Log details - Arable
97
- */
98
-
99
- export type LogArableMetadata = LogMetadataBase & {
100
- item: string;
101
- quantity: number;
102
- unit: string;
103
- concentration: number;
104
- concentrationUnit: string;
105
- location: string;
106
- fieldLocation?: string;
107
- otherParty?: string;
108
- referenceNumber?: string;
109
- values?: LabelValueObj[];
110
- tax: number;
111
- };
112
-
113
- export interface LogArableObj {
114
- type?: LogArableTypeEnum; // Only set in server if manually extended
115
- activity: LogArableActivityEnum;
116
- notes: string | null;
117
- translation?: string | null;
118
- metadata?: Partial<LogArableMetadata> | null;
55
+ // One typed field-def value on a registry-driven operation's log
56
+ export interface LogEntryDetailsFieldGQL {
57
+ key: string;
58
+ fieldType: string | null;
59
+ textValue: string | null;
60
+ numberValue: number | null;
61
+ booleanValue: boolean | null;
62
+ dateValue: string | null;
63
+ datetimeValue: string | null;
64
+ unit: string | null;
119
65
  }
120
66
 
121
- export interface LogArableDetailsObj extends LogArableObj {
122
- __table: 'logs_arable';
123
- id: number | bigint;
124
- childOrg: never;
67
+ // One typed field-def value sent when editing a registry-driven log
68
+ export interface LogEntryDetailsFieldInput {
69
+ key: string;
70
+ textValue?: string | null;
71
+ numberValue?: number | null;
72
+ booleanValue?: boolean | null;
73
+ dateValue?: string | null;
74
+ datetimeValue?: string | null;
75
+ unit?: string | null;
76
+ clear?: boolean | null;
125
77
  }
126
78
 
127
- export type LogArableMetadataGQL = LogArableMetadata & LogDetailsGQLBase;
79
+ // Details for registry-driven operations; type/activity are registry keys
80
+ export interface LogEntryDetailsGQL {
81
+ __typename: 'LogEntryDetails';
128
82
 
129
- /**
130
- * Log details - Farmers Market
131
- */
132
-
133
- export type LogFarmersMarketMetadata = LogMetadataBase & {
134
- referenceNumber: string;
135
- voided: boolean;
136
- childOrgId?: number;
137
- values: LabelValueObj[];
138
- };
83
+ id: string;
84
+ type: string | null;
85
+ activity: string;
86
+ notes: string;
139
87
 
140
- export interface LogFarmersMarketObj {
141
- childOrgId: number | bigint;
142
- type?: LogFarmersMarketTypeEnum; // Only set in server if manually extended
143
- activity: LogFarmersMarketActivityEnum;
144
- notes: string | null;
145
- translation?: string | null;
146
- metadata?: Partial<LogFarmersMarketMetadata> | null;
88
+ item: string | null;
89
+ quantity: number | null;
90
+ unit: string | null;
91
+ price: number | null;
92
+ values: LabelAndValue[] | null;
93
+ fields: LogEntryDetailsFieldGQL[] | null;
94
+
95
+ otherParty: string | null;
96
+ referenceNumber: string | null;
97
+ fieldLocation: string | null;
98
+ voided: boolean | null;
147
99
  }
148
100
 
149
- export interface LogFarmersMarketDetailsObj extends LogFarmersMarketObj {
150
- __table: 'logs_farmers_market';
151
- id: number | bigint;
152
- childOrg: {
153
- id: number | bigint;
154
- name: string;
155
- };
101
+ // Log taxonomy carried by the existing organization bootstrap (registry rows)
102
+ export interface LogTaxonomyGroupGQL {
103
+ key: string;
104
+ label: string | null;
105
+ ordinal: number | null;
106
+ requiredFields: string[] | null;
107
+ orRequiredFields: string[] | null;
156
108
  }
157
109
 
158
- export type LogFarmersMarketMetadataGQL = LogFarmersMarketMetadata & LogDetailsGQLBase;
159
-
160
- /**
161
- * Log details - Livestock
162
- */
163
-
164
- export type LogLivestockMetadata = LogMetadataBase & {
165
- damIdentifier?: string;
166
- livestockIdentifiers: string[];
167
- livestockGroup?: string;
168
- livestock: string;
169
- otherParty?: string;
170
- referenceNumber?: string;
171
- values?: LabelValueObj[];
172
- item: string;
173
- quantity: number;
174
- unit: string;
175
- location: string;
176
- fieldLocation?: string;
177
- price: number;
178
- tax: number;
179
- };
180
-
181
- export interface LogLivestockObj {
182
- type?: LogLivestockTypeEnum; // Only set in server if manually extended
183
- activity: LogLivestockActivityEnum;
184
- notes: string | null;
185
- translation?: string | null;
186
- damIdentifier?: string;
187
- livestockIdentifiers: string[];
188
- livestockGroup?: string;
189
- metadata?: Partial<LogLivestockMetadata> | null;
110
+ export interface LogTaxonomyActivityGQL {
111
+ key: string;
112
+ groupKey: string | null;
113
+ agentText: string | null;
114
+ ordinal: number | null;
115
+ requiredFields: string[] | null;
116
+ orRequiredFields: string[] | null;
190
117
  }
191
118
 
192
- export interface LogLivestockDetailsObj extends LogLivestockObj {
193
- __table: 'logs_livestock';
194
- id: number | bigint;
195
- childOrg: never;
119
+ export interface LogTaxonomyFieldDefGQL {
120
+ key: string;
121
+ fieldType: string;
122
+ required: boolean | null;
123
+ ordinal: number | null;
124
+ agentHint: string | null;
125
+ options: string[] | null;
126
+ allowedUnits: string[] | null;
127
+ groupKey: string | null;
128
+ activityKey: string | null;
196
129
  }
197
130
 
198
- export type LogLivestockMetadataGQL = LogLivestockMetadata & LogDetailsGQLBase;
199
-
200
- /**
201
- * Union type for log details
202
- */
203
-
204
- export type LogDetailsObj = LogArableObj | LogFarmersMarketObj | LogLivestockObj;
205
- export type LogMetadataGQL = LogArableMetadataGQL | LogFarmersMarketMetadataGQL | LogLivestockMetadataGQL;
131
+ export interface LogTaxonomyGQL {
132
+ operation: string;
133
+ groups: LogTaxonomyGroupGQL[];
134
+ activities: LogTaxonomyActivityGQL[];
135
+ fieldDefs: LogTaxonomyFieldDefGQL[];
136
+ }
206
137
 
207
138
  /**
208
139
  * GQL data interfaces
209
140
  */
210
141
 
211
142
  export interface LogEntryGQL {
143
+ __typename: string;
212
144
  __deleted?: boolean;
213
145
 
214
146
  id: string;
147
+ cursor?: string | null;
215
148
  accountId: string;
216
149
  organizationId: string;
217
- details: LogMetadataGQL;
218
- status: LogActionStatusEnum | null;
150
+ childOrgId: string | null;
151
+ childOrgName: string | null;
152
+ inboundContactId: string | null;
153
+ inboundContactName: string | null;
154
+ inboundContactEmail?: string | null;
155
+ inboundContactPhone?: string | null;
156
+ fieldDocId: string | null;
157
+ fieldDocName?: string | null;
158
+ fieldDocSubmissionId: string | null;
159
+ fieldDocSubmissionPeriod?: string | null;
160
+ siteId: string | null;
161
+ siteName?: string | null;
162
+ location: string | null;
163
+ accountPersonName?: string | null;
164
+ details: LogEntryDetailsGQL;
165
+ summary: string;
166
+ source?: RequestSourceEnum | null;
167
+ confidence?: number | null;
168
+ originalMessage?: string | null;
169
+ flagColor?: string | null;
219
170
 
220
171
  account: any;
221
- actions?: ActionTaskGQL[];
172
+ files: StorageGQL[];
222
173
 
223
174
  date: string; // ISO date string
224
175
  createdAt: string; // ISO date string
@@ -227,9 +178,18 @@ export interface LogEntryGQL {
227
178
 
228
179
  export interface LogEntryInsertObj {
229
180
  id?: number | bigint; // Only for edits
230
- accountId: number | bigint;
181
+ accountId: number | bigint | null;
231
182
  organizationId: number | bigint;
232
- status?: LogActionStatusEnum | null;
183
+ childOrgId?: number | bigint | null;
184
+ inboundContactId?: number | bigint | null;
185
+ emailId?: number | bigint | null;
186
+ fieldDocId?: number | bigint | null;
187
+ fieldDocSubmissionId?: number | bigint | null;
188
+ siteId?: number | bigint | null;
189
+ summary: string;
190
+ source?: RequestSourceEnum | null;
191
+ confidence?: number | null;
192
+ originalMessage?: string | null;
233
193
  details: any;
234
194
  date: Date;
235
195
  }
@@ -239,16 +199,36 @@ export interface LogEntryData {
239
199
  id: number | bigint;
240
200
  accountId: number | bigint;
241
201
  organizationId: number | bigint;
242
- status: LogActionStatusEnum | null;
202
+ childOrgId?: number | bigint | null;
203
+ inboundContactId?: number | bigint | null;
204
+ emailId?: number | bigint | null;
205
+ inboundContact?: {
206
+ id: number | bigint;
207
+ personName?: string | null;
208
+ } | null;
209
+ childOrg?: {
210
+ id: number | bigint;
211
+ name: string;
212
+ operation?: OrganizationOperationEnum | null;
213
+ } | null;
214
+ fieldDocId?: number | bigint | null;
215
+ fieldDocSubmissionId?: number | bigint | null;
216
+ siteId?: number | bigint | null;
217
+ summary: string;
218
+ source?: RequestSourceEnum | null;
219
+ confidence?: number | null;
220
+ originalMessage?: string | null;
221
+ location?: {
222
+ name: string;
223
+ } | null;
243
224
  distance?: number; // For vector search
244
- details: LogArableDetailsObj | LogFarmersMarketDetailsObj | LogLivestockDetailsObj;
225
+ details: LogEntryDetailsData;
245
226
  date: Date;
246
227
  createdAt: Date;
247
228
  updatedAt: Date;
248
229
 
249
230
  // This is for outputs, but will never be set for inserts
250
231
  account?: AccountObj;
251
- actions?: ActionTaskObj[];
252
232
  }
253
233
 
254
234
  /**
@@ -256,13 +236,12 @@ export interface LogEntryData {
256
236
  */
257
237
 
258
238
  export interface FilterLogEntriesArgs {
259
- operation: OrganizationOperationEnum;
260
239
  accountId?: string | null; // Account ID to filter logs by account
261
- preset?: 'WEEKS_5' | 'AI_TASKS' | 'INCLUDE_AI_TASKS' | 'HIDE_AI_TASKS' | null;
262
- types?: LogTypeEnum[] | null;
263
- activities?: LogActivityEnum[] | null;
240
+ siteId?: string | number | bigint | null; // Site ID to filter logs by site
241
+ preset?: 'WEEKS_5' | null;
242
+ types?: string[] | null;
243
+ activities?: string[] | null;
264
244
  startDate?: string | null; // CalDate, with dashes (YYYY-MM-DD)
265
245
  endDate?: string | null; // CalDate, with dashes (YYYY-MM-DD)
266
- timeZone?: string | null; // Timezone string, e.g., 'America/New_York'
267
246
  query?: string | null;
268
247
  }
@@ -0,0 +1,86 @@
1
+ import type {
2
+ NOTE_BLOCK_TYPES,
3
+ NOTE_INLINE_TYPES,
4
+ NOTE_MARK_TYPES,
5
+ } from '../constants/noteDoc.ts';
6
+
7
+ export type NoteBlockType = (typeof NOTE_BLOCK_TYPES)[number];
8
+ export type NoteInlineType = (typeof NOTE_INLINE_TYPES)[number];
9
+ export type NoteMarkType = (typeof NOTE_MARK_TYPES)[number];
10
+
11
+ // Heading depth; sanitizeNoteDoc clamps anything else into this range
12
+ export type NoteHeadingLevel = 1 | 2 | 3;
13
+
14
+ /**
15
+ * Attrs carried by one "image" void block. storageId is the string form of
16
+ * the storage row id and is the notes_storage_rels source-of-truth key:
17
+ * image blocks whose storageId has no surviving rel row are filtered out of
18
+ * the document on read. fileUri locates the GCS object for rendering.
19
+ */
20
+
21
+ export interface NoteImageAttrs {
22
+ storageId: string;
23
+ fileUri: string;
24
+ alt?: string;
25
+ width?: number;
26
+ }
27
+
28
+ /**
29
+ * One inline mark on a text run. color/highlight marks carry a palette
30
+ * token from NOTE_COLOR_TOKENS; link marks carry an http(s)/mailto href;
31
+ * every other mark type carries no attrs.
32
+ */
33
+
34
+ export interface NoteMark {
35
+ type: NoteMarkType;
36
+ attrs?: {
37
+ token?: string;
38
+ href?: string;
39
+ };
40
+ }
41
+
42
+ /**
43
+ * One inline node inside a text-bearing block: a styled text run, or a
44
+ * hard line break (which carries neither text nor marks).
45
+ */
46
+
47
+ export interface NoteInlineNode {
48
+ type: NoteInlineType;
49
+ text?: string;
50
+ marks?: NoteMark[];
51
+ }
52
+
53
+ /**
54
+ * Attrs a block node may carry: "level" on headings, image attrs on image
55
+ * blocks. Every other block type carries no attrs.
56
+ */
57
+
58
+ export interface NoteBlockAttrs extends Partial<NoteImageAttrs> {
59
+ level?: NoteHeadingLevel;
60
+ }
61
+
62
+ /**
63
+ * One block-level node. Containers (bulletList, orderedList, listItem,
64
+ * blockquote) hold block children; paragraph/heading hold inline children;
65
+ * divider/image hold none. _key and _uploading are client-editor-only
66
+ * fields, always stripped by sanitizeNoteDoc before persistence.
67
+ */
68
+
69
+ export interface NoteBlockNode {
70
+ type: NoteBlockType;
71
+ attrs?: NoteBlockAttrs;
72
+ content?: Array<NoteBlockNode | NoteInlineNode>;
73
+ _key?: string;
74
+ _uploading?: boolean;
75
+ }
76
+
77
+ /**
78
+ * The root note document stored in notes.content (JSONB). Always non-empty
79
+ * after sanitizing: at least one (possibly empty) paragraph.
80
+ */
81
+
82
+ export interface NoteDoc {
83
+ type: 'doc';
84
+ version: number;
85
+ content: NoteBlockNode[];
86
+ }