@katlux/providers 0.1.1-alpha.121 → 0.1.1-alpha.122
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 +154 -31
- 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 +154 -31
- 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,16 +4868,19 @@ class CFlatClientDataProvider extends AEncryptedClientProvider {
|
|
|
4797
4868
|
this.error = null;
|
|
4798
4869
|
try {
|
|
4799
4870
|
this._computeFilteredAndSorted();
|
|
4800
|
-
if (this.
|
|
4801
|
-
const { rows, decrypted } = await this.decryptRows(this.
|
|
4871
|
+
if (this._rowMap && this._rowMap.length > 0) {
|
|
4872
|
+
const { rows, decrypted } = await this.decryptRows(this._rowMap);
|
|
4802
4873
|
if (decrypted) {
|
|
4803
|
-
this.
|
|
4804
|
-
const startIndex = this.pageSize <= 0 ? 0 : (this.currentPage - 1) * this.pageSize;
|
|
4805
|
-
for (let i = 0; i < rows.length; i++) {
|
|
4806
|
-
this._rowMap[startIndex + i] = rows[i];
|
|
4807
|
-
}
|
|
4874
|
+
this._rowMap = rows;
|
|
4808
4875
|
}
|
|
4809
4876
|
}
|
|
4877
|
+
if (this.pageSize <= 0) {
|
|
4878
|
+
this.pageData = this._rowMap;
|
|
4879
|
+
} else {
|
|
4880
|
+
const startIndex = (this.currentPage - 1) * this.pageSize;
|
|
4881
|
+
const endIndex = startIndex + this.pageSize;
|
|
4882
|
+
this.pageData = this._rowMap.slice(startIndex, endIndex);
|
|
4883
|
+
}
|
|
4810
4884
|
} catch (err) {
|
|
4811
4885
|
this.error = err;
|
|
4812
4886
|
console.warn("[Katlux Providers] CFlatClientDataProvider loadPageData error", err);
|
|
@@ -7421,6 +7495,7 @@ class CTreeClientDataProvider extends CFlatClientDataProvider {
|
|
|
7421
7495
|
_sortedNodeIdsCache = null;
|
|
7422
7496
|
_filteredNodesCache = null;
|
|
7423
7497
|
_allVisibleRowsCache = null;
|
|
7498
|
+
_decryptedNodeMap = /* @__PURE__ */ new Map();
|
|
7424
7499
|
invalidateStaticCache() {
|
|
7425
7500
|
this._staticNodesCache = null;
|
|
7426
7501
|
this._nodeMapCache = null;
|
|
@@ -7468,6 +7543,7 @@ class CTreeClientDataProvider extends CFlatClientDataProvider {
|
|
|
7468
7543
|
this.updatePageData();
|
|
7469
7544
|
}
|
|
7470
7545
|
_applyTreeData(rows) {
|
|
7546
|
+
this._decryptedNodeMap.clear();
|
|
7471
7547
|
this.invalidateStaticCache();
|
|
7472
7548
|
this.allData = rows;
|
|
7473
7549
|
this._filterDirty = true;
|
|
@@ -7771,22 +7847,30 @@ class CTreeClientDataProvider extends CFlatClientDataProvider {
|
|
|
7771
7847
|
const filteredNodes = this._filteredNodesCache;
|
|
7772
7848
|
this.filteredData = filteredNodes;
|
|
7773
7849
|
const paginated = this.paginateNodes(filteredNodes);
|
|
7774
|
-
this.pageData = paginated.map((node) =>
|
|
7775
|
-
|
|
7776
|
-
...node,
|
|
7777
|
-
|
|
7778
|
-
|
|
7850
|
+
this.pageData = paginated.map((node) => {
|
|
7851
|
+
const decrypted = this.isEncryptionEnabled ? this._decryptedNodeMap.get(node.id) : void 0;
|
|
7852
|
+
const nodeData = decrypted ? { ...node.data, ...decrypted } : node.data;
|
|
7853
|
+
return {
|
|
7854
|
+
...nodeData,
|
|
7855
|
+
...node,
|
|
7856
|
+
__treeNode: node
|
|
7857
|
+
};
|
|
7858
|
+
});
|
|
7779
7859
|
if (this.allData.length > 0) {
|
|
7780
7860
|
this.initialLoad = false;
|
|
7781
7861
|
}
|
|
7782
7862
|
return;
|
|
7783
7863
|
}
|
|
7784
7864
|
const visible = this.visibleRows;
|
|
7785
|
-
this.pageData = visible.map((node) =>
|
|
7786
|
-
|
|
7787
|
-
...node,
|
|
7788
|
-
|
|
7789
|
-
|
|
7865
|
+
this.pageData = visible.map((node) => {
|
|
7866
|
+
const decrypted = this.isEncryptionEnabled ? this._decryptedNodeMap.get(node.id) : void 0;
|
|
7867
|
+
const nodeData = decrypted ? { ...node.data, ...decrypted } : node.data;
|
|
7868
|
+
return {
|
|
7869
|
+
...nodeData,
|
|
7870
|
+
...node,
|
|
7871
|
+
__treeNode: node
|
|
7872
|
+
};
|
|
7873
|
+
});
|
|
7790
7874
|
if (this.allData.length > 0) {
|
|
7791
7875
|
this.initialLoad = false;
|
|
7792
7876
|
}
|
|
@@ -7822,18 +7906,37 @@ class CTreeClientDataProvider extends CFlatClientDataProvider {
|
|
|
7822
7906
|
this.loading = true;
|
|
7823
7907
|
this.error = null;
|
|
7824
7908
|
try {
|
|
7825
|
-
this.
|
|
7826
|
-
|
|
7827
|
-
const {
|
|
7909
|
+
const visibleNodes = this.allVisibleNodes.map((node) => {
|
|
7910
|
+
const decrypted = this._decryptedNodeMap.get(node.id);
|
|
7911
|
+
const nodeData = decrypted ? { ...node.data, ...decrypted } : node.data;
|
|
7912
|
+
return {
|
|
7913
|
+
...nodeData,
|
|
7914
|
+
...node,
|
|
7915
|
+
__treeNode: node
|
|
7916
|
+
};
|
|
7917
|
+
});
|
|
7918
|
+
if (visibleNodes.length > 0) {
|
|
7919
|
+
const { rows, decrypted } = await this.decryptRows(visibleNodes);
|
|
7828
7920
|
if (decrypted) {
|
|
7829
|
-
|
|
7830
|
-
|
|
7831
|
-
|
|
7832
|
-
|
|
7833
|
-
this._allVisibleRowsCache[startIndex + i] = rows[i];
|
|
7921
|
+
for (const r of rows) {
|
|
7922
|
+
const id = r[this.idKey] ?? r.id;
|
|
7923
|
+
if (id !== void 0 && id !== null) {
|
|
7924
|
+
this._decryptedNodeMap.set(id, r);
|
|
7834
7925
|
}
|
|
7835
7926
|
}
|
|
7836
7927
|
}
|
|
7928
|
+
this._allVisibleRowsCache = decrypted ? rows : visibleNodes;
|
|
7929
|
+
} else {
|
|
7930
|
+
this._allVisibleRowsCache = [];
|
|
7931
|
+
}
|
|
7932
|
+
if (this.pageSize <= 0) {
|
|
7933
|
+
this.pageData = [...this._allVisibleRowsCache];
|
|
7934
|
+
} else {
|
|
7935
|
+
const startIndex = (this.currentPage - 1) * this.pageSize;
|
|
7936
|
+
this.pageData = this._allVisibleRowsCache.slice(startIndex, startIndex + this.pageSize);
|
|
7937
|
+
}
|
|
7938
|
+
if (this.allData.length > 0) {
|
|
7939
|
+
this.initialLoad = false;
|
|
7837
7940
|
}
|
|
7838
7941
|
} catch (err) {
|
|
7839
7942
|
this.error = err;
|
|
@@ -7846,6 +7949,7 @@ class CTreeClientDataProvider extends CFlatClientDataProvider {
|
|
|
7846
7949
|
}
|
|
7847
7950
|
clearEncryption() {
|
|
7848
7951
|
super.clearEncryption();
|
|
7952
|
+
this._decryptedNodeMap.clear();
|
|
7849
7953
|
this._filterDirty = true;
|
|
7850
7954
|
this._sortDirty = true;
|
|
7851
7955
|
this._filteredNodesCache = null;
|
|
@@ -7886,11 +7990,15 @@ class CTreeClientDataProvider extends CFlatClientDataProvider {
|
|
|
7886
7990
|
}
|
|
7887
7991
|
get allVisibleRows() {
|
|
7888
7992
|
if (!this._allVisibleRowsCache) {
|
|
7889
|
-
this._allVisibleRowsCache = this.allVisibleNodes.map((node) =>
|
|
7890
|
-
|
|
7891
|
-
...node,
|
|
7892
|
-
|
|
7893
|
-
|
|
7993
|
+
this._allVisibleRowsCache = this.allVisibleNodes.map((node) => {
|
|
7994
|
+
const decrypted = this.isEncryptionEnabled ? this._decryptedNodeMap.get(node.id) : void 0;
|
|
7995
|
+
const nodeData = decrypted ? { ...node.data, ...decrypted } : node.data;
|
|
7996
|
+
return {
|
|
7997
|
+
...nodeData,
|
|
7998
|
+
...node,
|
|
7999
|
+
__treeNode: node
|
|
8000
|
+
};
|
|
8001
|
+
});
|
|
7894
8002
|
if (this.isEncryptionEnabled && this.pageData && this.pageData.length > 0) {
|
|
7895
8003
|
const startIndex = this.pageSize <= 0 ? 0 : (this.currentPage - 1) * this.pageSize;
|
|
7896
8004
|
for (let i = 0; i < this.pageData.length; i++) {
|
|
@@ -7921,6 +8029,9 @@ class CTreeClientDataProvider extends CFlatClientDataProvider {
|
|
|
7921
8029
|
}
|
|
7922
8030
|
this.updatePageData();
|
|
7923
8031
|
this.notify();
|
|
8032
|
+
if (this.isEncryptionEnabled) {
|
|
8033
|
+
this.loadPageData();
|
|
8034
|
+
}
|
|
7924
8035
|
}
|
|
7925
8036
|
expand(nodeId) {
|
|
7926
8037
|
if (this.filter && this.filter.active) {
|
|
@@ -7930,6 +8041,9 @@ class CTreeClientDataProvider extends CFlatClientDataProvider {
|
|
|
7930
8041
|
this.expandedNodes.add(nodeId);
|
|
7931
8042
|
this.updatePageData();
|
|
7932
8043
|
this.notify();
|
|
8044
|
+
if (this.isEncryptionEnabled) {
|
|
8045
|
+
this.loadPageData();
|
|
8046
|
+
}
|
|
7933
8047
|
}
|
|
7934
8048
|
collapse(nodeId) {
|
|
7935
8049
|
if (this.filter && this.filter.active) {
|
|
@@ -7939,6 +8053,9 @@ class CTreeClientDataProvider extends CFlatClientDataProvider {
|
|
|
7939
8053
|
this.expandedNodes.delete(nodeId);
|
|
7940
8054
|
this.updatePageData();
|
|
7941
8055
|
this.notify();
|
|
8056
|
+
if (this.isEncryptionEnabled) {
|
|
8057
|
+
this.loadPageData();
|
|
8058
|
+
}
|
|
7942
8059
|
}
|
|
7943
8060
|
expandNode(nodeId) {
|
|
7944
8061
|
this.expand(nodeId);
|
|
@@ -7955,6 +8072,9 @@ class CTreeClientDataProvider extends CFlatClientDataProvider {
|
|
|
7955
8072
|
this.expandedNodes = new Set(allIds);
|
|
7956
8073
|
this.updatePageData();
|
|
7957
8074
|
this.notify();
|
|
8075
|
+
if (this.isEncryptionEnabled) {
|
|
8076
|
+
this.loadPageData();
|
|
8077
|
+
}
|
|
7958
8078
|
}
|
|
7959
8079
|
collapseAll() {
|
|
7960
8080
|
if (this.filter && this.filter.active) {
|
|
@@ -7964,6 +8084,9 @@ class CTreeClientDataProvider extends CFlatClientDataProvider {
|
|
|
7964
8084
|
this.expandedNodes = /* @__PURE__ */ new Set();
|
|
7965
8085
|
this.updatePageData();
|
|
7966
8086
|
this.notify();
|
|
8087
|
+
if (this.isEncryptionEnabled) {
|
|
8088
|
+
this.loadPageData();
|
|
8089
|
+
}
|
|
7967
8090
|
}
|
|
7968
8091
|
getNode(nodeId) {
|
|
7969
8092
|
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,16 +4851,19 @@ class CFlatClientDataProvider extends AEncryptedClientProvider {
|
|
|
4780
4851
|
this.error = null;
|
|
4781
4852
|
try {
|
|
4782
4853
|
this._computeFilteredAndSorted();
|
|
4783
|
-
if (this.
|
|
4784
|
-
const { rows, decrypted } = await this.decryptRows(this.
|
|
4854
|
+
if (this._rowMap && this._rowMap.length > 0) {
|
|
4855
|
+
const { rows, decrypted } = await this.decryptRows(this._rowMap);
|
|
4785
4856
|
if (decrypted) {
|
|
4786
|
-
this.
|
|
4787
|
-
const startIndex = this.pageSize <= 0 ? 0 : (this.currentPage - 1) * this.pageSize;
|
|
4788
|
-
for (let i = 0; i < rows.length; i++) {
|
|
4789
|
-
this._rowMap[startIndex + i] = rows[i];
|
|
4790
|
-
}
|
|
4857
|
+
this._rowMap = rows;
|
|
4791
4858
|
}
|
|
4792
4859
|
}
|
|
4860
|
+
if (this.pageSize <= 0) {
|
|
4861
|
+
this.pageData = this._rowMap;
|
|
4862
|
+
} else {
|
|
4863
|
+
const startIndex = (this.currentPage - 1) * this.pageSize;
|
|
4864
|
+
const endIndex = startIndex + this.pageSize;
|
|
4865
|
+
this.pageData = this._rowMap.slice(startIndex, endIndex);
|
|
4866
|
+
}
|
|
4793
4867
|
} catch (err) {
|
|
4794
4868
|
this.error = err;
|
|
4795
4869
|
console.warn("[Katlux Providers] CFlatClientDataProvider loadPageData error", err);
|
|
@@ -7404,6 +7478,7 @@ class CTreeClientDataProvider extends CFlatClientDataProvider {
|
|
|
7404
7478
|
_sortedNodeIdsCache = null;
|
|
7405
7479
|
_filteredNodesCache = null;
|
|
7406
7480
|
_allVisibleRowsCache = null;
|
|
7481
|
+
_decryptedNodeMap = /* @__PURE__ */ new Map();
|
|
7407
7482
|
invalidateStaticCache() {
|
|
7408
7483
|
this._staticNodesCache = null;
|
|
7409
7484
|
this._nodeMapCache = null;
|
|
@@ -7451,6 +7526,7 @@ class CTreeClientDataProvider extends CFlatClientDataProvider {
|
|
|
7451
7526
|
this.updatePageData();
|
|
7452
7527
|
}
|
|
7453
7528
|
_applyTreeData(rows) {
|
|
7529
|
+
this._decryptedNodeMap.clear();
|
|
7454
7530
|
this.invalidateStaticCache();
|
|
7455
7531
|
this.allData = rows;
|
|
7456
7532
|
this._filterDirty = true;
|
|
@@ -7754,22 +7830,30 @@ class CTreeClientDataProvider extends CFlatClientDataProvider {
|
|
|
7754
7830
|
const filteredNodes = this._filteredNodesCache;
|
|
7755
7831
|
this.filteredData = filteredNodes;
|
|
7756
7832
|
const paginated = this.paginateNodes(filteredNodes);
|
|
7757
|
-
this.pageData = paginated.map((node) =>
|
|
7758
|
-
|
|
7759
|
-
...node,
|
|
7760
|
-
|
|
7761
|
-
|
|
7833
|
+
this.pageData = paginated.map((node) => {
|
|
7834
|
+
const decrypted = this.isEncryptionEnabled ? this._decryptedNodeMap.get(node.id) : void 0;
|
|
7835
|
+
const nodeData = decrypted ? { ...node.data, ...decrypted } : node.data;
|
|
7836
|
+
return {
|
|
7837
|
+
...nodeData,
|
|
7838
|
+
...node,
|
|
7839
|
+
__treeNode: node
|
|
7840
|
+
};
|
|
7841
|
+
});
|
|
7762
7842
|
if (this.allData.length > 0) {
|
|
7763
7843
|
this.initialLoad = false;
|
|
7764
7844
|
}
|
|
7765
7845
|
return;
|
|
7766
7846
|
}
|
|
7767
7847
|
const visible = this.visibleRows;
|
|
7768
|
-
this.pageData = visible.map((node) =>
|
|
7769
|
-
|
|
7770
|
-
...node,
|
|
7771
|
-
|
|
7772
|
-
|
|
7848
|
+
this.pageData = visible.map((node) => {
|
|
7849
|
+
const decrypted = this.isEncryptionEnabled ? this._decryptedNodeMap.get(node.id) : void 0;
|
|
7850
|
+
const nodeData = decrypted ? { ...node.data, ...decrypted } : node.data;
|
|
7851
|
+
return {
|
|
7852
|
+
...nodeData,
|
|
7853
|
+
...node,
|
|
7854
|
+
__treeNode: node
|
|
7855
|
+
};
|
|
7856
|
+
});
|
|
7773
7857
|
if (this.allData.length > 0) {
|
|
7774
7858
|
this.initialLoad = false;
|
|
7775
7859
|
}
|
|
@@ -7805,18 +7889,37 @@ class CTreeClientDataProvider extends CFlatClientDataProvider {
|
|
|
7805
7889
|
this.loading = true;
|
|
7806
7890
|
this.error = null;
|
|
7807
7891
|
try {
|
|
7808
|
-
this.
|
|
7809
|
-
|
|
7810
|
-
const {
|
|
7892
|
+
const visibleNodes = this.allVisibleNodes.map((node) => {
|
|
7893
|
+
const decrypted = this._decryptedNodeMap.get(node.id);
|
|
7894
|
+
const nodeData = decrypted ? { ...node.data, ...decrypted } : node.data;
|
|
7895
|
+
return {
|
|
7896
|
+
...nodeData,
|
|
7897
|
+
...node,
|
|
7898
|
+
__treeNode: node
|
|
7899
|
+
};
|
|
7900
|
+
});
|
|
7901
|
+
if (visibleNodes.length > 0) {
|
|
7902
|
+
const { rows, decrypted } = await this.decryptRows(visibleNodes);
|
|
7811
7903
|
if (decrypted) {
|
|
7812
|
-
|
|
7813
|
-
|
|
7814
|
-
|
|
7815
|
-
|
|
7816
|
-
this._allVisibleRowsCache[startIndex + i] = rows[i];
|
|
7904
|
+
for (const r of rows) {
|
|
7905
|
+
const id = r[this.idKey] ?? r.id;
|
|
7906
|
+
if (id !== void 0 && id !== null) {
|
|
7907
|
+
this._decryptedNodeMap.set(id, r);
|
|
7817
7908
|
}
|
|
7818
7909
|
}
|
|
7819
7910
|
}
|
|
7911
|
+
this._allVisibleRowsCache = decrypted ? rows : visibleNodes;
|
|
7912
|
+
} else {
|
|
7913
|
+
this._allVisibleRowsCache = [];
|
|
7914
|
+
}
|
|
7915
|
+
if (this.pageSize <= 0) {
|
|
7916
|
+
this.pageData = [...this._allVisibleRowsCache];
|
|
7917
|
+
} else {
|
|
7918
|
+
const startIndex = (this.currentPage - 1) * this.pageSize;
|
|
7919
|
+
this.pageData = this._allVisibleRowsCache.slice(startIndex, startIndex + this.pageSize);
|
|
7920
|
+
}
|
|
7921
|
+
if (this.allData.length > 0) {
|
|
7922
|
+
this.initialLoad = false;
|
|
7820
7923
|
}
|
|
7821
7924
|
} catch (err) {
|
|
7822
7925
|
this.error = err;
|
|
@@ -7829,6 +7932,7 @@ class CTreeClientDataProvider extends CFlatClientDataProvider {
|
|
|
7829
7932
|
}
|
|
7830
7933
|
clearEncryption() {
|
|
7831
7934
|
super.clearEncryption();
|
|
7935
|
+
this._decryptedNodeMap.clear();
|
|
7832
7936
|
this._filterDirty = true;
|
|
7833
7937
|
this._sortDirty = true;
|
|
7834
7938
|
this._filteredNodesCache = null;
|
|
@@ -7869,11 +7973,15 @@ class CTreeClientDataProvider extends CFlatClientDataProvider {
|
|
|
7869
7973
|
}
|
|
7870
7974
|
get allVisibleRows() {
|
|
7871
7975
|
if (!this._allVisibleRowsCache) {
|
|
7872
|
-
this._allVisibleRowsCache = this.allVisibleNodes.map((node) =>
|
|
7873
|
-
|
|
7874
|
-
...node,
|
|
7875
|
-
|
|
7876
|
-
|
|
7976
|
+
this._allVisibleRowsCache = this.allVisibleNodes.map((node) => {
|
|
7977
|
+
const decrypted = this.isEncryptionEnabled ? this._decryptedNodeMap.get(node.id) : void 0;
|
|
7978
|
+
const nodeData = decrypted ? { ...node.data, ...decrypted } : node.data;
|
|
7979
|
+
return {
|
|
7980
|
+
...nodeData,
|
|
7981
|
+
...node,
|
|
7982
|
+
__treeNode: node
|
|
7983
|
+
};
|
|
7984
|
+
});
|
|
7877
7985
|
if (this.isEncryptionEnabled && this.pageData && this.pageData.length > 0) {
|
|
7878
7986
|
const startIndex = this.pageSize <= 0 ? 0 : (this.currentPage - 1) * this.pageSize;
|
|
7879
7987
|
for (let i = 0; i < this.pageData.length; i++) {
|
|
@@ -7904,6 +8012,9 @@ class CTreeClientDataProvider extends CFlatClientDataProvider {
|
|
|
7904
8012
|
}
|
|
7905
8013
|
this.updatePageData();
|
|
7906
8014
|
this.notify();
|
|
8015
|
+
if (this.isEncryptionEnabled) {
|
|
8016
|
+
this.loadPageData();
|
|
8017
|
+
}
|
|
7907
8018
|
}
|
|
7908
8019
|
expand(nodeId) {
|
|
7909
8020
|
if (this.filter && this.filter.active) {
|
|
@@ -7913,6 +8024,9 @@ class CTreeClientDataProvider extends CFlatClientDataProvider {
|
|
|
7913
8024
|
this.expandedNodes.add(nodeId);
|
|
7914
8025
|
this.updatePageData();
|
|
7915
8026
|
this.notify();
|
|
8027
|
+
if (this.isEncryptionEnabled) {
|
|
8028
|
+
this.loadPageData();
|
|
8029
|
+
}
|
|
7916
8030
|
}
|
|
7917
8031
|
collapse(nodeId) {
|
|
7918
8032
|
if (this.filter && this.filter.active) {
|
|
@@ -7922,6 +8036,9 @@ class CTreeClientDataProvider extends CFlatClientDataProvider {
|
|
|
7922
8036
|
this.expandedNodes.delete(nodeId);
|
|
7923
8037
|
this.updatePageData();
|
|
7924
8038
|
this.notify();
|
|
8039
|
+
if (this.isEncryptionEnabled) {
|
|
8040
|
+
this.loadPageData();
|
|
8041
|
+
}
|
|
7925
8042
|
}
|
|
7926
8043
|
expandNode(nodeId) {
|
|
7927
8044
|
this.expand(nodeId);
|
|
@@ -7938,6 +8055,9 @@ class CTreeClientDataProvider extends CFlatClientDataProvider {
|
|
|
7938
8055
|
this.expandedNodes = new Set(allIds);
|
|
7939
8056
|
this.updatePageData();
|
|
7940
8057
|
this.notify();
|
|
8058
|
+
if (this.isEncryptionEnabled) {
|
|
8059
|
+
this.loadPageData();
|
|
8060
|
+
}
|
|
7941
8061
|
}
|
|
7942
8062
|
collapseAll() {
|
|
7943
8063
|
if (this.filter && this.filter.active) {
|
|
@@ -7947,6 +8067,9 @@ class CTreeClientDataProvider extends CFlatClientDataProvider {
|
|
|
7947
8067
|
this.expandedNodes = /* @__PURE__ */ new Set();
|
|
7948
8068
|
this.updatePageData();
|
|
7949
8069
|
this.notify();
|
|
8070
|
+
if (this.isEncryptionEnabled) {
|
|
8071
|
+
this.loadPageData();
|
|
8072
|
+
}
|
|
7950
8073
|
}
|
|
7951
8074
|
getNode(nodeId) {
|
|
7952
8075
|
const staticNode = this._nodeMap.get(nodeId);
|