2026-06-06 09:53:44 +00:00
|
|
|
import { getSchemaBytes, initCodec, isCodecReady } from '../dist/fig/codec.js'
|
2026-06-06 10:37:29 +00:00
|
|
|
import { buildFigKiwi, parseFigKiwiChunks } from '../dist/fig/container.js'
|
2026-06-06 12:59:48 +00:00
|
|
|
import { guidToString } from '../dist/fig/guid.js'
|
2026-06-06 10:29:29 +00:00
|
|
|
import { parseFigKiwiContainer } from '../dist/fig/parse.js'
|
2026-06-06 08:34:33 +00:00
|
|
|
import { figmaSchema, getKiwiMessageType, parseSchema, validateSchema } from '../dist/index.js'
|
|
|
|
|
|
|
|
|
|
const schema = parseSchema(`
|
|
|
|
|
message Smoke {
|
|
|
|
|
uint id = 1;
|
|
|
|
|
}
|
|
|
|
|
`)
|
|
|
|
|
validateSchema(schema)
|
|
|
|
|
validateSchema(figmaSchema)
|
|
|
|
|
|
|
|
|
|
if (figmaSchema.definitions.length !== 605) {
|
|
|
|
|
throw new Error(`Unexpected Figma schema definition count: ${figmaSchema.definitions.length}`)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (getKiwiMessageType(new Uint8Array([1, 3, 0])) !== 3) {
|
|
|
|
|
throw new Error('Failed to read Kiwi message type from built dist')
|
|
|
|
|
}
|
2026-06-06 09:53:44 +00:00
|
|
|
|
|
|
|
|
await initCodec()
|
|
|
|
|
|
|
|
|
|
if (!isCodecReady() || getSchemaBytes().length === 0) {
|
|
|
|
|
throw new Error('Failed to initialize built FIG codec')
|
|
|
|
|
}
|
2026-06-06 10:29:29 +00:00
|
|
|
|
|
|
|
|
if (parseFigKiwiContainer(new TextEncoder().encode('not-fig-kiwi')) !== null) {
|
|
|
|
|
throw new Error('Failed to reject invalid FIG Kiwi container')
|
|
|
|
|
}
|
2026-06-06 10:37:29 +00:00
|
|
|
|
|
|
|
|
const figKiwi = buildFigKiwi(new Uint8Array([1]), new Uint8Array([2]))
|
|
|
|
|
if (parseFigKiwiChunks(figKiwi)?.length !== 2) {
|
|
|
|
|
throw new Error('Failed to read built FIG Kiwi container chunks')
|
|
|
|
|
}
|
2026-06-06 12:59:48 +00:00
|
|
|
|
|
|
|
|
if (guidToString({ sessionID: 1, localID: 2 }) !== '1:2') {
|
|
|
|
|
throw new Error('Failed to format built FIG GUID helper')
|
|
|
|
|
}
|