-
03d0b2f: # Breaking changes
Remove
readonly
library util in favor of nativez.ZodReadonly
.Upgrades should remove the library
readonly
since it is not going to be handled anymore.Zod recently released a native way of handling readonly. Although this readonly is not exactly the same as what we call "readonly" from our db resources. It does allow us to mark fields as readonly and we can take advantage of this mark and make the corresponding type inferences to treat these fields as our own readonly.
- Upgrade Zod to >=3.23.8
- Remove any
import {readonly} from '@thinknimble/tn-models'
- Replace any
readonly(zod)
withzod.readonly()
which is the native way of doing this with zod - That should be it!
- 187e807: Fix issue on
createCustomServiceCall
where outputShapes with nested ZodBranded fields would cause the types for the resulting service call function to break.
- 35fb8f8: Add boolean to accepted types for filters
- 986108e: - Allow disabling warning logs with
disableLoggingWarning
option- Try-catch all
parse
calls so that users don't just get the intelligible zod error in console.
- Try-catch all
-
2f61919: ## Migration Guide v2 - v3
- Now all functions accept a single object as parameter. No more secondary parameters.
- Improvements on the type layer ( non perceptible from user perspective). Removed all overloads for functions which were a pain to maintain. Now a single function definition makes the inference for all possibilities.
For a full fledged example on how to migrate you can check the test file changes on the v3 PR.
The summary is as follows:
- The callback no longer is in the second parameter. Instead we provide it in the first parameter as a
cb
field
const testPost = createCustomServiceCall( { inputShape, outputShape, + cb: async ({ client, input, utils, slashEndingBaseUri }) => { + const toApiInput = utils.toApi(input) + const res = await client.post(slashEndingBaseUri, toApiInput) + const parsed = utils.fromApi(res.data) + return parsed + }, -async ({ client, input, utils, slashEndingBaseUri }) => { - const toApiInput = utils.toApi(input) - const res = await client.post(slashEndingBaseUri, toApiInput) - const parsed = utils.fromApi(res.data) - return parsed -} })
- options (
uri
andhttpMethod
) are no longer in the second parameter. Instead we pass them in anopts
field in the first parameter.
const paginatedServiceCall = createPaginatedServiceCall( { outputShape, inputShape, + opts: { + httpMethod: "post" + } }, - { httpMethod: "post" } )
- If you don't have any custom calls in the
createApi
call then you should be good ✅ - If you do have custom calls, move the second parameter into a
customCalls
field in the first parameter.
const testApi = createApi( { baseUri, client: mockedAxios, + customCalls: { + testPost + } }, - { - testPost, - } )
- b4e81ed: Rollback changes made to filter parsing, it users can use their own axios client to do the serializing of parameters. tn-models will not take part on that
- cdb5ea6: Make filters in built-in method
list
to be partial
- 54e7707: Add upsert built-in method. This method merges both create and update into a single one. if an ID property is passed an update is performed, otherwise a create is called.
- 5678bcd: - Fix issue where using shapes with
readonly
fields in custom service calls would breakcreateApi
resulting custom call type.
- c8fa1f2: Add default parsing for array query params to be a joined comma separated string
- 650e5b8: Fix issue with
update
not properly camel casing the return object
- a7eec87: Fix issue with type exposing an enpty object typed filter when no extra filters were passed to models
- 545bcf4: Fix: add missing exports which were causing some type inference issues
- Fix issue where zod names were not properly resolved in some environments, thus internal zod checks were failing unnoticeably
- c9f65b6: Allow to pass array of strings or numbers to filters
- 1821769: - Fix issue with
instanceof
operator not working as expected in different nodeJS environments.- Replaced with a naive but more reliable implementation which uses
typeName
fromzod
to be able to tell apart zod instance types.
- Replaced with a naive but more reliable implementation which uses
- 0363678: - Fix paginated response returning brand in its type.
- Fix wrong type error when trying to add models without entity or without an id field
-
482601b: Release tn-models from tn-models-fp.
This is a major update and the api was completely changed in favor of a better type layer support for typescript users.
Please read the docs at our repo for more information as to how can this new version be used.
- 71c1cc8: Prevent obfuscation of extra fields coming from responses. Now these fields will be available in the response (just won't be type-discoverable). Paginated calls will receive them as camelCased, whereas regular calls will receive them as they come from the raw response.
- 1aa2f85: Add chance to call built in methods without a trailing slash. TODO: type level remove restriction of axios
- 98b8519: Fix issue with
readonly
not properly working on Vue and other JS environments. Changed the way ZodBrand is being checked.
- 77705b2: Fix readonly fields not working properly on create model override. Now readonly fields should be completely ignored for create model override. Allowing you to re-use your entity models that have readonly fields in case you want to.
- b051a97:
createPaginatedServiceCall
fix not properly camel casing nested array fields
- a2c44a0: createPaginatedServiceCall allow url params to be passed to paginated call so that we can build our own uri with a function. Now if a
urlParams
is passed down to the inputShape we will take that as a uri parameter which will require to pass a function in second parameter
- 89f68e2: Fix
readonly
function being exported as type
- 5ebb3b2: createCustomServiceCall - allow output shape to be of type ZodArray
- bb2a6eb: custom calls - allow input and output shape to be native enums
- fd42759: Fix
GetInferredFromRaw
inferring readonly brands
- fcd3a2e:
createApi
show error when users try to pass things intomodels
that are not valid
- ddad1f6: Fix
createApi
resulting type breaking if not passing any models to it
- a13361d: Fix
create
built-in method requiring readonly fields as input.
- 566582f: Make
create
method to always exist if there's a declared entity shape frommodels
. This makes it so that if you want to use your owncreate
shape inmodels
you can, but that's now optional. If resolved fromentity
shape then the resulting callback signature is going to strip all readonly fields andid
from the entity shape and use that resolved type as the input.
- 5dacdf6: Fix issue with return type of remove
- 8af767a: Allow ids to be of type string or number and infer them properly in the corresponding inputs from built-in methods. Improve branded types resolution of return types from built-in methods.
- f976657: Add chance to declare readonly fields at root level of entity shapes. Introduce
update
anddelete
built-in methods for the api.update
has a couple of variants which allow users to pick the right behaviour for their update calls
- b1392c9: Fix standAlone calls including base uri when it would always be undefined
- 33a6eb5: Add filters to the main methods of the library.
createCustomServiceCall
createCustomServiceCall.standAlone
andcreatePaginatedServiceCall
allowfilterShape
which yields aparsedFilters
parameter in the callback for you to get snake cased parsed filters and pass them as parameters to your axios calls. Adding filters modify current input arguament so beware that you'll need an object withinput
andfilters?
- d17171e: Add
standAlone
function tocreateCustomServiceCall
. This fn allows users to create a service call that does not need to be attached to any api, it can work on its own. The only extra requirement for this call is the axios client.
- ddecbf6: Fix paginated requests doing strict parse of responses instead of safe parse. Remove use of
parse
inlist
andcreatePaginatedServiceCall
- e64ed54: Allow passing filters to
createPaginatedServiceCall
. For this there's a newmodels
field that can be used to pass the filters shape:filtersShape
. You'll then get afilters
optional key when using the service call which will allow you to pass the filters you declared
- 9679bd2: Fix missing argument in
Pagination.hasNextPage
- b7f9346: Fix
createPaginatedServiceCall
erroring when not passing opts param. Now it should allow you to skip the second parameter and thus use its built-in defaults ( uri = '' , httpMethod = 'get' )
- dc5421e: Fix issue with nulls being considered of type object in js. Mischeck was crashing library on null values
- c31e928:
createPaginatedServiceCall
uri parameter now is optional, and it is now also properly handled if it is an empty string
- 8270dfe: Fix
createPaginatedServiceCall
not snake casing the request properly. @paribaker
- 25b3716: Fix issue where object fields of arrays were not properly cased
- 6f39fad: createCustomServiceCall: allow output shapes to be arrays. Improve createApiUtils so that output shpaes can also be arrays and manage them properly.
- 9c97033: Add type-wrapper to axios client provided in
createCustomServiceCall
argument so that we make sure users pass a slash ending uri rather than any string. This has some caveats that have been updated in our README
- c6e3f47: Allow users to skip including models in their api creation. Models now is completely optional and types are properly inferred based on which models are passed.
create
model is not allowed to be passed alone, same forextraFilters
.
- bc4193f: Change
endpoint
forbaseUri
. Update custom service calls baseUri parameter to have a better name and hint users they should consider that baseUri to contain a trailing slash
- 9404505: Fix fromApi not using the right zod to compare
- b5dbef0: Fix issue with createPaginatedServiceCall not properly inferring return type of entity lit
- 1af70d0: Re-add zod shapes as main way of validating input and outputs. Add support for zod operators: optional, nullable, nullish, or/union, and/intersection
- 3cd5224: Change createPaginatedServiceCall to ask for pagination parameter on return callback
- 553cf31: Add createPaginatedServiceCall util to add better paginated requests
- cc42056: Add export for recursiveShapeToValidZodRawShape and add extra documentation around this method as well (will probably remove this export in the future)
- 43c3973: Move
Prettify
util to an actual ts file instead ofglobal.d.ts
- f0de186: Add missing type exports for recursive shapes
- 8940172: - Breaking: Allow recursive shapes to be used as input shapes
- Breaking: Remove the need for users to call z.object on their shapes' objects (we now do that on our end)
- 773bb15: Update readme for contribution guide
- a6fa7a8: Publish 0.0.3
- 1817cc3: First version of the tn-models-fp package