@tanstack/angular-db 0.2.10 → 0.2.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +4 -3
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.js +5 -4
- package/dist/esm/index.js.map +1 -1
- package/package.json +2 -2
- package/skills/angular-db/SKILL.md +1 -1
- package/src/index.ts +5 -4
package/dist/cjs/index.cjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const core = require("@angular/core");
|
|
4
4
|
const db = require("@tanstack/db");
|
|
5
|
+
const DEFAULT_GC_TIME_MS = 1;
|
|
5
6
|
function injectLiveQuery(opts) {
|
|
6
7
|
core.assertInInjectionContext(injectLiveQuery);
|
|
7
8
|
const destroyRef = core.inject(core.DestroyRef);
|
|
@@ -15,7 +16,7 @@ function injectLiveQuery(opts) {
|
|
|
15
16
|
if (result === void 0 || result === null) {
|
|
16
17
|
return null;
|
|
17
18
|
}
|
|
18
|
-
return db.resolveLiveQueryValue(result, { gcTime:
|
|
19
|
+
return db.resolveLiveQueryValue(result, { gcTime: DEFAULT_GC_TIME_MS });
|
|
19
20
|
}
|
|
20
21
|
const isReactiveQueryOptions = opts && typeof opts === `object` && typeof opts.query === `function` && typeof opts.params === `function`;
|
|
21
22
|
if (isReactiveQueryOptions) {
|
|
@@ -26,10 +27,10 @@ function injectLiveQuery(opts) {
|
|
|
26
27
|
if (result === void 0 || result === null) {
|
|
27
28
|
return null;
|
|
28
29
|
}
|
|
29
|
-
return db.resolveLiveQueryValue(result, { gcTime:
|
|
30
|
+
return db.resolveLiveQueryValue(result, { gcTime: DEFAULT_GC_TIME_MS });
|
|
30
31
|
}
|
|
31
32
|
if (opts && typeof opts === `object` && typeof opts.query === `function`) {
|
|
32
|
-
return db.
|
|
33
|
+
return db.resolveLiveQueryValue(opts, { gcTime: DEFAULT_GC_TIME_MS });
|
|
33
34
|
}
|
|
34
35
|
throw new Error(`Invalid options provided to injectLiveQuery`);
|
|
35
36
|
});
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/index.ts"],"sourcesContent":["import {\n DestroyRef,\n assertInInjectionContext,\n computed,\n effect,\n inject,\n signal,\n} from '@angular/core'\nimport {\n BaseQueryBuilder,\n createLiveQueryCollection,\n createLiveQueryObserver,\n getPublicCollection,\n isCollection,\n isSingleResultCollection,\n resolveLiveQueryValue,\n} from '@tanstack/db'\nimport type {\n Collection,\n CollectionStatus,\n Context,\n GetResult,\n InferResultType,\n InitialQueryBuilder,\n LiveQueryCollectionConfig,\n LiveQueryObserver,\n LiveQueryPersistedStatus,\n NonSingleResult,\n QueryBuilder,\n SingleResult,\n} from '@tanstack/db'\nimport type { Signal } from '@angular/core'\n\nexport * from '@tanstack/db'\n\n/**\n * The result of calling `injectLiveQuery`.\n * Contains reactive signals for the query state and data.\n */\nexport interface InjectLiveQueryResult<TContext extends Context> {\n /** A signal containing the complete state map of results keyed by their ID */\n state: Signal<Map<string | number, GetResult<TContext>>>\n /** A signal containing the results as an array, or single result for findOne queries */\n data: Signal<InferResultType<TContext>>\n /** A signal containing the underlying collection instance (null for disabled queries) */\n collection: Signal<Collection<\n GetResult<TContext>,\n string | number,\n {}\n > | null>\n /** A signal containing the current status of the collection */\n status: Signal<CollectionStatus | `disabled`>\n /** A signal indicating whether the collection is currently loading */\n isLoading: Signal<boolean>\n /** A signal indicating whether the collection is ready */\n isReady: Signal<boolean>\n persistedStatus: Signal<LiveQueryPersistedStatus>\n isPersistedReady: Signal<boolean>\n persistedError: Signal<unknown | undefined>\n /** A signal indicating whether the collection is idle */\n isIdle: Signal<boolean>\n /** A signal indicating whether the collection has an error */\n isError: Signal<boolean>\n /** A signal indicating whether the collection has been cleaned up */\n isCleanedUp: Signal<boolean>\n}\n\ntype InferConditionalResultType<TContext extends Context> =\n TContext extends SingleResult\n ? InferResultType<TContext> | []\n : InferResultType<TContext>\n\nexport type InjectConditionalLiveQueryResult<TContext extends Context> = Omit<\n InjectLiveQueryResult<TContext>,\n `data`\n> & {\n data: Signal<InferConditionalResultType<TContext>>\n}\n\nexport interface InjectLiveQueryResultWithCollection<\n TResult extends object = any,\n TKey extends string | number = string | number,\n TUtils extends Record<string, any> = {},\n> {\n state: Signal<Map<TKey, TResult>>\n data: Signal<Array<TResult>>\n collection: Signal<Collection<TResult, TKey, TUtils> | null>\n status: Signal<CollectionStatus | `disabled`>\n isLoading: Signal<boolean>\n isReady: Signal<boolean>\n persistedStatus: Signal<LiveQueryPersistedStatus>\n isPersistedReady: Signal<boolean>\n persistedError: Signal<unknown | undefined>\n isIdle: Signal<boolean>\n isError: Signal<boolean>\n isCleanedUp: Signal<boolean>\n}\n\nexport interface InjectLiveQueryResultWithSingleResultCollection<\n TResult extends object = any,\n TKey extends string | number = string | number,\n TUtils extends Record<string, any> = {},\n> {\n state: Signal<Map<TKey, TResult>>\n data: Signal<TResult | undefined>\n collection: Signal<(Collection<TResult, TKey, TUtils> & SingleResult) | null>\n status: Signal<CollectionStatus | `disabled`>\n isLoading: Signal<boolean>\n isReady: Signal<boolean>\n persistedStatus: Signal<LiveQueryPersistedStatus>\n isPersistedReady: Signal<boolean>\n persistedError: Signal<unknown | undefined>\n isIdle: Signal<boolean>\n isError: Signal<boolean>\n isCleanedUp: Signal<boolean>\n}\n\nexport function injectLiveQuery<\n TContext extends Context,\n TParams extends any,\n>(options: {\n params: () => TParams\n query: (args: {\n params: TParams\n q: InitialQueryBuilder\n }) => QueryBuilder<TContext>\n}): InjectLiveQueryResult<TContext>\nexport function injectLiveQuery<\n TContext extends Context,\n TParams extends any,\n>(options: {\n params: () => TParams\n query: (args: {\n params: TParams\n q: InitialQueryBuilder\n }) => QueryBuilder<TContext> | undefined | null\n}): InjectConditionalLiveQueryResult<TContext>\nexport function injectLiveQuery<TContext extends Context>(\n queryFn: (q: InitialQueryBuilder) => QueryBuilder<TContext>,\n): InjectLiveQueryResult<TContext>\nexport function injectLiveQuery<TContext extends Context>(\n queryFn: (\n q: InitialQueryBuilder,\n ) => QueryBuilder<TContext> | undefined | null,\n): InjectConditionalLiveQueryResult<TContext>\nexport function injectLiveQuery<TContext extends Context>(\n config: LiveQueryCollectionConfig<TContext>,\n): InjectLiveQueryResult<TContext>\n// Pre-created collection without singleResult\nexport function injectLiveQuery<\n TResult extends object,\n TKey extends string | number,\n TUtils extends Record<string, any>,\n>(\n liveQueryCollection: Collection<TResult, TKey, TUtils> & NonSingleResult,\n): InjectLiveQueryResultWithCollection<TResult, TKey, TUtils>\n// Pre-created collection with singleResult\nexport function injectLiveQuery<\n TResult extends object,\n TKey extends string | number,\n TUtils extends Record<string, any>,\n>(\n liveQueryCollection: Collection<TResult, TKey, TUtils> & SingleResult,\n): InjectLiveQueryResultWithSingleResultCollection<TResult, TKey, TUtils>\nexport function injectLiveQuery(opts: any) {\n assertInInjectionContext(injectLiveQuery)\n const destroyRef = inject(DestroyRef)\n\n const collection = computed(() => {\n // Check if it's an existing collection\n if (isCollection(opts)) {\n return opts\n }\n\n if (typeof opts === `function`) {\n // Check if query function returns null/undefined (disabled query)\n const queryBuilder = new BaseQueryBuilder() as InitialQueryBuilder\n const result = opts(queryBuilder)\n\n if (result === undefined || result === null) {\n // Disabled query - return null\n return null\n }\n\n return resolveLiveQueryValue(result, { gcTime: 0 })\n }\n\n // Check if it's reactive query options\n const isReactiveQueryOptions =\n opts &&\n typeof opts === `object` &&\n typeof opts.query === `function` &&\n typeof opts.params === `function`\n\n if (isReactiveQueryOptions) {\n const { params, query } = opts\n const currentParams = params()\n\n // Check if query function returns null/undefined (disabled query)\n const queryBuilder = new BaseQueryBuilder() as InitialQueryBuilder\n const result = query({ params: currentParams, q: queryBuilder })\n\n if (result === undefined || result === null) {\n // Disabled query - return null\n return null\n }\n\n return resolveLiveQueryValue(result, { gcTime: 0 })\n }\n\n // Handle LiveQueryCollectionConfig objects. Default startSync/gcTime to\n // match the query-fn and reactive-options paths, but let an explicit value\n // in the config win — otherwise a bare `{ query }` never syncs.\n if (opts && typeof opts === `object` && typeof opts.query === `function`) {\n return createLiveQueryCollection({ startSync: true, gcTime: 0, ...opts })\n }\n\n throw new Error(`Invalid options provided to injectLiveQuery`)\n })\n\n const state = signal(new Map<string | number, any>())\n const internalData = signal<Array<any>>([])\n const statusValue = signal<CollectionStatus | `disabled`>(`idle`)\n const status = computed(() => {\n const value = statusValue()\n return value === `idle` && !collection() ? `disabled` : value\n })\n const persistedStatus = signal<LiveQueryPersistedStatus>(`unavailable`)\n const persistedError = signal<unknown>(undefined)\n\n // Returns single item for singleResult collections, array otherwise\n const data = computed(() => {\n const currentCollection = collection()\n if (!currentCollection) {\n return internalData()\n }\n return isSingleResultCollection(currentCollection)\n ? internalData()[0]\n : internalData()\n })\n\n const syncDataFromCollection = (\n currentCollection: Collection<any, any, any>,\n observer: LiveQueryObserver<any, any>,\n ) => {\n const newState = new Map(currentCollection.entries())\n const newData = Array.from(newState.values())\n\n state.set(newState)\n internalData.set(newData)\n const snapshot = observer.getSnapshot()\n statusValue.set(snapshot.status)\n persistedStatus.set(snapshot.persistedStatus)\n persistedError.set(snapshot.persistedError)\n }\n\n let unsub: (() => void) | null = null\n const cleanup = () => {\n unsub?.()\n unsub = null\n }\n\n effect((onCleanup) => {\n const currentCollection = collection()\n\n // Handle null collection (disabled query)\n if (!currentCollection) {\n statusValue.set(`disabled` as const)\n persistedStatus.set(`unavailable`)\n persistedError.set(undefined)\n state.set(new Map())\n internalData.set([])\n cleanup()\n return\n }\n\n cleanup()\n\n // The shared observer owns sync start, subscription, the ready-race, and\n // status transitions; Angular re-reads the whole collection on each notify\n // (wholesale) into its signals.\n // Angular re-reads the collection on notify; wholesale mode preserves its\n // pre-observer loading policy (no initial-state snapshot request).\n const observer = createLiveQueryObserver(currentCollection, {\n mode: `wholesale`,\n })\n\n const unsubscribe = observer.subscribe(() => {\n syncDataFromCollection(currentCollection, observer)\n })\n // Wholesale attach suppresses listener calls raised by synchronous sync\n // startup. Read once after subscribe returns to capture that final state.\n syncDataFromCollection(currentCollection, observer)\n unsub = () => {\n unsubscribe()\n observer.dispose()\n }\n\n onCleanup(cleanup)\n })\n\n destroyRef.onDestroy(cleanup)\n\n return {\n state,\n data,\n // Loosely typed so the impl return stays compatible with every overload\n // (the shared `isCollection` guard narrows the computed to `Collection | null`).\n collection: computed(() =>\n getPublicCollection(collection()),\n ) as Signal<any>,\n status,\n isLoading: computed(() => status() === `loading`),\n isReady: computed(() => status() === `ready` || status() === `disabled`),\n persistedStatus,\n isPersistedReady: computed(() => persistedStatus() === `ready`),\n persistedError,\n isIdle: computed(() => status() === `idle`),\n isError: computed(() => status() === `error`),\n isCleanedUp: computed(() => status() === `cleaned-up`),\n }\n}\n"],"names":["assertInInjectionContext","inject","DestroyRef","computed","isCollection","BaseQueryBuilder","resolveLiveQueryValue","createLiveQueryCollection","signal","isSingleResultCollection","effect","createLiveQueryObserver","getPublicCollection"],"mappings":";;;;AAoKO,SAAS,gBAAgB,MAAW;AACzCA,OAAAA,yBAAyB,eAAe;AACxC,QAAM,aAAaC,KAAAA,OAAOC,eAAU;AAEpC,QAAM,aAAaC,KAAAA,SAAS,MAAM;AAEhC,QAAIC,GAAAA,aAAa,IAAI,GAAG;AACtB,aAAO;AAAA,IACT;AAEA,QAAI,OAAO,SAAS,YAAY;AAE9B,YAAM,eAAe,IAAIC,oBAAA;AACzB,YAAM,SAAS,KAAK,YAAY;AAEhC,UAAI,WAAW,UAAa,WAAW,MAAM;AAE3C,eAAO;AAAA,MACT;AAEA,aAAOC,GAAAA,sBAAsB,QAAQ,EAAE,QAAQ,GAAG;AAAA,IACpD;AAGA,UAAM,yBACJ,QACA,OAAO,SAAS,YAChB,OAAO,KAAK,UAAU,cACtB,OAAO,KAAK,WAAW;AAEzB,QAAI,wBAAwB;AAC1B,YAAM,EAAE,QAAQ,MAAA,IAAU;A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,MAAa,YAAY;AAAA,EAAA;AAEzD;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/index.ts"],"sourcesContent":["import {\n DestroyRef,\n assertInInjectionContext,\n computed,\n effect,\n inject,\n signal,\n} from '@angular/core'\nimport {\n BaseQueryBuilder,\n createLiveQueryObserver,\n getPublicCollection,\n isCollection,\n isSingleResultCollection,\n resolveLiveQueryValue,\n} from '@tanstack/db'\nimport type {\n Collection,\n CollectionStatus,\n Context,\n GetResult,\n InferResultType,\n InitialQueryBuilder,\n LiveQueryCollectionConfig,\n LiveQueryObserver,\n LiveQueryPersistedStatus,\n NonSingleResult,\n QueryBuilder,\n SingleResult,\n} from '@tanstack/db'\nimport type { Signal } from '@angular/core'\n\nconst DEFAULT_GC_TIME_MS = 1\n\nexport * from '@tanstack/db'\n\n/**\n * The result of calling `injectLiveQuery`.\n * Contains reactive signals for the query state and data.\n */\nexport interface InjectLiveQueryResult<TContext extends Context> {\n /** A signal containing the complete state map of results keyed by their ID */\n state: Signal<Map<string | number, GetResult<TContext>>>\n /** A signal containing the results as an array, or single result for findOne queries */\n data: Signal<InferResultType<TContext>>\n /** A signal containing the underlying collection instance (null for disabled queries) */\n collection: Signal<Collection<\n GetResult<TContext>,\n string | number,\n {}\n > | null>\n /** A signal containing the current status of the collection */\n status: Signal<CollectionStatus | `disabled`>\n /** A signal indicating whether the collection is currently loading */\n isLoading: Signal<boolean>\n /** A signal indicating whether the collection is ready */\n isReady: Signal<boolean>\n persistedStatus: Signal<LiveQueryPersistedStatus>\n isPersistedReady: Signal<boolean>\n persistedError: Signal<unknown | undefined>\n /** A signal indicating whether the collection is idle */\n isIdle: Signal<boolean>\n /** A signal indicating whether the collection has an error */\n isError: Signal<boolean>\n /** A signal indicating whether the collection has been cleaned up */\n isCleanedUp: Signal<boolean>\n}\n\ntype InferConditionalResultType<TContext extends Context> =\n TContext extends SingleResult\n ? InferResultType<TContext> | []\n : InferResultType<TContext>\n\nexport type InjectConditionalLiveQueryResult<TContext extends Context> = Omit<\n InjectLiveQueryResult<TContext>,\n `data`\n> & {\n data: Signal<InferConditionalResultType<TContext>>\n}\n\nexport interface InjectLiveQueryResultWithCollection<\n TResult extends object = any,\n TKey extends string | number = string | number,\n TUtils extends Record<string, any> = {},\n> {\n state: Signal<Map<TKey, TResult>>\n data: Signal<Array<TResult>>\n collection: Signal<Collection<TResult, TKey, TUtils> | null>\n status: Signal<CollectionStatus | `disabled`>\n isLoading: Signal<boolean>\n isReady: Signal<boolean>\n persistedStatus: Signal<LiveQueryPersistedStatus>\n isPersistedReady: Signal<boolean>\n persistedError: Signal<unknown | undefined>\n isIdle: Signal<boolean>\n isError: Signal<boolean>\n isCleanedUp: Signal<boolean>\n}\n\nexport interface InjectLiveQueryResultWithSingleResultCollection<\n TResult extends object = any,\n TKey extends string | number = string | number,\n TUtils extends Record<string, any> = {},\n> {\n state: Signal<Map<TKey, TResult>>\n data: Signal<TResult | undefined>\n collection: Signal<(Collection<TResult, TKey, TUtils> & SingleResult) | null>\n status: Signal<CollectionStatus | `disabled`>\n isLoading: Signal<boolean>\n isReady: Signal<boolean>\n persistedStatus: Signal<LiveQueryPersistedStatus>\n isPersistedReady: Signal<boolean>\n persistedError: Signal<unknown | undefined>\n isIdle: Signal<boolean>\n isError: Signal<boolean>\n isCleanedUp: Signal<boolean>\n}\n\nexport function injectLiveQuery<\n TContext extends Context,\n TParams extends any,\n>(options: {\n params: () => TParams\n query: (args: {\n params: TParams\n q: InitialQueryBuilder\n }) => QueryBuilder<TContext>\n}): InjectLiveQueryResult<TContext>\nexport function injectLiveQuery<\n TContext extends Context,\n TParams extends any,\n>(options: {\n params: () => TParams\n query: (args: {\n params: TParams\n q: InitialQueryBuilder\n }) => QueryBuilder<TContext> | undefined | null\n}): InjectConditionalLiveQueryResult<TContext>\nexport function injectLiveQuery<TContext extends Context>(\n queryFn: (q: InitialQueryBuilder) => QueryBuilder<TContext>,\n): InjectLiveQueryResult<TContext>\nexport function injectLiveQuery<TContext extends Context>(\n queryFn: (\n q: InitialQueryBuilder,\n ) => QueryBuilder<TContext> | undefined | null,\n): InjectConditionalLiveQueryResult<TContext>\nexport function injectLiveQuery<TContext extends Context>(\n config: LiveQueryCollectionConfig<TContext>,\n): InjectLiveQueryResult<TContext>\n// Pre-created collection without singleResult\nexport function injectLiveQuery<\n TResult extends object,\n TKey extends string | number,\n TUtils extends Record<string, any>,\n>(\n liveQueryCollection: Collection<TResult, TKey, TUtils> & NonSingleResult,\n): InjectLiveQueryResultWithCollection<TResult, TKey, TUtils>\n// Pre-created collection with singleResult\nexport function injectLiveQuery<\n TResult extends object,\n TKey extends string | number,\n TUtils extends Record<string, any>,\n>(\n liveQueryCollection: Collection<TResult, TKey, TUtils> & SingleResult,\n): InjectLiveQueryResultWithSingleResultCollection<TResult, TKey, TUtils>\nexport function injectLiveQuery(opts: any) {\n assertInInjectionContext(injectLiveQuery)\n const destroyRef = inject(DestroyRef)\n\n const collection = computed(() => {\n // Check if it's an existing collection\n if (isCollection(opts)) {\n return opts\n }\n\n if (typeof opts === `function`) {\n // Check if query function returns null/undefined (disabled query)\n const queryBuilder = new BaseQueryBuilder() as InitialQueryBuilder\n const result = opts(queryBuilder)\n\n if (result === undefined || result === null) {\n // Disabled query - return null\n return null\n }\n\n return resolveLiveQueryValue(result, { gcTime: DEFAULT_GC_TIME_MS })\n }\n\n // Check if it's reactive query options\n const isReactiveQueryOptions =\n opts &&\n typeof opts === `object` &&\n typeof opts.query === `function` &&\n typeof opts.params === `function`\n\n if (isReactiveQueryOptions) {\n const { params, query } = opts\n const currentParams = params()\n\n // Check if query function returns null/undefined (disabled query)\n const queryBuilder = new BaseQueryBuilder() as InitialQueryBuilder\n const result = query({ params: currentParams, q: queryBuilder })\n\n if (result === undefined || result === null) {\n // Disabled query - return null\n return null\n }\n\n return resolveLiveQueryValue(result, { gcTime: DEFAULT_GC_TIME_MS })\n }\n\n // Handle LiveQueryCollectionConfig objects. Default startSync/gcTime to\n // match the query-fn and reactive-options paths, but let an explicit value\n // in the config win — otherwise a bare `{ query }` never syncs.\n if (opts && typeof opts === `object` && typeof opts.query === `function`) {\n return resolveLiveQueryValue(opts, { gcTime: DEFAULT_GC_TIME_MS })\n }\n\n throw new Error(`Invalid options provided to injectLiveQuery`)\n })\n\n const state = signal(new Map<string | number, any>())\n const internalData = signal<Array<any>>([])\n const statusValue = signal<CollectionStatus | `disabled`>(`idle`)\n const status = computed(() => {\n const value = statusValue()\n return value === `idle` && !collection() ? `disabled` : value\n })\n const persistedStatus = signal<LiveQueryPersistedStatus>(`unavailable`)\n const persistedError = signal<unknown>(undefined)\n\n // Returns single item for singleResult collections, array otherwise\n const data = computed(() => {\n const currentCollection = collection()\n if (!currentCollection) {\n return internalData()\n }\n return isSingleResultCollection(currentCollection)\n ? internalData()[0]\n : internalData()\n })\n\n const syncDataFromCollection = (\n currentCollection: Collection<any, any, any>,\n observer: LiveQueryObserver<any, any>,\n ) => {\n const newState = new Map(currentCollection.entries())\n const newData = Array.from(newState.values())\n\n state.set(newState)\n internalData.set(newData)\n const snapshot = observer.getSnapshot()\n statusValue.set(snapshot.status)\n persistedStatus.set(snapshot.persistedStatus)\n persistedError.set(snapshot.persistedError)\n }\n\n let unsub: (() => void) | null = null\n const cleanup = () => {\n unsub?.()\n unsub = null\n }\n\n effect((onCleanup) => {\n const currentCollection = collection()\n\n // Handle null collection (disabled query)\n if (!currentCollection) {\n statusValue.set(`disabled` as const)\n persistedStatus.set(`unavailable`)\n persistedError.set(undefined)\n state.set(new Map())\n internalData.set([])\n cleanup()\n return\n }\n\n cleanup()\n\n // The shared observer owns sync start, subscription, the ready-race, and\n // status transitions; Angular re-reads the whole collection on each notify\n // (wholesale) into its signals.\n // Angular re-reads the collection on notify; wholesale mode preserves its\n // pre-observer loading policy (no initial-state snapshot request).\n const observer = createLiveQueryObserver(currentCollection, {\n mode: `wholesale`,\n })\n\n const unsubscribe = observer.subscribe(() => {\n syncDataFromCollection(currentCollection, observer)\n })\n // Wholesale attach suppresses listener calls raised by synchronous sync\n // startup. Read once after subscribe returns to capture that final state.\n syncDataFromCollection(currentCollection, observer)\n unsub = () => {\n unsubscribe()\n observer.dispose()\n }\n\n onCleanup(cleanup)\n })\n\n destroyRef.onDestroy(cleanup)\n\n return {\n state,\n data,\n // Loosely typed so the impl return stays compatible with every overload\n // (the shared `isCollection` guard narrows the computed to `Collection | null`).\n collection: computed(() =>\n getPublicCollection(collection()),\n ) as Signal<any>,\n status,\n isLoading: computed(() => status() === `loading`),\n isReady: computed(() => status() === `ready` || status() === `disabled`),\n persistedStatus,\n isPersistedReady: computed(() => persistedStatus() === `ready`),\n persistedError,\n isIdle: computed(() => status() === `idle`),\n isError: computed(() => status() === `error`),\n isCleanedUp: computed(() => status() === `cleaned-up`),\n }\n}\n"],"names":["assertInInjectionContext","inject","DestroyRef","computed","isCollection","BaseQueryBuilder","resolveLiveQueryValue","signal","isSingleResultCollection","effect","createLiveQueryObserver","getPublicCollection"],"mappings":";;;;AAgCA,MAAM,qBAAqB;AAqIpB,SAAS,gBAAgB,MAAW;AACzCA,OAAAA,yBAAyB,eAAe;AACxC,QAAM,aAAaC,KAAAA,OAAOC,eAAU;AAEpC,QAAM,aAAaC,KAAAA,SAAS,MAAM;AAEhC,QAAIC,GAAAA,aAAa,IAAI,GAAG;AACtB,aAAO;AAAA,IACT;AAEA,QAAI,OAAO,SAAS,YAAY;AAE9B,YAAM,eAAe,IAAIC,oBAAA;AACzB,YAAM,SAAS,KAAK,YAAY;AAEhC,UAAI,WAAW,UAAa,WAAW,MAAM;AAE3C,eAAO;AAAA,MACT;AAEA,aAAOC,GAAAA,sBAAsB,QAAQ,EAAE,QAAQ,oBAAoB;AAAA,IACrE;AAGA,UAAM,yBACJ,QACA,OAAO,SAAS,YAChB,OAAO,KAAK,UAAU,cACtB,OAAO,KAAK,WAAW;AAEzB,QAAI,wBAAwB;AAC1B,YAAM,EAAE,QAAQ,MAAA,IAAU;AAC1B,YAAM,gBAAgB,OAAA;A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;;"}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { assertInInjectionContext, inject, DestroyRef, computed, signal, effect } from "@angular/core";
|
|
2
|
-
import { isCollection, BaseQueryBuilder, resolveLiveQueryValue,
|
|
2
|
+
import { isCollection, BaseQueryBuilder, resolveLiveQueryValue, isSingleResultCollection, createLiveQueryObserver, getPublicCollection } from "@tanstack/db";
|
|
3
3
|
export * from "@tanstack/db";
|
|
4
|
+
const DEFAULT_GC_TIME_MS = 1;
|
|
4
5
|
function injectLiveQuery(opts) {
|
|
5
6
|
assertInInjectionContext(injectLiveQuery);
|
|
6
7
|
const destroyRef = inject(DestroyRef);
|
|
@@ -14,7 +15,7 @@ function injectLiveQuery(opts) {
|
|
|
14
15
|
if (result === void 0 || result === null) {
|
|
15
16
|
return null;
|
|
16
17
|
}
|
|
17
|
-
return resolveLiveQueryValue(result, { gcTime:
|
|
18
|
+
return resolveLiveQueryValue(result, { gcTime: DEFAULT_GC_TIME_MS });
|
|
18
19
|
}
|
|
19
20
|
const isReactiveQueryOptions = opts && typeof opts === `object` && typeof opts.query === `function` && typeof opts.params === `function`;
|
|
20
21
|
if (isReactiveQueryOptions) {
|
|
@@ -25,10 +26,10 @@ function injectLiveQuery(opts) {
|
|
|
25
26
|
if (result === void 0 || result === null) {
|
|
26
27
|
return null;
|
|
27
28
|
}
|
|
28
|
-
return resolveLiveQueryValue(result, { gcTime:
|
|
29
|
+
return resolveLiveQueryValue(result, { gcTime: DEFAULT_GC_TIME_MS });
|
|
29
30
|
}
|
|
30
31
|
if (opts && typeof opts === `object` && typeof opts.query === `function`) {
|
|
31
|
-
return
|
|
32
|
+
return resolveLiveQueryValue(opts, { gcTime: DEFAULT_GC_TIME_MS });
|
|
32
33
|
}
|
|
33
34
|
throw new Error(`Invalid options provided to injectLiveQuery`);
|
|
34
35
|
});
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["import {\n DestroyRef,\n assertInInjectionContext,\n computed,\n effect,\n inject,\n signal,\n} from '@angular/core'\nimport {\n BaseQueryBuilder,\n createLiveQueryCollection,\n createLiveQueryObserver,\n getPublicCollection,\n isCollection,\n isSingleResultCollection,\n resolveLiveQueryValue,\n} from '@tanstack/db'\nimport type {\n Collection,\n CollectionStatus,\n Context,\n GetResult,\n InferResultType,\n InitialQueryBuilder,\n LiveQueryCollectionConfig,\n LiveQueryObserver,\n LiveQueryPersistedStatus,\n NonSingleResult,\n QueryBuilder,\n SingleResult,\n} from '@tanstack/db'\nimport type { Signal } from '@angular/core'\n\nexport * from '@tanstack/db'\n\n/**\n * The result of calling `injectLiveQuery`.\n * Contains reactive signals for the query state and data.\n */\nexport interface InjectLiveQueryResult<TContext extends Context> {\n /** A signal containing the complete state map of results keyed by their ID */\n state: Signal<Map<string | number, GetResult<TContext>>>\n /** A signal containing the results as an array, or single result for findOne queries */\n data: Signal<InferResultType<TContext>>\n /** A signal containing the underlying collection instance (null for disabled queries) */\n collection: Signal<Collection<\n GetResult<TContext>,\n string | number,\n {}\n > | null>\n /** A signal containing the current status of the collection */\n status: Signal<CollectionStatus | `disabled`>\n /** A signal indicating whether the collection is currently loading */\n isLoading: Signal<boolean>\n /** A signal indicating whether the collection is ready */\n isReady: Signal<boolean>\n persistedStatus: Signal<LiveQueryPersistedStatus>\n isPersistedReady: Signal<boolean>\n persistedError: Signal<unknown | undefined>\n /** A signal indicating whether the collection is idle */\n isIdle: Signal<boolean>\n /** A signal indicating whether the collection has an error */\n isError: Signal<boolean>\n /** A signal indicating whether the collection has been cleaned up */\n isCleanedUp: Signal<boolean>\n}\n\ntype InferConditionalResultType<TContext extends Context> =\n TContext extends SingleResult\n ? InferResultType<TContext> | []\n : InferResultType<TContext>\n\nexport type InjectConditionalLiveQueryResult<TContext extends Context> = Omit<\n InjectLiveQueryResult<TContext>,\n `data`\n> & {\n data: Signal<InferConditionalResultType<TContext>>\n}\n\nexport interface InjectLiveQueryResultWithCollection<\n TResult extends object = any,\n TKey extends string | number = string | number,\n TUtils extends Record<string, any> = {},\n> {\n state: Signal<Map<TKey, TResult>>\n data: Signal<Array<TResult>>\n collection: Signal<Collection<TResult, TKey, TUtils> | null>\n status: Signal<CollectionStatus | `disabled`>\n isLoading: Signal<boolean>\n isReady: Signal<boolean>\n persistedStatus: Signal<LiveQueryPersistedStatus>\n isPersistedReady: Signal<boolean>\n persistedError: Signal<unknown | undefined>\n isIdle: Signal<boolean>\n isError: Signal<boolean>\n isCleanedUp: Signal<boolean>\n}\n\nexport interface InjectLiveQueryResultWithSingleResultCollection<\n TResult extends object = any,\n TKey extends string | number = string | number,\n TUtils extends Record<string, any> = {},\n> {\n state: Signal<Map<TKey, TResult>>\n data: Signal<TResult | undefined>\n collection: Signal<(Collection<TResult, TKey, TUtils> & SingleResult) | null>\n status: Signal<CollectionStatus | `disabled`>\n isLoading: Signal<boolean>\n isReady: Signal<boolean>\n persistedStatus: Signal<LiveQueryPersistedStatus>\n isPersistedReady: Signal<boolean>\n persistedError: Signal<unknown | undefined>\n isIdle: Signal<boolean>\n isError: Signal<boolean>\n isCleanedUp: Signal<boolean>\n}\n\nexport function injectLiveQuery<\n TContext extends Context,\n TParams extends any,\n>(options: {\n params: () => TParams\n query: (args: {\n params: TParams\n q: InitialQueryBuilder\n }) => QueryBuilder<TContext>\n}): InjectLiveQueryResult<TContext>\nexport function injectLiveQuery<\n TContext extends Context,\n TParams extends any,\n>(options: {\n params: () => TParams\n query: (args: {\n params: TParams\n q: InitialQueryBuilder\n }) => QueryBuilder<TContext> | undefined | null\n}): InjectConditionalLiveQueryResult<TContext>\nexport function injectLiveQuery<TContext extends Context>(\n queryFn: (q: InitialQueryBuilder) => QueryBuilder<TContext>,\n): InjectLiveQueryResult<TContext>\nexport function injectLiveQuery<TContext extends Context>(\n queryFn: (\n q: InitialQueryBuilder,\n ) => QueryBuilder<TContext> | undefined | null,\n): InjectConditionalLiveQueryResult<TContext>\nexport function injectLiveQuery<TContext extends Context>(\n config: LiveQueryCollectionConfig<TContext>,\n): InjectLiveQueryResult<TContext>\n// Pre-created collection without singleResult\nexport function injectLiveQuery<\n TResult extends object,\n TKey extends string | number,\n TUtils extends Record<string, any>,\n>(\n liveQueryCollection: Collection<TResult, TKey, TUtils> & NonSingleResult,\n): InjectLiveQueryResultWithCollection<TResult, TKey, TUtils>\n// Pre-created collection with singleResult\nexport function injectLiveQuery<\n TResult extends object,\n TKey extends string | number,\n TUtils extends Record<string, any>,\n>(\n liveQueryCollection: Collection<TResult, TKey, TUtils> & SingleResult,\n): InjectLiveQueryResultWithSingleResultCollection<TResult, TKey, TUtils>\nexport function injectLiveQuery(opts: any) {\n assertInInjectionContext(injectLiveQuery)\n const destroyRef = inject(DestroyRef)\n\n const collection = computed(() => {\n // Check if it's an existing collection\n if (isCollection(opts)) {\n return opts\n }\n\n if (typeof opts === `function`) {\n // Check if query function returns null/undefined (disabled query)\n const queryBuilder = new BaseQueryBuilder() as InitialQueryBuilder\n const result = opts(queryBuilder)\n\n if (result === undefined || result === null) {\n // Disabled query - return null\n return null\n }\n\n return resolveLiveQueryValue(result, { gcTime: 0 })\n }\n\n // Check if it's reactive query options\n const isReactiveQueryOptions =\n opts &&\n typeof opts === `object` &&\n typeof opts.query === `function` &&\n typeof opts.params === `function`\n\n if (isReactiveQueryOptions) {\n const { params, query } = opts\n const currentParams = params()\n\n // Check if query function returns null/undefined (disabled query)\n const queryBuilder = new BaseQueryBuilder() as InitialQueryBuilder\n const result = query({ params: currentParams, q: queryBuilder })\n\n if (result === undefined || result === null) {\n // Disabled query - return null\n return null\n }\n\n return resolveLiveQueryValue(result, { gcTime: 0 })\n }\n\n // Handle LiveQueryCollectionConfig objects. Default startSync/gcTime to\n // match the query-fn and reactive-options paths, but let an explicit value\n // in the config win — otherwise a bare `{ query }` never syncs.\n if (opts && typeof opts === `object` && typeof opts.query === `function`) {\n return createLiveQueryCollection({ startSync: true, gcTime: 0, ...opts })\n }\n\n throw new Error(`Invalid options provided to injectLiveQuery`)\n })\n\n const state = signal(new Map<string | number, any>())\n const internalData = signal<Array<any>>([])\n const statusValue = signal<CollectionStatus | `disabled`>(`idle`)\n const status = computed(() => {\n const value = statusValue()\n return value === `idle` && !collection() ? `disabled` : value\n })\n const persistedStatus = signal<LiveQueryPersistedStatus>(`unavailable`)\n const persistedError = signal<unknown>(undefined)\n\n // Returns single item for singleResult collections, array otherwise\n const data = computed(() => {\n const currentCollection = collection()\n if (!currentCollection) {\n return internalData()\n }\n return isSingleResultCollection(currentCollection)\n ? internalData()[0]\n : internalData()\n })\n\n const syncDataFromCollection = (\n currentCollection: Collection<any, any, any>,\n observer: LiveQueryObserver<any, any>,\n ) => {\n const newState = new Map(currentCollection.entries())\n const newData = Array.from(newState.values())\n\n state.set(newState)\n internalData.set(newData)\n const snapshot = observer.getSnapshot()\n statusValue.set(snapshot.status)\n persistedStatus.set(snapshot.persistedStatus)\n persistedError.set(snapshot.persistedError)\n }\n\n let unsub: (() => void) | null = null\n const cleanup = () => {\n unsub?.()\n unsub = null\n }\n\n effect((onCleanup) => {\n const currentCollection = collection()\n\n // Handle null collection (disabled query)\n if (!currentCollection) {\n statusValue.set(`disabled` as const)\n persistedStatus.set(`unavailable`)\n persistedError.set(undefined)\n state.set(new Map())\n internalData.set([])\n cleanup()\n return\n }\n\n cleanup()\n\n // The shared observer owns sync start, subscription, the ready-race, and\n // status transitions; Angular re-reads the whole collection on each notify\n // (wholesale) into its signals.\n // Angular re-reads the collection on notify; wholesale mode preserves its\n // pre-observer loading policy (no initial-state snapshot request).\n const observer = createLiveQueryObserver(currentCollection, {\n mode: `wholesale`,\n })\n\n const unsubscribe = observer.subscribe(() => {\n syncDataFromCollection(currentCollection, observer)\n })\n // Wholesale attach suppresses listener calls raised by synchronous sync\n // startup. Read once after subscribe returns to capture that final state.\n syncDataFromCollection(currentCollection, observer)\n unsub = () => {\n unsubscribe()\n observer.dispose()\n }\n\n onCleanup(cleanup)\n })\n\n destroyRef.onDestroy(cleanup)\n\n return {\n state,\n data,\n // Loosely typed so the impl return stays compatible with every overload\n // (the shared `isCollection` guard narrows the computed to `Collection | null`).\n collection: computed(() =>\n getPublicCollection(collection()),\n ) as Signal<any>,\n status,\n isLoading: computed(() => status() === `loading`),\n isReady: computed(() => status() === `ready` || status() === `disabled`),\n persistedStatus,\n isPersistedReady: computed(() => persistedStatus() === `ready`),\n persistedError,\n isIdle: computed(() => status() === `idle`),\n isError: computed(() => status() === `error`),\n isCleanedUp: computed(() => status() === `cleaned-up`),\n }\n}\n"],"names":[],"mappings":";;;AAoKO,SAAS,gBAAgB,MAAW;AACzC,2BAAyB,eAAe;AACxC,QAAM,aAAa,OAAO,UAAU;AAEpC,QAAM,aAAa,SAAS,MAAM;AAEhC,QAAI,aAAa,IAAI,GAAG;AACtB,aAAO;AAAA,IACT;AAEA,QAAI,OAAO,SAAS,YAAY;AAE9B,YAAM,eAAe,IAAI,iBAAA;AACzB,YAAM,SAAS,KAAK,YAAY;AAEhC,UAAI,WAAW,UAAa,WAAW,MAAM;AAE3C,eAAO;AAAA,MACT;AAEA,aAAO,sBAAsB,QAAQ,EAAE,QAAQ,GAAG;AAAA,IACpD;AAGA,UAAM,yBACJ,QACA,OAAO,SAAS,YAChB,OAAO,KAAK,UAAU,cACtB,OAAO,KAAK,WAAW;AAEzB,QAAI,wBAAwB;AAC1B,YAAM,EAAE,QAAQ,MAAA,IAAU;AAC1B,YAAM,gBAAgB,OAAA;AAGtB,YAAM,eAAe,IAAI,iBAAA;AACzB,YAAM,SAAS,MAAM,EAAE,QAAQ,eAAe,GAAG,cAAc;AAE/D,UAAI,WAAW,UAAa,WAAW,MAAM;AAE3C,eAAO;AAAA,MACT;AAEA,aAAO,sBAAsB,QAAQ,EAAE,QAAQ,GAAG;AAAA,IACpD;AAKA,QAAI,QAAQ,OAAO,SAAS,YAAY,OAAO,KAAK,UAAU,YAAY;AACxE,aAAO,0BAA0B,EAAE,WAAW,M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,WAAW,wBAAwB,mBAAmB;AAAA,MAC1D,MAAM;AAAA,IAAA,CACP;AAED,UAAM,cAAc,SAAS,UAAU,MAAM;AAC3C,6BAAuB,mBAAmB,QAAQ;AAAA,IACpD,CAAC;AAGD,2BAAuB,mBAAmB,QAAQ;AAClD,YAAQ,MAAM;AACZ,kBAAA;AACA,eAAS,QAAA;AAAA,IACX;AAEA,cAAU,OAAO;AAAA,EACnB,CAAC;AAED,aAAW,UAAU,OAAO;AAE5B,SAAO;AAAA,IACL;AAAA,IACA;AAAA;AAAA;AAAA,IAGA,YAAY;AAAA,MAAS,MACnB,oBAAoB,WAAA,CAAY;AAAA,IAAA;AAAA,IAElC;AAAA,IACA,WAAW,SAAS,MAAM,OAAA,MAAa,SAAS;AAAA,IAChD,SAAS,SAAS,MAAM,aAAa,WAAW,OAAA,MAAa,UAAU;AAAA,IACvE;AAAA,IACA,kBAAkB,SAAS,MAAM,gBAAA,MAAsB,OAAO;AAAA,IAC9D;AAAA,IACA,QAAQ,SAAS,MAAM,OAAA,MAAa,MAAM;AAAA,IAC1C,SAAS,SAAS,MAAM,OAAA,MAAa,OAAO;AAAA,IAC5C,aAAa,SAAS,MAAM,OAAA,MAAa,YAAY;AAAA,EAAA;AAEzD;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["import {\n DestroyRef,\n assertInInjectionContext,\n computed,\n effect,\n inject,\n signal,\n} from '@angular/core'\nimport {\n BaseQueryBuilder,\n createLiveQueryObserver,\n getPublicCollection,\n isCollection,\n isSingleResultCollection,\n resolveLiveQueryValue,\n} from '@tanstack/db'\nimport type {\n Collection,\n CollectionStatus,\n Context,\n GetResult,\n InferResultType,\n InitialQueryBuilder,\n LiveQueryCollectionConfig,\n LiveQueryObserver,\n LiveQueryPersistedStatus,\n NonSingleResult,\n QueryBuilder,\n SingleResult,\n} from '@tanstack/db'\nimport type { Signal } from '@angular/core'\n\nconst DEFAULT_GC_TIME_MS = 1\n\nexport * from '@tanstack/db'\n\n/**\n * The result of calling `injectLiveQuery`.\n * Contains reactive signals for the query state and data.\n */\nexport interface InjectLiveQueryResult<TContext extends Context> {\n /** A signal containing the complete state map of results keyed by their ID */\n state: Signal<Map<string | number, GetResult<TContext>>>\n /** A signal containing the results as an array, or single result for findOne queries */\n data: Signal<InferResultType<TContext>>\n /** A signal containing the underlying collection instance (null for disabled queries) */\n collection: Signal<Collection<\n GetResult<TContext>,\n string | number,\n {}\n > | null>\n /** A signal containing the current status of the collection */\n status: Signal<CollectionStatus | `disabled`>\n /** A signal indicating whether the collection is currently loading */\n isLoading: Signal<boolean>\n /** A signal indicating whether the collection is ready */\n isReady: Signal<boolean>\n persistedStatus: Signal<LiveQueryPersistedStatus>\n isPersistedReady: Signal<boolean>\n persistedError: Signal<unknown | undefined>\n /** A signal indicating whether the collection is idle */\n isIdle: Signal<boolean>\n /** A signal indicating whether the collection has an error */\n isError: Signal<boolean>\n /** A signal indicating whether the collection has been cleaned up */\n isCleanedUp: Signal<boolean>\n}\n\ntype InferConditionalResultType<TContext extends Context> =\n TContext extends SingleResult\n ? InferResultType<TContext> | []\n : InferResultType<TContext>\n\nexport type InjectConditionalLiveQueryResult<TContext extends Context> = Omit<\n InjectLiveQueryResult<TContext>,\n `data`\n> & {\n data: Signal<InferConditionalResultType<TContext>>\n}\n\nexport interface InjectLiveQueryResultWithCollection<\n TResult extends object = any,\n TKey extends string | number = string | number,\n TUtils extends Record<string, any> = {},\n> {\n state: Signal<Map<TKey, TResult>>\n data: Signal<Array<TResult>>\n collection: Signal<Collection<TResult, TKey, TUtils> | null>\n status: Signal<CollectionStatus | `disabled`>\n isLoading: Signal<boolean>\n isReady: Signal<boolean>\n persistedStatus: Signal<LiveQueryPersistedStatus>\n isPersistedReady: Signal<boolean>\n persistedError: Signal<unknown | undefined>\n isIdle: Signal<boolean>\n isError: Signal<boolean>\n isCleanedUp: Signal<boolean>\n}\n\nexport interface InjectLiveQueryResultWithSingleResultCollection<\n TResult extends object = any,\n TKey extends string | number = string | number,\n TUtils extends Record<string, any> = {},\n> {\n state: Signal<Map<TKey, TResult>>\n data: Signal<TResult | undefined>\n collection: Signal<(Collection<TResult, TKey, TUtils> & SingleResult) | null>\n status: Signal<CollectionStatus | `disabled`>\n isLoading: Signal<boolean>\n isReady: Signal<boolean>\n persistedStatus: Signal<LiveQueryPersistedStatus>\n isPersistedReady: Signal<boolean>\n persistedError: Signal<unknown | undefined>\n isIdle: Signal<boolean>\n isError: Signal<boolean>\n isCleanedUp: Signal<boolean>\n}\n\nexport function injectLiveQuery<\n TContext extends Context,\n TParams extends any,\n>(options: {\n params: () => TParams\n query: (args: {\n params: TParams\n q: InitialQueryBuilder\n }) => QueryBuilder<TContext>\n}): InjectLiveQueryResult<TContext>\nexport function injectLiveQuery<\n TContext extends Context,\n TParams extends any,\n>(options: {\n params: () => TParams\n query: (args: {\n params: TParams\n q: InitialQueryBuilder\n }) => QueryBuilder<TContext> | undefined | null\n}): InjectConditionalLiveQueryResult<TContext>\nexport function injectLiveQuery<TContext extends Context>(\n queryFn: (q: InitialQueryBuilder) => QueryBuilder<TContext>,\n): InjectLiveQueryResult<TContext>\nexport function injectLiveQuery<TContext extends Context>(\n queryFn: (\n q: InitialQueryBuilder,\n ) => QueryBuilder<TContext> | undefined | null,\n): InjectConditionalLiveQueryResult<TContext>\nexport function injectLiveQuery<TContext extends Context>(\n config: LiveQueryCollectionConfig<TContext>,\n): InjectLiveQueryResult<TContext>\n// Pre-created collection without singleResult\nexport function injectLiveQuery<\n TResult extends object,\n TKey extends string | number,\n TUtils extends Record<string, any>,\n>(\n liveQueryCollection: Collection<TResult, TKey, TUtils> & NonSingleResult,\n): InjectLiveQueryResultWithCollection<TResult, TKey, TUtils>\n// Pre-created collection with singleResult\nexport function injectLiveQuery<\n TResult extends object,\n TKey extends string | number,\n TUtils extends Record<string, any>,\n>(\n liveQueryCollection: Collection<TResult, TKey, TUtils> & SingleResult,\n): InjectLiveQueryResultWithSingleResultCollection<TResult, TKey, TUtils>\nexport function injectLiveQuery(opts: any) {\n assertInInjectionContext(injectLiveQuery)\n const destroyRef = inject(DestroyRef)\n\n const collection = computed(() => {\n // Check if it's an existing collection\n if (isCollection(opts)) {\n return opts\n }\n\n if (typeof opts === `function`) {\n // Check if query function returns null/undefined (disabled query)\n const queryBuilder = new BaseQueryBuilder() as InitialQueryBuilder\n const result = opts(queryBuilder)\n\n if (result === undefined || result === null) {\n // Disabled query - return null\n return null\n }\n\n return resolveLiveQueryValue(result, { gcTime: DEFAULT_GC_TIME_MS })\n }\n\n // Check if it's reactive query options\n const isReactiveQueryOptions =\n opts &&\n typeof opts === `object` &&\n typeof opts.query === `function` &&\n typeof opts.params === `function`\n\n if (isReactiveQueryOptions) {\n const { params, query } = opts\n const currentParams = params()\n\n // Check if query function returns null/undefined (disabled query)\n const queryBuilder = new BaseQueryBuilder() as InitialQueryBuilder\n const result = query({ params: currentParams, q: queryBuilder })\n\n if (result === undefined || result === null) {\n // Disabled query - return null\n return null\n }\n\n return resolveLiveQueryValue(result, { gcTime: DEFAULT_GC_TIME_MS })\n }\n\n // Handle LiveQueryCollectionConfig objects. Default startSync/gcTime to\n // match the query-fn and reactive-options paths, but let an explicit value\n // in the config win — otherwise a bare `{ query }` never syncs.\n if (opts && typeof opts === `object` && typeof opts.query === `function`) {\n return resolveLiveQueryValue(opts, { gcTime: DEFAULT_GC_TIME_MS })\n }\n\n throw new Error(`Invalid options provided to injectLiveQuery`)\n })\n\n const state = signal(new Map<string | number, any>())\n const internalData = signal<Array<any>>([])\n const statusValue = signal<CollectionStatus | `disabled`>(`idle`)\n const status = computed(() => {\n const value = statusValue()\n return value === `idle` && !collection() ? `disabled` : value\n })\n const persistedStatus = signal<LiveQueryPersistedStatus>(`unavailable`)\n const persistedError = signal<unknown>(undefined)\n\n // Returns single item for singleResult collections, array otherwise\n const data = computed(() => {\n const currentCollection = collection()\n if (!currentCollection) {\n return internalData()\n }\n return isSingleResultCollection(currentCollection)\n ? internalData()[0]\n : internalData()\n })\n\n const syncDataFromCollection = (\n currentCollection: Collection<any, any, any>,\n observer: LiveQueryObserver<any, any>,\n ) => {\n const newState = new Map(currentCollection.entries())\n const newData = Array.from(newState.values())\n\n state.set(newState)\n internalData.set(newData)\n const snapshot = observer.getSnapshot()\n statusValue.set(snapshot.status)\n persistedStatus.set(snapshot.persistedStatus)\n persistedError.set(snapshot.persistedError)\n }\n\n let unsub: (() => void) | null = null\n const cleanup = () => {\n unsub?.()\n unsub = null\n }\n\n effect((onCleanup) => {\n const currentCollection = collection()\n\n // Handle null collection (disabled query)\n if (!currentCollection) {\n statusValue.set(`disabled` as const)\n persistedStatus.set(`unavailable`)\n persistedError.set(undefined)\n state.set(new Map())\n internalData.set([])\n cleanup()\n return\n }\n\n cleanup()\n\n // The shared observer owns sync start, subscription, the ready-race, and\n // status transitions; Angular re-reads the whole collection on each notify\n // (wholesale) into its signals.\n // Angular re-reads the collection on notify; wholesale mode preserves its\n // pre-observer loading policy (no initial-state snapshot request).\n const observer = createLiveQueryObserver(currentCollection, {\n mode: `wholesale`,\n })\n\n const unsubscribe = observer.subscribe(() => {\n syncDataFromCollection(currentCollection, observer)\n })\n // Wholesale attach suppresses listener calls raised by synchronous sync\n // startup. Read once after subscribe returns to capture that final state.\n syncDataFromCollection(currentCollection, observer)\n unsub = () => {\n unsubscribe()\n observer.dispose()\n }\n\n onCleanup(cleanup)\n })\n\n destroyRef.onDestroy(cleanup)\n\n return {\n state,\n data,\n // Loosely typed so the impl return stays compatible with every overload\n // (the shared `isCollection` guard narrows the computed to `Collection | null`).\n collection: computed(() =>\n getPublicCollection(collection()),\n ) as Signal<any>,\n status,\n isLoading: computed(() => status() === `loading`),\n isReady: computed(() => status() === `ready` || status() === `disabled`),\n persistedStatus,\n isPersistedReady: computed(() => persistedStatus() === `ready`),\n persistedError,\n isIdle: computed(() => status() === `idle`),\n isError: computed(() => status() === `error`),\n isCleanedUp: computed(() => status() === `cleaned-up`),\n }\n}\n"],"names":[],"mappings":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AAS,MACnB,oBAAoB,WAAA,CAAY;AAAA,IAAA;AAAA,IAElC;AAAA,IACA,WAAW,SAAS,MAAM,OAAA,MAAa,SAAS;AAAA,IAChD,SAAS,SAAS,MAAM,aAAa,WAAW,OAAA,MAAa,UAAU;AAAA,IACvE;AAAA,IACA,kBAAkB,SAAS,MAAM,gBAAA,MAAsB,OAAO;AAAA,IAC9D;AAAA,IACA,QAAQ,SAAS,MAAM,OAAA,MAAa,MAAM;AAAA,IAC1C,SAAS,SAAS,MAAM,OAAA,MAAa,OAAO;AAAA,IAC5C,aAAa,SAAS,MAAM,OAAA,MAAa,YAAY;AAAA,EAAA;AAEzD;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/angular-db",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.12",
|
|
4
4
|
"description": "Angular integration for @tanstack/db",
|
|
5
5
|
"author": "Ethan McDaniel",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"skills"
|
|
41
41
|
],
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@tanstack/db": "0.15.
|
|
43
|
+
"@tanstack/db": "0.15.2"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"@angular/core": ">=16.0.0",
|
|
@@ -101,7 +101,7 @@ const query = injectLiveQuery({
|
|
|
101
101
|
})
|
|
102
102
|
```
|
|
103
103
|
|
|
104
|
-
A bare `{ query }` config defaults to `startSync: true` and `gcTime:
|
|
104
|
+
A bare `{ query }` config defaults to `startSync: true` and `gcTime: 1`, like
|
|
105
105
|
the query-function overload. Explicit values in the config override those
|
|
106
106
|
defaults.
|
|
107
107
|
|
package/src/index.ts
CHANGED
|
@@ -8,7 +8,6 @@ import {
|
|
|
8
8
|
} from '@angular/core'
|
|
9
9
|
import {
|
|
10
10
|
BaseQueryBuilder,
|
|
11
|
-
createLiveQueryCollection,
|
|
12
11
|
createLiveQueryObserver,
|
|
13
12
|
getPublicCollection,
|
|
14
13
|
isCollection,
|
|
@@ -31,6 +30,8 @@ import type {
|
|
|
31
30
|
} from '@tanstack/db'
|
|
32
31
|
import type { Signal } from '@angular/core'
|
|
33
32
|
|
|
33
|
+
const DEFAULT_GC_TIME_MS = 1
|
|
34
|
+
|
|
34
35
|
export * from '@tanstack/db'
|
|
35
36
|
|
|
36
37
|
/**
|
|
@@ -182,7 +183,7 @@ export function injectLiveQuery(opts: any) {
|
|
|
182
183
|
return null
|
|
183
184
|
}
|
|
184
185
|
|
|
185
|
-
return resolveLiveQueryValue(result, { gcTime:
|
|
186
|
+
return resolveLiveQueryValue(result, { gcTime: DEFAULT_GC_TIME_MS })
|
|
186
187
|
}
|
|
187
188
|
|
|
188
189
|
// Check if it's reactive query options
|
|
@@ -205,14 +206,14 @@ export function injectLiveQuery(opts: any) {
|
|
|
205
206
|
return null
|
|
206
207
|
}
|
|
207
208
|
|
|
208
|
-
return resolveLiveQueryValue(result, { gcTime:
|
|
209
|
+
return resolveLiveQueryValue(result, { gcTime: DEFAULT_GC_TIME_MS })
|
|
209
210
|
}
|
|
210
211
|
|
|
211
212
|
// Handle LiveQueryCollectionConfig objects. Default startSync/gcTime to
|
|
212
213
|
// match the query-fn and reactive-options paths, but let an explicit value
|
|
213
214
|
// in the config win — otherwise a bare `{ query }` never syncs.
|
|
214
215
|
if (opts && typeof opts === `object` && typeof opts.query === `function`) {
|
|
215
|
-
return
|
|
216
|
+
return resolveLiveQueryValue(opts, { gcTime: DEFAULT_GC_TIME_MS })
|
|
216
217
|
}
|
|
217
218
|
|
|
218
219
|
throw new Error(`Invalid options provided to injectLiveQuery`)
|