@hypequery/clickhouse 1.4.0-beta.2 → 1.4.0
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/README.md +65 -2
- package/dist/cli/bin.js +65 -23
- package/dist/cli/generate-types.js +41 -3
- package/dist/core/cache/cache-manager.d.ts +4 -0
- package/dist/core/cache/cache-manager.d.ts.map +1 -0
- package/dist/core/cache/cache-manager.js +176 -0
- package/dist/core/cache/controller.d.ts +15 -0
- package/dist/core/cache/controller.d.ts.map +1 -0
- package/dist/core/cache/controller.js +58 -0
- package/dist/core/cache/key.d.ts +11 -0
- package/dist/core/cache/key.d.ts.map +1 -0
- package/dist/core/cache/key.js +26 -0
- package/dist/core/cache/providers/memory-lru.d.ts +31 -0
- package/dist/core/cache/providers/memory-lru.d.ts.map +1 -0
- package/dist/core/cache/providers/memory-lru.js +156 -0
- package/dist/core/cache/providers/noop.d.ts +7 -0
- package/dist/core/cache/providers/noop.d.ts.map +1 -0
- package/dist/core/cache/providers/noop.js +11 -0
- package/dist/core/cache/runtime-context.d.ts +30 -0
- package/dist/core/cache/runtime-context.d.ts.map +1 -0
- package/dist/core/cache/runtime-context.js +58 -0
- package/dist/core/cache/serialization.d.ts +6 -0
- package/dist/core/cache/serialization.d.ts.map +1 -0
- package/dist/core/cache/serialization.js +166 -0
- package/dist/core/cache/types.d.ts +52 -0
- package/dist/core/cache/types.d.ts.map +1 -0
- package/dist/core/cache/types.js +1 -0
- package/dist/core/cache/utils.d.ts +9 -0
- package/dist/core/cache/utils.d.ts.map +1 -0
- package/dist/core/cache/utils.js +30 -0
- package/dist/core/connection.d.ts.map +1 -1
- package/dist/core/connection.js +4 -3
- package/dist/core/cross-filter.d.ts +12 -9
- package/dist/core/cross-filter.d.ts.map +1 -1
- package/dist/core/cross-filter.js +9 -6
- package/dist/core/env/auto-client.browser.d.ts +3 -0
- package/dist/core/env/auto-client.browser.d.ts.map +1 -0
- package/dist/core/env/auto-client.browser.js +3 -0
- package/dist/core/env/auto-client.d.ts +9 -0
- package/dist/core/env/auto-client.d.ts.map +1 -0
- package/dist/core/env/auto-client.js +21 -0
- package/dist/core/features/aggregations.d.ts +18 -22
- package/dist/core/features/aggregations.d.ts.map +1 -1
- package/dist/core/features/aggregations.js +6 -6
- package/dist/core/features/analytics.d.ts +15 -19
- package/dist/core/features/analytics.d.ts.map +1 -1
- package/dist/core/features/analytics.js +2 -2
- package/dist/core/features/cross-filtering.d.ts +4 -24
- package/dist/core/features/cross-filtering.d.ts.map +1 -1
- package/dist/core/features/cross-filtering.js +0 -34
- package/dist/core/features/executor.d.ts +11 -9
- package/dist/core/features/executor.d.ts.map +1 -1
- package/dist/core/features/executor.js +14 -5
- package/dist/core/features/filtering.d.ts +32 -28
- package/dist/core/features/filtering.d.ts.map +1 -1
- package/dist/core/features/filtering.js +27 -26
- package/dist/core/features/joins.d.ts +7 -10
- package/dist/core/features/joins.d.ts.map +1 -1
- package/dist/core/features/pagination.d.ts +8 -10
- package/dist/core/features/pagination.d.ts.map +1 -1
- package/dist/core/features/pagination.js +15 -42
- package/dist/core/features/query-modifiers.d.ts +18 -21
- package/dist/core/features/query-modifiers.d.ts.map +1 -1
- package/dist/core/formatters/sql-formatter.d.ts.map +1 -1
- package/dist/core/formatters/sql-formatter.js +6 -0
- package/dist/core/join-relationships.d.ts +2 -1
- package/dist/core/join-relationships.d.ts.map +1 -1
- package/dist/core/query-builder.d.ts +69 -74
- package/dist/core/query-builder.d.ts.map +1 -1
- package/dist/core/query-builder.js +155 -114
- package/dist/core/tests/integration/pagination-test-tbc.js +1 -0
- package/dist/core/tests/integration/setup.d.ts +8 -1
- package/dist/core/tests/integration/setup.d.ts.map +1 -1
- package/dist/core/tests/integration/setup.js +55 -22
- package/dist/core/tests/integration/test-config.d.ts +2 -2
- package/dist/core/tests/integration/test-config.d.ts.map +1 -1
- package/dist/core/tests/integration/test-config.js +3 -4
- package/dist/core/tests/integration/test-data.json +190 -0
- package/dist/core/tests/test-utils.d.ts +18 -3
- package/dist/core/tests/test-utils.d.ts.map +1 -1
- package/dist/core/tests/test-utils.js +37 -10
- package/dist/core/types/builder-state.d.ts +25 -0
- package/dist/core/types/builder-state.d.ts.map +1 -0
- package/dist/core/types/builder-state.js +1 -0
- package/dist/core/types/select-types.d.ts +32 -0
- package/dist/core/types/select-types.d.ts.map +1 -0
- package/dist/core/types/select-types.js +1 -0
- package/dist/core/types/type-helpers.d.ts +5 -0
- package/dist/core/types/type-helpers.d.ts.map +1 -0
- package/dist/core/types/type-helpers.js +1 -0
- package/dist/core/utils/logger.d.ts +6 -0
- package/dist/core/utils/logger.d.ts.map +1 -1
- package/dist/core/utils/logger.js +7 -2
- package/dist/core/utils/predicate-builder.d.ts +29 -0
- package/dist/core/utils/predicate-builder.d.ts.map +1 -0
- package/dist/core/utils/predicate-builder.js +92 -0
- package/dist/core/utils/sql-expressions.d.ts +24 -10
- package/dist/core/utils/sql-expressions.d.ts.map +1 -1
- package/dist/core/utils/sql-expressions.js +7 -30
- package/dist/core/utils/streaming-helpers.d.ts +2 -0
- package/dist/core/utils/streaming-helpers.d.ts.map +1 -0
- package/dist/core/utils/streaming-helpers.js +137 -0
- package/dist/core/validators/filter-validator.d.ts +2 -1
- package/dist/core/validators/filter-validator.d.ts.map +1 -1
- package/dist/core/validators/value-validator.d.ts +2 -1
- package/dist/core/validators/value-validator.d.ts.map +1 -1
- package/dist/index.d.ts +11 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/types/base.d.ts +10 -15
- package/dist/types/base.d.ts.map +1 -1
- package/dist/types/clickhouse-types.d.ts +9 -4
- package/dist/types/clickhouse-types.d.ts.map +1 -1
- package/dist/types/filters.d.ts +1 -1
- package/dist/types/filters.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +2 -0
- package/dist/types/schema.d.ts +19 -0
- package/dist/types/schema.d.ts.map +1 -0
- package/dist/types/schema.js +1 -0
- package/package.json +14 -12
- package/dist/core/tests/integration/test-initializer.d.ts +0 -7
- package/dist/core/tests/integration/test-initializer.d.ts.map +0 -1
- package/dist/core/tests/integration/test-initializer.js +0 -32
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
function extractNamespace(key) {
|
|
2
|
+
const parts = key.split(':');
|
|
3
|
+
if (parts.length < 4) {
|
|
4
|
+
return 'default';
|
|
5
|
+
}
|
|
6
|
+
if (parts.length === 4) {
|
|
7
|
+
return parts[2];
|
|
8
|
+
}
|
|
9
|
+
// Namespace may contain additional ':' (e.g., protocol prefixes); rejoin everything
|
|
10
|
+
// between the version segment and the trailing table/digest tokens.
|
|
11
|
+
const namespace = parts.slice(2, -2).join(':');
|
|
12
|
+
return namespace || 'default';
|
|
13
|
+
}
|
|
14
|
+
export class MemoryCacheProvider {
|
|
15
|
+
entries = new Map();
|
|
16
|
+
tagIndex = new Map();
|
|
17
|
+
currentBytes = 0;
|
|
18
|
+
maxEntries;
|
|
19
|
+
maxBytes;
|
|
20
|
+
cleanupIntervalMs;
|
|
21
|
+
cleanupTimer;
|
|
22
|
+
constructor(options = {}) {
|
|
23
|
+
this.maxEntries = options.maxEntries ?? 1000;
|
|
24
|
+
this.maxBytes = options.maxBytes ?? 50 * 1024 * 1024;
|
|
25
|
+
this.cleanupIntervalMs = options.cleanupIntervalMs ?? 30_000;
|
|
26
|
+
if (this.cleanupIntervalMs > 0 && typeof setInterval !== 'undefined') {
|
|
27
|
+
this.cleanupTimer = setInterval(() => this.cleanup(), this.cleanupIntervalMs);
|
|
28
|
+
const timer = this.cleanupTimer;
|
|
29
|
+
if (typeof timer.unref === 'function') {
|
|
30
|
+
timer.unref();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
dispose() {
|
|
35
|
+
if (this.cleanupTimer) {
|
|
36
|
+
clearInterval(this.cleanupTimer);
|
|
37
|
+
this.cleanupTimer = undefined;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
async get(key) {
|
|
41
|
+
this.cleanup();
|
|
42
|
+
const entry = this.entries.get(key);
|
|
43
|
+
if (!entry)
|
|
44
|
+
return null;
|
|
45
|
+
if (entry.cacheTimeMs > 0 && Date.now() > entry.createdAt + entry.cacheTimeMs) {
|
|
46
|
+
await this.delete(key);
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
this.touch(key, entry);
|
|
50
|
+
return entry;
|
|
51
|
+
}
|
|
52
|
+
async set(key, entry) {
|
|
53
|
+
const existing = this.entries.get(key);
|
|
54
|
+
if (existing) {
|
|
55
|
+
this.currentBytes -= existing.byteSize || 0;
|
|
56
|
+
this.unindexTags(key, existing.tags);
|
|
57
|
+
}
|
|
58
|
+
this.entries.set(key, entry);
|
|
59
|
+
this.currentBytes += entry.byteSize || 0;
|
|
60
|
+
this.indexTags(key, entry.tags);
|
|
61
|
+
this.enforceLimits();
|
|
62
|
+
}
|
|
63
|
+
async delete(key) {
|
|
64
|
+
const entry = this.entries.get(key);
|
|
65
|
+
if (!entry)
|
|
66
|
+
return;
|
|
67
|
+
this.entries.delete(key);
|
|
68
|
+
this.currentBytes -= entry.byteSize || 0;
|
|
69
|
+
this.unindexTags(key, entry.tags);
|
|
70
|
+
}
|
|
71
|
+
async deleteByTag(namespace, tag) {
|
|
72
|
+
const indexKey = this.getTagIndexKey(namespace, tag);
|
|
73
|
+
const keys = this.tagIndex.get(indexKey);
|
|
74
|
+
if (!keys)
|
|
75
|
+
return;
|
|
76
|
+
for (const key of keys) {
|
|
77
|
+
await this.delete(key);
|
|
78
|
+
}
|
|
79
|
+
this.tagIndex.delete(indexKey);
|
|
80
|
+
}
|
|
81
|
+
async clearNamespace(namespace) {
|
|
82
|
+
const keys = Array.from(this.entries.keys());
|
|
83
|
+
await Promise.all(keys.map(key => {
|
|
84
|
+
if (extractNamespace(key) === namespace) {
|
|
85
|
+
return this.delete(key);
|
|
86
|
+
}
|
|
87
|
+
return Promise.resolve();
|
|
88
|
+
}));
|
|
89
|
+
}
|
|
90
|
+
touch(key, entry) {
|
|
91
|
+
this.entries.delete(key);
|
|
92
|
+
this.entries.set(key, entry);
|
|
93
|
+
}
|
|
94
|
+
enforceLimits() {
|
|
95
|
+
while (this.entries.size > this.maxEntries || this.currentBytes > this.maxBytes) {
|
|
96
|
+
const oldestKey = this.entries.keys().next().value;
|
|
97
|
+
if (!oldestKey)
|
|
98
|
+
break;
|
|
99
|
+
this.delete(oldestKey);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
cleanup() {
|
|
103
|
+
if (!this.entries.size)
|
|
104
|
+
return;
|
|
105
|
+
const now = Date.now();
|
|
106
|
+
for (const [key, entry] of this.entries) {
|
|
107
|
+
if (entry.cacheTimeMs > 0 && now > entry.createdAt + entry.cacheTimeMs) {
|
|
108
|
+
this.delete(key);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
this.cleanupTagIndex();
|
|
112
|
+
}
|
|
113
|
+
indexTags(key, tags) {
|
|
114
|
+
if (!tags || !tags.length)
|
|
115
|
+
return;
|
|
116
|
+
const namespace = extractNamespace(key);
|
|
117
|
+
tags.forEach(tag => {
|
|
118
|
+
const indexKey = this.getTagIndexKey(namespace, tag);
|
|
119
|
+
if (!this.tagIndex.has(indexKey)) {
|
|
120
|
+
this.tagIndex.set(indexKey, new Set());
|
|
121
|
+
}
|
|
122
|
+
this.tagIndex.get(indexKey).add(key);
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
unindexTags(key, tags) {
|
|
126
|
+
if (!tags || !tags.length)
|
|
127
|
+
return;
|
|
128
|
+
const namespace = extractNamespace(key);
|
|
129
|
+
tags.forEach(tag => {
|
|
130
|
+
const indexKey = this.getTagIndexKey(namespace, tag);
|
|
131
|
+
const bucket = this.tagIndex.get(indexKey);
|
|
132
|
+
if (!bucket)
|
|
133
|
+
return;
|
|
134
|
+
bucket.delete(key);
|
|
135
|
+
if (!bucket.size) {
|
|
136
|
+
this.tagIndex.delete(indexKey);
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
getTagIndexKey(namespace, tag) {
|
|
141
|
+
return `${namespace}:${tag}`;
|
|
142
|
+
}
|
|
143
|
+
cleanupTagIndex() {
|
|
144
|
+
for (const [indexKey, keys] of this.tagIndex) {
|
|
145
|
+
for (const key of keys) {
|
|
146
|
+
if (!this.entries.has(key)) {
|
|
147
|
+
keys.delete(key);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (!keys.size) {
|
|
151
|
+
this.tagIndex.delete(indexKey);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
export { MemoryCacheProvider as MemoryLRUCacheProvider };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { CacheEntry, CacheProvider } from '../types.js';
|
|
2
|
+
export declare class NoopCacheProvider implements CacheProvider {
|
|
3
|
+
get(_key: string): Promise<CacheEntry | null>;
|
|
4
|
+
set(_key: string, _entry: CacheEntry): Promise<void>;
|
|
5
|
+
delete(_key: string): Promise<void>;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=noop.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"noop.d.ts","sourceRoot":"","sources":["../../../../src/core/cache/providers/noop.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE7D,qBAAa,iBAAkB,YAAW,aAAa;IAC/C,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;IAI7C,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAIpD,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAG1C"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { CacheConfig, CacheOptions, CacheProvider, CacheSerializeFn, CacheDeserializeFn, CacheStats } from './types.js';
|
|
2
|
+
export interface QueryRuntimeContext {
|
|
3
|
+
provider?: CacheProvider;
|
|
4
|
+
defaults: CacheOptions;
|
|
5
|
+
namespace: string;
|
|
6
|
+
versionTag: string;
|
|
7
|
+
serialize: CacheSerializeFn;
|
|
8
|
+
deserialize: CacheDeserializeFn;
|
|
9
|
+
inFlight: Map<string, Promise<unknown>>;
|
|
10
|
+
stats: CacheStats;
|
|
11
|
+
parsedValues: Map<string, ParsedValueEntry>;
|
|
12
|
+
}
|
|
13
|
+
export interface ParsedValueEntry {
|
|
14
|
+
createdAt: number;
|
|
15
|
+
rows: unknown;
|
|
16
|
+
tags?: string[];
|
|
17
|
+
}
|
|
18
|
+
export declare function createCacheStats(): CacheStats;
|
|
19
|
+
export declare function mergeCacheOptions(...candidates: Array<CacheOptions | undefined>): CacheOptions;
|
|
20
|
+
export interface CacheRuntimeConfig {
|
|
21
|
+
namespace: string;
|
|
22
|
+
versionTag: string;
|
|
23
|
+
provider?: CacheProvider;
|
|
24
|
+
defaults: CacheOptions;
|
|
25
|
+
serialize: CacheSerializeFn;
|
|
26
|
+
deserialize: CacheDeserializeFn;
|
|
27
|
+
}
|
|
28
|
+
export declare function buildRuntimeContext(config: CacheRuntimeConfig): QueryRuntimeContext;
|
|
29
|
+
export declare function resolveCacheConfig(config: CacheConfig | undefined, fallbackNamespace: string): CacheRuntimeConfig;
|
|
30
|
+
//# sourceMappingURL=runtime-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-context.d.ts","sourceRoot":"","sources":["../../../src/core/cache/runtime-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,kBAAkB,EAClB,UAAU,EACX,MAAM,YAAY,CAAC;AAWpB,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,EA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leIfError: false,
|
|
7
|
+
dedupe: true
|
|
8
|
+
};
|
|
9
|
+
export function createCacheStats() {
|
|
10
|
+
return { hits: 0, misses: 0, staleHits: 0, revalidations: 0 };
|
|
11
|
+
}
|
|
12
|
+
function uniqueTags(left, right) {
|
|
13
|
+
const combined = [...(left || []), ...(right || [])];
|
|
14
|
+
if (!combined.length)
|
|
15
|
+
return undefined;
|
|
16
|
+
return Array.from(new Set(combined));
|
|
17
|
+
}
|
|
18
|
+
export function mergeCacheOptions(...candidates) {
|
|
19
|
+
return candidates.reduce((acc, candidate) => {
|
|
20
|
+
if (!candidate)
|
|
21
|
+
return acc;
|
|
22
|
+
const next = { ...acc };
|
|
23
|
+
for (const [key, value] of Object.entries(candidate)) {
|
|
24
|
+
if (key === 'tags') {
|
|
25
|
+
next.tags = uniqueTags(next.tags, value);
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (value !== undefined) {
|
|
29
|
+
next[key] = value;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return next;
|
|
33
|
+
}, { ...DEFAULT_CACHE_OPTIONS });
|
|
34
|
+
}
|
|
35
|
+
export function buildRuntimeContext(config) {
|
|
36
|
+
return {
|
|
37
|
+
provider: config.provider,
|
|
38
|
+
defaults: { ...config.defaults },
|
|
39
|
+
namespace: config.namespace,
|
|
40
|
+
versionTag: config.versionTag,
|
|
41
|
+
serialize: config.serialize,
|
|
42
|
+
deserialize: config.deserialize,
|
|
43
|
+
inFlight: new Map(),
|
|
44
|
+
stats: createCacheStats(),
|
|
45
|
+
parsedValues: new Map()
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
export function resolveCacheConfig(config, fallbackNamespace) {
|
|
49
|
+
const defaults = mergeCacheOptions(config);
|
|
50
|
+
return {
|
|
51
|
+
namespace: config?.namespace || fallbackNamespace,
|
|
52
|
+
versionTag: config?.versionTag || 'v1',
|
|
53
|
+
provider: config?.provider,
|
|
54
|
+
defaults,
|
|
55
|
+
serialize: config?.serialize || ((value) => defaultSerialize(value)),
|
|
56
|
+
deserialize: config?.deserialize || ((raw) => defaultDeserialize(raw))
|
|
57
|
+
};
|
|
58
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CacheSerializationResult } from './types.js';
|
|
2
|
+
export declare function stableStringify(value: unknown): string;
|
|
3
|
+
export declare function defaultSerialize(value: unknown): CacheSerializationResult;
|
|
4
|
+
export declare function defaultDeserialize<T = unknown>(raw: string | Uint8Array): T;
|
|
5
|
+
export declare function estimateByteSize(value: unknown): number;
|
|
6
|
+
//# sourceMappingURL=serialization.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialization.d.ts","sourceRoot":"","sources":["../../../src/core/cache/serialization.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAiH3D,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAEtD;AAyDD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,wBAAwB,CAOzE;AAED,wBAAgB,kBAAkB,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,UAAU,GAAG,CAAC,CAQ3E;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAMvD"}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
const encoder = typeof TextEncoder !== 'undefined' ? new TextEncoder() : null;
|
|
2
|
+
const decoder = typeof TextDecoder !== 'undefined' ? new TextDecoder() : null;
|
|
3
|
+
const TYPE_KEY = '__hq_type';
|
|
4
|
+
function hasBuffer() {
|
|
5
|
+
return typeof globalThis !== 'undefined' && typeof globalThis.Buffer !== 'undefined';
|
|
6
|
+
}
|
|
7
|
+
function bufferFrom(bytes) {
|
|
8
|
+
return globalThis.Buffer.from(bytes);
|
|
9
|
+
}
|
|
10
|
+
function bufferToUint8(buffer) {
|
|
11
|
+
return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
12
|
+
}
|
|
13
|
+
function toBase64(bytes) {
|
|
14
|
+
if (hasBuffer()) {
|
|
15
|
+
return bufferFrom(bytes).toString('base64');
|
|
16
|
+
}
|
|
17
|
+
let binary = '';
|
|
18
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
19
|
+
binary += String.fromCharCode(bytes[i]);
|
|
20
|
+
}
|
|
21
|
+
if (typeof btoa !== 'undefined') {
|
|
22
|
+
return btoa(binary);
|
|
23
|
+
}
|
|
24
|
+
throw new Error('Base64 encoding not supported in this environment.');
|
|
25
|
+
}
|
|
26
|
+
function fromBase64(value) {
|
|
27
|
+
if (hasBuffer()) {
|
|
28
|
+
const buf = globalThis.Buffer.from(value, 'base64');
|
|
29
|
+
return bufferToUint8(buf);
|
|
30
|
+
}
|
|
31
|
+
if (typeof atob === 'undefined') {
|
|
32
|
+
throw new Error('Base64 decoding not supported in this environment.');
|
|
33
|
+
}
|
|
34
|
+
const binary = atob(value);
|
|
35
|
+
const bytes = new Uint8Array(binary.length);
|
|
36
|
+
for (let i = 0; i < binary.length; i++) {
|
|
37
|
+
bytes[i] = binary.charCodeAt(i);
|
|
38
|
+
}
|
|
39
|
+
return bytes;
|
|
40
|
+
}
|
|
41
|
+
function normalizeForStable(value) {
|
|
42
|
+
if (value === null || typeof value === 'number' || typeof value === 'boolean') {
|
|
43
|
+
return Number.isNaN(value)
|
|
44
|
+
? { [TYPE_KEY]: 'nan', value: 'NaN' }
|
|
45
|
+
: value;
|
|
46
|
+
}
|
|
47
|
+
if (typeof value === 'string') {
|
|
48
|
+
return value;
|
|
49
|
+
}
|
|
50
|
+
if (typeof value === 'bigint') {
|
|
51
|
+
return { [TYPE_KEY]: 'bigint', value: value.toString() };
|
|
52
|
+
}
|
|
53
|
+
if (typeof value === 'undefined') {
|
|
54
|
+
return { [TYPE_KEY]: 'undefined' };
|
|
55
|
+
}
|
|
56
|
+
if (value instanceof Date) {
|
|
57
|
+
return { [TYPE_KEY]: 'date', value: value.toISOString() };
|
|
58
|
+
}
|
|
59
|
+
if (Array.isArray(value)) {
|
|
60
|
+
return value.map(item => normalizeForStable(item));
|
|
61
|
+
}
|
|
62
|
+
if (value instanceof Set) {
|
|
63
|
+
return Array.from(value.values())
|
|
64
|
+
.map(item => normalizeForStable(item))
|
|
65
|
+
.sort((a, b) => JSON.stringify(a).localeCompare(JSON.stringify(b)));
|
|
66
|
+
}
|
|
67
|
+
if (value instanceof Map) {
|
|
68
|
+
const entries = Array.from(value.entries()).sort(([a], [b]) => String(a).localeCompare(String(b)));
|
|
69
|
+
const normalized = {};
|
|
70
|
+
for (const [key, val] of entries) {
|
|
71
|
+
normalized[String(key)] = normalizeForStable(val);
|
|
72
|
+
}
|
|
73
|
+
return normalized;
|
|
74
|
+
}
|
|
75
|
+
if (typeof ArrayBuffer !== 'undefined' && ArrayBuffer.isView(value)) {
|
|
76
|
+
const uint8 = new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
|
|
77
|
+
return { [TYPE_KEY]: 'u8', value: toBase64(uint8) };
|
|
78
|
+
}
|
|
79
|
+
if (value && typeof value === 'object') {
|
|
80
|
+
const raw = value;
|
|
81
|
+
const keys = Object.keys(raw).sort();
|
|
82
|
+
const normalized = {};
|
|
83
|
+
for (const key of keys) {
|
|
84
|
+
normalized[key] = normalizeForStable(raw[key]);
|
|
85
|
+
}
|
|
86
|
+
return normalized;
|
|
87
|
+
}
|
|
88
|
+
return { [TYPE_KEY]: 'unknown', value: String(value) };
|
|
89
|
+
}
|
|
90
|
+
export function stableStringify(value) {
|
|
91
|
+
return JSON.stringify(normalizeForStable(value));
|
|
92
|
+
}
|
|
93
|
+
function encodeSpecial(value) {
|
|
94
|
+
if (typeof value === 'bigint') {
|
|
95
|
+
return { [TYPE_KEY]: 'bigint', value: value.toString() };
|
|
96
|
+
}
|
|
97
|
+
if (value instanceof Date) {
|
|
98
|
+
return { [TYPE_KEY]: 'date', value: value.toISOString() };
|
|
99
|
+
}
|
|
100
|
+
if (typeof value === 'undefined') {
|
|
101
|
+
return { [TYPE_KEY]: 'undefined' };
|
|
102
|
+
}
|
|
103
|
+
if (typeof ArrayBuffer !== 'undefined' && ArrayBuffer.isView(value)) {
|
|
104
|
+
const uint8 = new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
|
|
105
|
+
return { [TYPE_KEY]: 'u8', value: toBase64(uint8) };
|
|
106
|
+
}
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
function decodeSpecial(value) {
|
|
110
|
+
switch (value[TYPE_KEY]) {
|
|
111
|
+
case 'bigint':
|
|
112
|
+
return value.value !== undefined ? BigInt(value.value) : undefined;
|
|
113
|
+
case 'date':
|
|
114
|
+
return value.value ? new Date(value.value) : null;
|
|
115
|
+
case 'undefined':
|
|
116
|
+
return undefined;
|
|
117
|
+
case 'u8':
|
|
118
|
+
if (!value.value)
|
|
119
|
+
return new Uint8Array();
|
|
120
|
+
return fromBase64(value.value);
|
|
121
|
+
case 'nan':
|
|
122
|
+
return Number.NaN;
|
|
123
|
+
default:
|
|
124
|
+
return value.value;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
function reviveSpecialValues(value) {
|
|
128
|
+
if (!value || typeof value !== 'object') {
|
|
129
|
+
return value;
|
|
130
|
+
}
|
|
131
|
+
if (value[TYPE_KEY]) {
|
|
132
|
+
return decodeSpecial(value);
|
|
133
|
+
}
|
|
134
|
+
if (Array.isArray(value)) {
|
|
135
|
+
return value.map(item => reviveSpecialValues(item));
|
|
136
|
+
}
|
|
137
|
+
const record = value;
|
|
138
|
+
for (const key of Object.keys(record)) {
|
|
139
|
+
record[key] = reviveSpecialValues(record[key]);
|
|
140
|
+
}
|
|
141
|
+
return record;
|
|
142
|
+
}
|
|
143
|
+
export function defaultSerialize(value) {
|
|
144
|
+
const json = JSON.stringify(value, (_key, val) => encodeSpecial(val) ?? val);
|
|
145
|
+
if (!encoder) {
|
|
146
|
+
return { payload: json, byteSize: json.length };
|
|
147
|
+
}
|
|
148
|
+
const bytes = encoder.encode(json);
|
|
149
|
+
return { payload: bytes, byteSize: bytes.byteLength };
|
|
150
|
+
}
|
|
151
|
+
export function defaultDeserialize(raw) {
|
|
152
|
+
const json = typeof raw === 'string'
|
|
153
|
+
? raw
|
|
154
|
+
: encoder && decoder
|
|
155
|
+
? decoder.decode(raw)
|
|
156
|
+
: new TextDecoder().decode(raw);
|
|
157
|
+
const parsed = JSON.parse(json);
|
|
158
|
+
return reviveSpecialValues(parsed);
|
|
159
|
+
}
|
|
160
|
+
export function estimateByteSize(value) {
|
|
161
|
+
const json = JSON.stringify(value);
|
|
162
|
+
if (!encoder) {
|
|
163
|
+
return json.length;
|
|
164
|
+
}
|
|
165
|
+
return encoder.encode(json).byteLength;
|
|
166
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export type HypeQueryCacheMode = 'no-store' | 'cache-first' | 'network-first' | 'stale-while-revalidate';
|
|
2
|
+
export interface CacheSerializationResult {
|
|
3
|
+
payload: string | Uint8Array;
|
|
4
|
+
byteSize: number;
|
|
5
|
+
}
|
|
6
|
+
export type CacheSerializeFn = (value: unknown) => CacheSerializationResult | Promise<CacheSerializationResult>;
|
|
7
|
+
export type CacheDeserializeFn<T = unknown> = (raw: string | Uint8Array) => T | Promise<T>;
|
|
8
|
+
export type CacheStatus = 'hit' | 'miss' | 'stale-hit' | 'revalidate' | 'bypass';
|
|
9
|
+
export interface CacheOptions {
|
|
10
|
+
mode?: HypeQueryCacheMode;
|
|
11
|
+
ttlMs?: number;
|
|
12
|
+
staleTtlMs?: number;
|
|
13
|
+
cacheTimeMs?: number;
|
|
14
|
+
staleIfError?: boolean;
|
|
15
|
+
dedupe?: boolean;
|
|
16
|
+
tags?: string[];
|
|
17
|
+
key?: string;
|
|
18
|
+
namespace?: string;
|
|
19
|
+
serialize?: CacheSerializeFn;
|
|
20
|
+
deserialize?: CacheDeserializeFn;
|
|
21
|
+
}
|
|
22
|
+
export interface CacheConfig extends CacheOptions {
|
|
23
|
+
provider?: CacheProvider;
|
|
24
|
+
versionTag?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface CacheEntry<TSerialized = string | Uint8Array> {
|
|
27
|
+
value: TSerialized;
|
|
28
|
+
createdAt: number;
|
|
29
|
+
ttlMs: number;
|
|
30
|
+
staleTtlMs: number;
|
|
31
|
+
cacheTimeMs: number;
|
|
32
|
+
tags?: string[];
|
|
33
|
+
rowCount?: number;
|
|
34
|
+
byteSize?: number;
|
|
35
|
+
sqlFingerprint?: string;
|
|
36
|
+
metadata?: Record<string, unknown>;
|
|
37
|
+
status?: 'pending' | 'fulfilled' | 'revalidating' | 'error';
|
|
38
|
+
}
|
|
39
|
+
export interface CacheProvider<TSerialized = string | Uint8Array> {
|
|
40
|
+
get(key: string): Promise<CacheEntry<TSerialized> | null>;
|
|
41
|
+
set(key: string, entry: CacheEntry<TSerialized>): Promise<void>;
|
|
42
|
+
delete(key: string): Promise<void>;
|
|
43
|
+
deleteByTag?(namespace: string, tag: string): Promise<void>;
|
|
44
|
+
clearNamespace?(namespace: string): Promise<void>;
|
|
45
|
+
}
|
|
46
|
+
export interface CacheStats {
|
|
47
|
+
hits: number;
|
|
48
|
+
misses: number;
|
|
49
|
+
staleHits: number;
|
|
50
|
+
revalidations: number;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/core/cache/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,kBAAkB,GAC1B,UAAU,GACV,aAAa,GACb,eAAe,GACf,wBAAwB,CAAC;AAE7B,MAAM,WAAW,wBAAwB;IACvC,OAAO,EAAE,MAAM,GAAG,UAAU,CAAC;IAC7B,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,MAAM,gBAAgB,GAAG,CAAC,KAAK,EAAE,OAAO,KAAK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M,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,MAAM,CAAC,EAAE,SAAS,GAAG,WAAW,GAAG,cAAc,GAAG,OAAO,CAAC;CAC7D;AAED,MAAM,WAAW,aAAa,CAAC,WAAW,GAAG,MAAM,GAAG,UAAU;IAC9D,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC,CAAC;IAC1D,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,CAAC,WAAW,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChE,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnC,WAAW,CAAC,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5D,cAAc,CAAC,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACnD;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;CACvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { CacheConfig, CacheOptions } from './types.js';
|
|
2
|
+
import type { QueryRuntimeContext } from './runtime-context.js';
|
|
3
|
+
import { CacheController } from './controller.js';
|
|
4
|
+
export declare function mergeCacheOptionsPartial(target: CacheOptions | undefined, update: CacheOptions): CacheOptions;
|
|
5
|
+
export declare function initializeCacheRuntime(cacheConfig: CacheConfig | undefined, namespace: string): {
|
|
6
|
+
runtime: QueryRuntimeContext;
|
|
7
|
+
cacheController: CacheController;
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/core/cache/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC5D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAIlD,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,YAAY,GAAG,SAAS,EAAE,MAAM,EAAE,YAAY,GAAG,YAAY,CAgB7G;AAED,wBAAgB,sBAAsB,CACpC,WAAW,EAAE,WAAW,GAAG,SAAS,EACpC,SAAS,EAAE,MAAM,GAChB;IAAE,OAAO,EAAE,mBAAmB,CAAC;IAAC,eAAe,EAAE,eAAe,CAAA;CAAE,CASpE"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { CacheController } from './controller.js';
|
|
2
|
+
import { buildRuntimeContext, resolveCacheConfig } from './runtime-context.js';
|
|
3
|
+
import { MemoryCacheProvider } from './providers/memory-lru.js';
|
|
4
|
+
export function mergeCacheOptionsPartial(target, update) {
|
|
5
|
+
const result = { ...(target || {}) };
|
|
6
|
+
for (const [key, value] of Object.entries(update)) {
|
|
7
|
+
if (key === 'tags') {
|
|
8
|
+
const existing = result.tags || [];
|
|
9
|
+
const incoming = value || [];
|
|
10
|
+
if (incoming.length) {
|
|
11
|
+
result.tags = Array.from(new Set([...existing, ...incoming]));
|
|
12
|
+
}
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
if (value !== undefined) {
|
|
16
|
+
result[key] = value;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
export function initializeCacheRuntime(cacheConfig, namespace) {
|
|
22
|
+
const provider = cacheConfig?.provider ?? (cacheConfig ? new MemoryCacheProvider() : undefined);
|
|
23
|
+
const mergedCacheConfig = cacheConfig
|
|
24
|
+
? { ...cacheConfig, namespace, provider }
|
|
25
|
+
: { namespace, provider };
|
|
26
|
+
const runtimeConfig = resolveCacheConfig(mergedCacheConfig, namespace);
|
|
27
|
+
const runtime = buildRuntimeContext(runtimeConfig);
|
|
28
|
+
const cacheController = new CacheController(runtime);
|
|
29
|
+
return { runtime, cacheController };
|
|
30
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../src/core/connection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,KAAK,EAAE,gBAAgB,IAAI,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AACnF,OAAO,KAAK,EAAE,gBAAgB,IAAI,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../src/core/connection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,KAAK,EAAE,gBAAgB,IAAI,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AACnF,OAAO,KAAK,EAAE,gBAAgB,IAAI,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AACtF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAM3D,KAAK,gBAAgB,GAAG,oBAAoB,GAAG,mBAAmB,CAAC;AAsCnE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAiC;IACxD,OAAO,CAAC,MAAM,CAAC,YAAY,CAAuC;IAElE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACH,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,oBAAoB;IAaxE;;;;;;;;;;;;;;OAcG;IACH,MAAM,CAAC,SAAS,IAAI,gBAAgB;IAOpC;;;;;OAKG;IACH,MAAM,CAAC,qBAAqB,IAAI,kBAAkB;CAGnD"}
|
package/dist/core/connection.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createClient as createNodeClient } from '@clickhouse/client';
|
|
2
1
|
import { isClientConfig } from './query-builder.js';
|
|
2
|
+
import { getAutoClientModule } from './env/auto-client.js';
|
|
3
3
|
// Function to synchronously get the appropriate client
|
|
4
4
|
function getClickHouseClientSync() {
|
|
5
5
|
const isDev = process.env.NODE_ENV === 'development';
|
|
@@ -9,9 +9,10 @@ function getClickHouseClientSync() {
|
|
|
9
9
|
if (isDev) {
|
|
10
10
|
console.log('hypequery: Using @clickhouse/client for Node.js environment');
|
|
11
11
|
}
|
|
12
|
+
const clientModule = getAutoClientModule();
|
|
12
13
|
return {
|
|
13
|
-
createClient:
|
|
14
|
-
ClickHouseSettings: {}
|
|
14
|
+
createClient: clientModule.createClient,
|
|
15
|
+
ClickHouseSettings: clientModule.ClickHouseSettings || {}
|
|
15
16
|
};
|
|
16
17
|
}
|
|
17
18
|
// For browser environments, require() doesn't work, so we can't auto-detect
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { FilterConditionInput, FilterOperator, OperatorValueMap } from '../types/index.js';
|
|
2
|
-
import type { ColumnType, InferColumnType } from '../types/
|
|
3
|
-
|
|
2
|
+
import type { ColumnType, InferColumnType } from '../types/schema.js';
|
|
3
|
+
import type { SchemaDefinition } from './types/builder-state.js';
|
|
4
|
+
type GenericSchema = Record<string, Record<string, ColumnType>>;
|
|
5
|
+
type GenericSchemaDefinition = SchemaDefinition<GenericSchema>;
|
|
6
|
+
export interface FilterGroup<Schema extends SchemaDefinition<Schema> = GenericSchemaDefinition, OriginalT extends Record<string, any> = Record<string, any>> {
|
|
4
7
|
operator: 'AND' | 'OR';
|
|
5
8
|
conditions: Array<FilterConditionInput<any, Schema, OriginalT> | FilterGroup<Schema, OriginalT>>;
|
|
6
9
|
limit?: number;
|
|
@@ -14,14 +17,13 @@ export interface FilterGroup<Schema extends Record<string, Record<string, any>>
|
|
|
14
17
|
* @template Schema - The full database schema type
|
|
15
18
|
* @template TableName - The specific table being filtered
|
|
16
19
|
*/
|
|
17
|
-
export declare class CrossFilter<Schema extends {
|
|
18
|
-
[tableName: string]: {
|
|
19
|
-
[columnName: string]: ColumnType;
|
|
20
|
-
};
|
|
21
|
-
} = any, TableName extends keyof Schema = Extract<keyof Schema, string>> {
|
|
22
|
-
private schema?;
|
|
20
|
+
export declare class CrossFilter<Schema extends SchemaDefinition<Schema> = GenericSchemaDefinition, TableName extends keyof Schema & string = Extract<keyof Schema, string>> {
|
|
23
21
|
private rootGroup;
|
|
24
|
-
|
|
22
|
+
private schema?;
|
|
23
|
+
private targetTable?;
|
|
24
|
+
constructor();
|
|
25
|
+
constructor(schema: Schema);
|
|
26
|
+
constructor(schema: Schema, tableName: TableName);
|
|
25
27
|
/**
|
|
26
28
|
* Adds a single filter condition to the root group with an implicit AND conjunction.
|
|
27
29
|
* Performs type-safe validation if a schema is provided.
|
|
@@ -67,4 +69,5 @@ export declare class CrossFilter<Schema extends {
|
|
|
67
69
|
*/
|
|
68
70
|
topN<K extends keyof Schema[TableName]>(valueColumn: K, n: number, orderBy?: 'desc' | 'asc'): this;
|
|
69
71
|
}
|
|
72
|
+
export {};
|
|
70
73
|
//# sourceMappingURL=cross-filter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cross-filter.d.ts","sourceRoot":"","sources":["../../src/core/cross-filter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC3F,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"cross-filter.d.ts","sourceRoot":"","sources":["../../src/core/cross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