@linyjs/plugin-docs 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (254) hide show
  1. package/README.md +137 -0
  2. package/docs/api-reference/index.md +361 -0
  3. package/docs/best-practices/error-handling.md +462 -0
  4. package/docs/best-practices/naming-conventions.md +496 -0
  5. package/docs/best-practices/performance.md +532 -0
  6. package/docs/best-practices/security.md +620 -0
  7. package/docs/best-practices/service-definition.md +332 -0
  8. package/docs/faq.md +322 -0
  9. package/docs/getting-started/first-plugin.md +358 -0
  10. package/docs/getting-started/installation.md +244 -0
  11. package/docs/getting-started/quick-start.md +235 -0
  12. package/docs/guides/authentication.md +428 -0
  13. package/docs/guides/client-module.md +604 -0
  14. package/docs/guides/data-persistence.md +640 -0
  15. package/docs/guides/permissions.md +440 -0
  16. package/docs/guides/server-module.md +377 -0
  17. package/docs/guides/ui-slots.md +475 -0
  18. package/docs/migration/v0-to-v1.md +354 -0
  19. package/examples/analytics-plugin/README.md +416 -0
  20. package/examples/analytics-plugin/dist/client/index.d.ts +36 -0
  21. package/examples/analytics-plugin/dist/client/index.js +173 -0
  22. package/examples/analytics-plugin/dist/index.d.ts +64 -0
  23. package/examples/analytics-plugin/dist/index.js +72 -0
  24. package/examples/analytics-plugin/dist/server/index.d.ts +119 -0
  25. package/examples/analytics-plugin/dist/server/index.js +313 -0
  26. package/examples/analytics-plugin/package.json +28 -0
  27. package/examples/analytics-plugin/src/client/index.tsx +414 -0
  28. package/examples/analytics-plugin/src/index.ts +71 -0
  29. package/examples/analytics-plugin/src/server/index.ts +349 -0
  30. package/examples/analytics-plugin/tsconfig.json +21 -0
  31. package/examples/blog-plugin/README.md +319 -0
  32. package/examples/blog-plugin/dist/client/index.d.ts +22 -0
  33. package/examples/blog-plugin/dist/client/index.js +197 -0
  34. package/examples/blog-plugin/dist/server/index.d.ts +5 -0
  35. package/examples/blog-plugin/dist/server/index.js +220 -0
  36. package/examples/blog-plugin/package.json +24 -0
  37. package/examples/blog-plugin/src/client/index.tsx +409 -0
  38. package/examples/blog-plugin/src/server/index.ts +240 -0
  39. package/examples/blog-plugin/tsconfig.json +16 -0
  40. package/examples/hello-world/README.md +101 -0
  41. package/examples/hello-world/dist/client/index.d.ts +5 -0
  42. package/examples/hello-world/dist/client/index.js +80 -0
  43. package/examples/hello-world/dist/server/index.d.ts +5 -0
  44. package/examples/hello-world/dist/server/index.js +38 -0
  45. package/examples/hello-world/node_modules/.package-lock.json +61 -0
  46. package/examples/hello-world/node_modules/@linyjs/client-module-interface/HOOKS_USAGE.md +281 -0
  47. package/examples/hello-world/node_modules/@linyjs/client-module-interface/IMPLEMENTATION_SUMMARY.md +166 -0
  48. package/examples/hello-world/node_modules/@linyjs/client-module-interface/QUICK_REFERENCE.md +130 -0
  49. package/examples/hello-world/node_modules/@linyjs/client-module-interface/README.md +214 -0
  50. package/examples/hello-world/node_modules/@linyjs/client-module-interface/package.json +26 -0
  51. package/examples/hello-world/node_modules/@linyjs/client-module-interface/src/application.ts +50 -0
  52. package/examples/hello-world/node_modules/@linyjs/client-module-interface/src/comparison-example.tsx +229 -0
  53. package/examples/hello-world/node_modules/@linyjs/client-module-interface/src/di.ts +127 -0
  54. package/examples/hello-world/node_modules/@linyjs/client-module-interface/src/domain.ts +52 -0
  55. package/examples/hello-world/node_modules/@linyjs/client-module-interface/src/hooks-example.tsx +275 -0
  56. package/examples/hello-world/node_modules/@linyjs/client-module-interface/src/hooks.ts +175 -0
  57. package/examples/hello-world/node_modules/@linyjs/client-module-interface/src/index.ts +87 -0
  58. package/examples/hello-world/node_modules/@linyjs/client-module-interface/src/interfaces.ts +117 -0
  59. package/examples/hello-world/node_modules/@linyjs/client-module-interface/src/router.ts +49 -0
  60. package/examples/hello-world/node_modules/@linyjs/client-module-interface/tsconfig.json +10 -0
  61. package/examples/hello-world/node_modules/@linyjs/server-module-interface/package.json +21 -0
  62. package/examples/hello-world/node_modules/@linyjs/server-module-interface/src/application.ts +21 -0
  63. package/examples/hello-world/node_modules/@linyjs/server-module-interface/src/di.ts +127 -0
  64. package/examples/hello-world/node_modules/@linyjs/server-module-interface/src/domain.ts +75 -0
  65. package/examples/hello-world/node_modules/@linyjs/server-module-interface/src/index.ts +55 -0
  66. package/examples/hello-world/node_modules/@linyjs/server-module-interface/src/interfaces.ts +58 -0
  67. package/examples/hello-world/node_modules/@linyjs/server-module-interface/tsconfig.json +8 -0
  68. package/examples/hello-world/node_modules/@types/react/LICENSE +21 -0
  69. package/examples/hello-world/node_modules/@types/react/README.md +15 -0
  70. package/examples/hello-world/node_modules/@types/react/canary.d.ts +129 -0
  71. package/examples/hello-world/node_modules/@types/react/compiler-runtime.d.ts +4 -0
  72. package/examples/hello-world/node_modules/@types/react/experimental.d.ts +184 -0
  73. package/examples/hello-world/node_modules/@types/react/global.d.ts +166 -0
  74. package/examples/hello-world/node_modules/@types/react/index.d.ts +4369 -0
  75. package/examples/hello-world/node_modules/@types/react/jsx-dev-runtime.d.ts +33 -0
  76. package/examples/hello-world/node_modules/@types/react/jsx-runtime.d.ts +24 -0
  77. package/examples/hello-world/node_modules/@types/react/package.json +210 -0
  78. package/examples/hello-world/node_modules/@types/react/ts5.0/canary.d.ts +129 -0
  79. package/examples/hello-world/node_modules/@types/react/ts5.0/experimental.d.ts +184 -0
  80. package/examples/hello-world/node_modules/@types/react/ts5.0/global.d.ts +166 -0
  81. package/examples/hello-world/node_modules/@types/react/ts5.0/index.d.ts +4356 -0
  82. package/examples/hello-world/node_modules/@types/react/ts5.0/jsx-dev-runtime.d.ts +33 -0
  83. package/examples/hello-world/node_modules/@types/react/ts5.0/jsx-runtime.d.ts +24 -0
  84. package/examples/hello-world/node_modules/csstype/LICENSE +19 -0
  85. package/examples/hello-world/node_modules/csstype/README.md +291 -0
  86. package/examples/hello-world/node_modules/csstype/index.d.ts +22569 -0
  87. package/examples/hello-world/node_modules/csstype/index.js.flow +6863 -0
  88. package/examples/hello-world/node_modules/csstype/package.json +70 -0
  89. package/examples/hello-world/node_modules/react/LICENSE +21 -0
  90. package/examples/hello-world/node_modules/react/README.md +37 -0
  91. package/examples/hello-world/node_modules/react/cjs/react-compiler-runtime.development.js +24 -0
  92. package/examples/hello-world/node_modules/react/cjs/react-compiler-runtime.production.js +16 -0
  93. package/examples/hello-world/node_modules/react/cjs/react-compiler-runtime.profiling.js +16 -0
  94. package/examples/hello-world/node_modules/react/cjs/react-jsx-dev-runtime.development.js +338 -0
  95. package/examples/hello-world/node_modules/react/cjs/react-jsx-dev-runtime.production.js +14 -0
  96. package/examples/hello-world/node_modules/react/cjs/react-jsx-dev-runtime.profiling.js +14 -0
  97. package/examples/hello-world/node_modules/react/cjs/react-jsx-dev-runtime.react-server.development.js +370 -0
  98. package/examples/hello-world/node_modules/react/cjs/react-jsx-dev-runtime.react-server.production.js +40 -0
  99. package/examples/hello-world/node_modules/react/cjs/react-jsx-runtime.development.js +352 -0
  100. package/examples/hello-world/node_modules/react/cjs/react-jsx-runtime.production.js +34 -0
  101. package/examples/hello-world/node_modules/react/cjs/react-jsx-runtime.profiling.js +34 -0
  102. package/examples/hello-world/node_modules/react/cjs/react-jsx-runtime.react-server.development.js +370 -0
  103. package/examples/hello-world/node_modules/react/cjs/react-jsx-runtime.react-server.production.js +40 -0
  104. package/examples/hello-world/node_modules/react/cjs/react.development.js +1284 -0
  105. package/examples/hello-world/node_modules/react/cjs/react.production.js +542 -0
  106. package/examples/hello-world/node_modules/react/cjs/react.react-server.development.js +848 -0
  107. package/examples/hello-world/node_modules/react/cjs/react.react-server.production.js +423 -0
  108. package/examples/hello-world/node_modules/react/compiler-runtime.js +14 -0
  109. package/examples/hello-world/node_modules/react/index.js +7 -0
  110. package/examples/hello-world/node_modules/react/jsx-dev-runtime.js +7 -0
  111. package/examples/hello-world/node_modules/react/jsx-dev-runtime.react-server.js +7 -0
  112. package/examples/hello-world/node_modules/react/jsx-runtime.js +7 -0
  113. package/examples/hello-world/node_modules/react/jsx-runtime.react-server.js +7 -0
  114. package/examples/hello-world/node_modules/react/package.json +51 -0
  115. package/examples/hello-world/node_modules/react/react.react-server.js +7 -0
  116. package/examples/hello-world/node_modules/typescript/LICENSE.txt +55 -0
  117. package/examples/hello-world/node_modules/typescript/README.md +50 -0
  118. package/examples/hello-world/node_modules/typescript/SECURITY.md +41 -0
  119. package/examples/hello-world/node_modules/typescript/ThirdPartyNoticeText.txt +193 -0
  120. package/examples/hello-world/node_modules/typescript/bin/tsc +2 -0
  121. package/examples/hello-world/node_modules/typescript/bin/tsserver +2 -0
  122. package/examples/hello-world/node_modules/typescript/lib/_tsc.js +133818 -0
  123. package/examples/hello-world/node_modules/typescript/lib/_tsserver.js +659 -0
  124. package/examples/hello-world/node_modules/typescript/lib/_typingsInstaller.js +222 -0
  125. package/examples/hello-world/node_modules/typescript/lib/cs/diagnosticMessages.generated.json +2122 -0
  126. package/examples/hello-world/node_modules/typescript/lib/de/diagnosticMessages.generated.json +2122 -0
  127. package/examples/hello-world/node_modules/typescript/lib/es/diagnosticMessages.generated.json +2122 -0
  128. package/examples/hello-world/node_modules/typescript/lib/fr/diagnosticMessages.generated.json +2122 -0
  129. package/examples/hello-world/node_modules/typescript/lib/it/diagnosticMessages.generated.json +2122 -0
  130. package/examples/hello-world/node_modules/typescript/lib/ja/diagnosticMessages.generated.json +2122 -0
  131. package/examples/hello-world/node_modules/typescript/lib/ko/diagnosticMessages.generated.json +2122 -0
  132. package/examples/hello-world/node_modules/typescript/lib/lib.d.ts +22 -0
  133. package/examples/hello-world/node_modules/typescript/lib/lib.decorators.d.ts +384 -0
  134. package/examples/hello-world/node_modules/typescript/lib/lib.decorators.legacy.d.ts +22 -0
  135. package/examples/hello-world/node_modules/typescript/lib/lib.dom.asynciterable.d.ts +41 -0
  136. package/examples/hello-world/node_modules/typescript/lib/lib.dom.d.ts +39429 -0
  137. package/examples/hello-world/node_modules/typescript/lib/lib.dom.iterable.d.ts +571 -0
  138. package/examples/hello-world/node_modules/typescript/lib/lib.es2015.collection.d.ts +147 -0
  139. package/examples/hello-world/node_modules/typescript/lib/lib.es2015.core.d.ts +597 -0
  140. package/examples/hello-world/node_modules/typescript/lib/lib.es2015.d.ts +28 -0
  141. package/examples/hello-world/node_modules/typescript/lib/lib.es2015.generator.d.ts +77 -0
  142. package/examples/hello-world/node_modules/typescript/lib/lib.es2015.iterable.d.ts +605 -0
  143. package/examples/hello-world/node_modules/typescript/lib/lib.es2015.promise.d.ts +81 -0
  144. package/examples/hello-world/node_modules/typescript/lib/lib.es2015.proxy.d.ts +128 -0
  145. package/examples/hello-world/node_modules/typescript/lib/lib.es2015.reflect.d.ts +144 -0
  146. package/examples/hello-world/node_modules/typescript/lib/lib.es2015.symbol.d.ts +46 -0
  147. package/examples/hello-world/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts +326 -0
  148. package/examples/hello-world/node_modules/typescript/lib/lib.es2016.array.include.d.ts +116 -0
  149. package/examples/hello-world/node_modules/typescript/lib/lib.es2016.d.ts +21 -0
  150. package/examples/hello-world/node_modules/typescript/lib/lib.es2016.full.d.ts +23 -0
  151. package/examples/hello-world/node_modules/typescript/lib/lib.es2016.intl.d.ts +31 -0
  152. package/examples/hello-world/node_modules/typescript/lib/lib.es2017.arraybuffer.d.ts +21 -0
  153. package/examples/hello-world/node_modules/typescript/lib/lib.es2017.d.ts +26 -0
  154. package/examples/hello-world/node_modules/typescript/lib/lib.es2017.date.d.ts +31 -0
  155. package/examples/hello-world/node_modules/typescript/lib/lib.es2017.full.d.ts +23 -0
  156. package/examples/hello-world/node_modules/typescript/lib/lib.es2017.intl.d.ts +44 -0
  157. package/examples/hello-world/node_modules/typescript/lib/lib.es2017.object.d.ts +49 -0
  158. package/examples/hello-world/node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts +135 -0
  159. package/examples/hello-world/node_modules/typescript/lib/lib.es2017.string.d.ts +45 -0
  160. package/examples/hello-world/node_modules/typescript/lib/lib.es2017.typedarrays.d.ts +53 -0
  161. package/examples/hello-world/node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts +77 -0
  162. package/examples/hello-world/node_modules/typescript/lib/lib.es2018.asynciterable.d.ts +53 -0
  163. package/examples/hello-world/node_modules/typescript/lib/lib.es2018.d.ts +24 -0
  164. package/examples/hello-world/node_modules/typescript/lib/lib.es2018.full.d.ts +24 -0
  165. package/examples/hello-world/node_modules/typescript/lib/lib.es2018.intl.d.ts +83 -0
  166. package/examples/hello-world/node_modules/typescript/lib/lib.es2018.promise.d.ts +30 -0
  167. package/examples/hello-world/node_modules/typescript/lib/lib.es2018.regexp.d.ts +37 -0
  168. package/examples/hello-world/node_modules/typescript/lib/lib.es2019.array.d.ts +79 -0
  169. package/examples/hello-world/node_modules/typescript/lib/lib.es2019.d.ts +24 -0
  170. package/examples/hello-world/node_modules/typescript/lib/lib.es2019.full.d.ts +24 -0
  171. package/examples/hello-world/node_modules/typescript/lib/lib.es2019.intl.d.ts +23 -0
  172. package/examples/hello-world/node_modules/typescript/lib/lib.es2019.object.d.ts +33 -0
  173. package/examples/hello-world/node_modules/typescript/lib/lib.es2019.string.d.ts +37 -0
  174. package/examples/hello-world/node_modules/typescript/lib/lib.es2019.symbol.d.ts +24 -0
  175. package/examples/hello-world/node_modules/typescript/lib/lib.es2020.bigint.d.ts +765 -0
  176. package/examples/hello-world/node_modules/typescript/lib/lib.es2020.d.ts +27 -0
  177. package/examples/hello-world/node_modules/typescript/lib/lib.es2020.date.d.ts +42 -0
  178. package/examples/hello-world/node_modules/typescript/lib/lib.es2020.full.d.ts +24 -0
  179. package/examples/hello-world/node_modules/typescript/lib/lib.es2020.intl.d.ts +474 -0
  180. package/examples/hello-world/node_modules/typescript/lib/lib.es2020.number.d.ts +28 -0
  181. package/examples/hello-world/node_modules/typescript/lib/lib.es2020.promise.d.ts +47 -0
  182. package/examples/hello-world/node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts +99 -0
  183. package/examples/hello-world/node_modules/typescript/lib/lib.es2020.string.d.ts +44 -0
  184. package/examples/hello-world/node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts +41 -0
  185. package/examples/hello-world/node_modules/typescript/lib/lib.es2021.d.ts +23 -0
  186. package/examples/hello-world/node_modules/typescript/lib/lib.es2021.full.d.ts +24 -0
  187. package/examples/hello-world/node_modules/typescript/lib/lib.es2021.intl.d.ts +166 -0
  188. package/examples/hello-world/node_modules/typescript/lib/lib.es2021.promise.d.ts +48 -0
  189. package/examples/hello-world/node_modules/typescript/lib/lib.es2021.string.d.ts +33 -0
  190. package/examples/hello-world/node_modules/typescript/lib/lib.es2021.weakref.d.ts +78 -0
  191. package/examples/hello-world/node_modules/typescript/lib/lib.es2022.array.d.ts +121 -0
  192. package/examples/hello-world/node_modules/typescript/lib/lib.es2022.d.ts +25 -0
  193. package/examples/hello-world/node_modules/typescript/lib/lib.es2022.error.d.ts +75 -0
  194. package/examples/hello-world/node_modules/typescript/lib/lib.es2022.full.d.ts +24 -0
  195. package/examples/hello-world/node_modules/typescript/lib/lib.es2022.intl.d.ts +145 -0
  196. package/examples/hello-world/node_modules/typescript/lib/lib.es2022.object.d.ts +26 -0
  197. package/examples/hello-world/node_modules/typescript/lib/lib.es2022.regexp.d.ts +39 -0
  198. package/examples/hello-world/node_modules/typescript/lib/lib.es2022.string.d.ts +25 -0
  199. package/examples/hello-world/node_modules/typescript/lib/lib.es2023.array.d.ts +924 -0
  200. package/examples/hello-world/node_modules/typescript/lib/lib.es2023.collection.d.ts +21 -0
  201. package/examples/hello-world/node_modules/typescript/lib/lib.es2023.d.ts +22 -0
  202. package/examples/hello-world/node_modules/typescript/lib/lib.es2023.full.d.ts +24 -0
  203. package/examples/hello-world/node_modules/typescript/lib/lib.es2023.intl.d.ts +56 -0
  204. package/examples/hello-world/node_modules/typescript/lib/lib.es2024.arraybuffer.d.ts +65 -0
  205. package/examples/hello-world/node_modules/typescript/lib/lib.es2024.collection.d.ts +29 -0
  206. package/examples/hello-world/node_modules/typescript/lib/lib.es2024.d.ts +26 -0
  207. package/examples/hello-world/node_modules/typescript/lib/lib.es2024.full.d.ts +24 -0
  208. package/examples/hello-world/node_modules/typescript/lib/lib.es2024.object.d.ts +29 -0
  209. package/examples/hello-world/node_modules/typescript/lib/lib.es2024.promise.d.ts +35 -0
  210. package/examples/hello-world/node_modules/typescript/lib/lib.es2024.regexp.d.ts +25 -0
  211. package/examples/hello-world/node_modules/typescript/lib/lib.es2024.sharedmemory.d.ts +68 -0
  212. package/examples/hello-world/node_modules/typescript/lib/lib.es2024.string.d.ts +29 -0
  213. package/examples/hello-world/node_modules/typescript/lib/lib.es5.d.ts +4601 -0
  214. package/examples/hello-world/node_modules/typescript/lib/lib.es6.d.ts +23 -0
  215. package/examples/hello-world/node_modules/typescript/lib/lib.esnext.array.d.ts +35 -0
  216. package/examples/hello-world/node_modules/typescript/lib/lib.esnext.collection.d.ts +96 -0
  217. package/examples/hello-world/node_modules/typescript/lib/lib.esnext.d.ts +29 -0
  218. package/examples/hello-world/node_modules/typescript/lib/lib.esnext.decorators.d.ts +28 -0
  219. package/examples/hello-world/node_modules/typescript/lib/lib.esnext.disposable.d.ts +193 -0
  220. package/examples/hello-world/node_modules/typescript/lib/lib.esnext.error.d.ts +24 -0
  221. package/examples/hello-world/node_modules/typescript/lib/lib.esnext.float16.d.ts +445 -0
  222. package/examples/hello-world/node_modules/typescript/lib/lib.esnext.full.d.ts +24 -0
  223. package/examples/hello-world/node_modules/typescript/lib/lib.esnext.intl.d.ts +21 -0
  224. package/examples/hello-world/node_modules/typescript/lib/lib.esnext.iterator.d.ts +148 -0
  225. package/examples/hello-world/node_modules/typescript/lib/lib.esnext.promise.d.ts +34 -0
  226. package/examples/hello-world/node_modules/typescript/lib/lib.esnext.sharedmemory.d.ts +25 -0
  227. package/examples/hello-world/node_modules/typescript/lib/lib.scripthost.d.ts +322 -0
  228. package/examples/hello-world/node_modules/typescript/lib/lib.webworker.asynciterable.d.ts +41 -0
  229. package/examples/hello-world/node_modules/typescript/lib/lib.webworker.d.ts +13150 -0
  230. package/examples/hello-world/node_modules/typescript/lib/lib.webworker.importscripts.d.ts +23 -0
  231. package/examples/hello-world/node_modules/typescript/lib/lib.webworker.iterable.d.ts +340 -0
  232. package/examples/hello-world/node_modules/typescript/lib/pl/diagnosticMessages.generated.json +2122 -0
  233. package/examples/hello-world/node_modules/typescript/lib/pt-br/diagnosticMessages.generated.json +2122 -0
  234. package/examples/hello-world/node_modules/typescript/lib/ru/diagnosticMessages.generated.json +2122 -0
  235. package/examples/hello-world/node_modules/typescript/lib/tr/diagnosticMessages.generated.json +2122 -0
  236. package/examples/hello-world/node_modules/typescript/lib/tsc.js +8 -0
  237. package/examples/hello-world/node_modules/typescript/lib/tsserver.js +8 -0
  238. package/examples/hello-world/node_modules/typescript/lib/tsserverlibrary.d.ts +17 -0
  239. package/examples/hello-world/node_modules/typescript/lib/tsserverlibrary.js +21 -0
  240. package/examples/hello-world/node_modules/typescript/lib/typesMap.json +497 -0
  241. package/examples/hello-world/node_modules/typescript/lib/typescript.d.ts +11437 -0
  242. package/examples/hello-world/node_modules/typescript/lib/typescript.js +200276 -0
  243. package/examples/hello-world/node_modules/typescript/lib/typingsInstaller.js +8 -0
  244. package/examples/hello-world/node_modules/typescript/lib/watchGuard.js +53 -0
  245. package/examples/hello-world/node_modules/typescript/lib/zh-cn/diagnosticMessages.generated.json +2122 -0
  246. package/examples/hello-world/node_modules/typescript/lib/zh-tw/diagnosticMessages.generated.json +2122 -0
  247. package/examples/hello-world/node_modules/typescript/package.json +120 -0
  248. package/examples/hello-world/package-lock.json +74 -0
  249. package/examples/hello-world/package.json +23 -0
  250. package/examples/hello-world/src/client/index.tsx +110 -0
  251. package/examples/hello-world/src/server/index.ts +42 -0
  252. package/examples/hello-world/tsconfig.json +16 -0
  253. package/package.json +46 -0
  254. package/src/cli.ts +321 -0
@@ -0,0 +1,332 @@
1
+ # ServiceDef 代码风格规范
2
+
3
+ 本指南介绍 linyjs 插件开发中 `ServiceDef` 的两条核心代码风格规范,确保代码组织一致、可读、易维护。
4
+
5
+ ## 为什么需要规范?
6
+
7
+ - 📖 **提高可读性** — 服务定义与实现放在一起,一目了然
8
+ - 🔍 **便于查找** — 看到类就能找到它的 ServiceDef,反之亦然
9
+ - 🛠️ **减少错误** — 独立声明减少缩进层级,避免括号匹配错误
10
+ - 🤝 **团队协作** — 统一风格,降低 review 沟通成本
11
+
12
+ ---
13
+
14
+ ## 规则一:ServiceDef 必须声明为独立变量
15
+
16
+ ### 规则说明
17
+
18
+ `ServiceDef` 必须先声明为独立变量,然后在 `serviceDefs` 数组中通过变量名引用。**禁止**将 `ServiceDef` 对象字面量直接内联在 `serviceDefs` 数组中。
19
+
20
+ ### ✅ 正确写法
21
+
22
+ ```typescript
23
+ import type { IModule, IServiceDef } from '@linyjs/server-module-interface';
24
+
25
+ class HelloController {
26
+ getRoutes() {
27
+ return [/* ... */];
28
+ }
29
+ }
30
+
31
+ const helloControllerDef: IServiceDef = {
32
+ serviceTag: 'helloController',
33
+ serviceImpl: HelloController,
34
+ meta: { usageType: 'controller' }
35
+ };
36
+
37
+ export const helloServerModule: IModule = {
38
+ name: 'helloServer',
39
+ serviceDefs: [helloControllerDef]
40
+ };
41
+ ```
42
+
43
+ ### ❌ 错误写法
44
+
45
+ ```typescript
46
+ import type { IModule } from '@linyjs/server-module-interface';
47
+
48
+ class HelloController {
49
+ getRoutes() {
50
+ return [/* ... */];
51
+ }
52
+ }
53
+
54
+ export const helloServerModule: IModule = {
55
+ name: 'helloServer',
56
+ serviceDefs: [
57
+ {
58
+ serviceTag: 'helloController',
59
+ serviceImpl: HelloController,
60
+ meta: { usageType: 'controller' }
61
+ }
62
+ ]
63
+ };
64
+ ```
65
+
66
+ ### 原因
67
+
68
+ | 对比项 | 独立变量声明 | 内联在数组中 |
69
+ |--------|------------|------------|
70
+ | 缩进层级 | 浅(2层) | 深(4层+) |
71
+ | 可读性 | 高,变量名即语义 | 低,大段对象字面量淹没模块声明 |
72
+ | 复用性 | 可被多个模块引用 | 无法复用 |
73
+ | 维护性 | 修改时不影响模块声明 | 修改时需在数组中定位 |
74
+
75
+ ---
76
+
77
+ ## 规则二:ServiceDef 声明必须与实现类放在同一个文件中
78
+
79
+ ### 规则说明
80
+
81
+ `ServiceDef` 声明必须紧挨着它的 `serviceImpl` 实现类,放在同一个文件中。**禁止**将 `ServiceDef` 和实现类分离到不同文件,然后在模块入口文件中重新声明。
82
+
83
+ ### ✅ 正确写法
84
+
85
+ **`src/server/services/article-controller.ts`**
86
+
87
+ ```typescript
88
+ import type { IControllerService, IControllerServiceDef } from '@linyjs/server-module-interface';
89
+
90
+ export class ArticleController implements IControllerService {
91
+ getRoutes() {
92
+ return [/* ... */];
93
+ }
94
+ }
95
+
96
+ export const articleControllerDef: IControllerServiceDef = {
97
+ serviceTag: 'articleController',
98
+ serviceImpl: ArticleController,
99
+ dependencies: ['mdb.mongoDBService'],
100
+ meta: { usageType: 'controller' }
101
+ };
102
+ ```
103
+
104
+ **`src/server/server-module.ts`**
105
+
106
+ ```typescript
107
+ import type { IModule } from '@linyjs/server-module-interface';
108
+ import { articleControllerDef } from './services/article-controller.js';
109
+
110
+ export const articleServerModule: IModule = {
111
+ name: 'articleServer',
112
+ moduleDependencies: ['mdb'],
113
+ serviceDefs: [articleControllerDef]
114
+ };
115
+ ```
116
+
117
+ ### ❌ 错误写法
118
+
119
+ **`src/server/services/article-controller.ts`** — 只有类,没有 ServiceDef
120
+
121
+ ```typescript
122
+ export class ArticleController implements IControllerService {
123
+ getRoutes() {
124
+ return [/* ... */];
125
+ }
126
+ }
127
+ ```
128
+
129
+ **`src/server/server-module.ts`** — ServiceDef 与类分离
130
+
131
+ ```typescript
132
+ import { ArticleController } from './services/article-controller.js';
133
+
134
+ const articleControllerDef: IControllerServiceDef = {
135
+ serviceTag: 'articleController',
136
+ serviceImpl: ArticleController,
137
+ dependencies: ['mdb.mongoDBService'],
138
+ meta: { usageType: 'controller' }
139
+ };
140
+
141
+ export const articleServerModule: IModule = {
142
+ name: 'articleServer',
143
+ moduleDependencies: ['mdb'],
144
+ serviceDefs: [articleControllerDef]
145
+ };
146
+ ```
147
+
148
+ ### 原因
149
+
150
+ | 对比项 | 同文件放置 | 分离到不同文件 |
151
+ |--------|----------|-------------|
152
+ | 内聚性 | 高,定义与实现在一起 | 低,需跨文件查找 |
153
+ | 修改成本 | 低,改一处即可 | 高,可能漏改 |
154
+ | 文件职责 | 清晰,每个文件自包含 | 模糊,入口文件混杂声明 |
155
+
156
+ ---
157
+
158
+ ## 完整示例
159
+
160
+ 以下是一个完整的服务端模块示例,遵循两条规范:
161
+
162
+ ### 项目结构
163
+
164
+ ```
165
+ src/server/
166
+ ├── controllers/
167
+ │ └── article-controller.ts # ArticleController 类 + articleControllerDef
168
+ ├── middleware/
169
+ │ └── auth-middleware.ts # AuthMiddleware 类 + authMiddlewareDef
170
+ ├── services/
171
+ │ └── article-service.ts # ArticleService 类 + articleServiceDef
172
+ └── server-module.ts # 模块入口,只做导入和组装
173
+ ```
174
+
175
+ ### 控制器文件
176
+
177
+ **`src/server/controllers/article-controller.ts`**
178
+
179
+ ```typescript
180
+ import type { IControllerService, IControllerServiceDef } from '@linyjs/server-module-interface';
181
+
182
+ export class ArticleController implements IControllerService {
183
+ getRoutes() {
184
+ return [
185
+ {
186
+ method: 'GET' as const,
187
+ path: '/api/articles',
188
+ middlewares: [],
189
+ responseType: 'json' as const,
190
+ handler: async () => {
191
+ return { articles: [] };
192
+ }
193
+ }
194
+ ];
195
+ }
196
+ }
197
+
198
+ export const articleControllerDef: IControllerServiceDef = {
199
+ serviceTag: 'articleController',
200
+ serviceImpl: ArticleController,
201
+ dependencies: ['articleService'],
202
+ meta: { usageType: 'controller' }
203
+ };
204
+ ```
205
+
206
+ ### 中间件文件
207
+
208
+ **`src/server/middleware/auth-middleware.ts`**
209
+
210
+ ```typescript
211
+ import type { IMiddlewareService, IMiddlewareServiceDef } from '@linyjs/server-module-interface';
212
+
213
+ export class AuthMiddleware implements IMiddlewareService {
214
+ getMiddlewares() {
215
+ return [{
216
+ middlewareId: 'auth',
217
+ handler: async (params, ctx, next) => {
218
+ // 认证逻辑...
219
+ await next();
220
+ }
221
+ }];
222
+ }
223
+ }
224
+
225
+ export const authMiddlewareDef: IMiddlewareServiceDef = {
226
+ serviceTag: 'authMiddleware',
227
+ serviceImpl: AuthMiddleware,
228
+ meta: { usageType: 'middleware' }
229
+ };
230
+ ```
231
+
232
+ ### 模块入口文件
233
+
234
+ **`src/server/server-module.ts`**
235
+
236
+ ```typescript
237
+ import type { IModule } from '@linyjs/server-module-interface';
238
+ import { articleControllerDef } from './controllers/article-controller.js';
239
+ import { authMiddlewareDef } from './middleware/auth-middleware.js';
240
+
241
+ export const myServerModule: IModule = {
242
+ name: 'myServer',
243
+ serviceDefs: [articleControllerDef, authMiddlewareDef]
244
+ };
245
+ ```
246
+
247
+ > 模块入口文件只负责**导入和组装**,不包含任何 ServiceDef 声明或服务实现类。
248
+
249
+ ---
250
+
251
+ ## 客户端模块同样适用
252
+
253
+ 以上两条规范同样适用于客户端模块:
254
+
255
+ ### ✅ 正确写法
256
+
257
+ **`src/client/index.tsx`**
258
+
259
+ ```typescript
260
+ import type { IModule, IRouteDef } from '@linyjs/client-module-interface';
261
+ import React from 'react';
262
+
263
+ function HelloPage() {
264
+ return <div>Hello!</div>;
265
+ }
266
+
267
+ class HelloRouteService implements IRouteService {
268
+ basePath = '/hello';
269
+
270
+ getRoutes() {
271
+ return [{
272
+ path: '/',
273
+ component: HelloPage,
274
+ key: 'hello-page',
275
+ meta: { title: 'Hello' }
276
+ }];
277
+ }
278
+ }
279
+
280
+ const helloRouteDef: IRouteDef = {
281
+ serviceTag: 'helloRoute',
282
+ serviceImpl: HelloRouteService,
283
+ meta: { usageType: 'route' }
284
+ };
285
+
286
+ export const helloClientModule: IModule = {
287
+ name: 'helloClient',
288
+ serviceDefs: [helloRouteDef]
289
+ };
290
+ ```
291
+
292
+ ### ❌ 错误写法
293
+
294
+ ```typescript
295
+ // ServiceDef 内联在数组中,且使用了匿名类
296
+ export const helloClientModule: IModule = {
297
+ name: 'helloClient',
298
+ serviceDefs: [{
299
+ serviceTag: 'helloRoute',
300
+ serviceImpl: class {
301
+ basePath = '/hello';
302
+ getRoutes() { /* ... */ }
303
+ },
304
+ meta: { usageType: 'route' }
305
+ }]
306
+ };
307
+ ```
308
+
309
+ > 客户端模块中如果文件较小(如 Hello World 级别),可以将类、ServiceDef 和模块声明放在同一个文件中。但仍然禁止内联在 `serviceDefs` 数组中,也禁止使用匿名类作为 `serviceImpl`。
310
+
311
+ ---
312
+
313
+ ## 检查清单
314
+
315
+ 在提交代码前,请检查以下几点:
316
+
317
+ - [ ] 所有 `ServiceDef` 都声明为独立变量,未内联在 `serviceDefs` 数组中
318
+ - [ ] 每个 `ServiceDef` 声明都紧挨着对应的实现类,在同一个文件中
319
+ - [ ] `serviceImpl` 使用具名类,不使用匿名类或内联箭头函数
320
+ - [ ] 模块入口文件(`server-module.ts` / `client-module.ts`)只做导入和组装,不包含 ServiceDef 声明
321
+ - [ ] 导入类型时包含 `IServiceDef`(或其子类型如 `IControllerServiceDef`),为声明提供类型标注
322
+
323
+ ## 相关文档
324
+
325
+ - 📖 [服务端模块开发](../guides/server-module.md)
326
+ - 📖 [客户端模块开发](../guides/client-module.md)
327
+ - 📖 [命名规范](./naming-conventions.md)
328
+ - ⚠️ [错误处理](./error-handling.md)
329
+
330
+ ---
331
+
332
+ **上一篇**: [命名规范](./naming-conventions.md) | **下一篇**: [错误处理](./error-handling.md)
package/docs/faq.md ADDED
@@ -0,0 +1,322 @@
1
+ # 常见问题 (FAQ)
2
+
3
+ ## 入门相关
4
+
5
+ ### Q1: linyjs 是什么?
6
+
7
+ **A:** linyjs 是一个插件式的前后端应用平台,允许开发者通过创建 `.mpk` 格式的插件来扩展平台功能。它提供了完整的前后端开发框架,包括依赖注入、权限控制、UI扩展等特性。
8
+
9
+ ### Q2: 我需要哪些前置知识?
10
+
11
+ **A:**
12
+ - TypeScript (必需)
13
+ - React (客户端开发)
14
+ - Node.js (服务端开发)
15
+ - 基本的 HTTP/API 概念
16
+
17
+ ### Q3: 如何开始第一个插件?
18
+
19
+ **A:** 阅读 [快速开始](./getting-started/quick-start.md) 教程,5分钟即可创建你的第一个插件!
20
+
21
+ ---
22
+
23
+ ## 安装和配置
24
+
25
+ ### Q4: 如何安装 linyjs CLI 工具?
26
+
27
+ **A:**
28
+ ```bash
29
+ # 全局安装(推荐)
30
+ npm install -g @linyjs/cli
31
+
32
+ # 或使用 npx
33
+ npx @linyjs/cli <command>
34
+ ```
35
+
36
+ ### Q5: TypeScript 编译错误怎么办?
37
+
38
+ **A:** 确保:
39
+ 1. 安装了正确版本的 TypeScript (`^5.7.0`)
40
+ 2. `tsconfig.json` 配置正确
41
+ 3. 所有类型定义包已安装 (`@types/react` 等)
42
+
43
+ ### Q6: 如何更新到最新版本?
44
+
45
+ **A:**
46
+ ```bash
47
+ npm update @linyjs/server-module-interface
48
+ npm update @linyjs/client-module-interface
49
+ npm update @linyjs/cli
50
+ ```
51
+
52
+ ---
53
+
54
+ ## 开发相关
55
+
56
+ ### Q7: 如何调试插件?
57
+
58
+ **A:**
59
+
60
+ **方法 1: 使用 tsx 运行**
61
+ ```bash
62
+ npx tsx src/server/index.ts
63
+ ```
64
+
65
+ **方法 2: 添加日志**
66
+ ```typescript
67
+ console.log('[MyPlugin]', 'Debug info:', data);
68
+ ```
69
+
70
+ **方法 3: 浏览器 DevTools**
71
+ 客户端代码可以在浏览器中调试。
72
+
73
+ ### Q8: 插件之间如何通信?
74
+
75
+ **A:**
76
+
77
+ **方式 1: 通过共享服务**
78
+ ```typescript
79
+ // 插件 A 提供服务
80
+ export const serviceA = {
81
+ serviceTag: 'sharedService',
82
+ serviceImpl: SharedService
83
+ };
84
+
85
+ // 插件 B 使用服务
86
+ export const serviceB = {
87
+ serviceTag: 'consumer',
88
+ serviceImpl: ConsumerService,
89
+ dependencies: ['pluginA.sharedService']
90
+ };
91
+ ```
92
+
93
+ **方式 2: 通过全局状态**
94
+ 使用 jotai atoms 共享状态。
95
+
96
+ ### Q9: 如何处理插件版本兼容性?
97
+
98
+ **A:** 在 `manifest.json` 中指定依赖版本:
99
+ ```json
100
+ {
101
+ "dependencies": {
102
+ "core-auth": "^1.0.0",
103
+ "core-mongodb": ">=1.2.0"
104
+ }
105
+ }
106
+ ```
107
+
108
+ ### Q10: 插件可以修改其他插件的行为吗?
109
+
110
+ **A:** 可以通过以下方式:
111
+ 1. **覆盖路由**: 注册相同路径的路由(后加载的优先)
112
+ 2. **扩展 Slot**: 向现有 Slot 添加新组件
113
+
114
+ ---
115
+
116
+ ## 打包和发布
117
+
118
+ ### Q11: 如何打包插件?
119
+
120
+ **A:** 使用 CLI 工具:
121
+ ```bash
122
+ cd my-plugin
123
+ npx @linyjs/cli pack
124
+ ```
125
+
126
+ 这将自动完成:构建、生成 manifest、验证结构、打包压缩。
127
+
128
+ ### Q12: .mpk 文件是什么格式?
129
+
130
+ **A:** `.mpk` 是 ZIP 压缩格式,包含:
131
+ ```
132
+ my-plugin.mpk (ZIP)
133
+ ├── manifest.json # 插件清单
134
+ ├── server/ # 服务端模块
135
+ │ └── index.js # 编译后的 JS
136
+ ├── client/ # 客户端模块
137
+ │ └── index.js # 编译后的 JS
138
+ └── assets/ # 静态资源
139
+ ```
140
+
141
+ ### Q13: 如何测试插件?
142
+
143
+ **A:**
144
+ ```bash
145
+ # 将插件复制到 extensions 目录
146
+ cp my-plugin.mpk /path/to/linyjs/packages/ssr/extensions/
147
+
148
+ # 启动 SSR 服务器
149
+ cd /path/to/linyjs/packages/ssr
150
+ npx tsx src/demo/dev-server-with-pkg.tsx
151
+ ```
152
+
153
+ ---
154
+
155
+ ## 高级主题
156
+
157
+ ### Q14: 为什么我的插件无法访问 React Context?
158
+
159
+ **A:** 这通常是因为 React 实例不共享导致的。确保:
160
+ 1. CLI 已 external React(默认行为)
161
+ 2. 宿主应用提供了 React(通过 Import Map)
162
+ 3. 所有插件使用同一个 React 版本
163
+
164
+ ```html
165
+ <!-- 宿主应用的 HTML -->
166
+ <script type="importmap">
167
+ {
168
+ "imports": {
169
+ "react": "/vendor/react.production.min.js",
170
+ "react-dom": "/vendor/react-dom.production.min.js"
171
+ }
172
+ }
173
+ </script>
174
+ ```
175
+
176
+ ### Q15: CLI 打包的 Bundle 体积太大怎么办?
177
+
178
+ **A:** CLI 默认启用了优化:
179
+ - ✅ esbuild - 极速构建和小体积
180
+ - ✅ Minification - 代码压缩
181
+ - ✅ Tree Shaking - 移除未使用代码
182
+ - ✅ External Dependencies - React 等由宿主提供
183
+
184
+ 进一步优化:
185
+ ```typescript
186
+ // 使用懒加载
187
+ const HeavyComponent = React.lazy(() => import('./HeavyComponent'))
188
+
189
+ // 代码分割
190
+ import('./module').then(module => {
191
+ // 动态导入
192
+ })
193
+ ```
194
+
195
+ ### Q16: 如何处理插件卸载?
196
+
197
+ **A:** 建议在插件中提供清理逻辑:
198
+ ```typescript
199
+ export function onUninstall() {
200
+ // 清理数据
201
+ db.collection('my_data').deleteMany({ plugin: 'my-plugin' });
202
+ }
203
+ ```
204
+
205
+ ### Q17: 插件可以访问环境变量吗?
206
+
207
+ **A:** 可以,通过 `process.env`:
208
+ ```typescript
209
+ const apiKey = process.env.MY_PLUGIN_API_KEY;
210
+ ```
211
+
212
+ 确保在 `.env` 文件中配置:
213
+ ```bash
214
+ MY_PLUGIN_API_KEY=your-api-key
215
+ ```
216
+
217
+ ---
218
+
219
+ ## 性能和优化
220
+
221
+ ### Q18: 如何优化插件性能?
222
+
223
+ **A:**
224
+ 1. **懒加载组件**
225
+ ```typescript
226
+ const HeavyComponent = React.lazy(() => import('./HeavyComponent'));
227
+ ```
228
+
229
+ 2. **避免不必要的重渲染**
230
+ ```typescript
231
+ import { memo } from 'react';
232
+ const ExpensiveComponent = memo(({ data }) => {
233
+ return <div>{/* ... */}</div>;
234
+ });
235
+ ```
236
+
237
+ 3. **使用缓存**
238
+ ```typescript
239
+ const cachedData = useMemo(() => expensiveCalculation(data), [data]);
240
+ ```
241
+
242
+ ### Q19: 如何减少 Bundle 大小?
243
+
244
+ **A:**
245
+ - 使用 tree shaking(确保使用 ES modules)
246
+ - External 大型依赖(如 lodash)
247
+ - 代码分割和懒加载
248
+ - 压缩图片等资源
249
+
250
+ ---
251
+
252
+ ## 安全性
253
+
254
+ ### Q20: 如何防止 XSS 攻击?
255
+
256
+ **A:**
257
+ ```typescript
258
+ function SafeDisplay({ content }: { content: string }) {
259
+ // 转义 HTML
260
+ const escaped = escapeHtml(content);
261
+ return <div dangerouslySetInnerHTML={{ __html: escaped }} />;
262
+ }
263
+ ```
264
+
265
+ ### Q21: 如何防止 SQL 注入?
266
+
267
+ **A:** 使用参数化查询:
268
+ ```typescript
269
+ // ❌ 不安全
270
+ const user = await db.collection('users').findOne({
271
+ email: userInput // 可能被注入
272
+ });
273
+
274
+ // ✅ 安全(使用 MongoDB 的参数化查询)
275
+ const user = await db.collection('users').findOne({
276
+ email: userInput // MongoDB 会自动处理
277
+ });
278
+ ```
279
+
280
+ ### Q22: 如何验证用户输入?
281
+
282
+ **A:**
283
+ ```typescript
284
+ handler: async (params) => {
285
+ const { email } = params.body;
286
+
287
+ // 验证邮箱格式
288
+ if (!isValidEmail(email)) {
289
+ return {
290
+ status: 400,
291
+ data: { error: 'Invalid email format' }
292
+ };
293
+ }
294
+ }
295
+ ```
296
+
297
+ ---
298
+
299
+ ## 获取帮助
300
+
301
+ ### Q23: 遇到问题怎么办?
302
+
303
+ **A:**
304
+ 1. 📖 查阅本文档和相关指南
305
+ 2. 💡 查看[示例项目](../examples/)
306
+ 3. 🔍 搜索 GitHub Issues
307
+ 4. 💬 在社区论坛提问
308
+ 5. 🐛 报告 Bug: [GitHub Issues](https://github.com/linyjs/linyjs/issues)
309
+
310
+ ### Q24: 如何贡献文档?
311
+
312
+ **A:**
313
+ 1. Fork 仓库
314
+ 2. 修改或添加文档
315
+ 3. 提交 Pull Request
316
+ 4. 等待审查和合并
317
+
318
+ 详见 [CONTRIBUTING.md](../CONTRIBUTING.md)
319
+
320
+ ---
321
+
322
+ **返回**: [文档首页](../README.md)