@arcote.tech/arc 0.3.4 → 0.3.5
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.
|
@@ -8,5 +8,12 @@ export * from "./context-element";
|
|
|
8
8
|
export * from "./event";
|
|
9
9
|
export * from "./listener";
|
|
10
10
|
export * from "./route";
|
|
11
|
+
export * from "./static-view";
|
|
11
12
|
export * from "./view";
|
|
13
|
+
import type { ArcStaticViewAny, ArcStaticViewRecord } from "./static-view";
|
|
14
|
+
import type { ArcViewAny, ArcViewRecord } from "./view";
|
|
15
|
+
/**
|
|
16
|
+
* Helper type to extract record type from any view (regular or static)
|
|
17
|
+
*/
|
|
18
|
+
export type ArcAnyViewRecord<View extends ArcViewAny | ArcStaticViewAny> = View extends ArcViewAny ? ArcViewRecord<View> : View extends ArcStaticViewAny ? ArcStaticViewRecord<View> : never;
|
|
12
19
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -104,7 +104,7 @@ export declare class ArcStaticView<const Data extends ArcStaticViewData> extends
|
|
|
104
104
|
export declare function staticView<const Name extends string, Id, Schema extends ArcObjectAny | ArcRawShape>(name: Name, id: Id, schema: Schema): ArcStaticView<{
|
|
105
105
|
name: Name;
|
|
106
106
|
id: Id;
|
|
107
|
-
schema: ArcObject<ArcRawShape, [{
|
|
107
|
+
schema: (Schema & ArcObject<any, any>) | ArcObject<ArcRawShape, [{
|
|
108
108
|
name: "type";
|
|
109
109
|
validator: (value: any) => false | {
|
|
110
110
|
current: "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function";
|
|
@@ -115,7 +115,7 @@ export declare function staticView<const Name extends string, Id, Schema extends
|
|
|
115
115
|
validator: (value: any) => false | {
|
|
116
116
|
[x: string]: unknown;
|
|
117
117
|
};
|
|
118
|
-
}]
|
|
118
|
+
}]>;
|
|
119
119
|
items: [];
|
|
120
120
|
}>;
|
|
121
121
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1931,6 +1931,84 @@ function route(name) {
|
|
|
1931
1931
|
isPublic: false
|
|
1932
1932
|
});
|
|
1933
1933
|
}
|
|
1934
|
+
// src/context-element/static-view/static-view.ts
|
|
1935
|
+
class ArcStaticView extends ArcContextElement {
|
|
1936
|
+
data;
|
|
1937
|
+
constructor(data) {
|
|
1938
|
+
super(data.name);
|
|
1939
|
+
this.data = data;
|
|
1940
|
+
}
|
|
1941
|
+
get id() {
|
|
1942
|
+
return this.data.id;
|
|
1943
|
+
}
|
|
1944
|
+
get schema() {
|
|
1945
|
+
return this.data.schema;
|
|
1946
|
+
}
|
|
1947
|
+
get items() {
|
|
1948
|
+
return this.data.items;
|
|
1949
|
+
}
|
|
1950
|
+
description(description) {
|
|
1951
|
+
return new ArcStaticView({
|
|
1952
|
+
...this.data,
|
|
1953
|
+
description
|
|
1954
|
+
});
|
|
1955
|
+
}
|
|
1956
|
+
addItems(items) {
|
|
1957
|
+
return new ArcStaticView({
|
|
1958
|
+
...this.data,
|
|
1959
|
+
items
|
|
1960
|
+
});
|
|
1961
|
+
}
|
|
1962
|
+
queryContext(_adapters) {
|
|
1963
|
+
const items = this.data.items;
|
|
1964
|
+
return {
|
|
1965
|
+
find: async (options) => {
|
|
1966
|
+
let results = [...items];
|
|
1967
|
+
if (options?.where) {
|
|
1968
|
+
results = results.filter((item) => this.matchesWhere(item, options.where));
|
|
1969
|
+
}
|
|
1970
|
+
if (options?.orderBy) {
|
|
1971
|
+
const entries = Object.entries(options.orderBy);
|
|
1972
|
+
results.sort((a, b) => {
|
|
1973
|
+
for (const [key, direction] of entries) {
|
|
1974
|
+
const aVal = a[key];
|
|
1975
|
+
const bVal = b[key];
|
|
1976
|
+
if (aVal < bVal)
|
|
1977
|
+
return direction === "asc" ? -1 : 1;
|
|
1978
|
+
if (aVal > bVal)
|
|
1979
|
+
return direction === "asc" ? 1 : -1;
|
|
1980
|
+
}
|
|
1981
|
+
return 0;
|
|
1982
|
+
});
|
|
1983
|
+
}
|
|
1984
|
+
if (options?.limit) {
|
|
1985
|
+
results = results.slice(0, options.limit);
|
|
1986
|
+
}
|
|
1987
|
+
return results;
|
|
1988
|
+
},
|
|
1989
|
+
findOne: async (where) => {
|
|
1990
|
+
if (!where)
|
|
1991
|
+
return items[0];
|
|
1992
|
+
const item = items.find((item2) => this.matchesWhere(item2, where));
|
|
1993
|
+
return item;
|
|
1994
|
+
}
|
|
1995
|
+
};
|
|
1996
|
+
}
|
|
1997
|
+
matchesWhere(item, where) {
|
|
1998
|
+
return Object.entries(where).every(([key, value]) => {
|
|
1999
|
+
return item[key] === value;
|
|
2000
|
+
});
|
|
2001
|
+
}
|
|
2002
|
+
}
|
|
2003
|
+
function staticView(name, id2, schema) {
|
|
2004
|
+
const schemaObj = schema instanceof ArcObject ? schema : new ArcObject(schema);
|
|
2005
|
+
return new ArcStaticView({
|
|
2006
|
+
name,
|
|
2007
|
+
id: id2,
|
|
2008
|
+
schema: schemaObj,
|
|
2009
|
+
items: []
|
|
2010
|
+
});
|
|
2011
|
+
}
|
|
1934
2012
|
// src/context-element/view/view.ts
|
|
1935
2013
|
class ArcView extends ArcContextElement {
|
|
1936
2014
|
data;
|
|
@@ -3756,17 +3834,25 @@ class StreamingEventPublisher {
|
|
|
3756
3834
|
}
|
|
3757
3835
|
}
|
|
3758
3836
|
// src/streaming/streaming-live-query.ts
|
|
3837
|
+
function isStaticView(element2) {
|
|
3838
|
+
return element2 && "items" in element2 && !("getHandlers" in element2);
|
|
3839
|
+
}
|
|
3759
3840
|
function streamingLiveQuery(model, queryFn, callback, options) {
|
|
3760
3841
|
const { queryWire, cache, authToken } = options;
|
|
3761
3842
|
let currentResult = undefined;
|
|
3762
3843
|
const unsubscribers = [];
|
|
3763
3844
|
const queriedViews = new Set;
|
|
3845
|
+
const staticViews = new Set;
|
|
3764
3846
|
const queryContext = new Proxy({}, {
|
|
3765
3847
|
get(_target, viewName) {
|
|
3766
3848
|
const element2 = model.context.get(viewName);
|
|
3767
3849
|
if (!element2) {
|
|
3768
3850
|
throw new Error(`View '${viewName}' not found in context`);
|
|
3769
3851
|
}
|
|
3852
|
+
if (isStaticView(element2)) {
|
|
3853
|
+
staticViews.add(viewName);
|
|
3854
|
+
return element2.queryContext(model.getAdapters());
|
|
3855
|
+
}
|
|
3770
3856
|
queriedViews.add(viewName);
|
|
3771
3857
|
return {
|
|
3772
3858
|
find: async (findOptions = {}) => {
|
|
@@ -3787,7 +3873,12 @@ function streamingLiveQuery(model, queryFn, callback, options) {
|
|
|
3787
3873
|
};
|
|
3788
3874
|
const setupStreams = async () => {
|
|
3789
3875
|
queriedViews.clear();
|
|
3876
|
+
staticViews.clear();
|
|
3790
3877
|
await queryFn(queryContext);
|
|
3878
|
+
if (queriedViews.size === 0 && staticViews.size > 0) {
|
|
3879
|
+
executeQuery();
|
|
3880
|
+
return;
|
|
3881
|
+
}
|
|
3791
3882
|
for (const viewName of queriedViews) {
|
|
3792
3883
|
const store = cache.getStore(viewName);
|
|
3793
3884
|
const cacheUnsub = store.subscribe(() => {
|
|
@@ -4246,6 +4337,7 @@ export {
|
|
|
4246
4337
|
stringEnum,
|
|
4247
4338
|
string,
|
|
4248
4339
|
streamingLiveQuery,
|
|
4340
|
+
staticView,
|
|
4249
4341
|
secureDataStorage,
|
|
4250
4342
|
route,
|
|
4251
4343
|
resolveQueryChange,
|
|
@@ -4299,6 +4391,7 @@ export {
|
|
|
4299
4391
|
ArcToken,
|
|
4300
4392
|
ArcStringEnum,
|
|
4301
4393
|
ArcString,
|
|
4394
|
+
ArcStaticView,
|
|
4302
4395
|
ArcRoute,
|
|
4303
4396
|
ArcRecord,
|
|
4304
4397
|
ArcOr,
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* Uses SSE stream to get initial data and updates from server.
|
|
5
5
|
* Uses StreamingQueryCache for local state and reactivity.
|
|
6
6
|
* Deduplicates SSE streams - multiple queries on same view share one stream.
|
|
7
|
+
* Static views are handled directly without SSE.
|
|
7
8
|
*/
|
|
8
9
|
import type { QueryWire } from "../adapters/query-wire";
|
|
9
10
|
import type { ArcContextAny } from "../context/context";
|
|
@@ -20,6 +21,7 @@ export interface StreamingLiveQueryOptions {
|
|
|
20
21
|
*
|
|
21
22
|
* Opens SSE stream to server, populates cache, and reacts to changes.
|
|
22
23
|
* Reuses existing streams for the same view (deduplication via cache).
|
|
24
|
+
* Static views return data directly without SSE.
|
|
23
25
|
*/
|
|
24
26
|
export declare function streamingLiveQuery<C extends ArcContextAny, TResult>(model: Model<C>, queryFn: (q: QueryContext<C>) => Promise<TResult>, callback: (data: TResult) => void, options: StreamingLiveQueryOptions): LiveQueryResult<TResult>;
|
|
25
27
|
//# sourceMappingURL=streaming-live-query.d.ts.map
|
package/package.json
CHANGED