@katlux/toolkit 0.1.1-alpha.144 → 0.1.1-alpha.146
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/bin/ai-init.mjs +517 -0
- package/bin/ai-tokens.mjs +1043 -0
- package/bin/cli.mjs +80 -43
- package/bin/create-preset.mjs +1 -0
- package/bin/preset-contracts.json +2941 -0
- package/dist/compiled/composables/locales.mjs +204 -25
- package/dist/compiled/composables/useDataProvider.mjs +36 -25
- package/dist/compiled/composables/useFilterLogic.mjs +10 -2
- package/dist/compiled/composables/useKatluxForm.mjs +6 -4
- package/dist/compiled/composables/useVirtualDataset.mjs +689 -0
- package/dist/compiled/composables/useVirtualScroll.mjs +29 -9
- package/dist/module.cjs +63 -77
- package/dist/module.d.cts +5 -0
- package/dist/module.d.mts +4 -1
- package/dist/module.json +1 -1
- package/dist/module.mjs +60 -78
- package/dist/runtime/components/KAccordion/KAccordion.global.d.vue.ts +2 -2
- package/dist/runtime/components/KAccordion/KAccordion.global.vue.d.ts +2 -2
- package/dist/runtime/components/KAlert/KAlert.global.d.vue.ts +1 -1
- package/dist/runtime/components/KAlert/KAlert.global.vue.d.ts +1 -1
- package/dist/runtime/components/KBulkActions/KBulkActions.global.d.vue.ts +7 -3
- package/dist/runtime/components/KBulkActions/KBulkActions.global.vue +4 -1
- package/dist/runtime/components/KBulkActions/KBulkActions.global.vue.d.ts +7 -3
- package/dist/runtime/components/KBulkActions/KBulkActions.logic.d.ts +4 -2
- package/dist/runtime/components/KBulkActions/KBulkActions.logic.js +70 -37
- package/dist/runtime/components/KButton/KButton.global.d.vue.ts +2 -2
- package/dist/runtime/components/KButton/KButton.global.vue.d.ts +2 -2
- package/dist/runtime/components/KButton/KButton.logic.d.ts +1 -1
- package/dist/runtime/components/KCalendar/KCalendar.global.d.vue.ts +19 -10
- package/dist/runtime/components/KCalendar/KCalendar.global.vue +7 -2
- package/dist/runtime/components/KCalendar/KCalendar.global.vue.d.ts +19 -10
- package/dist/runtime/components/KCalendar/KCalendar.logic.d.ts +14 -201
- package/dist/runtime/components/KCalendar/KCalendar.logic.js +60 -11
- package/dist/runtime/components/KCalendar/KCalendarMonth.global.d.vue.ts +25 -5
- package/dist/runtime/components/KCalendar/KCalendarMonth.global.vue +11 -1
- package/dist/runtime/components/KCalendar/KCalendarMonth.global.vue.d.ts +25 -5
- package/dist/runtime/components/KCalendar/KCalendarMonth.logic.d.ts +19 -3
- package/dist/runtime/components/KCalendar/KCalendarMonth.logic.js +115 -1
- package/dist/runtime/components/KCheckbox/KCheckbox.global.d.vue.ts +2 -2
- package/dist/runtime/components/KCheckbox/KCheckbox.global.vue.d.ts +2 -2
- package/dist/runtime/components/KCombobox/KCombobox.global.d.vue.ts +9 -9
- package/dist/runtime/components/KCombobox/KCombobox.global.vue +1 -1
- package/dist/runtime/components/KCombobox/KCombobox.global.vue.d.ts +9 -9
- package/dist/runtime/components/KCombobox/KCombobox.logic.d.ts +7 -1
- package/dist/runtime/components/KCombobox/KCombobox.logic.js +1 -1
- package/dist/runtime/components/KCompositeInput/KCompositeInput.global.d.vue.ts +14 -14
- package/dist/runtime/components/KCompositeInput/KCompositeInput.global.vue.d.ts +14 -14
- package/dist/runtime/components/KCompositeInput/KCompositeInput.logic.d.ts +3 -3
- package/dist/runtime/components/KContextMenu/KContextMenu.logic.js +5 -0
- package/dist/runtime/components/KDatatable/KDataIterator.global.d.vue.ts +22 -18
- package/dist/runtime/components/KDatatable/KDataIterator.global.vue +23 -16
- package/dist/runtime/components/KDatatable/KDataIterator.global.vue.d.ts +22 -18
- package/dist/runtime/components/KDatatable/KDataIterator.logic.d.ts +13 -10
- package/dist/runtime/components/KDatatable/KDataIterator.logic.js +25 -20
- package/dist/runtime/components/KDatatable/KDatatable.global.d.vue.ts +9 -13
- package/dist/runtime/components/KDatatable/KDatatable.global.vue +6 -5
- package/dist/runtime/components/KDatatable/KDatatable.global.vue.d.ts +9 -13
- package/dist/runtime/components/KDatatable/KDatatable.logic.d.ts +4 -6
- package/dist/runtime/components/KDatatable/KDatatable.logic.js +26 -19
- package/dist/runtime/components/KDatePicker/KDatePicker.global.d.vue.ts +31 -15
- package/dist/runtime/components/KDatePicker/KDatePicker.global.vue +38 -13
- package/dist/runtime/components/KDatePicker/KDatePicker.global.vue.d.ts +31 -15
- package/dist/runtime/components/KDatePicker/KDatePicker.logic.d.ts +28 -6
- package/dist/runtime/components/KDatePicker/KDatePicker.logic.js +197 -53
- package/dist/runtime/components/KDateTimePicker/KDateTimePicker.global.d.vue.ts +3 -3
- package/dist/runtime/components/KDateTimePicker/KDateTimePicker.global.vue.d.ts +3 -3
- package/dist/runtime/components/KDateTimePicker/KDateTimePicker.logic.js +2 -0
- package/dist/runtime/components/KDropdown/KDropdown.global.d.vue.ts +1 -1
- package/dist/runtime/components/KDropdown/KDropdown.global.vue.d.ts +1 -1
- package/dist/runtime/components/KGantt/KGantt.global.d.vue.ts +55 -6
- package/dist/runtime/components/KGantt/KGantt.global.vue +12 -3
- package/dist/runtime/components/KGantt/KGantt.global.vue.d.ts +55 -6
- package/dist/runtime/components/KGantt/KGantt.logic.d.ts +33 -5
- package/dist/runtime/components/KGantt/KGantt.logic.js +39 -6
- package/dist/runtime/components/KHourPicker/KHourPicker.global.d.vue.ts +2 -2
- package/dist/runtime/components/KHourPicker/KHourPicker.global.vue.d.ts +2 -2
- package/dist/runtime/components/KHourSelect/KHourSelect.global.d.vue.ts +1 -1
- package/dist/runtime/components/KHourSelect/KHourSelect.global.vue.d.ts +1 -1
- package/dist/runtime/components/KLoader/KLoader.global.vue +2 -0
- package/dist/runtime/components/KMaskTextbox/KMaskTextbox.global.d.vue.ts +2 -2
- package/dist/runtime/components/KMaskTextbox/KMaskTextbox.global.vue.d.ts +2 -2
- package/dist/runtime/components/KMultiTabs/MultiTabs.global.d.vue.ts +23 -0
- package/dist/runtime/components/KMultiTabs/MultiTabs.global.vue +22 -0
- package/dist/runtime/components/KMultiTabs/MultiTabs.global.vue.d.ts +23 -0
- package/dist/runtime/components/KPagination/KPagination.global.d.vue.ts +4 -2
- package/dist/runtime/components/KPagination/KPagination.global.vue +2 -1
- package/dist/runtime/components/KPagination/KPagination.global.vue.d.ts +4 -2
- package/dist/runtime/components/KPagination/KPagination.logic.d.ts +1 -0
- package/dist/runtime/components/KPagination/KPagination.logic.js +57 -5
- package/dist/runtime/components/KRadiobox/KRadiobox.global.d.vue.ts +1 -1
- package/dist/runtime/components/KRadiobox/KRadiobox.global.vue.d.ts +1 -1
- package/dist/runtime/components/KRangeSlider/KRangeSlider.global.d.vue.ts +1 -1
- package/dist/runtime/components/KRangeSlider/KRangeSlider.global.vue.d.ts +1 -1
- package/dist/runtime/components/KSlider/KSlider.global.d.vue.ts +1 -1
- package/dist/runtime/components/KSlider/KSlider.global.vue.d.ts +1 -1
- package/dist/runtime/components/KTabs/KTabs.global.d.vue.ts +2 -2
- package/dist/runtime/components/KTabs/KTabs.global.vue.d.ts +2 -2
- package/dist/runtime/components/KTextarea/KTextarea.global.d.vue.ts +2 -2
- package/dist/runtime/components/KTextarea/KTextarea.global.vue.d.ts +2 -2
- package/dist/runtime/components/KTextbox/KTextbox.global.d.vue.ts +3 -3
- package/dist/runtime/components/KTextbox/KTextbox.global.vue.d.ts +3 -3
- package/dist/runtime/components/KToast/KToast.global.d.vue.ts +3 -3
- package/dist/runtime/components/KToast/KToast.global.vue.d.ts +3 -3
- package/dist/runtime/components/KTooltip/KTooltip.global.d.vue.ts +1 -1
- package/dist/runtime/components/KTooltip/KTooltip.global.vue.d.ts +1 -1
- package/dist/runtime/components/KTree/KTree.global.d.vue.ts +7 -7
- package/dist/runtime/components/KTree/KTree.global.vue.d.ts +7 -7
- package/dist/runtime/components/KTree/KTree.logic.d.ts +2 -2
- package/dist/runtime/components/KTree/KTree.logic.js +16 -12
- package/dist/runtime/components/KTreePicker/KTreePicker.global.d.vue.ts +7 -9
- package/dist/runtime/components/KTreePicker/KTreePicker.global.vue +1 -5
- package/dist/runtime/components/KTreePicker/KTreePicker.global.vue.d.ts +7 -9
- package/dist/runtime/components/KTreeView/KTreeView.global.d.vue.ts +39 -5
- package/dist/runtime/components/KTreeView/KTreeView.global.vue +19 -1
- package/dist/runtime/components/KTreeView/KTreeView.global.vue.d.ts +39 -5
- package/dist/runtime/components/KTreeView/KTreeView.logic.d.ts +23 -3
- package/dist/runtime/components/KTreeView/KTreeView.logic.js +76 -6
- package/dist/runtime/composables/locales.js +204 -25
- package/dist/runtime/composables/useDataProvider.d.ts +5 -3
- package/dist/runtime/composables/useDataProvider.js +36 -25
- package/dist/runtime/composables/useFilterLogic.d.ts +16 -4
- package/dist/runtime/composables/useFilterLogic.js +10 -2
- package/dist/runtime/composables/useKatluxForm.d.ts +4 -4
- package/dist/runtime/composables/useKatluxForm.js +6 -4
- package/dist/runtime/composables/useSortLogic.d.ts +1 -1
- package/dist/runtime/composables/useVirtualDataset.d.ts +121 -0
- package/dist/runtime/composables/useVirtualDataset.js +689 -0
- package/dist/runtime/composables/useVirtualScroll.d.ts +8 -4
- package/dist/runtime/composables/useVirtualScroll.js +29 -9
- package/dist/runtime/plugins/nuxtCompatPlugin.js +9 -1
- package/dist/runtime/presets/default/assets/scss/css-variables.css +3 -0
- package/dist/runtime/presets/default/assets/scss/css-variables.scss +6 -1
- package/dist/runtime/presets/default/assets/scss/index.css +3 -0
- package/dist/runtime/presets/default/assets/svg/katlux-logo.svg +7 -0
- package/dist/runtime/presets/default/assets/svg/katlux.svg +6 -0
- package/dist/runtime/presets/default/components/KBulkActions/KBulkActions.d.vue.ts +3 -2
- package/dist/runtime/presets/default/components/KBulkActions/KBulkActions.vue +31 -3
- package/dist/runtime/presets/default/components/KBulkActions/KBulkActions.vue.d.ts +3 -2
- package/dist/runtime/presets/default/components/KCalendar/KCalendar.d.vue.ts +3 -0
- package/dist/runtime/presets/default/components/KCalendar/KCalendar.vue +6 -0
- package/dist/runtime/presets/default/components/KCalendar/KCalendar.vue.d.ts +3 -0
- package/dist/runtime/presets/default/components/KCalendar/KCalendarMonth.d.vue.ts +5 -0
- package/dist/runtime/presets/default/components/KCalendar/KCalendarMonth.vue +33 -2
- package/dist/runtime/presets/default/components/KCalendar/KCalendarMonth.vue.d.ts +5 -0
- package/dist/runtime/presets/default/components/KCheckbox/KCheckbox.d.vue.ts +2 -2
- package/dist/runtime/presets/default/components/KCheckbox/KCheckbox.vue.d.ts +2 -2
- package/dist/runtime/presets/default/components/KContextMenu/KContextMenu.vue +7 -1
- package/dist/runtime/presets/default/components/KDataIterator/KDataIterator.d.vue.ts +30 -8
- package/dist/runtime/presets/default/components/KDataIterator/KDataIterator.vue +80 -164
- package/dist/runtime/presets/default/components/KDataIterator/KDataIterator.vue.d.ts +30 -8
- package/dist/runtime/presets/default/components/KDatatable/KDatatable.d.vue.ts +16 -9
- package/dist/runtime/presets/default/components/KDatatable/KDatatable.vue +99 -394
- package/dist/runtime/presets/default/components/KDatatable/KDatatable.vue.d.ts +16 -9
- package/dist/runtime/presets/default/components/KDatePicker/KDatePicker.d.vue.ts +6 -0
- package/dist/runtime/presets/default/components/KDatePicker/KDatePicker.vue +71 -4
- package/dist/runtime/presets/default/components/KDatePicker/KDatePicker.vue.d.ts +6 -0
- package/dist/runtime/presets/default/components/KGantt/KGantt.d.vue.ts +11 -12
- package/dist/runtime/presets/default/components/KGantt/KGantt.vue +77 -14
- package/dist/runtime/presets/default/components/KGantt/KGantt.vue.d.ts +11 -12
- package/dist/runtime/presets/default/components/KGantt/KGanttTimeline.vue +1 -0
- package/dist/runtime/presets/default/components/KToast/KToast.d.vue.ts +2 -2
- package/dist/runtime/presets/default/components/KToast/KToast.vue.d.ts +2 -2
- package/dist/runtime/presets/default/components/KTree/KTree.d.vue.ts +4 -4
- package/dist/runtime/presets/default/components/KTree/KTree.vue +48 -14
- package/dist/runtime/presets/default/components/KTree/KTree.vue.d.ts +4 -4
- package/dist/runtime/presets/default/components/KTreeView/KTreeView.d.vue.ts +11 -2
- package/dist/runtime/presets/default/components/KTreeView/KTreeView.vue +14 -2
- package/dist/runtime/presets/default/components/KTreeView/KTreeView.vue.d.ts +11 -2
- package/dist/skills/KATLUX_INDEX.md +9 -6
- package/dist/skills/katlux-components/SKILL.md +2 -0
- package/dist/skills/katlux-components/components/KBulkActions.md +25 -1
- package/dist/skills/katlux-components/components/KCombobox.md +2 -2
- package/dist/skills/katlux-components/components/KDataIterator.md +12 -4
- package/dist/skills/katlux-components/components/KDatatable.md +38 -0
- package/dist/skills/katlux-components/components/KDatePicker.md +3 -1
- package/dist/skills/katlux-components/components/KGantt.md +9 -0
- package/dist/skills/katlux-components/components/KIcon.md +1 -1
- package/dist/skills/katlux-components/components/KLineChart.md +3 -0
- package/dist/skills/katlux-components/components/KProductList.md +0 -1
- package/dist/skills/katlux-components/components/KScatterChart.md +3 -0
- package/dist/skills/katlux-components/components/KTreePicker.md +2 -1
- package/dist/skills/katlux-components/components/KTreeView.md +12 -0
- package/dist/skills/katlux-config/SKILL.md +19 -8
- package/dist/skills/katlux-presets/SKILL.md +121 -1
- package/dist/skills/katlux-presets/creating-a-preset.md +67 -0
- package/dist/skills/katlux-providers/SKILL.md +7 -5
- package/dist/skills/katlux-providers/providers/ADataProvider.md +16 -9
- package/dist/skills/katlux-providers/providers/CAPIFlatClientDataProvider.md +27 -3
- package/dist/skills/katlux-providers/providers/CAPIFlatServerDataProvider.md +11 -1
- package/dist/skills/katlux-providers/providers/CFlatClientDataProvider.md +19 -4
- package/dist/skills/katlux-providers/providers/CFlatServerDataProvider.md +4 -2
- package/dist/skills/katlux-providers/providers/CTreeClientDataProvider.md +2 -2
- package/dist/skills/katlux-providers/providers/RequestProvider.md +10 -0
- package/dist/skills/katlux-providers/providers/encryption-field-level.md +63 -19
- package/dist/skills/katlux-providers/providers/encryption-key-management.md +20 -2
- package/dist/skills/katlux-providers/providers/encryption-key-pinning.md +25 -11
- package/dist/skills/katlux-providers/providers/encryption-searchable.md +218 -0
- package/dist/skills/katlux-providers/providers/encryption-symmetric.md +25 -1
- package/dist/skills/katlux-providers/providers/encryption-threat-model.md +63 -0
- package/dist/skills/katlux-providers/providers/encryption.md +26 -1
- package/dist/skills/katlux-providers/providers/types.md +3 -1
- package/dist/skills/katlux-providers/providers/useDataProvider.md +2 -1
- package/dist/skills/katlux-providers/providers/useVirtualDataset.md +154 -0
- package/dist/skills/katlux-tokens/SKILL.md +2 -1
- package/dist/types.d.mts +1 -1
- package/package.json +9 -3
- package/bin/add-ai-reference.mjs +0 -259
|
@@ -179,7 +179,127 @@ defineProps<{
|
|
|
179
179
|
```
|
|
180
180
|
|
|
181
181
|
> [!NOTE]
|
|
182
|
-
> Custom preset component files are **case-sensitive**. The folder name and file name must exactly match the component name (e.g., `KButton/KButton.vue`). Component-level props come from the internal logic layer
|
|
182
|
+
> Custom preset component files are **case-sensitive**. The folder name and file name must exactly match the component name (e.g., `KButton/KButton.vue`). Component-level props come from the internal logic layer (`templateProps`).
|
|
183
|
+
|
|
184
|
+
### Scaffolding a Preset Component Override (MCP Tool: `katlux_scaffold_preset_component`)
|
|
185
|
+
|
|
186
|
+
Instead of manually inspecting canonical source code, AI agents scaffold compile-safe atomic preset component templates with exact typed contracts via the MCP server:
|
|
187
|
+
|
|
188
|
+
```json
|
|
189
|
+
{
|
|
190
|
+
"component": "KButton",
|
|
191
|
+
"presetName": "my-brand",
|
|
192
|
+
"density": "minimal",
|
|
193
|
+
"format": "pug",
|
|
194
|
+
"writeToDisk": true
|
|
195
|
+
}
|
|
196
|
+
```
|
|
197
|
+
*Features:*
|
|
198
|
+
- **Self-contained**: Bundled inside `@katlux/mcp` with zero dependency on `node_modules` or monorepo files.
|
|
199
|
+
- **In-Memory or Disk Writes**: Set `writeToDisk: false` to return the code directly to chat for design customization, or `writeToDisk: true` to scaffold to `presets/<preset>/components/<Component>/<Component>.vue`.
|
|
200
|
+
- **Non-destructive collision guard**: Skips writing if target file already exists on disk.
|
|
201
|
+
- **Contract accuracy**: Guaranteed prop and event contracts matching Katlux's two-tier architecture.
|
|
202
|
+
- **Atomic scaffolding**: Scaffolds strictly one component at a time to preserve the Zero-Copy Cascade.
|
|
203
|
+
|
|
204
|
+
---
|
|
205
|
+
|
|
206
|
+
### Overriding Data Components in Presets (`KDatatable`, `KDataIterator`)
|
|
207
|
+
|
|
208
|
+
> [!IMPORTANT]
|
|
209
|
+
> **Data Component Architecture Rule for AI Agents & Developers**:
|
|
210
|
+
> When creating or overriding data-driven components in a preset (`KDatatable`, `KDataIterator`, or custom virtual tables/grids):
|
|
211
|
+
> 1. **Never copy-paste raw virtual scrolling math, row caches, or slice queue algorithms** into the preset component.
|
|
212
|
+
> 2. **Always consume `useVirtualDataset`** from `#toolkit/composables/useVirtualDataset`.
|
|
213
|
+
> 3. The preset component is strictly responsible for **DOM markup, CSS variables, slot rendering, and ARIA attributes**. All data provider bridging, windowing, and selection are handled by `useVirtualDataset`.
|
|
214
|
+
|
|
215
|
+
#### Canonical Data Component Recipe (`KDatatable.vue` in a Preset)
|
|
216
|
+
|
|
217
|
+
```vue
|
|
218
|
+
<template lang="pug">
|
|
219
|
+
.k-datatable(
|
|
220
|
+
:ref="tableContainerRef"
|
|
221
|
+
@scroll="virtual.onScroll"
|
|
222
|
+
:style="{ maxHeight: `${viewportHeight}px`, overflowY: 'auto' }"
|
|
223
|
+
)
|
|
224
|
+
table
|
|
225
|
+
thead
|
|
226
|
+
tr
|
|
227
|
+
th(v-if="multiSelect")
|
|
228
|
+
KCheckbox(:modelValue="virtual.selectAll.value" @update:modelValue="virtual.toggleSelectAll")
|
|
229
|
+
th(v-for="field in activeFields" :key="field" @click="handleSort(field)")
|
|
230
|
+
slot(:name="`header-${field}`" :field="field")
|
|
231
|
+
| {{ columnHeaders?.[field] || field }}
|
|
232
|
+
tbody
|
|
233
|
+
// 1. Top Spacer: Maintains proportional scrollbar height
|
|
234
|
+
tr.spacer-top(v-if="virtualScroll && virtual.topSpacerHeight.value > 0")
|
|
235
|
+
td(:colspan="colSpan" :style="{ height: `${virtual.topSpacerHeight.value}px`, padding: 0 }")
|
|
236
|
+
|
|
237
|
+
// 2. Visible Window Rows
|
|
238
|
+
tr(
|
|
239
|
+
v-for="(row, idx) in virtual.visibleRows.value"
|
|
240
|
+
:key="row[idKey] || (virtual.startIndex.value + idx)"
|
|
241
|
+
:class="{ 'is-selected': virtual.isRowSelected(row) }"
|
|
242
|
+
)
|
|
243
|
+
td(v-if="multiSelect")
|
|
244
|
+
KCheckbox(:modelValue="virtual.isRowSelected(row)" @update:modelValue="virtual.toggleSelection(row)")
|
|
245
|
+
td(v-for="field in activeFields" :key="field")
|
|
246
|
+
slot(:name="`cell-${field}`" :row="row" :value="row[field]")
|
|
247
|
+
| {{ row[field] }}
|
|
248
|
+
|
|
249
|
+
// 3. Bottom Spacer: Maintains proportional scrollbar height
|
|
250
|
+
tr.spacer-bottom(v-if="virtualScroll && virtual.bottomSpacerHeight.value > 0")
|
|
251
|
+
td(:colspan="colSpan" :style="{ height: `${virtual.bottomSpacerHeight.value}px`, padding: 0 }")
|
|
252
|
+
</template>
|
|
253
|
+
|
|
254
|
+
<script setup lang="ts">
|
|
255
|
+
import { ref, computed } from 'vue'
|
|
256
|
+
import { useVirtualDataset } from '#toolkit/composables/useVirtualDataset'
|
|
257
|
+
|
|
258
|
+
const props = withDefaults(defineProps<{
|
|
259
|
+
dataProvider?: any
|
|
260
|
+
items?: any[]
|
|
261
|
+
visibleFields?: string[] | null
|
|
262
|
+
columnHeaders?: Record<string, string>
|
|
263
|
+
virtualScroll?: boolean
|
|
264
|
+
itemHeight?: number
|
|
265
|
+
viewportHeight?: number
|
|
266
|
+
multiSelect?: boolean
|
|
267
|
+
idKey?: string
|
|
268
|
+
}>(), {
|
|
269
|
+
virtualScroll: true,
|
|
270
|
+
itemHeight: 40,
|
|
271
|
+
viewportHeight: 500,
|
|
272
|
+
multiSelect: false,
|
|
273
|
+
idKey: 'id'
|
|
274
|
+
})
|
|
275
|
+
|
|
276
|
+
const tableContainerRef = ref<HTMLElement | null>(null)
|
|
277
|
+
|
|
278
|
+
// Centralized virtual dataset bridge handles viewport, cache, encryption, and selection:
|
|
279
|
+
const virtual = useVirtualDataset({
|
|
280
|
+
provider: () => props.dataProvider,
|
|
281
|
+
items: () => props.items,
|
|
282
|
+
itemHeight: () => props.itemHeight,
|
|
283
|
+
viewportHeight: () => props.viewportHeight,
|
|
284
|
+
virtualScroll: () => props.virtualScroll,
|
|
285
|
+
scrollContainerRef: tableContainerRef,
|
|
286
|
+
idKey: props.idKey
|
|
287
|
+
})
|
|
288
|
+
|
|
289
|
+
const colSpan = computed(() => (props.visibleFields?.length || 1) + (props.multiSelect ? 1 : 0))
|
|
290
|
+
</script>
|
|
291
|
+
|
|
292
|
+
<style lang="scss" scoped>
|
|
293
|
+
.k-datatable {
|
|
294
|
+
width: 100%;
|
|
295
|
+
border-collapse: collapse;
|
|
296
|
+
th, td {
|
|
297
|
+
padding: var(--gap-sm) var(--gap-md);
|
|
298
|
+
border-bottom: 1px solid var(--border-color-light);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
</style>
|
|
302
|
+
```
|
|
183
303
|
|
|
184
304
|
---
|
|
185
305
|
|
|
@@ -160,6 +160,73 @@ withDefaults(defineProps<ButtonProps>(), {
|
|
|
160
160
|
</style>
|
|
161
161
|
```
|
|
162
162
|
|
|
163
|
+
### Overriding Data Components (`KDatatable`, `KDataIterator`)
|
|
164
|
+
When overriding a data-intensive component like `KDatatable` in your preset, **never copy-paste virtual scroll math, page slice queuing, or row caching**. Use the `@katlux/toolkit` composable `useVirtualDataset`:
|
|
165
|
+
|
|
166
|
+
```vue
|
|
167
|
+
<!-- presets/my-brand/components/KDatatable/KDatatable.vue -->
|
|
168
|
+
<template lang="pug">
|
|
169
|
+
.KDatatable.my-brand-datatable(:ref="containerRef" @scroll="virtual.onScroll" :style="{ maxHeight: `${viewportHeight}px`, overflowY: 'auto' }")
|
|
170
|
+
table
|
|
171
|
+
thead
|
|
172
|
+
tr
|
|
173
|
+
th(v-if="multiSelect")
|
|
174
|
+
KCheckbox(:modelValue="virtual.selectAll.value" @update:modelValue="virtual.toggleSelectAll")
|
|
175
|
+
th(v-for="field in activeFields" :key="field")
|
|
176
|
+
slot(:name="`header-${field}`" :field="field") {{ columnHeaders?.[field] || field }}
|
|
177
|
+
tbody
|
|
178
|
+
tr.spacer-top(v-if="virtualScroll && virtual.topSpacerHeight.value > 0")
|
|
179
|
+
td(:colspan="colSpan" :style="{ height: `${virtual.topSpacerHeight.value}px`, padding: 0 }")
|
|
180
|
+
tr(
|
|
181
|
+
v-for="(row, idx) in virtual.visibleRows.value"
|
|
182
|
+
:key="row[idKey] || (virtual.startIndex.value + idx)"
|
|
183
|
+
:class="{ 'is-selected': virtual.isRowSelected(row) }"
|
|
184
|
+
)
|
|
185
|
+
td(v-if="multiSelect")
|
|
186
|
+
KCheckbox(:modelValue="virtual.isRowSelected(row)" @update:modelValue="virtual.toggleSelection(row)")
|
|
187
|
+
td(v-for="field in activeFields" :key="field")
|
|
188
|
+
slot(:name="`cell-${field}`" :row="row" :value="row[field]") {{ row[field] }}
|
|
189
|
+
tr.spacer-bottom(v-if="virtualScroll && virtual.bottomSpacerHeight.value > 0")
|
|
190
|
+
td(:colspan="colSpan" :style="{ height: `${virtual.bottomSpacerHeight.value}px`, padding: 0 }")
|
|
191
|
+
</template>
|
|
192
|
+
|
|
193
|
+
<script setup lang="ts">
|
|
194
|
+
import { ref, computed } from 'vue'
|
|
195
|
+
import { useVirtualDataset } from '#toolkit/composables/useVirtualDataset'
|
|
196
|
+
|
|
197
|
+
const props = withDefaults(defineProps<{
|
|
198
|
+
dataProvider?: any
|
|
199
|
+
items?: any[]
|
|
200
|
+
visibleFields?: string[] | null
|
|
201
|
+
columnHeaders?: Record<string, string>
|
|
202
|
+
virtualScroll?: boolean
|
|
203
|
+
itemHeight?: number
|
|
204
|
+
viewportHeight?: number
|
|
205
|
+
multiSelect?: boolean
|
|
206
|
+
idKey?: string
|
|
207
|
+
}>(), {
|
|
208
|
+
virtualScroll: true,
|
|
209
|
+
itemHeight: 40,
|
|
210
|
+
viewportHeight: 500,
|
|
211
|
+
multiSelect: false,
|
|
212
|
+
idKey: 'id'
|
|
213
|
+
})
|
|
214
|
+
|
|
215
|
+
const containerRef = ref<HTMLElement | null>(null)
|
|
216
|
+
const virtual = useVirtualDataset({
|
|
217
|
+
provider: () => props.dataProvider,
|
|
218
|
+
items: () => props.items,
|
|
219
|
+
itemHeight: () => props.itemHeight,
|
|
220
|
+
viewportHeight: () => props.viewportHeight,
|
|
221
|
+
virtualScroll: () => props.virtualScroll,
|
|
222
|
+
scrollContainerRef: containerRef,
|
|
223
|
+
idKey: props.idKey
|
|
224
|
+
})
|
|
225
|
+
|
|
226
|
+
const colSpan = computed(() => (props.visibleFields?.length || 1) + (props.multiSelect ? 1 : 0))
|
|
227
|
+
</script>
|
|
228
|
+
```
|
|
229
|
+
|
|
163
230
|
---
|
|
164
231
|
|
|
165
232
|
## 6. Step 3: Registering & Activating the Preset (`app.config.ts`)
|
|
@@ -16,17 +16,19 @@ description: Complete reference and atomic index for Katlux data management arch
|
|
|
16
16
|
| `ADataProvider` | Core abstract base class | Foundation for all providers. Constructor options, native state properties, observer events, URL serialization | [ADataProvider.md](providers/ADataProvider.md) |
|
|
17
17
|
| Core Types & Interfaces | Standard interfaces and enums | `IDataResult`, `IDataFilter`, `IDataSort`, `ECacheStrategy`, filter operators | [types.md](providers/types.md) |
|
|
18
18
|
| `useDataProvider` | Vue 3 reactivity bridge composable | Binds native `ADataProvider` to Vue refs (`pageData`, `loading`, `rowCount`), Pinia store sync, SSR cleanup | [useDataProvider.md](providers/useDataProvider.md) |
|
|
19
|
+
| `useVirtualDataset` | Virtual dataset & windowing bridge | Combines `useDataProvider` and `useVirtualScroll`, row delivery cache, encryption retention, page queue, selection | [useVirtualDataset.md](providers/useVirtualDataset.md) |
|
|
19
20
|
| React 18+ Integration | React integration guide | `useSyncExternalStore` binding for zero-overhead React 18+ concurrent rendering | [react-integration.md](providers/react-integration.md) |
|
|
20
21
|
|
|
21
22
|
---
|
|
22
23
|
|
|
23
24
|
## 2. Client-Side Data Providers
|
|
24
25
|
|
|
25
|
-
| Class | Description | Caching / Performance | Spec Link |
|
|
26
|
+
| Class | Description | Caching / Performance / Batching | Spec Link |
|
|
26
27
|
| :--- | :--- | :--- | :--- |
|
|
27
|
-
| `CFlatClientDataProvider` | In-memory client data engine | Instant sorting, complex AST filtering, local pagination for preloaded arrays | [CFlatClientDataProvider.md](providers/CFlatClientDataProvider.md) |
|
|
28
|
-
| `CTreeClientDataProvider` | Hierarchical client tree engine | Parent-child relationship management, recursive expansion, tree filtering | [CTreeClientDataProvider.md](providers/CTreeClientDataProvider.md) |
|
|
29
|
-
| `CAPIFlatClientDataProvider` | Remote fetch with client-side ops | Fetches dataset from API once, then performs all filtering/sorting locally | [CAPIFlatClientDataProvider.md](providers/CAPIFlatClientDataProvider.md) |
|
|
28
|
+
| `CFlatClientDataProvider` | In-memory client data engine | Instant sorting, complex AST filtering, local pagination for preloaded arrays. Progressive chunked ingestion via `batchSize`. | [CFlatClientDataProvider.md](providers/CFlatClientDataProvider.md) |
|
|
29
|
+
| `CTreeClientDataProvider` | Hierarchical client tree engine | Parent-child relationship management, recursive expansion, tree filtering. Progressive chunked tree ingestion via `batchSize`. | [CTreeClientDataProvider.md](providers/CTreeClientDataProvider.md) |
|
|
30
|
+
| `CAPIFlatClientDataProvider` | Remote fetch with client-side ops | Fetches dataset from API once, then performs all filtering/sorting locally. Supports sequential background batch ingestion (`batchSize`, `batchLoad: 'initially' \| 'onDemand'`). | [CAPIFlatClientDataProvider.md](providers/CAPIFlatClientDataProvider.md) |
|
|
31
|
+
| `CAPITreeClientDataProvider` | Remote hierarchical tree client provider | Fetches hierarchical data with client-side tree traversal, local filtering, and incremental batch ingestion (`batchSize`). | [CAPIFlatClientDataProvider.md](providers/CAPIFlatClientDataProvider.md) |
|
|
30
32
|
|
|
31
33
|
---
|
|
32
34
|
|
|
@@ -50,7 +52,7 @@ description: Complete reference and atomic index for Katlux data management arch
|
|
|
50
52
|
| `RequestQueue` | Offline PWA operation queue | Queues mutations offline in IndexedDB, auto-flushes on reconnect | [RequestQueue.md](providers/RequestQueue.md) |
|
|
51
53
|
| `KatluxIndexedDB` | High-performance IndexedDB wrapper | Client-side persistent storage for offline data and large cache entries | [KatluxIndexedDB.md](providers/KatluxIndexedDB.md) |
|
|
52
54
|
| `CacheProvider` | Tiered multi-layer caching engine | Memory, BrowserSession, LocalStorage, IndexedDB, Cookie tiers | [caching.md](providers/caching.md) |
|
|
53
|
-
| `EncryptionProvider` & `CKeyManager` | WebCrypto & NodeCrypto cryptographic suite | AES-GCM, asymmetric hybrid, ADEK re-wrapping, RFC 8785 grants, domain KDF, TOFU pinning, streaming AEAD, blind indexing | [encryption.md](providers/encryption.md) (Index: [threat-model](providers/encryption-threat-model.md) · [symmetric](providers/encryption-symmetric.md) · [asymmetric](providers/encryption-asymmetric.md) · [key-mgmt](providers/encryption-key-management.md) · [key-pinning](providers/encryption-key-pinning.md) · [streaming](providers/encryption-streaming.md) · [field-level](providers/encryption-field-level.md)) |
|
|
55
|
+
| `EncryptionProvider` & `CKeyManager` | WebCrypto & NodeCrypto cryptographic suite | AES-GCM, asymmetric hybrid, ADEK re-wrapping, RFC 8785 grants, domain KDF, TOFU pinning, streaming AEAD, blind indexing | [encryption.md](providers/encryption.md) (Index: [threat-model](providers/encryption-threat-model.md) · [symmetric](providers/encryption-symmetric.md) · [asymmetric](providers/encryption-asymmetric.md) · [key-mgmt](providers/encryption-key-management.md) · [key-pinning](providers/encryption-key-pinning.md) · [streaming](providers/encryption-streaming.md) · [field-level](providers/encryption-field-level.md) · [searchable](providers/encryption-searchable.md)) |
|
|
54
56
|
|
|
55
57
|
---
|
|
56
58
|
|
|
@@ -15,10 +15,9 @@
|
|
|
15
15
|
| --- | --- | --- | --- |
|
|
16
16
|
| `filter` | `IDataFilter` | `null` | Initial filter configuration |
|
|
17
17
|
| `sortList` | `IDataSort[]` | `[]` | Initial sort configuration |
|
|
18
|
-
| `pageSize` | `number` | `10` | Items per page |
|
|
18
|
+
| `pageSize` | `number` | `10` | Items per page. Set `<= 0` for unpaged mode. |
|
|
19
19
|
| `currentPage` | `number` | `1` | Starting page |
|
|
20
20
|
| `SSR` | `boolean` | `false` | Server-side rendering flag |
|
|
21
|
-
| `urlPageParam` | `string` | `undefined` | URL query key for page sync (e.g. `'p'`) |
|
|
22
21
|
| `cacheStrategy` | `ECacheStrategy` | `undefined` | Persistence engine |
|
|
23
22
|
| `cacheLifetime` | `number` | `undefined` | Cache expiration in milliseconds |
|
|
24
23
|
| `filterDebounce` | `number` | `300` | Debounce time in ms for `setFilter` |
|
|
@@ -36,21 +35,29 @@
|
|
|
36
35
|
- **`pageSize`**: `number` - Items per page.
|
|
37
36
|
- **`filter`**: `IDataFilter | null` - Active filter configuration.
|
|
38
37
|
- **`sortList`**: `IDataSort[]` - Active multi-column sort array.
|
|
39
|
-
- **`
|
|
38
|
+
- **`stateVersion`**: `number` - Monotonically increasing version counter incremented on every `notify()` or mutation.
|
|
40
39
|
- **`SSR`**: `boolean` - Server-side rendering flag.
|
|
41
40
|
|
|
42
|
-
> **Architecture Note (Headless Data Layer
|
|
41
|
+
> **Architecture Note (Headless Data Layer & Client/Server Parity)**:
|
|
42
|
+
> - **Zero Selection Crosstalk**: Selection state (`selectedRows`, `selectAll`, `selectAllScope`, `unselectedRows`) is transient UI state owned exclusively by presentation components like `KDatatable`. DataProviders remain pure headless data engines (fetching, caching, sorting, filtering, pagination) with zero selection state, ensuring multiple components (e.g. Datatable + Combobox) can safely share the same provider without cross-component selection collisions.
|
|
43
|
+
> - **Unified Contract Across Client & Server**: DataProvider semantics are identical whether using a client-side provider (`CFlatClientDataProvider`) or server-side provider (`CAPIFlatServerDataProvider`). In dataset-scope selection and virtual scrolling, `selectedRows` is passed as `[]` because massive datasets cannot be enumerated in client memory. Handlers must inspect `isAllSelected` and `filter` to perform dataset/query-level operations. DataProviders do not fabricate artificial DOM viewport slices.
|
|
43
44
|
|
|
44
45
|
### Methods
|
|
45
46
|
- **`setFilter(filter: IDataFilter | null, immediate: boolean = false)`**: Updates filter and resets to page 1. Set `immediate: true` to bypass the 300ms debounce.
|
|
46
47
|
- **`setSortList(sort: IDataSort[], immediate: boolean = false)`**: Updates sorting and resets to page 1.
|
|
47
|
-
- **`setCurrentPage(page: number)
|
|
48
|
-
- **`setPageSize(size: number)
|
|
48
|
+
- **`setCurrentPage(page: number): Promise<void>`**: Direct page navigation. Returns a Promise resolving only after network/provider data has loaded and processed.
|
|
49
|
+
- **`setPageSize(size: number): Promise<void>`**: Updates items per page; resets to page 1 and awaits data loading.
|
|
50
|
+
- **`prevPage(): Promise<void>`**: Navigates to previous page and awaits data loading.
|
|
51
|
+
- **`nextPage(): Promise<void>`**: Navigates to next page and awaits data loading.
|
|
52
|
+
- **`batchUpdates<R>(fn: () => R): R`**: Batches multiple state updates or mutations so that `notify()` and subscriber events fire exactly once upon completion rather than on every state change. Supports nested calls and asynchronous handlers.
|
|
49
53
|
- **`loadPageData(options?)`**: (Abstract) Core logic for data retrieval. Supports `{ disableCache: true }` to force a fresh fetch.
|
|
50
54
|
- **`refresh(hardRefresh?: boolean)`**: Re-runs the last request and reloads data. Cache will only be overridden if `hardRefresh` is true.
|
|
51
|
-
- **`subscribe(listener: (
|
|
52
|
-
- **`notify()`**: Dispatches current state to all active subscribers
|
|
53
|
-
- **`
|
|
55
|
+
- **`subscribe(listener: (provider) => void): () => void`**: Subscribes a listener to provider state updates. Returns an unsubscribe function.
|
|
56
|
+
- **`notify()`**: Dispatches current state to all active subscribers and increments `stateVersion`.
|
|
57
|
+
- **`onSortChanged(listener: (sortList: IDataSort[]) => void): () => void`**: Subscribes specifically to sort changes.
|
|
58
|
+
- **`onFilterChanged(listener: (filter: IDataFilter | null) => void): () => void`**: Subscribes specifically to filter changes.
|
|
59
|
+
- **`onDataChanged(listener: (pageData: T[]) => void): () => void`**: Subscribes specifically to page data changes.
|
|
60
|
+
- **`getState(): IDataProviderState<T>`**: Returns an immutable snapshot object of current state (`currentPage`, `pageSize`, `filter`, `sortList`, `stateVersion`).
|
|
54
61
|
- **`setState(partial: Partial<IDataProviderState<T>>, options?: IDataProviderSetStateOptions): void`**: Atomically updates provider state. Supports `{ silent: true }` to avoid auto-triggering data loads.
|
|
55
62
|
- **`onStateChange(listener: TDataProviderStateChangeListener<T>): () => void`**: Subscribes specifically to state change events, providing an array of changed keys. Returns unsubscribe function.
|
|
56
63
|
- **`serializeState(): string`**: Serializes active pagination, filters, and sorts to a URL query string (e.g. `page=2&pageSize=25`).
|
|
@@ -1,12 +1,36 @@
|
|
|
1
1
|
### `CAPIFlatClientDataProvider` / `CAPITreeClientDataProvider`
|
|
2
2
|
Specialized versions that fetch a dataset **once** from an API and then manage it locally as flat or tree data.
|
|
3
|
-
- **Purpose**: Ideal for
|
|
3
|
+
- **Purpose**: Ideal for datasets that need local filtering/sorting after an initial fetch.
|
|
4
|
+
- **Batch Ingestion (`batchSize: number | false`)**:
|
|
5
|
+
- When `batchSize: false` (default), fetches the entire dataset in a single request (`pageSize: 0` or standard endpoint).
|
|
6
|
+
- When `batchSize: number` (e.g. `50`), fetches data using standard server-side pagination query parameters (`pageNumber: 1, 2, ...`, `pageSize: batchSize`), expecting standard `IDataResult<TRow>` (`{ rowCount: number, rows: TRow[] }`).
|
|
7
|
+
- **Fast UI Readiness**: Batch 1 is displayed immediately (`loading` turns `false`), allowing immediate user interaction.
|
|
8
|
+
- **Batch Loading Strategies (`batchLoad`)**:
|
|
9
|
+
- `'initially'` (default): Sequentially streams remaining batches in the background while `isBatchLoading` is `true`. Each batch accumulates into `allData`, updates `batchProgress`, and triggers `onBatchLoaded(event)`.
|
|
10
|
+
- `'onDemand'`: Loads only Batch 1 on initial fetch, setting `rowCount` from `result.rowCount` and registering batch 1 in `loadedBatches`. Defers subsequent batch requests until user interaction requires records outside loaded memory (pagination navigation, virtual scroll viewport shifts, or explicit calls to `loadBatch` / `ensureRangeLoaded`).
|
|
11
|
+
- **On-Demand Buffer Management**:
|
|
12
|
+
- `loadedBatches: Set<number>`: Registry tracking all currently ingested batch indices.
|
|
13
|
+
- Splicing: On-demand batches are spliced directly into `allData` at `(batchNumber - 1) * batchSize`, maintaining an efficient sparse data buffer.
|
|
14
|
+
- Viewport & Pagination Triggers: Navigating to page $P$ via `setCurrentPage(P)` computes record range $[(P - 1) \cdot \text{pageSize}, P \cdot \text{pageSize}]$ and lazily queries any missing batches covering that range.
|
|
15
|
+
- Virtual Scrolling: Window shifts invoke `ensureRangeLoaded(startIndex, endIndex)` to lazily fetch missing batch ranges.
|
|
16
|
+
- In-Flight Deduplication: Simultaneous requests for the same batch are deduplicated into a shared single Promise.
|
|
17
|
+
- **Filter & Sort Invalidation Strategy (`onDemandFilterPolicy`)**:
|
|
18
|
+
- `'ingestAll'` (default): When a client-side filter or sort is applied while only a subset of batches are loaded, automatically streams all remaining batches in the background to guarantee 100% accurate client-side evaluation across the full dataset.
|
|
19
|
+
- `'warnOnly'`: Issues a development warning and sorts/filters only the records currently in memory without issuing remote requests.
|
|
20
|
+
- **Generation Tracking**: Switching URLs via `setAPIUrl()` or triggering `refresh()` increments the generation token, immediately aborting any active background batch stream to prevent race conditions or stale data contamination.
|
|
4
21
|
- **Methods**:
|
|
5
22
|
| Method | Params | Description |
|
|
6
23
|
| --- | --- | --- |
|
|
7
24
|
| `setAPIUrl(url)` | `string` | Sets endpoint and triggers initial fetch |
|
|
8
|
-
| `
|
|
9
|
-
| `
|
|
25
|
+
| `loadMore()` | None | Progressively fetches and accumulates the next page into `allData` with deduplication |
|
|
26
|
+
| `refresh(hardRefresh?)`| `boolean` | Manually refetch the entire dataset. Cache will only be overridden if `hardRefresh` parameter is true. Resets batch registry. |
|
|
27
|
+
| `loadBatch(batchNumber)` | `number` | On-demand fetch of a specific batch index; splices into `allData`. |
|
|
28
|
+
| `ensureRangeLoaded(start, end)` | `number, number` | Ensures all batches covering index range `[start, end)` are loaded. |
|
|
29
|
+
| `loadRange(start, end)` | `number, number` | Alias for `ensureRangeLoaded`. |
|
|
30
|
+
| `ingestAllBatches()` | None | Sequentially fetches all missing on-demand batches. |
|
|
31
|
+
| `setCurrentPage(page)` | `number` | Navigates to page, fetching missing on-demand batches if required before page slice render. |
|
|
32
|
+
| `setFilter(filter, immediate?)` | `IDataFilter \| null, boolean?` | Applies a structured filter. When in on-demand mode with unloaded batches, executes `onDemandFilterPolicy`. |
|
|
33
|
+
| `setSortList(sortList, immediate?)` | `IDataSort[], boolean?` | Applies client-side sorting. When in on-demand mode with unloaded batches, executes `onDemandFilterPolicy`. |
|
|
10
34
|
| `create(item)` | `TRow` | POST to API and update local state |
|
|
11
35
|
| `update(item)` | `TRow` | PUT to API and update local item |
|
|
12
36
|
| `delete(items)` | `TRow[]` | DELETE from API and remove locally |
|
|
@@ -16,9 +16,11 @@ Handle full API integration with automatic query generation. Pagination, filteri
|
|
|
16
16
|
| --- | --- | --- |
|
|
17
17
|
| `refresh(hardRefresh?)`| `boolean` | Manual trigger for reload. Cache will only be overridden if `hardRefresh` parameter is true. |
|
|
18
18
|
| `loadPageData(opts)` | `{ disableCache?: boolean }` | Core logic for data retrieval |
|
|
19
|
+
| `fetchAll(opts?)` | `{ disableCache?: boolean; signal?: AbortSignal }` | Fetches unpaginated dataset (`pageSize: 0`) into `_allData` without altering active `pageSize` |
|
|
19
20
|
| `create(item)` | `TRow` | Async POST request to creation endpoint |
|
|
20
21
|
| `update(item)` | `TRow` | Async PUT request to update endpoint |
|
|
21
22
|
| `delete(items)` | `TRow[]` | Async batch deletion via endpoint |
|
|
23
|
+
| `batchUpdates(fn)` | `() => R` | Inherited from `ADataProvider`. Groups multiple mutations or state changes so `notify()` fires once. |
|
|
22
24
|
|
|
23
25
|
#### Server-Side Encrypted Datatable & Search Integration
|
|
24
26
|
When querying backend persistence endpoints (e.g. server-side datatable backends or Cloudflare stateless edge workers) that store and return encrypted records:
|
|
@@ -28,7 +30,8 @@ const provider = new CAPIFlatServerDataProvider({
|
|
|
28
30
|
cacheStrategy: ECacheStrategy.IndexedDB,
|
|
29
31
|
encryption: {
|
|
30
32
|
enabled: true,
|
|
31
|
-
key:
|
|
33
|
+
// In production, retrieve key dynamically from runtimeConfig or authenticated session callback:
|
|
34
|
+
key: () => useRuntimeConfig().public.dataEncryptionKey, // or KMS session callback
|
|
32
35
|
fields: ['name', 'email', 'salary']
|
|
33
36
|
}
|
|
34
37
|
})
|
|
@@ -43,3 +46,10 @@ provider.setFilter({
|
|
|
43
46
|
active: true
|
|
44
47
|
})
|
|
45
48
|
```
|
|
49
|
+
|
|
50
|
+
#### Chart Visualization Architecture & Full-Dataset Loading
|
|
51
|
+
Server-side data providers (`CAPIFlatServerDataProvider`, `CFlatServerDataProvider`) display `pageData` (the current page) by default. For full unpaginated charting:
|
|
52
|
+
1. Pass `{ fetchAll: true }` to `useChartData(provider, { fetchAll: true })` — this calls `provider.fetchAll()`, which requests `pageSize: 0` without mutating the provider's active paginated `pageSize`.
|
|
53
|
+
2. Or call `await provider.fetchAll()` manually — this loads and decrypts the complete dataset into `_allData` and returns it.
|
|
54
|
+
3. Or enable accumulation via infinite-scroll / `loadMore()` so `_allData` contains all loaded pages.
|
|
55
|
+
|
|
@@ -1,11 +1,26 @@
|
|
|
1
1
|
### `CFlatClientDataProvider`
|
|
2
2
|
Manages local arrays with client-side logic, extending `AEncryptedClientProvider`.
|
|
3
|
-
- **`setData(data: TRow[]): Promise<void> | void`**: Ingests dataset into provider. When encryption is enabled, eagerly encrypts designated `fields` before storing in `allData`. Plaintext never persists in `allData`. Pre-encrypted envelopes (`__encrypted: true`) pass through unchanged (idempotent). Zero overhead synchronous fast-path when encryption is disabled
|
|
3
|
+
- **`setData(data: TRow[]): Promise<void> | void`**: Ingests dataset into provider. When `batchSize` is set to a number (default `false`), ingests the dataset in sequential batches: Batch 1 is loaded immediately and rendered to `pageData` so the UI is interactive without delay, while remaining batches are ingested in the background yielding to the event loop (`setTimeout(0)`), updating `isBatchLoading`, `batchProgress`, and firing `onBatchLoaded`. When encryption is enabled, eagerly encrypts designated `fields` before storing in `allData`. Plaintext never persists in `allData`. Pre-encrypted envelopes (`__encrypted: true`) pass through unchanged (idempotent). Zero overhead synchronous fast-path when encryption is disabled and `batchSize` is `false`.
|
|
4
4
|
- **`setDataChunked(data: TRow[], options?: ISetDataChunkedOptions): Promise<void>`**: Ingests massive datasets in batches, yielding to the event loop between chunks to keep the browser UI responsive (`chunkSize`, `onProgress`, `yieldStrategy`).
|
|
5
5
|
- **`setEncryption(options)` / `clearEncryption()`**: Dynamically updates, rotates, or wipes cryptographic keys and cached ciphers at runtime.
|
|
6
|
-
- **`allData`**: `Ref<TRow[]>` - The complete source dataset (holds ciphertext for encrypted fields in JS memory).
|
|
7
|
-
- **`pageData`**: `Ref<TRow[]>` - Active visible page slice (lazily decrypted into plaintext on active page render). Only `pageSize` rows are plaintext in JS memory.
|
|
6
|
+
- **`allData`**: `Ref<TRow[]>` - The complete source dataset (holds ciphertext for encrypted fields in JS memory). **Zero-bulk plaintext in memory**: Plaintext never persists in `allData`. Bulk data remains 100% encrypted in RAM.
|
|
7
|
+
- **`pageData`**: `Ref<TRow[]>` - Active visible page slice (lazily decrypted into plaintext on active page render on-the-fly). Only `pageSize` rows (e.g. 10 or 25) are plaintext in JS memory.
|
|
8
|
+
- **`decryptedCache` & Controlled Information Leakage**:
|
|
9
|
+
- `decryptedCache: false` (Default): Decrypted rows are garbage-collected upon page transition. Client filtering operates on ciphertext tags via `searchIndex` (HMAC blind indexing, trigrams, and shadow bucketing). Candidate false-positive rows from coarse buckets or trigrams are pruned automatically via `verifyDecryptedRows()` on the decrypted page slice.
|
|
10
|
+
- `decryptedCache: true`: In-memory decrypted cache enabling instant client-side filtering on all fields in RAM without blind indexing. Leaves decrypted plaintext in browser memory until page unmount.
|
|
11
|
+
- **Security Warning on Searchable Toggles**: Blind indexing (`blindIndex`) leaks frequency distribution and is strictly forbidden on low-cardinality fields. Shadow bucketing (`rangeBuckets`) leaks coarse ranges. Trigram search (`trigrams`) leaks approximate string length.
|
|
8
12
|
- **`rowMap`**: `readonly TRow[]` - Reference map array maintaining the active filtered & sorted row references. When a page is requested, a portion of this array is served directly in $O(1)$ without re-evaluating filters or sorts.
|
|
13
|
+
- **`pageSize` & Unpaged Mode (`pageSize <= 0`)**:
|
|
14
|
+
- `pageSize > 0` (Default: `10`): Slices dataset to the current page. Only the visible page slice (e.g. 10 rows) is decrypted into `pageData`, while `_rowMap` retains encrypted ciphertext envelopes for zero-trust at rest.
|
|
15
|
+
- `pageSize <= 0` (Unpaged mode): Disables pagination; the entire filtered dataset becomes the active page. As a result, all records are decrypted into `pageData` and `_rowMap` so downstream consumers (charts, export utilities) have immediate access to plaintext data.
|
|
16
|
+
- **Developer Decision & Guidance**: Developers decide the appropriate `pageSize` based on dataset volume. For large datasets (e.g., 5,000–100,000 records), developers should always use discrete pagination (`pageSize: 20` or `50`) or virtual windowing. Setting `pageSize <= 0` on 100k items attempts to load and decrypt all records into browser DOM/memory simultaneously, leading to tab freezes regardless of whether data is encrypted or plaintext.
|
|
9
17
|
- **`updateMap()`**: Explicitly forces recalculation of the `rowMap` if items inside `allData` were modified in-place.
|
|
10
|
-
- **`setFilter(filter: IDataFilter | null, immediate: boolean = false)`**: Applies a structured filter. When `encryption.searchIndex: true`, performs exact match (`==`, `!=`) and substring search (`in`) on encrypted fields using HMAC-SHA256 blind index tokens and trigram sets via `CSearchIndex`. Resets to page 1.
|
|
11
18
|
- **`filter`**: `Ref<IDataFilter | null>` - The currently active filter configuration.
|
|
19
|
+
- **Batch Ingestion Options & Properties (Client-side Only)**:
|
|
20
|
+
- `batchSize`: `number | false` (default: `false`) - Size of sequential batches for chunked in-memory loading. When a positive integer, `setData()` ingests batch 1 immediately and streams subsequent batches via `setTimeout(0)`.
|
|
21
|
+
- `batchLoad`: `'initially' | 'onDemand'` (default: `'initially'`) - When `'initially'`, streams all remaining batches sequentially into `allData`. When `'onDemand'`, stops after batch 1 until subsequent batches are explicitly triggered (via `loadBatch`, `ensureRangeLoaded`, or pagination).
|
|
22
|
+
- `onDemandFilterPolicy`: `'ingestAll' | 'warnOnly'` (default: `'ingestAll'`) - Invalidation policy when filtering or sorting with partial on-demand batches.
|
|
23
|
+
- `loadedBatches`: `Set<number>` - Registry of loaded batch numbers.
|
|
24
|
+
- `onBatchLoaded`: `(event: IBatchLoadedEvent) => void` - Callback executed every time a batch chunk is ingested.
|
|
25
|
+
- `isBatchLoading`: `boolean` - Reactive state property indicating whether background batch streaming is actively in progress.
|
|
26
|
+
- `batchProgress`: `IBatchProgress | undefined` - `{ loaded: number, total: number, percent: number }` representing current streaming completion percentage.
|
|
@@ -9,7 +9,6 @@ Handler-based server-side flat data provider that delegates pagination, filterin
|
|
|
9
9
|
| `filter` | `IDataFilter \| null` | `null` | Initial filter structure |
|
|
10
10
|
| `sortList` | `IDataSort[]` | `[]` | Initial sorting rules |
|
|
11
11
|
| `SSR` | `boolean` | `false` | Enable Nuxt SSR hydration via `getAsyncData` |
|
|
12
|
-
| `urlPageParam` | `string` | `''` | Optional URL query parameter for page syncing |
|
|
13
12
|
| `deduplicate` | `boolean` | `true` | Prevent duplicate concurrent fetches |
|
|
14
13
|
|
|
15
14
|
- **Reactive Properties**:
|
|
@@ -27,10 +26,13 @@ Handler-based server-side flat data provider that delegates pagination, filterin
|
|
|
27
26
|
| --- | --- | --- |
|
|
28
27
|
| `setContextKey(key)` | `string` | Sets a stable unique key for Nuxt SSR hydration |
|
|
29
28
|
| `setPageDataHandler(handler)` | `TPageDataHandler` | Sets the async fetching function and triggers initial load |
|
|
30
|
-
| `loadPageData(opts?)` | `{ disableCache?: boolean }` | Triggers the registered handler |
|
|
29
|
+
| `loadPageData(opts?)` | `{ disableCache?: boolean; page?: number }` | Triggers the registered handler |
|
|
30
|
+
| `fetchAll(opts?)` | `{ disableCache?: boolean; signal?: AbortSignal }` | Fetches unpaginated dataset (`pageSize: 0`) into `_allData` without altering active `pageSize` |
|
|
31
|
+
| `loadMore()` | `none` | Progressively fetches and accumulates the next page into `allData` with deduplication |
|
|
31
32
|
| `refresh(hardRefresh?)` | `boolean` | Re-runs the handler; overrides cache if `hardRefresh = true` |
|
|
32
33
|
| `setFilter(filter)` | `IDataFilter \| null` | Updates active filter criteria and resets to page 1 |
|
|
33
34
|
| `setSortList(sorts)` | `IDataSort[]` | Updates sort order and resets to page 1 |
|
|
35
|
+
| `batchUpdates(fn)` | `() => R` | Inherited from `ADataProvider`. Groups multiple mutations or state changes so `notify()` fires once. |
|
|
34
36
|
|
|
35
37
|
- **Example Usage**:
|
|
36
38
|
```ts
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
### `CTreeClientDataProvider`
|
|
2
2
|
Builds and manages reactive trees from flat arrays, extending `CFlatClientDataProvider`.
|
|
3
|
-
- **`setData(data: TRow[]): Promise<void> | void`**: Ingests hierarchical items. Encrypts sensitive fields eagerly while preserving structural keys (`idKey`, `parentKey`) in plaintext.
|
|
3
|
+
- **`setData(data: TRow[]): Promise<void> | void`**: Ingests hierarchical items. When `batchSize` is set to a number, ingests nodes in sequential batches, displaying the initial batch immediately and rebuilding hierarchical structures progressively in the background while yielding to the event loop. Encrypts sensitive fields eagerly while preserving structural keys (`idKey`, `parentKey`) in plaintext.
|
|
4
4
|
- **`setDataChunked(data: TRow[], options?: ISetDataChunkedOptions)`**: Non-blocking chunked ingestion for large trees.
|
|
5
5
|
- **Constructor Options (`ITreeDataProviderOptions`)**:
|
|
6
6
|
| Option | Type | Default | Description |
|
|
@@ -10,5 +10,5 @@ Builds and manages reactive trees from flat arrays, extending `CFlatClientDataPr
|
|
|
10
10
|
| `expandedByDefault`| `boolean` | `false` | Initial node state |
|
|
11
11
|
| `paginateBy` | `string` | `'all'` | `'all'` (flat) or `'root'` (hierarchical) |
|
|
12
12
|
| `encryption` | `IProviderEncryptionOptions` | `undefined` | AES-GCM or custom cipher encryption configuration |
|
|
13
|
-
- **`setFilter(filter: IDataFilter | null)`**: Applies a structured filter across tree nodes client-side. When `searchIndex: true`, matches on encrypted fields
|
|
13
|
+
- **`setFilter(filter: IDataFilter | null)`**: Applies a structured filter across tree nodes client-side. When `decryptedCache: true` or `searchIndex: true`, matches on encrypted fields and automatically expands parent ancestors of matching child nodes. When filtering without either support, logs an informative warning and never matches raw `[object Object]` envelopes. Resets to page 1.
|
|
14
14
|
- **`filter`**: `Ref<IDataFilter | null>` - The currently active filter configuration.
|
|
@@ -29,12 +29,22 @@ The core engine for all HTTP communication, supporting deduplication, tag-based
|
|
|
29
29
|
| `cacheKey` | `string` | Namespace/context key for shared cache storage |
|
|
30
30
|
| `deduplicate` | `boolean` | Override global deduplication setting |
|
|
31
31
|
| `disableCache` | `boolean` | Explicitly override cache for this request |
|
|
32
|
+
| `signal` | `AbortSignal` | Caller abort signal; bridged across deduplicated callers so aborting one does not cancel others |
|
|
33
|
+
| `context` | `any` | Framework or SSR request context (e.g., `{ event }` or Nitro H3Event) |
|
|
34
|
+
| `event` | `any` | Direct H3Event/SSR event forwarding for server cookie and tenant resolution |
|
|
32
35
|
| `tags` | `string[]` | Associated tags for invalidation / auto-refresh upon mutation |
|
|
33
36
|
| `queue` | `boolean` | When true (for non-GET requests), enqueues the mutation into `RequestQueue` instead of dispatching immediately |
|
|
34
37
|
| `label` | `string` | Human-readable description for queued mutation display in UI |
|
|
38
|
+
| `encryption` | `IProviderEncryptionOptions` | Per-request encryption overrides (e.g. `encryptBinary: true` for offline queue) |
|
|
35
39
|
| `nuxtApp` | `unknown` | Nuxt app instance — enables SSR cookie forwarding via h3 |
|
|
36
40
|
| `_generation` | `number` | Internal request generation counter to discard stale responses |
|
|
37
41
|
|
|
42
|
+
- **Static Context Resolution & Multi-Subscriber Abort Bridge**:
|
|
43
|
+
- `RequestProvider.setContextResolver(fn)`: Pluggable resolver returning `{ event }` for SSR environments (e.g. Nuxt `useRequestEvent()`).
|
|
44
|
+
- **Multi-Subscriber Abort Bridge**: Concurrent GET requests joining an in-flight deduplication promise register independent subscriber listeners. The underlying network request is only aborted when **all** active subscribers have aborted their signals.
|
|
45
|
+
- **Offline Queue Binary Encryption**: When `encryption.enabled = true` and `encryption.encryptBinary = true`, binary payloads (`FormData`, `Blob`, `File`, `ArrayBuffer`) are encrypted into ciphertext envelopes before persistence into IndexedDB, and transparently decrypted on flush.
|
|
46
|
+
- **SSR Cache & Tenant Isolation**: On SSR (`isServer`), when request context is uncontextualized (`!event`) and per-tenant encryption key ID is missing, shared server cache reads and writes are automatically bypassed to prevent cross-tenant data leaks. A developer warning is logged if relative same-origin requests lack event context to forward Cookies.
|
|
47
|
+
|
|
38
48
|
### `RequestProviderRegistry`
|
|
39
49
|
Framework-agnostic static registry mapping active `RequestProvider` instances to tag arrays. When mutations complete (or offline queues flush), `RequestProviderRegistry` automatically triggers `refresh(true)` on all matching registered GET providers.
|
|
40
50
|
|
|
@@ -50,7 +50,8 @@ const customerProvider = new CFlatClientDataProvider({
|
|
|
50
50
|
pageSize: 20,
|
|
51
51
|
encryption: {
|
|
52
52
|
enabled: true,
|
|
53
|
-
|
|
53
|
+
// In production, retrieve credentials dynamically from environment variables, KMS, or runtime config:
|
|
54
|
+
key: () => useRuntimeConfig().public.dataEncryptionKey, // or process.env.DATA_KEY
|
|
54
55
|
kid: 'tenant-key-v1',
|
|
55
56
|
fields: ['ssn', 'salary', 'creditCard'],
|
|
56
57
|
searchIndex: true // Enables search/filter on encrypted fields via CSearchIndex
|
|
@@ -74,6 +75,9 @@ await customerProvider.setDataChunked(largeEmployees, {
|
|
|
74
75
|
### Pre-Encrypted Dataset Ingestion (`preEncrypted: true`)
|
|
75
76
|
When datasets arrive already encrypted from server endpoints, data providers perform a transient in-memory decryption pass on indexed fields to populate `CSearchIndex` without modifying or leaking persistent ciphertext rows in `allData`.
|
|
76
77
|
|
|
78
|
+
> [!IMPORTANT]
|
|
79
|
+
> **Production Key Security**: Never hardcode secret passphrases or master encryption keys in client-side bundles or source code. Always retrieve keys dynamically from secure environment variables (`process.env.DATA_KEY`), Nuxt `useRuntimeConfig()`, an authenticated user session, or an async callback (`key: async () => await fetchSessionKey()`).
|
|
80
|
+
|
|
77
81
|
---
|
|
78
82
|
|
|
79
83
|
## 4. Blind Index Search & Substring Trigram Indexing (`CSearchIndex`)
|
|
@@ -85,6 +89,17 @@ Enables fast exact match (`==`, `!=`) and substring search (`in`) over encrypted
|
|
|
85
89
|
2. **Blind Index Token**: Generate exact blind index token via `CKeyManager.computeBlindIndex(plain, hmacKey)`.
|
|
86
90
|
3. **Trigram Slices**: Extract 3-character slices via `extractTrigrams(plain)` and hash each trigram with `searchIndex.computeTrigramTokens(plain)`.
|
|
87
91
|
|
|
92
|
+
### Client Filtering & Sorting on Encrypted Envelopes (`decryptedCache` & Sort Guards)
|
|
93
|
+
In client-side data providers (`CFlatClientDataProvider` and `CTreeClientDataProvider`), data records in `allData` remain encrypted at rest as ciphertext envelopes (`{ __encrypted: true, ciphertext, iv }`).
|
|
94
|
+
|
|
95
|
+
1. **Filtering on Encrypted Fields**:
|
|
96
|
+
- **Blind Index (`searchIndex: true`)**: Recommended for large datasets (10,000+ rows). Uses HMAC tokens and trigram hashes without holding plaintext copies of records at rest.
|
|
97
|
+
- **Decrypted Row Cache (`decryptedCache: true`)**: Opt-in in-memory cache holding plaintext row representations for instant local evaluation across any filter operator (`Equal`, `Contains`, `In`, custom predicates) without blind index setup.
|
|
98
|
+
- **Unconfigured Guard**: Attempting to filter on an encrypted field without `searchIndex` or `decryptedCache` emits an informative console warning. Filter comparisons explicitly guard against `"[object Object]"` string coercion, ensuring raw envelopes never match plaintext queries.
|
|
99
|
+
|
|
100
|
+
2. **Sorting on Encrypted Fields (Sort Guard)**:
|
|
101
|
+
- Client sorting on encrypted fields without deterministic sortable shadow buckets (`TASK-031`) emits a development warning and leaves dataset order unchanged, preventing broken `"[object Object]"` comparisons.
|
|
102
|
+
|
|
88
103
|
---
|
|
89
104
|
|
|
90
105
|
## 5. Backend Persistence & Datatable Encrypted Search
|
|
@@ -136,10 +151,16 @@ CREATE INDEX idx_contacts_email_trigrams ON contacts USING GIN (email_trigrams);
|
|
|
136
151
|
WHERE name_trigrams @> $1::text[] AND department = 'Security'
|
|
137
152
|
```
|
|
138
153
|
|
|
139
|
-
### 3. Production Best Practices
|
|
154
|
+
### 3. Production Best Practices & Security Disclosures (BUG-034)
|
|
140
155
|
- **Strict Key Isolation**: Isolate `DATA_ENCRYPTION_KEY` (AES-256-GCM) from `BLIND_INDEX_HMAC_KEY`.
|
|
156
|
+
- **Architectural Trust Models**:
|
|
157
|
+
- *End-to-End Zero-Plaintext (Client-Side Query Rewriting)*: In true zero-plaintext architectures, the client computes HMAC search tokens locally using client-held keys (`rewriteEncryptedFilters`) and dispatches only opaque hashes (`name_bidx = <hash>`). The server never observes plaintext search strings.
|
|
158
|
+
- *Server-Side Blind Indexing (Protected Persistence)*: When search queries are sent over HTTP and evaluated on the server, backend database records remain encrypted at rest, but wire transport carries search terms (claims of "zero plaintext over HTTP" do not apply).
|
|
159
|
+
- **Leakage Disclosures**:
|
|
160
|
+
- *Deterministic Equality Tokens (`==`, `in`)*: Deterministic HMAC tokens expose dataset frequency distributions. Highly susceptible to dictionary matching and frequency analysis on low-entropy fields. Never blind-index low-cardinality fields (gender, boolean flags, status, city).
|
|
161
|
+
- *Trigram Tokens (Substring Search)*: Expose approximate string length and character combinations.
|
|
162
|
+
- *Safe Fields*: Restrict blind indexing strictly to high-entropy identifiers with dedicated index keys (email addresses, SSNs, tax IDs, account numbers, UUIDs).
|
|
141
163
|
- **Short Queries (< 3 chars)**: Substring search requires at least 3 characters to form a valid trigram. Enforce a 3-character minimum in client UI.
|
|
142
|
-
- **Low-Cardinality Isolation**: Never blind index low-cardinality fields (boolean flags, binary status) to prevent frequency analysis leakage.
|
|
143
164
|
- **Client Decryption Pipeline**: API responses return encrypted envelopes (`__encrypted: true`). Frontend `CAPIFlatServerDataProvider` decrypts only the received page slice via `decryptPageRows()` on arrival.
|
|
144
165
|
|
|
145
166
|
---
|
|
@@ -197,22 +218,19 @@ const writeToken = await CKeyManager.computeWriteBlindIndex('user@example.com',
|
|
|
197
218
|
|
|
198
219
|
### Encrypted Query Rewriting (`rewriteEncryptedFilters`)
|
|
199
220
|
|
|
200
|
-
When an application receives datatable
|
|
221
|
+
When an application receives datatable filter criteria targeting encrypted fields, `rewriteEncryptedFilters` acts as a pure `IDataFilter` AST transformation function (No ORM / No SQL generation), expanding equality and negation predicates into candidate tokens across multi-KID keyrings while preserving compound logical hierarchies (`and`, `or`, `nor`, `nand`):
|
|
201
222
|
|
|
202
223
|
```ts
|
|
203
|
-
import { rewriteEncryptedFilters } from '@katlux/providers'
|
|
224
|
+
import { rewriteEncryptedFilters, EDataFilterOperator, type IDataFilter } from '@katlux/providers'
|
|
204
225
|
|
|
205
226
|
const rewritten = await rewriteEncryptedFilters(
|
|
206
227
|
[
|
|
207
|
-
{
|
|
208
|
-
{
|
|
228
|
+
{ operator: EDataFilterOperator.Equal, field: { email: 'user@example.com' }, active: true },
|
|
229
|
+
{ operator: EDataFilterOperator.Equal, field: { status: 'Active' }, active: true } // unencrypted passthrough
|
|
209
230
|
],
|
|
210
231
|
{
|
|
211
|
-
|
|
212
|
-
fields: {
|
|
232
|
+
blindIndexFields: {
|
|
213
233
|
email: {
|
|
214
|
-
encrypted: true,
|
|
215
|
-
blindIndex: true,
|
|
216
234
|
keyring: emailKeyring,
|
|
217
235
|
column: 'email_bidx'
|
|
218
236
|
}
|
|
@@ -221,19 +239,23 @@ const rewritten = await rewriteEncryptedFilters(
|
|
|
221
239
|
}
|
|
222
240
|
)
|
|
223
241
|
|
|
224
|
-
//
|
|
225
|
-
//
|
|
226
|
-
//
|
|
242
|
+
// Output AST (Pure IDataFilter[]):
|
|
243
|
+
// [
|
|
244
|
+
// { operator: EDataFilterOperator.In, field: { email_bidx: ['bidx_v2', 'bidx_v1'] }, active: true },
|
|
245
|
+
// { operator: EDataFilterOperator.Equal, field: { status: 'Active' }, active: true }
|
|
246
|
+
// ]
|
|
247
|
+
// Total tokens generated: rewritten.totalCandidateTokens
|
|
227
248
|
```
|
|
228
249
|
|
|
229
|
-
#### Operator Mapping &
|
|
230
|
-
- **Equality (`==`) / Set Membership (`in`)**: Expands to
|
|
231
|
-
- **Negation (`!=`) / Exclusion (`nin` / `not in`)**: Expands to
|
|
232
|
-
- **
|
|
250
|
+
#### Operator Mapping & Security Guards
|
|
251
|
+
- **Equality (`==`) / Set Membership (`in`)**: Expands to `{ operator: EDataFilterOperator.In, field: { [col_bidx]: tokenCandidates }, active: true }` over candidate tokens generated from active and `search-only` keys.
|
|
252
|
+
- **Negation (`!=`) / Exclusion (`nin` / `not in`)**: Expands to `{ operator: EDataFilterOperator.NotIn, field: { [col_bidx]: tokenCandidates }, active: true }`.
|
|
253
|
+
- **Compound Hierarchies**: Fully preserves logical groupings (`or`, `and`, `nor`, `nand`) without flattening into `AND`.
|
|
254
|
+
- **Unsupported Operators Guard (`ERR_BIDX_UNSUPPORTED_OPERATOR`)**: Querying a blind-indexed column with unsupported operators (e.g. `>`, `<`, `>=`, `<=`, `contains`, `startsWith`, `endsWith`, `like`) immediately throws `ERR_BIDX_UNSUPPORTED_OPERATOR`. Plaintext fallback values are never leaked.
|
|
255
|
+
- **Pass-through**: Unencrypted fields (e.g. `status = 'Active'`) pass through unmodified in their tree positions.
|
|
233
256
|
|
|
234
257
|
#### Guard Rails
|
|
235
258
|
- `maxCandidateTokens` (default: 500): Prevents query explosion from large `in` lists combined with multiple key versions. Throws `ERR_BIDX_TOO_MANY_CANDIDATES` if exceeded.
|
|
236
|
-
- Parameter Chunking: SQLite/MySQL dialect chunking breaks down long `IN` lists when exceeding parameter limits.
|
|
237
259
|
|
|
238
260
|
---
|
|
239
261
|
|
|
@@ -258,3 +280,25 @@ When rotating a blind index HMAC key:
|
|
|
258
280
|
> [!TIP]
|
|
259
281
|
> **Information Leakage Trade-off**: Keeping historical keys in `'search-only'` mode expands SQL queries to test multiple HMAC hashes per search term. To minimize index leakage and maintain optimal query performance, complete Step 2 (background re-indexing) promptly so older keys can be transitioned to `'retired'`.
|
|
260
282
|
|
|
283
|
+
---
|
|
284
|
+
|
|
285
|
+
## 8. Field Suitability Matrix & Threat Modeling ("Hangi Alanlar İçin?")
|
|
286
|
+
|
|
287
|
+
Selecting an appropriate cryptographic representation for data fields requires balancing **query capability** against **information leakage**:
|
|
288
|
+
|
|
289
|
+
| Storage / Query Strategy | Suitable Fields / Data Types | Required Entropy | Supported Query Capabilities | Information Leakage & Cryptographic Tradeoffs | Recommended Best Practice |
|
|
290
|
+
| :--- | :--- | :--- | :--- | :--- | :--- |
|
|
291
|
+
| **Plaintext / Unencrypted** | Public IDs, system timestamps, foreign keys, non-sensitive categories (e.g. `id`, `created_at`, `status`, `role`) | Public / Any | Full SQL & AST query expressions (`=`, `!=`, `<`, `>`, `LIKE`, `IN`, Sorting, Grouping) | Zero confidentiality. Visible to storage admins, database dumps, and query logs. | **Use for operational metadata & relations**. Do not encrypt fields required for high-throughput relational joins or non-sensitive filters. |
|
|
292
|
+
| **Standard AES-256-GCM Envelope Encryption** | Highly sensitive PII, passwords, private keys, medical notes, credit card CVVs, rich text payloads (e.g. `medical_notes`, `api_secret`, `cvv`) | High or Low | None (direct ciphertext storage only; decrypted in client memory or authorized application layer) | Zero index leakage. Randomized IV/nonce ensures identical plaintexts yield completely different ciphertexts. Immune to frequency analysis. | **Gold standard for confidential data**. Use whenever fields do not require server-side filtering, searching, or indexing. |
|
|
293
|
+
| **Blind Index Equality Token (HMAC-SHA256)** | High-entropy unique / semi-unique identifiers: `email`, `ssn`, `tax_id`, `phone_number`, `national_id`, `uuid` | **High Entropy Only** | Exact match (`==`, `!=`, `IN`, `NOT IN`) via B-Tree index on `*_bidx` column | Deterministic token preserves equality and frequency distributions. Duplicates and recurring values are observable. | **Use strictly for exact lookups of high-entropy identifiers**. Always use a dedicated HMAC key separated from the DEK. Never apply to low-cardinality fields. |
|
|
294
|
+
| **Trigram Substring Search** | Long, high-entropy textual strings requiring substring/contains queries: `full_name`, `address_line`, `company_name` | **High to Medium Entropy** | Substring / Contains search via GIN inverted index (`@>` array containment) on `*_trigrams` | Leaks approximate string length and character co-occurrence frequencies. | **Use with caution on high-entropy text**. Enforce 3+ character minimum query length in client UI. Do not apply to small discrete enum sets. |
|
|
295
|
+
| **Shadow Bucketing / Range Tokens (RFC-001 / TASK-031)** | Numeric ranges, dates, monetary amounts, age groups, salaries (e.g. `salary_bucket`, `created_date_bucket`, `credit_score_range`) | Low to Medium | Range queries (`>`, `<`, `>=`, `<=`, `BETWEEN`) on discretized bucket values | Coarse range leakage. Reveals which discrete bucket (e.g. `$50k-$75k`, `2026-Q1`) a record falls into. | **Recommended when range search is strictly necessary**. Tune bucket granularity to balance query precision against distribution leakage. |
|
|
296
|
+
|
|
297
|
+
### Low-Cardinality Column Warning & Frequency Analysis Attacks
|
|
298
|
+
> [!CAUTION]
|
|
299
|
+
> **Strict Prohibition on Low-Cardinality Blind Indexing**:
|
|
300
|
+
> Deterministic HMAC tokens preserve frequency distribution. In low-cardinality columns (e.g. `gender` [M/F], boolean flags [true/false], order status ['pending', 'shipped', 'delivered'], or country codes), an observer who accesses the encrypted table or query stream can match token frequencies against known population statistics (e.g., 51% female vs 49% male) and instantly deduce the plaintext values without knowing the HMAC secret key.
|
|
301
|
+
>
|
|
302
|
+
> If a field has fewer than 1,000 distinct possible values in the domain, or consists of common dictionary words, **do NOT blind index it**. Use standard envelope encryption combined with in-memory client filtering (`decryptedCache: true`) or leave operational flags in plaintext.
|
|
303
|
+
|
|
304
|
+
|