tinybase 9.4.0 → 9.5.0-beta.1
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.
- package/@types/_internal/store/with-schemas/index.d.ts +43 -8
- package/@types/mergeable-store/with-schemas/index.d.ts +30 -11
- package/@types/queries/index.d.ts +11 -11
- package/@types/queries/with-schemas/index.d.ts +17 -3
- package/@types/schematizers/index.d.ts +6 -4
- package/@types/schematizers/schematizer-arktype/index.d.ts +6 -6
- package/@types/schematizers/schematizer-arktype/with-schemas/index.d.ts +112 -1
- package/@types/schematizers/schematizer-effect/index.d.ts +9 -11
- package/@types/schematizers/schematizer-effect/with-schemas/index.d.ts +114 -1
- package/@types/schematizers/schematizer-typebox/index.d.ts +7 -7
- package/@types/schematizers/schematizer-typebox/with-schemas/index.d.ts +114 -1
- package/@types/schematizers/schematizer-valibot/index.d.ts +6 -6
- package/@types/schematizers/schematizer-valibot/with-schemas/index.d.ts +112 -1
- package/@types/schematizers/schematizer-yup/index.d.ts +5 -4
- package/@types/schematizers/schematizer-yup/with-schemas/index.d.ts +112 -1
- package/@types/schematizers/schematizer-zod/index.d.ts +6 -6
- package/@types/schematizers/schematizer-zod/with-schemas/index.d.ts +112 -1
- package/@types/schematizers/with-schemas/index.d.ts +113 -4
- package/@types/store/index.d.ts +175 -16
- package/@types/store/with-schemas/index.d.ts +238 -55
- package/@types/synchronizers/with-schemas/index.d.ts +12 -2
- package/@types/ui-react/with-schemas/index.d.ts +576 -7
- package/@types/ui-react-dom/index.d.ts +10 -10
- package/@types/ui-react-dom/with-schemas/index.d.ts +94 -10
- package/@types/ui-react-dom-charts/index.d.ts +7 -7
- package/@types/ui-react-dom-charts/with-schemas/index.d.ts +7 -7
- package/@types/ui-react-inspector/index.d.ts +1 -1
- package/@types/ui-react-inspector/with-schemas/index.d.ts +1 -1
- package/@types/ui-solid/with-schemas/index.d.ts +340 -7
- package/@types/ui-solid-dom/index.d.ts +10 -10
- package/@types/ui-solid-dom/with-schemas/index.d.ts +94 -10
- package/@types/ui-solid-inspector/index.d.ts +1 -1
- package/@types/ui-solid-inspector/with-schemas/index.d.ts +1 -1
- package/@types/ui-svelte/with-schemas/index.d.ts +30 -0
- package/@types/ui-svelte-dom/index.d.ts +10 -10
- package/@types/ui-svelte-dom/with-schemas/index.d.ts +94 -10
- package/@types/ui-svelte-inspector/index.d.ts +1 -1
- package/@types/ui-svelte-inspector/with-schemas/index.d.ts +1 -1
- package/agents.md +4 -0
- package/index.js +76 -22
- package/mergeable-store/index.js +76 -22
- package/mergeable-store/with-schemas/index.js +76 -22
- package/min/index.js +1 -1
- package/min/index.js.gz +0 -0
- package/min/mergeable-store/index.js +1 -1
- package/min/mergeable-store/index.js.gz +0 -0
- package/min/mergeable-store/with-schemas/index.js +1 -1
- package/min/mergeable-store/with-schemas/index.js.gz +0 -0
- package/min/omni/index.js +1 -1
- package/min/omni/index.js.gz +0 -0
- package/min/omni/with-schemas/index.js +1 -1
- package/min/omni/with-schemas/index.js.gz +0 -0
- package/min/schematizers/index.js +1 -1
- package/min/schematizers/index.js.gz +0 -0
- package/min/schematizers/schematizer-arktype/index.js +1 -1
- package/min/schematizers/schematizer-arktype/index.js.gz +0 -0
- package/min/schematizers/schematizer-arktype/with-schemas/index.js +1 -1
- package/min/schematizers/schematizer-arktype/with-schemas/index.js.gz +0 -0
- package/min/schematizers/schematizer-effect/index.js +1 -1
- package/min/schematizers/schematizer-effect/index.js.gz +0 -0
- package/min/schematizers/schematizer-effect/with-schemas/index.js +1 -1
- package/min/schematizers/schematizer-effect/with-schemas/index.js.gz +0 -0
- package/min/schematizers/schematizer-typebox/index.js +1 -1
- package/min/schematizers/schematizer-typebox/index.js.gz +0 -0
- package/min/schematizers/schematizer-typebox/with-schemas/index.js +1 -1
- package/min/schematizers/schematizer-typebox/with-schemas/index.js.gz +0 -0
- package/min/schematizers/schematizer-valibot/index.js +1 -1
- package/min/schematizers/schematizer-valibot/index.js.gz +0 -0
- package/min/schematizers/schematizer-valibot/with-schemas/index.js +1 -1
- package/min/schematizers/schematizer-valibot/with-schemas/index.js.gz +0 -0
- package/min/schematizers/schematizer-yup/index.js +1 -1
- package/min/schematizers/schematizer-yup/index.js.gz +0 -0
- package/min/schematizers/schematizer-yup/with-schemas/index.js +1 -1
- package/min/schematizers/schematizer-yup/with-schemas/index.js.gz +0 -0
- package/min/schematizers/schematizer-zod/index.js +1 -1
- package/min/schematizers/schematizer-zod/index.js.gz +0 -0
- package/min/schematizers/schematizer-zod/with-schemas/index.js +1 -1
- package/min/schematizers/schematizer-zod/with-schemas/index.js.gz +0 -0
- package/min/schematizers/with-schemas/index.js +1 -1
- package/min/schematizers/with-schemas/index.js.gz +0 -0
- package/min/store/index.js +1 -1
- package/min/store/index.js.gz +0 -0
- package/min/store/with-schemas/index.js +1 -1
- package/min/store/with-schemas/index.js.gz +0 -0
- package/min/ui-react-inspector/index.js +1 -1
- package/min/ui-react-inspector/index.js.gz +0 -0
- package/min/ui-react-inspector/with-schemas/index.js +1 -1
- package/min/ui-react-inspector/with-schemas/index.js.gz +0 -0
- package/min/ui-solid-inspector/index.js +1 -1
- package/min/ui-solid-inspector/index.js.gz +0 -0
- package/min/ui-solid-inspector/with-schemas/index.js +1 -1
- package/min/ui-solid-inspector/with-schemas/index.js.gz +0 -0
- package/min/ui-svelte-inspector/index.js +1 -1
- package/min/ui-svelte-inspector/index.js.gz +0 -0
- package/min/ui-svelte-inspector/with-schemas/index.js +1 -1
- package/min/ui-svelte-inspector/with-schemas/index.js.gz +0 -0
- package/min/with-schemas/index.js +1 -1
- package/min/with-schemas/index.js.gz +0 -0
- package/omni/index.js +76 -22
- package/omni/with-schemas/index.js +76 -22
- package/package.json +2 -2
- package/readme.md +14 -14
- package/releases.md +95 -65
- package/schematizers/index.js +54 -6
- package/schematizers/schematizer-arktype/index.js +99 -19
- package/schematizers/schematizer-arktype/with-schemas/index.js +99 -19
- package/schematizers/schematizer-effect/index.js +101 -11
- package/schematizers/schematizer-effect/with-schemas/index.js +101 -11
- package/schematizers/schematizer-typebox/index.js +87 -11
- package/schematizers/schematizer-typebox/with-schemas/index.js +87 -11
- package/schematizers/schematizer-valibot/index.js +125 -21
- package/schematizers/schematizer-valibot/with-schemas/index.js +125 -21
- package/schematizers/schematizer-yup/index.js +58 -14
- package/schematizers/schematizer-yup/with-schemas/index.js +58 -14
- package/schematizers/schematizer-zod/index.js +131 -12
- package/schematizers/schematizer-zod/with-schemas/index.js +131 -12
- package/schematizers/with-schemas/index.js +54 -6
- package/store/index.js +76 -22
- package/store/with-schemas/index.js +76 -22
- package/ui-react-inspector/index.js +76 -22
- package/ui-react-inspector/with-schemas/index.js +76 -22
- package/ui-solid-inspector/index.js +76 -22
- package/ui-solid-inspector/with-schemas/index.js +76 -22
- package/ui-svelte-inspector/index.js +76 -22
- package/ui-svelte-inspector/with-schemas/index.js +76 -22
- package/with-schemas/index.js +76 -22
|
@@ -7520,7 +7520,80 @@ export type WithSchemas<Schemas extends OptionalSchemas> = {
|
|
|
7520
7520
|
metricsOrMetricsId?: MetricsOrMetricsId<Schemas>,
|
|
7521
7521
|
) => Metrics<Schemas> | undefined;
|
|
7522
7522
|
|
|
7523
|
-
|
|
7523
|
+
/**
|
|
7524
|
+
* The useProvideMetrics hook is used to add a Metrics object by Id to a
|
|
7525
|
+
* Provider component, but imperatively from a component within it.
|
|
7526
|
+
*
|
|
7527
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
7528
|
+
*
|
|
7529
|
+
* ```ts override
|
|
7530
|
+
* useProvideMetrics(metricsId: Id, metrics: Metrics): void;
|
|
7531
|
+
* ```
|
|
7532
|
+
*
|
|
7533
|
+
* Normally you will register a Metrics object by Id in a context by using the
|
|
7534
|
+
* `metricsById` prop of the top-level Provider component. This hook, however,
|
|
7535
|
+
* lets you dynamically add a new Metrics object to the context, from within a
|
|
7536
|
+
* descendent component. This is useful for applications where the set of
|
|
7537
|
+
* Metrics objects is not known at the time of the first render of the root
|
|
7538
|
+
* Provider.
|
|
7539
|
+
*
|
|
7540
|
+
* A Metrics object added to the Provider context in this way will be available
|
|
7541
|
+
* to other components within the context (using the useMetrics hook and so on).
|
|
7542
|
+
* If you use the same Id as an existing Metrics object registration, the new
|
|
7543
|
+
* one will take priority over one provided by the `metricsById` prop.
|
|
7544
|
+
*
|
|
7545
|
+
* Note that other components that consume a Metrics object registered like this
|
|
7546
|
+
* should defend against it being undefined at first. On the first render, the
|
|
7547
|
+
* other component will likely not yet have completed the registration. In the
|
|
7548
|
+
* example below, we use the null-safe `useMetrics('petMetrics')?` to do this.
|
|
7549
|
+
* @param metricsId The Id of the Metrics object to be registered with the
|
|
7550
|
+
* Provider.
|
|
7551
|
+
* @param metrics The Metrics object to be registered.
|
|
7552
|
+
* @example
|
|
7553
|
+
* This example creates a Provider context. A child component registers a
|
|
7554
|
+
* Metrics object into it which is then consumable by a peer child component.
|
|
7555
|
+
*
|
|
7556
|
+
* ```jsx
|
|
7557
|
+
* import React from 'react';
|
|
7558
|
+
* import {createRoot} from 'react-dom/client';
|
|
7559
|
+
* import {createMetrics, createStore} from 'tinybase';
|
|
7560
|
+
* import {
|
|
7561
|
+
* Provider,
|
|
7562
|
+
* useCreateMetrics,
|
|
7563
|
+
* useCreateStore,
|
|
7564
|
+
* useMetrics,
|
|
7565
|
+
* useProvideMetrics,
|
|
7566
|
+
* } from 'tinybase/ui-react';
|
|
7567
|
+
*
|
|
7568
|
+
* const App = () => (
|
|
7569
|
+
* <Provider>
|
|
7570
|
+
* <RegisterMetrics />
|
|
7571
|
+
* <ConsumeMetrics />
|
|
7572
|
+
* </Provider>
|
|
7573
|
+
* );
|
|
7574
|
+
* const RegisterMetrics = () => {
|
|
7575
|
+
* const store = useCreateStore(() =>
|
|
7576
|
+
* createStore().setCell('pets', 'fido', 'color', 'brown'),
|
|
7577
|
+
* );
|
|
7578
|
+
* const metrics = useCreateMetrics(store, (store) =>
|
|
7579
|
+
* createMetrics(store).setMetricDefinition('petCount', 'pets', 'count'),
|
|
7580
|
+
* );
|
|
7581
|
+
* useProvideMetrics('petMetrics', metrics);
|
|
7582
|
+
* return null;
|
|
7583
|
+
* };
|
|
7584
|
+
* const ConsumeMetrics = () => (
|
|
7585
|
+
* <span>{useMetrics('petMetrics')?.getMetric('petCount')}</span>
|
|
7586
|
+
* );
|
|
7587
|
+
*
|
|
7588
|
+
* const app = document.createElement('div');
|
|
7589
|
+
* const root = createRoot(app);
|
|
7590
|
+
* root.render(<App />); // !act
|
|
7591
|
+
* console.log(app.innerHTML);
|
|
7592
|
+
* // -> '<span>1</span>'
|
|
7593
|
+
* ```
|
|
7594
|
+
* @category Metrics hooks
|
|
7595
|
+
* @since v5.3.0
|
|
7596
|
+
*/
|
|
7524
7597
|
useProvideMetrics: (metricsId: Id, metrics: Metrics<Schemas>) => void;
|
|
7525
7598
|
|
|
7526
7599
|
/**
|
|
@@ -8125,7 +8198,87 @@ export type WithSchemas<Schemas extends OptionalSchemas> = {
|
|
|
8125
8198
|
indexesOrIndexesId?: IndexesOrIndexesId<Schemas>,
|
|
8126
8199
|
) => Indexes<Schemas> | undefined;
|
|
8127
8200
|
|
|
8128
|
-
|
|
8201
|
+
/**
|
|
8202
|
+
* The useProvideIndexes hook is used to add an Indexes object by Id to a
|
|
8203
|
+
* Provider component, but imperatively from a component within it.
|
|
8204
|
+
*
|
|
8205
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
8206
|
+
*
|
|
8207
|
+
* ```ts override
|
|
8208
|
+
* useProvideIndexes(indexesId: Id, indexes: Indexes): void;
|
|
8209
|
+
* ```
|
|
8210
|
+
*
|
|
8211
|
+
* Normally you will register an Indexes object by Id in a context by using the
|
|
8212
|
+
* `indexesById` prop of the top-level Provider component. This hook, however,
|
|
8213
|
+
* lets you dynamically add a new Indexes object to the context, from within a
|
|
8214
|
+
* descendent component. This is useful for applications where the set of
|
|
8215
|
+
* Indexes objects is not known at the time of the first render of the root
|
|
8216
|
+
* Provider.
|
|
8217
|
+
*
|
|
8218
|
+
* A Indexes object added to the Provider context in this way will be available
|
|
8219
|
+
* to other components within the context (using the useIndexes hook and so on).
|
|
8220
|
+
* If you use the same Id as an existing Indexes object registration, the new
|
|
8221
|
+
* one will take priority over one provided by the `indexesById` prop.
|
|
8222
|
+
*
|
|
8223
|
+
* Note that other components that consume an Indexes object registered like
|
|
8224
|
+
* this should defend against it being undefined at first. On the first render,
|
|
8225
|
+
* the other component will likely not yet have completed the registration. In
|
|
8226
|
+
* the example below, we use the null-safe `useIndexes('petIndexes')?` to do
|
|
8227
|
+
* this.
|
|
8228
|
+
* @param indexesId The Id of the Indexes object to be registered with the
|
|
8229
|
+
* Provider.
|
|
8230
|
+
* @param indexes The Indexes object to be registered.
|
|
8231
|
+
* @example
|
|
8232
|
+
* This example creates a Provider context. A child component registers an
|
|
8233
|
+
* Indexes object into it which is then consumable by a peer child component.
|
|
8234
|
+
*
|
|
8235
|
+
* ```jsx
|
|
8236
|
+
* import React from 'react';
|
|
8237
|
+
* import {createRoot} from 'react-dom/client';
|
|
8238
|
+
* import {createIndexes, createStore} from 'tinybase';
|
|
8239
|
+
* import {
|
|
8240
|
+
* Provider,
|
|
8241
|
+
* useCreateIndexes,
|
|
8242
|
+
* useCreateStore,
|
|
8243
|
+
* useIndexes,
|
|
8244
|
+
* useProvideIndexes,
|
|
8245
|
+
* } from 'tinybase/ui-react';
|
|
8246
|
+
*
|
|
8247
|
+
* const App = () => (
|
|
8248
|
+
* <Provider>
|
|
8249
|
+
* <RegisterIndexes />
|
|
8250
|
+
* <ConsumeIndexes />
|
|
8251
|
+
* </Provider>
|
|
8252
|
+
* );
|
|
8253
|
+
* const RegisterIndexes = () => {
|
|
8254
|
+
* const store = useCreateStore(() =>
|
|
8255
|
+
* createStore().setCell('pets', 'fido', 'color', 'brown'),
|
|
8256
|
+
* );
|
|
8257
|
+
* const indexes = useCreateIndexes(store, (store) =>
|
|
8258
|
+
* createIndexes(store).setIndexDefinition(
|
|
8259
|
+
* 'petsByColor',
|
|
8260
|
+
* 'pets',
|
|
8261
|
+
* 'color',
|
|
8262
|
+
* ),
|
|
8263
|
+
* );
|
|
8264
|
+
* useProvideIndexes('petIndexes', indexes);
|
|
8265
|
+
* return null;
|
|
8266
|
+
* };
|
|
8267
|
+
* const ConsumeIndexes = () => (
|
|
8268
|
+
* <span>
|
|
8269
|
+
* {JSON.stringify(useIndexes('petIndexes')?.getSliceIds('petsByColor'))}
|
|
8270
|
+
* </span>
|
|
8271
|
+
* );
|
|
8272
|
+
*
|
|
8273
|
+
* const app = document.createElement('div');
|
|
8274
|
+
* const root = createRoot(app);
|
|
8275
|
+
* root.render(<App />); // !act
|
|
8276
|
+
* console.log(app.innerHTML);
|
|
8277
|
+
* // -> '<span>["brown"]</span>'
|
|
8278
|
+
* ```
|
|
8279
|
+
* @category Indexes hooks
|
|
8280
|
+
* @since v5.3.0
|
|
8281
|
+
*/
|
|
8129
8282
|
useProvideIndexes: (indexesId: Id, indexes: Indexes<Schemas>) => void;
|
|
8130
8283
|
|
|
8131
8284
|
/**
|
|
@@ -9065,7 +9218,98 @@ export type WithSchemas<Schemas extends OptionalSchemas> = {
|
|
|
9065
9218
|
relationshipsOrRelationshipsId?: RelationshipsOrRelationshipsId<Schemas>,
|
|
9066
9219
|
) => Relationships<Schemas> | undefined;
|
|
9067
9220
|
|
|
9068
|
-
|
|
9221
|
+
/**
|
|
9222
|
+
* The useProvideRelationships hook is used to add a Relationships object by Id
|
|
9223
|
+
* to a Provider component, but imperatively from a component within it.
|
|
9224
|
+
*
|
|
9225
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
9226
|
+
*
|
|
9227
|
+
* ```ts override
|
|
9228
|
+
* useProvideRelationships(
|
|
9229
|
+
* relationshipsId: Id,
|
|
9230
|
+
* relationships: Relationships,
|
|
9231
|
+
* ): void;
|
|
9232
|
+
* ```
|
|
9233
|
+
*
|
|
9234
|
+
* Normally you will register a Relationships object by Id in a context by using
|
|
9235
|
+
* the `relationshipsById` prop of the top-level Provider component. This hook,
|
|
9236
|
+
* however, lets you dynamically add a new Relationships object to the context,
|
|
9237
|
+
* from within a component. This is useful for applications where the set of
|
|
9238
|
+
* Relationships objects is not known at the time of the first render of the
|
|
9239
|
+
* root Provider.
|
|
9240
|
+
*
|
|
9241
|
+
* A Relationships object added to the Provider context in this way will be
|
|
9242
|
+
* available to other components within the context (using the useRelationships
|
|
9243
|
+
* hook and so on). If you use the same Id as an existing Relationships object
|
|
9244
|
+
* registration, the new one will take priority over one provided by the
|
|
9245
|
+
* `relationshipsById` prop.
|
|
9246
|
+
*
|
|
9247
|
+
* Note that other components that consume a Relationships object registered
|
|
9248
|
+
* like this should defend against it being undefined at first. On the first
|
|
9249
|
+
* render, the other component will likely not yet have completed the
|
|
9250
|
+
* registration. In the example below, we use the null-safe
|
|
9251
|
+
* `useRelationships('petRelationships')?` to do this.
|
|
9252
|
+
* @param relationshipsId The Id of the Relationships object to be registered
|
|
9253
|
+
* with the Provider.
|
|
9254
|
+
* @param relationships The Relationships object to be registered.
|
|
9255
|
+
* @example
|
|
9256
|
+
* This example creates a Provider context. A child component registers a
|
|
9257
|
+
* Relationships object into it which is then consumable by a peer child
|
|
9258
|
+
* component.
|
|
9259
|
+
*
|
|
9260
|
+
* ```jsx
|
|
9261
|
+
* import React from 'react';
|
|
9262
|
+
* import {createRoot} from 'react-dom/client';
|
|
9263
|
+
* import {createRelationships, createStore} from 'tinybase';
|
|
9264
|
+
* import {
|
|
9265
|
+
* Provider,
|
|
9266
|
+
* useCreateRelationships,
|
|
9267
|
+
* useCreateStore,
|
|
9268
|
+
* useProvideRelationships,
|
|
9269
|
+
* useRelationships,
|
|
9270
|
+
* } from 'tinybase/ui-react';
|
|
9271
|
+
*
|
|
9272
|
+
* const App = () => (
|
|
9273
|
+
* <Provider>
|
|
9274
|
+
* <RegisterRelationships />
|
|
9275
|
+
* <ConsumeRelationships />
|
|
9276
|
+
* </Provider>
|
|
9277
|
+
* );
|
|
9278
|
+
* const RegisterRelationships = () => {
|
|
9279
|
+
* const store = useCreateStore(() =>
|
|
9280
|
+
* createStore()
|
|
9281
|
+
* .setTable('pets', {fido: {species: 'dog'}})
|
|
9282
|
+
* .setTable('species', {dog: {price: 5}}),
|
|
9283
|
+
* );
|
|
9284
|
+
* const relationships = useCreateRelationships(store, (store) =>
|
|
9285
|
+
* createRelationships(store).setRelationshipDefinition(
|
|
9286
|
+
* 'petSpecies',
|
|
9287
|
+
* 'pets',
|
|
9288
|
+
* 'species',
|
|
9289
|
+
* 'species',
|
|
9290
|
+
* ),
|
|
9291
|
+
* );
|
|
9292
|
+
* useProvideRelationships('petRelationships', relationships);
|
|
9293
|
+
* return null;
|
|
9294
|
+
* };
|
|
9295
|
+
* const ConsumeRelationships = () => (
|
|
9296
|
+
* <span>
|
|
9297
|
+
* {useRelationships('petRelationships')?.getRemoteRowId(
|
|
9298
|
+
* 'petSpecies',
|
|
9299
|
+
* 'fido',
|
|
9300
|
+
* )}
|
|
9301
|
+
* </span>
|
|
9302
|
+
* );
|
|
9303
|
+
*
|
|
9304
|
+
* const app = document.createElement('div');
|
|
9305
|
+
* const root = createRoot(app);
|
|
9306
|
+
* root.render(<App />); // !act
|
|
9307
|
+
* console.log(app.innerHTML);
|
|
9308
|
+
* // -> '<span>dog</span>'
|
|
9309
|
+
* ```
|
|
9310
|
+
* @category Relationships hooks
|
|
9311
|
+
* @since v5.3.0
|
|
9312
|
+
*/
|
|
9069
9313
|
useProvideRelationships: (
|
|
9070
9314
|
relationshipsId: Id,
|
|
9071
9315
|
relationships: Relationships<Schemas>,
|
|
@@ -10217,7 +10461,88 @@ export type WithSchemas<Schemas extends OptionalSchemas> = {
|
|
|
10217
10461
|
queriesOrQueriesId?: QueriesOrQueriesId<Schemas>,
|
|
10218
10462
|
) => Queries<Schemas> | undefined;
|
|
10219
10463
|
|
|
10220
|
-
|
|
10464
|
+
/**
|
|
10465
|
+
* The useProvideQueries hook is used to add a Queries object by Id to a
|
|
10466
|
+
* Provider component, but imperatively from a component within it.
|
|
10467
|
+
*
|
|
10468
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
10469
|
+
*
|
|
10470
|
+
* ```ts override
|
|
10471
|
+
* useProvideQueries(queriesId: Id, queries: Queries): void;
|
|
10472
|
+
* ```
|
|
10473
|
+
*
|
|
10474
|
+
* Normally you will register a Queries object by Id in a context by using the
|
|
10475
|
+
* `queriesById` prop of the top-level Provider component. This hook, however,
|
|
10476
|
+
* lets you dynamically add a new Queries object to the context, from within a
|
|
10477
|
+
* component. This is useful for applications where the set of Queries objects
|
|
10478
|
+
* is not known at the time of the first render of the root Provider.
|
|
10479
|
+
*
|
|
10480
|
+
* A Queries object added to the Provider context in this way will be available
|
|
10481
|
+
* to other components within the context (using the useQueries hook and so on).
|
|
10482
|
+
* If you use the same Id as an existing Queries object registration, the new
|
|
10483
|
+
* one will take priority over one provided by the `queriesById` prop.
|
|
10484
|
+
*
|
|
10485
|
+
* Note that other components that consume a Queries object registered like this
|
|
10486
|
+
* should defend against it being undefined at first. On the first render, the
|
|
10487
|
+
* other component will likely not yet have completed the registration. In the
|
|
10488
|
+
* example below, we use the null-safe `useQueries('petQueries')?` to do this.
|
|
10489
|
+
* @param queriesId The Id of the Queries object to be registered with the
|
|
10490
|
+
* Provider.
|
|
10491
|
+
* @param queries The Queries object to be registered.
|
|
10492
|
+
* @example
|
|
10493
|
+
* This example creates a Provider context. A child component registers a
|
|
10494
|
+
* Queries object into it which is then consumable by a peer child component.
|
|
10495
|
+
*
|
|
10496
|
+
* ```jsx
|
|
10497
|
+
* import React from 'react';
|
|
10498
|
+
* import {createRoot} from 'react-dom/client';
|
|
10499
|
+
* import {createQueries, createStore} from 'tinybase';
|
|
10500
|
+
* import {
|
|
10501
|
+
* Provider,
|
|
10502
|
+
* useCreateQueries,
|
|
10503
|
+
* useCreateStore,
|
|
10504
|
+
* useProvideQueries,
|
|
10505
|
+
* useQueries,
|
|
10506
|
+
* } from 'tinybase/ui-react';
|
|
10507
|
+
*
|
|
10508
|
+
* const App = () => (
|
|
10509
|
+
* <Provider>
|
|
10510
|
+
* <RegisterQueries />
|
|
10511
|
+
* <ConsumeQueries />
|
|
10512
|
+
* </Provider>
|
|
10513
|
+
* );
|
|
10514
|
+
* const RegisterQueries = () => {
|
|
10515
|
+
* const store = useCreateStore(() =>
|
|
10516
|
+
* createStore().setRow('pets', 'fido', {color: 'brown', legs: 4}),
|
|
10517
|
+
* );
|
|
10518
|
+
* const queries = useCreateQueries(store, (store) =>
|
|
10519
|
+
* createQueries(store).setQueryDefinition(
|
|
10520
|
+
* 'brownLegs',
|
|
10521
|
+
* 'pets',
|
|
10522
|
+
* ({select, where}) => {
|
|
10523
|
+
* select('legs');
|
|
10524
|
+
* where('color', 'brown');
|
|
10525
|
+
* },
|
|
10526
|
+
* ),
|
|
10527
|
+
* );
|
|
10528
|
+
* useProvideQueries('petQueries', queries);
|
|
10529
|
+
* return null;
|
|
10530
|
+
* };
|
|
10531
|
+
* const ConsumeQueries = () => (
|
|
10532
|
+
* <span>
|
|
10533
|
+
* {JSON.stringify(useQueries('petQueries')?.getResultTable('brownLegs'))}
|
|
10534
|
+
* </span>
|
|
10535
|
+
* );
|
|
10536
|
+
*
|
|
10537
|
+
* const app = document.createElement('div');
|
|
10538
|
+
* const root = createRoot(app);
|
|
10539
|
+
* root.render(<App />); // !act
|
|
10540
|
+
* console.log(app.innerHTML);
|
|
10541
|
+
* // -> '<span>{\"fido\":{\"legs\":4}}</span>'
|
|
10542
|
+
* ```
|
|
10543
|
+
* @category Queries hooks
|
|
10544
|
+
* @since v5.3.0
|
|
10545
|
+
*/
|
|
10221
10546
|
useProvideQueries: (queriesId: Id, queries: Queries<Schemas>) => void;
|
|
10222
10547
|
|
|
10223
10548
|
/**
|
|
@@ -13610,7 +13935,86 @@ export type WithSchemas<Schemas extends OptionalSchemas> = {
|
|
|
13610
13935
|
checkpointsOrCheckpointsId?: CheckpointsOrCheckpointsId<Schemas>,
|
|
13611
13936
|
) => Checkpoints<Schemas> | undefined;
|
|
13612
13937
|
|
|
13613
|
-
|
|
13938
|
+
/**
|
|
13939
|
+
* The useProvideCheckpoints hook is used to add a Checkpoints object by Id to a
|
|
13940
|
+
* Provider component, but imperatively from a component within it.
|
|
13941
|
+
*
|
|
13942
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
13943
|
+
*
|
|
13944
|
+
* ```ts override
|
|
13945
|
+
* useProvideCheckpoints(
|
|
13946
|
+
* checkpointsId: Id,
|
|
13947
|
+
* checkpoints: Checkpoints,
|
|
13948
|
+
* ): void;
|
|
13949
|
+
* ```
|
|
13950
|
+
*
|
|
13951
|
+
* Normally you will register a Checkpoints object by Id in a context by using
|
|
13952
|
+
* the `checkpointsById` prop of the top-level Provider component. This hook,
|
|
13953
|
+
* however, lets you dynamically add a new Checkpoints object to the context,
|
|
13954
|
+
* from within a component. This is useful for applications where the set of
|
|
13955
|
+
* Checkpoints objects is not known at the time of the first render of the root
|
|
13956
|
+
* Provider.
|
|
13957
|
+
*
|
|
13958
|
+
* A Checkpoints object added to the Provider context in this way will be
|
|
13959
|
+
* available to other components within the context (using the useCheckpoints
|
|
13960
|
+
* hook and so on). If you use the same Id as an existing Checkpoints object
|
|
13961
|
+
* registration, the new one will take priority over one provided by the
|
|
13962
|
+
* `checkpointsById` prop.
|
|
13963
|
+
*
|
|
13964
|
+
* Note that other components that consume a Checkpoints object registered like
|
|
13965
|
+
* this should defend against it being undefined at first. On the first render,
|
|
13966
|
+
* the other component will likely not yet have completed the registration. In
|
|
13967
|
+
* the example below, we use the null-safe `useCheckpoints('petCheckpoints')?`
|
|
13968
|
+
* to do this.
|
|
13969
|
+
* @param checkpointsId The Id of the Checkpoints object to be registered with
|
|
13970
|
+
* the Provider.
|
|
13971
|
+
* @param checkpoints The Checkpoints object to be registered.
|
|
13972
|
+
* @example
|
|
13973
|
+
* This example creates a Provider context. A child component registers a
|
|
13974
|
+
* Checkpoints object into it which is then consumable by a peer child
|
|
13975
|
+
* component.
|
|
13976
|
+
*
|
|
13977
|
+
* ```jsx
|
|
13978
|
+
* import React from 'react';
|
|
13979
|
+
* import {createRoot} from 'react-dom/client';
|
|
13980
|
+
* import {createCheckpoints, createStore} from 'tinybase';
|
|
13981
|
+
* import {
|
|
13982
|
+
* Provider,
|
|
13983
|
+
* useCheckpoints,
|
|
13984
|
+
* useCreateCheckpoints,
|
|
13985
|
+
* useCreateStore,
|
|
13986
|
+
* useProvideCheckpoints,
|
|
13987
|
+
* } from 'tinybase/ui-react';
|
|
13988
|
+
*
|
|
13989
|
+
* const App = () => (
|
|
13990
|
+
* <Provider>
|
|
13991
|
+
* <RegisterCheckpoints />
|
|
13992
|
+
* <ConsumeCheckpoints />
|
|
13993
|
+
* </Provider>
|
|
13994
|
+
* );
|
|
13995
|
+
* const RegisterCheckpoints = () => {
|
|
13996
|
+
* const store = useCreateStore(() =>
|
|
13997
|
+
* createStore().setCell('pets', 'fido', 'color', 'brown'),
|
|
13998
|
+
* );
|
|
13999
|
+
* const checkpoints = useCreateCheckpoints(store, createCheckpoints);
|
|
14000
|
+
* useProvideCheckpoints('petCheckpoints', checkpoints);
|
|
14001
|
+
* return null;
|
|
14002
|
+
* };
|
|
14003
|
+
* const ConsumeCheckpoints = () => (
|
|
14004
|
+
* <span>
|
|
14005
|
+
* {JSON.stringify(useCheckpoints('petCheckpoints')?.getCheckpointIds())}
|
|
14006
|
+
* </span>
|
|
14007
|
+
* );
|
|
14008
|
+
*
|
|
14009
|
+
* const app = document.createElement('div');
|
|
14010
|
+
* const root = createRoot(app);
|
|
14011
|
+
* root.render(<App />); // !act
|
|
14012
|
+
* console.log(app.innerHTML);
|
|
14013
|
+
* // -> '<span>[[],"0",[]]</span>'
|
|
14014
|
+
* ```
|
|
14015
|
+
* @category Checkpoints hooks
|
|
14016
|
+
* @since v5.3.0
|
|
14017
|
+
*/
|
|
13614
14018
|
useProvideCheckpoints: (
|
|
13615
14019
|
checkpointsId: Id,
|
|
13616
14020
|
checkpoints: Checkpoints<Schemas>,
|
|
@@ -14894,7 +15298,89 @@ export type WithSchemas<Schemas extends OptionalSchemas> = {
|
|
|
14894
15298
|
persisterOrPersisterId?: PersisterOrPersisterId<Schemas>,
|
|
14895
15299
|
) => Persister<Schemas, Persists.StoreOrMergeableStore> | undefined;
|
|
14896
15300
|
|
|
14897
|
-
|
|
15301
|
+
/**
|
|
15302
|
+
* The useProvidePersister hook is used to add a Persister object by Id to a
|
|
15303
|
+
* Provider component, but imperatively from a component within it.
|
|
15304
|
+
*
|
|
15305
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
15306
|
+
*
|
|
15307
|
+
* ```ts override
|
|
15308
|
+
* useProvidePersister(
|
|
15309
|
+
* persisterId: Id,
|
|
15310
|
+
* persister: AnyPersister,
|
|
15311
|
+
* ): void;
|
|
15312
|
+
* ```
|
|
15313
|
+
*
|
|
15314
|
+
* Normally you will register a Persister object by Id in a context by using the
|
|
15315
|
+
* `persistersById` prop of the top-level Provider component. This hook,
|
|
15316
|
+
* however, lets you dynamically add a new Persister object to the context, from
|
|
15317
|
+
* within a component. This is useful for applications where the set of
|
|
15318
|
+
* Persister objects is not known at the time of the first render of the root
|
|
15319
|
+
* Provider.
|
|
15320
|
+
*
|
|
15321
|
+
* A Persister object added to the Provider context in this way will be
|
|
15322
|
+
* available to other components within the context (using the usePersister hook
|
|
15323
|
+
* and so on). If you use the same Id as an existing Persister object
|
|
15324
|
+
* registration, the new one will take priority over one provided by the
|
|
15325
|
+
* `persistersById` prop.
|
|
15326
|
+
*
|
|
15327
|
+
* Note that other components that consume a Persister object registered like
|
|
15328
|
+
* this should defend against it being undefined at first. On the first render,
|
|
15329
|
+
* the other component will likely not yet have completed the registration. In
|
|
15330
|
+
* the example below, we use the null-safe `usePersister('petPersister')?` to do
|
|
15331
|
+
* this.
|
|
15332
|
+
* @param persisterId The Id of the Persister object to be registered with the
|
|
15333
|
+
* Provider.
|
|
15334
|
+
* @param persister The Persister object to be registered.
|
|
15335
|
+
* @example
|
|
15336
|
+
* This example creates a Provider context. A child component registers a
|
|
15337
|
+
* Persister object into it which is then consumable by a peer child
|
|
15338
|
+
* component.
|
|
15339
|
+
*
|
|
15340
|
+
* ```jsx
|
|
15341
|
+
* import React from 'react';
|
|
15342
|
+
* import {createRoot} from 'react-dom/client';
|
|
15343
|
+
* import {createStore} from 'tinybase';
|
|
15344
|
+
* import {createSessionPersister} from 'tinybase/persisters/persister-browser';
|
|
15345
|
+
* import {
|
|
15346
|
+
* Provider,
|
|
15347
|
+
* useCreatePersister,
|
|
15348
|
+
* useCreateStore,
|
|
15349
|
+
* usePersister,
|
|
15350
|
+
* useProvidePersister,
|
|
15351
|
+
* } from 'tinybase/ui-react';
|
|
15352
|
+
*
|
|
15353
|
+
* const App = () => (
|
|
15354
|
+
* <Provider>
|
|
15355
|
+
* <RegisterPersister />
|
|
15356
|
+
* <ConsumePersister />
|
|
15357
|
+
* </Provider>
|
|
15358
|
+
* );
|
|
15359
|
+
* const RegisterPersister = () => {
|
|
15360
|
+
* const store = useCreateStore(() =>
|
|
15361
|
+
* createStore().setCell('pets', 'fido', 'color', 'brown'),
|
|
15362
|
+
* );
|
|
15363
|
+
* const persister = useCreatePersister(store, (store) =>
|
|
15364
|
+
* createSessionPersister(store, 'pets'),
|
|
15365
|
+
* );
|
|
15366
|
+
* useProvidePersister('petPersister', persister);
|
|
15367
|
+
* return null;
|
|
15368
|
+
* };
|
|
15369
|
+
* const ConsumePersister = () => (
|
|
15370
|
+
* <span>{usePersister('petPersister')?.getStatus()}</span>
|
|
15371
|
+
* );
|
|
15372
|
+
*
|
|
15373
|
+
* const app = document.createElement('div');
|
|
15374
|
+
* const root = createRoot(app);
|
|
15375
|
+
* root.render(<App />); // !act
|
|
15376
|
+
*
|
|
15377
|
+
* // ... // !act
|
|
15378
|
+
* console.log(app.innerHTML);
|
|
15379
|
+
* // -> '<span>0</span>'
|
|
15380
|
+
* ```
|
|
15381
|
+
* @category Persister hooks
|
|
15382
|
+
* @since v5.3.0
|
|
15383
|
+
*/
|
|
14898
15384
|
useProvidePersister: (
|
|
14899
15385
|
persisterId: Id,
|
|
14900
15386
|
persister: AnyPersister<Schemas> | undefined,
|
|
@@ -15450,7 +15936,90 @@ export type WithSchemas<Schemas extends OptionalSchemas> = {
|
|
|
15450
15936
|
synchronizerOrSynchronizerId?: SynchronizerOrSynchronizerId<Schemas>,
|
|
15451
15937
|
) => Synchronizer<Schemas> | undefined;
|
|
15452
15938
|
|
|
15453
|
-
|
|
15939
|
+
/**
|
|
15940
|
+
* The useProvideSynchronizer hook is used to add a Synchronizer object by Id to
|
|
15941
|
+
* a Provider component, but imperatively from a component within it.
|
|
15942
|
+
*
|
|
15943
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
15944
|
+
*
|
|
15945
|
+
* ```ts override
|
|
15946
|
+
* useProvideSynchronizer(
|
|
15947
|
+
* synchronizerId: Id,
|
|
15948
|
+
* synchronizer: Synchronizer,
|
|
15949
|
+
* ): void;
|
|
15950
|
+
* ```
|
|
15951
|
+
*
|
|
15952
|
+
* Normally you will register a Synchronizer object by Id in a context by using
|
|
15953
|
+
* the `synchronizersById` prop of the top-level Provider component. This hook,
|
|
15954
|
+
* however, lets you dynamically add a new Synchronizer object to the context,
|
|
15955
|
+
* from within a component. This is useful for applications where the set of
|
|
15956
|
+
* Synchronizer objects is not known at the time of the first render of the root
|
|
15957
|
+
* Provider.
|
|
15958
|
+
*
|
|
15959
|
+
* A Synchronizer object added to the Provider context in this way will be
|
|
15960
|
+
* available to other components within the context (using the useSynchronizer
|
|
15961
|
+
* hook and so on). If you use the same Id as an existing Synchronizer object
|
|
15962
|
+
* registration, the new one will take priority over one provided by the
|
|
15963
|
+
* `synchronizersById` prop.
|
|
15964
|
+
*
|
|
15965
|
+
* Note that other components that consume a Synchronizer object registered like
|
|
15966
|
+
* this should defend against it being undefined at first. On the first render,
|
|
15967
|
+
* the other component will likely not yet have completed the registration. In
|
|
15968
|
+
* the example below, we use the null-safe `useSynchronizer('petSynchronizer')?`
|
|
15969
|
+
* to do this.
|
|
15970
|
+
* @param synchronizerId The Id of the Synchronizer object to be registered with
|
|
15971
|
+
* the Provider.
|
|
15972
|
+
* @param synchronizer The Synchronizer object to be registered.
|
|
15973
|
+
* @example
|
|
15974
|
+
* This example creates a Provider context. A child component registers a
|
|
15975
|
+
* Synchronizer object into it which is then consumable by a peer child
|
|
15976
|
+
* component.
|
|
15977
|
+
*
|
|
15978
|
+
* ```jsx
|
|
15979
|
+
* import React from 'react';
|
|
15980
|
+
* import {createRoot} from 'react-dom/client';
|
|
15981
|
+
* import {createMergeableStore} from 'tinybase';
|
|
15982
|
+
* import {createLocalSynchronizer} from 'tinybase/synchronizers/synchronizer-local';
|
|
15983
|
+
* import {
|
|
15984
|
+
* Provider,
|
|
15985
|
+
* useCreateStore,
|
|
15986
|
+
* useCreateSynchronizer,
|
|
15987
|
+
* useProvideSynchronizer,
|
|
15988
|
+
* useSynchronizer,
|
|
15989
|
+
* } from 'tinybase/ui-react';
|
|
15990
|
+
*
|
|
15991
|
+
* const App = () => (
|
|
15992
|
+
* <Provider>
|
|
15993
|
+
* <RegisterSynchronizer />
|
|
15994
|
+
* <ConsumeSynchronizer />
|
|
15995
|
+
* </Provider>
|
|
15996
|
+
* );
|
|
15997
|
+
* const RegisterSynchronizer = () => {
|
|
15998
|
+
* const store = useCreateStore(() =>
|
|
15999
|
+
* createMergeableStore().setCell('pets', 'fido', 'color', 'brown'),
|
|
16000
|
+
* );
|
|
16001
|
+
* const synchronizer = useCreateSynchronizer(
|
|
16002
|
+
* store,
|
|
16003
|
+
* createLocalSynchronizer,
|
|
16004
|
+
* );
|
|
16005
|
+
* useProvideSynchronizer('petSynchronizer', synchronizer);
|
|
16006
|
+
* return null;
|
|
16007
|
+
* };
|
|
16008
|
+
* const ConsumeSynchronizer = () => (
|
|
16009
|
+
* <span>{useSynchronizer('petSynchronizer')?.getStatus()}</span>
|
|
16010
|
+
* );
|
|
16011
|
+
*
|
|
16012
|
+
* const app = document.createElement('div');
|
|
16013
|
+
* const root = createRoot(app);
|
|
16014
|
+
* root.render(<App />); // !act
|
|
16015
|
+
*
|
|
16016
|
+
* // ... // !act
|
|
16017
|
+
* console.log(app.innerHTML);
|
|
16018
|
+
* // -> '<span>0</span>'
|
|
16019
|
+
* ```
|
|
16020
|
+
* @category Synchronizer hooks
|
|
16021
|
+
* @since v5.3.0
|
|
16022
|
+
*/
|
|
15454
16023
|
useProvideSynchronizer: (
|
|
15455
16024
|
synchronizerId: Id,
|
|
15456
16025
|
synchronizer: Synchronizer<Schemas> | undefined,
|