{"id":18573883,"url":"https://github.com/basedwon/codex","last_synced_at":"2025-10-12T02:43:52.658Z","repository":{"id":198068360,"uuid":"700130321","full_name":"basedwon/codex","owner":"basedwon","description":null,"archived":false,"fork":false,"pushed_at":"2023-11-07T11:27:18.000Z","size":24,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-02T19:40:53.513Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/basedwon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"docs/contributing.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-04T02:13:21.000Z","updated_at":"2023-10-04T03:48:39.000Z","dependencies_parsed_at":"2023-11-07T12:30:10.705Z","dependency_job_id":"8391bd81-2cae-4fbf-96d4-e4f2fe25f481","html_url":"https://github.com/basedwon/codex","commit_stats":{"total_commits":15,"total_committers":1,"mean_commits":15.0,"dds":0.0,"last_synced_commit":"2097d6b4aa0dbccd75a98bf77488f7e8cea5701b"},"previous_names":["basedwon/codex"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/basedwon/codex","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/basedwon%2Fcodex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/basedwon%2Fcodex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/basedwon%2Fcodex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/basedwon%2Fcodex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/basedwon","download_url":"https://codeload.github.com/basedwon/codex/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/basedwon%2Fcodex/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279009969,"owners_count":26084671,"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","status":"online","status_checked_at":"2025-10-12T02:00:06.719Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-11-06T23:13:18.647Z","updated_at":"2025-10-12T02:43:52.639Z","avatar_url":"https://github.com/basedwon.png","language":"JavaScript","readme":"# Codex\n\n[![npm](https://img.shields.io/npm/v/@basd/codex?style=flat\u0026logo=npm)](https://www.npmjs.com/package/@basd/codex)\n[![pipeline](https://gitlab.com/frenware/core/codex/badges/master/pipeline.svg)](https://gitlab.com/frenware/core/codex/-/pipelines)\n[![license](https://img.shields.io/npm/l/@basd/codex)](https://gitlab.com/frenware/core/codex/-/blob/master/LICENSE)\n[![downloads](https://img.shields.io/npm/dw/@basd/codex)](https://www.npmjs.com/package/@basd/codex) \n\n[![Gitlab](https://img.shields.io/badge/Gitlab%20-%20?logo=gitlab\u0026color=%23383a40)](https://gitlab.com/frenware/core/codex)\n[![Github](https://img.shields.io/badge/Github%20-%20?logo=github\u0026color=%23383a40)](https://github.com/basedwon/codex)\n[![Twitter](https://img.shields.io/badge/@basdwon%20-%20?logo=twitter\u0026color=%23383a40)](https://twitter.com/basdwon)\n[![Discord](https://img.shields.io/badge/Basedwon%20-%20?logo=discord\u0026color=%23383a40)](https://discordapp.com/users/basedwon)\n\nA flexible and robust package that provides a system for managing models, fields, and their validations. Designed to be highly extensible, it provides a solid structure for working with different types of data structures.\n\n## Features\n\n- Define and manage complex data models.\n- Field validation for models.\n- Extendable with custom fields.\n- Supports foreign keys and relationships.\n- Easy integration with other systems.\n\n## Installation\n\nInstall the package with:\n\n```bash\nnpm install @basd/codex\n```\n\n## Usage\n\nFirst, import the `Codex` library.\n\n```js\nimport Codex from '@basd/codex'\n```\nor\n```js\nconst Codex = require('@basd/codex')\n```\n\n### Defining Models\n\n```js\nconst codex = new Codex({\n  user: {\n    name: '*string', // * makes it required (default)\n    age: 'number',\n    friend: '~user' // ~ makes it optional\n  }\n})\n\nconst userModel = codex.getModel('user')\nconst userInstance = userModel.create({ name: 'John', age: 30 })\n```\n\nThe above example defines a `user` model with a name, age, and an optional recursive friend relationship.\n\n### Field Validation\n\nFields are automatically validated upon creation:\n\n```js\nconst invalidUser = userModel.create({ name: 123, age: 'thirty' })  // This will throw an error\n```\n\nOr you can manually validate:\n\n```js\nconst isValid = codex.valid('user', { username: 'JohnDoe', age: 'twenty five' }) // returns false\n```\n\n### Using Custom Fields\n\n```js\nclass CustomField extends Field {\n  // Custom implementation\n}\n// Add to registry (assuming registry instance is available)\nregistry.set('field.custom', CustomField)\n\nconst customModel = new Model({\n  customField: 'custom'\n})\n```\n\n### Extending Field Types\n\nThe library is designed with extensibility in mind. You can easily extend built-in field types or create your own.\n\nFor example, to extend the `StringField`:\n\n```js\nclass CapitalizedStringField extends StringField {\n  _create(value) {\n    const strValue = super._create(value)\n    return strValue.charAt(0).toUpperCase() + strValue.slice(1)\n  }\n}\n```\n\n## Documentation\n\n- [API Reference](/docs/api.md)\n\n### API Reference\n\n- `Field`: The base class for all field types.\n- `StringField`, `NumberField`, `ForeignField`: Field types provided by default.\n- `Model`: Class to define and manage data models.\n- `Factory`: A helper class to create models and fields.\n- `Codex`: Main entry point to define and manage the whole system.\n\nFor each class and method, refer to the code documentation for detailed usage.\n\n### Extending\n\nYou can extend default classes to introduce custom behavior or implement additional field types. Use the Factory class to register and manage custom implementations.\n\n### Error Handling\n\nThe library comes with a predefined set of error messages that are thrown when validation fails. You can easily capture these and handle them in your application.\n\n## Tests\n\nIn order to run the test suite, simply clone the repository and install its dependencies:\n\n```bash\ngit clone https://gitlab.com/frenware/core/codex.git\ncd codex\nnpm install\n```\n\nTo run the tests:\n\n```bash\nnpm test\n```\n\n## Contributing\n\nThank you! Please see our [contributing guidelines](/docs/contributing.md) for details.\n\n## Donations\n\nIf you find this project useful and want to help support further development, please send us some coin. We greatly appreciate any and all contributions. Thank you!\n\n**Bitcoin (BTC):**\n```\n1JUb1yNFH6wjGekRUW6Dfgyg4J4h6wKKdF\n```\n\n**Monero (XMR):**\n```\n46uV2fMZT3EWkBrGUgszJCcbqFqEvqrB4bZBJwsbx7yA8e2WBakXzJSUK8aqT4GoqERzbg4oKT2SiPeCgjzVH6VpSQ5y7KQ\n```\n\n## License\n\n@basd/codex is [MIT licensed](https://gitlab.com/frenware/core/codex/-/blob/master/LICENSE).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbasedwon%2Fcodex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbasedwon%2Fcodex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbasedwon%2Fcodex/lists"}