Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More โ†’
Socket
Sign inDemoInstall
Socket

@hazae41/glacier

Package Overview
Dependencies
Maintainers
1
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hazae41/glacier - npm Package Compare versions

Comparing version 2.0.0-102 to 2.0.0-103

dist/cjs/mods/coders/coder.cjs

26

dist/types/index.d.ts
import * as index from './mods/index.js';
export { index as Glacier };
export { AsyncBicoder, AsyncEncoder, AsyncJson, AsyncPipeBicoder, AsyncPipeEncoder, Bicoder, Encoder, SyncBicoder, SyncEncoder, SyncIdentity, SyncJson, SyncPipeBicoder, SyncPipeEncoder } from './mods/coders/coder.js';
export { AesGcmCoder } from './mods/coders/crypto/aes/gcm.js';
export { CryptoError } from './mods/coders/crypto/error/error.js';
export { HmacEncoder } from './mods/coders/crypto/hmac/hmac.js';
export { AsyncStorageError, CooldownError, Core, MissingFetcherError, MissingKeyError, QueryMetadata, TimeoutError, core } from './mods/core/core.js';
export { DEFAULT_EQUALS, DEFAULT_SERIALIZER } from './mods/defaults.js';
export { Equals, Equalser } from './mods/equals/equals.js';
export { Data, DataInit } from './mods/fetched/data.js';
export { Fail, FailInit } from './mods/fetched/fail.js';
export { Fetched, FetchedInit } from './mods/fetched/fetched.js';
export { Times, TimesInit } from './mods/fetched/times.js';
export { ScrollError, Scrollable } from './mods/queries/scroll/helper.js';
export { ScrollableFetcherfulQuery, ScrollableFetcherlessQuery, ScrollableQuery, ScrollableSkeletonQuery, createScrollableQuery } from './mods/queries/scroll/query.js';
export { Simple } from './mods/queries/simple/helper.js';
export { SimpleFetcherfulQuery, SimpleFetcherlessQuery, SimpleQuery, SimpleSkeletonQuery, createQuery } from './mods/queries/simple/query.js';
export { useDebug } from './mods/react/hooks/blocks/use-debug.js';

@@ -17,16 +29,4 @@ export { useError } from './mods/react/hooks/blocks/use-error.js';

export { ScrollableFetcherfulReactQuery, ScrollableFetcherlessReactQuery, ScrollableSkeletonReactQuery, useFetcherfulScrollableQuery, useFetcherlessScrollableQuery, useScrollableQuery, useSkeletonScrollableQuery } from './mods/react/hooks/queries/scroll.js';
export { SimpleFetcherfulReactQuery, SimpleFetcherlessReactQuery, SimpleSkeletonReactQuery, useQuery, useSimpleFetcherfulQuery, useSimpleFetcherlessQuery, useSimpleSkeletonQuery } from './mods/react/hooks/queries/single.js';
export { SimpleFetcherfulReactQuery, SimpleFetcherlessReactQuery, SimpleSkeletonReactQuery, useQuery, useSimpleFetcherfulQuery, useSimpleFetcherlessQuery, useSimpleSkeletonQuery } from './mods/react/hooks/queries/simple.js';
export { FetcherfulReactQuery, FetcherlessReactQuery, ReactQuery, SkeletonReactQuery } from './mods/react/types/query.js';
export { Data, DataInit } from './mods/result/data.js';
export { Fail, FailInit } from './mods/result/fail.js';
export { Fetched, FetchedInit } from './mods/result/fetched.js';
export { Times, TimesInit } from './mods/result/times.js';
export { ScrollError, Scrollable } from './mods/scroll/helper.js';
export { ScrollableFetcherfulQuery, ScrollableFetcherlessQuery, ScrollableQuery, ScrollableSkeletonQuery, createScrollableQuery } from './mods/scroll/query.js';
export { AsyncBicoder, AsyncEncoder, AsyncJson, AsyncPipeBicoder, AsyncPipeEncoder, Bicoder, Encoder, SyncBicoder, SyncEncoder, SyncIdentity, SyncJson, SyncPipeBicoder, SyncPipeEncoder } from './mods/serializers/coder.js';
export { AesGcmCoder } from './mods/serializers/crypto/aes/gcm.js';
export { CryptoError } from './mods/serializers/crypto/error/error.js';
export { HmacEncoder } from './mods/serializers/crypto/hmac/hmac.js';
export { Simple } from './mods/single/helper.js';
export { SimpleFetcherfulQuery, SimpleFetcherlessQuery, SimpleQuery, SimpleSkeletonQuery, createQuery } from './mods/single/query.js';
export { StorageCreationError } from './mods/storages/errors.js';

@@ -33,0 +33,0 @@ export { IDBError, IDBStorage, IDBStorageParams, useIDBStorage } from './mods/storages/idb/basic.js';

@@ -5,3 +5,3 @@ import { Nullable, Option } from '@hazae41/option';

import { Promiseable } from '../../libs/promises/promises.js';
import { Fetched } from '../result/fetched.js';
import { Fetched } from '../fetched/fetched.js';
import { Mutator, Setter } from '../types/mutator.js';

@@ -8,0 +8,0 @@ import { QuerySettings } from '../types/settings.js';

@@ -0,4 +1,16 @@

export { AsyncBicoder, AsyncEncoder, AsyncJson, AsyncPipeBicoder, AsyncPipeEncoder, Bicoder, Encoder, SyncBicoder, SyncEncoder, SyncIdentity, SyncJson, SyncPipeBicoder, SyncPipeEncoder } from './coders/coder.js';
export { AesGcmCoder } from './coders/crypto/aes/gcm.js';
export { CryptoError } from './coders/crypto/error/error.js';
export { HmacEncoder } from './coders/crypto/hmac/hmac.js';
export { AsyncStorageError, CooldownError, Core, MissingFetcherError, MissingKeyError, QueryMetadata, TimeoutError, core } from './core/core.js';
export { DEFAULT_EQUALS, DEFAULT_SERIALIZER } from './defaults.js';
export { Equals, Equalser } from './equals/equals.js';
export { Data, DataInit } from './fetched/data.js';
export { Fail, FailInit } from './fetched/fail.js';
export { Fetched, FetchedInit } from './fetched/fetched.js';
export { Times, TimesInit } from './fetched/times.js';
export { ScrollError, Scrollable } from './queries/scroll/helper.js';
export { ScrollableFetcherfulQuery, ScrollableFetcherlessQuery, ScrollableQuery, ScrollableSkeletonQuery, createScrollableQuery } from './queries/scroll/query.js';
export { Simple } from './queries/simple/helper.js';
export { SimpleFetcherfulQuery, SimpleFetcherlessQuery, SimpleQuery, SimpleSkeletonQuery, createQuery } from './queries/simple/query.js';
export { useDebug } from './react/hooks/blocks/use-debug.js';

@@ -15,16 +27,4 @@ export { useError } from './react/hooks/blocks/use-error.js';

export { ScrollableFetcherfulReactQuery, ScrollableFetcherlessReactQuery, ScrollableSkeletonReactQuery, useFetcherfulScrollableQuery, useFetcherlessScrollableQuery, useScrollableQuery, useSkeletonScrollableQuery } from './react/hooks/queries/scroll.js';
export { SimpleFetcherfulReactQuery, SimpleFetcherlessReactQuery, SimpleSkeletonReactQuery, useQuery, useSimpleFetcherfulQuery, useSimpleFetcherlessQuery, useSimpleSkeletonQuery } from './react/hooks/queries/single.js';
export { SimpleFetcherfulReactQuery, SimpleFetcherlessReactQuery, SimpleSkeletonReactQuery, useQuery, useSimpleFetcherfulQuery, useSimpleFetcherlessQuery, useSimpleSkeletonQuery } from './react/hooks/queries/simple.js';
export { FetcherfulReactQuery, FetcherlessReactQuery, ReactQuery, SkeletonReactQuery } from './react/types/query.js';
export { Data, DataInit } from './result/data.js';
export { Fail, FailInit } from './result/fail.js';
export { Fetched, FetchedInit } from './result/fetched.js';
export { Times, TimesInit } from './result/times.js';
export { ScrollError, Scrollable } from './scroll/helper.js';
export { ScrollableFetcherfulQuery, ScrollableFetcherlessQuery, ScrollableQuery, ScrollableSkeletonQuery, createScrollableQuery } from './scroll/query.js';
export { AsyncBicoder, AsyncEncoder, AsyncJson, AsyncPipeBicoder, AsyncPipeEncoder, Bicoder, Encoder, SyncBicoder, SyncEncoder, SyncIdentity, SyncJson, SyncPipeBicoder, SyncPipeEncoder } from './serializers/coder.js';
export { AesGcmCoder } from './serializers/crypto/aes/gcm.js';
export { CryptoError } from './serializers/crypto/error/error.js';
export { HmacEncoder } from './serializers/crypto/hmac/hmac.js';
export { Simple } from './single/helper.js';
export { SimpleFetcherfulQuery, SimpleFetcherlessQuery, SimpleQuery, SimpleSkeletonQuery, createQuery } from './single/query.js';
export { StorageCreationError } from './storages/errors.js';

@@ -31,0 +31,0 @@ export { IDBError, IDBStorage, IDBStorageParams, useIDBStorage } from './storages/idb/basic.js';

@@ -0,3 +1,3 @@

import { Fetched } from '../../../fetched/fetched.js';
import { ReactQuery } from '../../types/query.js';
import { Fetched } from '../../../result/fetched.js';

@@ -4,0 +4,0 @@ /**

import { Nullable } from '@hazae41/option';
import { Result } from '@hazae41/result';
import { MissingKeyError, MissingFetcherError } from '../../../core/core.js';
import { SkeletonReactQuery, FetcherlessReactQuery, FetcherfulReactQuery } from '../../types/query.js';
import { ScrollableFetcherlessQuerySettings, ScrollableFetcherfulQuerySettings } from '../../../types/settings.js';
import { State } from '../../../types/state.js';
import { ScrollableQuery } from '../../../queries/scroll/query.js';
import { SkeletonReactQuery, FetcherlessReactQuery, FetcherfulReactQuery } from '../../types/query.js';
import { DependencyList } from 'react';
import { ScrollableQuery } from '../../../scroll/query.js';

@@ -10,0 +10,0 @@ declare function useScrollableQuery<T extends ScrollableQuery.Infer<T>, L extends DependencyList>(factory: (...deps: L) => T, deps: L): ScrollableQuery.Reactify<T>;

import { Nullable } from '@hazae41/option';
import { Result } from '@hazae41/result';
import { MissingKeyError, CooldownError, MissingFetcherError } from '../../core/core.js';
import { Data } from '../../result/data.js';
import { Fail } from '../../result/fail.js';
import { Fetched } from '../../result/fetched.js';
import { Data } from '../../fetched/data.js';
import { Fail } from '../../fetched/fail.js';
import { Fetched } from '../../fetched/fetched.js';
import { Mutator } from '../../types/mutator.js';

@@ -8,0 +8,0 @@ import { SkeletonQuerySettings, FetcherfulQuerySettings, FetcherlessQuerySettings } from '../../types/settings.js';

import { Nullable } from '@hazae41/option';
import { Result, Err, Ok } from '@hazae41/result';
import { Encoder, Bicoder } from '../../serializers/coder.js';
import { Encoder, Bicoder } from '../../coders/coder.js';
import { Storage } from '../storage.js';

@@ -5,0 +5,0 @@ import { RawState } from '../../types/state.js';

import { Nullable } from '@hazae41/option';
import { Result } from '@hazae41/result';
import { Encoder, Bicoder } from '../../serializers/coder.js';
import { Encoder, Bicoder } from '../../coders/coder.js';
import { RawState } from '../../types/state.js';

@@ -5,0 +5,0 @@ import { StorageCreationError } from '../errors.js';

import { Result } from '@hazae41/result';
import { Promiseable } from '../../libs/promises/promises.js';
import { FetchedInit } from '../result/fetched.js';
import { FetchedInit } from '../fetched/fetched.js';
type Fetcher<K, D, F> = (key: K, more?: FetcherMore) => Promiseable<Result<FetchedInit<D, F>, Error>>;
type Fetcher<K, D, F> = (key: K, more: FetcherMore) => Promiseable<Result<FetchedInit<D, F>, Error>>;
interface FetcherMore {

@@ -7,0 +7,0 @@ readonly signal?: AbortSignal;

import { Option, Nullable } from '@hazae41/option';
import { Result } from '@hazae41/result';
import { Promiseable } from '../../libs/promises/promises.js';
import { FetchedInit } from '../result/fetched.js';
import { FetchedInit } from '../fetched/fetched.js';
import { State } from './state.js';

@@ -6,0 +6,0 @@

import { Nullable } from '@hazae41/option';
import { Result } from '@hazae41/result';
import { Fetched } from '../result/fetched.js';
import { Fetched } from '../fetched/fetched.js';

@@ -5,0 +5,0 @@ type Normalizer<D, F> = (fetched: Nullable<Fetched<D, F>>, more: NormalizerMore) => Promise<Result<Nullable<Fetched<D, F>>, Error>>;

@@ -0,3 +1,3 @@

import { Bicoder, SyncEncoder } from '../coders/coder.js';
import { Equalser } from '../equals/equals.js';
import { Bicoder, SyncEncoder } from '../serializers/coder.js';
import { Storage } from '../storages/storage.js';

@@ -4,0 +4,0 @@ import { Normalizer } from './normalizer.js';

@@ -1,3 +0,3 @@

import { DataInit, Data } from '../result/data.js';
import { FailInit, Fail } from '../result/fail.js';
import { DataInit, Data } from '../fetched/data.js';
import { FailInit, Fail } from '../fetched/fail.js';

@@ -4,0 +4,0 @@ type RawState<D = unknown, E = unknown> = RawState1<D, E> | RawState2<D, E>;

{
"type": "module",
"name": "@hazae41/glacier",
"version": "2.0.0-102",
"version": "2.0.0-103",
"author": "hazae41",

@@ -25,7 +25,8 @@ "license": "MIT",

"dependencies": {
"@hazae41/base64": "^1.0.6",
"@hazae41/bytes": "^1.2.2",
"@hazae41/mutex": "^1.2.10",
"@hazae41/option": "^1.0.21",
"@hazae41/result": "^1.1.4"
"@hazae41/base64": "^1.0.8",
"@hazae41/box": "^1.0.8",
"@hazae41/bytes": "^1.2.3",
"@hazae41/mutex": "^1.2.11",
"@hazae41/option": "^1.0.26",
"@hazae41/result": "^1.1.8"
},

@@ -37,9 +38,9 @@ "peerDependencies": {

"@hazae41/phobos": "^1.0.10",
"@rollup/plugin-typescript": "^11.1.3",
"@types/node": "^20.6.2",
"@types/react": "^18.2.22",
"rimraf": "^5.0.1",
"rollup": "^3.29.2",
"rollup-plugin-dts": "^6.0.2",
"rollup-plugin-node-externals": "^6.1.1",
"@rollup/plugin-typescript": "^11.1.5",
"@types/node": "^20.8.4",
"@types/react": "^18.2.28",
"rimraf": "^5.0.5",
"rollup": "^4.0.2",
"rollup-plugin-dts": "^6.1.0",
"rollup-plugin-node-externals": "^6.1.2",
"typescript": "^5.2.2"

@@ -46,0 +47,0 @@ },

@@ -9,3 +9,3 @@ <div align="center">

[**Node Package ๐Ÿ“ฆ**](https://www.npmjs.com/package/@hazae41/glacier) โ€ข [**Read the docs ๐Ÿ“š**](https://xswr.hazae41.me) โ€ข [**Next.js Example ๐Ÿชฃ**](https://codesandbox.io/p/github/hazae41/xswr-example-next) โ€ข [**Expo Example ๐Ÿชฃ**](https://snack.expo.dev/@git/github.com/hazae41/xswr-example-expo) โ€ข [**Comparison with other libs ๐ŸŒ**](https://xswr.hazae41.me/faq/comparison)
[**Node Package ๐Ÿ“ฆ**](https://www.npmjs.com/package/@hazae41/glacier) โ€ข [**Read the docs ๐Ÿ“š**](https://github.com/hazae41/glacier/blob/master/docs) โ€ข [**Next.js Example ๐Ÿชฃ**](https://codesandbox.io/p/github/hazae41/xswr-example-next) โ€ข [**Expo Example ๐Ÿชฃ**](https://snack.expo.dev/@git/github.com/hazae41/xswr-example-expo) โ€ข [**Comparison with other libs ๐ŸŒ**](https://github.com/hazae41/glacier/blob/master/docs/comparison.md)

@@ -18,98 +18,21 @@ ## Philosophy ๐Ÿง 

## Features ๐Ÿ”ฅ
### Current features
- 100% TypeScript and ESM
- Composition-based hooks
- Very easy learning curve
- No dependency except React
- Not over-engineered (hello react-query)
- No unexpected behaviour (hello swr)
- Backend agnostic fetching (REST, GraphQL, WebSocket)
- Storage agnostic caching (new Map(), LocalStorage, IndexedDB)
- Automatic refetching
- Dependent and conditional queries
- Request deduplication, cooldown, timeout, and expiration
- Page-based and cursor-based pagination
- Exponential backoff retry
- SSR & ISR support
- Optimistic mutations
- Cancellable requests
- Automatic cancellation
- Automatic garbage collection
- Per-query persistent storage
- Out of the box IndexedDB and LocalStorage
- Out of the box store normalization
- Super natural React Suspense
- React Native support
### [Upcoming features](https://github.com/sponsors/hazae41)
- Transport agnostic streaming (ethers.js, WebSockets, Socket.io)
- Bidirectional scrolling
# Installation ๐Ÿ”ง
Just install `@hazae41/glacier` using your favorite package manager.
```bash
npm i @hazae41/glacier
```
Then, wrap your app in a `CoreProvider` component.
```tsx
import { CoreProvider } from "@hazae41/glacier"
function MyWrapper() {
return <CoreProvider>
<MyAwesomeApp />
</CoreProvider>
function useAutoFetchMixture(query: Query) {
useFetch(query) // Fetch on mount and url change
useVisible(query) // Fetch when the page is focused
useOnline(query) // Fetch when the browser is online
}
```
## Your first mix ๐Ÿงช
When using Glacier and its composition-based hooks, you create a mix and only include the ingredients you want.
We'll do a request at `/api/data` using JSON, display it with a loading, and automatically refetch it.
### Create a fetcher โšก๏ธ
It will just take an url, fetch it, and return the data.
```tsx
async function fetchAsJson<T>(url: string) {
const res = await fetch(url)
const data = await res.json() as T
return { data }
}
```
### Create a mix ๐ŸŒช
Then create a mix using a query and some blocks.
```tsx
function useHello() {
const query = useQuery<Hello>(`/api/hello`, fetchAsJson)
useFetch(query) // Fetch on mount and on url change
useVisible(query) // Fetch when the page becomes visible
useOnline(query) // Fetch when the browser becomes online
function useHelloWithAutoFetch() {
const query = useQuery(createHelloQuery, [])
useAutoFetchMixture(query)
return query
}
```
### Use it in your components ๐Ÿš€
```tsx
function MyApp() {
const { data, error } = useHello()
const { data, error } = useHelloWithAutoFetch()
if (error)
if (error != null)
return <MyError error={error} />
if (!data)
if (data == null)
return <MyLoading />

@@ -120,76 +43,19 @@ return <MyPage data={data} />

## Advanced example ๐Ÿ—ฟ
## Features ๐Ÿ”ฅ
Last example was good, but here is the best way to use Glacier.
### Making our fetcher cancellable โšก๏ธ
Our fetcher was good, but this one can be aborted.
```tsx
async function fetchAsJson<T>(url: string, more: FetcherMore<T>) {
const { signal } = more
const res = await fetch(url, { signal })
if (!res.ok) {
const error = new Error(await res.text())
return { error }
}
const data = await res.json() as T
return { data }
}
```
It also returns an error if the request failed.
### Defining schemas ๐Ÿ“
Using schemas may seems boilerplate, but it will save you a lot of time later.
```tsx
function getHelloSchema() {
return getSchema<Hello>("/api/hello", fetchAsJson)
}
```
It allows you to reuse the same set of key+fetcher+params in multiple places, including imperative code.
### Creating mixtures ๐Ÿงช
The mixtures pattern allows you to reuse the same group of blocks.
```tsx
function useAutoFetchMixture(query: Query) {
useFetch(query)
useVisible(query)
useOnline(query)
}
```
### Mixing it ๐ŸŒช
Once you got a schema and a mixture, you just have to mix it.
```tsx
function useHelloMix() {
const query = useSchema(getHelloSchema, [])
useAutoFetchMixture(query)
return query
}
```
### Use it in your app ๐Ÿš€
```tsx
function MyApp() {
const { data, error } = useHelloMix()
if (error)
return <MyError error={error} />
if (!data)
return <MyLoading />
return <MyPage data={data} />
}
```
- 100% TypeScript and ESM
- No external dependency
- Composition-based hooks
- Rust-like patterns
- Transport agnostic (REST, GraphQL, WebSocket)
- Storage agnostic (IndexedDB, localStorage)
- Works in a Service Worker or in a serverless function
- Per-query, encrypted, garbage-collected, persistent storage
- Store normalization and indexes
- Concurrent and multi-step optimistic states
- Request deduplication, cooldown, timeout, cancellation, expiration, and retrying
- Automatic refetching based on various signals
- Page-based and cursor-based pagination
- SSR & ISR support
- React Suspense support
- React Native support

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with โšก๏ธ by Socket Inc