narvin-tpt-sdk
v0.6.3-0
Published
## Requirements
Downloads
16
Readme
narvin-tpt-sdk
Requirements
- Node.js + npm. Versions are defined in
./package.json
and.nvmrc
.
How to use?
Import whatever you need from narvin-tpt-sdk
module eg.
import { AuthorService } from 'narvin-tpt-sdk';
new authorService() = new AuthorService();
const author = authorService.getOne();
If you need some developers tools you can import them from narvin-tpt-sdk/dev
eg.
import { AuthorMockService } from 'narvin-tpt-sdk/dev';
new authorMockService() = new AuthorMockService();
const author = authorMockService.getOne();
Structure
SDK is devided into:
core - place for config, errors, requests logic. Mostly for internal usage.
domain - here we should place all our domain related logic. Every domain can consist of:
- services/ - directory where we put all domain related services.
Each Service should use standarised protocol for communication:
- Be class based
- Make use of
FailedResult
andCorrectResult
types as an return value from function
- repository.ts - file where we fetch data.
- factory.ts - place where we create our models.
- schemas.ts - file where we defined zod schemas which are used during fetching.
- types.ts - place to define our models/schema types.
- errors.ts - fiel to define custom errors.
- index.ts - entry file to our domain. We should only export elements which should be publicly available.
- index.dev.ts - entry file to our domain but only for developer purposes only.
- services/ - directory where we put all domain related services.
Each Service should use standarised protocol for communication:
utils - place for internal, not domain specific utils.
API docs
Basic information about API is available here.
Q&A
- Why we don't use class based models? - We are using typed plain object instead of contstructed ones (
new Modal()
) as models, because of React Server Components limitation which is forbidding use of them (serialization problem). - How to develop locally? - Use
npm link
here andnpm link narvin-tpt-sdk
in your project directory. - How to publish? - Login to company account via
npm login
, create new version withnpm version
and publish vianpm publish
TODO
- Translate error messages?
- Refactor apiRequest function
- Handle 204 apiRequest better (problem with missing schema)
- Split to smaller modules?
- Move error codes to static property of services
- Watch for cycle dependencies -> author <==> article
- Split author and category schema between detail and collection ones. In detail we will have articles, in collection not