diff --git a/gulpfile.mjs b/gulpfile.mjs index 0c0d90c784d..13415d752ae 100644 --- a/gulpfile.mjs +++ b/gulpfile.mjs @@ -64,12 +64,14 @@ const ALL_MODULES = [ 'ui-react-dom', 'ui-react-inspector', 'ui-react', + 'ui-solid', ]; const ALL_DEFINITIONS = [ ...ALL_MODULES, '_internal/store', '_internal/queries', '_internal/ui-react', + '_internal/ui-solid', ]; const DIST_DIR = 'dist'; @@ -518,9 +520,13 @@ const compileModule = async (module, dir = DIST_DIR, min = false) => { 'react', 'react-dom', 'react/jsx-runtime', + 'solid-js', + 'solid-js/jsx-runtime', 'url', 'yjs', - ...(module == 'omni' ? [] : ['tinybase/store', '../ui-react']), + ...(module == 'omni' + ? [] + : ['tinybase/store', '../ui-react', '../ui-solid']), ], input: inputFile, plugins: [ @@ -533,7 +539,12 @@ const compileModule = async (module, dir = DIST_DIR, min = false) => { '/*!': '\n/*', delimiters: ['', ''], preventAssignment: true, - ...(module == 'omni' ? {} : {'../ui-react/index.ts': '../ui-react'}), + ...(module == 'omni' + ? {} + : { + '../ui-react/index.ts': '../ui-react', + '../ui-solid/index.ts': '../ui-solid', + }), }), shebang(), image(), @@ -574,12 +585,22 @@ const compileModule = async (module, dir = DIST_DIR, min = false) => { ['../ui-react', '../../ui-react/with-schemas/' + index], outputFileWithSchemas, ); + await copyWithReplace( + outputFileWithSchemas, + ['../ui-solid', '../../ui-solid/with-schemas/' + index], + outputFileWithSchemas, + ); await copyWithReplace( outputFile, ['../ui-react', '../ui-react/' + index], outputFile, ); + await copyWithReplace( + outputFile, + ['../ui-solid', '../ui-solid/' + index], + outputFile, + ); if (min) { allOf(outputFiles, (outputFile) => gzipFile(outputFile)); diff --git a/package-lock.json b/package-lock.json index 02f8721d8eb..f6248dbc74b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -77,6 +77,7 @@ "rollup-plugin-esbuild": "^6.2.1", "rollup-plugin-preserve-shebang": "^1.0.1", "rollup-plugin-prettier": "^4.1.2", + "solid-js": "^1.9.10", "sqlite3": "^6.0.1", "tinybase": "file:./dist", "tinydocs": "^0.1.61", @@ -115,6 +116,7 @@ "react-dom": "^19.2.4", "react-native-mmkv": "4.2.0", "react-native-sqlite-storage": "^6.0.1", + "solid-js": "^1.9.10", "sqlite3": "^5.1.7", "valibot": "^1.2.0", "ws": "^8.19.0", @@ -185,6 +187,9 @@ "react-native-sqlite-storage": { "optional": true }, + "solid-js": { + "optional": true + }, "sqlite3": { "optional": true }, @@ -13544,6 +13549,37 @@ "node": ">=20.0.0" } }, + "node_modules/seroval": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/seroval/-/seroval-1.5.0.tgz", + "integrity": "sha512-OE4cvmJ1uSPrKorFIH9/w/Qwuvi/IMcGbv5RKgcJ/zjA/IohDLU6SVaxFN9FwajbP7nsX0dQqMDes1whk3y+yw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=10" + } + }, + "node_modules/seroval-plugins": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/seroval-plugins/-/seroval-plugins-1.5.0.tgz", + "integrity": "sha512-EAHqADIQondwRZIdeW2I636zgsODzoBDwb3PT/+7TLDWyw1Dy/Xv7iGUIEXXav7usHDE9HVhOU61irI3EnyyHA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=10" + }, + "peerDependencies": { + "seroval": "^1.0" + } + }, + "node_modules/set-blocking": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", + "integrity": "sha512-KiKBS8AnWGEyLzofFfmvKwpdPzqiy16LvQfK3yv/fVH7Bj13/wl3JSR1J+rfgRE9q7xUJK4qvgS8raSOeLUehw==", + "dev": true, + "license": "ISC", + "optional": true + }, "node_modules/set-function-length": { "version": "1.2.2", "dev": true, @@ -13807,18 +13843,16 @@ "npm": ">= 3.0.0" } }, - "node_modules/socks-proxy-agent": { - "version": "8.0.5", + "node_modules/solid-js": { + "version": "1.9.11", + "resolved": "https://registry.npmjs.org/solid-js/-/solid-js-1.9.11.tgz", + "integrity": "sha512-WEJtcc5mkh/BnHA6Yrg4whlF8g6QwpmXXRg4P2ztPmcKeHHlH4+djYecBLhSpecZY2RRECXYUwIc/C2r3yzQ4Q==", "dev": true, "license": "MIT", - "optional": true, "dependencies": { - "agent-base": "^7.1.2", - "debug": "^4.3.4", - "socks": "^2.8.3" - }, - "engines": { - "node": ">= 14" + "csstype": "^3.1.0", + "seroval": "~1.5.0", + "seroval-plugins": "~1.5.0" } }, "node_modules/source-map-js": { diff --git a/package.json b/package.json index 080f91afdce..428cde53d70 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "postgres": "^3.4.8", "react": "^19.2.4", "react-dom": "^19.2.4", + "solid-js": "^1.9.10", "react-native-mmkv": "4.2.0", "react-native-sqlite-storage": "^6.0.1", "sqlite3": "^5.1.7", @@ -106,6 +107,9 @@ "react-dom": { "optional": true }, + "solid-js": { + "optional": true + }, "react-native-sqlite-storage": { "optional": true }, @@ -236,6 +240,7 @@ "prettier-plugin-organize-imports": "^4.3.0", "react": "^19.2.4", "react-dom": "^19.2.4", + "solid-js": "^1.9.10", "react-native-mmkv": "4.2.0", "react-native-sqlite-storage": "^6.0.1", "rollup": "^4.59.0", diff --git a/src/@types/_internal/ui-solid/index.d.ts b/src/@types/_internal/ui-solid/index.d.ts new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/@types/_internal/ui-solid/with-schemas/index.d.ts b/src/@types/_internal/ui-solid/with-schemas/index.d.ts new file mode 100644 index 00000000000..59dd8805420 --- /dev/null +++ b/src/@types/_internal/ui-solid/with-schemas/index.d.ts @@ -0,0 +1,458 @@ +import type {Component, JSXElement} from 'solid-js'; +import type {Checkpoints} from '../../../checkpoints/with-schemas/index.d.ts'; +import type {Callback, Id} from '../../../common/with-schemas/index.d.ts'; +import type {Indexes} from '../../../indexes/with-schemas/index.d.ts'; +import type {Metrics} from '../../../metrics/with-schemas/index.d.ts'; +import type { + Persister, + Persists, +} from '../../../persisters/with-schemas/index.d.ts'; +import type {Queries} from '../../../queries/with-schemas/index.d.ts'; +import type {Relationships} from '../../../relationships/with-schemas/index.d.ts'; +import type { + OptionalSchemas, + Store, +} from '../../../store/with-schemas/index.d.ts'; +import type {Synchronizer} from '../../../synchronizers/with-schemas/index.d.ts'; +import type { + CellIdFromSchema, + TableIdFromSchema, + ValueIdFromSchema, +} from '../../store/with-schemas/index.d.ts'; + +type StoreOrStoreId = Store | Id; + +type MetricsOrMetricsId = + | Metrics + | Id; + +type IndexesOrIndexesId = + | Indexes + | Id; + +type RelationshipsOrRelationshipsId = + | Relationships + | Id; + +type QueriesOrQueriesId = + | Queries + | Id; + +type CheckpointsOrCheckpointsId = + | Checkpoints + | Id; + +type PersisterOrPersisterId = + | Persister + | Id; + +type SynchronizerOrSynchronizerId = + | Synchronizer + | Id; + +type UndoOrRedoInformation = [boolean, Callback, Id | undefined, string]; + +type GetId = ( + parameter: Parameter, + store: Store, +) => Id; + +type ExtraProps = {[propName: string]: any}; + +type TablesProps = { + /// TablesProps.store + readonly store?: StoreOrStoreId; + /// TablesProps.tableComponent + readonly tableComponent?: Component>; + /// TablesProps.getTableComponentProps + readonly getTableComponentProps?: (tableId: Id) => ExtraProps; + /// TablesProps.separator + readonly separator?: JSXElement | string; + /// TablesProps.debugIds + readonly debugIds?: boolean; +}; + +export type TableProps< + Schemas extends OptionalSchemas, + TableIds extends TableIdFromSchema = TableIdFromSchema< + Schemas[0] + >, +> = TableIds extends infer TableId + ? TableId extends TableIdFromSchema + ? { + /// TableProps.tableId + readonly tableId: TableId; + /// TableProps.store + readonly store?: StoreOrStoreId; + /// TableProps.rowComponent + readonly rowComponent?: Component>; + /// TableProps.getRowComponentProps + readonly getRowComponentProps?: (rowId: Id) => ExtraProps; + /// TableProps.customCellIds + readonly customCellIds?: CellIdFromSchema[]; + /// TableProps.separator + readonly separator?: JSXElement | string; + /// TableProps.debugIds + readonly debugIds?: boolean; + } + : never + : never; + +export type SortedTableProps< + Schemas extends OptionalSchemas, + TableIds extends TableIdFromSchema = TableIdFromSchema< + Schemas[0] + >, +> = TableIds extends infer TableId + ? TableId extends TableIdFromSchema + ? { + /// SortedTableProps.tableId + readonly tableId: TableId; + /// SortedTableProps.cellId + readonly cellId?: CellIdFromSchema; + /// SortedTableProps.descending + readonly descending?: boolean; + /// SortedTableProps.offset + readonly offset?: number; + /// SortedTableProps.limit + readonly limit?: number; + /// SortedTableProps.store + readonly store?: StoreOrStoreId; + /// SortedTableProps.rowComponent + readonly rowComponent?: Component>; + /// SortedTableProps.getRowComponentProps + readonly getRowComponentProps?: (rowId: Id) => ExtraProps; + /// SortedTableProps.customCellIds + readonly customCellIds?: CellIdFromSchema[]; + /// SortedTableProps.separator + readonly separator?: JSXElement | string; + /// SortedTableProps.debugIds + readonly debugIds?: boolean; + } + : never + : never; + +export type RowProps< + Schemas extends OptionalSchemas, + TableIds extends TableIdFromSchema = TableIdFromSchema< + Schemas[0] + >, +> = TableIds extends infer TableId + ? TableId extends TableIdFromSchema + ? { + /// RowProps.tableId + readonly tableId: TableId; + /// RowProps.rowId + readonly rowId: Id; + /// RowProps.store + readonly store?: StoreOrStoreId; + /// RowProps.cellComponent + readonly cellComponent?: Component>; + /// RowProps.getCellComponentProps + readonly getCellComponentProps?: (cellId: Id) => ExtraProps; + /// RowProps.customCellIds + readonly customCellIds?: CellIdFromSchema[]; + /// RowProps.separator + readonly separator?: JSXElement | string; + /// RowProps.debugIds + readonly debugIds?: boolean; + } + : never + : never; + +export type CellProps< + Schemas extends OptionalSchemas, + TableIds extends TableIdFromSchema = TableIdFromSchema< + Schemas[0] + >, +> = TableIds extends infer TableId + ? TableId extends TableIdFromSchema + ? CellPropsForTableIdAndCellId< + Schemas, + TableId, + CellIdFromSchema + > + : never + : never; + +export type CellPropsForTableIdAndCellId< + Schemas extends OptionalSchemas, + TableId extends TableIdFromSchema, + CellId extends CellIdFromSchema, +> = { + /// CellProps.tableId + readonly tableId: TableId; + /// CellProps.rowId + readonly rowId: Id; + /// CellProps.cellId + readonly cellId: CellId; + /// CellProps.store + readonly store?: StoreOrStoreId; + /// CellProps.debugIds + readonly debugIds?: boolean; +}; + +export type ValuesProps = { + /// ValuesProps.store + readonly store?: StoreOrStoreId; + /// ValuesProps.valueComponent + readonly valueComponent?: Component>; + /// ValuesProps.getValueComponentProps + readonly getValueComponentProps?: (valueId: Id) => ExtraProps; + /// ValuesProps.separator + readonly separator?: JSXElement | string; + /// ValuesProps.debugIds + readonly debugIds?: boolean; +}; + +export type ValueProps = { + /// ValueProps.valueId + readonly valueId: ValueIdFromSchema; + /// ValueProps.store + readonly store?: StoreOrStoreId; + /// ValueProps.debugIds + readonly debugIds?: boolean; +}; + +export type MetricProps = { + /// MetricProps.metricId + readonly metricId: Id; + /// MetricProps.metrics + readonly metrics?: MetricsOrMetricsId; + /// MetricProps.debugIds + readonly debugIds?: boolean; +}; + +export type IndexProps = { + /// IndexProps.indexId + readonly indexId: Id; + /// IndexProps.indexes + readonly indexes?: IndexesOrIndexesId; + /// IndexProps.sliceComponent + readonly sliceComponent?: Component>; + /// IndexProps.getSliceComponentProps + readonly getSliceComponentProps?: (sliceId: Id) => ExtraProps; + /// IndexProps.separator + readonly separator?: JSXElement | string; + /// IndexProps.debugIds + readonly debugIds?: boolean; +}; + +export type SliceProps = { + /// SliceProps.indexId + readonly indexId: Id; + /// SliceProps.sliceId + readonly sliceId: Id; + /// SliceProps.indexes + readonly indexes?: IndexesOrIndexesId; + /// SliceProps.rowComponent + readonly rowComponent?: Component>; + /// SliceProps.getRowComponentProps + readonly getRowComponentProps?: (rowId: Id) => ExtraProps; + /// SliceProps.separator + readonly separator?: JSXElement | string; + /// SliceProps.debugIds + readonly debugIds?: boolean; +}; + +export type RemoteRowProps = { + /// RemoteRowProps.relationshipId + readonly relationshipId: Id; + /// RemoteRowProps.localRowId + readonly localRowId: Id; + /// RemoteRowProps.relationships + readonly relationships?: RelationshipsOrRelationshipsId; + /// RemoteRowProps.rowComponent + readonly rowComponent?: Component>; + /// RemoteRowProps.getRowComponentProps + readonly getRowComponentProps?: (rowId: Id) => ExtraProps; + /// RemoteRowProps.debugIds + readonly debugIds?: boolean; +}; + +export type LocalRowsProps = { + /// LocalRowsProps.relationshipId + readonly relationshipId: Id; + /// LocalRowsProps.remoteRowId + readonly remoteRowId: Id; + /// LocalRowsProps.relationships + readonly relationships?: RelationshipsOrRelationshipsId; + /// LocalRowsProps.rowComponent + readonly rowComponent?: Component>; + /// LocalRowsProps.getRowComponentProps + readonly getRowComponentProps?: (rowId: Id) => ExtraProps; + /// LocalRowsProps.separator + readonly separator?: JSXElement | string; + /// LocalRowsProps.debugIds + readonly debugIds?: boolean; +}; + +export type LinkedRowsProps = { + /// LinkedRowsProps.relationshipId + readonly relationshipId: Id; + /// LinkedRowsProps.firstRowId + readonly firstRowId: Id; + /// LinkedRowsProps.relationships + readonly relationships?: RelationshipsOrRelationshipsId; + /// LinkedRowsProps.rowComponent + readonly rowComponent?: Component>; + /// LinkedRowsProps.getRowComponentProps + readonly getRowComponentProps?: (rowId: Id) => ExtraProps; + /// LinkedRowsProps.separator + readonly separator?: JSXElement | string; + /// LinkedRowsProps.debugIds + readonly debugIds?: boolean; +}; + +export type ResultTableProps = { + /// ResultTableProps.queryId + readonly queryId: Id; + /// ResultTableProps.queries + readonly queries?: QueriesOrQueriesId; + /// ResultTableProps.resultRowComponent + readonly resultRowComponent?: Component>; + /// ResultTableProps.getResultRowComponentProps + readonly getResultRowComponentProps?: (rowId: Id) => ExtraProps; + /// ResultTableProps.separator + readonly separator?: JSXElement | string; + /// ResultTableProps.debugIds + readonly debugIds?: boolean; +}; + +export type ResultSortedTableProps = { + /// ResultSortedTableProps.queryId + readonly queryId: Id; + /// ResultSortedTableProps.cellId + readonly cellId?: Id; + /// ResultSortedTableProps.descending + readonly descending?: boolean; + /// ResultSortedTableProps.offset + readonly offset?: number; + /// ResultSortedTableProps.limit + readonly limit?: number; + /// ResultSortedTableProps.queries + readonly queries?: QueriesOrQueriesId; + /// ResultSortedTableProps.resultRowComponent + readonly resultRowComponent?: Component>; + /// ResultSortedTableProps.getResultRowComponentProps + readonly getResultRowComponentProps?: (rowId: Id) => ExtraProps; + /// ResultSortedTableProps.separator + readonly separator?: JSXElement | string; + /// ResultSortedTableProps.debugIds + readonly debugIds?: boolean; +}; + +export type ResultRowProps = { + /// ResultRowProps.queryId + readonly queryId: Id; + /// ResultRowProps.rowId + readonly rowId: Id; + /// ResultRowProps.queries + readonly queries?: QueriesOrQueriesId; + /// ResultRowProps.resultCellComponent + readonly resultCellComponent?: Component>; + /// ResultRowProps.getResultCellComponentProps + readonly getResultCellComponentProps?: (cellId: Id) => ExtraProps; + /// ResultRowProps.separator + readonly separator?: JSXElement | string; + /// ResultRowProps.debugIds + readonly debugIds?: boolean; +}; + +export type ResultCellProps = { + /// ResultCellProps.queryId + readonly queryId: Id; + /// ResultCellProps.rowId + readonly rowId: Id; + /// ResultCellProps.cellId + readonly cellId: Id; + /// ResultCellProps.queries + readonly queries?: QueriesOrQueriesId; + /// ResultCellProps.debugIds + readonly debugIds?: boolean; +}; + +export type CheckpointProps = { + /// CheckpointProps.checkpointId + readonly checkpointId: Id; + /// CheckpointProps.checkpoints + readonly checkpoints?: CheckpointsOrCheckpointsId; + /// CheckpointProps.debugIds + readonly debugIds?: boolean; +}; + +export type BackwardCheckpointsProps = { + /// BackwardCheckpointsProps.checkpoints + readonly checkpoints?: CheckpointsOrCheckpointsId; + /// BackwardCheckpointsProps.checkpointComponent + readonly checkpointComponent?: Component>; + /// BackwardCheckpointsProps.getCheckpointComponentProps + readonly getCheckpointComponentProps?: (checkpointId: Id) => ExtraProps; + /// BackwardCheckpointsProps.separator + readonly separator?: JSXElement | string; + /// BackwardCheckpointsProps.debugIds + readonly debugIds?: boolean; +}; + +export type CurrentCheckpointProps = { + /// CurrentCheckpointProps.checkpoints + readonly checkpoints?: CheckpointsOrCheckpointsId; + /// CurrentCheckpointProps.checkpointComponent + readonly checkpointComponent?: Component>; + /// CurrentCheckpointProps.getCheckpointComponentProps + readonly getCheckpointComponentProps?: (checkpointId: Id) => ExtraProps; + /// CurrentCheckpointProps.debugIds + readonly debugIds?: boolean; +}; + +export type ForwardCheckpointsProps = { + /// ForwardCheckpointsProps.checkpoints + readonly checkpoints?: CheckpointsOrCheckpointsId; + /// ForwardCheckpointsProps.checkpointComponent + readonly checkpointComponent?: Component>; + /// ForwardCheckpointsProps.getCheckpointComponentProps + readonly getCheckpointComponentProps?: (checkpointId: Id) => ExtraProps; + /// ForwardCheckpointsProps.separator + readonly separator?: JSXElement | string; + /// ForwardCheckpointsProps.debugIds + readonly debugIds?: boolean; +}; + +export type ProviderProps = { + /// ProviderProps.store + readonly store?: Store; + /// ProviderProps.storesById + readonly storesById?: {[storeId: Id]: Store}; + /// ProviderProps.metrics + readonly metrics?: Metrics; + /// ProviderProps.metricsById + readonly metricsById?: {[metricsId: Id]: Metrics}; + /// ProviderProps.indexes + readonly indexes?: Indexes; + /// ProviderProps.indexesById + readonly indexesById?: {[indexesId: Id]: Indexes}; + /// ProviderProps.relationships + readonly relationships?: Relationships; + /// ProviderProps.relationshipsById + readonly relationshipsById?: {[relationshipsId: Id]: Relationships}; + /// ProviderProps.queries + readonly queries?: Queries; + /// ProviderProps.queriesById + readonly queriesById?: {[queriesId: Id]: Queries}; + /// ProviderProps.checkpoints + readonly checkpoints?: Checkpoints; + /// ProviderProps.checkpointsById + readonly checkpointsById?: {[checkpointsId: Id]: Checkpoints}; + /// ProviderProps.persister + readonly persister?: Persister; + /// ProviderProps.persistersById + readonly persistersById?: { + [persisterId: Id]: Persister; + }; + /// ProviderProps.synchronizer + readonly synchronizer?: Synchronizer; + /// ProviderProps.synchronizersById + readonly synchronizersById?: {[synchronizerId: Id]: Synchronizer}; +}; + +export type ComponentReturnType = JSXElement; diff --git a/src/@types/omni/index.d.ts b/src/@types/omni/index.d.ts index f1e36bd2690..29d300e2bee 100644 --- a/src/@types/omni/index.d.ts +++ b/src/@types/omni/index.d.ts @@ -45,3 +45,4 @@ export * from '../synchronizers/synchronizer-ws-server/index.d.ts'; export * from '../ui-react-dom/index.d.ts'; export * from '../ui-react-inspector/index.d.ts'; export * from '../ui-react/index.d.ts'; +export * from '../ui-solid/index.d.ts'; diff --git a/src/@types/omni/with-schemas/index.d.ts b/src/@types/omni/with-schemas/index.d.ts index 103fc8a01c7..67b9c42c2e5 100644 --- a/src/@types/omni/with-schemas/index.d.ts +++ b/src/@types/omni/with-schemas/index.d.ts @@ -45,3 +45,4 @@ export * from '../../synchronizers/with-schemas/index.d.ts'; export {WithSchemas as UiReactDomWithSchemas} from '../../ui-react-dom/with-schemas/index.d.ts'; export {WithSchemas as UiReactInspectorWithSchemas} from '../../ui-react-inspector/with-schemas/index.d.ts'; export {WithSchemas as UiReactWithSchemas} from '../../ui-react/with-schemas/index.d.ts'; +export {WithSchemas as UiSolidWithSchemas} from '../../ui-solid/with-schemas/index.d.ts'; diff --git a/src/@types/ui-solid/docs.js b/src/@types/ui-solid/docs.js new file mode 100644 index 00000000000..b53a348005d --- /dev/null +++ b/src/@types/ui-solid/docs.js @@ -0,0 +1,7 @@ +/** + * The ui-solid module of the TinyBase project provides the same API surface as + * ui-react, adapted for Solid applications. + * @category Module + * @since 8.0.0 + * @module ui-solid + */ diff --git a/src/@types/ui-solid/index.d.ts b/src/@types/ui-solid/index.d.ts new file mode 100644 index 00000000000..ea552af8dea --- /dev/null +++ b/src/@types/ui-solid/index.d.ts @@ -0,0 +1,1450 @@ +import type {Accessor, Component, JSXElement} from 'solid-js'; +import type { + CheckpointIds, + CheckpointIdsListener, + CheckpointListener, + Checkpoints, +} from '../checkpoints/index.d.ts'; +import type { + Callback, + Id, + IdOrNull, + Ids, + ParameterizedCallback, +} from '../common/index.d.ts'; +import type { + Indexes, + SliceIdsListener, + SliceRowIdsListener, +} from '../indexes/index.d.ts'; +import type {MergeableStore} from '../mergeable-store/index.d.ts'; +import type {MetricListener, Metrics} from '../metrics/index.d.ts'; +import type { + AnyPersister, + PersistedStore, + Persister, + Persists, + Status, + StatusListener, +} from '../persisters/index.d.ts'; +import type { + ParamValue, + ParamValueListener, + ParamValues, + ParamValuesListener, + Queries, + ResultCellIdsListener, + ResultCellListener, + ResultRowCountListener, + ResultRowIdsListener, + ResultRowListener, + ResultSortedRowIdsListener, + ResultTableCellIdsListener, + ResultTableListener, +} from '../queries/index.d.ts'; +import type { + LinkedRowIdsListener, + LocalRowIdsListener, + Relationships, + RemoteRowIdListener, +} from '../relationships/index.d.ts'; +import type { + Cell, + CellIdsListener, + CellListener, + CellOrUndefined, + HasCellListener, + HasRowListener, + HasTableCellListener, + HasTableListener, + HasTablesListener, + HasValueListener, + HasValuesListener, + MapCell, + MapValue, + Row, + RowCountListener, + RowIdsListener, + RowListener, + SortedRowIdsArgs, + SortedRowIdsListener, + Store, + Table, + TableCellIdsListener, + TableIdsListener, + TableListener, + Tables, + TablesListener, + TransactionListener, + Value, + ValueIdsListener, + ValueListener, + ValueOrUndefined, + Values, + ValuesListener, +} from '../store/index.d.ts'; +import type {Synchronizer} from '../synchronizers/index.d.ts'; + +type DependencyList = ReadonlyArray; + +export type StoreOrStoreId = Store | Id; + +export type MetricsOrMetricsId = Metrics | Id; + +export type IndexesOrIndexesId = Indexes | Id; + +export type RelationshipsOrRelationshipsId = Relationships | Id; + +export type QueriesOrQueriesId = Queries | Id; + +export type CheckpointsOrCheckpointsId = Checkpoints | Id; + +export type PersisterOrPersisterId = AnyPersister | Id; + +export type SynchronizerOrSynchronizerId = Synchronizer | Id; + +export type UndoOrRedoInformation = [boolean, Callback, Id | undefined, string]; + +export type GetId = (parameter: Parameter, store: Store) => Id; + +export function useCreateStore( + create: () => Store, + createDeps?: DependencyList, +): Accessor; + +export function useCreateMergeableStore( + create: () => MergeableStore, + createDeps?: DependencyList, +): Accessor; + +export function useStoreIds(): Accessor; + +export function useStore(id?: Id): Accessor; + +export function useStores(): Accessor<{[storeId: Id]: Store}>; + +export function useStoreOrStoreById( + storeOrStoreId?: StoreOrStoreId, +): Accessor; + +export function useProvideStore(storeId: Id, store: Store): void; + +export function useHasTables(storeOrStoreId?: StoreOrStoreId): Accessor; + +export function useTables(storeOrStoreId?: StoreOrStoreId): Accessor; + +export function useTablesState( + storeOrStoreId?: StoreOrStoreId, +): [Accessor, (tables: Tables) => void]; + +export function useTableIds(storeOrStoreId?: StoreOrStoreId): Accessor; + +export function useHasTable( + tableId: Id, + storeOrStoreId?: StoreOrStoreId, +): Accessor; + +export function useTable(tableId: Id, storeOrStoreId?: StoreOrStoreId): Accessor; + +export function useTableState( + tableId: Id, + storeOrStoreId?: StoreOrStoreId, +): [Accessor
, (table: Table) => void]; + +export function useTableCellIds( + tableId: Id, + storeOrStoreId?: StoreOrStoreId, +): Accessor; + +export function useHasTableCell( + tableId: Id, + cellId: Id, + storeOrStoreId?: StoreOrStoreId, +): Accessor; + +export function useRowCount( + tableId: Id, + storeOrStoreId?: StoreOrStoreId, +): Accessor; + +export function useRowIds(tableId: Id, storeOrStoreId?: StoreOrStoreId): Accessor; + +export function useSortedRowIds( + tableId: Id, + cellId?: Id, + descending?: boolean, + offset?: number, + limit?: number, + storeOrStoreId?: StoreOrStoreId, +): Accessor; + +export function useSortedRowIds( + args: SortedRowIdsArgs, + storeOrStoreId?: StoreOrStoreId, +): Accessor; + +export function useHasRow( + tableId: Id, + rowId: Id, + storeOrStoreId?: StoreOrStoreId, +): Accessor; + +export function useRow( + tableId: Id, + rowId: Id, + storeOrStoreId?: StoreOrStoreId, +): Accessor; + +export function useRowState( + tableId: Id, + rowId: Id, + storeOrStoreId?: StoreOrStoreId, +): [Accessor, (row: Row) => void]; + +export function useCellIds( + tableId: Id, + rowId: Id, + storeOrStoreId?: StoreOrStoreId, +): Accessor; + +export function useHasCell( + tableId: Id, + rowId: Id, + cellId: Id, + storeOrStoreId?: StoreOrStoreId, +): Accessor; + +export function useCell( + tableId: Id, + rowId: Id, + cellId: Id, + storeOrStoreId?: StoreOrStoreId, +): Accessor; + +export function useCellState( + tableId: Id, + rowId: Id, + cellId: Id, + storeOrStoreId?: StoreOrStoreId, +): [Accessor, (cell: Cell) => void]; + +export function useHasValues(storeOrStoreId?: StoreOrStoreId): Accessor; + +export function useValues(storeOrStoreId?: StoreOrStoreId): Accessor; + +export function useValuesState( + storeOrStoreId?: StoreOrStoreId, +): [Accessor, (values: Values) => void]; + +export function useValueIds(storeOrStoreId?: StoreOrStoreId): Accessor; + +export function useHasValue( + valueId: Id, + storeOrStoreId?: StoreOrStoreId, +): Accessor; + +export function useValue( + valueId: Id, + storeOrStoreId?: StoreOrStoreId, +): Accessor; + +export function useValueState( + valueId: Id, + storeOrStoreId?: StoreOrStoreId, +): [value: Accessor, setValue: (value: Value) => void]; + +export function useSetTablesCallback( + getTables: (parameter: Parameter, store: Store) => Tables, + getTablesDeps?: DependencyList, + storeOrStoreId?: StoreOrStoreId, + then?: (store: Store, tables: Tables) => void, + thenDeps?: DependencyList, +): ParameterizedCallback; + +export function useSetTableCallback( + tableId: Id | GetId, + getTable: (parameter: Parameter, store: Store) => Table, + getTableDeps?: DependencyList, + storeOrStoreId?: StoreOrStoreId, + then?: (store: Store, table: Table) => void, + thenDeps?: DependencyList, +): ParameterizedCallback; + +export function useSetRowCallback( + tableId: Id | GetId, + rowId: Id | GetId, + getRow: (parameter: Parameter, store: Store) => Row, + getRowDeps?: DependencyList, + storeOrStoreId?: StoreOrStoreId, + then?: (store: Store, row: Row) => void, + thenDeps?: DependencyList, +): ParameterizedCallback; + +export function useAddRowCallback( + tableId: Id | GetId, + getRow: (parameter: Parameter, store: Store) => Row, + getRowDeps?: DependencyList, + storeOrStoreId?: StoreOrStoreId, + then?: (rowId: Id | undefined, store: Store, row: Row) => void, + thenDeps?: DependencyList, + reuseRowIds?: boolean, +): ParameterizedCallback; + +export function useSetPartialRowCallback( + tableId: Id | GetId, + rowId: Id | GetId, + getPartialRow: (parameter: Parameter, store: Store) => Row, + getPartialRowDeps?: DependencyList, + storeOrStoreId?: StoreOrStoreId, + then?: (store: Store, partialRow: Row) => void, + thenDeps?: DependencyList, +): ParameterizedCallback; + +export function useSetCellCallback( + tableId: Id | GetId, + rowId: Id | GetId, + cellId: Id | GetId, + getCell: (parameter: Parameter, store: Store) => Cell | MapCell, + getCellDeps?: DependencyList, + storeOrStoreId?: StoreOrStoreId, + then?: (store: Store, cell: Cell | MapCell) => void, + thenDeps?: DependencyList, +): ParameterizedCallback; + +export function useSetValuesCallback( + getValues: (parameter: Parameter, store: Store) => Values, + getValuesDeps?: DependencyList, + storeOrStoreId?: StoreOrStoreId, + then?: (store: Store, values: Values) => void, + thenDeps?: DependencyList, +): ParameterizedCallback; + +export function useSetPartialValuesCallback( + getPartialValues: (parameter: Parameter, store: Store) => Values, + getPartialValuesDeps?: DependencyList, + storeOrStoreId?: StoreOrStoreId, + then?: (store: Store, partialValues: Values) => void, + thenDeps?: DependencyList, +): ParameterizedCallback; + +export function useSetValueCallback( + valueId: Id | GetId, + getValue: (parameter: Parameter, store: Store) => Value | MapValue, + getValueDeps?: DependencyList, + storeOrStoreId?: StoreOrStoreId, + then?: (store: Store, value: Value | MapValue) => void, + thenDeps?: DependencyList, +): ParameterizedCallback; + +export function useDelTablesCallback( + storeOrStoreId?: StoreOrStoreId, + then?: (store: Store) => void, + thenDeps?: DependencyList, +): Callback; + +export function useDelTableCallback( + tableId: Id | GetId, + storeOrStoreId?: StoreOrStoreId, + then?: (store: Store) => void, + thenDeps?: DependencyList, +): ParameterizedCallback; + +export function useDelRowCallback( + tableId: Id | GetId, + rowId: Id | GetId, + storeOrStoreId?: StoreOrStoreId, + then?: (store: Store) => void, + thenDeps?: DependencyList, +): ParameterizedCallback; + +export function useDelCellCallback( + tableId: Id | GetId, + rowId: Id | GetId, + cellId: Id | GetId, + forceDel?: boolean, + storeOrStoreId?: StoreOrStoreId, + then?: (store: Store) => void, + thenDeps?: DependencyList, +): ParameterizedCallback; + +export function useDelValuesCallback( + storeOrStoreId?: StoreOrStoreId, + then?: (store: Store) => void, + thenDeps?: DependencyList, +): Callback; + +export function useDelValueCallback( + valueId: Id | GetId, + storeOrStoreId?: StoreOrStoreId, + then?: (store: Store) => void, + thenDeps?: DependencyList, +): ParameterizedCallback; + +export function useHasTablesListener( + listener: HasTablesListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, +): void; + +export function useTablesListener( + listener: TablesListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, +): void; + +export function useTableIdsListener( + listener: TableIdsListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, +): void; + +export function useHasTableListener( + tableId: IdOrNull, + listener: HasTableListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, +): void; + +export function useTableListener( + tableId: IdOrNull, + listener: TableListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, +): void; + +export function useTableCellIdsListener( + tableId: IdOrNull, + listener: TableCellIdsListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, +): void; + +export function useHasTableCellListener( + tableId: IdOrNull, + cellId: IdOrNull, + listener: HasTableCellListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, +): void; + +export function useRowCountListener( + tableId: IdOrNull, + listener: RowCountListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, +): void; + +export function useRowIdsListener( + tableId: IdOrNull, + listener: RowIdsListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, +): void; + +export function useSortedRowIdsListener( + tableId: Id, + cellId: Id | undefined, + descending: boolean, + offset: number, + limit: number | undefined, + listener: SortedRowIdsListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, +): void; + +export function useSortedRowIdsListener( + args: SortedRowIdsArgs, + listener: SortedRowIdsListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, +): void; + +export function useHasRowListener( + tableId: IdOrNull, + rowId: IdOrNull, + listener: HasRowListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, +): void; + +export function useRowListener( + tableId: IdOrNull, + rowId: IdOrNull, + listener: RowListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, +): void; + +export function useCellIdsListener( + tableId: IdOrNull, + rowId: IdOrNull, + listener: CellIdsListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, +): void; + +export function useHasCellListener( + tableId: IdOrNull, + rowId: IdOrNull, + cellId: IdOrNull, + listener: HasCellListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, +): void; + +export function useCellListener( + tableId: IdOrNull, + rowId: IdOrNull, + cellId: IdOrNull, + listener: CellListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, +): void; + +export function useHasValuesListener( + listener: HasValuesListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, +): void; + +export function useValuesListener( + listener: ValuesListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, +): void; + +export function useValueIdsListener( + listener: ValueIdsListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, +): void; + +export function useHasValueListener( + valueId: IdOrNull, + listener: HasValueListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, +): void; + +export function useValueListener( + valueId: IdOrNull, + listener: ValueListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, +): void; + +export function useStartTransactionListener( + listener: TransactionListener, + listenerDeps?: DependencyList, + storeOrStoreId?: StoreOrStoreId, +): void; + +export function useWillFinishTransactionListener( + listener: TransactionListener, + listenerDeps?: DependencyList, + storeOrStoreId?: StoreOrStoreId, +): void; + +export function useDidFinishTransactionListener( + listener: TransactionListener, + listenerDeps?: DependencyList, + storeOrStoreId?: StoreOrStoreId, +): void; + +export function useCreateMetrics( + store: Store | undefined, + create: (store: Store) => Metrics, + createDeps?: DependencyList, +): Accessor; + +export function useMetricsIds(): Accessor; + +export function useMetrics(id?: Id): Accessor; + +export function useMetricsOrMetricsById( + metricsOrMetricsId?: MetricsOrMetricsId, +): Accessor; + +export function useProvideMetrics(metricsId: Id, metrics: Metrics): void; + +export function useMetricIds(metricsOrMetricsId?: MetricsOrMetricsId): Accessor; + +export function useMetric( + metricId: Id, + metricsOrMetricsId?: MetricsOrMetricsId, +): Accessor; + +export function useMetricListener( + metricId: IdOrNull, + listener: MetricListener, + listenerDeps?: DependencyList, + metricsOrMetricsId?: MetricsOrMetricsId, +): void; + +export function useCreateIndexes( + store: Store | undefined, + create: (store: Store) => Indexes, + createDeps?: DependencyList, +): Accessor; + +export function useIndexesIds(): Accessor; + +export function useIndexes(id?: Id): Accessor; + +export function useIndexesOrIndexesById( + indexesOrIndexesId?: IndexesOrIndexesId, +): Accessor; + +export function useProvideIndexes(indexesId: Id, indexes: Indexes): void; + +export function useIndexIds(indexesOrIndexesId?: IndexesOrIndexesId): Accessor; + +export function useSliceIds( + indexId: Id, + indexesOrIndexesId?: IndexesOrIndexesId, +): Accessor; + +export function useSliceRowIds( + indexId: Id, + sliceId: Id, + indexesOrIndexesId?: IndexesOrIndexesId, +): Accessor; + +export function useSliceIdsListener( + indexId: IdOrNull, + listener: SliceIdsListener, + listenerDeps?: DependencyList, + indexesOrIndexesId?: IndexesOrIndexesId, +): void; + +export function useSliceRowIdsListener( + indexId: IdOrNull, + sliceId: IdOrNull, + listener: SliceRowIdsListener, + listenerDeps?: DependencyList, + indexesOrIndexesId?: IndexesOrIndexesId, +): void; + +export function useCreateRelationships( + store: Store | undefined, + create: (store: Store) => Relationships, + createDeps?: DependencyList, +): Accessor; + +export function useRelationshipsIds(): Accessor; + +export function useRelationships(id?: Id): Accessor; + +export function useRelationshipsOrRelationshipsById( + relationshipsOrRelationshipsId?: RelationshipsOrRelationshipsId, +): Accessor; + +export function useProvideRelationships( + relationshipsId: Id, + relationships: Relationships, +): void; + +export function useRelationshipIds( + relationshipsOrRelationshipsId?: RelationshipsOrRelationshipsId, +): Accessor; + +export function useRemoteRowId( + relationshipId: Id, + localRowId: Id, + relationshipsOrRelationshipsId?: RelationshipsOrRelationshipsId, +): Accessor; + +export function useLocalRowIds( + relationshipId: Id, + remoteRowId: Id, + relationshipsOrRelationshipsId?: RelationshipsOrRelationshipsId, +): Accessor; + +export function useLinkedRowIds( + relationshipId: Id, + firstRowId: Id, + relationshipsOrRelationshipsId?: RelationshipsOrRelationshipsId, +): Accessor; + +export function useRemoteRowIdListener( + relationshipId: IdOrNull, + localRowId: IdOrNull, + listener: RemoteRowIdListener, + listenerDeps?: DependencyList, + relationshipsOrRelationshipsId?: RelationshipsOrRelationshipsId, +): void; + +export function useLocalRowIdsListener( + relationshipId: IdOrNull, + remoteRowId: IdOrNull, + listener: LocalRowIdsListener, + listenerDeps?: DependencyList, + relationshipsOrRelationshipsId?: RelationshipsOrRelationshipsId, +): void; + +export function useLinkedRowIdsListener( + relationshipId: Id, + firstRowId: Id, + listener: LinkedRowIdsListener, + listenerDeps?: DependencyList, + relationshipsOrRelationshipsId?: RelationshipsOrRelationshipsId, +): void; + +export function useCreateQueries( + store: Store | undefined, + create: (store: Store) => Queries, + createDeps?: DependencyList, +): Accessor; + +export function useQueriesIds(): Accessor; + +export function useQueries(id?: Id): Accessor; + +export function useQueriesOrQueriesById( + queriesOrQueriesId?: QueriesOrQueriesId, +): Accessor; + +export function useProvideQueries(queriesId: Id, queries: Queries): void; + +export function useQueryIds(queriesOrQueriesId?: QueriesOrQueriesId): Accessor; + +export function useResultTable( + queryId: Id, + queriesOrQueriesId?: QueriesOrQueriesId, +): Accessor
; + +export function useResultTableCellIds( + queryId: Id, + queriesOrQueriesId?: QueriesOrQueriesId, +): Accessor; + +export function useResultRowCount( + queryId: Id, + queriesOrQueriesId?: QueriesOrQueriesId, +): Accessor; + +export function useResultRowIds( + queryId: Id, + queriesOrQueriesId?: QueriesOrQueriesId, +): Accessor; + +export function useResultSortedRowIds( + queryId: Id, + cellId?: Id, + descending?: boolean, + offset?: number, + limit?: number, + queriesOrQueriesId?: QueriesOrQueriesId, +): Accessor; + +export function useResultRow( + queryId: Id, + rowId: Id, + queriesOrQueriesId?: QueriesOrQueriesId, +): Accessor; + +export function useResultCellIds( + queryId: Id, + rowId: Id, + queriesOrQueriesId?: QueriesOrQueriesId, +): Accessor; + +export function useResultCell( + queryId: Id, + rowId: Id, + cellId: Id, + queriesOrQueriesId?: QueriesOrQueriesId, +): Accessor; + +export function useResultTableListener( + queryId: IdOrNull, + listener: ResultTableListener, + listenerDeps?: DependencyList, + queriesOrQueriesId?: QueriesOrQueriesId, +): void; + +export function useResultTableCellIdsListener( + queryId: IdOrNull, + listener: ResultTableCellIdsListener, + listenerDeps?: DependencyList, + queriesOrQueriesId?: QueriesOrQueriesId, +): void; + +export function useResultRowCountListener( + queryId: IdOrNull, + listener: ResultRowCountListener, + listenerDeps?: DependencyList, + queriesOrQueriesId?: QueriesOrQueriesId, +): void; + +export function useResultRowIdsListener( + queryId: IdOrNull, + listener: ResultRowIdsListener, + listenerDeps?: DependencyList, + queriesOrQueriesId?: QueriesOrQueriesId, +): void; + +export function useResultSortedRowIdsListener( + queryId: Id, + cellId: Id | undefined, + descending: boolean, + offset: number, + limit: number | undefined, + listener: ResultSortedRowIdsListener, + listenerDeps?: DependencyList, + queriesOrQueriesId?: QueriesOrQueriesId, +): void; + +export function useResultRowListener( + queryId: IdOrNull, + rowId: IdOrNull, + listener: ResultRowListener, + listenerDeps?: DependencyList, + queriesOrQueriesId?: QueriesOrQueriesId, +): void; + +export function useResultCellIdsListener( + queryId: IdOrNull, + rowId: IdOrNull, + listener: ResultCellIdsListener, + listenerDeps?: DependencyList, + queriesOrQueriesId?: QueriesOrQueriesId, +): void; + +export function useResultCellListener( + queryId: IdOrNull, + rowId: IdOrNull, + cellId: IdOrNull, + listener: ResultCellListener, + listenerDeps?: DependencyList, + queriesOrQueriesId?: QueriesOrQueriesId, +): void; + +export function useParamValues( + queryId: Id, + queriesOrQueriesId?: QueriesOrQueriesId, +): Accessor; + +export function useParamValuesState( + queryId: Id, + queriesOrQueriesId?: QueriesOrQueriesId, +): [Accessor, (paramValues: ParamValues) => void]; + +export function useParamValue( + queryId: Id, + paramId: Id, + queriesOrQueriesId?: QueriesOrQueriesId, +): Accessor; + +export function useParamValueState( + queryId: Id, + paramId: Id, + queriesOrQueriesId?: QueriesOrQueriesId, +): [Accessor, (paramValue: ParamValue) => void]; + +export function useParamValuesListener( + queryId: IdOrNull, + listener: ParamValuesListener, + listenerDeps?: DependencyList, + queriesOrQueriesId?: QueriesOrQueriesId, +): void; + +export function useParamValueListener( + queryId: IdOrNull, + paramId: IdOrNull, + listener: ParamValueListener, + listenerDeps?: DependencyList, + queriesOrQueriesId?: QueriesOrQueriesId, +): void; + +export function useSetParamValueCallback( + queryId: Id | GetId, + paramId: Id | GetId, + getParamValue: (parameter: Parameter, queries: Queries) => ParamValue, + getParamValueDeps?: DependencyList, + queriesOrQueriesId?: QueriesOrQueriesId, + then?: (queries: Queries, paramValue: ParamValue) => void, + thenDeps?: DependencyList, +): ParameterizedCallback; + +export function useSetParamValuesCallback( + queryId: Id | GetId, + getParamValues: (parameter: Parameter, queries: Queries) => ParamValues, + getParamValuesDeps?: DependencyList, + queriesOrQueriesId?: QueriesOrQueriesId, + then?: (queries: Queries, paramValues: ParamValues) => void, + thenDeps?: DependencyList, +): ParameterizedCallback; + +export function useCreateCheckpoints( + store: Store | undefined, + create: (store: Store) => Checkpoints, + createDeps?: DependencyList, +): Accessor; + +export function useCheckpointsIds(): Accessor; + +export function useCheckpoints(id?: Id): Accessor; + +export function useCheckpointsOrCheckpointsById( + checkpointsOrCheckpointsId?: CheckpointsOrCheckpointsId, +): Accessor; + +export function useProvideCheckpoints( + checkpointsId: Id, + checkpoints: Checkpoints, +): void; + +export function useCheckpointIds( + checkpointsOrCheckpointsId?: CheckpointsOrCheckpointsId, +): Accessor; + +export function useCheckpoint( + checkpointId: Id, + checkpointsOrCheckpointsId?: CheckpointsOrCheckpointsId, +): Accessor; + +export function useSetCheckpointCallback( + getCheckpoint?: (parameter: Parameter) => string, + getCheckpointDeps?: DependencyList, + checkpointsOrCheckpointsId?: CheckpointsOrCheckpointsId, + then?: (checkpointId: Id, checkpoints: Checkpoints, label?: string) => void, + thenDeps?: DependencyList, +): ParameterizedCallback; + +export function useGoBackwardCallback( + checkpointsOrCheckpointsId?: CheckpointsOrCheckpointsId, +): Callback; + +export function useGoForwardCallback( + checkpointsOrCheckpointsId?: CheckpointsOrCheckpointsId, +): Callback; + +export function useGoToCallback( + getCheckpointId: (parameter: Parameter) => Id, + getCheckpointIdDeps?: DependencyList, + checkpointsOrCheckpointsId?: CheckpointsOrCheckpointsId, + then?: (checkpoints: Checkpoints, checkpointId: Id) => void, + thenDeps?: DependencyList, +): ParameterizedCallback; + +export function useUndoInformation( + checkpointsOrCheckpointsId?: CheckpointsOrCheckpointsId, +): UndoOrRedoInformation; + +export function useRedoInformation( + checkpointsOrCheckpointsId?: CheckpointsOrCheckpointsId, +): UndoOrRedoInformation; + +export function useCheckpointIdsListener( + listener: CheckpointIdsListener, + listenerDeps?: DependencyList, + checkpointsOrCheckpointsId?: CheckpointsOrCheckpointsId, +): void; + +export function useCheckpointListener( + checkpointId: IdOrNull, + listener: CheckpointListener, + listenerDeps?: DependencyList, + checkpointsOrCheckpointsId?: CheckpointsOrCheckpointsId, +): void; + +export function useCreatePersister< + Persist extends Persists, + PersisterOrUndefined extends Persister | undefined, +>( + store: PersistedStore | undefined, + create: ( + store: PersistedStore, + ) => PersisterOrUndefined | Promise, + createDeps?: DependencyList, + then?: (persister: Persister) => Promise, + thenDeps?: DependencyList, + destroy?: (persister: Persister) => void, + destroyDeps?: DependencyList, +): Accessor; + +export function usePersisterIds(): Accessor; + +export function usePersister(id?: Id): Accessor; + +export function usePersisterOrPersisterById( + persisterOrPersisterId?: PersisterOrPersisterId, +): Accessor; + +export function useProvidePersister( + persisterId: Id, + persister: AnyPersister, +): void; + +export function usePersisterStatus( + persisterOrPersisterId?: PersisterOrPersisterId, +): Accessor; + +export function usePersisterStatusListener( + listener: StatusListener, + listenerDeps?: DependencyList, + persisterOrPersisterId?: PersisterOrPersisterId, +): void; + +export function useCreateSynchronizer< + SynchronizerOrUndefined extends Synchronizer | undefined, +>( + store: MergeableStore | undefined, + create: (store: MergeableStore) => Promise, + createDeps?: DependencyList, + destroy?: (synchronizer: Synchronizer) => void, + destroyDeps?: DependencyList, +): Accessor; + +export function useSynchronizerIds(): Accessor; + +export function useSynchronizer(id?: Id): Accessor; + +export function useSynchronizerOrSynchronizerById( + synchronizerOrSynchronizerId?: SynchronizerOrSynchronizerId, +): Accessor; + +export function useProvideSynchronizer( + synchronizerId: Id, + synchronizer: Synchronizer, +): void; + +export function useSynchronizerStatus( + synchronizerOrSynchronizerId?: SynchronizerOrSynchronizerId, +): Accessor; + +export function useSynchronizerStatusListener( + listener: StatusListener, + listenerDeps?: DependencyList, + synchronizerOrSynchronizerId?: SynchronizerOrSynchronizerId, +): void; + +export type ExtraProps = {[propName: string]: any}; + +export type TablesProps = { + /// TablesProps.store + readonly store?: StoreOrStoreId; + /// TablesProps.tableComponent + readonly tableComponent?: Component; + /// TablesProps.getTableComponentProps + readonly getTableComponentProps?: (tableId: Id) => ExtraProps; + /// TablesProps.separator + readonly separator?: JSXElement | string; + /// TablesProps.debugIds + readonly debugIds?: boolean; +}; + +export type TableProps = { + /// TableProps.tableId + readonly tableId: Id; + /// TableProps.store + readonly store?: StoreOrStoreId; + /// TableProps.rowComponent + readonly rowComponent?: Component; + /// TableProps.getRowComponentProps + readonly getRowComponentProps?: (rowId: Id) => ExtraProps; + /// TableProps.customCellIds + readonly customCellIds?: Ids; + /// TableProps.separator + readonly separator?: JSXElement | string; + /// TableProps.debugIds + readonly debugIds?: boolean; +}; + +export type SortedTableProps = { + /// SortedTableProps.tableId + readonly tableId: Id; + /// SortedTableProps.cellId + readonly cellId?: Id; + /// SortedTableProps.descending + readonly descending?: boolean; + /// SortedTableProps.offset + readonly offset?: number; + /// SortedTableProps.limit + readonly limit?: number; + /// SortedTableProps.store + readonly store?: StoreOrStoreId; + /// SortedTableProps.rowComponent + readonly rowComponent?: Component; + /// SortedTableProps.getRowComponentProps + readonly getRowComponentProps?: (rowId: Id) => ExtraProps; + /// SortedTableProps.customCellIds + readonly customCellIds?: Ids; + /// SortedTableProps.separator + readonly separator?: JSXElement | string; + /// SortedTableProps.debugIds + readonly debugIds?: boolean; +}; + +export type RowProps = { + /// RowProps.tableId + readonly tableId: Id; + /// RowProps.rowId + readonly rowId: Id; + /// RowProps.store + readonly store?: StoreOrStoreId; + /// RowProps.cellComponent + readonly cellComponent?: Component; + /// RowProps.getCellComponentProps + readonly getCellComponentProps?: (cellId: Id) => ExtraProps; + /// RowProps.customCellIds + readonly customCellIds?: Ids; + /// RowProps.separator + readonly separator?: JSXElement | string; + /// RowProps.debugIds + readonly debugIds?: boolean; +}; + +export type CellProps = { + /// CellProps.tableId + readonly tableId: Id; + /// CellProps.rowId + readonly rowId: Id; + /// CellProps.cellId + readonly cellId: Id; + /// CellProps.store + readonly store?: StoreOrStoreId; + /// CellProps.debugIds + readonly debugIds?: boolean; +}; + +export type ValuesProps = { + /// ValuesProps.store + readonly store?: StoreOrStoreId; + /// ValuesProps.valueComponent + readonly valueComponent?: Component; + /// ValuesProps.getValueComponentProps + readonly getValueComponentProps?: (valueId: Id) => ExtraProps; + /// ValuesProps.separator + readonly separator?: JSXElement | string; + /// ValuesProps.debugIds + readonly debugIds?: boolean; +}; + +export type ValueProps = { + /// ValueProps.valueId + readonly valueId: Id; + /// ValueProps.store + readonly store?: StoreOrStoreId; + /// ValueProps.debugIds + readonly debugIds?: boolean; +}; + +export type MetricProps = { + /// MetricProps.metricId + readonly metricId: Id; + /// MetricProps.metrics + readonly metrics?: MetricsOrMetricsId; + /// MetricProps.debugIds + readonly debugIds?: boolean; +}; + +export type IndexProps = { + /// IndexProps.indexId + readonly indexId: Id; + /// IndexProps.indexes + readonly indexes?: IndexesOrIndexesId; + /// IndexProps.sliceComponent + readonly sliceComponent?: Component; + /// IndexProps.getSliceComponentProps + readonly getSliceComponentProps?: (sliceId: Id) => ExtraProps; + /// IndexProps.separator + readonly separator?: JSXElement | string; + /// IndexProps.debugIds + readonly debugIds?: boolean; +}; + +export type SliceProps = { + /// SliceProps.indexId + readonly indexId: Id; + /// SliceProps.sliceId + readonly sliceId: Id; + /// SliceProps.indexes + readonly indexes?: IndexesOrIndexesId; + /// SliceProps.rowComponent + readonly rowComponent?: Component; + /// SliceProps.getRowComponentProps + readonly getRowComponentProps?: (rowId: Id) => ExtraProps; + /// SliceProps.separator + readonly separator?: JSXElement | string; + /// SliceProps.debugIds + readonly debugIds?: boolean; +}; + +export type RemoteRowProps = { + /// RemoteRowProps.relationshipId + readonly relationshipId: Id; + /// RemoteRowProps.localRowId + readonly localRowId: Id; + /// RemoteRowProps.relationships + readonly relationships?: RelationshipsOrRelationshipsId; + /// RemoteRowProps.rowComponent + readonly rowComponent?: Component; + /// RemoteRowProps.getRowComponentProps + readonly getRowComponentProps?: (rowId: Id) => ExtraProps; + /// RemoteRowProps.debugIds + readonly debugIds?: boolean; +}; + +export type LocalRowsProps = { + /// LocalRowsProps.relationshipId + readonly relationshipId: Id; + /// LocalRowsProps.remoteRowId + readonly remoteRowId: Id; + /// LocalRowsProps.relationships + readonly relationships?: RelationshipsOrRelationshipsId; + /// LocalRowsProps.rowComponent + readonly rowComponent?: Component; + /// LocalRowsProps.getRowComponentProps + readonly getRowComponentProps?: (rowId: Id) => ExtraProps; + /// LocalRowsProps.separator + readonly separator?: JSXElement | string; + /// LocalRowsProps.debugIds + readonly debugIds?: boolean; +}; + +export type LinkedRowsProps = { + /// LinkedRowsProps.relationshipId + readonly relationshipId: Id; + /// LinkedRowsProps.firstRowId + readonly firstRowId: Id; + /// LinkedRowsProps.relationships + readonly relationships?: RelationshipsOrRelationshipsId; + /// LinkedRowsProps.rowComponent + readonly rowComponent?: Component; + /// LinkedRowsProps.getRowComponentProps + readonly getRowComponentProps?: (rowId: Id) => ExtraProps; + /// LinkedRowsProps.separator + readonly separator?: JSXElement | string; + /// LinkedRowsProps.debugIds + readonly debugIds?: boolean; +}; + +export type ResultTableProps = { + /// ResultTableProps.queryId + readonly queryId: Id; + /// ResultTableProps.queries + readonly queries?: QueriesOrQueriesId; + /// ResultTableProps.resultRowComponent + readonly resultRowComponent?: Component; + /// ResultTableProps.getResultRowComponentProps + readonly getResultRowComponentProps?: (rowId: Id) => ExtraProps; + /// ResultTableProps.separator + readonly separator?: JSXElement | string; + /// ResultTableProps.debugIds + readonly debugIds?: boolean; +}; + +export type ResultSortedTableProps = { + /// ResultSortedTableProps.queryId + readonly queryId: Id; + /// ResultSortedTableProps.cellId + readonly cellId?: Id; + /// ResultSortedTableProps.descending + readonly descending?: boolean; + /// ResultSortedTableProps.offset + readonly offset?: number; + /// ResultSortedTableProps.limit + readonly limit?: number; + /// ResultSortedTableProps.queries + readonly queries?: QueriesOrQueriesId; + /// ResultSortedTableProps.resultRowComponent + readonly resultRowComponent?: Component; + /// ResultSortedTableProps.getResultRowComponentProps + readonly getResultRowComponentProps?: (rowId: Id) => ExtraProps; + /// ResultSortedTableProps.separator + readonly separator?: JSXElement | string; + /// ResultSortedTableProps.debugIds + readonly debugIds?: boolean; +}; + +export type ResultRowProps = { + /// ResultRowProps.queryId + readonly queryId: Id; + /// ResultRowProps.rowId + readonly rowId: Id; + /// ResultRowProps.queries + readonly queries?: QueriesOrQueriesId; + /// ResultRowProps.resultCellComponent + readonly resultCellComponent?: Component; + /// ResultRowProps.getResultCellComponentProps + readonly getResultCellComponentProps?: (cellId: Id) => ExtraProps; + /// ResultRowProps.separator + readonly separator?: JSXElement | string; + /// ResultRowProps.debugIds + readonly debugIds?: boolean; +}; + +export type ResultCellProps = { + /// ResultCellProps.queryId + readonly queryId: Id; + /// ResultCellProps.rowId + readonly rowId: Id; + /// ResultCellProps.cellId + readonly cellId: Id; + /// ResultCellProps.queries + readonly queries?: QueriesOrQueriesId; + /// ResultCellProps.debugIds + readonly debugIds?: boolean; +}; + +export type CheckpointProps = { + /// CheckpointProps.checkpointId + readonly checkpointId: Id; + /// CheckpointProps.checkpoints + readonly checkpoints?: CheckpointsOrCheckpointsId; + /// CheckpointProps.debugIds + readonly debugIds?: boolean; +}; + +export type BackwardCheckpointsProps = { + /// BackwardCheckpointsProps.checkpoints + readonly checkpoints?: CheckpointsOrCheckpointsId; + /// BackwardCheckpointsProps.checkpointComponent + readonly checkpointComponent?: Component; + /// BackwardCheckpointsProps.getCheckpointComponentProps + readonly getCheckpointComponentProps?: (checkpointId: Id) => ExtraProps; + /// BackwardCheckpointsProps.separator + readonly separator?: JSXElement | string; + /// BackwardCheckpointsProps.debugIds + readonly debugIds?: boolean; +}; + +export type CurrentCheckpointProps = { + /// CurrentCheckpointProps.checkpoints + readonly checkpoints?: CheckpointsOrCheckpointsId; + /// CurrentCheckpointProps.checkpointComponent + readonly checkpointComponent?: Component; + /// CurrentCheckpointProps.getCheckpointComponentProps + readonly getCheckpointComponentProps?: (checkpointId: Id) => ExtraProps; + /// CurrentCheckpointProps.debugIds + readonly debugIds?: boolean; +}; + +export type ForwardCheckpointsProps = { + /// ForwardCheckpointsProps.checkpoints + readonly checkpoints?: CheckpointsOrCheckpointsId; + /// ForwardCheckpointsProps.checkpointComponent + readonly checkpointComponent?: Component; + /// ForwardCheckpointsProps.getCheckpointComponentProps + readonly getCheckpointComponentProps?: (checkpointId: Id) => ExtraProps; + /// ForwardCheckpointsProps.separator + readonly separator?: JSXElement | string; + /// ForwardCheckpointsProps.debugIds + readonly debugIds?: boolean; +}; + +export type ProviderProps = { + /// ProviderProps.store + readonly store?: Store; + /// ProviderProps.storesById + readonly storesById?: {[storeId: Id]: Store}; + /// ProviderProps.metrics + readonly metrics?: Metrics; + /// ProviderProps.metricsById + readonly metricsById?: {[metricsId: Id]: Metrics}; + /// ProviderProps.indexes + readonly indexes?: Indexes; + /// ProviderProps.indexesById + readonly indexesById?: {[indexesId: Id]: Indexes}; + /// ProviderProps.relationships + readonly relationships?: Relationships; + /// ProviderProps.relationshipsById + readonly relationshipsById?: {[relationshipsId: Id]: Relationships}; + /// ProviderProps.queries + readonly queries?: Queries; + /// ProviderProps.queriesById + readonly queriesById?: {[queriesId: Id]: Queries}; + /// ProviderProps.checkpoints + readonly checkpoints?: Checkpoints; + /// ProviderProps.checkpointsById + readonly checkpointsById?: {[checkpointsId: Id]: Checkpoints}; + /// ProviderProps.persister + readonly persister?: AnyPersister; + /// ProviderProps.persistersById + readonly persistersById?: { + [persisterId: Id]: AnyPersister; + }; + /// ProviderProps.synchronizer + readonly synchronizer?: Synchronizer; + /// ProviderProps.synchronizersById + readonly synchronizersById?: {[synchronizerId: Id]: Synchronizer}; +}; + +export type ComponentReturnType = JSXElement; + +export function Provider( + props: ProviderProps & {children: JSXElement}, +): ComponentReturnType; + +export function CellView(props: CellProps): ComponentReturnType; + +export function RowView(props: RowProps): ComponentReturnType; + +export function SortedTableView(props: SortedTableProps): ComponentReturnType; + +export function TableView(props: TableProps): ComponentReturnType; + +export function TablesView(props: TablesProps): ComponentReturnType; + +export function ValueView(props: ValueProps): ComponentReturnType; + +export function ValuesView(props: ValuesProps): ComponentReturnType; + +export function MetricView(props: MetricProps): ComponentReturnType; + +export function SliceView(props: SliceProps): ComponentReturnType; + +export function IndexView(props: IndexProps): ComponentReturnType; + +export function RemoteRowView(props: RemoteRowProps): ComponentReturnType; + +export function LocalRowsView(props: LocalRowsProps): ComponentReturnType; + +export function LinkedRowsView(props: LinkedRowsProps): ComponentReturnType; + +export function ResultCellView(props: ResultCellProps): ComponentReturnType; + +export function ResultRowView(props: ResultRowProps): ComponentReturnType; + +export function ResultSortedTableView( + props: ResultSortedTableProps, +): ComponentReturnType; + +export function ResultTableView(props: ResultTableProps): ComponentReturnType; + +export function CheckpointView(props: CheckpointProps): ComponentReturnType; + +export function BackwardCheckpointsView( + props: BackwardCheckpointsProps, +): ComponentReturnType; + +export function CurrentCheckpointView( + props: CurrentCheckpointProps, +): ComponentReturnType; + +export function ForwardCheckpointsView( + props: ForwardCheckpointsProps, +): ComponentReturnType; diff --git a/src/@types/ui-solid/with-schemas/index.d.ts b/src/@types/ui-solid/with-schemas/index.d.ts new file mode 100644 index 00000000000..808bd504e3c --- /dev/null +++ b/src/@types/ui-solid/with-schemas/index.d.ts @@ -0,0 +1,1582 @@ +import type {JSXElement} from 'solid-js'; +import type { + AllCellIdFromSchema, + CellIdFromSchema, + DefaultedValueFromSchema, + NoInfer, + TableIdFromSchema, + ValueIdFromSchema, +} from '../../_internal/store/with-schemas/index.d.ts'; +import type { + BackwardCheckpointsProps, + CellProps, + CheckpointProps, + CheckpointsOrCheckpointsId, + ComponentReturnType, + CurrentCheckpointProps, + ExtraProps, + ForwardCheckpointsProps, + GetId, + IndexProps, + IndexesOrIndexesId, + LinkedRowsProps, + LocalRowsProps, + MetricProps, + MetricsOrMetricsId, + PersisterOrPersisterId, + ProviderProps, + QueriesOrQueriesId, + RelationshipsOrRelationshipsId, + RemoteRowProps, + ResultCellProps, + ResultRowProps, + ResultSortedTableProps, + ResultTableProps, + RowProps, + SliceProps, + SortedTableProps, + StoreOrStoreId, + SynchronizerOrSynchronizerId, + TableProps, + TablesProps, + UndoOrRedoInformation, + ValueProps, + ValuesProps, +} from '../../_internal/ui-solid/with-schemas/index.d.ts'; +import type { + CheckpointIds, + CheckpointIdsListener, + CheckpointListener, + Checkpoints, +} from '../../checkpoints/with-schemas/index.d.ts'; +import type { + Callback, + Id, + IdOrNull, + Ids, + ParameterizedCallback, +} from '../../common/with-schemas/index.d.ts'; +import type { + Indexes, + SliceIdsListener, + SliceRowIdsListener, +} from '../../indexes/with-schemas/index.d.ts'; +import type {MergeableStore} from '../../mergeable-store/with-schemas/index.d.ts'; +import type { + MetricListener, + Metrics, +} from '../../metrics/with-schemas/index.d.ts'; +import type { + AnyPersister, + PersistedStore, + Persister, + Persists, + Status, + StatusListener, +} from '../../persisters/with-schemas/index.d.ts'; +import type { + ParamValue, + ParamValueListener, + ParamValues, + ParamValuesListener, + Queries, + ResultCell, + ResultCellIdsListener, + ResultCellListener, + ResultRow, + ResultRowCountListener, + ResultRowIdsListener, + ResultRowListener, + ResultSortedRowIdsListener, + ResultTable, + ResultTableCellIdsListener, + ResultTableListener, +} from '../../queries/with-schemas/index.d.ts'; +import type { + LinkedRowIdsListener, + LocalRowIdsListener, + Relationships, + RemoteRowIdListener, +} from '../../relationships/with-schemas/index.d.ts'; +import type { + Cell, + CellIdsListener, + CellListener, + CellOrUndefined, + HasCellListener, + HasRowListener, + HasTableCellListener, + HasTableListener, + HasTablesListener, + HasValueListener, + HasValuesListener, + MapCell, + MapValue, + OptionalSchemas, + Row, + RowCountListener, + RowIdsListener, + RowListener, + SortedRowIdsArgs, + SortedRowIdsListener, + Store, + Table, + TableCellIdsListener, + TableIdsListener, + TableListener, + Tables, + TablesListener, + TransactionListener, + Value, + ValueIdsListener, + ValueListener, + Values, + ValuesListener, +} from '../../store/with-schemas/index.d.ts'; +import type {Synchronizer} from '../../synchronizers/with-schemas/index.d.ts'; + +type DependencyList = ReadonlyArray; + +export type WithSchemas = { + /// StoreOrStoreId + StoreOrStoreId: StoreOrStoreId; + + /// MetricsOrMetricsId + MetricsOrMetricsId: MetricsOrMetricsId; + + /// IndexesOrIndexesId + IndexesOrIndexesId: IndexesOrIndexesId; + + /// RelationshipsOrRelationshipsId + RelationshipsOrRelationshipsId: RelationshipsOrRelationshipsId; + + /// QueriesOrQueriesId + QueriesOrQueriesId: QueriesOrQueriesId; + + /// CheckpointsOrCheckpointsId + CheckpointsOrCheckpointsId: CheckpointsOrCheckpointsId; + + /// PersisterOrPersisterId + PersisterOrPersisterId: PersisterOrPersisterId; + + /// SynchronizerOrSynchronizerId + SynchronizerOrSynchronizerId: SynchronizerOrSynchronizerId; + + /// UndoOrRedoInformation + UndoOrRedoInformation: UndoOrRedoInformation; + + /// useCreateStore + useCreateStore: ( + create: () => Store, + createDeps?: DependencyList, + ) => Store; + + /// useCreateMergeableStore + useCreateMergeableStore: ( + create: () => MergeableStore, + createDeps?: DependencyList, + ) => MergeableStore; + + /// useStoreIds + useStoreIds: () => Ids; + + /// useStore + useStore: (id?: Id) => Store | undefined; + + /// useStores + useStores: () => {[storeId: Id]: Store}; + + /// useStoreOrStoreById + useStoreOrStoreById: ( + storeOrStoreId?: StoreOrStoreId, + ) => Store | undefined; + + /// useProvideStore + useProvideStore: (storeId: Id, store: Store) => void; + + /// useHasTables + useHasTables: (storeOrStoreId?: StoreOrStoreId) => boolean; + + /// useTables + useTables: (storeOrStoreId?: StoreOrStoreId) => Tables; + + /// useTablesState + useTablesState: ( + storeOrStoreId?: StoreOrStoreId, + ) => [Tables, (tables: Tables) => void]; + + /// useTableIds + useTableIds: ( + storeOrStoreId?: StoreOrStoreId, + ) => TableIdFromSchema[]; + + /// useHasTable + useHasTable: >( + tableId: TableId, + storeOrStoreId?: StoreOrStoreId, + ) => boolean; + + /// useTable + useTable: >( + tableId: TableId, + storeOrStoreId?: StoreOrStoreId, + ) => Table; + + /// useTableState + useTableState: >( + tableId: TableId, + storeOrStoreId?: StoreOrStoreId, + ) => [ + Table, + (table: Table) => void, + ]; + + /// useTableCellIds + useTableCellIds: >( + tableId: TableId, + storeOrStoreId?: StoreOrStoreId, + ) => CellIdFromSchema[]; + + /// useHasTableCell + useHasTableCell: >( + tableId: TableId, + cellId: CellIdFromSchema, + storeOrStoreId?: StoreOrStoreId, + ) => boolean; + + /// useRowCount + useRowCount: ( + tableId: TableIdFromSchema, + storeOrStoreId?: StoreOrStoreId, + ) => number; + + /// useRowIds + useRowIds: ( + tableId: TableIdFromSchema, + storeOrStoreId?: StoreOrStoreId, + ) => Ids; + + useSortedRowIds: { + /// useSortedRowIds + < + TableId extends TableIdFromSchema, + CellId extends CellIdFromSchema, + >( + tableId: TableId, + cellId?: CellId, + descending?: boolean, + offset?: number, + limit?: number, + storeOrStoreId?: StoreOrStoreId, + ): Ids; + + /// useSortedRowIds.2 + >( + args: SortedRowIdsArgs, + storeOrStoreId?: StoreOrStoreId, + ): Ids; + }; + + /// useHasRow + useHasRow: >( + tableId: TableId, + rowId: Id, + storeOrStoreId?: StoreOrStoreId, + ) => boolean; + + /// useRow + useRow: >( + tableId: TableId, + rowId: Id, + storeOrStoreId?: StoreOrStoreId, + ) => Row; + + /// useRowState + useRowState: >( + tableId: TableId, + rowId: Id, + storeOrStoreId?: StoreOrStoreId, + ) => [Row, (row: Row) => void]; + + /// useCellIds + useCellIds: >( + tableId: TableId, + rowId: Id, + storeOrStoreId?: StoreOrStoreId, + ) => CellIdFromSchema[]; + + /// useHasCell + useHasCell: < + TableId extends TableIdFromSchema, + CellId extends CellIdFromSchema, + >( + tableId: TableId, + rowId: Id, + cellId: CellId, + storeOrStoreId?: StoreOrStoreId, + ) => boolean; + + /// useCell + useCell: < + TableId extends TableIdFromSchema, + CellId extends CellIdFromSchema, + >( + tableId: TableId, + rowId: Id, + cellId: CellId, + storeOrStoreId?: StoreOrStoreId, + ) => NoInfer>; + + /// useCellState + useCellState: < + TableId extends TableIdFromSchema, + CellId extends CellIdFromSchema, + >( + tableId: TableId, + rowId: Id, + cellId: CellId, + storeOrStoreId?: StoreOrStoreId, + ) => [ + CellOrUndefined, + (cell: Cell) => void, + ]; + + /// useHasValues + useHasValues: (storeOrStoreId?: StoreOrStoreId) => boolean; + + /// useValues + useValues: (storeOrStoreId?: StoreOrStoreId) => Values; + + /// useValuesState + useValuesState: ( + storeOrStoreId?: StoreOrStoreId, + ) => [Values, (values: Values) => void]; + + /// useValueIds + useValueIds: ( + storeOrStoreId?: StoreOrStoreId, + ) => ValueIdFromSchema[]; + + /// useHasValue + useHasValue: >( + valueId: ValueId, + storeOrStoreId?: StoreOrStoreId, + ) => boolean; + + /// useValue + useValue: >( + valueId: ValueId, + storeOrStoreId?: StoreOrStoreId, + ) => DefaultedValueFromSchema; + + /// useValueState + useValueState: >( + valueId: ValueId, + storeOrStoreId?: StoreOrStoreId, + ) => [ + value: DefaultedValueFromSchema, + setValue: (value: Value) => void, + ]; + + /// useSetTablesCallback + useSetTablesCallback: >( + getTables: ( + parameter: Parameter, + store: Store, + ) => NoInfer, + getTablesDeps?: DependencyList, + storeOrStoreId?: StoreOrStoreId, + then?: (store: Store, tables: SetTables) => void, + thenDeps?: DependencyList, + ) => ParameterizedCallback; + + /// useSetTableCallback + useSetTableCallback: < + Parameter, + TableId extends TableIdFromSchema, + SetTable = Table, + >( + tableId: TableId | GetId, + getTable: ( + parameter: Parameter, + store: Store, + ) => NoInfer, + getTableDeps?: DependencyList, + storeOrStoreId?: StoreOrStoreId, + then?: (store: Store, table: SetTable) => void, + thenDeps?: DependencyList, + ) => ParameterizedCallback; + + /// useSetRowCallback + useSetRowCallback: < + Parameter, + TableId extends TableIdFromSchema, + SetRow = Row, + >( + tableId: TableId | GetId, + rowId: Id | GetId, + getRow: (parameter: Parameter, store: Store) => NoInfer, + getRowDeps?: DependencyList, + storeOrStoreId?: StoreOrStoreId, + then?: (store: Store, row: SetRow) => void, + thenDeps?: DependencyList, + ) => ParameterizedCallback; + + /// useAddRowCallback + useAddRowCallback: < + Parameter, + TableId extends TableIdFromSchema, + AddRow = Row, + >( + tableId: TableId | GetId, + getRow: (parameter: Parameter, store: Store) => NoInfer, + getRowDeps?: DependencyList, + storeOrStoreId?: StoreOrStoreId, + then?: (rowId: Id | undefined, store: Store, row: AddRow) => void, + thenDeps?: DependencyList, + reuseRowIds?: boolean, + ) => ParameterizedCallback; + + /// useSetPartialRowCallback + useSetPartialRowCallback: < + Parameter, + TableId extends TableIdFromSchema, + SetPartialRow = Row, + >( + tableId: TableId | GetId, + rowId: Id | GetId, + getPartialRow: ( + parameter: Parameter, + store: Store, + ) => NoInfer, + getPartialRowDeps?: DependencyList, + storeOrStoreId?: StoreOrStoreId, + then?: (store: Store, partialRow: SetPartialRow) => void, + thenDeps?: DependencyList, + ) => ParameterizedCallback; + + /// useSetCellCallback + useSetCellCallback: < + Parameter, + TableId extends TableIdFromSchema, + CellId extends CellIdFromSchema, + SetOrMapCell = + | Cell + | MapCell, + >( + tableId: TableId | GetId, + rowId: Id | GetId, + cellId: CellId | GetId, + getCell: ( + parameter: Parameter, + store: Store, + ) => NoInfer, + getCellDeps?: DependencyList, + storeOrStoreId?: StoreOrStoreId, + then?: (store: Store, cell: SetOrMapCell) => void, + thenDeps?: DependencyList, + ) => ParameterizedCallback; + + /// useSetValuesCallback + useSetValuesCallback: >( + getValues: ( + parameter: Parameter, + store: Store, + ) => NoInfer, + getValuesDeps?: DependencyList, + storeOrStoreId?: StoreOrStoreId, + then?: (store: Store, values: SetValues) => void, + thenDeps?: DependencyList, + ) => ParameterizedCallback; + + /// useSetPartialValuesCallback + useSetPartialValuesCallback: < + Parameter, + SetPartialValues = Values, + >( + getPartialValues: ( + parameter: Parameter, + store: Store, + ) => NoInfer, + getPartialValuesDeps?: DependencyList, + storeOrStoreId?: StoreOrStoreId, + then?: (store: Store, partialValues: SetPartialValues) => void, + thenDeps?: DependencyList, + ) => ParameterizedCallback; + + /// useSetValueCallback + useSetValueCallback: < + Parameter, + ValueId extends ValueIdFromSchema, + SetOrMapValue = Value | MapValue, + >( + valueId: ValueId | GetId, + getValue: ( + parameter: Parameter, + store: Store, + ) => NoInfer, + getValueDeps?: DependencyList, + storeOrStoreId?: StoreOrStoreId, + then?: (store: Store, value: SetOrMapValue) => void, + thenDeps?: DependencyList, + ) => ParameterizedCallback; + + /// useDelTablesCallback + useDelTablesCallback: ( + storeOrStoreId?: StoreOrStoreId, + then?: (store: Store) => void, + thenDeps?: DependencyList, + ) => Callback; + + /// useDelTableCallback + useDelTableCallback: < + Parameter, + TableId extends TableIdFromSchema, + >( + tableId: TableId | GetId, + storeOrStoreId?: StoreOrStoreId, + then?: (store: Store) => void, + thenDeps?: DependencyList, + ) => ParameterizedCallback; + + /// useDelRowCallback + useDelRowCallback: >( + tableId: TableId | GetId, + rowId: Id | GetId, + storeOrStoreId?: StoreOrStoreId, + then?: (store: Store) => void, + thenDeps?: DependencyList, + ) => ParameterizedCallback; + + /// useDelCellCallback + useDelCellCallback: < + Parameter, + TableId extends TableIdFromSchema, + CellId extends CellIdFromSchema, + >( + tableId: TableId | GetId, + rowId: Id | GetId, + cellId: CellId | GetId, + forceDel?: boolean, + storeOrStoreId?: StoreOrStoreId, + then?: (store: Store) => void, + thenDeps?: DependencyList, + ) => ParameterizedCallback; + + /// useDelValuesCallback + useDelValuesCallback: ( + storeOrStoreId?: StoreOrStoreId, + then?: (store: Store) => void, + thenDeps?: DependencyList, + ) => Callback; + + /// useDelValueCallback + useDelValueCallback: < + Parameter, + ValueId extends ValueIdFromSchema, + >( + valueId: ValueId | GetId, + storeOrStoreId?: StoreOrStoreId, + then?: (store: Store) => void, + thenDeps?: DependencyList, + ) => ParameterizedCallback; + + /// useHasTablesListener + useHasTablesListener: ( + listener: HasTablesListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, + ) => void; + + /// useTablesListener + useTablesListener: ( + listener: TablesListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, + ) => void; + + /// useTableIdsListener + useTableIdsListener: ( + listener: TableIdsListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, + ) => void; + + /// useHasTableListener + useHasTableListener: < + TableIdOrNull extends TableIdFromSchema | null, + >( + tableId: TableIdOrNull, + listener: HasTableListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, + ) => void; + + /// useTableListener + useTableListener: < + TableIdOrNull extends TableIdFromSchema | null, + >( + tableId: TableIdOrNull, + listener: TableListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, + ) => void; + + /// useTableCellIdsListener + useTableCellIdsListener: < + TableIdOrNull extends TableIdFromSchema | null, + >( + tableId: TableIdOrNull, + listener: TableCellIdsListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, + ) => void; + + /// useHasTableCellListener + useHasTableCellListener: < + TableIdOrNull extends TableIdFromSchema | null, + CellIdOrNull extends + | (TableIdOrNull extends TableIdFromSchema + ? CellIdFromSchema + : AllCellIdFromSchema) + | null, + >( + tableId: TableIdOrNull, + cellId: CellIdOrNull, + listener: HasTableCellListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, + ) => void; + + /// useRowCountListener + useRowCountListener: < + TableIdOrNull extends TableIdFromSchema | null, + >( + tableId: TableIdOrNull, + listener: RowCountListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, + ) => void; + + /// useRowIdsListener + useRowIdsListener: < + TableIdOrNull extends TableIdFromSchema | null, + >( + tableId: TableIdOrNull, + listener: RowIdsListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, + ) => void; + + useSortedRowIdsListener: { + /// useSortedRowIdsListener + < + TableId extends TableIdFromSchema, + CellIdOrUndefined extends + | CellIdFromSchema + | undefined, + >( + tableId: TableId, + cellId: CellIdOrUndefined, + descending: boolean, + offset: number, + limit: number | undefined, + listener: SortedRowIdsListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, + ): void; + + /// useSortedRowIdsListener.2 + < + TableId extends TableIdFromSchema, + CellIdOrUndefined extends + | CellIdFromSchema + | undefined, + >( + args: SortedRowIdsArgs, + listener: SortedRowIdsListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, + ): void; + }; + + /// useHasRowListener + useHasRowListener: < + TableIdOrNull extends TableIdFromSchema | null, + RowIdOrNull extends IdOrNull, + >( + tableId: TableIdOrNull, + rowId: RowIdOrNull, + listener: HasRowListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, + ) => void; + + /// useRowListener + useRowListener: < + TableIdOrNull extends TableIdFromSchema | null, + RowIdOrNull extends IdOrNull, + >( + tableId: TableIdOrNull, + rowId: RowIdOrNull, + listener: RowListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, + ) => void; + + /// useCellIdsListener + useCellIdsListener: < + TableIdOrNull extends TableIdFromSchema | null, + RowIdOrNull extends IdOrNull, + >( + tableId: TableIdOrNull, + rowId: RowIdOrNull, + listener: CellIdsListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, + ) => void; + + /// useHasCellListener + useHasCellListener: < + TableIdOrNull extends TableIdFromSchema | null, + RowIdOrNull extends IdOrNull, + CellIdOrNull extends + | (TableIdOrNull extends TableIdFromSchema + ? CellIdFromSchema + : AllCellIdFromSchema) + | null, + >( + tableId: TableIdOrNull, + rowId: RowIdOrNull, + cellId: CellIdOrNull, + listener: HasCellListener< + Schemas, + TableIdOrNull, + RowIdOrNull, + CellIdOrNull + >, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, + ) => void; + + /// useCellListener + useCellListener: < + TableIdOrNull extends TableIdFromSchema | null, + RowIdOrNull extends IdOrNull, + CellIdOrNull extends + | (TableIdOrNull extends TableIdFromSchema + ? CellIdFromSchema + : AllCellIdFromSchema) + | null, + >( + tableId: TableIdOrNull, + rowId: RowIdOrNull, + cellId: CellIdOrNull, + listener: CellListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, + ) => void; + + /// useHasValuesListener + useHasValuesListener: ( + listener: HasValuesListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, + ) => void; + + /// useValuesListener + useValuesListener: ( + listener: ValuesListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, + ) => void; + + /// useValueIdsListener + useValueIdsListener: ( + listener: ValueIdsListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, + ) => void; + + /// useHasValueListener + useHasValueListener: < + ValueIdOrNull extends ValueIdFromSchema | null, + >( + valueId: ValueIdOrNull, + listener: HasValueListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, + ) => void; + + /// useValueListener + useValueListener: < + ValueIdOrNull extends ValueIdFromSchema | null, + >( + valueId: ValueIdOrNull, + listener: ValueListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, + ) => void; + + /// useStartTransactionListener + useStartTransactionListener: ( + listener: TransactionListener, + listenerDeps?: DependencyList, + storeOrStoreId?: StoreOrStoreId, + ) => void; + + /// useWillFinishTransactionListener + useWillFinishTransactionListener: ( + listener: TransactionListener, + listenerDeps?: DependencyList, + storeOrStoreId?: StoreOrStoreId, + ) => void; + + /// useDidFinishTransactionListener + useDidFinishTransactionListener: ( + listener: TransactionListener, + listenerDeps?: DependencyList, + storeOrStoreId?: StoreOrStoreId, + ) => void; + + /// useCreateMetrics + useCreateMetrics: ( + store: Store | undefined, + create: (store: Store) => Metrics, + createDeps?: DependencyList, + ) => Metrics | undefined; + + /// useMetricsIds + useMetricsIds: () => Ids; + + /// useMetrics + useMetrics: (id?: Id) => Metrics | undefined; + + /// useMetricsOrMetricsById + useMetricsOrMetricsById: ( + metricsOrMetricsId?: MetricsOrMetricsId, + ) => Metrics | undefined; + + // useProvideMetrics + useProvideMetrics: (metricsId: Id, metrics: Metrics) => void; + + /// useMetricIds + useMetricIds(metricsOrMetricsId?: MetricsOrMetricsId): Ids; + + /// useMetric + useMetric: ( + metricId: Id, + metricsOrMetricsId?: MetricsOrMetricsId, + ) => number | undefined; + + /// useMetricListener + useMetricListener: ( + metricId: IdOrNull, + listener: MetricListener, + listenerDeps?: DependencyList, + metricsOrMetricsId?: MetricsOrMetricsId, + ) => void; + + /// useCreateIndexes + useCreateIndexes: ( + store: Store | undefined, + create: (store: Store) => Indexes, + createDeps?: DependencyList, + ) => Indexes | undefined; + + /// useIndexesIds + useIndexesIds: () => Ids; + + /// useIndexes + useIndexes: (id?: Id) => Indexes | undefined; + + /// useIndexesOrIndexesById + useIndexesOrIndexesById: ( + indexesOrIndexesId?: IndexesOrIndexesId, + ) => Indexes | undefined; + + // useProvideIndexes + useProvideIndexes: (indexesId: Id, indexes: Indexes) => void; + + /// useIndexIds + useIndexIds(indexesOrIndexesId?: IndexesOrIndexesId): Ids; + + /// useSliceIds + useSliceIds: ( + indexId: Id, + indexesOrIndexesId?: IndexesOrIndexesId, + ) => Ids; + + /// useSliceRowIds + useSliceRowIds: ( + indexId: Id, + sliceId: Id, + indexesOrIndexesId?: IndexesOrIndexesId, + ) => Ids; + + /// useSliceIdsListener + useSliceIdsListener: ( + indexId: IdOrNull, + listener: SliceIdsListener, + listenerDeps?: DependencyList, + indexesOrIndexesId?: IndexesOrIndexesId, + ) => void; + + /// useSliceRowIdsListener + useSliceRowIdsListener: ( + indexId: IdOrNull, + sliceId: IdOrNull, + listener: SliceRowIdsListener, + listenerDeps?: DependencyList, + indexesOrIndexesId?: IndexesOrIndexesId, + ) => void; + + /// useCreateRelationships + useCreateRelationships: ( + store: Store | undefined, + create: (store: Store) => Relationships, + createDeps?: DependencyList, + ) => Relationships | undefined; + + /// useRelationshipsIds + useRelationshipsIds: () => Ids; + + /// useRelationships + useRelationships: (id?: Id) => Relationships | undefined; + + /// useRelationshipsOrRelationshipsById + useRelationshipsOrRelationshipsById: ( + relationshipsOrRelationshipsId?: RelationshipsOrRelationshipsId, + ) => Relationships | undefined; + + // useProvideRelationships + useProvideRelationships: ( + relationshipsId: Id, + relationships: Relationships, + ) => void; + + /// useRelationshipIds + useRelationshipIds( + relationshipsOrRelationshipsId?: RelationshipsOrRelationshipsId, + ): Ids; + + /// useRemoteRowId + useRemoteRowId: ( + relationshipId: Id, + localRowId: Id, + relationshipsOrRelationshipsId?: RelationshipsOrRelationshipsId, + ) => Id | undefined; + + /// useLocalRowIds + useLocalRowIds: ( + relationshipId: Id, + remoteRowId: Id, + relationshipsOrRelationshipsId?: RelationshipsOrRelationshipsId, + ) => Ids; + + /// useLinkedRowIds + useLinkedRowIds: ( + relationshipId: Id, + firstRowId: Id, + relationshipsOrRelationshipsId?: RelationshipsOrRelationshipsId, + ) => Ids; + + /// useRemoteRowIdListener + useRemoteRowIdListener: ( + relationshipId: IdOrNull, + localRowId: IdOrNull, + listener: RemoteRowIdListener, + listenerDeps?: DependencyList, + relationshipsOrRelationshipsId?: RelationshipsOrRelationshipsId, + ) => void; + + /// useLocalRowIdsListener + useLocalRowIdsListener: ( + relationshipId: IdOrNull, + remoteRowId: IdOrNull, + listener: LocalRowIdsListener, + listenerDeps?: DependencyList, + relationshipsOrRelationshipsId?: RelationshipsOrRelationshipsId, + ) => void; + + /// useLinkedRowIdsListener + useLinkedRowIdsListener: ( + relationshipId: Id, + firstRowId: Id, + listener: LinkedRowIdsListener, + listenerDeps?: DependencyList, + relationshipsOrRelationshipsId?: RelationshipsOrRelationshipsId, + ) => void; + + /// useCreateQueries + useCreateQueries: ( + store: Store | undefined, + create: (store: Store) => Queries, + createDeps?: DependencyList, + ) => Queries | undefined; + + /// useQueriesIds + useQueriesIds: () => Ids; + + /// useQueries + useQueries: (id?: Id) => Queries | undefined; + + /// useQueriesOrQueriesById + useQueriesOrQueriesById: ( + queriesOrQueriesId?: QueriesOrQueriesId, + ) => Queries | undefined; + + // useProvideQueries + useProvideQueries: (queriesId: Id, queries: Queries) => void; + + /// useQueryIds + useQueryIds(queriesOrQueriesId?: QueriesOrQueriesId): Ids; + + /// useResultTable + useResultTable: ( + queryId: Id, + queriesOrQueriesId?: QueriesOrQueriesId, + ) => ResultTable; + + /// useResultTableCellIds + useResultTableCellIds: ( + queryId: Id, + queriesOrQueriesId?: QueriesOrQueriesId, + ) => Ids; + + /// useResultRowCount + useResultRowCount: ( + queryId: Id, + queriesOrQueriesId?: QueriesOrQueriesId, + ) => number; + + /// useResultRowIds + useResultRowIds: ( + queryId: Id, + queriesOrQueriesId?: QueriesOrQueriesId, + ) => Ids; + + /// useResultSortedRowIds + useResultSortedRowIds: ( + queryId: Id, + cellId?: Id, + descending?: boolean, + offset?: number, + limit?: number, + queriesOrQueriesId?: QueriesOrQueriesId, + ) => Ids; + + /// useResultRow + useResultRow: ( + queryId: Id, + rowId: Id, + queriesOrQueriesId?: QueriesOrQueriesId, + ) => ResultRow; + + /// useResultCellIds + useResultCellIds: ( + queryId: Id, + rowId: Id, + queriesOrQueriesId?: QueriesOrQueriesId, + ) => Ids; + + /// useResultCell + useResultCell: ( + queryId: Id, + rowId: Id, + cellId: Id, + queriesOrQueriesId?: QueriesOrQueriesId, + ) => ResultCell | undefined; + + /// useResultTableListener + useResultTableListener: ( + queryId: IdOrNull, + listener: ResultTableListener, + listenerDeps?: DependencyList, + queriesOrQueriesId?: QueriesOrQueriesId, + ) => void; + + /// useResultTableCellIdsListener + useResultTableCellIdsListener: ( + queryId: IdOrNull, + listener: ResultTableCellIdsListener, + listenerDeps?: DependencyList, + queriesOrQueriesId?: QueriesOrQueriesId, + ) => void; + + /// useResultRowCountListener + useResultRowCountListener: ( + queryId: IdOrNull, + listener: ResultRowCountListener, + listenerDeps?: DependencyList, + queriesOrQueriesId?: QueriesOrQueriesId, + ) => void; + + /// useResultRowIdsListener + useResultRowIdsListener: ( + queryId: IdOrNull, + listener: ResultRowIdsListener, + listenerDeps?: DependencyList, + queriesOrQueriesId?: QueriesOrQueriesId, + ) => void; + + /// useResultSortedRowIdsListener + useResultSortedRowIdsListener: ( + queryId: Id, + cellId: Id | undefined, + descending: boolean, + offset: number, + limit: number | undefined, + listener: ResultSortedRowIdsListener, + listenerDeps?: DependencyList, + queriesOrQueriesId?: QueriesOrQueriesId, + ) => void; + + /// useResultRowListener + useResultRowListener: ( + queryId: IdOrNull, + rowId: IdOrNull, + listener: ResultRowListener, + listenerDeps?: DependencyList, + queriesOrQueriesId?: QueriesOrQueriesId, + ) => void; + + /// useResultCellIdsListener + useResultCellIdsListener: ( + queryId: IdOrNull, + rowId: IdOrNull, + listener: ResultCellIdsListener, + listenerDeps?: DependencyList, + queriesOrQueriesId?: QueriesOrQueriesId, + ) => void; + + /// useResultCellListener + useResultCellListener: ( + queryId: IdOrNull, + rowId: IdOrNull, + cellId: IdOrNull, + listener: ResultCellListener, + listenerDeps?: DependencyList, + queriesOrQueriesId?: QueriesOrQueriesId, + ) => void; + + /// useParamValues + useParamValues: ( + queryId: Id, + queriesOrQueriesId?: QueriesOrQueriesId, + ) => ParamValues; + + /// useParamValuesState + useParamValuesState: ( + queryId: Id, + queriesOrQueriesId?: QueriesOrQueriesId, + ) => [ParamValues, (paramValues: ParamValues) => void]; + + /// useParamValue + useParamValue: ( + queryId: Id, + paramId: Id, + queriesOrQueriesId?: QueriesOrQueriesId, + ) => ParamValue | undefined; + + /// useParamValueState + useParamValueState: ( + queryId: Id, + paramId: Id, + queriesOrQueriesId?: QueriesOrQueriesId, + ) => [ParamValue | undefined, (paramValue: ParamValue) => void]; + + /// useParamValuesListener + useParamValuesListener: ( + queryId: IdOrNull, + listener: ParamValuesListener, + listenerDeps?: DependencyList, + queriesOrQueriesId?: QueriesOrQueriesId, + ) => void; + + /// useParamValueListener + useParamValueListener: ( + queryId: IdOrNull, + paramId: IdOrNull, + listener: ParamValueListener, + listenerDeps?: DependencyList, + queriesOrQueriesId?: QueriesOrQueriesId, + ) => void; + + /// useSetParamValueCallback + useSetParamValueCallback: ( + queryId: Id | GetId, + paramId: Id | GetId, + getParamValue: ( + parameter: Parameter, + queries: Queries, + ) => ParamValue, + getParamValueDeps?: DependencyList, + queriesOrQueriesId?: QueriesOrQueriesId, + then?: (queries: Queries, paramValue: ParamValue) => void, + thenDeps?: DependencyList, + ) => ParameterizedCallback; + + /// useSetParamValuesCallback + useSetParamValuesCallback: ( + queryId: Id | GetId, + getParamValues: ( + parameter: Parameter, + queries: Queries, + ) => ParamValues, + getParamValuesDeps?: DependencyList, + queriesOrQueriesId?: QueriesOrQueriesId, + then?: (queries: Queries, paramValues: ParamValues) => void, + thenDeps?: DependencyList, + ) => ParameterizedCallback; + + /// useCreateCheckpoints + useCreateCheckpoints: ( + store: Store | undefined, + create: (store: Store) => Checkpoints, + createDeps?: DependencyList, + ) => Checkpoints | undefined; + + /// useCheckpointsIds + useCheckpointsIds: () => Ids; + + /// useCheckpoints + useCheckpoints: (id?: Id) => Checkpoints | undefined; + + /// useCheckpointsOrCheckpointsById + useCheckpointsOrCheckpointsById: ( + checkpointsOrCheckpointsId?: CheckpointsOrCheckpointsId, + ) => Checkpoints | undefined; + + // useProvideCheckpoints + useProvideCheckpoints: ( + checkpointsId: Id, + checkpoints: Checkpoints, + ) => void; + + /// useCheckpointIds + useCheckpointIds: ( + checkpointsOrCheckpointsId?: CheckpointsOrCheckpointsId, + ) => CheckpointIds; + + /// useCheckpoint + useCheckpoint: ( + checkpointId: Id, + checkpointsOrCheckpointsId?: CheckpointsOrCheckpointsId, + ) => string | undefined; + + /// useSetCheckpointCallback + useSetCheckpointCallback: ( + getCheckpoint?: (parameter: Parameter) => string, + getCheckpointDeps?: DependencyList, + checkpointsOrCheckpointsId?: CheckpointsOrCheckpointsId, + then?: ( + checkpointId: Id, + checkpoints: Checkpoints, + label?: string, + ) => void, + thenDeps?: DependencyList, + ) => ParameterizedCallback; + + /// useGoBackwardCallback + useGoBackwardCallback: ( + checkpointsOrCheckpointsId?: CheckpointsOrCheckpointsId, + ) => Callback; + + /// useGoForwardCallback + useGoForwardCallback: ( + checkpointsOrCheckpointsId?: CheckpointsOrCheckpointsId, + ) => Callback; + + /// useGoToCallback + useGoToCallback: ( + getCheckpointId: (parameter: Parameter) => Id, + getCheckpointIdDeps?: DependencyList, + checkpointsOrCheckpointsId?: CheckpointsOrCheckpointsId, + then?: (checkpoints: Checkpoints, checkpointId: Id) => void, + thenDeps?: DependencyList, + ) => ParameterizedCallback; + + /// useUndoInformation + useUndoInformation: ( + checkpointsOrCheckpointsId?: CheckpointsOrCheckpointsId, + ) => UndoOrRedoInformation; + + /// useRedoInformation + useRedoInformation: ( + checkpointsOrCheckpointsId?: CheckpointsOrCheckpointsId, + ) => UndoOrRedoInformation; + + /// useCheckpointIdsListener + useCheckpointIdsListener: ( + listener: CheckpointIdsListener, + listenerDeps?: DependencyList, + checkpointsOrCheckpointsId?: CheckpointsOrCheckpointsId, + ) => void; + + /// useCheckpointListener + useCheckpointListener: ( + checkpointId: IdOrNull, + listener: CheckpointListener, + listenerDeps?: DependencyList, + checkpointsOrCheckpointsId?: CheckpointsOrCheckpointsId, + ) => void; + + /// useCreatePersister + useCreatePersister: < + Persist extends Persists, + PersisterOrUndefined extends Persister | undefined, + >( + store: PersistedStore | undefined, + create: ( + store: PersistedStore, + ) => PersisterOrUndefined | Promise, + createDeps?: DependencyList, + then?: (persister: Persister) => Promise, + thenDeps?: DependencyList, + destroy?: (persister: Persister) => void, + destroyDeps?: DependencyList, + ) => PersisterOrUndefined; + + /// usePersisterIds + usePersisterIds: () => Ids; + + /// usePersister + usePersister: ( + id?: Id, + ) => Persister | undefined; + + /// usePersisterOrPersisterById + usePersisterOrPersisterById: ( + persisterOrPersisterId?: PersisterOrPersisterId, + ) => Persister | undefined; + + // useProvidePersister + useProvidePersister: ( + persisterId: Id, + persister: AnyPersister | undefined, + ) => void; + + /// usePersisterStatus + usePersisterStatus: ( + persisterOrPersisterId?: PersisterOrPersisterId, + ) => Status; + + /// usePersisterStatusListener + usePersisterStatusListener: ( + listener: StatusListener, + listenerDeps?: DependencyList, + persisterOrPersisterId?: PersisterOrPersisterId, + ) => void; + + /// useCreateSynchronizer + useCreateSynchronizer: < + SynchronizerOrUndefined extends Synchronizer | undefined, + >( + store: MergeableStore | undefined, + create: ( + store: MergeableStore, + ) => Promise, + createDeps?: DependencyList, + destroy?: (synchronizer: Synchronizer) => void, + destroyDeps?: DependencyList, + ) => SynchronizerOrUndefined; + + /// useSynchronizerIds + useSynchronizerIds: () => Ids; + + /// useSynchronizer + useSynchronizer: (id?: Id) => Synchronizer | undefined; + + /// useSynchronizerOrSynchronizerById + useSynchronizerOrSynchronizerById: ( + synchronizerOrSynchronizerId?: SynchronizerOrSynchronizerId, + ) => Synchronizer | undefined; + + // useProvideSynchronizer + useProvideSynchronizer: ( + synchronizerId: Id, + synchronizer: Synchronizer | undefined, + ) => void; + + /// useSynchronizerStatus + useSynchronizerStatus: ( + synchronizerOrSynchronizerId?: SynchronizerOrSynchronizerId, + ) => Status; + + /// useSynchronizerStatusListener + useSynchronizerStatusListener: ( + listener: StatusListener, + listenerDeps?: DependencyList, + synchronizerOrSynchronizerId?: SynchronizerOrSynchronizerId, + ) => void; + + /// ExtraProps + ExtraProps: ExtraProps; + + /// TablesProps + TablesProps: TablesProps; + + /// TableProps + TableProps: TableProps; + + /// SortedTableProps + SortedTableProps: SortedTableProps; + + /// RowProps + RowProps: RowProps; + + /// CellProps + CellProps: CellProps; + + /// ValuesProps + ValuesProps: ValuesProps; + + /// ValueProps + ValueProps: ValueProps; + + /// MetricProps + MetricProps: MetricProps; + + /// IndexProps + IndexProps: IndexProps; + + /// SliceProps + SliceProps: SliceProps; + + /// RemoteRowProps + RemoteRowProps: RemoteRowProps; + + /// LocalRowsProps + LocalRowsProps: LocalRowsProps; + + /// LinkedRowsProps + LinkedRowsProps: LinkedRowsProps; + + /// ResultTableProps + ResultTableProps: ResultTableProps; + + /// ResultSortedTableProps + ResultSortedTableProps: ResultSortedTableProps; + + /// ResultRowProps + ResultRowProps: ResultRowProps; + + /// ResultCellProps + ResultCellProps: ResultCellProps; + + /// CheckpointProps + CheckpointProps: CheckpointProps; + + /// BackwardCheckpointsProps + BackwardCheckpointsProps: BackwardCheckpointsProps; + + /// CurrentCheckpointProps + CurrentCheckpointProps: CurrentCheckpointProps; + + /// ForwardCheckpointsProps + ForwardCheckpointsProps: ForwardCheckpointsProps; + + /// ProviderProps + ProviderProps: ProviderProps; + + /// ComponentReturnType + ComponentReturnType: ComponentReturnType; + + /// Provider + Provider: ( + props: ProviderProps & {children: JSXElement}, + ) => ComponentReturnType; + + /// CellView + CellView: (props: CellProps) => ComponentReturnType; + + /// RowView + RowView: (props: RowProps) => ComponentReturnType; + + /// SortedTableView + SortedTableView: (props: SortedTableProps) => ComponentReturnType; + + /// TableView + TableView: (props: TableProps) => ComponentReturnType; + + /// TablesView + TablesView: (props: TablesProps) => ComponentReturnType; + + /// ValueView + ValueView: (props: ValueProps) => ComponentReturnType; + + /// ValuesView + ValuesView: (props: ValuesProps) => ComponentReturnType; + + /// MetricView + MetricView: (props: MetricProps) => ComponentReturnType; + + /// SliceView + SliceView: (props: SliceProps) => ComponentReturnType; + + /// IndexView + IndexView: (props: IndexProps) => ComponentReturnType; + + /// RemoteRowView + RemoteRowView: (props: RemoteRowProps) => ComponentReturnType; + + /// LocalRowsView + LocalRowsView: (props: LocalRowsProps) => ComponentReturnType; + + /// LinkedRowsView + LinkedRowsView: (props: LinkedRowsProps) => ComponentReturnType; + + /// ResultCellView + ResultCellView: (props: ResultCellProps) => ComponentReturnType; + + /// ResultRowView + ResultRowView: (props: ResultRowProps) => ComponentReturnType; + + /// ResultSortedTableView + ResultSortedTableView: ( + props: ResultSortedTableProps, + ) => ComponentReturnType; + + /// ResultTableView + ResultTableView: (props: ResultTableProps) => ComponentReturnType; + + /// CheckpointView + CheckpointView: (props: CheckpointProps) => ComponentReturnType; + + /// BackwardCheckpointsView + BackwardCheckpointsView: ( + props: BackwardCheckpointsProps, + ) => ComponentReturnType; + + /// CurrentCheckpointView + CurrentCheckpointView: ( + props: CurrentCheckpointProps, + ) => ComponentReturnType; + + /// ForwardCheckpointsView + ForwardCheckpointsView: ( + props: ForwardCheckpointsProps, + ) => ComponentReturnType; +}; diff --git a/src/common/solid.ts b/src/common/solid.ts new file mode 100644 index 00000000000..2ec952eb86d --- /dev/null +++ b/src/common/solid.ts @@ -0,0 +1,39 @@ +import type {Id, Ids} from '../@types/common/index.d.ts'; +import type {Indexes} from '../@types/indexes/index.d.ts'; +import type {Relationships} from '../@types/relationships/index.d.ts'; +import type {Store} from '../@types/store/index.d.ts'; +import {isFunction, isUndefined} from './other.ts'; + +export type DependencyList = ReadonlyArray; + +export const getValue = (value: Value | (() => Value)): Value => + (isFunction(value) ? (value as () => Value)() : value) as Value; + +export const getProps = ( + getProps: ((...ids: Ids) => Props) | undefined, + ...ids: Ids +): Props => (isUndefined(getProps) ? ({} as Props) : getProps(...ids)); + +export const getRelationshipsStoreTableIds = ( + relationships: Relationships | undefined, + relationshipId: Id, +): [ + Relationships | undefined, + Store | undefined, + Id | undefined, + Id | undefined, +] => [ + relationships, + relationships?.getStore(), + relationships?.getLocalTableId(relationshipId), + relationships?.getRemoteTableId(relationshipId), +]; + +export const getIndexStoreTableId = ( + indexes: Indexes | undefined, + indexId: Id, +): [Indexes | undefined, Store | undefined, Id | undefined] => [ + indexes, + indexes?.getStore(), + indexes?.getTableId(indexId), +]; diff --git a/src/ui-solid/BackwardCheckpointsView.tsx b/src/ui-solid/BackwardCheckpointsView.tsx new file mode 100644 index 00000000000..fbf6291f6b9 --- /dev/null +++ b/src/ui-solid/BackwardCheckpointsView.tsx @@ -0,0 +1,5 @@ +/* @jsxImportSource solid-js */ +import {getUseCheckpointView} from './common/index.tsx'; + +export const BackwardCheckpointsView = + getUseCheckpointView((checkpointIds) => checkpointIds[0]); \ No newline at end of file diff --git a/src/ui-solid/CellView.tsx b/src/ui-solid/CellView.tsx new file mode 100644 index 00000000000..9df4066991e --- /dev/null +++ b/src/ui-solid/CellView.tsx @@ -0,0 +1,25 @@ +/* @jsxImportSource solid-js */ +import type { + CellProps, +} from '../@types/ui-solid/index.d.ts'; +import {getValue} from '../common/solid.ts'; +import {EMPTY_STRING} from '../common/strings.ts'; +import {wrap} from './common/wrap.tsx'; +import {useCell} from './hooks.ts'; + +export const CellView = ({ + tableId, + rowId, + cellId, + store, + debugIds, +}: CellProps): any => { + const cell = useCell(tableId, rowId, cellId, store) as any; + return () => + wrap( + EMPTY_STRING + ((getValue(cell) as any) ?? EMPTY_STRING), + undefined, + debugIds, + cellId, + ); +}; \ No newline at end of file diff --git a/src/ui-solid/CheckpointView.tsx b/src/ui-solid/CheckpointView.tsx new file mode 100644 index 00000000000..025e04179f5 --- /dev/null +++ b/src/ui-solid/CheckpointView.tsx @@ -0,0 +1,23 @@ +/* @jsxImportSource solid-js */ +import type { + CheckpointProps, +} from '../@types/ui-solid/index.d.ts'; +import {getValue} from '../common/solid.ts'; +import {EMPTY_STRING} from '../common/strings.ts'; +import {wrap} from './common/wrap.tsx'; +import {useCheckpoint} from './hooks.ts'; + +export const CheckpointView = ({ + checkpoints, + checkpointId, + debugIds, +}: CheckpointProps): any => { + const checkpoint = useCheckpoint(checkpointId, checkpoints) as any; + return () => + wrap( + (getValue(checkpoint) as any) ?? EMPTY_STRING, + undefined, + debugIds, + checkpointId, + ); +}; \ No newline at end of file diff --git a/src/ui-solid/CurrentCheckpointView.tsx b/src/ui-solid/CurrentCheckpointView.tsx new file mode 100644 index 00000000000..142a72ce128 --- /dev/null +++ b/src/ui-solid/CurrentCheckpointView.tsx @@ -0,0 +1,8 @@ +/* @jsxImportSource solid-js */ +import {isUndefined} from '../common/other.ts'; +import {getUseCheckpointView} from './common/index.tsx'; + +export const CurrentCheckpointView = + getUseCheckpointView((checkpointIds) => + isUndefined(checkpointIds[1]) ? [] : [checkpointIds[1]], + ); \ No newline at end of file diff --git a/src/ui-solid/ForwardCheckpointsView.tsx b/src/ui-solid/ForwardCheckpointsView.tsx new file mode 100644 index 00000000000..ca705868af7 --- /dev/null +++ b/src/ui-solid/ForwardCheckpointsView.tsx @@ -0,0 +1,5 @@ +/* @jsxImportSource solid-js */ +import {getUseCheckpointView} from './common/index.tsx'; + +export const ForwardCheckpointsView = + getUseCheckpointView((checkpointIds) => checkpointIds[2]); \ No newline at end of file diff --git a/src/ui-solid/IndexView.tsx b/src/ui-solid/IndexView.tsx new file mode 100644 index 00000000000..9ff8d5a5b7e --- /dev/null +++ b/src/ui-solid/IndexView.tsx @@ -0,0 +1,36 @@ +/* @jsxImportSource solid-js */ +import type { + IndexProps, +} from '../@types/ui-solid/index.d.ts'; +import type {Id} from '../@types/index.d.ts'; +import {arrayMap} from '../common/array.ts'; +import {getProps, getValue} from '../common/solid.ts'; +import {wrap} from './common/wrap.tsx'; +import {useSliceIds} from './hooks.ts'; +import {SliceView} from './SliceView.tsx'; + +export const IndexView = ({ + indexId, + indexes, + sliceComponent: Slice = SliceView, + getSliceComponentProps, + separator, + debugIds, +}: IndexProps): any => { + const sliceIds = useSliceIds(indexId, indexes) as any; + return () => + wrap( + arrayMap(getValue(sliceIds) as Id[], (sliceId: Id) => ( + + )), + separator, + debugIds, + indexId, + ); +}; diff --git a/src/ui-solid/LinkedRowsView.tsx b/src/ui-solid/LinkedRowsView.tsx new file mode 100644 index 00000000000..80979efe9ee --- /dev/null +++ b/src/ui-solid/LinkedRowsView.tsx @@ -0,0 +1,10 @@ +/* @jsxImportSource solid-js */ +import type { + LinkedRowsProps, +} from '../@types/ui-solid/index.d.ts'; +import {useComponentPerRow} from './common/index.tsx'; +import {useLinkedRowIds} from './hooks.ts'; + +export const LinkedRowsView = ( + props: LinkedRowsProps, +): any => useComponentPerRow(props as any, useLinkedRowIds as any, props.firstRowId); diff --git a/src/ui-solid/LocalRowsView.tsx b/src/ui-solid/LocalRowsView.tsx new file mode 100644 index 00000000000..eeb66d857c6 --- /dev/null +++ b/src/ui-solid/LocalRowsView.tsx @@ -0,0 +1,10 @@ +/* @jsxImportSource solid-js */ +import type { + LocalRowsProps, +} from '../@types/ui-solid/index.d.ts'; +import {useComponentPerRow} from './common/index.tsx'; +import {useLocalRowIds} from './hooks.ts'; + +export const LocalRowsView = ( + props: LocalRowsProps, +): any => useComponentPerRow(props as any, useLocalRowIds as any, props.remoteRowId); diff --git a/src/ui-solid/MetricView.tsx b/src/ui-solid/MetricView.tsx new file mode 100644 index 00000000000..7f8ebb56a1c --- /dev/null +++ b/src/ui-solid/MetricView.tsx @@ -0,0 +1,23 @@ +/* @jsxImportSource solid-js */ +import type { + MetricProps, +} from '../@types/ui-solid/index.d.ts'; +import {getValue} from '../common/solid.ts'; +import {EMPTY_STRING} from '../common/strings.ts'; +import {wrap} from './common/wrap.tsx'; +import {useMetric} from './hooks.ts'; + +export const MetricView = ({ + metricId, + metrics, + debugIds, +}: MetricProps): any => { + const metric = useMetric(metricId, metrics) as any; + return () => + wrap( + (getValue(metric) as any) ?? EMPTY_STRING, + undefined, + debugIds, + metricId, + ); +}; \ No newline at end of file diff --git a/src/ui-solid/Provider.tsx b/src/ui-solid/Provider.tsx new file mode 100644 index 00000000000..02750b6432c --- /dev/null +++ b/src/ui-solid/Provider.tsx @@ -0,0 +1,148 @@ +/* @jsxImportSource solid-js */ +import type {Accessor, JSXElement} from 'solid-js'; +import {createMemo, createSignal, useContext} from 'solid-js'; +import type {Id} from '../@types/index.d.ts'; +import type {ProviderProps} from '../@types/ui-solid/index.d.ts'; +import {arrayNew, arrayWith} from '../common/array.ts'; +import {objDel, objGet, objHas} from '../common/obj.ts'; +import {ExtraThingsById, ThingsById} from './common/index.tsx'; +import {Context, ContextValue, ThingsByOffset} from './context.ts'; + +export type Offsets = + | typeof OFFSET_STORE + | typeof OFFSET_METRICS + | typeof OFFSET_INDEXES + | typeof OFFSET_RELATIONSHIPS + | typeof OFFSET_QUERIES + | typeof OFFSET_CHECKPOINTS + | typeof OFFSET_PERSISTER + | typeof OFFSET_SYNCHRONIZER; + +export const OFFSET_STORE = 0; +export const OFFSET_METRICS = 1; +export const OFFSET_INDEXES = 2; +export const OFFSET_RELATIONSHIPS = 3; +export const OFFSET_QUERIES = 4; +export const OFFSET_CHECKPOINTS = 5; +export const OFFSET_PERSISTER = 6; +export const OFFSET_SYNCHRONIZER = 7; + +const mergeParentThings = ( + offset: Offset, + parentValue: ContextValue, + defaultThing: ThingsByOffset[Offset] | undefined, + thingsById: ThingsById[Offset] | undefined, + extraThingsById: ExtraThingsById, +): [ThingsByOffset[Offset] | undefined, ThingsById[Offset]] => [ + defaultThing ?? + (parentValue[offset * 2] as ThingsByOffset[Offset] | undefined), + { + ...parentValue[offset * 2 + 1], + ...thingsById, + ...extraThingsById[offset], + }, +]; + +const EMPTY_CONTEXT = () => [] as ContextValue; + +export const Provider = ( + props: ProviderProps & {readonly children: JSXElement}, +): any => { + const parentValue = + useContext(Context) ?? (EMPTY_CONTEXT as Accessor); + const [extraThingsById, setExtraThingsById] = createSignal( + arrayNew(8, () => ({})) as ExtraThingsById, + ); + + const addExtraThingById = ( + thingOffset: Offset, + id: Id, + thing: ThingsByOffset[Offset], + ): void => { + setExtraThingsById((extraThingsById) => + objGet(extraThingsById[thingOffset] as any, id) == thing + ? extraThingsById + : (arrayWith(extraThingsById, thingOffset, { + ...extraThingsById[thingOffset], + [id]: thing, + } as any) as ExtraThingsById), + ); + }; + + const delExtraThingById = (thingOffset: Offsets, id: Id): void => { + setExtraThingsById((extraThingsById) => + !objHas(extraThingsById[thingOffset], id) + ? extraThingsById + : (arrayWith( + extraThingsById, + thingOffset, + objDel(extraThingsById[thingOffset] as any, id), + ) as ExtraThingsById), + ); + }; + + const contextValue = createMemo(() => [ + ...mergeParentThings( + OFFSET_STORE, + parentValue(), + props.store, + props.storesById, + extraThingsById(), + ), + ...mergeParentThings( + OFFSET_METRICS, + parentValue(), + props.metrics, + props.metricsById, + extraThingsById(), + ), + ...mergeParentThings( + OFFSET_INDEXES, + parentValue(), + props.indexes, + props.indexesById, + extraThingsById(), + ), + ...mergeParentThings( + OFFSET_RELATIONSHIPS, + parentValue(), + props.relationships, + props.relationshipsById, + extraThingsById(), + ), + ...mergeParentThings( + OFFSET_QUERIES, + parentValue(), + props.queries, + props.queriesById, + extraThingsById(), + ), + ...mergeParentThings( + OFFSET_CHECKPOINTS, + parentValue(), + props.checkpoints, + props.checkpointsById, + extraThingsById(), + ), + ...mergeParentThings( + OFFSET_PERSISTER, + parentValue(), + props.persister, + props.persistersById, + extraThingsById(), + ), + ...mergeParentThings( + OFFSET_SYNCHRONIZER, + parentValue(), + props.synchronizer, + props.synchronizersById, + extraThingsById(), + ), + addExtraThingById, + delExtraThingById, + ]); + + return ( + {props.children} + ); +}; diff --git a/src/ui-solid/RemoteRowView.tsx b/src/ui-solid/RemoteRowView.tsx new file mode 100644 index 00000000000..fc7953ebc3f --- /dev/null +++ b/src/ui-solid/RemoteRowView.tsx @@ -0,0 +1,53 @@ +/* @jsxImportSource solid-js */ +import type {Id} from '../@types/index.d.ts'; +import type { + RemoteRowProps, +} from '../@types/ui-solid/index.d.ts'; +import {isUndefined} from '../common/other.ts'; +import { + getProps, + getRelationshipsStoreTableIds, + getValue, +} from '../common/solid.ts'; +import {wrap} from './common/wrap.tsx'; +import {useRelationshipsOrRelationshipsById, useRemoteRowId} from './hooks.ts'; +import {RowView} from './RowView.tsx'; + +export const RemoteRowView = ({ + relationshipId, + localRowId, + relationships, + rowComponent: Row = RowView, + getRowComponentProps, + debugIds, +}: RemoteRowProps): any => { + const resolvedRelationships = + useRelationshipsOrRelationshipsById(relationships); + const rowId = useRemoteRowId( + relationshipId, + localRowId, + resolvedRelationships as any, + ) as any; + return () => { + const [_relationshipsValue, store, , remoteTableId] = + getRelationshipsStoreTableIds( + getValue(resolvedRelationships as any), + relationshipId, + ); + const remoteRowId = getValue(rowId) as Id | undefined; + return wrap( + isUndefined(remoteTableId) || isUndefined(remoteRowId) ? null : ( + + ), + undefined, + debugIds, + localRowId, + ); + }; +}; diff --git a/src/ui-solid/ResultCellView.tsx b/src/ui-solid/ResultCellView.tsx new file mode 100644 index 00000000000..d31a6d11ea3 --- /dev/null +++ b/src/ui-solid/ResultCellView.tsx @@ -0,0 +1,25 @@ +/* @jsxImportSource solid-js */ +import type { + ResultCellProps, +} from '../@types/ui-solid/index.d.ts'; +import {getValue} from '../common/solid.ts'; +import {EMPTY_STRING} from '../common/strings.ts'; +import {wrap} from './common/wrap.tsx'; +import {useResultCell} from './hooks.ts'; + +export const ResultCellView = ({ + queryId, + rowId, + cellId, + queries, + debugIds, +}: ResultCellProps): any => { + const resultCell = useResultCell(queryId, rowId, cellId, queries) as any; + return () => + wrap( + EMPTY_STRING + ((getValue(resultCell) as any) ?? EMPTY_STRING), + undefined, + debugIds, + cellId, + ); +}; \ No newline at end of file diff --git a/src/ui-solid/ResultRowView.tsx b/src/ui-solid/ResultRowView.tsx new file mode 100644 index 00000000000..988570cf948 --- /dev/null +++ b/src/ui-solid/ResultRowView.tsx @@ -0,0 +1,38 @@ +/* @jsxImportSource solid-js */ +import type { + ResultRowProps, +} from '../@types/ui-solid/index.d.ts'; +import type {Id} from '../@types/index.d.ts'; +import {arrayMap} from '../common/array.ts'; +import {getProps, getValue} from '../common/solid.ts'; +import {wrap} from './common/wrap.tsx'; +import {useResultCellIds} from './hooks.ts'; +import {ResultCellView} from './ResultCellView.tsx'; + +export const ResultRowView = ({ + queryId, + rowId, + queries, + resultCellComponent: ResultCell = ResultCellView, + getResultCellComponentProps, + separator, + debugIds, +}: ResultRowProps): any => { + const resultCellIds = useResultCellIds(queryId, rowId, queries) as any; + return () => + wrap( + arrayMap(getValue(resultCellIds) as Id[], (cellId: Id) => ( + + )), + separator, + debugIds, + rowId, + ); +}; diff --git a/src/ui-solid/ResultSortedTableView.tsx b/src/ui-solid/ResultSortedTableView.tsx new file mode 100644 index 00000000000..4b73a91af3e --- /dev/null +++ b/src/ui-solid/ResultSortedTableView.tsx @@ -0,0 +1,25 @@ +/* @jsxImportSource solid-js */ +import type { + ResultSortedTableProps, +} from '../@types/ui-solid/index.d.ts'; +import {resultTableView} from './common/index.tsx'; +import {useResultSortedRowIds} from './hooks.ts'; + +export const ResultSortedTableView = ({ + cellId, + descending, + offset, + limit, + ...props +}: ResultSortedTableProps): any => + resultTableView( + props, + useResultSortedRowIds( + props.queryId, + cellId, + descending, + offset, + limit, + props.queries, + ), + ); \ No newline at end of file diff --git a/src/ui-solid/ResultTableView.tsx b/src/ui-solid/ResultTableView.tsx new file mode 100644 index 00000000000..f73961d3acd --- /dev/null +++ b/src/ui-solid/ResultTableView.tsx @@ -0,0 +1,10 @@ +/* @jsxImportSource solid-js */ +import type { + ResultTableProps, +} from '../@types/ui-solid/index.d.ts'; +import {resultTableView} from './common/index.tsx'; +import {useResultRowIds} from './hooks.ts'; + +export const ResultTableView = ( + props: ResultTableProps, +): any => resultTableView(props, useResultRowIds(props.queryId, props.queries)); \ No newline at end of file diff --git a/src/ui-solid/RowView.tsx b/src/ui-solid/RowView.tsx new file mode 100644 index 00000000000..4460e6c4cdf --- /dev/null +++ b/src/ui-solid/RowView.tsx @@ -0,0 +1,44 @@ +/* @jsxImportSource solid-js */ +import type { + RowProps, +} from '../@types/ui-solid/index.d.ts'; +import type {Id} from '../@types/index.d.ts'; +import {arrayMap} from '../common/array.ts'; +import {getProps, getValue} from '../common/solid.ts'; +import {CellView} from './CellView.tsx'; +import {useCustomOrDefaultCellIds} from './common/hooks.tsx'; +import {wrap} from './common/wrap.tsx'; + +export const RowView = ({ + tableId, + rowId, + store, + cellComponent: Cell = CellView, + getCellComponentProps, + customCellIds, + separator, + debugIds, +}: RowProps): any => { + const cellIds = useCustomOrDefaultCellIds( + customCellIds, + tableId, + rowId, + store, + ) as any; + return () => + wrap( + arrayMap(getValue(cellIds) as Id[], (cellId: Id) => ( + + )), + separator, + debugIds, + rowId, + ); +}; diff --git a/src/ui-solid/SliceView.tsx b/src/ui-solid/SliceView.tsx new file mode 100644 index 00000000000..f2bcd8907cb --- /dev/null +++ b/src/ui-solid/SliceView.tsx @@ -0,0 +1,43 @@ +/* @jsxImportSource solid-js */ +import type {Id} from '../@types/index.d.ts'; +import type { + SliceProps, +} from '../@types/ui-solid/index.d.ts'; +import {arrayMap} from '../common/array.ts'; +import {getIndexStoreTableId, getProps, getValue} from '../common/solid.ts'; +import {wrap} from './common/wrap.tsx'; +import {useIndexesOrIndexesById, useSliceRowIds} from './hooks.ts'; +import {RowView} from './RowView.tsx'; + +export const SliceView = ({ + indexId, + sliceId, + indexes, + rowComponent: Row = RowView, + getRowComponentProps, + separator, + debugIds, +}: SliceProps): any => { + const resolvedIndexes = useIndexesOrIndexesById(indexes); + const rowIds = useSliceRowIds(indexId, sliceId, resolvedIndexes as any) as any; + return () => { + const [_indexesValue, store, tableId] = getIndexStoreTableId( + getValue(resolvedIndexes as any), + indexId, + ); + return wrap( + arrayMap(getValue(rowIds) as Id[], (rowId) => ( + + )), + separator, + debugIds, + sliceId, + ); + }; +}; diff --git a/src/ui-solid/SortedTableView.tsx b/src/ui-solid/SortedTableView.tsx new file mode 100644 index 00000000000..4508e021829 --- /dev/null +++ b/src/ui-solid/SortedTableView.tsx @@ -0,0 +1,25 @@ +/* @jsxImportSource solid-js */ +import type { + SortedTableProps, +} from '../@types/ui-solid/index.d.ts'; +import {tableView} from './common/index.tsx'; +import {useSortedRowIds} from './hooks.ts'; + +export const SortedTableView = ({ + cellId, + descending, + offset, + limit, + ...props +}: SortedTableProps): any => + tableView( + props, + useSortedRowIds( + props.tableId, + cellId, + descending, + offset, + limit, + props.store, + ), + ); \ No newline at end of file diff --git a/src/ui-solid/TableView.tsx b/src/ui-solid/TableView.tsx new file mode 100644 index 00000000000..b988a62b0fc --- /dev/null +++ b/src/ui-solid/TableView.tsx @@ -0,0 +1,9 @@ +/* @jsxImportSource solid-js */ +import type { + TableProps, +} from '../@types/ui-solid/index.d.ts'; +import {tableView} from './common/index.tsx'; +import {useRowIds} from './hooks.ts'; + +export const TableView = (props: TableProps): any => + tableView(props, useRowIds(props.tableId, props.store)); \ No newline at end of file diff --git a/src/ui-solid/TablesView.tsx b/src/ui-solid/TablesView.tsx new file mode 100644 index 00000000000..f87f8f55798 --- /dev/null +++ b/src/ui-solid/TablesView.tsx @@ -0,0 +1,32 @@ +/* @jsxImportSource solid-js */ +import type { + TablesProps, +} from '../@types/ui-solid/index.d.ts'; +import type {Id} from '../@types/index.d.ts'; +import {arrayMap} from '../common/array.ts'; +import {getProps, getValue} from '../common/solid.ts'; +import {wrap} from './common/wrap.tsx'; +import {useTableIds} from './hooks.ts'; +import {TableView} from './TableView.tsx'; + +export const TablesView = ({ + store, + tableComponent: Table = TableView, + getTableComponentProps, + separator, + debugIds, +}: TablesProps): any => { + const tableIds = useTableIds(store) as any; + return () => + wrap( + arrayMap(getValue(tableIds) as Id[], (tableId: Id) => ( +
+ )), + separator, + ); +}; diff --git a/src/ui-solid/ValueView.tsx b/src/ui-solid/ValueView.tsx new file mode 100644 index 00000000000..759288c3e16 --- /dev/null +++ b/src/ui-solid/ValueView.tsx @@ -0,0 +1,23 @@ +/* @jsxImportSource solid-js */ +import type { + ValueProps, +} from '../@types/ui-solid/index.d.ts'; +import {getValue} from '../common/solid.ts'; +import {EMPTY_STRING} from '../common/strings.ts'; +import {wrap} from './common/wrap.tsx'; +import {useValue} from './hooks.ts'; + +export const ValueView = ({ + valueId, + store, + debugIds, +}: ValueProps): any => { + const value = useValue(valueId, store) as any; + return () => + wrap( + EMPTY_STRING + ((getValue(value) as any) ?? EMPTY_STRING), + undefined, + debugIds, + valueId, + ); +}; \ No newline at end of file diff --git a/src/ui-solid/ValuesView.tsx b/src/ui-solid/ValuesView.tsx new file mode 100644 index 00000000000..ba5af00e721 --- /dev/null +++ b/src/ui-solid/ValuesView.tsx @@ -0,0 +1,32 @@ +/* @jsxImportSource solid-js */ +import type { + ValuesProps, +} from '../@types/ui-solid/index.d.ts'; +import type {Id} from '../@types/index.d.ts'; +import {arrayMap} from '../common/array.ts'; +import {getProps, getValue} from '../common/solid.ts'; +import {wrap} from './common/wrap.tsx'; +import {useValueIds} from './hooks.ts'; +import {ValueView} from './ValueView.tsx'; + +export const ValuesView = ({ + store, + valueComponent: Value = ValueView, + getValueComponentProps, + separator, + debugIds, +}: ValuesProps): any => { + const valueIds = useValueIds(store) as any; + return () => + wrap( + arrayMap(getValue(valueIds) as Id[], (valueId: Id) => ( + + )), + separator, + ); +}; diff --git a/src/ui-solid/common/hooks.tsx b/src/ui-solid/common/hooks.tsx new file mode 100644 index 00000000000..30abb3b37e7 --- /dev/null +++ b/src/ui-solid/common/hooks.tsx @@ -0,0 +1,15 @@ +/* @jsxImportSource solid-js */ +import type {Id, Ids} from '../../@types/index.d.ts'; +import type {StoreOrStoreId} from '../../@types/ui-solid/index.d.ts'; +import {getValue} from '../../common/solid.ts'; +import {useCellIds} from '../hooks.ts'; + +export const useCustomOrDefaultCellIds = ( + customCellIds: Ids | undefined, + tableId: Id, + rowId: Id, + store?: StoreOrStoreId, +): Ids => { + const defaultCellIds = useCellIds(tableId, rowId, store); + return customCellIds ?? ((() => getValue(defaultCellIds as any)) as any); +}; \ No newline at end of file diff --git a/src/ui-solid/common/index.tsx b/src/ui-solid/common/index.tsx new file mode 100644 index 00000000000..4be292253a8 --- /dev/null +++ b/src/ui-solid/common/index.tsx @@ -0,0 +1,173 @@ +/* @jsxImportSource solid-js */ +import type {JSXElement} from 'solid-js'; +import type {CheckpointIds} from '../../@types/checkpoints/index.d.ts'; +import type {Id, Ids} from '../../@types/common/index.d.ts'; +import type { + BackwardCheckpointsProps, + CurrentCheckpointProps, + ForwardCheckpointsProps, + LinkedRowsProps, + LocalRowsProps, + RelationshipsOrRelationshipsId, + RemoteRowProps, + ResultTableProps, + TableProps, +} from '../../@types/ui-solid/index.d.ts'; +import {arrayMap} from '../../common/array.ts'; +import { + getProps, + getRelationshipsStoreTableIds, + getValue, +} from '../../common/solid.ts'; +import {CheckpointView} from '../CheckpointView.tsx'; +import {ThingsByOffset} from '../context.ts'; +import { + useCheckpointIds, + useCheckpointsOrCheckpointsById, + useRelationshipsOrRelationshipsById, +} from '../hooks.ts'; +import {ResultRowView} from '../ResultRowView.tsx'; +import {RowView} from '../RowView.tsx'; +import {wrap} from './wrap.tsx'; + +export type ThingsById = { + [Offset in keyof ThingsByOffset]: {[id: Id]: ThingsByOffset[Offset]}; +}; +export type ExtraThingsById = ThingsById; + +export const tableView = ( + { + tableId, + store, + rowComponent: Row = RowView, + getRowComponentProps, + customCellIds, + separator, + debugIds, + }: TableProps, + rowIds: Ids, +): any => + () => + wrap( + arrayMap(getValue(rowIds as any) as Ids, (rowId) => ( + + )), + separator, + debugIds, + tableId, + ); + +export const resultTableView = ( + { + queryId, + queries, + resultRowComponent: ResultRow = ResultRowView, + getResultRowComponentProps, + separator, + debugIds, + }: ResultTableProps, + rowIds: Ids, +): any => + () => + wrap( + arrayMap(getValue(rowIds as any) as Ids, (rowId) => ( + + )), + separator, + debugIds, + queryId, + ); + +export const useComponentPerRow = ( + { + relationshipId, + relationships, + rowComponent: Row = RowView, + getRowComponentProps, + separator, + debugIds, + }: (RemoteRowProps | LocalRowsProps | LinkedRowsProps) & { + separator?: JSXElement | string; + }, + getRowIdsHook: ( + relationshipId: Id, + rowId: Id, + relationships: RelationshipsOrRelationshipsId | undefined, + ) => Ids, + rowId: Id, +) => { + const resolvedRelationships = + useRelationshipsOrRelationshipsById(relationships); + const rowIds = getRowIdsHook( + relationshipId, + rowId, + resolvedRelationships as any, + ) as any; + return () => { + const [_relationship, store, localTableId] = getRelationshipsStoreTableIds( + getValue(resolvedRelationships as any), + relationshipId, + ); + return wrap( + arrayMap(getValue(rowIds) as Ids, (localRowId) => ( + + )), + separator, + debugIds, + rowId, + ); + }; +}; + +export const getUseCheckpointView = + (getCheckpoints: (checkpointIds: CheckpointIds) => Ids) => + ({ + checkpoints, + checkpointComponent: Checkpoint = CheckpointView, + getCheckpointComponentProps, + separator, + debugIds, + }: ( + | BackwardCheckpointsProps + | CurrentCheckpointProps + | ForwardCheckpointsProps + ) & { + separator?: JSXElement | string; + }): any => { + const resolvedCheckpoints = useCheckpointsOrCheckpointsById(checkpoints); + const checkpointIds = useCheckpointIds(resolvedCheckpoints) as any; + return () => + wrap( + arrayMap( + getCheckpoints(getValue(checkpointIds) as CheckpointIds), + (checkpointId: Id) => ( + + ), + ), + separator, + ); + }; diff --git a/src/ui-solid/common/wrap.tsx b/src/ui-solid/common/wrap.tsx new file mode 100644 index 00000000000..fe198f1f0db --- /dev/null +++ b/src/ui-solid/common/wrap.tsx @@ -0,0 +1,17 @@ +/* @jsxImportSource solid-js */ +import type {Id} from '../../@types/index.d.ts'; +import {arrayMap} from '../../common/array.ts'; +import {isArray, isUndefined} from '../../common/other.ts'; + +export const wrap = ( + children: any, + separator?: any, + encloseWithId?: boolean, + id?: Id, +) => { + const separated = + isUndefined(separator) || !isArray(children) + ? children + : arrayMap(children, (child, c) => (c > 0 ? [separator, child] : child)); + return encloseWithId ? [id, ':{', separated, '}'] : separated; +}; \ No newline at end of file diff --git a/src/ui-solid/context.ts b/src/ui-solid/context.ts new file mode 100644 index 00000000000..4a58078ed0a --- /dev/null +++ b/src/ui-solid/context.ts @@ -0,0 +1,139 @@ +import type {Accessor} from 'solid-js'; +import {createContext, createEffect, onCleanup, useContext} from 'solid-js'; +import type {Checkpoints} from '../@types/checkpoints/index.d.ts'; +import type {Id, Ids} from '../@types/common/index.d.ts'; +import type {Indexes} from '../@types/indexes/index.d.ts'; +import type {Metrics} from '../@types/metrics/index.d.ts'; +import type {AnyPersister} from '../@types/persisters/index.d.ts'; +import type {Queries} from '../@types/queries/index.d.ts'; +import type {Relationships} from '../@types/relationships/index.d.ts'; +import type {Store} from '../@types/store/index.d.ts'; +import type {Synchronizer} from '../@types/synchronizers/index.d.ts'; +import {IdObj, objGet, objIds} from '../common/obj.ts'; +import {GLOBAL, isFunction, isString, isUndefined} from '../common/other.ts'; +import {TINYBASE} from '../common/strings.ts'; +import type {Offsets} from './Provider.tsx'; + +export type Thing = + | Store + | Metrics + | Indexes + | Relationships + | Queries + | Checkpoints + | AnyPersister + | Synchronizer; + +export type ThingsByOffset = [ + Store, + Metrics, + Indexes, + Relationships, + Queries, + Checkpoints, + AnyPersister, + Synchronizer, +]; + +export type ContextValue = [ + store?: Store, + storesById?: {[storeId: Id]: Store}, + metrics?: Metrics, + metricsById?: {[metricsId: Id]: Metrics}, + indexes?: Indexes, + indexesById?: {[indexesId: Id]: Indexes}, + relationships?: Relationships, + relationshipsById?: {[relationshipsId: Id]: Relationships}, + queries?: Queries, + queriesById?: {[queriesId: Id]: Queries}, + checkpoints?: Checkpoints, + checkpointsById?: {[checkpointsId: Id]: Checkpoints}, + persister?: AnyPersister, + persistersById?: {[persisterId: Id]: AnyPersister}, + synchronizer?: Synchronizer, + synchronizersById?: {[synchronizerId: Id]: Synchronizer}, + addExtraThingById?: ( + offset: Offset, + id: string, + thing: ThingsByOffset[Offset], + ) => void, + delExtraThingById?: (offset: Offsets, id: string) => void, +]; + +const TINYBASE_CONTEXT = TINYBASE + '_uisc'; +const EMPTY_CONTEXT = () => [] as ContextValue; + +export const Context: ReturnType>> = + (GLOBAL as any)[TINYBASE_CONTEXT] + ? /*! istanbul ignore next */ (GLOBAL as any)[TINYBASE_CONTEXT] + : ((GLOBAL as any)[TINYBASE_CONTEXT] = + createContext>(EMPTY_CONTEXT)); + +export const useThing = ( + id: Id | undefined, + offset: Offsets, +): Accessor => { + const contextValue = useContext(Context) ?? EMPTY_CONTEXT; + return () => { + const resolvedContextValue = contextValue(); + return ( + isUndefined(id) + ? resolvedContextValue[offset * 2] + : isString(id) + ? objGet( + resolvedContextValue[offset * 2 + 1] as IdObj, + id, + ) + : id + ) as UsedThing; + }; +}; + +export const useThings = ( + offset: Offsets, +): Accessor> => { + const contextValue = useContext(Context) ?? EMPTY_CONTEXT; + return () => ({...contextValue()[offset * 2 + 1]}) as IdObj; +}; + +export const useThingOrThingById = < + UsedThing extends + | Store + | Metrics + | Indexes + | Relationships + | Queries + | Checkpoints + | AnyPersister + | Synchronizer, +>( + thingOrThingId: UsedThing | Id | undefined, + offset: Offsets, +): Accessor => { + const thing = useThing(thingOrThingId as Id, offset); + return () => + isUndefined(thingOrThingId) || isString(thingOrThingId) + ? (thing() as UsedThing | undefined) + : isFunction(thingOrThingId) + ? (thingOrThingId() as UsedThing) + : (thingOrThingId as UsedThing); +}; + +export const useProvideThing = ( + thingId: Id, + thing: ThingsByOffset[Offset], + offset: Offset, +): void => { + const contextValue = useContext(Context) ?? EMPTY_CONTEXT; + createEffect(() => { + const {16: addExtraThingById, 17: delExtraThingById} = contextValue(); + addExtraThingById?.(offset, thingId, thing); + onCleanup(() => delExtraThingById?.(offset, thingId)); + }); +}; + +export const useThingIds = (offset: Offsets): Accessor => { + const contextValue = useContext(Context) ?? EMPTY_CONTEXT; + return () => + objIds((contextValue()[offset * 2 + 1] ?? {}) as IdObj); +}; diff --git a/src/ui-solid/hooks.ts b/src/ui-solid/hooks.ts new file mode 100644 index 00000000000..0b4e82c81bc --- /dev/null +++ b/src/ui-solid/hooks.ts @@ -0,0 +1,2274 @@ +import type {Accessor} from 'solid-js'; +import { + createEffect, + createMemo, + createRenderEffect, + createSignal, + onCleanup, + untrack, +} from 'solid-js'; +import type { + CheckpointIds, + CheckpointIdsListener, + CheckpointListener, + Checkpoints, +} from '../@types/checkpoints/index.d.ts'; +import type { + Callback, + Id, + IdOrNull, + Ids, + ParameterizedCallback, +} from '../@types/common/index.d.ts'; +import type { + Indexes, + SliceIdsListener, + SliceRowIdsListener, +} from '../@types/indexes/index.d.ts'; +import type {MergeableStore} from '../@types/mergeable-store/index.d.ts'; +import type {MetricListener, Metrics} from '../@types/metrics/index.d.ts'; +import type { + AnyPersister, + PersistedStore, + Persister, + Persists, + Status, + StatusListener, +} from '../@types/persisters/index.d.ts'; +import type { + ParamValue, + ParamValueListener, + ParamValues, + ParamValuesListener, + Queries, + ResultCellIdsListener, + ResultCellListener, + ResultRowCountListener, + ResultRowIdsListener, + ResultRowListener, + ResultSortedRowIdsListener, + ResultTableCellIdsListener, + ResultTableListener, +} from '../@types/queries/index.d.ts'; +import type { + LinkedRowIdsListener, + LocalRowIdsListener, + Relationships, + RemoteRowIdListener, +} from '../@types/relationships/index.d.ts'; +import type { + Cell, + CellIdsListener, + CellListener, + CellOrUndefined, + HasCellListener, + HasRowListener, + HasTableCellListener, + HasTableListener, + HasTablesListener, + HasValueListener, + HasValuesListener, + MapCell, + MapValue, + Row, + RowCountListener, + RowIdsListener, + RowListener, + SortedRowIdsArgs, + SortedRowIdsListener, + Store, + Table, + TableCellIdsListener, + TableIdsListener, + TableListener, + Tables, + TablesListener, + TransactionListener, + Value, + ValueIdsListener, + ValueListener, + ValueOrUndefined, + Values, + ValuesListener, +} from '../@types/store/index.d.ts'; +import type {Synchronizer} from '../@types/synchronizers/index.d.ts'; +import type { + CheckpointsOrCheckpointsId, + GetId, + IndexesOrIndexesId, + MetricsOrMetricsId, + PersisterOrPersisterId, + QueriesOrQueriesId, + RelationshipsOrRelationshipsId, + StoreOrStoreId, + SynchronizerOrSynchronizerId, + UndoOrRedoInformation, +} from '../@types/ui-solid/index.d.ts'; +import { + arrayIsEmpty, + arrayIsEqual, + arrayMap, + arrayOrValueEqual, +} from '../common/array.ts'; +import {ListenerArgument} from '../common/listeners.ts'; +import {IdObj, isObject, objIsEqual} from '../common/obj.ts'; +import { + getArg, + getUndefined, + ifNotUndefined, + isFunction, + isUndefined, +} from '../common/other.ts'; +import type {DependencyList} from '../common/solid.ts'; +import { + ADD, + CELL, + CELL_IDS, + CHECKPOINT, + DEL, + EMPTY_STRING, + FINISH, + GET, + HAS, + IDS, + INDEX, + LINKED, + LISTENER, + LOCAL, + METRIC, + PARTIAL, + QUERY, + RELATIONSHIP, + REMOTE_ROW_ID, + RESULT, + ROW, + ROW_COUNT, + ROW_IDS, + SET, + SLICE, + SORTED_ROW_IDS, + STATUS, + TABLE, + TABLES, + TABLE_IDS, + TRANSACTION, + VALUE, + VALUES, + VALUE_IDS, + _HAS, +} from '../common/strings.ts'; +import { + useProvideThing, + useThing, + useThingIds, + useThingOrThingById, + useThings, +} from './context.ts'; +import { + OFFSET_CHECKPOINTS, + OFFSET_INDEXES, + OFFSET_METRICS, + OFFSET_PERSISTER, + OFFSET_QUERIES, + OFFSET_RELATIONSHIPS, + OFFSET_STORE, + OFFSET_SYNCHRONIZER, +} from './Provider.tsx'; + +const EMPTY_ARRAY: Readonly<[]> = []; + +enum ReturnType { + Object, + Array, + Checkpoints, + ParamValues, + ParamValue, + CellOrValue, + Boolean, + Number, +} +const DEFAULTS = [ + {}, + [], + [EMPTY_ARRAY, undefined, EMPTY_ARRAY], + {}, + undefined, + undefined, + false, + 0, +]; +const IS_EQUALS: ((thing1: any, thing2: any) => boolean)[] = [ + objIsEqual, + arrayIsEqual, + ( + [backwardIds1, currentId1, forwardIds1]: CheckpointIds, + [backwardIds2, currentId2, forwardIds2]: CheckpointIds, + ) => + currentId1 === currentId2 && + arrayIsEqual(backwardIds1, backwardIds2) && + arrayIsEqual(forwardIds1, forwardIds2), + (paramValues1: ParamValues, paramValues2: ParamValues): boolean => + objIsEqual(paramValues1, paramValues2, arrayOrValueEqual), + arrayOrValueEqual, +]; +const isEqual = (thing1: any, thing2: any) => thing1 === thing2; + +type MaybeAccessor = Thing | Accessor; + +const getThing = (thing: MaybeAccessor): Thing => + (isFunction(thing) ? (thing as Accessor)() : thing) as Thing; + +const useCreate = ( + store: MaybeAccessor, + create: (store: Store) => any, + _createDeps: DependencyList = EMPTY_ARRAY, +) => { + const [thing, setThing] = createSignal(); + createEffect(() => { + const resolvedStore = getThing(store); + const newThing = resolvedStore ? create(resolvedStore) : undefined; + setThing(() => newThing); + onCleanup(() => newThing?.destroy?.()); + }); + return thing as any; +}; + +const addAndDelListener = (thing: any, listenable: string, ...args: any[]) => { + const listenerId = thing?.[ADD + listenable + LISTENER]?.(...args); + return () => thing?.delListener?.(listenerId); +}; + +const useListenable = ( + listenable: string, + thing: MaybeAccessor, + returnType: ReturnType, + args: Readonly = EMPTY_ARRAY, +): any => { + const [result, setResult] = createSignal(DEFAULTS[returnType] as any); + const getResult = () => + getThing(thing)?.[ + (returnType == ReturnType.Boolean ? _HAS : GET) + listenable + ]?.(...args) ?? DEFAULTS[returnType]; + const updateResult = () => { + const nextResult = getResult(); + const prevResult = untrack(result); + setResult(() => + !(IS_EQUALS[returnType] ?? isEqual)(nextResult, prevResult) + ? nextResult + : prevResult, + ); + }; + createRenderEffect(() => { + const resolvedThing = getThing(thing); + updateResult(); + const cleanup = addAndDelListener( + resolvedThing, + (returnType == ReturnType.Boolean ? HAS : EMPTY_STRING) + listenable, + ...args, + updateResult, + ); + onCleanup(cleanup); + }); + return result as any; +}; + +const useListener = ( + listenable: string, + thing: MaybeAccessor, + listener: (...args: any[]) => void, + _listenerDeps: DependencyList = EMPTY_ARRAY, + preArgs: Readonly = EMPTY_ARRAY, + ...postArgs: ListenerArgument[] +): void => + createRenderEffect(() => { + const cleanup = addAndDelListener( + getThing(thing), + listenable, + ...preArgs, + listener, + ...postArgs, + ); + onCleanup(cleanup); + }); + +const useSetCallback = ( + storeOrQueries: MaybeAccessor, + settable: string, + get: (parameter: Parameter, obj: StoreOrQueries) => Thing, + _getDeps: DependencyList = EMPTY_ARRAY, + then: (obj: StoreOrQueries, thing: Thing) => void = getUndefined, + _thenDeps: DependencyList = EMPTY_ARRAY, + methodPrefix?: string, + ...args: (Id | GetId)[] +): ParameterizedCallback => + (parameter?: Parameter) => + ifNotUndefined(getThing(storeOrQueries), (obj: any) => + ifNotUndefined(get(parameter as any, obj), (thing: Thing) => + then( + obj[methodPrefix + settable]( + ...argsOrGetArgs(args, obj, parameter), + thing, + ), + thing, + ), + ), + ); + +const useStoreSetCallback = ( + storeOrStoreId: StoreOrStoreId | undefined, + settable: string, + get: (parameter: Parameter, store: Store) => Thing, + getDeps?: DependencyList, + then?: (store: Store, thing: Thing) => void, + thenDeps?: DependencyList, + ...args: (Id | GetId)[] +): ParameterizedCallback => + useSetCallback( + useStoreOrStoreById(storeOrStoreId), + settable, + get, + getDeps, + then, + thenDeps, + SET, + ...args, + ); + +const useQueriesSetCallback = ( + queriesOrQueriesId: QueriesOrQueriesId | undefined, + settable: string, + get: (parameter: Parameter, queries: Queries) => Thing, + getDeps?: DependencyList, + then?: (queries: Queries, thing: Thing) => void, + thenDeps?: DependencyList, + ...args: (Id | GetId)[] +): ParameterizedCallback => + useSetCallback( + useQueriesOrQueriesById(queriesOrQueriesId), + settable, + get, + getDeps, + then, + thenDeps, + EMPTY_STRING, + ...args, + ); + +const argsOrGetArgs = ( + args: (Id | GetId | boolean | undefined)[], + store: Store, + parameter?: Parameter, +) => + arrayMap(args, (arg) => + isFunction(arg) ? arg(parameter as any, store) : arg, + ); + +const useDel = ( + storeOrStoreId: StoreOrStoreId | undefined, + deletable: string, + then: (store: Store) => void = getUndefined, + _thenDeps: DependencyList = EMPTY_ARRAY, + ...args: (Id | GetId | boolean | undefined)[] +): ParameterizedCallback => { + const store: any = useStoreOrStoreById(storeOrStoreId); + return (parameter?: Parameter) => { + const resolvedStore = getThing(store); + then( + resolvedStore?.[DEL + deletable]( + ...argsOrGetArgs(args, resolvedStore, parameter), + ), + ); + }; +}; + +const useCheckpointAction = ( + checkpointsOrCheckpointsId: CheckpointsOrCheckpointsId | undefined, + action: string, + arg?: string, +) => { + const checkpoints: any = useCheckpointsOrCheckpointsById( + checkpointsOrCheckpointsId, + ); + return () => getThing(checkpoints)?.[action](arg); +}; + +const useSortedRowIdsImpl = ( + tableId: Id, + cellId?: Id, + descending?: boolean, + offset?: number, + limit?: number | undefined, + storeOrStoreId?: StoreOrStoreId, +): Ids => + useListenable( + SORTED_ROW_IDS, + useStoreOrStoreById(storeOrStoreId), + ReturnType.Array, + [tableId, cellId, descending, offset, limit], + ); + +export const useSortedRowIdsListenerImpl = ( + tableId: Id, + cellId: Id | undefined, + descending: boolean, + offset: number, + limit: number | undefined, + listener: SortedRowIdsListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, +): void => + useListener( + SORTED_ROW_IDS, + useStoreOrStoreById(storeOrStoreId), + listener, + listenerDeps, + [tableId, cellId, descending, offset, limit], + mutator, + ); + +// --- + +export const useCreateStore = ( + create: () => Store, + _createDeps: DependencyList = EMPTY_ARRAY, +): Store => createMemo(create) as any; + +export const useStoreIds = () => + useThingIds(OFFSET_STORE) as any; + +export const useStore = (id?: Id): Store | undefined => + useThing(id, OFFSET_STORE) as any; + +export const useStores = (): IdObj => + useThings(OFFSET_STORE) as any; + +export const useStoreOrStoreById = ( + storeOrStoreId?: StoreOrStoreId, +): Store | undefined => + useThingOrThingById(storeOrStoreId, OFFSET_STORE) as any; + +export const useProvideStore = ( + storeId: Id, + store: Store, +): void => useProvideThing(storeId, store, OFFSET_STORE); + +export const useCreateMergeableStore = ( + create: () => MergeableStore, + _createDeps: DependencyList = EMPTY_ARRAY, +): MergeableStore => createMemo(create) as any; + +export const useHasTables = ( + storeOrStoreId?: StoreOrStoreId, +): boolean => + useListenable( + TABLES, + useStoreOrStoreById(storeOrStoreId), + ReturnType.Boolean, + [], + ); + +export const useTables = ( + storeOrStoreId?: StoreOrStoreId, +): Tables => + useListenable(TABLES, useStoreOrStoreById(storeOrStoreId), ReturnType.Object); + +export const useTablesState = ( + storeOrStoreId?: StoreOrStoreId, +): [Tables, (tables: Tables) => void] => [ + useTables(storeOrStoreId), + useSetTablesCallback(getArg, [], storeOrStoreId), +]; + +export const useTableIds = ( + storeOrStoreId?: StoreOrStoreId, +): Ids => + useListenable( + TABLE_IDS, + useStoreOrStoreById(storeOrStoreId), + ReturnType.Array, + ); + +export const useHasTable = ( + tableId: Id, + storeOrStoreId?: StoreOrStoreId, +): boolean => + useListenable( + TABLE, + useStoreOrStoreById(storeOrStoreId), + ReturnType.Boolean, + [tableId], + ); + +export const useTable = ( + tableId: Id, + storeOrStoreId?: StoreOrStoreId, +): Table => + useListenable(TABLE, useStoreOrStoreById(storeOrStoreId), ReturnType.Object, [ + tableId, + ]); +export const useTableState = ( + tableId: Id, + storeOrStoreId?: StoreOrStoreId, +): [Table, (table: Table) => void] => [ + useTable(tableId, storeOrStoreId), + useSetTableCallback(tableId, getArg, [], storeOrStoreId), +]; + +export const useTableCellIds = ( + tableId: Id, + storeOrStoreId?: StoreOrStoreId, +): Ids => + useListenable( + TABLE + CELL_IDS, + useStoreOrStoreById(storeOrStoreId), + ReturnType.Array, + [tableId], + ); + +export const useHasTableCell = ( + tableId: Id, + cellId: Id, + storeOrStoreId?: StoreOrStoreId, +): boolean => + useListenable( + TABLE + CELL, + useStoreOrStoreById(storeOrStoreId), + ReturnType.Boolean, + [tableId, cellId], + ); + +export const useRowCount = ( + tableId: Id, + storeOrStoreId?: StoreOrStoreId, +): number => + useListenable( + ROW_COUNT, + useStoreOrStoreById(storeOrStoreId), + ReturnType.Number, + [tableId], + ); + +export const useRowIds = ( + tableId: Id, + storeOrStoreId?: StoreOrStoreId, +): Ids => + useListenable( + ROW_IDS, + useStoreOrStoreById(storeOrStoreId), + ReturnType.Array, + [tableId], + ); + +export const useSortedRowIds = ( + tableIdOrArgs: Id | SortedRowIdsArgs, + cellIdOrStoreOrStoreId?: Id | StoreOrStoreId, + descending?: boolean, + offset?: number, + limit?: number | undefined, + storeOrStoreId?: StoreOrStoreId, +): Ids => + (useSortedRowIdsImpl as any)( + ...(isObject(tableIdOrArgs) + ? [ + tableIdOrArgs.tableId, + tableIdOrArgs.cellId, + tableIdOrArgs.descending ?? false, + tableIdOrArgs.offset ?? 0, + tableIdOrArgs.limit, + cellIdOrStoreOrStoreId, + ] + : [ + tableIdOrArgs, + cellIdOrStoreOrStoreId, + descending, + offset, + limit, + storeOrStoreId, + ]), + ); + +export const useHasRow = ( + tableId: Id, + rowId: Id, + storeOrStoreId?: StoreOrStoreId, +): boolean => + useListenable(ROW, useStoreOrStoreById(storeOrStoreId), ReturnType.Boolean, [ + tableId, + rowId, + ]); + +export const useRow = ( + tableId: Id, + rowId: Id, + storeOrStoreId?: StoreOrStoreId, +): Row => + useListenable(ROW, useStoreOrStoreById(storeOrStoreId), ReturnType.Object, [ + tableId, + rowId, + ]); + +export const useRowState = ( + tableId: Id, + rowId: Id, + storeOrStoreId?: StoreOrStoreId, +): [Row, (row: Row) => void] => [ + useRow(tableId, rowId, storeOrStoreId), + useSetRowCallback(tableId, rowId, getArg, [], storeOrStoreId), +]; + +export const useCellIds = ( + tableId: Id, + rowId: Id, + storeOrStoreId?: StoreOrStoreId, +): Ids => + useListenable( + CELL_IDS, + useStoreOrStoreById(storeOrStoreId), + ReturnType.Array, + [tableId, rowId], + ); + +export const useHasCell = ( + tableId: Id, + rowId: Id, + cellId: Id, + storeOrStoreId?: StoreOrStoreId, +): boolean => + useListenable(CELL, useStoreOrStoreById(storeOrStoreId), ReturnType.Boolean, [ + tableId, + rowId, + cellId, + ]); + +export const useCell = ( + tableId: Id, + rowId: Id, + cellId: Id, + storeOrStoreId?: StoreOrStoreId, +): CellOrUndefined => + useListenable( + CELL, + useStoreOrStoreById(storeOrStoreId), + ReturnType.CellOrValue, + [tableId, rowId, cellId], + ); + +export const useCellState = ( + tableId: Id, + rowId: Id, + cellId: Id, + storeOrStoreId?: StoreOrStoreId, +): [CellOrUndefined, (cell: Cell) => void] => [ + useCell(tableId, rowId, cellId, storeOrStoreId), + useSetCellCallback(tableId, rowId, cellId, getArg, [], storeOrStoreId), +]; + +export const useHasValues = ( + storeOrStoreId?: StoreOrStoreId, +): boolean => + useListenable( + VALUES, + useStoreOrStoreById(storeOrStoreId), + ReturnType.Boolean, + [], + ); + +export const useValues = ( + storeOrStoreId?: StoreOrStoreId, +): Values => + useListenable(VALUES, useStoreOrStoreById(storeOrStoreId), ReturnType.Object); + +export const useValuesState = ( + storeOrStoreId?: StoreOrStoreId, +): [Values, (values: Values) => void] => [ + useValues(storeOrStoreId), + useSetValuesCallback(getArg, [], storeOrStoreId), +]; + +export const useValueIds = ( + storeOrStoreId?: StoreOrStoreId, +): Ids => + useListenable( + VALUE_IDS, + useStoreOrStoreById(storeOrStoreId), + ReturnType.Array, + ); + +export const useHasValue = ( + valueId: Id, + storeOrStoreId?: StoreOrStoreId, +): boolean => + useListenable( + VALUE, + useStoreOrStoreById(storeOrStoreId), + ReturnType.Boolean, + [valueId], + ); + +export const useValue = ( + valueId: Id, + storeOrStoreId?: StoreOrStoreId, +): ValueOrUndefined => + useListenable( + VALUE, + useStoreOrStoreById(storeOrStoreId), + ReturnType.CellOrValue, + [valueId], + ); + +export const useValueState = ( + valueId: Id, + storeOrStoreId?: StoreOrStoreId, +): [ValueOrUndefined, (value: Value) => void] => [ + useValue(valueId, storeOrStoreId), + useSetValueCallback(valueId, getArg, [], storeOrStoreId), +]; + +export const useSetTablesCallback = < + Parameter, +>( + getTables: (parameter: Parameter, store: Store) => Tables, + getTablesDeps?: DependencyList, + storeOrStoreId?: StoreOrStoreId, + then?: (store: Store, tables: Tables) => void, + thenDeps?: DependencyList, +): ParameterizedCallback => + useStoreSetCallback( + storeOrStoreId, + TABLES, + getTables, + getTablesDeps, + then, + thenDeps, + ); + +export const useSetTableCallback = ( + tableId: Id | GetId, + getTable: (parameter: Parameter, store: Store) => Table, + getTableDeps?: DependencyList, + storeOrStoreId?: StoreOrStoreId, + then?: (store: Store, table: Table) => void, + thenDeps?: DependencyList, +): ParameterizedCallback => + useStoreSetCallback( + storeOrStoreId, + TABLE, + getTable, + getTableDeps, + then, + thenDeps, + tableId, + ); + +export const useSetRowCallback = ( + tableId: Id | GetId, + rowId: Id | GetId, + getRow: (parameter: Parameter, store: Store) => Row, + getRowDeps?: DependencyList, + storeOrStoreId?: StoreOrStoreId, + then?: (store: Store, row: Row) => void, + thenDeps?: DependencyList, +): ParameterizedCallback => + useStoreSetCallback( + storeOrStoreId, + ROW, + getRow, + getRowDeps, + then, + thenDeps, + tableId, + rowId, + ); + +export const useAddRowCallback = ( + tableId: Id | GetId, + getRow: (parameter: Parameter, store: Store) => Row, + _getRowDeps: DependencyList = EMPTY_ARRAY, + storeOrStoreId?: StoreOrStoreId, + then: (rowId: Id | undefined, store: Store, row: Row) => void = getUndefined, + _thenDeps: DependencyList = EMPTY_ARRAY, + reuseRowIds = true, +): ParameterizedCallback => { + const store = useStoreOrStoreById(storeOrStoreId); + return (parameter) => + ifNotUndefined(getThing(store), (resolvedStore) => + ifNotUndefined(getRow(parameter as any, resolvedStore), (row: Row) => + then( + resolvedStore.addRow( + isFunction(tableId) + ? tableId(parameter as any, resolvedStore) + : tableId, + row, + reuseRowIds, + ), + resolvedStore, + row, + ), + ), + ); +}; + +export const useSetPartialRowCallback = < + Parameter, +>( + tableId: Id | GetId, + rowId: Id | GetId, + getPartialRow: (parameter: Parameter, store: Store) => Row, + getPartialRowDeps?: DependencyList, + storeOrStoreId?: StoreOrStoreId, + then?: (store: Store, partialRow: Row) => void, + thenDeps?: DependencyList, +): ParameterizedCallback => + useStoreSetCallback( + storeOrStoreId, + PARTIAL + ROW, + getPartialRow, + getPartialRowDeps, + then, + thenDeps, + tableId, + rowId, + ); + +export const useSetCellCallback = ( + tableId: Id | GetId, + rowId: Id | GetId, + cellId: Id | GetId, + getCell: (parameter: Parameter, store: Store) => Cell | MapCell, + getCellDeps?: DependencyList, + storeOrStoreId?: StoreOrStoreId, + then?: (store: Store, cell: Cell | MapCell) => void, + thenDeps?: DependencyList, +): ParameterizedCallback => + useStoreSetCallback( + storeOrStoreId, + CELL, + getCell, + getCellDeps, + then, + thenDeps, + tableId, + rowId, + cellId, + ); + +export const useSetValuesCallback = < + Parameter, +>( + getValues: (parameter: Parameter, store: Store) => Values, + getValuesDeps?: DependencyList, + storeOrStoreId?: StoreOrStoreId, + then?: (store: Store, values: Values) => void, + thenDeps?: DependencyList, +): ParameterizedCallback => + useStoreSetCallback( + storeOrStoreId, + VALUES, + getValues, + getValuesDeps, + then, + thenDeps, + ); + +export const useSetPartialValuesCallback = + ( + getPartialValues: (parameter: Parameter, store: Store) => Values, + getPartialValuesDeps?: DependencyList, + storeOrStoreId?: StoreOrStoreId, + then?: (store: Store, partialValues: Values) => void, + thenDeps?: DependencyList, + ): ParameterizedCallback => + useStoreSetCallback( + storeOrStoreId, + PARTIAL + VALUES, + getPartialValues, + getPartialValuesDeps, + then, + thenDeps, + ); + +export const useSetValueCallback = ( + valueId: Id | GetId, + getValue: (parameter: Parameter, store: Store) => Value | MapValue, + getValueDeps?: DependencyList, + storeOrStoreId?: StoreOrStoreId, + then?: (store: Store, value: Value | MapValue) => void, + thenDeps?: DependencyList, +): ParameterizedCallback => + useStoreSetCallback( + storeOrStoreId, + VALUE, + getValue, + getValueDeps, + then, + thenDeps, + valueId, + ); + +export const useDelTablesCallback = ( + storeOrStoreId?: StoreOrStoreId, + then?: (store: Store) => void, + thenDeps?: DependencyList, +): Callback => useDel(storeOrStoreId, TABLES, then, thenDeps); + +export const useDelTableCallback = ( + tableId: Id | GetId, + storeOrStoreId?: StoreOrStoreId, + then?: (store: Store) => void, + thenDeps?: DependencyList, +): ParameterizedCallback => + useDel(storeOrStoreId, TABLE, then, thenDeps, tableId); + +export const useDelRowCallback = ( + tableId: Id | GetId, + rowId: Id | GetId, + storeOrStoreId?: StoreOrStoreId, + then?: (store: Store) => void, + thenDeps?: DependencyList, +): ParameterizedCallback => + useDel(storeOrStoreId, ROW, then, thenDeps, tableId, rowId); + +export const useDelCellCallback = ( + tableId: Id | GetId, + rowId: Id | GetId, + cellId: Id | GetId, + forceDel?: boolean, + storeOrStoreId?: StoreOrStoreId, + then?: (store: Store) => void, + thenDeps?: DependencyList, +): ParameterizedCallback => + useDel( + storeOrStoreId, + CELL, + then, + thenDeps, + tableId, + rowId, + cellId, + forceDel, + ); + +export const useDelValuesCallback = ( + storeOrStoreId?: StoreOrStoreId, + then?: (store: Store) => void, + thenDeps?: DependencyList, +): Callback => useDel(storeOrStoreId, VALUES, then, thenDeps); + +export const useDelValueCallback = ( + valueId: Id | GetId, + storeOrStoreId?: StoreOrStoreId, + then?: (store: Store) => void, + thenDeps?: DependencyList, +): ParameterizedCallback => + useDel(storeOrStoreId, VALUE, then, thenDeps, valueId); + +export const useHasTablesListener = ( + listener: HasTablesListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, +): void => + useListener( + HAS + TABLES, + useStoreOrStoreById(storeOrStoreId), + listener, + listenerDeps, + [], + mutator, + ); + +export const useTablesListener = ( + listener: TablesListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, +): void => + useListener( + TABLES, + useStoreOrStoreById(storeOrStoreId), + listener, + listenerDeps, + EMPTY_ARRAY, + mutator, + ); + +export const useTableIdsListener = ( + listener: TableIdsListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, +): void => + useListener( + TABLE_IDS, + useStoreOrStoreById(storeOrStoreId), + listener, + listenerDeps, + EMPTY_ARRAY, + mutator, + ); + +export const useHasTableListener = ( + tableId: IdOrNull, + listener: HasTableListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, +): void => + useListener( + HAS + TABLE, + useStoreOrStoreById(storeOrStoreId), + listener, + listenerDeps, + [tableId], + mutator, + ); + +export const useTableListener = ( + tableId: IdOrNull, + listener: TableListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, +): void => + useListener( + TABLE, + useStoreOrStoreById(storeOrStoreId), + listener, + listenerDeps, + [tableId], + mutator, + ); + +export const useTableCellIdsListener = ( + tableId: IdOrNull, + listener: TableCellIdsListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, +): void => + useListener( + TABLE + CELL_IDS, + useStoreOrStoreById(storeOrStoreId), + listener, + listenerDeps, + [tableId], + mutator, + ); + +export const useHasTableCellListener = ( + tableId: IdOrNull, + cellId: IdOrNull, + listener: HasTableCellListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, +): void => + useListener( + HAS + TABLE + CELL, + useStoreOrStoreById(storeOrStoreId), + listener, + listenerDeps, + [tableId, cellId], + mutator, + ); + +export const useRowCountListener = ( + tableId: IdOrNull, + listener: RowCountListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, +): void => + useListener( + ROW_COUNT, + useStoreOrStoreById(storeOrStoreId), + listener, + listenerDeps, + [tableId], + mutator, + ); + +export const useRowIdsListener = ( + tableId: IdOrNull, + listener: RowIdsListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, +): void => + useListener( + ROW_IDS, + useStoreOrStoreById(storeOrStoreId), + listener, + listenerDeps, + [tableId], + mutator, + ); + +export const useSortedRowIdsListener = ( + tableIdOrArgs: Id | SortedRowIdsArgs, + cellIdOrListener: Id | undefined | SortedRowIdsListener, + descendingOrListenerDeps: boolean | DependencyList | undefined, + offsetOrMutator: number | boolean | undefined, + limitOrStoreOrStoreId: number | undefined | StoreOrStoreId, + listener?: SortedRowIdsListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, +): void => + (useSortedRowIdsListenerImpl as any)( + ...(isObject(tableIdOrArgs) + ? [ + tableIdOrArgs.tableId, + tableIdOrArgs.cellId, + tableIdOrArgs.descending ?? false, + tableIdOrArgs.offset ?? 0, + tableIdOrArgs.limit, + cellIdOrListener, + descendingOrListenerDeps, + offsetOrMutator, + limitOrStoreOrStoreId, + ] + : [ + tableIdOrArgs, + cellIdOrListener, + descendingOrListenerDeps, + offsetOrMutator, + limitOrStoreOrStoreId, + listener, + listenerDeps, + mutator, + storeOrStoreId, + ]), + ); + +export const useHasRowListener = ( + tableId: IdOrNull, + rowId: IdOrNull, + listener: HasRowListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, +): void => + useListener( + HAS + ROW, + useStoreOrStoreById(storeOrStoreId), + listener, + listenerDeps, + [tableId, rowId], + mutator, + ); + +export const useRowListener = ( + tableId: IdOrNull, + rowId: IdOrNull, + listener: RowListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, +): void => + useListener( + ROW, + useStoreOrStoreById(storeOrStoreId), + listener, + listenerDeps, + [tableId, rowId], + mutator, + ); + +export const useCellIdsListener = ( + tableId: IdOrNull, + rowId: IdOrNull, + listener: CellIdsListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, +): void => + useListener( + CELL_IDS, + useStoreOrStoreById(storeOrStoreId), + listener, + listenerDeps, + [tableId, rowId], + mutator, + ); + +export const useHasCellListener = ( + tableId: IdOrNull, + rowId: IdOrNull, + cellId: IdOrNull, + listener: HasCellListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, +): void => + useListener( + HAS + CELL, + useStoreOrStoreById(storeOrStoreId), + listener, + listenerDeps, + [tableId, rowId, cellId], + mutator, + ); + +export const useCellListener = ( + tableId: IdOrNull, + rowId: IdOrNull, + cellId: IdOrNull, + listener: CellListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, +): void => + useListener( + CELL, + useStoreOrStoreById(storeOrStoreId), + listener, + listenerDeps, + [tableId, rowId, cellId], + mutator, + ); + +export const useHasValuesListener = ( + listener: HasValuesListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, +): void => + useListener( + HAS + VALUES, + useStoreOrStoreById(storeOrStoreId), + listener, + listenerDeps, + [], + mutator, + ); + +export const useValuesListener = ( + listener: ValuesListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, +): void => + useListener( + VALUES, + useStoreOrStoreById(storeOrStoreId), + listener, + listenerDeps, + EMPTY_ARRAY, + mutator, + ); + +export const useValueIdsListener = ( + listener: ValueIdsListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, +): void => + useListener( + VALUE_IDS, + useStoreOrStoreById(storeOrStoreId), + listener, + listenerDeps, + EMPTY_ARRAY, + mutator, + ); + +export const useHasValueListener = ( + valueId: IdOrNull, + listener: HasValueListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, +): void => + useListener( + HAS + VALUE, + useStoreOrStoreById(storeOrStoreId), + listener, + listenerDeps, + [valueId], + mutator, + ); + +export const useValueListener = ( + valueId: IdOrNull, + listener: ValueListener, + listenerDeps?: DependencyList, + mutator?: boolean, + storeOrStoreId?: StoreOrStoreId, +): void => + useListener( + VALUE, + useStoreOrStoreById(storeOrStoreId), + listener, + listenerDeps, + [valueId], + mutator, + ); + +export const useStartTransactionListener = + ( + listener: TransactionListener, + listenerDeps?: DependencyList, + storeOrStoreId?: StoreOrStoreId, + ): void => + useListener( + 'Start' + TRANSACTION, + useStoreOrStoreById(storeOrStoreId), + listener, + listenerDeps, + ); + +export const useWillFinishTransactionListener = + ( + listener: TransactionListener, + listenerDeps?: DependencyList, + storeOrStoreId?: StoreOrStoreId, + ): void => + useListener( + 'Will' + FINISH + TRANSACTION, + useStoreOrStoreById(storeOrStoreId), + listener, + listenerDeps, + ); + +export const useDidFinishTransactionListener = + ( + listener: TransactionListener, + listenerDeps?: DependencyList, + storeOrStoreId?: StoreOrStoreId, + ): void => + useListener( + 'Did' + FINISH + TRANSACTION, + useStoreOrStoreById(storeOrStoreId), + listener, + listenerDeps, + ); + +export const useCreateMetrics = ( + store: Store | undefined, + create: (store: Store) => Metrics, + createDeps?: DependencyList, +): Metrics | undefined => useCreate(store, create, createDeps); + +export const useMetricsIds = () => + useThingIds(OFFSET_METRICS) as any; + +export const useMetrics = ( + id?: Id, +): Metrics | undefined => useThing(id, OFFSET_METRICS) as any; + +export const useMetricsOrMetricsById = ( + metricsOrMetricsId?: MetricsOrMetricsId, +): Metrics | undefined => + useThingOrThingById(metricsOrMetricsId, OFFSET_METRICS) as any; + +export const useProvideMetrics = ( + metricsId: Id, + metrics: Metrics, +): void => useProvideThing(metricsId, metrics, OFFSET_METRICS); + +export const useMetricIds = ( + metricsOrMetricsId?: MetricsOrMetricsId, +): Ids => + useListenable( + METRIC + IDS, + useMetricsOrMetricsById(metricsOrMetricsId), + ReturnType.Array, + ); + +export const useMetric = ( + metricId: Id, + metricsOrMetricsId?: MetricsOrMetricsId, +): number | undefined => + useListenable( + METRIC, + useMetricsOrMetricsById(metricsOrMetricsId), + ReturnType.CellOrValue, + [metricId], + ); + +export const useMetricListener = ( + metricId: IdOrNull, + listener: MetricListener, + listenerDeps?: DependencyList, + metricsOrMetricsId?: MetricsOrMetricsId, +): void => + useListener( + METRIC, + useMetricsOrMetricsById(metricsOrMetricsId), + listener, + listenerDeps, + [metricId], + ); + +export const useCreateIndexes = ( + store: Store | undefined, + create: (store: Store) => Indexes, + createDeps?: DependencyList, +): Indexes | undefined => useCreate(store, create, createDeps); + +export const useIndexesIds = () => + useThingIds(OFFSET_INDEXES) as any; + +export const useIndexes = ( + id?: Id, +): Indexes | undefined => useThing(id, OFFSET_INDEXES) as any; + +export const useIndexesOrIndexesById = ( + indexesOrIndexesId?: IndexesOrIndexesId, +): Indexes | undefined => + useThingOrThingById(indexesOrIndexesId, OFFSET_INDEXES) as any; + +export const useProvideIndexes = ( + indexesId: Id, + indexes: Indexes, +): void => useProvideThing(indexesId, indexes, OFFSET_INDEXES); + +export const useSliceIds = ( + indexId: Id, + indexesOrIndexesId?: IndexesOrIndexesId, +): Ids => + useListenable( + SLICE + IDS, + useIndexesOrIndexesById(indexesOrIndexesId), + ReturnType.Array, + [indexId], + ); + +export const useIndexIds = ( + indexesOrIndexesId?: IndexesOrIndexesId, +): Ids => + useListenable( + INDEX + IDS, + useIndexesOrIndexesById(indexesOrIndexesId), + ReturnType.Array, + ); + +export const useSliceRowIds = ( + indexId: Id, + sliceId: Id, + indexesOrIndexesId?: IndexesOrIndexesId, +): Ids => + useListenable( + SLICE + ROW_IDS, + useIndexesOrIndexesById(indexesOrIndexesId), + ReturnType.Array, + [indexId, sliceId], + ); + +export const useSliceIdsListener = ( + indexId: IdOrNull, + listener: SliceIdsListener, + listenerDeps?: DependencyList, + indexesOrIndexesId?: IndexesOrIndexesId, +): void => + useListener( + SLICE + IDS, + useIndexesOrIndexesById(indexesOrIndexesId), + listener, + listenerDeps, + [indexId], + ); + +export const useSliceRowIdsListener = ( + indexId: IdOrNull, + sliceId: IdOrNull, + listener: SliceRowIdsListener, + listenerDeps?: DependencyList, + indexesOrIndexesId?: IndexesOrIndexesId, +): void => + useListener( + SLICE + ROW_IDS, + useIndexesOrIndexesById(indexesOrIndexesId), + listener, + listenerDeps, + [indexId, sliceId], + ); + +export const useCreateRelationships = ( + store: Store | undefined, + create: (store: Store) => Relationships, + createDeps?: DependencyList, +): Relationships | undefined => useCreate(store, create, createDeps); + +export const useRelationshipsIds = () => + useThingIds(OFFSET_RELATIONSHIPS) as any; + +export const useRelationships = ( + id?: Id, +): Relationships | undefined => useThing(id, OFFSET_RELATIONSHIPS) as any; + +export const useRelationshipsOrRelationshipsById = + ( + relationshipsOrRelationshipsId?: RelationshipsOrRelationshipsId, + ): Relationships | undefined => + useThingOrThingById( + relationshipsOrRelationshipsId, + OFFSET_RELATIONSHIPS, + ) as any; + +export const useProvideRelationships = ( + relationshipsId: Id, + relationships: Relationships, +): void => + useProvideThing(relationshipsId, relationships, OFFSET_RELATIONSHIPS); + +export const useRelationshipIds = ( + relationshipsOrRelationshipsId?: RelationshipsOrRelationshipsId, +): Ids => + useListenable( + RELATIONSHIP + IDS, + useRelationshipsOrRelationshipsById(relationshipsOrRelationshipsId), + ReturnType.Array, + ); + +export const useRemoteRowId = ( + relationshipId: Id, + localRowId: Id, + relationshipsOrRelationshipsId?: RelationshipsOrRelationshipsId, +): Id | undefined => + useListenable( + REMOTE_ROW_ID, + useRelationshipsOrRelationshipsById(relationshipsOrRelationshipsId), + ReturnType.CellOrValue, + [relationshipId, localRowId], + ); + +export const useLocalRowIds = ( + relationshipId: Id, + remoteRowId: Id, + relationshipsOrRelationshipsId?: RelationshipsOrRelationshipsId, +): Ids => + useListenable( + LOCAL + ROW_IDS, + useRelationshipsOrRelationshipsById(relationshipsOrRelationshipsId), + ReturnType.Array, + [relationshipId, remoteRowId], + ); + +export const useLinkedRowIds = ( + relationshipId: Id, + firstRowId: Id, + relationshipsOrRelationshipsId?: RelationshipsOrRelationshipsId, +): Ids => + useListenable( + LINKED + ROW_IDS, + useRelationshipsOrRelationshipsById(relationshipsOrRelationshipsId), + ReturnType.Array, + [relationshipId, firstRowId], + ); + +export const useRemoteRowIdListener = ( + relationshipId: IdOrNull, + localRowId: IdOrNull, + listener: RemoteRowIdListener, + listenerDeps?: DependencyList, + relationshipsOrRelationshipsId?: RelationshipsOrRelationshipsId, +): void => + useListener( + REMOTE_ROW_ID, + useRelationshipsOrRelationshipsById(relationshipsOrRelationshipsId), + listener, + listenerDeps, + [relationshipId, localRowId], + ); + +export const useLocalRowIdsListener = ( + relationshipId: IdOrNull, + remoteRowId: IdOrNull, + listener: LocalRowIdsListener, + listenerDeps?: DependencyList, + relationshipsOrRelationshipsId?: RelationshipsOrRelationshipsId, +): void => + useListener( + LOCAL + ROW_IDS, + useRelationshipsOrRelationshipsById(relationshipsOrRelationshipsId), + listener, + listenerDeps, + [relationshipId, remoteRowId], + ); + +export const useLinkedRowIdsListener = ( + relationshipId: Id, + firstRowId: Id, + listener: LinkedRowIdsListener, + listenerDeps?: DependencyList, + relationshipsOrRelationshipsId?: RelationshipsOrRelationshipsId, +): void => + useListener( + LINKED + ROW_IDS, + useRelationshipsOrRelationshipsById(relationshipsOrRelationshipsId), + listener, + listenerDeps, + [relationshipId, firstRowId], + ); + +export const useCreateQueries = ( + store: Store | undefined, + create: (store: Store) => Queries, + createDeps?: DependencyList, +): Queries | undefined => useCreate(store, create, createDeps); + +export const useQueriesIds = () => + useThingIds(OFFSET_QUERIES) as any; + +export const useQueries = ( + id?: Id, +): Queries | undefined => useThing(id, OFFSET_QUERIES) as any; + +export const useQueriesOrQueriesById = ( + queriesOrQueriesId?: QueriesOrQueriesId, +): Queries | undefined => + useThingOrThingById(queriesOrQueriesId, OFFSET_QUERIES) as any; + +export const useProvideQueries = ( + queriesId: Id, + queries: Queries, +): void => useProvideThing(queriesId, queries, OFFSET_QUERIES); + +export const useQueryIds = ( + queriesOrQueriesId?: QueriesOrQueriesId, +): Ids => + useListenable( + QUERY + IDS, + useQueriesOrQueriesById(queriesOrQueriesId), + ReturnType.Array, + ); + +export const useResultTable = ( + queryId: Id, + queriesOrQueriesId?: QueriesOrQueriesId, +): Table => + useListenable( + RESULT + TABLE, + useQueriesOrQueriesById(queriesOrQueriesId), + ReturnType.Object, + [queryId], + ); + +export const useResultTableCellIds = ( + queryId: Id, + queriesOrQueriesId?: QueriesOrQueriesId, +): Ids => + useListenable( + RESULT + TABLE + CELL_IDS, + useQueriesOrQueriesById(queriesOrQueriesId), + ReturnType.Array, + [queryId], + ); + +export const useResultRowCount = ( + queryId: Id, + queriesOrQueriesId?: QueriesOrQueriesId, +): number => + useListenable( + RESULT + ROW_COUNT, + useQueriesOrQueriesById(queriesOrQueriesId), + ReturnType.Number, + [queryId], + ); + +export const useResultRowIds = ( + queryId: Id, + queriesOrQueriesId?: QueriesOrQueriesId, +): Ids => + useListenable( + RESULT + ROW_IDS, + useQueriesOrQueriesById(queriesOrQueriesId), + ReturnType.Array, + [queryId], + ); + +export const useResultSortedRowIds = ( + queryId: Id, + cellId?: Id, + descending?: boolean, + offset = 0, + limit?: number, + queriesOrQueriesId?: QueriesOrQueriesId, +): Ids => + useListenable( + RESULT + SORTED_ROW_IDS, + useQueriesOrQueriesById(queriesOrQueriesId), + ReturnType.Array, + [queryId, cellId, descending, offset, limit], + ); + +export const useResultRow = ( + queryId: Id, + rowId: Id, + queriesOrQueriesId?: QueriesOrQueriesId, +): Row => + useListenable( + RESULT + ROW, + useQueriesOrQueriesById(queriesOrQueriesId), + ReturnType.Object, + [queryId, rowId], + ); + +export const useResultCellIds = ( + queryId: Id, + rowId: Id, + queriesOrQueriesId?: QueriesOrQueriesId, +): Ids => + useListenable( + RESULT + CELL_IDS, + useQueriesOrQueriesById(queriesOrQueriesId), + ReturnType.Array, + [queryId, rowId], + ); + +export const useResultCell = ( + queryId: Id, + rowId: Id, + cellId: Id, + queriesOrQueriesId?: QueriesOrQueriesId, +): Cell | undefined => + useListenable( + RESULT + CELL, + useQueriesOrQueriesById(queriesOrQueriesId), + ReturnType.CellOrValue, + [queryId, rowId, cellId], + ); + +export const useResultTableListener = ( + queryId: IdOrNull, + listener: ResultTableListener, + listenerDeps?: DependencyList, + queriesOrQueriesId?: QueriesOrQueriesId, +): void => + useListener( + RESULT + TABLE, + useQueriesOrQueriesById(queriesOrQueriesId), + listener, + listenerDeps, + [queryId], + ); + +export const useResultTableCellIdsListener = + ( + queryId: IdOrNull, + listener: ResultTableCellIdsListener, + listenerDeps?: DependencyList, + queriesOrQueriesId?: QueriesOrQueriesId, + ): void => + useListener( + RESULT + TABLE + CELL_IDS, + useQueriesOrQueriesById(queriesOrQueriesId), + listener, + listenerDeps, + [queryId], + ); + +export const useResultRowCountListener = ( + queryId: IdOrNull, + listener: ResultRowCountListener, + listenerDeps?: DependencyList, + queriesOrQueriesId?: QueriesOrQueriesId, +): void => + useListener( + RESULT + ROW_COUNT, + useQueriesOrQueriesById(queriesOrQueriesId), + listener, + listenerDeps, + [queryId], + ); + +export const useResultRowIdsListener = ( + queryId: IdOrNull, + listener: ResultRowIdsListener, + listenerDeps?: DependencyList, + queriesOrQueriesId?: QueriesOrQueriesId, +): void => + useListener( + RESULT + ROW_IDS, + useQueriesOrQueriesById(queriesOrQueriesId), + listener, + listenerDeps, + [queryId], + ); + +export const useResultSortedRowIdsListener = + ( + queryId: Id, + cellId: Id | undefined, + descending: boolean, + offset: number, + limit: number | undefined, + listener: ResultSortedRowIdsListener, + listenerDeps?: DependencyList, + queriesOrQueriesId?: QueriesOrQueriesId, + ): void => + useListener( + RESULT + SORTED_ROW_IDS, + useQueriesOrQueriesById(queriesOrQueriesId), + listener, + listenerDeps, + [queryId, cellId, descending, offset, limit], + ); + +export const useResultRowListener = ( + queryId: IdOrNull, + rowId: IdOrNull, + listener: ResultRowListener, + listenerDeps?: DependencyList, + queriesOrQueriesId?: QueriesOrQueriesId, +): void => + useListener( + RESULT + ROW, + useQueriesOrQueriesById(queriesOrQueriesId), + listener, + listenerDeps, + [queryId, rowId], + ); + +export const useResultCellIdsListener = ( + queryId: IdOrNull, + rowId: IdOrNull, + listener: ResultCellIdsListener, + listenerDeps?: DependencyList, + queriesOrQueriesId?: QueriesOrQueriesId, +): void => + useListener( + RESULT + CELL_IDS, + useQueriesOrQueriesById(queriesOrQueriesId), + listener, + listenerDeps, + [queryId, rowId], + ); + +export const useResultCellListener = ( + queryId: IdOrNull, + rowId: IdOrNull, + cellId: IdOrNull, + listener: ResultCellListener, + listenerDeps?: DependencyList, + queriesOrQueriesId?: QueriesOrQueriesId, +): void => + useListener( + RESULT + CELL, + useQueriesOrQueriesById(queriesOrQueriesId), + listener, + listenerDeps, + [queryId, rowId, cellId], + ); + +export const useParamValues = ( + queryId: Id, + queriesOrQueriesId?: QueriesOrQueriesId, +): ParamValues => + useListenable( + 'ParamValues', + useQueriesOrQueriesById(queriesOrQueriesId), + ReturnType.ParamValues, + [queryId], + ); + +export const useParamValuesState = ( + queryId: Id, + queriesOrQueriesId?: QueriesOrQueriesId, +): [ParamValues, (paramValues: ParamValues) => void] => [ + useParamValues(queryId, queriesOrQueriesId), + useSetParamValuesCallback(queryId, getArg, [], queriesOrQueriesId), +]; + +export const useParamValue = ( + queryId: Id, + paramId: Id, + queriesOrQueriesId?: QueriesOrQueriesId, +): ParamValue | undefined => + useListenable( + 'ParamValue', + useQueriesOrQueriesById(queriesOrQueriesId), + ReturnType.ParamValue, + [queryId, paramId], + ); + +export const useParamValueState = ( + queryId: Id, + paramId: Id, + queriesOrQueriesId?: QueriesOrQueriesId, +): [ParamValue | undefined, (paramValue: ParamValue) => void] => [ + useParamValue(queryId, paramId, queriesOrQueriesId), + useSetParamValueCallback(queryId, paramId, getArg, [], queriesOrQueriesId), +]; + +export const useParamValuesListener = ( + queryId: IdOrNull, + listener: ParamValuesListener, + listenerDeps?: DependencyList, + queriesOrQueriesId?: QueriesOrQueriesId, +): void => + useListener( + 'ParamValues', + useQueriesOrQueriesById(queriesOrQueriesId), + listener, + listenerDeps, + [queryId], + ); + +export const useParamValueListener = ( + queryId: IdOrNull, + paramId: IdOrNull, + listener: ParamValueListener, + listenerDeps?: DependencyList, + queriesOrQueriesId?: QueriesOrQueriesId, +): void => + useListener( + 'ParamValue', + useQueriesOrQueriesById(queriesOrQueriesId), + listener, + listenerDeps, + [queryId, paramId], + ); + +export const useSetParamValueCallback = < + Parameter, +>( + queryId: Id | GetId, + paramId: Id | GetId, + getParamValue: (parameter: Parameter, queries: Queries) => ParamValue, + getParamValueDeps?: DependencyList, + queriesOrQueriesId?: QueriesOrQueriesId, + then?: (queries: Queries, paramValue: ParamValue) => void, + thenDeps?: DependencyList, +): ParameterizedCallback => + useQueriesSetCallback( + queriesOrQueriesId, + 'setParamValue', + getParamValue, + getParamValueDeps, + then, + thenDeps, + queryId, + paramId, + ); + +export const useSetParamValuesCallback = < + Parameter, +>( + queryId: Id | GetId, + getParamValues: (parameter: Parameter, queries: Queries) => ParamValues, + getParamValuesDeps?: DependencyList, + queriesOrQueriesId?: QueriesOrQueriesId, + then?: (queries: Queries, paramValues: ParamValues) => void, + thenDeps?: DependencyList, +): ParameterizedCallback => + useQueriesSetCallback( + queriesOrQueriesId, + 'setParamValues', + getParamValues, + getParamValuesDeps, + then, + thenDeps, + queryId, + ); + +export const useCreateCheckpoints = ( + store: Store | undefined, + create: (store: Store) => Checkpoints, + createDeps?: DependencyList, +): Checkpoints | undefined => useCreate(store, create, createDeps); + +export const useCheckpointsIds = () => + useThingIds(OFFSET_CHECKPOINTS) as any; + +export const useCheckpoints = ( + id?: Id, +): Checkpoints | undefined => useThing(id, OFFSET_CHECKPOINTS) as any; + +export const useCheckpointsOrCheckpointsById = + ( + checkpointsOrCheckpointsId?: CheckpointsOrCheckpointsId, + ): Checkpoints | undefined => + useThingOrThingById(checkpointsOrCheckpointsId, OFFSET_CHECKPOINTS) as any; + +export const useProvideCheckpoints = ( + checkpointsId: Id, + checkpoints: Checkpoints, +): void => useProvideThing(checkpointsId, checkpoints, OFFSET_CHECKPOINTS); + +export const useCheckpointIds = ( + checkpointsOrCheckpointsId?: CheckpointsOrCheckpointsId, +): CheckpointIds => + useListenable( + CHECKPOINT + IDS, + useCheckpointsOrCheckpointsById(checkpointsOrCheckpointsId), + ReturnType.Checkpoints, + ); + +export const useCheckpoint = ( + checkpointId: Id, + checkpointsOrCheckpointsId?: CheckpointsOrCheckpointsId, +): string | undefined => + useListenable( + CHECKPOINT, + useCheckpointsOrCheckpointsById(checkpointsOrCheckpointsId), + ReturnType.CellOrValue, + [checkpointId], + ); + +export const useSetCheckpointCallback = < + Parameter, +>( + getCheckpoint: (parameter: Parameter) => string | undefined = getUndefined, + _getCheckpointDeps: DependencyList = EMPTY_ARRAY, + checkpointsOrCheckpointsId?: CheckpointsOrCheckpointsId, + then: ( + checkpointId: Id, + checkpoints: Checkpoints, + label?: string, + ) => void = getUndefined, + _thenDeps: DependencyList = EMPTY_ARRAY, +): ParameterizedCallback => { + const checkpoints = useCheckpointsOrCheckpointsById( + checkpointsOrCheckpointsId, + ); + return (parameter) => + ifNotUndefined(getThing(checkpoints), (resolvedCheckpoints) => { + const label = getCheckpoint(parameter as any); + then( + resolvedCheckpoints.addCheckpoint(label), + resolvedCheckpoints, + label, + ); + }); +}; + +export const useGoBackwardCallback = ( + checkpointsOrCheckpointsId?: CheckpointsOrCheckpointsId, +): Callback => useCheckpointAction(checkpointsOrCheckpointsId, 'goBackward'); + +export const useGoForwardCallback = ( + checkpointsOrCheckpointsId?: CheckpointsOrCheckpointsId, +): Callback => useCheckpointAction(checkpointsOrCheckpointsId, 'goForward'); + +export const useGoToCallback = ( + getCheckpointId: (parameter: Parameter) => Id, + _getCheckpointIdDeps: DependencyList = EMPTY_ARRAY, + checkpointsOrCheckpointsId?: CheckpointsOrCheckpointsId, + then: (checkpoints: Checkpoints, checkpointId: Id) => void = getUndefined, + _thenDeps: DependencyList = EMPTY_ARRAY, +): ParameterizedCallback => { + const checkpoints = useCheckpointsOrCheckpointsById( + checkpointsOrCheckpointsId, + ); + return (parameter) => + ifNotUndefined(getThing(checkpoints), (resolvedCheckpoints) => + ifNotUndefined(getCheckpointId(parameter as any), (checkpointId: Id) => + then(resolvedCheckpoints.goTo(checkpointId), checkpointId), + ), + ); +}; + +export const useUndoInformation = ( + checkpointsOrCheckpointsId?: CheckpointsOrCheckpointsId, +): UndoOrRedoInformation => { + const checkpoints = useCheckpointsOrCheckpointsById( + checkpointsOrCheckpointsId, + ); + const [backwardIds, currentId] = getThing(useCheckpointIds(checkpoints)); + return [ + !arrayIsEmpty(backwardIds), + useGoBackwardCallback(checkpoints), + currentId, + ifNotUndefined( + currentId, + (id) => getThing(checkpoints)?.getCheckpoint(id), + ) ?? EMPTY_STRING, + ]; +}; + +export const useRedoInformation = ( + checkpointsOrCheckpointsId?: CheckpointsOrCheckpointsId, +): UndoOrRedoInformation => { + const checkpoints = useCheckpointsOrCheckpointsById( + checkpointsOrCheckpointsId, + ); + const [, , [forwardId]] = getThing(useCheckpointIds(checkpoints)); + return [ + !isUndefined(forwardId), + useGoForwardCallback(checkpoints), + forwardId, + ifNotUndefined( + forwardId, + (id) => getThing(checkpoints)?.getCheckpoint(id), + ) ?? EMPTY_STRING, + ]; +}; + +export const useCheckpointIdsListener = ( + listener: CheckpointIdsListener, + listenerDeps?: DependencyList, + checkpointsOrCheckpointsId?: CheckpointsOrCheckpointsId, +): void => + useListener( + CHECKPOINT + IDS, + useCheckpointsOrCheckpointsById(checkpointsOrCheckpointsId), + listener, + listenerDeps, + ); + +export const useCheckpointListener = ( + checkpointId: IdOrNull, + listener: CheckpointListener, + listenerDeps?: DependencyList, + checkpointsOrCheckpointsId?: CheckpointsOrCheckpointsId, +): void => + useListener( + CHECKPOINT, + useCheckpointsOrCheckpointsById(checkpointsOrCheckpointsId), + listener, + listenerDeps, + [checkpointId], + ); + +export const useCreatePersister = < + Persist extends Persists, + PersisterOrUndefined extends Persister | undefined, +>( + store: PersistedStore | undefined, + create: ( + store: PersistedStore, + ) => PersisterOrUndefined | Promise, + _createDeps: DependencyList = EMPTY_ARRAY, + then?: (persister: Persister) => Promise, + _thenDeps: DependencyList = EMPTY_ARRAY, + destroy?: (persister: Persister) => void, + _destroyDeps: DependencyList = EMPTY_ARRAY, +): PersisterOrUndefined => { + const [persister, setPersister] = createSignal(); + createEffect(() => { + (async () => { + const createdPersister = store ? await create(store) : undefined; + setPersister(() => createdPersister); + if (createdPersister && then) { + await then(createdPersister); + } + })(); + }); + createEffect(() => + onCleanup(() => { + const resolvedPersister = getThing(persister); + if (resolvedPersister) { + resolvedPersister.destroy(); + destroy?.(resolvedPersister); + } + }), + ); + return persister as any; +}; + +export const usePersisterIds = () => + useThingIds(OFFSET_PERSISTER) as any; + +export const usePersister = ( + id?: Id, +): AnyPersister | undefined => useThing(id, OFFSET_PERSISTER) as any; + +export const usePersisterOrPersisterById = + (persisterOrPersisterId?: PersisterOrPersisterId): AnyPersister | undefined => + useThingOrThingById(persisterOrPersisterId, OFFSET_PERSISTER) as any; + +export const useProvidePersister = ( + persisterId: Id, + persister: AnyPersister, +): void => useProvideThing(persisterId, persister, OFFSET_PERSISTER); + +export const usePersisterStatus = ( + persisterOrPersisterId?: PersisterOrPersisterId, +): Status => + useListenable( + STATUS, + usePersisterOrPersisterById(persisterOrPersisterId), + ReturnType.Number, + [], + ); + +export const usePersisterStatusListener = + ( + listener: StatusListener, + listenerDeps?: DependencyList, + persisterOrPersisterId?: PersisterOrPersisterId, + ): void => + useListener( + STATUS, + usePersisterOrPersisterById(persisterOrPersisterId), + listener, + listenerDeps, + [], + ); + +export const useCreateSynchronizer = < + SynchronizerOrUndefined extends Synchronizer | undefined, +>( + store: MergeableStore | undefined, + create: (store: MergeableStore) => Promise, + _createDeps: DependencyList = EMPTY_ARRAY, + destroy?: (synchronizer: Synchronizer) => void, + _destroyDeps: DependencyList = EMPTY_ARRAY, +): SynchronizerOrUndefined => { + const [synchronizer, setSynchronizer] = createSignal(); + createEffect(() => { + (async () => { + const createdSynchronizer = store ? await create(store) : undefined; + setSynchronizer(() => createdSynchronizer); + })(); + }); + createEffect(() => + onCleanup(() => { + const resolvedSynchronizer = getThing(synchronizer); + if (resolvedSynchronizer) { + resolvedSynchronizer.destroy(); + destroy?.(resolvedSynchronizer); + } + }), + ); + return synchronizer as any; +}; + +export const useSynchronizerIds = () => + useThingIds(OFFSET_SYNCHRONIZER) as any; + +export const useSynchronizer = ( + id?: Id, +): Synchronizer | undefined => useThing(id, OFFSET_SYNCHRONIZER) as any; + +export const useSynchronizerOrSynchronizerById = + ( + synchronizerOrSynchronizerId?: SynchronizerOrSynchronizerId, + ): Synchronizer | undefined => + useThingOrThingById( + synchronizerOrSynchronizerId, + OFFSET_SYNCHRONIZER, + ) as any; + +export const useProvideSynchronizer = ( + persisterId: Id, + persister: Synchronizer, +): void => useProvideThing(persisterId, persister, OFFSET_SYNCHRONIZER); + +export const useSynchronizerStatus = ( + synchronizerOrSynchronizerId?: SynchronizerOrSynchronizerId, +): Status => + useListenable( + STATUS, + useSynchronizerOrSynchronizerById(synchronizerOrSynchronizerId), + ReturnType.Number, + [], + ); + +export const useSynchronizerStatusListener = + ( + listener: StatusListener, + listenerDeps?: DependencyList, + synchronizerOrSynchronizerId?: SynchronizerOrSynchronizerId, + ): void => + useListener( + STATUS, + useSynchronizerOrSynchronizerById(synchronizerOrSynchronizerId), + listener, + listenerDeps, + [], + ); diff --git a/src/ui-solid/index.ts b/src/ui-solid/index.ts new file mode 100644 index 00000000000..42d1b86e9fc --- /dev/null +++ b/src/ui-solid/index.ts @@ -0,0 +1,24 @@ +export * from './hooks.ts'; + +export * from './BackwardCheckpointsView.tsx'; +export * from './CellView.tsx'; +export * from './CheckpointView.tsx'; +export * from './CurrentCheckpointView.tsx'; +export * from './ForwardCheckpointsView.tsx'; +export * from './IndexView.tsx'; +export * from './LinkedRowsView.tsx'; +export * from './LocalRowsView.tsx'; +export * from './MetricView.tsx'; +export * from './Provider.tsx'; +export * from './RemoteRowView.tsx'; +export * from './ResultCellView.tsx'; +export * from './ResultRowView.tsx'; +export * from './ResultSortedTableView.tsx'; +export * from './ResultTableView.tsx'; +export * from './RowView.tsx'; +export * from './SliceView.tsx'; +export * from './SortedTableView.tsx'; +export * from './TablesView.tsx'; +export * from './TableView.tsx'; +export * from './ValuesView.tsx'; +export * from './ValueView.tsx';