{"id":41018704,"url":"https://github.com/fastschema/sdk-js","last_synced_at":"2026-01-22T09:26:08.964Z","repository":{"id":246983773,"uuid":"823920828","full_name":"fastschema/sdk-js","owner":"fastschema","description":null,"archived":false,"fork":false,"pushed_at":"2025-09-18T10:56:27.000Z","size":149,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-18T12:49:59.159Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fastschema.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-07-04T02:36:07.000Z","updated_at":"2025-09-18T10:55:56.000Z","dependencies_parsed_at":"2024-07-06T02:56:34.030Z","dependency_job_id":"e3fa42cc-b26b-43de-8828-c2635251f2bc","html_url":"https://github.com/fastschema/sdk-js","commit_stats":null,"previous_names":["fastschema/sdk-js"],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/fastschema/sdk-js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastschema%2Fsdk-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastschema%2Fsdk-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastschema%2Fsdk-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastschema%2Fsdk-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fastschema","download_url":"https://codeload.github.com/fastschema/sdk-js/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastschema%2Fsdk-js/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28660647,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-22T01:17:37.254Z","status":"online","status_checked_at":"2026-01-22T02:00:07.137Z","response_time":144,"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":"2026-01-22T09:26:08.306Z","updated_at":"2026-01-22T09:26:08.959Z","avatar_url":"https://github.com/fastschema.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Javascript SDK for FastSchema\n\n**Document**\n\nhttps://fastschema.com/docs/sdk/\n\nFastSchema SDK provides a convenient way to connect to the FastSchema backend and perform various operations.\n\nThe FastSchema JavaScript SDK works in both Node.js and browser environments. To use the SDK, you need to install it using npm.\n\n## Installation\n\nFastSchema SDK can be installed using browser script tags or npm.\n\n### Browser\n\n```html\n\u003cscript src=\"https://unpkg.com/fastschema@latest/dist/fastschema.umd.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n  const fs = new fastschema.FastSchema(\"http://localhost:8000\");\n\u003c/script\u003e\n```\n\n### NPM\n\n```bash\nnpm install fastschema\n```\n\n## Login and initialize\n\nThe initialization must be done before any other operation.\n\n```typescript\nimport { FastSchema } from \"fastschema\";\n\n// Create a new instance of FastSchema\nconst fs = new FastSchema(\"https://localhost:8000\");\n\n// Login\nawait fs.auth().login({\n  login: \"admin\",\n  password: \"123\",\n});\n\n// Initialize: This must be called before any other operation\nawait fs.init();\n```\n\n## Schema operations\n\n### Create schema\n\n```typescript\nawait fs.schemas().create({\n  name: \"tag\",\n  namespace: \"tags\",\n  label_field: \"name\",\n  fields: [\n    {\n      name: \"name\",\n      label: \"Name\",\n      type: \"string\",\n      sortable: true,\n      filterable: true,\n      unique: false,\n    },\n    {\n      name: \"description\",\n      label: \"Description\",\n      type: \"string\",\n      optional: true,\n    },\n  ],\n});\n```\n\n### Get schema\n\nThis operation will throw an error if the schema does not exist.\n\n```typescript\nconst schemaTag = fs.schema(\"tag\");\n```\n\n### Update a schema\n\n```typescript\nawait fs.schemas().update(\"tag\", {\n  schema: {\n    // Same as create\n  },\n  rename_fields: {\n    // Rename fields\n  },\n  rename_tables: {\n    // Rename tables\n  },\n});\n```\n\n### Delete a schema\n\n```typescript\nawait fs.schemas().delete(\"tag\");\n```\n\n## Content operations\n\n### Get content\n\n```typescript\nfs.schema(\"tag\").get\u003cTag\u003e(params);\n```\n\n`params` can be one of the following:\n\n- `id: number | string`: ID of the content\n\n- A filter object that represents the following interface:\n\n  ```typescript\n  interface ListOptions {\n    filter?: Filter;\n    page?: number;\n    limit?: number;\n    sort?: string;\n    select?: string;\n  }\n  ```\n\n  Refer to the [Filter documentation](https://fastschema.com/docs/headless-cms/list-records.html#filter) for more information about the filter object.\n\n### Create content\n\n```typescript\ninterface Tag {\n  name: string;\n  description: string;\n}\n\nconst createdTag = await fs.schema(\"tag\").create\u003cTag\u003e({\n  name: \"Tag 01\",\n  description: \"A description\",\n});\n```\n\n### Update content\n\n```typescript\nconst updated = await fs.schema(\"tag\").update(id, {\n  description: \"updated desc tag 1\",\n});\n```\n\n### Delete content\n\n```typescript\nawait fs.schema(\"tag\").delete(id);\n```\n\n### Upload files\n\n```typescript\nconst files: File[] = [];\nfor (let i = 0; i \u003c 5; i++) {\n  files.push(new File([`test ${i}`], `test${i}.txt`));\n}\n\nconst result = await fs.file().upload(files);\n```\n\n**Note**\n\nNodejs version before 20 does not support the `File` object.\nYou can use package `@web-std/file` to create a `File` object.\n\n## Realtime Updates\n\nFastSchema provides a way to listen to events in real-time.\n\n- `create`: When a new record is created\n- `update`: When a record is updated\n- `delete`: When a record is deleted\n- `*`: Listen to all events\n\n```typescript\nconst schemaTag = fs.schema(\"tag\");\n\nconst cb1 = (data: T, event: EventType, error: Error) =\u003e {\n  console.log(\"Event:\", event, \"Data:\", data, \"Error:\", error);\n};\n\nconst cb2 = (data: T[], event: EventType, error: Error) =\u003e {\n  console.log(\"Event:\", event, \"Data:\", data, \"Error:\", error);\n};\n\nconst cb3 = (data: T | T[], event: EventType, error: Error) =\u003e {\n  console.log(\"Event:\", event, \"Data:\", data, \"Error:\", error);\n};\n\nschemaTag.on(\"create\", cb1);\nschemaTag.on(\"update\", cb2);\nschemaTag.on(\"delete\", cb2);\nschemaTag.on(\"*\", cb3);\n```\n\nYou can also listen to events for a specific record.\n\n```typescript\nschemaTag.on(\"create\", id, cb1);\nschemaTag.on(\"update\", id, cb1);\nschemaTag.on(\"delete\", id, cb1);\n```\n\nor use the configuration events:\n\n```typescript\nschemaTag.on({\n  id?: number;\n  once?: boolean;\n  select?: string;\n  filter?: Filter;\n}, cb1);\n```\n\nThe configuration object can have the following properties:\n\n- `id`: ID of the record\n- `once`: If true, the callback will be called only once\n- `select`: Fields to select, separated by commas. This is useful when you want to select only specific fields to reduce the payload size.\n- `filter`: Filter object, used to filter the records that will trigger the event.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffastschema%2Fsdk-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffastschema%2Fsdk-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffastschema%2Fsdk-js/lists"}