{"id":19614786,"url":"https://github.com/leancloud/typescript-sample-code","last_synced_at":"2026-02-27T14:04:25.273Z","repository":{"id":66228632,"uuid":"60656591","full_name":"leancloud/TypeScript-Sample-Code","owner":"leancloud","description":"TypeScript SDK 文档中的示例代码","archived":false,"fork":false,"pushed_at":"2016-11-08T01:38:15.000Z","size":42,"stargazers_count":4,"open_issues_count":21,"forks_count":1,"subscribers_count":19,"default_branch":"master","last_synced_at":"2025-10-26T19:02:58.373Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/leancloud.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-06-08T00:42:02.000Z","updated_at":"2022-01-22T18:42:29.000Z","dependencies_parsed_at":"2023-07-12T12:45:42.078Z","dependency_job_id":null,"html_url":"https://github.com/leancloud/TypeScript-Sample-Code","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/leancloud/TypeScript-Sample-Code","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leancloud%2FTypeScript-Sample-Code","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leancloud%2FTypeScript-Sample-Code/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leancloud%2FTypeScript-Sample-Code/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leancloud%2FTypeScript-Sample-Code/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leancloud","download_url":"https://codeload.github.com/leancloud/TypeScript-Sample-Code/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leancloud%2FTypeScript-Sample-Code/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29898872,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-27T12:09:13.686Z","status":"ssl_error","status_checked_at":"2026-02-27T12:09:13.282Z","response_time":57,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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-11T10:53:44.223Z","updated_at":"2026-02-27T14:04:25.234Z","avatar_url":"https://github.com/leancloud.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LeanCloud TypeScript SDK 文档示例代码\n\n## 文档地址\n[JavaScript \u0026 TypeScript 数据存储开发指南](https://leancloud.cn/docs/leanstorage_guide-js.html)\n\n\n## 功能\n当开发者阅读文档的代码片段，想要阅读更多关于执行代码片段使用的前置条件时，可以阅读本项目里面一一对应的代码片段的测试用例，这样可以方便开发者使用接口的时候有一个最佳实践的参考。\n\n\n## 贡献代码\n从文档中找到对应代码片段的 Test Case 的源代码，修改，然后发出 PR，主分支(master)会有 travis CI 的脚本自动运行单元测试，只有测试全都通过才可以被合并到主分支，而文档对应的地方也应该即使修改。\n\n## 代码示例\n代码示例请参考根目录下的：[code-example](code-example.ts)\n\n```typescript\n/// \u003creference path=\"typings/index.d.ts\" /\u003e\nimport * as chai from 'chai';\nimport * as AV from 'leancloud-storage';\n\n// 测试用例所需要的前置条件都需要在启动的时候调用，例如\n/*\nAV.init({\n  appId:'{put-test-appId-here}}',\n  appKey:'{put-test-appKey-here}'});\n*/\n\n// 或者有一些需要提前写入的测试数据，例如用户修改密码等操作，需要的前置条件是用户已经存在\n// 因此，也需要在脚本加载的时候就执行\n\n// 还可以定义一些占位符变量，例如测试用例要用到的 objectId 等重要数据\n/*\nlet targetObjectId = '';\nlet file = ...\n*/\n\n// category-name 可以是 Object，File 等功能模块的首字母大写\ndescribe('sample-category-name', function () {\n\n  // 测试用例所需要的前置条件都需要在启动的时候调用。\n  // 在 before 函数里面执行一些欲置脚本\n  // 例如初始化 LeanCloud SDK\n  before(function() {\n    // runs before all tests in this block\n    /*\n    AV.init({\n      appId:'{put-test-appId-here}}',\n      appKey:'{put-test-appKey-here}'});\n    */\n  });\n  // 实例方法使用 # 分隔类和方法\n  it('ClassName#instance-function-name', function (done) {\n    try{\n      // 示例代码-Start\n      // 示例代码-End\n      done();\n    }\n    catch(e){\n      chai.assert.isNull(e);\n    }\n  });\n\n  //静态方法使用 .(dot) 分隔类和方法\n  it('ClassName.static-function-name', function (done) {\n    try{\n      // 示例代码-Start\n\n      // 示例代码-End\n      done();\n    }\n    catch(e){\n      chai.assert.isNull(e);\n    }\n  });\n\n  // 在 after 里面可以执行一些清理脚本，清理本次执行所产生的脏数据\n  after(function() {\n    // runs after all tests in this block\n  });\n});\n\n\n```\n\n## Travis CI 配置\n因为网络原因，如果在服务端使用大陆节点的 AppID 以及 AppKey 偶尔会 Https 请求超时，单元测试的断言会误判。因此在 Travis CI 运行的时候动态修改了环境变量，使用了美国节点的应用。但是并没有直接书写在 `.travis.yml` 里，而是在服务端的配置里面。\n\n\n## FAQ\nQ：SDK 更新会对当前项目产生影响么？\n\nA：会，目前 JS SDK 每一次有新的 PR 被 merge 进主分支，都会发送一个 PR 到当前项目，这个 PR 只会更新 `package.json` 里面的 JS SDK 的版本，这样也会触发 travis CI 进行自动化检测，一旦 `npm test` 结果没有通过，会及时通知文档维护人员进行查看，需要手动的去比对文档中的代码，这样可以避免过期方法或者接口更名对用户造成的困扰。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleancloud%2Ftypescript-sample-code","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleancloud%2Ftypescript-sample-code","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleancloud%2Ftypescript-sample-code/lists"}