Coder Social home page Coder Social logo

sinisimattia / tapi Goto Github PK

View Code? Open in Web Editor NEW
38.0 38.0 0.0 917 KB

Consume APIs and convert them to TypeScript objects

Home Page: https://tapi.js.org

License: GNU General Public License v3.0

TypeScript 90.35% JavaScript 9.65%
api automapper converter deno javascript json typescript

tapi's Introduction

Hi there

Thank you for visiting my profile.


I'm currently working on building free, open and inclusive online platforms for managing anything from a blog to a school.

Have any cool ideas? Let's talk about them! I'm always open to collaboration on all sorts of projects.

Contact me here [email protected] 📪 or visit my site at mattia.codes 🔗

Top Langs

Trophies

tapi's People

Contributors

gregory-gerard avatar sinisimattia avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

tapi's Issues

Split Builder and `BuilderConfiguration`

This will contain the Aliases, Transformers, etc.

Objects don't need a whole builder, just its config object, the builder will use that instead of all the internal properties.

Error TS2307

Describe the bug
When building the project after installing tapi, get several TS2307 errors (e.g. Error: node_modules/tapi.js/dist/es/index.d.ts:1:21 - error TS2307: Cannot find module '@/core/Builder' or its corresponding type declarations).

May or may not be relevant, I got this error on an Angular 15 project.

To Reproduce
Install library using npm i -D tapi.js, then build/run the project (e.g. ng serve on Angular)

Expected behavior
Successful compilation

Environment (please complete the following information):

  • tapi version 0.5.0
  • node version 9.5.0
  • Angular version 15.2.0

Typescript config file(s):

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "noImplicitOverride": true,
    "noPropertyAccessFromIndexSignature": true,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,
    "sourceMap": true,
    "declaration": false,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "moduleResolution": "node",
    "importHelpers": true,
    "target": "ES2022",
    "module": "ES2022",
    "useDefineForClassFields": false,
    "lib": [
      "ES2022",
      "dom"
    ]
  },
  "angularCompilerOptions": {
    "enableI18nLegacyMessageIdFormat": false,
    "strictInjectionParameters": true,
    "strictInputAccessModifiers": true,
    "strictTemplates": true
  }
}

Additional context
I assume there is some (Babel?) syntax that is not supported universally in JavaScript. I could probably do a few searches to find how to compile with this syntax but put up this issue since other new users may encounter this issue.

Publicity

  • Publish article on Hashnode
  • - [ ] Publish project on Elixir
  • - [ ] Post about the project on my Ko-Fi page

Duplicate object when building array of items

Describe the bug
The object reference doesn't get updated when dealing with lists of items.

To Reproduce
Try to build any list of items, as an example:

state.list = (newProjects.content as any[]).map(project => new Project().fromJSON(project));

Solution
When returning the built object simply do this

return { ...new ClassToBuild().fromJSON(data) } as ClassToBuild

Wrong behavior with inheritance?

Describe the bug
I'm currently working with tapi.js to parse API response and create new class instance with ease 🙂

However, when I use tapi with classes that extend an abstract class, the class returned by the builder is the abstract class and not the concrete class.

To Reproduce
https://stackblitz.com/edit/typescript-t4ibg5?devToolsHeight=33&file=index.ts

Expected behavior
I'd expect that builder return concrete class instance.

Environment (please complete the following information):

  • tapi version v0.4.2
  • node version v18.9.0

Typescript config file(s):

{
  "compilerOptions": {
    "target": "ESNext",
    "useDefineForClassFields": true,
    "lib": ["DOM", "DOM.Iterable", "ESNext"],
    "allowJs": false,
    "skipLibCheck": true,
    "esModuleInterop": false,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "ESNext",
    "moduleResolution": "Node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx",
    "experimentalDecorators": true
  },
  "include": ["src"],
  "references": [{ "path": "./tsconfig.node.json" }]
}
{
  "compilerOptions": {
    "composite": true,
    "module": "ESNext",
    "moduleResolution": "Node",
    "allowSyntheticDefaultImports": true
  },
  "include": ["vite.config.ts"]
}

Additional context
I have a little trouble with prototype inheritance in JS, but from what I understand :

When I call Object.getPrototypeOf(Admin), the prototype of UserObject is returned.

So in the BuildableResource.ts file, when tapi gets the constructor like this: Admin.constructor.prototype.constructor, this is where the UserObject is returned.

I'm actively looking for a solution and will come back to post it if I find one, but in the meantime I'm posting the issue because the problem might be with my class definitions? In any case several pairs of eyes are better than one 😅

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.