decla-red/shared/src/serialization/serialized-fields.ts
Andras Schmelczer d9b80b92ca
Some checks failed
Build & deploy / Build & publish server image (pull_request) Has been skipped
Build & deploy / Build & deploy website (pull_request) Failing after 4m40s
ai
2026-06-20 11:30:49 +01:00

13 lines
722 B
TypeScript

// Derive a serializable object's positional wire array from a single declared
// list of field names, so toArray() and the constructor share ONE source of
// truth for field order instead of a hand-written array that can silently drift
// out of step with the parameters.
//
// deserialize reconstructs via `new Ctor(...array.slice(1))`, so the field list
// MUST name the constructor's parameters in order. Fields a constructor
// recomputes from others (e.g. a planet's centre/radius from its vertices) are
// derived, not serialized, and so are deliberately absent from the list.
export const toArrayFromFields = (
object: any,
fields: ReadonlyArray<string>,
): Array<any> => fields.map((field) => object[field]);