predikt/oracle/backend/scripts/find-deep-docs.ts
caelum0x 2b68bde5d5 Predikt: full Polymarket-style prediction market — web + mobile + on-chain + bots
Working tree is now the canonical repo. Off-chain play-money + trustless on-chain
(FPMM AMM + CLOB via UMA settlement), AI market factory, creator/social/distribution,
mobile shell + push, one-command demo + deploy-kit. Secrets excluded (see ENV-AND-KEYS.md).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-06 23:29:50 +03:00

49 lines
1.1 KiB
TypeScript

import { runScript } from './run-script'
import { log, processPartitioned } from 'shared/utils'
type DeepContractResult = {
data: any
depth: number
}
function maxDepth(obj: unknown) {
if (obj == null || typeof obj !== 'object') {
return 0
}
let result = 0
for (const [_key, val] of Object.entries(obj)) {
const depth = maxDepth(val) + 1
if (depth > result) {
result = depth
}
}
return result
}
if (require.main === module) {
runScript(async ({ firestore }) => {
log('Searching for deep contract objects...')
const results = [] as DeepContractResult[]
const source = firestore.collectionGroup('contracts')
await processPartitioned(source, 100, async (docs) => {
for (const doc of docs) {
const data = doc.data()
try {
const depth = maxDepth(data)
if (depth >= 20) {
results.push({ data, depth })
}
} catch (e) {
console.error(e)
console.log(data)
}
}
})
for (const result of results) {
console.log(result.data?.id, result.depth)
}
console.log(results.length)
})
}