{"id":15408819,"url":"https://github.com/sejori/super_cereal","last_synced_at":"2025-12-11T21:16:28.222Z","repository":{"id":61326652,"uuid":"550519150","full_name":"sejori/super_cereal","owner":"sejori","description":"Serialize object graphs into key-value pairs 🥣","archived":false,"fork":false,"pushed_at":"2022-12-26T21:25:13.000Z","size":79,"stargazers_count":16,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-29T07:05:04.522Z","etag":null,"topics":["deno","graph-algorithms","object-oriented-programming","serialization"],"latest_commit_sha":null,"homepage":"https://deno.land/x/super_cereal","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sejori.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-10-12T22:50:43.000Z","updated_at":"2023-06-14T00:17:14.000Z","dependencies_parsed_at":"2023-01-31T01:45:46.350Z","dependency_job_id":null,"html_url":"https://github.com/sejori/super_cereal","commit_stats":null,"previous_names":["sejori/super_cereal","sebringrose/super_cereal"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sejori%2Fsuper_cereal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sejori%2Fsuper_cereal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sejori%2Fsuper_cereal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sejori%2Fsuper_cereal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sejori","download_url":"https://codeload.github.com/sejori/super_cereal/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249195315,"owners_count":21228171,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deno","graph-algorithms","object-oriented-programming","serialization"],"created_at":"2024-10-01T16:35:19.467Z","updated_at":"2025-12-11T21:16:22.940Z","avatar_url":"https://github.com/sejori.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Super Cereal 🥣\n\nA super serial-izer that can turn any in-memory object graph into key/value string pairs (and back again)!\n\nSupports the following objects/types:\n- All primitive values (string, number, bool, etc)\n- Classes and inherited classes (base class must extend `Model`)\n- Object (with circular refs)\n- Response\n- Array\n- Function\n- Map\n- Set\n- Map\n- Date\n\n**TL;DR:** You get to keep your lovely graph structure and all of your lovely class methods too.\n\n## But how?\n\n```\nimport { Store, Model } from \"./mod.ts\";\n\nconst storeObj: Record\u003cstring, string\u003e = {};\n\nconst store = new Store({\n  get: (id: string) =\u003e storeObj[id],\n  set: (id: string, value: string) =\u003e storeObj[id] = value\n});\n\nclass Person extends Model {\n  name: string;\n  friends: Person[] = [];\n\n  constructor(name: string) {\n    super(store, arguments);\n    this.name = name;\n  }\n\n  addFriend(friend: Person) {\n    this.friends.push(friend);\n    friend.friends.push(this);\n  }\n}\n\nconst jim = new Person(\"Jim\");\nconst bob = new Person(\"Bob\");\njim.addFriend(bob);\n\n// jim now has a circular reference via bob - no problem!\nconst jimId = jim.save();\nconst freshJim = store.load(jimId) as Person;\n\nconsole.log(freshJim.friends);\n\nconst steve = new Person(\"Steve\");\n\n// class methods retained\nfreshJim.addFriend(steve);\n\nconsole.log(freshJim.friends);\n```\n\nThe Al-Gore-ithm does a depth-first-search through the object structure leaving unique IDs on non-primitive values. It then serializes and stores objects by ID, replacing all refs with the corresponding ID to \"unlink\" the structure so it never gets stuck in a circular reference loop.\n\nFirst instantiate a `Store` then simply pass objects into its `save` method. If you want to serialize your own classes, make sure your base classes extend `Model` and call `super(store, arguments)` in their constuctors. This allows the store to reinstantiate them with their initial arguments before using `Object.assign` to apply deserialized property values.\n\nNote: Classes that extend `Model` inherit the `save` method so you can call it directly from them!\n\n## But why?\n\nI wanted a tool that could serialize any in-memory data structure with classes and store it in a key-value store. This allows for browser-based storage of OOP software state that can extend to the edge/cloud.\n\nThe goal was to require minimal additional class boilerplate and I think this fits the bill nicely. The only caveat is that you have use `store.load(id) as Classname` to keep accurate TS syntax highlighting (there is currently no way for TS to infer this and generic types don't work with nested structures).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsejori%2Fsuper_cereal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsejori%2Fsuper_cereal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsejori%2Fsuper_cereal/lists"}