From fbce21f3c25d31edbbb46b5c2f7305775dcd3b16 Mon Sep 17 00:00:00 2001 From: Nathaniel Tucker Date: Tue, 3 Sep 2024 14:44:15 +0200 Subject: [PATCH] docs: Add schema table to README --- .changeset/early-balloons-judge.md | 7 +++ README.md | 84 +++++++++++++++++++++++--- packages/endpoint/README.md | 94 ++++++++++++++++++++++++------ packages/normalizr/README.md | 80 +++++++++++++++++++++++++ packages/normalizr/docs/api.md | 78 +++++++++++++++++++++++++ packages/rest/README.md | 78 +++++++++++++++++++++++++ 6 files changed, 395 insertions(+), 26 deletions(-) create mode 100644 .changeset/early-balloons-judge.md diff --git a/.changeset/early-balloons-judge.md b/.changeset/early-balloons-judge.md new file mode 100644 index 000000000000..0643ee4083c4 --- /dev/null +++ b/.changeset/early-balloons-judge.md @@ -0,0 +1,7 @@ +--- +'@data-client/normalizr': patch +'@data-client/endpoint': patch +'@data-client/rest': patch +--- + +Add schema table to README diff --git a/README.md b/README.md index 055117a571c0..f9bfa37126a7 100644 --- a/README.md +++ b/README.md @@ -298,12 +298,78 @@ For the small price of 9kb gziped.    [🏁Get started now](https://da - [Endpoints](https://dataclient.io/rest/api/Endpoint): [RestEndpoint](https://dataclient.io/rest/api/RestEndpoint), [GQLEndpoint](https://dataclient.io/graphql/api/GQLEndpoint) - [Resources](https://dataclient.io/docs/getting-started/resource): [resource()](https://dataclient.io/rest/api/resource), [hookifyResource()](https://dataclient.io/rest/api/hookifyResource) - [Data model](https://dataclient.io/docs/concepts/normalization) - - [Entity](https://dataclient.io/rest/api/Entity), [schema.Entity](https://dataclient.io/rest/api/schema.Entity) mixin, [GQLEntity](https://dataclient.io/graphql/api/GQLEntity) - - [Object](https://dataclient.io/rest/api/Object) - - [Array](https://dataclient.io/rest/api/Array) - - [Values](https://dataclient.io/rest/api/Values) - - [All](https://dataclient.io/rest/api/All) - - [Collection](https://dataclient.io/rest/api/Collection) - - [Query](https://dataclient.io/rest/api/Query) - - [Union](https://dataclient.io/rest/api/Union) - - [Invalidate](https://dataclient.io/rest/api/Invalidate) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Data TypeMutableSchemaDescriptionQueryable
ObjectEntitysingle unique object
Union(Entity)polymorphic objects (A | B)
🛑Objectstatically known keys🛑
Invalidate(Entity)delete an entity🛑
ListCollection(Array)growable lists
🛑Arrayimmutable lists🛑
Alllist of all entities of a kind
MapCollection(Values)growable maps
🛑Valuesimmutable maps🛑
anyQuery(Queryable)memoized custom transforms
diff --git a/packages/endpoint/README.md b/packages/endpoint/README.md index 902d6b4bd213..8c5b30f4c73f 100644 --- a/packages/endpoint/README.md +++ b/packages/endpoint/README.md @@ -201,24 +201,84 @@ const UserDetail = new Endpoint(({ id }) ⇒ fetch(`/users/${id}`)); const UserDetailNormalized = UserDetail.extend({ schema: User }); ``` -### Index +## Schemas + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Data TypeMutableSchemaDescriptionQueryable
ObjectEntitysingle unique object
Union(Entity)polymorphic objects (A | B)
🛑Objectstatically known keys🛑
Invalidate(Entity)delete an entity🛑
ListCollection(Array)growable lists
🛑Arrayimmutable lists🛑
Alllist of all entities of a kind
MapCollection(Values)growable maps
🛑Valuesimmutable maps🛑
anyQuery(Queryable)memoized custom transforms
-```typescript -import { Entity } from '@data-client/normalizr'; -import { Index } from '@data-client/endpoint'; - -class User extends Entity { - id = ''; - username = '';\ - - static indexes = ['username'] as const; -} - -const bob = useQuery(User, { username: 'bob' }); - -// @ts-expect-error Indexes don't fetch, they just retrieve already existing data -const bob = useSuspense(UserIndex, { username: 'bob' }); -``` ## API diff --git a/packages/normalizr/README.md b/packages/normalizr/README.md index bdaf5d6d0a0a..fd929e3837ed 100644 --- a/packages/normalizr/README.md +++ b/packages/normalizr/README.md @@ -227,6 +227,86 @@ is an Array of paths of all entities included in the result. `memo.buildQueryKey()` builds the input used to denormalize for `query()`. This is exposed to allow greater flexibility in its usage. +## Schemas + +Available from [@data-client/endpoint](https://www.npmjs.com/package/@data-client/endpoint) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Data TypeMutableSchemaDescriptionQueryable
ObjectEntitysingle unique object
Union(Entity)polymorphic objects (A | B)
🛑Objectstatically known keys🛑
Invalidate(Entity)delete an entity🛑
ListCollection(Array)growable lists
🛑Arrayimmutable lists🛑
Alllist of all entities of a kind
MapCollection(Values)growable maps
🛑Valuesimmutable maps🛑
anyQuery(Queryable)memoized custom transforms
+ ## Benchmarks [Performance compared](https://github.com/reactive/data-client/blob/master/examples/benchmark/README.md) to normalizr package (higher is better): diff --git a/packages/normalizr/docs/api.md b/packages/normalizr/docs/api.md index ddd9eb479193..a241c4bda91c 100644 --- a/packages/normalizr/docs/api.md +++ b/packages/normalizr/docs/api.md @@ -77,6 +77,84 @@ const denormalizedData = denormalize(mySchema, { users: [1, 2] }, entities); ## `schema` +Available from [@data-client/endpoint](https://www.npmjs.com/package/@data-client/endpoint) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Data TypeMutableSchemaDescriptionQueryable
ObjectEntitysingle unique object
Union(Entity)polymorphic objects (A | B)
🛑Objectstatically known keys🛑
Invalidate(Entity)delete an entity🛑
ListCollection(Array)growable lists
🛑Arrayimmutable lists🛑
Alllist of all entities of a kind
MapCollection(Values)growable maps
🛑Valuesimmutable maps🛑
anyQuery(Queryable)memoized custom transforms
+ ### `Array(definition, schemaAttribute)` Creates a schema to normalize an array of schemas. If the input value is an `Object` instead of an `Array`, the normalized result will be an `Array` of the `Object`'s values. diff --git a/packages/rest/README.md b/packages/rest/README.md index db9f48050082..4e0978b6134a 100644 --- a/packages/rest/README.md +++ b/packages/rest/README.md @@ -92,6 +92,84 @@ todo5 = await TodoResource.partialUpdate({ id: 5 }, { title: 'my todo' }); await TodoResource.delete({ id: 5 }); ``` +## Schemas + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Data TypeMutableSchemaDescriptionQueryable
ObjectEntitysingle unique object
Union(Entity)polymorphic objects (A | B)
🛑Objectstatically known keys🛑
Invalidate(Entity)delete an entity🛑
ListCollection(Array)growable lists
🛑Arrayimmutable lists🛑
Alllist of all entities of a kind
MapCollection(Values)growable maps
🛑Valuesimmutable maps🛑
anyQuery(Queryable)memoized custom transforms
+ ## Free React Integration No need for any custom hooks. All endpoints are 100% compatible with [Reactive Data Client](https://dataclient.io)