@arcote.tech/arc 0.1.12 → 0.3.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/dist/adapters/auth-adapter.d.ts +47 -0
- package/dist/adapters/command-wire.d.ts +28 -0
- package/dist/adapters/event-publisher.d.ts +106 -0
- package/dist/adapters/event-wire.d.ts +79 -0
- package/dist/adapters/index.d.ts +18 -0
- package/dist/adapters/wire.d.ts +20 -0
- package/dist/context/context.d.ts +49 -52
- package/dist/context/index.d.ts +1 -10
- package/dist/context-element/command/command-context.d.ts +71 -0
- package/dist/context-element/command/command-data.d.ts +33 -0
- package/dist/context-element/command/command-handler.d.ts +6 -0
- package/dist/context-element/command/command.d.ts +198 -0
- package/dist/context-element/command/index.d.ts +6 -0
- package/dist/context-element/context-element.d.ts +75 -0
- package/dist/context-element/event/event-data.d.ts +35 -0
- package/dist/context-element/event/event.d.ts +158 -0
- package/dist/context-element/event/index.d.ts +5 -0
- package/dist/context-element/event/instance.d.ts +26 -0
- package/dist/context-element/index.d.ts +10 -0
- package/dist/context-element/view/index.d.ts +5 -0
- package/dist/context-element/view/view-context.d.ts +51 -0
- package/dist/context-element/view/view-data.d.ts +40 -0
- package/dist/context-element/view/view.d.ts +194 -0
- package/dist/data-storage/data-storage-forked.d.ts +1 -1
- package/dist/data-storage/data-storage-master.d.ts +7 -10
- package/dist/data-storage/data-storage-observable.d.ts +61 -0
- package/dist/data-storage/data-storage.abstract.d.ts +1 -1
- package/dist/{db/interface.d.ts → data-storage/database-adapter.d.ts} +8 -3
- package/dist/{database → data-storage}/database-store.d.ts +45 -0
- package/dist/data-storage/{types.d.ts → find-options.d.ts} +1 -1
- package/dist/data-storage/index.d.ts +6 -2
- package/dist/{db/postgresAdapter.d.ts → data-storage/postgresql-adapter.d.ts} +7 -33
- package/dist/data-storage/query-result-resolver.d.ts +18 -0
- package/dist/data-storage/query-result-resolver.test.d.ts +2 -0
- package/dist/{db/sqliteAdapter.d.ts → data-storage/sqlite-adapter.d.ts} +5 -31
- package/dist/data-storage/store-state-fork.d.ts +1 -1
- package/dist/data-storage/store-state-master.d.ts +6 -2
- package/dist/data-storage/store-state.abstract.d.ts +1 -1
- package/dist/elements/abstract.d.ts +1 -1
- package/dist/elements/any.d.ts +1 -1
- package/dist/elements/array.d.ts +5 -5
- package/dist/elements/blob.d.ts +1 -1
- package/dist/elements/boolean.d.ts +1 -1
- package/dist/elements/branded.d.ts +5 -5
- package/dist/elements/date.d.ts +1 -1
- package/dist/elements/default.d.ts +5 -5
- package/dist/elements/file.d.ts +1 -1
- package/dist/elements/id.d.ts +3 -3
- package/dist/elements/index.d.ts +1 -0
- package/dist/elements/number.d.ts +1 -1
- package/dist/elements/object.d.ts +11 -10
- package/dist/elements/optional.d.ts +5 -5
- package/dist/elements/or.d.ts +5 -5
- package/dist/elements/record.d.ts +3 -3
- package/dist/elements/string-enum.d.ts +1 -1
- package/dist/elements/string.d.ts +1 -1
- package/dist/index.d.ts +8 -7
- package/dist/index.js +2373 -3439
- package/dist/model/index.d.ts +2 -0
- package/dist/model/live-query/index.d.ts +2 -0
- package/dist/model/live-query/live-query.d.ts +31 -0
- package/dist/model/live-query/query-cache.d.ts +60 -0
- package/dist/model/model-adapters.d.ts +13 -0
- package/dist/model/model.d.ts +19 -78
- package/dist/model/mutation-executor/index.d.ts +2 -0
- package/dist/model/mutation-executor/mutation-executor.d.ts +29 -0
- package/dist/token/index.d.ts +41 -0
- package/dist/token/secured-data-storage.d.ts +125 -0
- package/dist/token/token-cache.d.ts +100 -0
- package/dist/token/token-data.d.ts +38 -0
- package/dist/token/token-instance.d.ts +71 -0
- package/dist/token/token.d.ts +127 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/types/add-question-marks.d.ts +9 -0
- package/dist/utils/types/first-argument.d.ts +5 -0
- package/dist/utils/types/get-type.d.ts +13 -0
- package/dist/utils/types/index.d.ts +6 -0
- package/dist/utils/types/merge.d.ts +7 -0
- package/dist/utils/types/object-util.d.ts +6 -0
- package/dist/utils/types/simplify.d.ts +7 -0
- package/package.json +10 -6
- package/dist/command/command-definition.d.ts +0 -5
- package/dist/command/command.d.ts +0 -45
- package/dist/command/index.d.ts +0 -2
- package/dist/context/commands.d.ts +0 -12
- package/dist/context/element.d.ts +0 -80
- package/dist/context/event.d.ts +0 -45
- package/dist/context/query-builder-context.d.ts +0 -15
- package/dist/context/query-builders.d.ts +0 -17
- package/dist/context/query-cache.d.ts +0 -9
- package/dist/context/query.d.ts +0 -12
- package/dist/context/reactive-query.d.ts +0 -23
- package/dist/context/serializable-query.d.ts +0 -11
- package/dist/context/translator.d.ts +0 -4
- package/dist/database/database-mappers.d.ts +0 -39
- package/dist/database/index.d.ts +0 -3
- package/dist/db/index.d.ts +0 -4
- package/dist/listener/index.d.ts +0 -2
- package/dist/listener/listener.d.ts +0 -23
- package/dist/model/EventPublisher.d.ts +0 -12
- package/dist/model/event-publisher.d.ts +0 -12
- package/dist/query/query-definition.d.ts +0 -8
- package/dist/route/index.d.ts +0 -2
- package/dist/route/route.d.ts +0 -35
- package/dist/rtc/client.d.ts +0 -3
- package/dist/rtc/index.d.ts +0 -4
- package/dist/rtc/messages.d.ts +0 -20
- package/dist/rtc/rtc.d.ts +0 -11
- package/dist/server/query-handler.d.ts +0 -43
- package/dist/state/index.d.ts +0 -2
- package/dist/state/query-builder.d.ts +0 -2
- package/dist/state/query.d.ts +0 -2
- package/dist/state/state.d.ts +0 -2
- package/dist/strategies/cache-strategy.d.ts +0 -20
- package/dist/strategies/datastorage-strategy.d.ts +0 -15
- package/dist/strategies/index.d.ts +0 -7
- package/dist/strategies/leader-strategy.d.ts +0 -16
- package/dist/strategies/model-strategy.d.ts +0 -9
- package/dist/strategies/query-strategy.d.ts +0 -20
- package/dist/telemetry/context.d.ts +0 -65
- package/dist/telemetry/index.d.ts +0 -47
- package/dist/telemetry/interfaces.d.ts +0 -84
- package/dist/telemetry/logger.d.ts +0 -67
- package/dist/telemetry/no-op.d.ts +0 -54
- package/dist/telemetry/tracer.d.ts +0 -85
- package/dist/tests/context/context.test.d.ts +0 -2
- package/dist/tests/pipe.d.ts +0 -2
- package/dist/tests/query/advance-query.test.d.ts +0 -2
- package/dist/tests/query/collection-all.test.d.ts +0 -2
- package/dist/tests/utils/expect-not-false.d.ts +0 -2
- package/dist/tests/utils/sqlite-adapter.d.ts +0 -3
- package/dist/tests/utils/test-model.d.ts +0 -25
- package/dist/tests/validations/array.test.d.ts +0 -2
- package/dist/tests/validations/date.test.d.ts +0 -2
- package/dist/tests/validations/number.test.d.ts +0 -2
- package/dist/tests/validations/object.test.d.ts +0 -2
- package/dist/tests/validations/record.test.d.ts +0 -2
- package/dist/tests/validations/string-enum.test.d.ts +0 -2
- package/dist/tests/validations/string.test.d.ts +0 -2
- package/dist/utils.d.ts +0 -56
- package/dist/view/index.d.ts +0 -6
- package/dist/view/queries/abstract-view-query.d.ts +0 -19
- package/dist/view/queries/find-one.d.ts +0 -13
- package/dist/view/queries/find.d.ts +0 -21
- package/dist/view/queries/index.d.ts +0 -3
- package/dist/view/query-builders/find-one.d.ts +0 -14
- package/dist/view/query-builders/find.d.ts +0 -14
- package/dist/view/query-builders/index.d.ts +0 -2
- package/dist/view/query-builders/new-query-builder.d.ts +0 -2
- package/dist/view/record.d.ts +0 -4
- package/dist/view/static-view.d.ts +0 -43
- package/dist/view/view.d.ts +0 -68
- /package/dist/{database → data-storage}/schema-extraction.d.ts +0 -0
- /package/dist/{data-storage → utils}/deep-merge.d.ts +0 -0
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { ArcContextElement } from "../../context-element/context-element";
|
|
2
|
+
import type { DatabaseStoreSchema } from "../../data-storage/database-store";
|
|
3
|
+
import { type ArcObjectAny } from "../../elements/object";
|
|
4
|
+
import type { ArcTokenAny } from "../../token/token";
|
|
5
|
+
import type { TokenInstanceAny } from "../../token/token-instance";
|
|
6
|
+
import type { Merge } from "../../utils";
|
|
7
|
+
import type { ArcViewHandlerContext, ArcViewItem, ArcViewQueryContext } from "./view-context";
|
|
8
|
+
import type { ArcViewData, ViewProtectionFn } from "./view-data";
|
|
9
|
+
/**
|
|
10
|
+
* Arc View - Read-optimized projection of events
|
|
11
|
+
*
|
|
12
|
+
* Views are queryable collections built from events.
|
|
13
|
+
* They:
|
|
14
|
+
* - React to events and update their state
|
|
15
|
+
* - Provide optimized read access (find, findOne)
|
|
16
|
+
* - Can be queried by commands
|
|
17
|
+
* - Maintain denormalized data for fast reads
|
|
18
|
+
*
|
|
19
|
+
* Views follow the factory pattern from the Arc guide:
|
|
20
|
+
* - All configuration in a single Data object
|
|
21
|
+
* - Type-safe throughout
|
|
22
|
+
* - Immutable with clone-on-modify
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const tasks = view("tasks", taskId, taskSchema)
|
|
27
|
+
* .handleEvent(taskCreated, async (ctx, event) => {
|
|
28
|
+
* await ctx.set(event.payload.taskId, {
|
|
29
|
+
* title: event.payload.title,
|
|
30
|
+
* isCompleted: false,
|
|
31
|
+
* });
|
|
32
|
+
* })
|
|
33
|
+
* .handleEvent(taskCompleted, async (ctx, event) => {
|
|
34
|
+
* await ctx.modify(event.payload.taskId, {
|
|
35
|
+
* isCompleted: true,
|
|
36
|
+
* });
|
|
37
|
+
* });
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare class ArcView<const Data extends ArcViewData> extends ArcContextElement<Data["name"]> {
|
|
41
|
+
private readonly data;
|
|
42
|
+
constructor(data: Data);
|
|
43
|
+
/**
|
|
44
|
+
* Get view ID schema
|
|
45
|
+
*/
|
|
46
|
+
get id(): Data["id"];
|
|
47
|
+
/**
|
|
48
|
+
* Get view schema
|
|
49
|
+
*/
|
|
50
|
+
get schema(): Data["schema"];
|
|
51
|
+
/**
|
|
52
|
+
* Set view description for documentation
|
|
53
|
+
*/
|
|
54
|
+
description<const Desc extends string>(description: Desc): ArcView<Merge<Data, {
|
|
55
|
+
description: Desc;
|
|
56
|
+
}>>;
|
|
57
|
+
/**
|
|
58
|
+
* Mark view as async (handlers run asynchronously)
|
|
59
|
+
*/
|
|
60
|
+
async(): ArcView<Merge<Data, {
|
|
61
|
+
isAsync: true;
|
|
62
|
+
}>>;
|
|
63
|
+
/**
|
|
64
|
+
* Set view version for schema migrations
|
|
65
|
+
*/
|
|
66
|
+
version<const V extends number>(version: V): ArcView<Merge<Data, {
|
|
67
|
+
version: V;
|
|
68
|
+
}>>;
|
|
69
|
+
/**
|
|
70
|
+
* Declare which events this view listens to
|
|
71
|
+
* Must be called before handle() to register event dependencies
|
|
72
|
+
*
|
|
73
|
+
* @param events - Array of events this view reacts to
|
|
74
|
+
*/
|
|
75
|
+
listenTo<const Events extends ArcContextElement<any>[]>(events: Events): ArcView<Merge<Data, {
|
|
76
|
+
elements: Events;
|
|
77
|
+
}>>;
|
|
78
|
+
/**
|
|
79
|
+
* Add event handler for a specific event
|
|
80
|
+
* Handlers update view state in response to events
|
|
81
|
+
*
|
|
82
|
+
* @param event - Event to handle
|
|
83
|
+
* @param handler - Handler function that updates view state
|
|
84
|
+
*/
|
|
85
|
+
handleEvent<Event extends ArcContextElement<any>>(event: Event, handler: (ctx: ArcViewHandlerContext<Data["id"], Data["schema"]>, event: any) => Promise<void>): ArcView<Merge<Data, {
|
|
86
|
+
elements: [...Data["elements"], Event];
|
|
87
|
+
handler: Data["handler"] & { [K in Event["name"]]: typeof handler; };
|
|
88
|
+
}>>;
|
|
89
|
+
/**
|
|
90
|
+
* Set all event handlers at once
|
|
91
|
+
* Alternative to chaining handleEvent() calls
|
|
92
|
+
*
|
|
93
|
+
* @param handler - Object mapping event names to handlers
|
|
94
|
+
*/
|
|
95
|
+
handle<Handler extends Record<string, (ctx: any, event: any) => Promise<void>>>(handler: Handler): ArcView<Merge<Data, {
|
|
96
|
+
handler: Handler;
|
|
97
|
+
}>>;
|
|
98
|
+
/**
|
|
99
|
+
* Generate query context for this view
|
|
100
|
+
* Provides read access to view data
|
|
101
|
+
* Automatically applies token restrictions from protectBy
|
|
102
|
+
*
|
|
103
|
+
* @param adapters - Available adapters (storage, authAdapter)
|
|
104
|
+
* @returns Context object with find/findOne methods
|
|
105
|
+
*/
|
|
106
|
+
queryContext(adapters: any): ArcViewQueryContext<Data["id"], Data["schema"]>;
|
|
107
|
+
/**
|
|
108
|
+
* Get event handlers for this view
|
|
109
|
+
* Used by the framework to set up event listeners
|
|
110
|
+
*/
|
|
111
|
+
getHandlers(): Data["handler"];
|
|
112
|
+
/**
|
|
113
|
+
* Get elements (events) this view depends on
|
|
114
|
+
*/
|
|
115
|
+
getElements(): Data["elements"];
|
|
116
|
+
/**
|
|
117
|
+
* Add token-based protection to this view
|
|
118
|
+
* Defines read/write access conditions based on token params
|
|
119
|
+
*
|
|
120
|
+
* @param token - Token definition to protect with
|
|
121
|
+
* @param protectionFn - Function returning read/write conditions
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```typescript
|
|
125
|
+
* view("tasks", taskId, taskSchema)
|
|
126
|
+
* .protectBy(userToken, (params) => ({
|
|
127
|
+
* read: { userId: params.userId }, // Can only read own tasks
|
|
128
|
+
* write: { userId: params.userId }, // Can only write own tasks
|
|
129
|
+
* }));
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
protectBy<T extends ArcTokenAny>(token: T, protectionFn: ViewProtectionFn<any>): ArcView<Data>;
|
|
133
|
+
/**
|
|
134
|
+
* Check if view has protections
|
|
135
|
+
*/
|
|
136
|
+
get hasProtections(): boolean;
|
|
137
|
+
/**
|
|
138
|
+
* Get all protection configurations
|
|
139
|
+
*/
|
|
140
|
+
get protections(): import("./view-data").ViewProtection[];
|
|
141
|
+
/**
|
|
142
|
+
* Get protection config for a specific token instance
|
|
143
|
+
*
|
|
144
|
+
* @param tokenInstance - Token instance to get protection for
|
|
145
|
+
* @returns Protection config or null if no matching protection
|
|
146
|
+
*/
|
|
147
|
+
getProtectionFor(tokenInstance: TokenInstanceAny): {
|
|
148
|
+
read: any;
|
|
149
|
+
write: any;
|
|
150
|
+
} | null;
|
|
151
|
+
/**
|
|
152
|
+
* Generate database store schema for this view
|
|
153
|
+
* Returns the view table with _id as primary key
|
|
154
|
+
*/
|
|
155
|
+
databaseStoreSchema(): DatabaseStoreSchema;
|
|
156
|
+
/**
|
|
157
|
+
* Create reinitTable function for event replay
|
|
158
|
+
* This rebuilds the view by replaying all events through handlers
|
|
159
|
+
*/
|
|
160
|
+
private createReinitTable;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Create a new view with the given name, ID schema, and data schema
|
|
164
|
+
*
|
|
165
|
+
* @param name - Unique view name (plural noun, e.g., "tasks")
|
|
166
|
+
* @param id - ID schema for view records
|
|
167
|
+
* @param schema - Data schema for view records
|
|
168
|
+
* @returns New view instance ready for configuration
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```typescript
|
|
172
|
+
* const tasks = view("tasks", taskId, {
|
|
173
|
+
* title: string(),
|
|
174
|
+
* isCompleted: boolean(),
|
|
175
|
+
* });
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
export declare function view<const Name extends string, Id, Schema extends ArcObjectAny>(name: Name, id: Id, schema: Schema): ArcView<{
|
|
179
|
+
name: Name;
|
|
180
|
+
id: Id;
|
|
181
|
+
schema: Schema;
|
|
182
|
+
elements: [];
|
|
183
|
+
handler: {};
|
|
184
|
+
protections: [];
|
|
185
|
+
}>;
|
|
186
|
+
/**
|
|
187
|
+
* Type alias for any view (used in collections)
|
|
188
|
+
*/
|
|
189
|
+
export type ArcViewAny = ArcView<any>;
|
|
190
|
+
/**
|
|
191
|
+
* Helper type to extract view record type
|
|
192
|
+
*/
|
|
193
|
+
export type ArcViewRecord<View extends ArcViewAny> = View extends ArcView<infer Data> ? ArcViewItem<Data["id"], Data["schema"]> : never;
|
|
194
|
+
//# sourceMappingURL=view.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ReadTransaction, ReadWriteTransaction } from "../db";
|
|
2
1
|
import { DataStorage } from "./data-storage.abstract";
|
|
2
|
+
import type { ReadTransaction, ReadWriteTransaction } from "./database-adapter";
|
|
3
3
|
import { StoreState } from "./store-state.abstract";
|
|
4
4
|
export declare class ForkedDataStorage extends DataStorage {
|
|
5
5
|
private master;
|
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
import type { ArcContextAny } from "../context";
|
|
2
|
-
import type { DatabaseAdapter, ReadTransaction, ReadWriteTransaction } from "../db";
|
|
3
|
-
import type { RealTimeCommunicationAdapterFactory } from "../rtc/rtc";
|
|
4
1
|
import { ForkedDataStorage } from "./data-storage-forked";
|
|
5
2
|
import { DataStorage, type DataStorageChanges } from "./data-storage.abstract";
|
|
3
|
+
import type { DatabaseAdapter, ReadTransaction, ReadWriteTransaction } from "./database-adapter";
|
|
6
4
|
import type { StoreState } from "./store-state.abstract";
|
|
7
5
|
export declare class MasterDataStorage extends DataStorage {
|
|
8
6
|
private dbAdapter;
|
|
9
|
-
private arcContext;
|
|
10
7
|
private stores;
|
|
11
|
-
private rtcAdapter;
|
|
12
8
|
private reinitTablesExecuted;
|
|
13
|
-
constructor(dbAdapter: Promise<DatabaseAdapter> | DatabaseAdapter
|
|
9
|
+
constructor(dbAdapter: Promise<DatabaseAdapter> | DatabaseAdapter);
|
|
14
10
|
private executeReinitTablesOnReady;
|
|
15
11
|
getReadTransaction(): Promise<ReadTransaction>;
|
|
16
12
|
getReadWriteTransaction(): Promise<ReadWriteTransaction>;
|
|
@@ -28,9 +24,10 @@ export declare class MasterDataStorage extends DataStorage {
|
|
|
28
24
|
}[][]>;
|
|
29
25
|
commitChanges(changes: DataStorageChanges[]): Promise<void>;
|
|
30
26
|
fork(): ForkedDataStorage;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Destroy the data storage - clears all stores and destroys the database
|
|
29
|
+
* Used for logout/reset scenarios
|
|
30
|
+
*/
|
|
31
|
+
destroy(): Promise<void>;
|
|
35
32
|
}
|
|
36
33
|
//# sourceMappingURL=data-storage-master.d.ts.map
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { ForkedDataStorage } from "./data-storage-forked";
|
|
2
|
+
import type { DataStorage, DataStorageChanges, ListenerEvent, QueryListenerCallback } from "./data-storage.abstract";
|
|
3
|
+
import type { ReadTransaction, ReadWriteTransaction } from "./database-adapter";
|
|
4
|
+
import type { FindOptions } from "./find-options";
|
|
5
|
+
import type { StoreState } from "./store-state.abstract";
|
|
6
|
+
/**
|
|
7
|
+
* Observable DataStorage - wraps a DataStorage to track queries and notify on changes
|
|
8
|
+
*
|
|
9
|
+
* Used by liveQuery to:
|
|
10
|
+
* 1. Track which queries are made through view.queryContext
|
|
11
|
+
* 2. Cache results for change resolution
|
|
12
|
+
* 3. Notify when any tracked query's results change
|
|
13
|
+
*
|
|
14
|
+
* Implements DataStorage interface (duck typing)
|
|
15
|
+
*/
|
|
16
|
+
export declare class ObservableDataStorage {
|
|
17
|
+
private source;
|
|
18
|
+
private onChange;
|
|
19
|
+
private trackedQueries;
|
|
20
|
+
private stores;
|
|
21
|
+
constructor(source: DataStorage, onChange: () => void);
|
|
22
|
+
getStore<Item extends {
|
|
23
|
+
_id: string;
|
|
24
|
+
}>(storeName: string): StoreState<Item>;
|
|
25
|
+
fork(): ForkedDataStorage;
|
|
26
|
+
getReadTransaction(): Promise<ReadTransaction>;
|
|
27
|
+
getReadWriteTransaction(): Promise<ReadWriteTransaction>;
|
|
28
|
+
commitChanges(changes: DataStorageChanges[]): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Register a tracked query
|
|
31
|
+
*/
|
|
32
|
+
trackQuery<Item extends {
|
|
33
|
+
_id: string;
|
|
34
|
+
}>(storeName: string, options: FindOptions<Item>, result: Item[], listener: QueryListenerCallback<Item>): void;
|
|
35
|
+
/**
|
|
36
|
+
* Handle change events from a store
|
|
37
|
+
* Synchronously resolves changes and notifies if any query results changed
|
|
38
|
+
*/
|
|
39
|
+
handleStoreChange<Item extends {
|
|
40
|
+
_id: string;
|
|
41
|
+
}>(storeName: string, events: ListenerEvent<Item>[]): void;
|
|
42
|
+
/**
|
|
43
|
+
* Get the current cached result for a query
|
|
44
|
+
*/
|
|
45
|
+
getCachedResult(storeName: string, options: FindOptions<any>): any[] | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Clear all tracked queries and unsubscribe listeners
|
|
48
|
+
*/
|
|
49
|
+
clear(): void;
|
|
50
|
+
private getQueryKey;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Create an observable wrapper around a DataStorage that tracks queries and notifies on changes
|
|
54
|
+
* Used by liveQuery for reactivity
|
|
55
|
+
*
|
|
56
|
+
* @param dataStorage - The source DataStorage to wrap
|
|
57
|
+
* @param onChange - Called when any tracked query's results change
|
|
58
|
+
* @returns ObservableDataStorage with clear() method to unsubscribe
|
|
59
|
+
*/
|
|
60
|
+
export declare function observeQueries(dataStorage: DataStorage, onChange: () => void): ObservableDataStorage;
|
|
61
|
+
//# sourceMappingURL=data-storage-observable.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Patch } from "mutative";
|
|
2
|
-
import type { ReadTransaction, ReadWriteTransaction } from "../db";
|
|
3
2
|
import type { ForkedDataStorage } from "./data-storage-forked";
|
|
3
|
+
import type { ReadTransaction, ReadWriteTransaction } from "./database-adapter";
|
|
4
4
|
import type { StoreState } from "./store-state.abstract";
|
|
5
5
|
export declare abstract class DataStorage {
|
|
6
6
|
abstract getStore<Item extends {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ArcContextAny } from "../
|
|
2
|
-
import type { FindOptions } from "
|
|
1
|
+
import type { ArcContextAny } from "../";
|
|
2
|
+
import type { FindOptions } from "./find-options";
|
|
3
3
|
export interface ReadTransaction {
|
|
4
4
|
find(store: string, options: FindOptions<any>): Promise<any[]>;
|
|
5
5
|
}
|
|
@@ -12,6 +12,11 @@ export interface DatabaseAdapter {
|
|
|
12
12
|
readWriteTransaction(stores?: string[]): ReadWriteTransaction;
|
|
13
13
|
readTransaction(stores?: string[]): ReadTransaction;
|
|
14
14
|
executeReinitTables(dataStorage: any): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Destroy the database - drop all tables and clean up resources
|
|
17
|
+
* Used for logout/reset scenarios
|
|
18
|
+
*/
|
|
19
|
+
destroy?(): Promise<void>;
|
|
15
20
|
}
|
|
16
21
|
export type DBAdapterFactory = (context: ArcContextAny) => Promise<DatabaseAdapter>;
|
|
17
|
-
//# sourceMappingURL=
|
|
22
|
+
//# sourceMappingURL=database-adapter.d.ts.map
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Database-agnostic store data types and interfaces
|
|
3
3
|
*/
|
|
4
|
+
import type { ArcObjectAny } from "../elements";
|
|
5
|
+
import type { DataStorage } from "./data-storage.abstract";
|
|
4
6
|
export type DatabaseType = "sqlite" | "postgresql" | "mysql";
|
|
5
7
|
export interface DatabaseStoreData {
|
|
6
8
|
/** Mark this field as primary key */
|
|
@@ -55,4 +57,47 @@ export interface DatabaseAgnosticColumnInfo {
|
|
|
55
57
|
[key: string]: any;
|
|
56
58
|
};
|
|
57
59
|
}
|
|
60
|
+
export type StoreColumn = {
|
|
61
|
+
name: string;
|
|
62
|
+
type: string;
|
|
63
|
+
isOptional?: boolean;
|
|
64
|
+
default?: any;
|
|
65
|
+
computed?: string | ((item: any, context: {
|
|
66
|
+
now: string;
|
|
67
|
+
}) => any);
|
|
68
|
+
};
|
|
69
|
+
export type StoreRelation = {
|
|
70
|
+
table: string;
|
|
71
|
+
type: "one-to-many" | "many-to-many" | "one-to-one";
|
|
72
|
+
foreignKey: string;
|
|
73
|
+
throughTable?: string;
|
|
74
|
+
};
|
|
75
|
+
export type StoreTable = {
|
|
76
|
+
name: string;
|
|
77
|
+
columns: StoreColumn[];
|
|
78
|
+
primaryKey: string;
|
|
79
|
+
};
|
|
80
|
+
export type StoreSchema = {
|
|
81
|
+
tables: StoreTable[];
|
|
82
|
+
relations?: StoreRelation[];
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* New database-agnostic schema definition
|
|
86
|
+
*/
|
|
87
|
+
export type DatabaseStoreTable = {
|
|
88
|
+
name: string;
|
|
89
|
+
schema: ArcObjectAny;
|
|
90
|
+
version?: number;
|
|
91
|
+
options?: {
|
|
92
|
+
/** Include soft delete columns */
|
|
93
|
+
softDelete?: boolean;
|
|
94
|
+
/** Include per-table version tracking for data syncing */
|
|
95
|
+
versioning?: boolean;
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
export type DatabaseStoreSchema = {
|
|
99
|
+
tables: DatabaseStoreTable[];
|
|
100
|
+
relations?: StoreRelation[];
|
|
101
|
+
reinitTable?: (tableName: string, dataStorage: DataStorage) => Promise<void>;
|
|
102
|
+
};
|
|
58
103
|
//# sourceMappingURL=database-store.d.ts.map
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
export * from "./data-storage-forked";
|
|
2
2
|
export * from "./data-storage-master";
|
|
3
|
+
export * from "./data-storage-observable";
|
|
3
4
|
export * from "./data-storage.abstract";
|
|
4
|
-
export * from "./
|
|
5
|
+
export * from "./database-adapter";
|
|
6
|
+
export * from "./database-store";
|
|
7
|
+
export * from "./find-options";
|
|
8
|
+
export * from "./query-result-resolver";
|
|
9
|
+
export * from "./schema-extraction";
|
|
5
10
|
export * from "./store-state-fork";
|
|
6
11
|
export * from "./store-state-master";
|
|
7
12
|
export * from "./store-state.abstract";
|
|
8
|
-
export type * from "./types";
|
|
9
13
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
1
|
+
import type { ArcContextAny } from "../context";
|
|
2
|
+
import type { DatabaseAdapter, DBAdapterFactory, ReadTransaction, ReadWriteTransaction } from "./database-adapter";
|
|
3
|
+
import type { StoreColumn, StoreTable } from "./database-store";
|
|
4
|
+
import type { FindOptions, WhereCondition } from "./find-options";
|
|
5
5
|
export interface PostgreSQLDatabase {
|
|
6
6
|
exec(sql: string, params?: any[]): Promise<any>;
|
|
7
7
|
execBatch(queries: Array<{
|
|
@@ -17,7 +17,6 @@ declare class PostgreSQLReadTransaction implements ReadTransaction {
|
|
|
17
17
|
protected hasSoftDelete(tableName: string): boolean;
|
|
18
18
|
protected deserializeValue(value: any, column: StoreColumn): any;
|
|
19
19
|
protected deserializeRow(row: any, table: StoreTable): any;
|
|
20
|
-
protected getId(store: string, id: any): any;
|
|
21
20
|
protected buildWhereClause(where?: WhereCondition, tableName?: string): {
|
|
22
21
|
sql: string;
|
|
23
22
|
params: any[];
|
|
@@ -41,7 +40,6 @@ export declare class PostgreSQLAdapter implements DatabaseAdapter {
|
|
|
41
40
|
private db;
|
|
42
41
|
private context;
|
|
43
42
|
private tables;
|
|
44
|
-
private tableSchemas;
|
|
45
43
|
private pendingReinitTables;
|
|
46
44
|
private mapType;
|
|
47
45
|
private buildConstraints;
|
|
@@ -50,41 +48,17 @@ export declare class PostgreSQLAdapter implements DatabaseAdapter {
|
|
|
50
48
|
constructor(db: PostgreSQLDatabase, context: ArcContextAny);
|
|
51
49
|
initialize(): Promise<void>;
|
|
52
50
|
private createTableIfNotExistsNew;
|
|
53
|
-
/**
|
|
54
|
-
* Create the version counter table for tracking per-table version sequences
|
|
55
|
-
*/
|
|
56
51
|
private createVersionCounterTable;
|
|
57
|
-
/**
|
|
58
|
-
* Create the table versions tracking table for schema versioning
|
|
59
|
-
*/
|
|
60
52
|
private createTableVersionsTable;
|
|
61
|
-
/**
|
|
62
|
-
* Generate physical table name with version suffix
|
|
63
|
-
*/
|
|
64
53
|
private getPhysicalTableName;
|
|
65
|
-
/**
|
|
66
|
-
* Check if a versioned table exists
|
|
67
|
-
*/
|
|
68
54
|
private checkVersionedTableExists;
|
|
69
|
-
/**
|
|
70
|
-
* Register a new table version
|
|
71
|
-
*/
|
|
72
55
|
private registerTableVersion;
|
|
73
|
-
/**
|
|
74
|
-
* Check if a table has versioning enabled
|
|
75
|
-
*/
|
|
76
56
|
hasVersioning(tableName: string): boolean;
|
|
77
|
-
/**
|
|
78
|
-
* Check if a table has soft delete enabled
|
|
79
|
-
*/
|
|
80
57
|
hasSoftDelete(tableName: string): boolean;
|
|
81
|
-
/**
|
|
82
|
-
* Execute all pending reinitTable functions
|
|
83
|
-
*/
|
|
84
58
|
executeReinitTables(dataStorage: any): Promise<void>;
|
|
85
|
-
readWriteTransaction(
|
|
86
|
-
readTransaction(
|
|
59
|
+
readWriteTransaction(_stores?: string[]): PostgreSQLReadWriteTransaction;
|
|
60
|
+
readTransaction(_stores?: string[]): PostgreSQLReadTransaction;
|
|
87
61
|
}
|
|
88
62
|
export declare const createPostgreSQLAdapterFactory: (db: PostgreSQLDatabase) => DBAdapterFactory;
|
|
89
63
|
export {};
|
|
90
|
-
//# sourceMappingURL=
|
|
64
|
+
//# sourceMappingURL=postgresql-adapter.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ListenerEvent } from "./data-storage.abstract";
|
|
2
|
+
import type { FindOptions } from "./find-options";
|
|
3
|
+
/**
|
|
4
|
+
* Resolves a change event against a cached query result
|
|
5
|
+
* Returns the new result array or false if unchanged
|
|
6
|
+
*/
|
|
7
|
+
export declare function resolveQueryChange<Item extends {
|
|
8
|
+
_id: string;
|
|
9
|
+
}>(currentResult: Item[], event: ListenerEvent<Item>, options: FindOptions<Item>): Item[] | false;
|
|
10
|
+
/**
|
|
11
|
+
* Check if an item matches the where clause
|
|
12
|
+
*/
|
|
13
|
+
export declare function checkItemMatchesWhere<Item>(item: Item, where?: Record<string, any>): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Apply orderBy and limit to a result array
|
|
16
|
+
*/
|
|
17
|
+
export declare function applyOrderByAndLimit<Item>(result: Item[], options: FindOptions<Item>): Item[];
|
|
18
|
+
//# sourceMappingURL=query-result-resolver.d.ts.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
1
|
+
import type { ArcContextAny } from "../context";
|
|
2
|
+
import type { DatabaseAdapter, DBAdapterFactory, ReadTransaction, ReadWriteTransaction } from "./database-adapter";
|
|
3
|
+
import type { StoreColumn, StoreTable } from "./database-store";
|
|
4
|
+
import type { FindOptions, WhereCondition } from "./find-options";
|
|
5
5
|
export interface SQLiteDatabase {
|
|
6
6
|
exec(sql: string, params?: any[]): Promise<any>;
|
|
7
7
|
}
|
|
@@ -13,7 +13,6 @@ declare class SQLiteReadTransaction implements ReadTransaction {
|
|
|
13
13
|
protected hasSoftDelete(tableName: string): boolean;
|
|
14
14
|
protected deserializeValue(value: any, column: StoreColumn): any;
|
|
15
15
|
protected deserializeRow(row: any, table: StoreTable): any;
|
|
16
|
-
protected getId(store: string, id: any): any;
|
|
17
16
|
protected buildWhereClause(where?: WhereCondition, tableName?: string): {
|
|
18
17
|
sql: string;
|
|
19
18
|
params: any[];
|
|
@@ -36,7 +35,6 @@ export declare class SQLiteAdapter implements DatabaseAdapter {
|
|
|
36
35
|
private db;
|
|
37
36
|
private context;
|
|
38
37
|
private tables;
|
|
39
|
-
private tableSchemas;
|
|
40
38
|
private pendingReinitTables;
|
|
41
39
|
private mapType;
|
|
42
40
|
private buildConstraints;
|
|
@@ -45,41 +43,17 @@ export declare class SQLiteAdapter implements DatabaseAdapter {
|
|
|
45
43
|
constructor(db: SQLiteDatabase, context: ArcContextAny);
|
|
46
44
|
initialize(): Promise<void>;
|
|
47
45
|
private createTableIfNotExistsNew;
|
|
48
|
-
/**
|
|
49
|
-
* Create the version counter table for tracking per-table version sequences
|
|
50
|
-
*/
|
|
51
46
|
private createVersionCounterTable;
|
|
52
|
-
/**
|
|
53
|
-
* Create the table versions tracking table for schema versioning
|
|
54
|
-
*/
|
|
55
47
|
private createTableVersionsTable;
|
|
56
|
-
/**
|
|
57
|
-
* Generate physical table name with version suffix
|
|
58
|
-
*/
|
|
59
48
|
private getPhysicalTableName;
|
|
60
|
-
/**
|
|
61
|
-
* Check if a versioned table exists
|
|
62
|
-
*/
|
|
63
49
|
private checkVersionedTableExists;
|
|
64
|
-
/**
|
|
65
|
-
* Register a new table version
|
|
66
|
-
*/
|
|
67
50
|
private registerTableVersion;
|
|
68
|
-
/**
|
|
69
|
-
* Check if a table has versioning enabled
|
|
70
|
-
*/
|
|
71
51
|
hasVersioning(tableName: string): boolean;
|
|
72
|
-
/**
|
|
73
|
-
* Check if a table has soft delete enabled
|
|
74
|
-
*/
|
|
75
52
|
hasSoftDelete(tableName: string): boolean;
|
|
76
|
-
/**
|
|
77
|
-
* Execute all pending reinitTable functions
|
|
78
|
-
*/
|
|
79
53
|
executeReinitTables(dataStorage: any): Promise<void>;
|
|
80
54
|
readWriteTransaction(stores?: string[]): SQLiteReadWriteTransaction;
|
|
81
55
|
readTransaction(stores?: string[]): SQLiteReadTransaction;
|
|
82
56
|
}
|
|
83
57
|
export declare const createSQLiteAdapterFactory: (db: SQLiteDatabase) => DBAdapterFactory;
|
|
84
58
|
export {};
|
|
85
|
-
//# sourceMappingURL=
|
|
59
|
+
//# sourceMappingURL=sqlite-adapter.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { DataStorage, ListenerEvent, QueryListenerCallback, StoreStateChange } from "./data-storage.abstract";
|
|
2
2
|
import { StoreState } from "./store-state.abstract";
|
|
3
|
-
import type { FindOptions } from "./
|
|
3
|
+
import type { FindOptions } from "./find-options";
|
|
4
4
|
export declare class ForkedStoreState<Item extends {
|
|
5
5
|
_id: string;
|
|
6
6
|
}> extends StoreState<Item> {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { ReadWriteTransaction } from "../db";
|
|
2
1
|
import type { DataStorage, ListenerEvent, QueryListenerCallback, StoreStateChange } from "./data-storage.abstract";
|
|
2
|
+
import type { ReadWriteTransaction } from "./database-adapter";
|
|
3
|
+
import type { FindOptions } from "./find-options";
|
|
3
4
|
import { StoreState } from "./store-state.abstract";
|
|
4
|
-
import type { FindOptions } from "./types";
|
|
5
5
|
export declare class MasterStoreState<Item extends {
|
|
6
6
|
_id: string;
|
|
7
7
|
}> extends StoreState<Item> {
|
|
@@ -17,5 +17,9 @@ export declare class MasterStoreState<Item extends {
|
|
|
17
17
|
}>;
|
|
18
18
|
applyChanges(changes: StoreStateChange<Item>[]): Promise<void>;
|
|
19
19
|
find(options: FindOptions<Item>, listener?: QueryListenerCallback<Item>): Promise<Item[]>;
|
|
20
|
+
/**
|
|
21
|
+
* Public method to notify listeners (used by MasterDataStorage.commitChanges)
|
|
22
|
+
*/
|
|
23
|
+
notifyListenersPublic(events: ListenerEvent<Item>[]): void;
|
|
20
24
|
}
|
|
21
25
|
//# sourceMappingURL=store-state-master.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { DataStorage, ListenerEvent, QueryListener, QueryListenerCallback, StoreStateChange } from "./data-storage.abstract";
|
|
2
2
|
import { ForkedStoreState } from "./store-state-fork";
|
|
3
|
-
import type { FindOptions } from "./
|
|
3
|
+
import type { FindOptions } from "./find-options";
|
|
4
4
|
export declare abstract class StoreState<Item extends {
|
|
5
5
|
_id: string;
|
|
6
6
|
}> {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DatabaseAgnosticColumnInfo, DatabaseStoreData } from "../
|
|
1
|
+
import type { DatabaseAgnosticColumnInfo, DatabaseStoreData } from "../data-storage/database-store";
|
|
2
2
|
import { ArcBranded } from "./branded";
|
|
3
3
|
import { ArcDefault } from "./default";
|
|
4
4
|
import type { ArcElement } from "./element";
|
package/dist/elements/any.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ArcAbstract, type Validators } from "./abstract";
|
|
2
|
-
import type { DatabaseAgnosticColumnInfo } from "../
|
|
2
|
+
import type { DatabaseAgnosticColumnInfo } from "../data-storage/database-store";
|
|
3
3
|
export declare class ArcAny<T, V extends Validators = []> extends ArcAbstract<V> {
|
|
4
4
|
constructor();
|
|
5
5
|
parse(value: T): any;
|
package/dist/elements/array.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { FirstArgument } from "../utils/types/first-argument";
|
|
2
2
|
import { ArcAbstract, type CheckFn, type GetValidator, type Validators } from "./abstract";
|
|
3
3
|
import type { ArcElement } from "./element";
|
|
4
|
-
import type { DatabaseAgnosticColumnInfo } from "../
|
|
4
|
+
import type { DatabaseAgnosticColumnInfo } from "../data-storage/database-store";
|
|
5
5
|
declare const arrayValidator: {
|
|
6
6
|
name: "type";
|
|
7
7
|
validator: (value: any) => false | {
|
|
@@ -47,9 +47,9 @@ export declare class ArcArray<E extends ArcElement, V extends Validators = [
|
|
|
47
47
|
readonly msg: "array is empty";
|
|
48
48
|
} | undefined;
|
|
49
49
|
}]>;
|
|
50
|
-
parse(value:
|
|
51
|
-
serialize(value:
|
|
52
|
-
deserialize(value:
|
|
50
|
+
parse(value: FirstArgument<E["deserialize"]>[]): ReturnType<E["parse"]>[];
|
|
51
|
+
serialize(value: FirstArgument<E["serialize"]>[]): ReturnType<E["serialize"]>[];
|
|
52
|
+
deserialize(value: FirstArgument<E["deserialize"]>[]): ReturnType<E["deserialize"]>[];
|
|
53
53
|
deserializePath(path: string[], value: any): any;
|
|
54
54
|
validation<Name extends string, Fn extends CheckFn<any>>(name: Name, validator: Fn): ArcArray<E, GetValidator<ArcAbstract<[...V, {
|
|
55
55
|
name: Name;
|
package/dist/elements/blob.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { CheckFn, GetValidator, Validators } from "./abstract";
|
|
2
2
|
import { ArcPrimitive } from "./abstract-primitive";
|
|
3
|
-
import type { DatabaseAgnosticColumnInfo } from "../
|
|
3
|
+
import type { DatabaseAgnosticColumnInfo } from "../data-storage/database-store";
|
|
4
4
|
declare const blobValidator: {
|
|
5
5
|
readonly name: "blob";
|
|
6
6
|
readonly validator: (value: any) => {
|