@epxing/utils 0.0.0-stage → 5.3.0-beta.1
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/API.md +602 -0
- package/README.md +22 -2
- package/dist/_vendor/.pnpm/jsencrypt@3.5.4/_vendor/jsencrypt/bin/jsencrypt.min.js +1691 -0
- package/dist/_virtual/_commonjsHelpers.js +6 -0
- package/dist/_virtual/jsencrypt.min.js +31 -0
- package/dist/_virtual/jsencrypt.min2.js +4 -0
- package/dist/_virtual/preload-helper.js +88 -0
- package/dist/assets/ai-BBFn3QRy.png +0 -0
- package/dist/assets/ai_import-BxQ7Ohn6.png +0 -0
- package/dist/assets/app-DBNIokDP.png +0 -0
- package/dist/assets/approval-DGcBv-re.png +0 -0
- package/dist/assets/create_market_system-BH__UVbt.png +0 -0
- package/dist/assets/create_system-irg--ePh.png +0 -0
- package/dist/assets/custom-C-ujlHz1.png +0 -0
- package/dist/assets/default-icon-2193FMjv.png +0 -0
- package/dist/assets/ex_link-4fYPd9nh.png +0 -0
- package/dist/assets/excel-BYqRm2Y8.png +0 -0
- package/dist/assets/folder-CFVsNbjj.png +0 -0
- package/dist/assets/form-DD9HV-jN.png +0 -0
- package/dist/assets/import-tfKWbWVS.png +0 -0
- package/dist/assets/meta-Qorpi70B.png +0 -0
- package/dist/assets/module-DQrs7VAS.png +0 -0
- package/dist/assets/null-B2An29h4.png +0 -0
- package/dist/assets/option-CG02tIgh.svg +1 -0
- package/dist/assets/photo-uscRzRXF.png +0 -0
- package/dist/assets/process-Dcndu9m2.png +0 -0
- package/dist/assets/rule-DcYhYse0.png +0 -0
- package/dist/assets/service-CLYLpPl3.png +0 -0
- package/dist/assets/single_file-B3TJtJli.png +0 -0
- package/dist/assets/snapshot-history-BsVY9cVj.png +0 -0
- package/dist/assets/snapshot-manual-DBRfFHYI.png +0 -0
- package/dist/assets/snapshot-realtime-DjHnJI6C.png +0 -0
- package/dist/assets/staff-Bn_-_00l.png +0 -0
- package/dist/assets/sync_append-Bm8mtvZs.png +0 -0
- package/dist/assets/sync_append_update-DzjxqJ_U.png +0 -0
- package/dist/assets/sync_loading-D7LoNPFP.png +0 -0
- package/dist/assets/sync_replace-Cbbzz327.png +0 -0
- package/dist/assets/sync_update-Birao6Cr.png +0 -0
- package/dist/assets/userRole-D1LAdM6N.png +0 -0
- package/dist/assets/user_bg-BFHtaZjz.png +0 -0
- package/dist/src/Config.js +25 -0
- package/dist/src/asset-images.js +125 -0
- package/dist/src/assets/images/add.png.js +4 -0
- package/dist/src/assets/images/ai-button.png.js +4 -0
- package/dist/src/assets/images/ai.png.js +4 -0
- package/dist/src/assets/images/ai_import.png.js +4 -0
- package/dist/src/assets/images/app.png.js +4 -0
- package/dist/src/assets/images/approval.png.js +4 -0
- package/dist/src/assets/images/book.png.js +4 -0
- package/dist/src/assets/images/canvas-editor/alignment.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/arrow-left.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/arrow-right.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/block.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/bold.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/catalog.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/center.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/checkbox.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/close.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/codeblock.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/color.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/control.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/date.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/exit-fullscreen.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/format.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/highlight.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/hyperlink.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/image.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/italic.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/justify.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/latex.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/left.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/line-dash-dot-dot.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/line-dash-dot.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/line-dash-large-gap.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/line-dash-small-gap.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/line-dot.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/line-double.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/line-single.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/line-wavy.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/list.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/option.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/page-break.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/page-mode.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/page-scale-add.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/page-scale-minus.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/painter.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/paper-direction.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/paper-margin.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/paper-size.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/print.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/radio.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/redo.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/request-fullscreen.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/right.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/row-margin.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/search.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/separator.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/signature-undo.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/signature.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/size-add.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/size-minus.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/strikeout.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/subscript.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/superscript.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/table.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/title.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/trash.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/underline.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/undo.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/watermark.svg.js +4 -0
- package/dist/src/assets/images/canvas-editor/word-tool.svg.js +4 -0
- package/dist/src/assets/images/clear.png.js +4 -0
- package/dist/src/assets/images/create_market_system.png.js +4 -0
- package/dist/src/assets/images/create_system.png.js +4 -0
- package/dist/src/assets/images/custom.png.js +4 -0
- package/dist/src/assets/images/default-icon.png.js +4 -0
- package/dist/src/assets/images/ex_link.png.js +4 -0
- package/dist/src/assets/images/excel.png.js +4 -0
- package/dist/src/assets/images/file.png.js +4 -0
- package/dist/src/assets/images/folder.png.js +4 -0
- package/dist/src/assets/images/hall/form.png.js +4 -0
- package/dist/src/assets/images/hall/meta.png.js +4 -0
- package/dist/src/assets/images/hall/process.png.js +4 -0
- package/dist/src/assets/images/hall/rule.png.js +4 -0
- package/dist/src/assets/images/hall/service.png.js +4 -0
- package/dist/src/assets/images/hall/userRole.png.js +4 -0
- package/dist/src/assets/images/hr.png.js +4 -0
- package/dist/src/assets/images/import.png.js +4 -0
- package/dist/src/assets/images/jian.png.js +4 -0
- package/dist/src/assets/images/module.png.js +4 -0
- package/dist/src/assets/images/null.png.js +4 -0
- package/dist/src/assets/images/photo.png.js +4 -0
- package/dist/src/assets/images/qq.png.js +4 -0
- package/dist/src/assets/images/robot.png.js +4 -0
- package/dist/src/assets/images/single_file.png.js +4 -0
- package/dist/src/assets/images/snapshot-history.png.js +4 -0
- package/dist/src/assets/images/snapshot-manual.png.js +4 -0
- package/dist/src/assets/images/snapshot-realtime.png.js +4 -0
- package/dist/src/assets/images/staff.png.js +4 -0
- package/dist/src/assets/images/switch_app.png.js +4 -0
- package/dist/src/assets/images/sync_append.png.js +4 -0
- package/dist/src/assets/images/sync_append_update.png.js +4 -0
- package/dist/src/assets/images/sync_loading.png.js +4 -0
- package/dist/src/assets/images/sync_replace.png.js +4 -0
- package/dist/src/assets/images/sync_update.png.js +4 -0
- package/dist/src/assets/images/user_bg.png.js +4 -0
- package/dist/src/assets/images/weixin.png.js +4 -0
- package/dist/src/chart-config-update.js +17 -0
- package/dist/src/chart-data-adapters.js +112 -0
- package/dist/src/chart-option-override.js +128 -0
- package/dist/src/chart-option-paths.js +64 -0
- package/dist/src/chart-registry.js +46 -0
- package/dist/src/chart-render-host.js +57 -0
- package/dist/src/chart-request-broker.js +176 -0
- package/dist/src/chartTheme.js +683 -0
- package/dist/src/collection.js +25 -0
- package/dist/src/date-helper.js +60 -0
- package/dist/src/dom-helper.js +22 -0
- package/dist/src/eval-with.js +14 -0
- package/dist/src/fieldFactory.js +5 -0
- package/dist/src/formula.js +365 -0
- package/dist/src/hljs-lite.js +29 -0
- package/dist/src/index.js +24 -0
- package/dist/src/lazy-jsencrypt.js +13 -0
- package/dist/src/legacy.js +25 -0
- package/dist/src/locale.js +88 -0
- package/dist/src/menu-open.js +43 -0
- package/dist/src/mermaid.js +79 -0
- package/dist/src/meta.js +4 -0
- package/dist/src/mobile-chart-appearance.js +148 -0
- package/dist/src/moment-compat.js +558 -0
- package/dist/src/nav-history.js +184 -0
- package/dist/src/page.js +116 -0
- package/dist/src/pdf.viewer.js +4 -0
- package/dist/src/placeholder.js +64 -0
- package/dist/src/public.js +49 -0
- package/dist/src/security.js +26 -0
- package/dist/src/storage.js +107 -0
- package/dist/src/token-storage.js +108 -0
- package/dist/src/util.js +4 -0
- package/package.json +109 -3
- package/src/Config.js +25 -0
- package/src/asset-images.js +16 -0
- package/src/chart-config-update.js +16 -0
- package/src/chart-data-adapters.js +106 -0
- package/src/chart-option-override.js +126 -0
- package/src/chart-option-paths.js +63 -0
- package/src/chart-registry.js +41 -0
- package/src/chart-render-host.js +56 -0
- package/src/chart-request-broker.js +171 -0
- package/src/chartTheme.js +711 -0
- package/src/collection.js +28 -0
- package/src/date-helper.js +72 -0
- package/src/dom-helper.js +26 -0
- package/src/eval-with.js +21 -0
- package/src/fieldFactory.js +3 -0
- package/src/formula.js +362 -0
- package/src/hljs-lite.js +41 -0
- package/src/index.js +2 -0
- package/src/lazy-jsencrypt.js +36 -0
- package/src/legacy.js +29 -0
- package/src/locale.js +104 -0
- package/src/menu-open.js +72 -0
- package/src/mermaid.js +115 -0
- package/src/meta.js +2 -0
- package/src/mobile-chart-appearance.js +147 -0
- package/src/moment-compat.d.ts +91 -0
- package/src/moment-compat.js +744 -0
- package/src/nav-history.js +274 -0
- package/src/page.js +129 -0
- package/src/pdf.viewer.js +2 -0
- package/src/placeholder.js +107 -0
- package/src/public.js +11 -0
- package/src/security.js +29 -0
- package/src/storage.js +135 -0
- package/src/token-storage.js +120 -0
- package/src/util.js +2 -0
- package/types/Config.d.ts +4 -0
- package/types/collection.d.ts +40 -0
- package/types/date-helper.d.ts +11 -0
- package/types/date-time.d.ts +2 -0
- package/types/date.d.ts +1 -0
- package/types/dom-helper.d.ts +3 -0
- package/types/dom.d.ts +1 -0
- package/types/index.d.ts +1 -0
- package/types/moment-compat.d.ts +91 -0
- package/types/page.d.ts +56 -0
- package/types/placeholder.d.ts +42 -0
- package/types/public.d.ts +10 -0
- package/types/storage.d.ts +31 -0
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
// A dashboard owns this broker. It never shares report results between dashboards or components.
|
|
2
|
+
const stable = value => {
|
|
3
|
+
if (Array.isArray(value)) return value.map(stable)
|
|
4
|
+
if (value && typeof value === 'object') return Object.fromEntries(Object.keys(value).sort().map(key => [key, stable(value[key])]))
|
|
5
|
+
return value
|
|
6
|
+
}
|
|
7
|
+
const encode = value => JSON.stringify(stable(value))
|
|
8
|
+
|
|
9
|
+
export function createChartRequestBroker ({ concurrency = 6, ttl = 30000, maxEntries = 64, maxBytes = 2 * 1024 * 1024, now = Date.now } = {}) {
|
|
10
|
+
const cache = new Map()
|
|
11
|
+
const jobs = new Set()
|
|
12
|
+
const inFlight = new Map()
|
|
13
|
+
const queue = []
|
|
14
|
+
const counters = { hits: 0, misses: 0, coalesced: 0, cancelled: 0, peakActive: 0 }
|
|
15
|
+
let active = 0
|
|
16
|
+
let bytes = 0
|
|
17
|
+
let context = null
|
|
18
|
+
let expiryTimer = null
|
|
19
|
+
let disposed = false
|
|
20
|
+
|
|
21
|
+
const remove = key => {
|
|
22
|
+
const entry = cache.get(key)
|
|
23
|
+
if (entry) bytes -= entry.bytes
|
|
24
|
+
cache.delete(key)
|
|
25
|
+
}
|
|
26
|
+
const expire = () => {
|
|
27
|
+
if (expiryTimer) clearTimeout(expiryTimer)
|
|
28
|
+
expiryTimer = null
|
|
29
|
+
for (const [key, entry] of cache) if (entry.expires <= now()) remove(key)
|
|
30
|
+
if (cache.size) {
|
|
31
|
+
const next = Math.min(...Array.from(cache.values(), entry => entry.expires))
|
|
32
|
+
expiryTimer = setTimeout(expire, Math.max(1, next - now()))
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const clear = () => {
|
|
36
|
+
cache.clear()
|
|
37
|
+
bytes = 0
|
|
38
|
+
if (expiryTimer) clearTimeout(expiryTimer)
|
|
39
|
+
expiryTimer = null
|
|
40
|
+
}
|
|
41
|
+
const forget = job => {
|
|
42
|
+
jobs.delete(job)
|
|
43
|
+
if (inFlight.get(job.key) === job) inFlight.delete(job.key)
|
|
44
|
+
}
|
|
45
|
+
const cancel = job => {
|
|
46
|
+
if (job.cancelled) return
|
|
47
|
+
job.cancelled = true
|
|
48
|
+
job.invalidated = true
|
|
49
|
+
for (const consumer of job.consumers) consumer.resolve(null)
|
|
50
|
+
job.consumers.clear()
|
|
51
|
+
job.controller?.abort()
|
|
52
|
+
const index = queue.indexOf(job)
|
|
53
|
+
if (index !== -1) queue.splice(index, 1)
|
|
54
|
+
if (!job.started) forget(job)
|
|
55
|
+
counters.cancelled++
|
|
56
|
+
}
|
|
57
|
+
const syncContext = current => {
|
|
58
|
+
if (context && context.principal !== current.principal) {
|
|
59
|
+
clear()
|
|
60
|
+
for (const job of [...jobs]) cancel(job)
|
|
61
|
+
} else if (context && context.credential !== current.credential) {
|
|
62
|
+
// Token renewal invalidates responses, without cancelling authenticated work for the same principal.
|
|
63
|
+
clear()
|
|
64
|
+
}
|
|
65
|
+
context = current
|
|
66
|
+
}
|
|
67
|
+
const invalidate = reportId => {
|
|
68
|
+
for (const [key, entry] of cache) if (!reportId || entry.reportId === reportId) remove(key)
|
|
69
|
+
for (const job of jobs) if (!reportId || job.reportId === reportId) job.invalidated = true
|
|
70
|
+
expire()
|
|
71
|
+
}
|
|
72
|
+
const pump = () => {
|
|
73
|
+
if (disposed) return
|
|
74
|
+
while (active < concurrency && queue.length) {
|
|
75
|
+
const job = queue.shift()
|
|
76
|
+
syncContext(job.getContext())
|
|
77
|
+
if (job.cancelled || !job.consumers.size) { forget(job); continue }
|
|
78
|
+
job.started = true
|
|
79
|
+
job.credential = context.credential
|
|
80
|
+
job.version = job.getVersion()
|
|
81
|
+
job.cacheKey = encode([job.componentId, job.params, job.version])
|
|
82
|
+
job.controller = new AbortController()
|
|
83
|
+
active++
|
|
84
|
+
counters.peakActive = Math.max(counters.peakActive, active)
|
|
85
|
+
Promise.resolve().then(() => job.execute(job.controller.signal)).then(data => {
|
|
86
|
+
if (disposed || job.cancelled) return
|
|
87
|
+
const current = job.getContext()
|
|
88
|
+
syncContext(current)
|
|
89
|
+
if (job.cancelled) return
|
|
90
|
+
job.settled = true
|
|
91
|
+
const encoded = JSON.stringify(data)
|
|
92
|
+
// Include condition/version keys in the budget; complex filters can dwarf a small response.
|
|
93
|
+
const size = encoded ? (encoded.length + job.cacheKey.length) * 2 : 0
|
|
94
|
+
if (job.cacheable && !job.invalidated && current.credential === job.credential && job.getVersion() === job.version && encoded && size <= maxBytes / 2) {
|
|
95
|
+
remove(job.cacheKey)
|
|
96
|
+
cache.set(job.cacheKey, { encoded, bytes: size, expires: now() + ttl, reportId: job.reportId })
|
|
97
|
+
bytes += size
|
|
98
|
+
for (const cachedKey of cache.keys()) {
|
|
99
|
+
if (cache.size <= maxEntries && bytes <= maxBytes) break
|
|
100
|
+
remove(cachedKey)
|
|
101
|
+
}
|
|
102
|
+
expire()
|
|
103
|
+
}
|
|
104
|
+
for (const consumer of job.consumers) consumer.resolve(encoded === undefined ? data : JSON.parse(encoded))
|
|
105
|
+
}).catch(error => {
|
|
106
|
+
job.settled = true
|
|
107
|
+
if (!job.cancelled && !disposed) for (const consumer of job.consumers) consumer.reject(error)
|
|
108
|
+
}).finally(() => {
|
|
109
|
+
job.consumers.clear()
|
|
110
|
+
forget(job)
|
|
111
|
+
active--
|
|
112
|
+
pump()
|
|
113
|
+
})
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return {
|
|
118
|
+
request ({ params, componentId = params.reportId, execute, getContext, getVersion = () => '', cacheable = false, force = false }) {
|
|
119
|
+
if (disposed) return { promise: Promise.resolve(null), cancel: () => {} }
|
|
120
|
+
const current = getContext()
|
|
121
|
+
syncContext(current)
|
|
122
|
+
expire()
|
|
123
|
+
const version = getVersion()
|
|
124
|
+
const key = encode([componentId, params, version])
|
|
125
|
+
const reportId = params.reportId
|
|
126
|
+
if (force) invalidate(reportId)
|
|
127
|
+
const entry = cache.get(key)
|
|
128
|
+
if (cacheable && current.credential && !force && entry) {
|
|
129
|
+
counters.hits++
|
|
130
|
+
cache.delete(key)
|
|
131
|
+
cache.set(key, entry)
|
|
132
|
+
return {
|
|
133
|
+
promise: Promise.resolve().then(() => {
|
|
134
|
+
const latest = getContext()
|
|
135
|
+
return latest.principal === current.principal && latest.credential === current.credential ? JSON.parse(entry.encoded) : null
|
|
136
|
+
}),
|
|
137
|
+
cancel: () => {}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
let job = !force && inFlight.get(key)
|
|
141
|
+
if (job && !job.settled && !job.cancelled && !job.invalidated && job.credential === current.credential) counters.coalesced++
|
|
142
|
+
else {
|
|
143
|
+
counters.misses++
|
|
144
|
+
job = { key, componentId, params, reportId, execute, getContext, getVersion, version, credential: current.credential, cacheable: cacheable && !!current.credential, consumers: new Set() }
|
|
145
|
+
jobs.add(job)
|
|
146
|
+
inFlight.set(key, job)
|
|
147
|
+
queue.push(job)
|
|
148
|
+
}
|
|
149
|
+
const consumer = {}
|
|
150
|
+
const promise = new Promise((resolve, reject) => Object.assign(consumer, { resolve, reject }))
|
|
151
|
+
job.consumers.add(consumer)
|
|
152
|
+
pump()
|
|
153
|
+
return {
|
|
154
|
+
promise,
|
|
155
|
+
cancel: () => {
|
|
156
|
+
if (!job.consumers.delete(consumer)) return
|
|
157
|
+
consumer.resolve(null)
|
|
158
|
+
if (!job.consumers.size) cancel(job)
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
invalidate,
|
|
163
|
+
stats () { return { ...counters, active, queued: queue.length, entries: cache.size, bytes, disposed } },
|
|
164
|
+
dispose () {
|
|
165
|
+
disposed = true
|
|
166
|
+
clear()
|
|
167
|
+
for (const job of [...jobs]) cancel(job)
|
|
168
|
+
context = null
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|