@katlux/providers 0.1.1-alpha.121 → 0.1.1-alpha.123
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/dist/index.cjs +176 -32
- package/dist/index.d.cts +8 -0
- package/dist/index.d.mts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.mjs +176 -32
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -902,13 +902,84 @@ class AEncryptionProvider {
|
|
|
902
902
|
* - If payload is an array of objects: decrypts each row.
|
|
903
903
|
* - If payload is an object: decrypts any encrypted value cells across fields.
|
|
904
904
|
*/
|
|
905
|
+
/**
|
|
906
|
+
* Top-level polymorphic decryption method.
|
|
907
|
+
* Automatically performs value-level decryption:
|
|
908
|
+
* - If payload is an encrypted envelope: decrypts directly via decryptValue.
|
|
909
|
+
* - If payload is an array of objects: decrypts each row (batched with local memoization).
|
|
910
|
+
* - If payload is an object: decrypts any encrypted value cells across fields.
|
|
911
|
+
*/
|
|
905
912
|
async decrypt(payload, options) {
|
|
906
913
|
if (payload === void 0 || payload === null) return payload;
|
|
907
914
|
if (this.isEncrypted(payload)) {
|
|
908
915
|
return this.decryptValue(payload, options);
|
|
909
916
|
}
|
|
910
917
|
if (Array.isArray(payload)) {
|
|
911
|
-
|
|
918
|
+
if (payload.length === 0) return payload;
|
|
919
|
+
const localMemo = /* @__PURE__ */ new Map();
|
|
920
|
+
const decryptRow = async (item) => {
|
|
921
|
+
if (!item) return item;
|
|
922
|
+
if (this.isEncrypted(item)) {
|
|
923
|
+
const ct = item.ciphertext;
|
|
924
|
+
const iv = item.iv || "";
|
|
925
|
+
const aadPart = options?.aad ? typeof options.aad === "string" ? options.aad : "" : "";
|
|
926
|
+
const memoKey = `${ct}:${iv}:${aadPart}`;
|
|
927
|
+
if (!localMemo.has(memoKey)) {
|
|
928
|
+
localMemo.set(memoKey, this.decryptValue(item, options));
|
|
929
|
+
}
|
|
930
|
+
return localMemo.get(memoKey);
|
|
931
|
+
}
|
|
932
|
+
if (typeof item === "object" && !ArrayBuffer.isView(item) && !(item instanceof ArrayBuffer)) {
|
|
933
|
+
const targetKeys = options?.fields && options.fields.length > 0 ? options.fields.filter((f) => Object.prototype.hasOwnProperty.call(item, f)) : Object.keys(item);
|
|
934
|
+
const keysToDecrypt = targetKeys.filter((key) => this.isEncrypted(item[key]));
|
|
935
|
+
if (keysToDecrypt.length === 0) {
|
|
936
|
+
return item;
|
|
937
|
+
}
|
|
938
|
+
const proto = Object.getPrototypeOf(item);
|
|
939
|
+
const result = proto && proto !== Object.prototype ? Object.assign(Object.create(proto), item) : { ...item };
|
|
940
|
+
await Promise.all(
|
|
941
|
+
keysToDecrypt.map(async (key) => {
|
|
942
|
+
const env = item[key];
|
|
943
|
+
const boundOptions = this._bindFieldAad(item, key, options);
|
|
944
|
+
const hasBoundAad = boundOptions.aad !== options?.aad;
|
|
945
|
+
const ct = env.ciphertext;
|
|
946
|
+
const iv = env.iv || "";
|
|
947
|
+
const aadPart = boundOptions.aad ? typeof boundOptions.aad === "string" ? boundOptions.aad : "" : "";
|
|
948
|
+
const memoKey = `${ct}:${iv}:${aadPart}`;
|
|
949
|
+
if (!localMemo.has(memoKey)) {
|
|
950
|
+
const decryptPromise = this.decryptValue(env, boundOptions).catch((err) => {
|
|
951
|
+
if (hasBoundAad && isAuthOrDecryptionError(err)) {
|
|
952
|
+
return this.decryptValue(env, options);
|
|
953
|
+
}
|
|
954
|
+
throw err;
|
|
955
|
+
});
|
|
956
|
+
localMemo.set(memoKey, decryptPromise);
|
|
957
|
+
}
|
|
958
|
+
const decryptedVal = await localMemo.get(memoKey);
|
|
959
|
+
safeSetProperty(result, key, decryptedVal);
|
|
960
|
+
})
|
|
961
|
+
);
|
|
962
|
+
return result;
|
|
963
|
+
}
|
|
964
|
+
return item;
|
|
965
|
+
};
|
|
966
|
+
if (payload.length <= 100) {
|
|
967
|
+
return Promise.all(payload.map(decryptRow));
|
|
968
|
+
}
|
|
969
|
+
const batchSize = 1e3;
|
|
970
|
+
const results = new Array(payload.length);
|
|
971
|
+
for (let i = 0; i < payload.length; i += batchSize) {
|
|
972
|
+
const end = Math.min(i + batchSize, payload.length);
|
|
973
|
+
const chunk = payload.slice(i, end);
|
|
974
|
+
const chunkRes = await Promise.all(chunk.map(decryptRow));
|
|
975
|
+
for (let j = 0; j < chunkRes.length; j++) {
|
|
976
|
+
results[i + j] = chunkRes[j];
|
|
977
|
+
}
|
|
978
|
+
if (end < payload.length && (i > 0 && i % 5e3 === 0)) {
|
|
979
|
+
await new Promise((r) => setTimeout(r, 0));
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
return results;
|
|
912
983
|
}
|
|
913
984
|
if (typeof payload === "object" && !ArrayBuffer.isView(payload) && !(payload instanceof ArrayBuffer)) {
|
|
914
985
|
const targetKeys = options?.fields && options.fields.length > 0 ? options.fields.filter((f) => Object.prototype.hasOwnProperty.call(payload, f)) : Object.keys(payload);
|
|
@@ -4797,15 +4868,24 @@ class CFlatClientDataProvider extends AEncryptedClientProvider {
|
|
|
4797
4868
|
this.error = null;
|
|
4798
4869
|
try {
|
|
4799
4870
|
this._computeFilteredAndSorted();
|
|
4800
|
-
if (this.
|
|
4801
|
-
|
|
4802
|
-
|
|
4803
|
-
|
|
4804
|
-
|
|
4805
|
-
for (let i = 0; i < rows.length; i++) {
|
|
4806
|
-
this._rowMap[startIndex + i] = rows[i];
|
|
4871
|
+
if (this.pageSize <= 0) {
|
|
4872
|
+
if (this._rowMap && this._rowMap.length > 0) {
|
|
4873
|
+
const { rows, decrypted } = await this.decryptRows(this._rowMap);
|
|
4874
|
+
if (decrypted) {
|
|
4875
|
+
this._rowMap = rows;
|
|
4807
4876
|
}
|
|
4808
4877
|
}
|
|
4878
|
+
this.pageData = this._rowMap;
|
|
4879
|
+
} else {
|
|
4880
|
+
const startIndex = (this.currentPage - 1) * this.pageSize;
|
|
4881
|
+
const endIndex = startIndex + this.pageSize;
|
|
4882
|
+
const pageSlice = this._rowMap.slice(startIndex, endIndex);
|
|
4883
|
+
if (pageSlice && pageSlice.length > 0) {
|
|
4884
|
+
const { rows, decrypted } = await this.decryptRows(pageSlice);
|
|
4885
|
+
this.pageData = decrypted ? rows : pageSlice;
|
|
4886
|
+
} else {
|
|
4887
|
+
this.pageData = [];
|
|
4888
|
+
}
|
|
4809
4889
|
}
|
|
4810
4890
|
} catch (err) {
|
|
4811
4891
|
this.error = err;
|
|
@@ -7421,6 +7501,7 @@ class CTreeClientDataProvider extends CFlatClientDataProvider {
|
|
|
7421
7501
|
_sortedNodeIdsCache = null;
|
|
7422
7502
|
_filteredNodesCache = null;
|
|
7423
7503
|
_allVisibleRowsCache = null;
|
|
7504
|
+
_decryptedNodeMap = /* @__PURE__ */ new Map();
|
|
7424
7505
|
invalidateStaticCache() {
|
|
7425
7506
|
this._staticNodesCache = null;
|
|
7426
7507
|
this._nodeMapCache = null;
|
|
@@ -7468,6 +7549,7 @@ class CTreeClientDataProvider extends CFlatClientDataProvider {
|
|
|
7468
7549
|
this.updatePageData();
|
|
7469
7550
|
}
|
|
7470
7551
|
_applyTreeData(rows) {
|
|
7552
|
+
this._decryptedNodeMap.clear();
|
|
7471
7553
|
this.invalidateStaticCache();
|
|
7472
7554
|
this.allData = rows;
|
|
7473
7555
|
this._filterDirty = true;
|
|
@@ -7771,22 +7853,30 @@ class CTreeClientDataProvider extends CFlatClientDataProvider {
|
|
|
7771
7853
|
const filteredNodes = this._filteredNodesCache;
|
|
7772
7854
|
this.filteredData = filteredNodes;
|
|
7773
7855
|
const paginated = this.paginateNodes(filteredNodes);
|
|
7774
|
-
this.pageData = paginated.map((node) =>
|
|
7775
|
-
|
|
7776
|
-
...node,
|
|
7777
|
-
|
|
7778
|
-
|
|
7856
|
+
this.pageData = paginated.map((node) => {
|
|
7857
|
+
const decrypted = this.isEncryptionEnabled ? this._decryptedNodeMap.get(node.id) : void 0;
|
|
7858
|
+
const nodeData = decrypted ? { ...node.data, ...decrypted } : node.data;
|
|
7859
|
+
return {
|
|
7860
|
+
...nodeData,
|
|
7861
|
+
...node,
|
|
7862
|
+
__treeNode: node
|
|
7863
|
+
};
|
|
7864
|
+
});
|
|
7779
7865
|
if (this.allData.length > 0) {
|
|
7780
7866
|
this.initialLoad = false;
|
|
7781
7867
|
}
|
|
7782
7868
|
return;
|
|
7783
7869
|
}
|
|
7784
7870
|
const visible = this.visibleRows;
|
|
7785
|
-
this.pageData = visible.map((node) =>
|
|
7786
|
-
|
|
7787
|
-
...node,
|
|
7788
|
-
|
|
7789
|
-
|
|
7871
|
+
this.pageData = visible.map((node) => {
|
|
7872
|
+
const decrypted = this.isEncryptionEnabled ? this._decryptedNodeMap.get(node.id) : void 0;
|
|
7873
|
+
const nodeData = decrypted ? { ...node.data, ...decrypted } : node.data;
|
|
7874
|
+
return {
|
|
7875
|
+
...nodeData,
|
|
7876
|
+
...node,
|
|
7877
|
+
__treeNode: node
|
|
7878
|
+
};
|
|
7879
|
+
});
|
|
7790
7880
|
if (this.allData.length > 0) {
|
|
7791
7881
|
this.initialLoad = false;
|
|
7792
7882
|
}
|
|
@@ -7822,19 +7912,53 @@ class CTreeClientDataProvider extends CFlatClientDataProvider {
|
|
|
7822
7912
|
this.loading = true;
|
|
7823
7913
|
this.error = null;
|
|
7824
7914
|
try {
|
|
7825
|
-
this.
|
|
7826
|
-
|
|
7827
|
-
const {
|
|
7828
|
-
|
|
7829
|
-
|
|
7830
|
-
|
|
7831
|
-
|
|
7832
|
-
|
|
7833
|
-
|
|
7915
|
+
const visibleNodes = this.allVisibleNodes.map((node) => {
|
|
7916
|
+
const decrypted = this._decryptedNodeMap.get(node.id);
|
|
7917
|
+
const nodeData = decrypted ? { ...node.data, ...decrypted } : node.data;
|
|
7918
|
+
return {
|
|
7919
|
+
...nodeData,
|
|
7920
|
+
...node,
|
|
7921
|
+
__treeNode: node
|
|
7922
|
+
};
|
|
7923
|
+
});
|
|
7924
|
+
if (this.pageSize <= 0) {
|
|
7925
|
+
if (visibleNodes.length > 0) {
|
|
7926
|
+
const { rows, decrypted } = await this.decryptRows(visibleNodes);
|
|
7927
|
+
if (decrypted) {
|
|
7928
|
+
for (const r of rows) {
|
|
7929
|
+
const id = r[this.idKey] ?? r.id;
|
|
7930
|
+
if (id !== void 0 && id !== null) {
|
|
7931
|
+
this._decryptedNodeMap.set(id, r);
|
|
7932
|
+
}
|
|
7834
7933
|
}
|
|
7835
7934
|
}
|
|
7935
|
+
this._allVisibleRowsCache = decrypted ? rows : visibleNodes;
|
|
7936
|
+
} else {
|
|
7937
|
+
this._allVisibleRowsCache = [];
|
|
7938
|
+
}
|
|
7939
|
+
this.pageData = [...this._allVisibleRowsCache];
|
|
7940
|
+
} else {
|
|
7941
|
+
this._allVisibleRowsCache = null;
|
|
7942
|
+
const startIndex = (this.currentPage - 1) * this.pageSize;
|
|
7943
|
+
const pageSlice = visibleNodes.slice(startIndex, startIndex + this.pageSize);
|
|
7944
|
+
if (pageSlice.length > 0) {
|
|
7945
|
+
const { rows, decrypted } = await this.decryptRows(pageSlice);
|
|
7946
|
+
if (decrypted) {
|
|
7947
|
+
for (const r of rows) {
|
|
7948
|
+
const id = r[this.idKey] ?? r.id;
|
|
7949
|
+
if (id !== void 0 && id !== null) {
|
|
7950
|
+
this._decryptedNodeMap.set(id, r);
|
|
7951
|
+
}
|
|
7952
|
+
}
|
|
7953
|
+
}
|
|
7954
|
+
this.pageData = decrypted ? rows : pageSlice;
|
|
7955
|
+
} else {
|
|
7956
|
+
this.pageData = [];
|
|
7836
7957
|
}
|
|
7837
7958
|
}
|
|
7959
|
+
if (this.allData.length > 0) {
|
|
7960
|
+
this.initialLoad = false;
|
|
7961
|
+
}
|
|
7838
7962
|
} catch (err) {
|
|
7839
7963
|
this.error = err;
|
|
7840
7964
|
console.warn("[Katlux Providers] CTreeClientDataProvider loadPageData error", err);
|
|
@@ -7846,6 +7970,7 @@ class CTreeClientDataProvider extends CFlatClientDataProvider {
|
|
|
7846
7970
|
}
|
|
7847
7971
|
clearEncryption() {
|
|
7848
7972
|
super.clearEncryption();
|
|
7973
|
+
this._decryptedNodeMap.clear();
|
|
7849
7974
|
this._filterDirty = true;
|
|
7850
7975
|
this._sortDirty = true;
|
|
7851
7976
|
this._filteredNodesCache = null;
|
|
@@ -7886,11 +8011,15 @@ class CTreeClientDataProvider extends CFlatClientDataProvider {
|
|
|
7886
8011
|
}
|
|
7887
8012
|
get allVisibleRows() {
|
|
7888
8013
|
if (!this._allVisibleRowsCache) {
|
|
7889
|
-
this._allVisibleRowsCache = this.allVisibleNodes.map((node) =>
|
|
7890
|
-
|
|
7891
|
-
...node,
|
|
7892
|
-
|
|
7893
|
-
|
|
8014
|
+
this._allVisibleRowsCache = this.allVisibleNodes.map((node) => {
|
|
8015
|
+
const decrypted = this.isEncryptionEnabled ? this._decryptedNodeMap.get(node.id) : void 0;
|
|
8016
|
+
const nodeData = decrypted ? { ...node.data, ...decrypted } : node.data;
|
|
8017
|
+
return {
|
|
8018
|
+
...nodeData,
|
|
8019
|
+
...node,
|
|
8020
|
+
__treeNode: node
|
|
8021
|
+
};
|
|
8022
|
+
});
|
|
7894
8023
|
if (this.isEncryptionEnabled && this.pageData && this.pageData.length > 0) {
|
|
7895
8024
|
const startIndex = this.pageSize <= 0 ? 0 : (this.currentPage - 1) * this.pageSize;
|
|
7896
8025
|
for (let i = 0; i < this.pageData.length; i++) {
|
|
@@ -7921,6 +8050,9 @@ class CTreeClientDataProvider extends CFlatClientDataProvider {
|
|
|
7921
8050
|
}
|
|
7922
8051
|
this.updatePageData();
|
|
7923
8052
|
this.notify();
|
|
8053
|
+
if (this.isEncryptionEnabled) {
|
|
8054
|
+
this.loadPageData();
|
|
8055
|
+
}
|
|
7924
8056
|
}
|
|
7925
8057
|
expand(nodeId) {
|
|
7926
8058
|
if (this.filter && this.filter.active) {
|
|
@@ -7930,6 +8062,9 @@ class CTreeClientDataProvider extends CFlatClientDataProvider {
|
|
|
7930
8062
|
this.expandedNodes.add(nodeId);
|
|
7931
8063
|
this.updatePageData();
|
|
7932
8064
|
this.notify();
|
|
8065
|
+
if (this.isEncryptionEnabled) {
|
|
8066
|
+
this.loadPageData();
|
|
8067
|
+
}
|
|
7933
8068
|
}
|
|
7934
8069
|
collapse(nodeId) {
|
|
7935
8070
|
if (this.filter && this.filter.active) {
|
|
@@ -7939,6 +8074,9 @@ class CTreeClientDataProvider extends CFlatClientDataProvider {
|
|
|
7939
8074
|
this.expandedNodes.delete(nodeId);
|
|
7940
8075
|
this.updatePageData();
|
|
7941
8076
|
this.notify();
|
|
8077
|
+
if (this.isEncryptionEnabled) {
|
|
8078
|
+
this.loadPageData();
|
|
8079
|
+
}
|
|
7942
8080
|
}
|
|
7943
8081
|
expandNode(nodeId) {
|
|
7944
8082
|
this.expand(nodeId);
|
|
@@ -7955,6 +8093,9 @@ class CTreeClientDataProvider extends CFlatClientDataProvider {
|
|
|
7955
8093
|
this.expandedNodes = new Set(allIds);
|
|
7956
8094
|
this.updatePageData();
|
|
7957
8095
|
this.notify();
|
|
8096
|
+
if (this.isEncryptionEnabled) {
|
|
8097
|
+
this.loadPageData();
|
|
8098
|
+
}
|
|
7958
8099
|
}
|
|
7959
8100
|
collapseAll() {
|
|
7960
8101
|
if (this.filter && this.filter.active) {
|
|
@@ -7964,6 +8105,9 @@ class CTreeClientDataProvider extends CFlatClientDataProvider {
|
|
|
7964
8105
|
this.expandedNodes = /* @__PURE__ */ new Set();
|
|
7965
8106
|
this.updatePageData();
|
|
7966
8107
|
this.notify();
|
|
8108
|
+
if (this.isEncryptionEnabled) {
|
|
8109
|
+
this.loadPageData();
|
|
8110
|
+
}
|
|
7967
8111
|
}
|
|
7968
8112
|
getNode(nodeId) {
|
|
7969
8113
|
const staticNode = this._nodeMap.get(nodeId);
|
package/dist/index.d.cts
CHANGED
|
@@ -803,6 +803,7 @@ declare class CTreeClientDataProvider<TRow extends TDataRow = TDataRow> extends
|
|
|
803
803
|
private _sortedNodeIdsCache;
|
|
804
804
|
private _filteredNodesCache;
|
|
805
805
|
private _allVisibleRowsCache;
|
|
806
|
+
private _decryptedNodeMap;
|
|
806
807
|
invalidateStaticCache(): void;
|
|
807
808
|
setFilter(filter: IDataFilter | null, immediate?: boolean): void;
|
|
808
809
|
protected onFilterUpdated(): void;
|
|
@@ -1622,6 +1623,13 @@ declare abstract class AEncryptionProvider implements IEncryptionProvider {
|
|
|
1622
1623
|
* - If payload is an array of objects: decrypts each row.
|
|
1623
1624
|
* - If payload is an object: decrypts any encrypted value cells across fields.
|
|
1624
1625
|
*/
|
|
1626
|
+
/**
|
|
1627
|
+
* Top-level polymorphic decryption method.
|
|
1628
|
+
* Automatically performs value-level decryption:
|
|
1629
|
+
* - If payload is an encrypted envelope: decrypts directly via decryptValue.
|
|
1630
|
+
* - If payload is an array of objects: decrypts each row (batched with local memoization).
|
|
1631
|
+
* - If payload is an object: decrypts any encrypted value cells across fields.
|
|
1632
|
+
*/
|
|
1625
1633
|
decrypt(payload: any, options?: IEncryptionContext): Promise<any>;
|
|
1626
1634
|
}
|
|
1627
1635
|
|
package/dist/index.d.mts
CHANGED
|
@@ -803,6 +803,7 @@ declare class CTreeClientDataProvider<TRow extends TDataRow = TDataRow> extends
|
|
|
803
803
|
private _sortedNodeIdsCache;
|
|
804
804
|
private _filteredNodesCache;
|
|
805
805
|
private _allVisibleRowsCache;
|
|
806
|
+
private _decryptedNodeMap;
|
|
806
807
|
invalidateStaticCache(): void;
|
|
807
808
|
setFilter(filter: IDataFilter | null, immediate?: boolean): void;
|
|
808
809
|
protected onFilterUpdated(): void;
|
|
@@ -1622,6 +1623,13 @@ declare abstract class AEncryptionProvider implements IEncryptionProvider {
|
|
|
1622
1623
|
* - If payload is an array of objects: decrypts each row.
|
|
1623
1624
|
* - If payload is an object: decrypts any encrypted value cells across fields.
|
|
1624
1625
|
*/
|
|
1626
|
+
/**
|
|
1627
|
+
* Top-level polymorphic decryption method.
|
|
1628
|
+
* Automatically performs value-level decryption:
|
|
1629
|
+
* - If payload is an encrypted envelope: decrypts directly via decryptValue.
|
|
1630
|
+
* - If payload is an array of objects: decrypts each row (batched with local memoization).
|
|
1631
|
+
* - If payload is an object: decrypts any encrypted value cells across fields.
|
|
1632
|
+
*/
|
|
1625
1633
|
decrypt(payload: any, options?: IEncryptionContext): Promise<any>;
|
|
1626
1634
|
}
|
|
1627
1635
|
|
package/dist/index.d.ts
CHANGED
|
@@ -803,6 +803,7 @@ declare class CTreeClientDataProvider<TRow extends TDataRow = TDataRow> extends
|
|
|
803
803
|
private _sortedNodeIdsCache;
|
|
804
804
|
private _filteredNodesCache;
|
|
805
805
|
private _allVisibleRowsCache;
|
|
806
|
+
private _decryptedNodeMap;
|
|
806
807
|
invalidateStaticCache(): void;
|
|
807
808
|
setFilter(filter: IDataFilter | null, immediate?: boolean): void;
|
|
808
809
|
protected onFilterUpdated(): void;
|
|
@@ -1622,6 +1623,13 @@ declare abstract class AEncryptionProvider implements IEncryptionProvider {
|
|
|
1622
1623
|
* - If payload is an array of objects: decrypts each row.
|
|
1623
1624
|
* - If payload is an object: decrypts any encrypted value cells across fields.
|
|
1624
1625
|
*/
|
|
1626
|
+
/**
|
|
1627
|
+
* Top-level polymorphic decryption method.
|
|
1628
|
+
* Automatically performs value-level decryption:
|
|
1629
|
+
* - If payload is an encrypted envelope: decrypts directly via decryptValue.
|
|
1630
|
+
* - If payload is an array of objects: decrypts each row (batched with local memoization).
|
|
1631
|
+
* - If payload is an object: decrypts any encrypted value cells across fields.
|
|
1632
|
+
*/
|
|
1625
1633
|
decrypt(payload: any, options?: IEncryptionContext): Promise<any>;
|
|
1626
1634
|
}
|
|
1627
1635
|
|
package/dist/index.mjs
CHANGED
|
@@ -885,13 +885,84 @@ class AEncryptionProvider {
|
|
|
885
885
|
* - If payload is an array of objects: decrypts each row.
|
|
886
886
|
* - If payload is an object: decrypts any encrypted value cells across fields.
|
|
887
887
|
*/
|
|
888
|
+
/**
|
|
889
|
+
* Top-level polymorphic decryption method.
|
|
890
|
+
* Automatically performs value-level decryption:
|
|
891
|
+
* - If payload is an encrypted envelope: decrypts directly via decryptValue.
|
|
892
|
+
* - If payload is an array of objects: decrypts each row (batched with local memoization).
|
|
893
|
+
* - If payload is an object: decrypts any encrypted value cells across fields.
|
|
894
|
+
*/
|
|
888
895
|
async decrypt(payload, options) {
|
|
889
896
|
if (payload === void 0 || payload === null) return payload;
|
|
890
897
|
if (this.isEncrypted(payload)) {
|
|
891
898
|
return this.decryptValue(payload, options);
|
|
892
899
|
}
|
|
893
900
|
if (Array.isArray(payload)) {
|
|
894
|
-
|
|
901
|
+
if (payload.length === 0) return payload;
|
|
902
|
+
const localMemo = /* @__PURE__ */ new Map();
|
|
903
|
+
const decryptRow = async (item) => {
|
|
904
|
+
if (!item) return item;
|
|
905
|
+
if (this.isEncrypted(item)) {
|
|
906
|
+
const ct = item.ciphertext;
|
|
907
|
+
const iv = item.iv || "";
|
|
908
|
+
const aadPart = options?.aad ? typeof options.aad === "string" ? options.aad : "" : "";
|
|
909
|
+
const memoKey = `${ct}:${iv}:${aadPart}`;
|
|
910
|
+
if (!localMemo.has(memoKey)) {
|
|
911
|
+
localMemo.set(memoKey, this.decryptValue(item, options));
|
|
912
|
+
}
|
|
913
|
+
return localMemo.get(memoKey);
|
|
914
|
+
}
|
|
915
|
+
if (typeof item === "object" && !ArrayBuffer.isView(item) && !(item instanceof ArrayBuffer)) {
|
|
916
|
+
const targetKeys = options?.fields && options.fields.length > 0 ? options.fields.filter((f) => Object.prototype.hasOwnProperty.call(item, f)) : Object.keys(item);
|
|
917
|
+
const keysToDecrypt = targetKeys.filter((key) => this.isEncrypted(item[key]));
|
|
918
|
+
if (keysToDecrypt.length === 0) {
|
|
919
|
+
return item;
|
|
920
|
+
}
|
|
921
|
+
const proto = Object.getPrototypeOf(item);
|
|
922
|
+
const result = proto && proto !== Object.prototype ? Object.assign(Object.create(proto), item) : { ...item };
|
|
923
|
+
await Promise.all(
|
|
924
|
+
keysToDecrypt.map(async (key) => {
|
|
925
|
+
const env = item[key];
|
|
926
|
+
const boundOptions = this._bindFieldAad(item, key, options);
|
|
927
|
+
const hasBoundAad = boundOptions.aad !== options?.aad;
|
|
928
|
+
const ct = env.ciphertext;
|
|
929
|
+
const iv = env.iv || "";
|
|
930
|
+
const aadPart = boundOptions.aad ? typeof boundOptions.aad === "string" ? boundOptions.aad : "" : "";
|
|
931
|
+
const memoKey = `${ct}:${iv}:${aadPart}`;
|
|
932
|
+
if (!localMemo.has(memoKey)) {
|
|
933
|
+
const decryptPromise = this.decryptValue(env, boundOptions).catch((err) => {
|
|
934
|
+
if (hasBoundAad && isAuthOrDecryptionError(err)) {
|
|
935
|
+
return this.decryptValue(env, options);
|
|
936
|
+
}
|
|
937
|
+
throw err;
|
|
938
|
+
});
|
|
939
|
+
localMemo.set(memoKey, decryptPromise);
|
|
940
|
+
}
|
|
941
|
+
const decryptedVal = await localMemo.get(memoKey);
|
|
942
|
+
safeSetProperty(result, key, decryptedVal);
|
|
943
|
+
})
|
|
944
|
+
);
|
|
945
|
+
return result;
|
|
946
|
+
}
|
|
947
|
+
return item;
|
|
948
|
+
};
|
|
949
|
+
if (payload.length <= 100) {
|
|
950
|
+
return Promise.all(payload.map(decryptRow));
|
|
951
|
+
}
|
|
952
|
+
const batchSize = 1e3;
|
|
953
|
+
const results = new Array(payload.length);
|
|
954
|
+
for (let i = 0; i < payload.length; i += batchSize) {
|
|
955
|
+
const end = Math.min(i + batchSize, payload.length);
|
|
956
|
+
const chunk = payload.slice(i, end);
|
|
957
|
+
const chunkRes = await Promise.all(chunk.map(decryptRow));
|
|
958
|
+
for (let j = 0; j < chunkRes.length; j++) {
|
|
959
|
+
results[i + j] = chunkRes[j];
|
|
960
|
+
}
|
|
961
|
+
if (end < payload.length && (i > 0 && i % 5e3 === 0)) {
|
|
962
|
+
await new Promise((r) => setTimeout(r, 0));
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
return results;
|
|
895
966
|
}
|
|
896
967
|
if (typeof payload === "object" && !ArrayBuffer.isView(payload) && !(payload instanceof ArrayBuffer)) {
|
|
897
968
|
const targetKeys = options?.fields && options.fields.length > 0 ? options.fields.filter((f) => Object.prototype.hasOwnProperty.call(payload, f)) : Object.keys(payload);
|
|
@@ -4780,15 +4851,24 @@ class CFlatClientDataProvider extends AEncryptedClientProvider {
|
|
|
4780
4851
|
this.error = null;
|
|
4781
4852
|
try {
|
|
4782
4853
|
this._computeFilteredAndSorted();
|
|
4783
|
-
if (this.
|
|
4784
|
-
|
|
4785
|
-
|
|
4786
|
-
|
|
4787
|
-
|
|
4788
|
-
for (let i = 0; i < rows.length; i++) {
|
|
4789
|
-
this._rowMap[startIndex + i] = rows[i];
|
|
4854
|
+
if (this.pageSize <= 0) {
|
|
4855
|
+
if (this._rowMap && this._rowMap.length > 0) {
|
|
4856
|
+
const { rows, decrypted } = await this.decryptRows(this._rowMap);
|
|
4857
|
+
if (decrypted) {
|
|
4858
|
+
this._rowMap = rows;
|
|
4790
4859
|
}
|
|
4791
4860
|
}
|
|
4861
|
+
this.pageData = this._rowMap;
|
|
4862
|
+
} else {
|
|
4863
|
+
const startIndex = (this.currentPage - 1) * this.pageSize;
|
|
4864
|
+
const endIndex = startIndex + this.pageSize;
|
|
4865
|
+
const pageSlice = this._rowMap.slice(startIndex, endIndex);
|
|
4866
|
+
if (pageSlice && pageSlice.length > 0) {
|
|
4867
|
+
const { rows, decrypted } = await this.decryptRows(pageSlice);
|
|
4868
|
+
this.pageData = decrypted ? rows : pageSlice;
|
|
4869
|
+
} else {
|
|
4870
|
+
this.pageData = [];
|
|
4871
|
+
}
|
|
4792
4872
|
}
|
|
4793
4873
|
} catch (err) {
|
|
4794
4874
|
this.error = err;
|
|
@@ -7404,6 +7484,7 @@ class CTreeClientDataProvider extends CFlatClientDataProvider {
|
|
|
7404
7484
|
_sortedNodeIdsCache = null;
|
|
7405
7485
|
_filteredNodesCache = null;
|
|
7406
7486
|
_allVisibleRowsCache = null;
|
|
7487
|
+
_decryptedNodeMap = /* @__PURE__ */ new Map();
|
|
7407
7488
|
invalidateStaticCache() {
|
|
7408
7489
|
this._staticNodesCache = null;
|
|
7409
7490
|
this._nodeMapCache = null;
|
|
@@ -7451,6 +7532,7 @@ class CTreeClientDataProvider extends CFlatClientDataProvider {
|
|
|
7451
7532
|
this.updatePageData();
|
|
7452
7533
|
}
|
|
7453
7534
|
_applyTreeData(rows) {
|
|
7535
|
+
this._decryptedNodeMap.clear();
|
|
7454
7536
|
this.invalidateStaticCache();
|
|
7455
7537
|
this.allData = rows;
|
|
7456
7538
|
this._filterDirty = true;
|
|
@@ -7754,22 +7836,30 @@ class CTreeClientDataProvider extends CFlatClientDataProvider {
|
|
|
7754
7836
|
const filteredNodes = this._filteredNodesCache;
|
|
7755
7837
|
this.filteredData = filteredNodes;
|
|
7756
7838
|
const paginated = this.paginateNodes(filteredNodes);
|
|
7757
|
-
this.pageData = paginated.map((node) =>
|
|
7758
|
-
|
|
7759
|
-
...node,
|
|
7760
|
-
|
|
7761
|
-
|
|
7839
|
+
this.pageData = paginated.map((node) => {
|
|
7840
|
+
const decrypted = this.isEncryptionEnabled ? this._decryptedNodeMap.get(node.id) : void 0;
|
|
7841
|
+
const nodeData = decrypted ? { ...node.data, ...decrypted } : node.data;
|
|
7842
|
+
return {
|
|
7843
|
+
...nodeData,
|
|
7844
|
+
...node,
|
|
7845
|
+
__treeNode: node
|
|
7846
|
+
};
|
|
7847
|
+
});
|
|
7762
7848
|
if (this.allData.length > 0) {
|
|
7763
7849
|
this.initialLoad = false;
|
|
7764
7850
|
}
|
|
7765
7851
|
return;
|
|
7766
7852
|
}
|
|
7767
7853
|
const visible = this.visibleRows;
|
|
7768
|
-
this.pageData = visible.map((node) =>
|
|
7769
|
-
|
|
7770
|
-
...node,
|
|
7771
|
-
|
|
7772
|
-
|
|
7854
|
+
this.pageData = visible.map((node) => {
|
|
7855
|
+
const decrypted = this.isEncryptionEnabled ? this._decryptedNodeMap.get(node.id) : void 0;
|
|
7856
|
+
const nodeData = decrypted ? { ...node.data, ...decrypted } : node.data;
|
|
7857
|
+
return {
|
|
7858
|
+
...nodeData,
|
|
7859
|
+
...node,
|
|
7860
|
+
__treeNode: node
|
|
7861
|
+
};
|
|
7862
|
+
});
|
|
7773
7863
|
if (this.allData.length > 0) {
|
|
7774
7864
|
this.initialLoad = false;
|
|
7775
7865
|
}
|
|
@@ -7805,19 +7895,53 @@ class CTreeClientDataProvider extends CFlatClientDataProvider {
|
|
|
7805
7895
|
this.loading = true;
|
|
7806
7896
|
this.error = null;
|
|
7807
7897
|
try {
|
|
7808
|
-
this.
|
|
7809
|
-
|
|
7810
|
-
const {
|
|
7811
|
-
|
|
7812
|
-
|
|
7813
|
-
|
|
7814
|
-
|
|
7815
|
-
|
|
7816
|
-
|
|
7898
|
+
const visibleNodes = this.allVisibleNodes.map((node) => {
|
|
7899
|
+
const decrypted = this._decryptedNodeMap.get(node.id);
|
|
7900
|
+
const nodeData = decrypted ? { ...node.data, ...decrypted } : node.data;
|
|
7901
|
+
return {
|
|
7902
|
+
...nodeData,
|
|
7903
|
+
...node,
|
|
7904
|
+
__treeNode: node
|
|
7905
|
+
};
|
|
7906
|
+
});
|
|
7907
|
+
if (this.pageSize <= 0) {
|
|
7908
|
+
if (visibleNodes.length > 0) {
|
|
7909
|
+
const { rows, decrypted } = await this.decryptRows(visibleNodes);
|
|
7910
|
+
if (decrypted) {
|
|
7911
|
+
for (const r of rows) {
|
|
7912
|
+
const id = r[this.idKey] ?? r.id;
|
|
7913
|
+
if (id !== void 0 && id !== null) {
|
|
7914
|
+
this._decryptedNodeMap.set(id, r);
|
|
7915
|
+
}
|
|
7817
7916
|
}
|
|
7818
7917
|
}
|
|
7918
|
+
this._allVisibleRowsCache = decrypted ? rows : visibleNodes;
|
|
7919
|
+
} else {
|
|
7920
|
+
this._allVisibleRowsCache = [];
|
|
7921
|
+
}
|
|
7922
|
+
this.pageData = [...this._allVisibleRowsCache];
|
|
7923
|
+
} else {
|
|
7924
|
+
this._allVisibleRowsCache = null;
|
|
7925
|
+
const startIndex = (this.currentPage - 1) * this.pageSize;
|
|
7926
|
+
const pageSlice = visibleNodes.slice(startIndex, startIndex + this.pageSize);
|
|
7927
|
+
if (pageSlice.length > 0) {
|
|
7928
|
+
const { rows, decrypted } = await this.decryptRows(pageSlice);
|
|
7929
|
+
if (decrypted) {
|
|
7930
|
+
for (const r of rows) {
|
|
7931
|
+
const id = r[this.idKey] ?? r.id;
|
|
7932
|
+
if (id !== void 0 && id !== null) {
|
|
7933
|
+
this._decryptedNodeMap.set(id, r);
|
|
7934
|
+
}
|
|
7935
|
+
}
|
|
7936
|
+
}
|
|
7937
|
+
this.pageData = decrypted ? rows : pageSlice;
|
|
7938
|
+
} else {
|
|
7939
|
+
this.pageData = [];
|
|
7819
7940
|
}
|
|
7820
7941
|
}
|
|
7942
|
+
if (this.allData.length > 0) {
|
|
7943
|
+
this.initialLoad = false;
|
|
7944
|
+
}
|
|
7821
7945
|
} catch (err) {
|
|
7822
7946
|
this.error = err;
|
|
7823
7947
|
console.warn("[Katlux Providers] CTreeClientDataProvider loadPageData error", err);
|
|
@@ -7829,6 +7953,7 @@ class CTreeClientDataProvider extends CFlatClientDataProvider {
|
|
|
7829
7953
|
}
|
|
7830
7954
|
clearEncryption() {
|
|
7831
7955
|
super.clearEncryption();
|
|
7956
|
+
this._decryptedNodeMap.clear();
|
|
7832
7957
|
this._filterDirty = true;
|
|
7833
7958
|
this._sortDirty = true;
|
|
7834
7959
|
this._filteredNodesCache = null;
|
|
@@ -7869,11 +7994,15 @@ class CTreeClientDataProvider extends CFlatClientDataProvider {
|
|
|
7869
7994
|
}
|
|
7870
7995
|
get allVisibleRows() {
|
|
7871
7996
|
if (!this._allVisibleRowsCache) {
|
|
7872
|
-
this._allVisibleRowsCache = this.allVisibleNodes.map((node) =>
|
|
7873
|
-
|
|
7874
|
-
...node,
|
|
7875
|
-
|
|
7876
|
-
|
|
7997
|
+
this._allVisibleRowsCache = this.allVisibleNodes.map((node) => {
|
|
7998
|
+
const decrypted = this.isEncryptionEnabled ? this._decryptedNodeMap.get(node.id) : void 0;
|
|
7999
|
+
const nodeData = decrypted ? { ...node.data, ...decrypted } : node.data;
|
|
8000
|
+
return {
|
|
8001
|
+
...nodeData,
|
|
8002
|
+
...node,
|
|
8003
|
+
__treeNode: node
|
|
8004
|
+
};
|
|
8005
|
+
});
|
|
7877
8006
|
if (this.isEncryptionEnabled && this.pageData && this.pageData.length > 0) {
|
|
7878
8007
|
const startIndex = this.pageSize <= 0 ? 0 : (this.currentPage - 1) * this.pageSize;
|
|
7879
8008
|
for (let i = 0; i < this.pageData.length; i++) {
|
|
@@ -7904,6 +8033,9 @@ class CTreeClientDataProvider extends CFlatClientDataProvider {
|
|
|
7904
8033
|
}
|
|
7905
8034
|
this.updatePageData();
|
|
7906
8035
|
this.notify();
|
|
8036
|
+
if (this.isEncryptionEnabled) {
|
|
8037
|
+
this.loadPageData();
|
|
8038
|
+
}
|
|
7907
8039
|
}
|
|
7908
8040
|
expand(nodeId) {
|
|
7909
8041
|
if (this.filter && this.filter.active) {
|
|
@@ -7913,6 +8045,9 @@ class CTreeClientDataProvider extends CFlatClientDataProvider {
|
|
|
7913
8045
|
this.expandedNodes.add(nodeId);
|
|
7914
8046
|
this.updatePageData();
|
|
7915
8047
|
this.notify();
|
|
8048
|
+
if (this.isEncryptionEnabled) {
|
|
8049
|
+
this.loadPageData();
|
|
8050
|
+
}
|
|
7916
8051
|
}
|
|
7917
8052
|
collapse(nodeId) {
|
|
7918
8053
|
if (this.filter && this.filter.active) {
|
|
@@ -7922,6 +8057,9 @@ class CTreeClientDataProvider extends CFlatClientDataProvider {
|
|
|
7922
8057
|
this.expandedNodes.delete(nodeId);
|
|
7923
8058
|
this.updatePageData();
|
|
7924
8059
|
this.notify();
|
|
8060
|
+
if (this.isEncryptionEnabled) {
|
|
8061
|
+
this.loadPageData();
|
|
8062
|
+
}
|
|
7925
8063
|
}
|
|
7926
8064
|
expandNode(nodeId) {
|
|
7927
8065
|
this.expand(nodeId);
|
|
@@ -7938,6 +8076,9 @@ class CTreeClientDataProvider extends CFlatClientDataProvider {
|
|
|
7938
8076
|
this.expandedNodes = new Set(allIds);
|
|
7939
8077
|
this.updatePageData();
|
|
7940
8078
|
this.notify();
|
|
8079
|
+
if (this.isEncryptionEnabled) {
|
|
8080
|
+
this.loadPageData();
|
|
8081
|
+
}
|
|
7941
8082
|
}
|
|
7942
8083
|
collapseAll() {
|
|
7943
8084
|
if (this.filter && this.filter.active) {
|
|
@@ -7947,6 +8088,9 @@ class CTreeClientDataProvider extends CFlatClientDataProvider {
|
|
|
7947
8088
|
this.expandedNodes = /* @__PURE__ */ new Set();
|
|
7948
8089
|
this.updatePageData();
|
|
7949
8090
|
this.notify();
|
|
8091
|
+
if (this.isEncryptionEnabled) {
|
|
8092
|
+
this.loadPageData();
|
|
8093
|
+
}
|
|
7950
8094
|
}
|
|
7951
8095
|
getNode(nodeId) {
|
|
7952
8096
|
const staticNode = this._nodeMap.get(nodeId);
|