d25d482dc2
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
81 lines
2.3 KiB
TypeScript
81 lines
2.3 KiB
TypeScript
import { isLargeValueRef, type LargeValueRef } from '@/lib/execution/payloads/large-value-ref'
|
|
|
|
export const LARGE_ARRAY_MANIFEST_MARKER = '__simLargeArrayManifest'
|
|
export const LARGE_ARRAY_MANIFEST_VERSION = 2
|
|
export const LARGE_ARRAY_MANIFEST_PREVIEW_MAX_BYTES = 16 * 1024
|
|
|
|
export interface LargeArrayManifest {
|
|
[LARGE_ARRAY_MANIFEST_MARKER]: true
|
|
version: typeof LARGE_ARRAY_MANIFEST_VERSION
|
|
kind: 'array'
|
|
totalCount: number
|
|
chunkCount: number
|
|
byteSize: number
|
|
chunks: LargeArrayManifestChunk[]
|
|
preview: unknown[]
|
|
}
|
|
|
|
export interface LargeArrayManifestChunk {
|
|
ref: LargeValueRef
|
|
count: number
|
|
byteSize: number
|
|
}
|
|
|
|
function isValidCount(value: unknown): value is number {
|
|
return typeof value === 'number' && Number.isInteger(value) && value >= 0
|
|
}
|
|
|
|
function isValidByteSize(value: unknown): value is number {
|
|
return typeof value === 'number' && Number.isFinite(value) && value >= 0
|
|
}
|
|
|
|
function isValidPreview(value: unknown): value is unknown[] {
|
|
return Array.isArray(value) && value.length <= 3
|
|
}
|
|
|
|
export function isLargeArrayManifest(value: unknown): value is LargeArrayManifest {
|
|
if (!value || typeof value !== 'object') {
|
|
return false
|
|
}
|
|
|
|
const candidate = value as Record<string, unknown>
|
|
if (
|
|
candidate[LARGE_ARRAY_MANIFEST_MARKER] !== true ||
|
|
candidate.version !== LARGE_ARRAY_MANIFEST_VERSION ||
|
|
candidate.kind !== 'array' ||
|
|
!isValidCount(candidate.totalCount) ||
|
|
!isValidCount(candidate.chunkCount) ||
|
|
!isValidByteSize(candidate.byteSize) ||
|
|
!Array.isArray(candidate.chunks) ||
|
|
!isValidPreview(candidate.preview) ||
|
|
candidate.chunkCount !== candidate.chunks.length
|
|
) {
|
|
return false
|
|
}
|
|
|
|
let totalCount = 0
|
|
let byteSize = 0
|
|
for (const chunk of candidate.chunks) {
|
|
if (!chunk || typeof chunk !== 'object') {
|
|
return false
|
|
}
|
|
|
|
const chunkRecord = chunk as Record<string, unknown>
|
|
if (
|
|
!isLargeValueRef(chunkRecord.ref) ||
|
|
!isValidCount(chunkRecord.count) ||
|
|
chunkRecord.count <= 0 ||
|
|
!isValidByteSize(chunkRecord.byteSize) ||
|
|
chunkRecord.byteSize <= 0 ||
|
|
chunkRecord.byteSize !== chunkRecord.ref.size
|
|
) {
|
|
return false
|
|
}
|
|
|
|
totalCount += chunkRecord.count
|
|
byteSize += chunkRecord.ref.size
|
|
}
|
|
|
|
return candidate.totalCount === totalCount && candidate.byteSize === byteSize
|
|
}
|