@kedem/okdb 1.0.4 → 1.1.0
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/README.md +13 -4
- package/bin/okdb.js +1 -1
- package/docs/OKDB-ARCHITECTURE.md +2 -1
- package/docs/manifest.json +1 -0
- package/docs/pipelines.md +2 -0
- package/docs/views.md +351 -0
- package/okdb.js +1 -1
- package/package.json +1 -1
- package/public/sections/queue/parts/queue-buckets.ok.js +1 -1
- package/public/sections/queue/parts/queue-jobs.ok.js +1 -1
- package/public/sections/views/modals/create-view-modal.ok.js +1 -1
- package/public/sections/views/parts/view-detail.ok.js +1 -1
- package/public/sections/views/parts/views-overview.ok.js +1 -1
- package/types/features/views.d.ts +142 -10
|
@@ -1,16 +1,148 @@
|
|
|
1
|
+
/** Sift-style (MongoDB-compatible) filter object */
|
|
2
|
+
export type OKDBFilter = Record<string, unknown>;
|
|
3
|
+
|
|
4
|
+
/** Map operator specs */
|
|
5
|
+
export type OKDBMapRefSpec = { $ref: [type: string, fkField: string, targetField: string] };
|
|
6
|
+
export type OKDBMapConcatSpec = { $concat: string[] };
|
|
7
|
+
export type OKDBMapCoalesceSpec = { $coalesce: string[] };
|
|
8
|
+
export type OKDBMapFieldSpec = string | OKDBMapRefSpec | OKDBMapConcatSpec | OKDBMapCoalesceSpec;
|
|
9
|
+
|
|
10
|
+
/** Declarative per-doc transform merged onto source docs before reducers run */
|
|
11
|
+
export type OKDBViewMap = Record<string, OKDBMapFieldSpec>;
|
|
12
|
+
|
|
13
|
+
/** Built-in reducer specs */
|
|
14
|
+
export type OKDBCountSpec = { $count: true; items?: boolean };
|
|
15
|
+
export type OKDBSumSpec = { $sum: string; items?: boolean };
|
|
16
|
+
export type OKDBAvgSpec = { $avg: string; items?: boolean };
|
|
17
|
+
export type OKDBMinSpec = { $min: string; items?: boolean };
|
|
18
|
+
export type OKDBMaxSpec = { $max: string; items?: boolean };
|
|
19
|
+
export type OKDBCountBySpec = { $countBy: string; items?: boolean };
|
|
20
|
+
export type OKDBCustomSpec = { [reducer: string]: unknown; items?: boolean };
|
|
21
|
+
|
|
22
|
+
/** $ref sub-view aggregation */
|
|
23
|
+
export interface OKDBRefSpec {
|
|
24
|
+
type: string;
|
|
25
|
+
key: string;
|
|
26
|
+
filter?: OKDBFilter;
|
|
27
|
+
reduce: Record<string, OKDBReducerSpec>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type OKDBReducerSpec =
|
|
31
|
+
| OKDBCountSpec
|
|
32
|
+
| OKDBSumSpec
|
|
33
|
+
| OKDBAvgSpec
|
|
34
|
+
| OKDBMinSpec
|
|
35
|
+
| OKDBMaxSpec
|
|
36
|
+
| OKDBCountBySpec
|
|
37
|
+
| { $ref: OKDBRefSpec }
|
|
38
|
+
| OKDBCustomSpec;
|
|
39
|
+
|
|
40
|
+
/** View definition passed to views.create() */
|
|
1
41
|
export interface OKDBViewDefinition {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
42
|
+
/** Source type. Must be registered in this environment. */
|
|
43
|
+
type: string;
|
|
44
|
+
/** Optional sift-style filter. Only matching docs contribute to the view. */
|
|
45
|
+
filter?: OKDBFilter;
|
|
46
|
+
/** Optional declarative transform applied to each doc before reducers run. */
|
|
47
|
+
map?: OKDBViewMap;
|
|
48
|
+
/** Required, non-empty. Maps output field names to reducer specs. */
|
|
49
|
+
reduce: Record<string, OKDBReducerSpec>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Shape returned for a scalar reducer output ($count, $sum, $avg, $min, $max) */
|
|
53
|
+
export interface OKDBScalarResult {
|
|
54
|
+
value: number | null;
|
|
55
|
+
/** Present when items:true was set — returns the live source docs for this bucket */
|
|
56
|
+
items?: () => unknown[];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Shape returned for a $countBy reducer output */
|
|
60
|
+
export type OKDBCountByResult = Record<string, OKDBScalarResult>;
|
|
61
|
+
|
|
62
|
+
/** Shape returned for a $ref slot */
|
|
63
|
+
export type OKDBRefResult = Record<string, OKDBScalarResult | OKDBCountByResult>;
|
|
64
|
+
|
|
65
|
+
/** The full output object returned by views.get() */
|
|
66
|
+
export type OKDBViewOutput = Record<string, OKDBScalarResult | OKDBCountByResult | OKDBRefResult>;
|
|
67
|
+
|
|
68
|
+
/** View lifecycle meta returned by views.getMeta() */
|
|
69
|
+
export interface OKDBViewMeta {
|
|
70
|
+
state: 'creating' | 'ready' | 'halted' | 'stopped' | 'resetting';
|
|
71
|
+
clock: number;
|
|
72
|
+
error: { clock: number; key: string; error: string } | null;
|
|
73
|
+
refs: Record<string, { state: string; clock: number; error: string | null }>;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Stored view definition returned by views.getDefinition() (includes name and createdAt) */
|
|
77
|
+
export type OKDBStoredViewDefinition = OKDBViewDefinition & { name: string; createdAt: number };
|
|
78
|
+
|
|
79
|
+
/** Options for views.remove() */
|
|
80
|
+
export interface OKDBViewRemoveOptions {
|
|
81
|
+
/**
|
|
82
|
+
* How to handle indexes auto-created by this view.
|
|
83
|
+
* Required when the view owns indexes that would otherwise become orphaned.
|
|
84
|
+
* - 'drop' — drop the index
|
|
85
|
+
* - 'keep' — retain the index (it becomes unowned)
|
|
86
|
+
*/
|
|
87
|
+
managedIndexes?: 'drop' | 'keep';
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Custom reducer registration */
|
|
91
|
+
export interface OKDBCustomReducer {
|
|
92
|
+
apply(state: unknown, before: unknown, after: unknown, opts: unknown): unknown;
|
|
8
93
|
}
|
|
9
94
|
|
|
10
95
|
export declare class OKDBViews {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
96
|
+
/**
|
|
97
|
+
* Create a new materialized view. The source type must already be registered.
|
|
98
|
+
* Synchronously bootstraps existing documents then registers an incremental processor.
|
|
99
|
+
*/
|
|
100
|
+
create(name: string, definition: OKDBViewDefinition): Promise<{ name: string }>;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Read the current view output. Synchronous and O(1).
|
|
104
|
+
* Returns null if the view does not exist.
|
|
105
|
+
*/
|
|
106
|
+
get(name: string): OKDBViewOutput | null;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Get view lifecycle meta (state, clock, error).
|
|
110
|
+
* Returns null if the view does not exist.
|
|
111
|
+
*/
|
|
112
|
+
getMeta(name: string): OKDBViewMeta | null;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Get the stored view definition.
|
|
116
|
+
* Returns null if the view does not exist.
|
|
117
|
+
*/
|
|
118
|
+
getDefinition(name: string): Promise<OKDBStoredViewDefinition | null>;
|
|
119
|
+
|
|
120
|
+
/** List all view names in this environment. */
|
|
121
|
+
list(): Promise<string[]>;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Remove a view. Pass managedIndexes when the view owns auto-created indexes.
|
|
125
|
+
*/
|
|
126
|
+
remove(name: string, options?: OKDBViewRemoveOptions): Promise<void>;
|
|
127
|
+
|
|
128
|
+
/** Clears all accumulated state and re-scans from scratch. */
|
|
129
|
+
rebuild(name: string): Promise<void>;
|
|
130
|
+
|
|
131
|
+
/** Pause the view. Writes that arrive while stopped are replayed on start(). */
|
|
132
|
+
stop(name: string): Promise<void>;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Resume a stopped (or halted) view.
|
|
136
|
+
* Optimistically catches up with new inserts; performs a full rebuild otherwise.
|
|
137
|
+
*/
|
|
138
|
+
start(name: string): Promise<void>;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Register a custom reducer. Must be called before creating any view that uses it.
|
|
142
|
+
* The name must start with '$' and must not conflict with a built-in reducer.
|
|
143
|
+
*/
|
|
144
|
+
registerReducer(name: string, reducer: OKDBCustomReducer): void;
|
|
145
|
+
|
|
146
|
+
/** @internal Called by OKDB after sync to activate views that arrived from peers. */
|
|
15
147
|
bootSyncedViews(): Promise<void>;
|
|
16
148
|
}
|