@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,198 @@
|
|
|
1
|
+
import type { ArcObjectAny, ArcRawShape } from "../../elements/object";
|
|
2
|
+
import { ArcObject } from "../../elements/object";
|
|
3
|
+
import type { ModelAdapters } from "../../model/model-adapters";
|
|
4
|
+
import type { ArcTokenAny } from "../../token/token";
|
|
5
|
+
import type { TokenInstanceAny } from "../../token/token-instance";
|
|
6
|
+
import type { Merge } from "../../utils";
|
|
7
|
+
import type { $type } from "../../utils/types/get-type";
|
|
8
|
+
import { ArcContextElement } from "../context-element";
|
|
9
|
+
import type { ArcCommandContextFromData } from "./command-context";
|
|
10
|
+
import type { ArcCommandData, CommandProtection, CommandProtectionCheck } from "./command-data";
|
|
11
|
+
import type { ArcCommandHandler } from "./command-handler";
|
|
12
|
+
/**
|
|
13
|
+
* Arc Command - Business action that modifies state
|
|
14
|
+
*
|
|
15
|
+
* Commands are the primary way to execute business logic in Arc Framework.
|
|
16
|
+
* They can:
|
|
17
|
+
* - Accept typed parameters
|
|
18
|
+
* - Return typed results
|
|
19
|
+
* - Query state through query elements (views)
|
|
20
|
+
* - Mutate state through mutation elements (events, other commands)
|
|
21
|
+
*
|
|
22
|
+
* Commands follow the factory pattern from the Arc guide:
|
|
23
|
+
* - All configuration in a single Data object
|
|
24
|
+
* - Type-safe throughout
|
|
25
|
+
* - Immutable with clone-on-modify
|
|
26
|
+
* - Separate query and mutation concerns
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* const registerCmd = command("register")
|
|
31
|
+
* .public()
|
|
32
|
+
* .query([usersView])
|
|
33
|
+
* .mutate([userRegisteredEvent])
|
|
34
|
+
* .withParams({ email: string(), password: string() })
|
|
35
|
+
* .withResult({ success: boolean() })
|
|
36
|
+
* .handle(async (ctx, params) => {
|
|
37
|
+
* // Business logic here
|
|
38
|
+
* return { success: true };
|
|
39
|
+
* });
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare class ArcCommand<const Data extends ArcCommandData> extends ArcContextElement<Data["name"]> {
|
|
43
|
+
private readonly data;
|
|
44
|
+
constructor(data: Data);
|
|
45
|
+
/**
|
|
46
|
+
* Set command description for documentation and tooling
|
|
47
|
+
*/
|
|
48
|
+
description<const Desc extends string>(description: Desc): ArcCommand<Merge<Data, {
|
|
49
|
+
description: Desc;
|
|
50
|
+
}>>;
|
|
51
|
+
/**
|
|
52
|
+
* Check if command is public (no protections = public)
|
|
53
|
+
* Commands without protectBy() are considered public
|
|
54
|
+
*/
|
|
55
|
+
get isPublic(): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Add query elements (views) that this command needs to read from
|
|
58
|
+
* Query elements provide read-only access to state
|
|
59
|
+
*
|
|
60
|
+
* @param elements - Array of view elements to query
|
|
61
|
+
*/
|
|
62
|
+
query<const Elements extends ArcContextElement<any>[]>(elements: Elements): ArcCommand<Merge<Data, {
|
|
63
|
+
queryElements: Elements;
|
|
64
|
+
}>>;
|
|
65
|
+
/**
|
|
66
|
+
* Add mutation elements (events, commands) that this command needs to modify state
|
|
67
|
+
* Mutation elements provide write access to state
|
|
68
|
+
*
|
|
69
|
+
* @param elements - Array of event/command elements to mutate with
|
|
70
|
+
*/
|
|
71
|
+
mutate<const Elements extends ArcContextElement<any>[]>(elements: Elements): ArcCommand<Merge<Data, {
|
|
72
|
+
mutationElements: Elements;
|
|
73
|
+
}>>;
|
|
74
|
+
/**
|
|
75
|
+
* Define command parameters schema
|
|
76
|
+
*
|
|
77
|
+
* @param schema - Object schema or raw shape defining parameter structure
|
|
78
|
+
*/
|
|
79
|
+
withParams<NewParams extends ArcRawShape>(schema: NewParams | ArcObject<NewParams>): ArcCommand<Merge<Data, {
|
|
80
|
+
params: ArcObject<NewParams>;
|
|
81
|
+
}>>;
|
|
82
|
+
/**
|
|
83
|
+
* Define command result schemas
|
|
84
|
+
* Commands can return multiple result types (success, error variants)
|
|
85
|
+
*
|
|
86
|
+
* @param schemas - Array of object schemas for possible results
|
|
87
|
+
*/
|
|
88
|
+
withResult<NewResults extends ArcRawShape[]>(...schemas: NewResults): ArcCommand<Merge<Data, {
|
|
89
|
+
results: { [K in keyof NewResults]: ArcObject<NewResults[K]>; };
|
|
90
|
+
}>>;
|
|
91
|
+
/**
|
|
92
|
+
* Set command handler function
|
|
93
|
+
* The handler contains the business logic for this command
|
|
94
|
+
*
|
|
95
|
+
* @param handler - Function that executes command logic, or false to disable
|
|
96
|
+
*/
|
|
97
|
+
handle<Handler extends ArcCommandHandler<ArcCommandContextFromData<Data>, Data["params"] extends ArcObjectAny ? $type<Data["params"]> : null, $type<Data["results"][number]>> | false>(handler: Handler): ArcCommand<Merge<Data, {
|
|
98
|
+
handler: Handler;
|
|
99
|
+
}>>;
|
|
100
|
+
/**
|
|
101
|
+
* Add token-based protection to this command
|
|
102
|
+
* Multiple protections can be added (all must pass)
|
|
103
|
+
*
|
|
104
|
+
* @param token - Token definition to protect with
|
|
105
|
+
* @param check - Function to check if access is allowed
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```typescript
|
|
109
|
+
* command("editForm")
|
|
110
|
+
* .protectBy(moderatorToken, (token) => token.canI('form:edit'))
|
|
111
|
+
* .handle(async (ctx, params) => { ... });
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
protectBy<T extends ArcTokenAny>(token: T, check: CommandProtectionCheck<T>): ArcCommand<Merge<Data, {
|
|
115
|
+
protections: [...Data["protections"] extends infer P extends CommandProtection[] ? P : [], {
|
|
116
|
+
token: T;
|
|
117
|
+
check: typeof check;
|
|
118
|
+
}];
|
|
119
|
+
}>>;
|
|
120
|
+
/**
|
|
121
|
+
* Check if command has protections
|
|
122
|
+
*/
|
|
123
|
+
get hasProtections(): boolean;
|
|
124
|
+
/**
|
|
125
|
+
* Get all protection configurations
|
|
126
|
+
*/
|
|
127
|
+
get protections(): CommandProtection[];
|
|
128
|
+
/**
|
|
129
|
+
* Verify all protections pass for given token instances
|
|
130
|
+
*
|
|
131
|
+
* @param tokens - Array of token instances to verify
|
|
132
|
+
* @returns true if all protections pass
|
|
133
|
+
*/
|
|
134
|
+
verifyProtections(tokens: TokenInstanceAny[]): Promise<boolean>;
|
|
135
|
+
/**
|
|
136
|
+
* Initialize command in the given environment
|
|
137
|
+
* On server: registers command handler for remote execution
|
|
138
|
+
*/
|
|
139
|
+
init(environment: import("../context-element").ArcEnvironment, adapters: ModelAdapters): Promise<void>;
|
|
140
|
+
/**
|
|
141
|
+
* Generate mutation context for this command
|
|
142
|
+
* Provides execute functionality to run the command
|
|
143
|
+
*
|
|
144
|
+
* @param adapters - Available adapters (storage, commandWire, eventPublisher)
|
|
145
|
+
* @returns Context object with execute method
|
|
146
|
+
*/
|
|
147
|
+
mutateContext(adapters: ModelAdapters): ((params: Data["params"] extends ArcObjectAny ? $type<Data["params"]> : null) => Promise<$type<Data["results"][number]>>) & {
|
|
148
|
+
params: Data["params"];
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* Execute command locally with handler
|
|
152
|
+
* Collects events and publishes them via eventPublisher
|
|
153
|
+
*/
|
|
154
|
+
private executeLocally;
|
|
155
|
+
/**
|
|
156
|
+
* Build command context with access to query and mutation elements
|
|
157
|
+
*/
|
|
158
|
+
private buildCommandContext;
|
|
159
|
+
/**
|
|
160
|
+
* Convert command to JSON Schema format
|
|
161
|
+
* Used for OpenAPI documentation and validation
|
|
162
|
+
*/
|
|
163
|
+
toJsonSchema(): {
|
|
164
|
+
type: string;
|
|
165
|
+
name: string;
|
|
166
|
+
description: string | undefined;
|
|
167
|
+
parameters: any;
|
|
168
|
+
strict: boolean;
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Create a new command with the given name
|
|
173
|
+
*
|
|
174
|
+
* @param name - Unique command name
|
|
175
|
+
* @returns New command instance ready for configuration
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```typescript
|
|
179
|
+
* const myCommand = command("myCommand")
|
|
180
|
+
* .withParams({ input: string() })
|
|
181
|
+
* .handle(async (ctx, params) => {
|
|
182
|
+
* // logic here
|
|
183
|
+
* });
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
186
|
+
export declare function command<const Name extends string>(name: Name): ArcCommand<{
|
|
187
|
+
readonly name: Name;
|
|
188
|
+
readonly params: null;
|
|
189
|
+
readonly results: [];
|
|
190
|
+
readonly queryElements: [];
|
|
191
|
+
readonly mutationElements: [];
|
|
192
|
+
readonly protections: [];
|
|
193
|
+
}>;
|
|
194
|
+
/**
|
|
195
|
+
* Type alias for any command (used in collections)
|
|
196
|
+
*/
|
|
197
|
+
export type ArcCommandAny = ArcCommand<any>;
|
|
198
|
+
//# sourceMappingURL=command.d.ts.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { ArcCommand, command, type ArcCommandAny } from "./command";
|
|
2
|
+
export type { ArcCommandContext, ArcCommandContextFromData, AuthContext, } from "./command-context";
|
|
3
|
+
export type { ArcCommandData, CommandProtection, CommandProtectionCheck, } from "./command-data";
|
|
4
|
+
export type { ArcCommandHandler } from "./command-handler";
|
|
5
|
+
export type { ArcObjectAny, ArcRawShape } from "../../elements/object";
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context Element - Core building block of Arc Framework
|
|
3
|
+
*
|
|
4
|
+
* Every element in Arc (command, event, view, listener) extends this base class.
|
|
5
|
+
* Elements provide type-safe access to their functionality through the context system.
|
|
6
|
+
*/
|
|
7
|
+
import type { ModelAdapters } from "../model/model-adapters";
|
|
8
|
+
export type ArcEnvironment = "client" | "server" | "universal";
|
|
9
|
+
/**
|
|
10
|
+
* Base class for all Arc context elements
|
|
11
|
+
*
|
|
12
|
+
* Elements are the building blocks of Arc Framework:
|
|
13
|
+
* - Commands: Business actions that modify state
|
|
14
|
+
* - Events: Records of what happened
|
|
15
|
+
* - Views: Read models derived from events
|
|
16
|
+
* - Listeners: Side effects triggered by events
|
|
17
|
+
*
|
|
18
|
+
* Each element declares:
|
|
19
|
+
* 1. Its name (for identification)
|
|
20
|
+
* 2. Its context generation logic
|
|
21
|
+
* 3. Its handler/logic
|
|
22
|
+
*/
|
|
23
|
+
export declare abstract class ArcContextElement<const Name extends string> {
|
|
24
|
+
/**
|
|
25
|
+
* Element name - used for identification and error messages
|
|
26
|
+
* Must be unique within a context
|
|
27
|
+
*/
|
|
28
|
+
readonly name: Name;
|
|
29
|
+
constructor(name: Name);
|
|
30
|
+
/**
|
|
31
|
+
* Initialize element in the given environment
|
|
32
|
+
* Called by Model when context is created
|
|
33
|
+
*
|
|
34
|
+
* Use this to:
|
|
35
|
+
* - Register server-side handlers
|
|
36
|
+
* - Set up subscriptions
|
|
37
|
+
* - Initialize adapters
|
|
38
|
+
*
|
|
39
|
+
* @param environment - Current execution environment
|
|
40
|
+
* @param adapters - Available adapters
|
|
41
|
+
*/
|
|
42
|
+
init?(environment: ArcEnvironment, adapters: ModelAdapters): void | Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Get the mutation context for this element
|
|
45
|
+
* Provides write operations (emit events, execute commands, etc.)
|
|
46
|
+
*
|
|
47
|
+
* @param adapters - Available adapters (storage, leaderConnection)
|
|
48
|
+
* @returns Mutation context with write methods, or undefined if not supported
|
|
49
|
+
*
|
|
50
|
+
* Example implementations:
|
|
51
|
+
* - Events: { emit: (payload) => Promise<void> }
|
|
52
|
+
* - Commands: { execute: (params) => Promise<result> }
|
|
53
|
+
*/
|
|
54
|
+
mutateContext?(adapters: ModelAdapters): unknown;
|
|
55
|
+
/**
|
|
56
|
+
* Get the query context for this element
|
|
57
|
+
* Provides read operations (query views, read state, etc.)
|
|
58
|
+
*
|
|
59
|
+
* @param adapters - Available adapters (storage, leaderConnection)
|
|
60
|
+
* @returns Query context with read methods, or undefined if not supported
|
|
61
|
+
*
|
|
62
|
+
* Example implementations:
|
|
63
|
+
* - Views: { findOne: (query) => Promise<data>, findMany: (query) => Promise<data[]> }
|
|
64
|
+
*/
|
|
65
|
+
queryContext?(adapters: ModelAdapters): unknown;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Type helper to extract element name from element type
|
|
69
|
+
*/
|
|
70
|
+
export type ArcContextElementName<E extends ArcContextElement<any>> = E extends ArcContextElement<infer N> ? N : never;
|
|
71
|
+
/**
|
|
72
|
+
* Type for any context element (used for collections)
|
|
73
|
+
*/
|
|
74
|
+
export type ArcContextElementAny = ArcContextElement<string>;
|
|
75
|
+
//# sourceMappingURL=context-element.d.ts.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { WhereCondition } from "../../data-storage/find-options";
|
|
2
|
+
import type { ArcObjectAny } from "../../elements/object";
|
|
3
|
+
import type { ArcTokenAny } from "../../token/token";
|
|
4
|
+
/**
|
|
5
|
+
* Protection config for events
|
|
6
|
+
* Defines read/write access conditions based on token params
|
|
7
|
+
*/
|
|
8
|
+
export type EventProtectionConfig = {
|
|
9
|
+
read: WhereCondition | false;
|
|
10
|
+
write: WhereCondition | false;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Protection function for events
|
|
14
|
+
* Receives token params and returns read/write conditions
|
|
15
|
+
*/
|
|
16
|
+
export type EventProtectionFn<TokenParams> = (params: TokenParams) => EventProtectionConfig;
|
|
17
|
+
/**
|
|
18
|
+
* Event protection configuration
|
|
19
|
+
*/
|
|
20
|
+
export type EventProtection = {
|
|
21
|
+
token: ArcTokenAny;
|
|
22
|
+
protectionFn: EventProtectionFn<any>;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Event data configuration
|
|
26
|
+
* Contains all generic types and non-generic configuration in one object
|
|
27
|
+
*/
|
|
28
|
+
export type ArcEventData = {
|
|
29
|
+
name: string;
|
|
30
|
+
payload: ArcObjectAny | undefined;
|
|
31
|
+
description?: string;
|
|
32
|
+
protections?: EventProtection[];
|
|
33
|
+
tagFields?: string[];
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=event-data.d.ts.map
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import type { DatabaseStoreSchema } from "../../data-storage/database-store";
|
|
2
|
+
import { ArcObject, type ArcObjectAny, type ArcRawShape } from "../../elements/object";
|
|
3
|
+
import type { ModelAdapters } from "../../model/model-adapters";
|
|
4
|
+
import type { ArcTokenAny } from "../../token/token";
|
|
5
|
+
import type { TokenInstanceAny } from "../../token/token-instance";
|
|
6
|
+
import type { Merge } from "../../utils";
|
|
7
|
+
import type { $type } from "../../utils/types/get-type";
|
|
8
|
+
import { ArcContextElement } from "../context-element";
|
|
9
|
+
import type { ArcEventData, EventProtectionFn } from "./event-data";
|
|
10
|
+
/**
|
|
11
|
+
* Arc Event - Record of something that happened
|
|
12
|
+
*
|
|
13
|
+
* Events are immutable records of state changes in Arc Framework.
|
|
14
|
+
* They:
|
|
15
|
+
* - Have a unique name/type
|
|
16
|
+
* - Carry a typed payload
|
|
17
|
+
* - Are append-only (never modified or deleted)
|
|
18
|
+
* - Drive view updates and listener reactions
|
|
19
|
+
*
|
|
20
|
+
* Events follow the factory pattern from the Arc guide:
|
|
21
|
+
* - All configuration in a single Data object
|
|
22
|
+
* - Type-safe throughout
|
|
23
|
+
* - Immutable with clone-on-modify
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* const userRegistered = event("userRegistered", {
|
|
28
|
+
* userId: string().branded("user-id"),
|
|
29
|
+
* email: string().email(),
|
|
30
|
+
* timestamp: date(),
|
|
31
|
+
* });
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare class ArcEvent<const Data extends ArcEventData> extends ArcContextElement<Data["name"]> {
|
|
35
|
+
private readonly data;
|
|
36
|
+
private readonly eventId;
|
|
37
|
+
constructor(data: Data);
|
|
38
|
+
/**
|
|
39
|
+
* Get event payload schema
|
|
40
|
+
*/
|
|
41
|
+
get payload(): Data["payload"];
|
|
42
|
+
/**
|
|
43
|
+
* Set event description for documentation
|
|
44
|
+
*/
|
|
45
|
+
description<const Desc extends string>(description: Desc): ArcEvent<Merge<Data, {
|
|
46
|
+
description: Desc;
|
|
47
|
+
}>>;
|
|
48
|
+
/**
|
|
49
|
+
* Generate mutation context for this event
|
|
50
|
+
* Provides emit functionality to publish event instances
|
|
51
|
+
*
|
|
52
|
+
* @param adapters - Available adapters (eventPublisher, dataStorage)
|
|
53
|
+
* @returns Context object with emit method
|
|
54
|
+
*/
|
|
55
|
+
mutateContext(adapters: ModelAdapters): {
|
|
56
|
+
emit: (payload: Data["payload"] extends ArcObjectAny ? $type<Data["payload"]> : undefined) => Promise<void>;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Add token-based protection to this event
|
|
60
|
+
* Defines read/write access conditions based on token params
|
|
61
|
+
*
|
|
62
|
+
* @param token - Token definition to protect with
|
|
63
|
+
* @param protectionFn - Function returning read/write conditions
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* event("taskCreated", taskPayload)
|
|
68
|
+
* .protectBy(userToken, (params) => ({
|
|
69
|
+
* read: { userId: params.userId }, // Can only read own events
|
|
70
|
+
* write: { userId: params.userId }, // Can only emit own events
|
|
71
|
+
* }));
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
protectBy<T extends ArcTokenAny>(token: T, protectionFn: EventProtectionFn<any>): ArcEvent<Data>;
|
|
75
|
+
/**
|
|
76
|
+
* Check if event has protections
|
|
77
|
+
*/
|
|
78
|
+
get hasProtections(): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Get all protection configurations
|
|
81
|
+
*/
|
|
82
|
+
get protections(): import("./event-data").EventProtection[];
|
|
83
|
+
/**
|
|
84
|
+
* Get protection config for a specific token instance
|
|
85
|
+
*
|
|
86
|
+
* @param tokenInstance - Token instance to get protection for
|
|
87
|
+
* @returns Protection config or null if no matching protection
|
|
88
|
+
*/
|
|
89
|
+
getProtectionFor(tokenInstance: TokenInstanceAny): {
|
|
90
|
+
read: any;
|
|
91
|
+
write: any;
|
|
92
|
+
} | null;
|
|
93
|
+
/**
|
|
94
|
+
* Specify which payload fields should be stored as tags for efficient querying
|
|
95
|
+
* Tags are stored in a separate table with foreign key to events
|
|
96
|
+
*
|
|
97
|
+
* @param tagFields - Array of payload field names to use as tags
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```typescript
|
|
101
|
+
* event("taskCreated", { taskId: string(), userId: string(), title: string() })
|
|
102
|
+
* .tags(["userId", "taskId"]); // userId and taskId become queryable tags
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
tags<TagFields extends string[]>(tagFields: TagFields): ArcEvent<Merge<Data, {
|
|
106
|
+
tagFields: TagFields;
|
|
107
|
+
}>>;
|
|
108
|
+
/**
|
|
109
|
+
* Get the tag fields for this event
|
|
110
|
+
*/
|
|
111
|
+
get tagFields(): string[];
|
|
112
|
+
/** Cached shared schema - created once and reused */
|
|
113
|
+
private static _sharedSchema;
|
|
114
|
+
/**
|
|
115
|
+
* Get the shared database store schema for all events
|
|
116
|
+
* All events are stored in the same tables, distinguished by the `type` field
|
|
117
|
+
*
|
|
118
|
+
* Returns 3 tables:
|
|
119
|
+
* - events - single table for ALL events
|
|
120
|
+
* - event_tags - tags with FK to events
|
|
121
|
+
* - event_sync_status - sync tracking
|
|
122
|
+
*/
|
|
123
|
+
static sharedDatabaseStoreSchema(): DatabaseStoreSchema;
|
|
124
|
+
/**
|
|
125
|
+
* Instance method that returns the shared schema
|
|
126
|
+
* This ensures all events share the same table structure
|
|
127
|
+
*/
|
|
128
|
+
databaseStoreSchema(): DatabaseStoreSchema;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Create a new event with the given name and payload schema
|
|
132
|
+
*
|
|
133
|
+
* @param name - Unique event name/type
|
|
134
|
+
* @param payload - Optional payload schema (raw shape or ArcObject)
|
|
135
|
+
* @returns New event instance ready for configuration
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```typescript
|
|
139
|
+
* // Event with payload
|
|
140
|
+
* const taskCreated = event("taskCreated", {
|
|
141
|
+
* taskId: string(),
|
|
142
|
+
* title: string(),
|
|
143
|
+
* });
|
|
144
|
+
*
|
|
145
|
+
* // Event without payload
|
|
146
|
+
* const systemStarted = event("systemStarted");
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
export declare function event<const Name extends string, PayloadShape extends ArcObjectAny | ArcRawShape | undefined = undefined>(name: Name, payload?: PayloadShape): ArcEvent<{
|
|
150
|
+
name: Name;
|
|
151
|
+
payload: PayloadShape extends ArcRawShape ? ArcObject<PayloadShape> : PayloadShape extends ArcObjectAny ? PayloadShape : undefined;
|
|
152
|
+
protections: [];
|
|
153
|
+
}>;
|
|
154
|
+
/**
|
|
155
|
+
* Type alias for any event (used in collections)
|
|
156
|
+
*/
|
|
157
|
+
export type ArcEventAny = ArcEvent<any>;
|
|
158
|
+
//# sourceMappingURL=event.d.ts.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { ArcEvent, event, type ArcEventAny } from "./event";
|
|
2
|
+
export type { ArcEventData } from "./event-data";
|
|
3
|
+
export type { ArcEventInstance, ArcEventPayload, EventMetadata, } from "./instance";
|
|
4
|
+
export type { ArcObjectAny, ArcRawShape } from "../../elements/object";
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { $type } from "../../utils/types/get-type";
|
|
2
|
+
import type { ArcEventAny } from "./event";
|
|
3
|
+
/**
|
|
4
|
+
* Event metadata attached to every event instance
|
|
5
|
+
*/
|
|
6
|
+
export type EventMetadata = {
|
|
7
|
+
id: string;
|
|
8
|
+
createdAt: Date;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Event instance type - represents an actual event occurrence
|
|
12
|
+
* Combines event type, payload, and metadata
|
|
13
|
+
*/
|
|
14
|
+
export type ArcEventInstance<Event extends ArcEventAny> = {
|
|
15
|
+
type: Event["name"];
|
|
16
|
+
payload: Event["payload"] extends {
|
|
17
|
+
deserialize: (...args: any) => any;
|
|
18
|
+
} ? $type<Event["payload"]> : undefined;
|
|
19
|
+
} & EventMetadata;
|
|
20
|
+
/**
|
|
21
|
+
* Helper type to extract event payload type
|
|
22
|
+
*/
|
|
23
|
+
export type ArcEventPayload<Event extends ArcEventAny> = Event["payload"] extends {
|
|
24
|
+
deserialize: (...args: any) => any;
|
|
25
|
+
} ? $type<Event["payload"]> : undefined;
|
|
26
|
+
//# sourceMappingURL=instance.d.ts.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { ArcView, view, type ArcViewAny, type ArcViewRecord } from "./view";
|
|
2
|
+
export type { ArcViewData } from "./view-data";
|
|
3
|
+
export type { ArcViewHandlerContext, ArcViewItem, ArcViewQueryContext, } from "./view-context";
|
|
4
|
+
export type { ArcObjectAny } from "../../elements/object";
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { ArcIdAny } from "../../elements/id";
|
|
2
|
+
import type { ArcObjectAny } from "../../elements/object";
|
|
3
|
+
import type { $type } from "../../utils/types/get-type";
|
|
4
|
+
/**
|
|
5
|
+
* Request context available in view handlers
|
|
6
|
+
* Contains information about the current request (e.g., IP address)
|
|
7
|
+
*/
|
|
8
|
+
export type ViewRequestContext = {
|
|
9
|
+
/** Client IP address (available in server context) */
|
|
10
|
+
ipAddress?: string;
|
|
11
|
+
/** Additional request metadata */
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* View handler context provided to event handlers
|
|
16
|
+
* Allows handlers to modify view state in response to events
|
|
17
|
+
*/
|
|
18
|
+
export type ArcViewHandlerContext<Id extends ArcIdAny, Schema extends ArcObjectAny> = {
|
|
19
|
+
/** Set a complete record in the view (create or replace) */
|
|
20
|
+
set: (id: $type<Id>, data: $type<Schema>) => Promise<void>;
|
|
21
|
+
/** Modify specific fields of an existing record */
|
|
22
|
+
modify: (id: $type<Id>, data: Partial<$type<Schema>>) => Promise<void>;
|
|
23
|
+
/** Remove a record from the view */
|
|
24
|
+
remove: (id: $type<Id>) => Promise<void>;
|
|
25
|
+
/** Find multiple records matching criteria */
|
|
26
|
+
find: (options: any) => Promise<ArcViewItem<Id, Schema>[]>;
|
|
27
|
+
/** Find a single record matching criteria */
|
|
28
|
+
findOne: (where: any) => Promise<ArcViewItem<Id, Schema> | undefined>;
|
|
29
|
+
/** Request context (IP address, etc.) - available in server context */
|
|
30
|
+
$auth: ViewRequestContext;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* View item type - represents a single record in the view
|
|
34
|
+
* Includes the ID field (_id) plus all schema fields
|
|
35
|
+
*/
|
|
36
|
+
export type ArcViewItem<Id extends ArcIdAny, Schema extends ArcObjectAny> = {
|
|
37
|
+
_id: $type<Id>;
|
|
38
|
+
} & $type<Schema>;
|
|
39
|
+
/**
|
|
40
|
+
* View query context provided to commands
|
|
41
|
+
* Allows commands to read from views
|
|
42
|
+
*/
|
|
43
|
+
export type ArcViewQueryContext<Id extends ArcIdAny, Schema extends ArcObjectAny> = {
|
|
44
|
+
/** Find multiple records matching criteria */
|
|
45
|
+
find: (options: any) => Promise<ArcViewItem<Id, Schema>[]>;
|
|
46
|
+
/** Find a single record matching criteria */
|
|
47
|
+
findOne: (where: any) => Promise<ArcViewItem<Id, Schema> | undefined>;
|
|
48
|
+
/** Subscribe to view changes (optional, for reactive queries) */
|
|
49
|
+
subscribe?: (options: any, callback: (data: ArcViewItem<Id, Schema>[]) => void) => () => void;
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=view-context.d.ts.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { WhereCondition } from "../../data-storage/find-options";
|
|
2
|
+
import type { ArcObjectAny } from "../../elements/object";
|
|
3
|
+
import type { ArcTokenAny } from "../../token/token";
|
|
4
|
+
import type { ArcContextElement } from "../context-element";
|
|
5
|
+
/**
|
|
6
|
+
* Protection config for views
|
|
7
|
+
* Defines read/write access conditions based on token params
|
|
8
|
+
*/
|
|
9
|
+
export type ViewProtectionConfig = {
|
|
10
|
+
read: WhereCondition | false;
|
|
11
|
+
write: WhereCondition | false;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Protection function for views
|
|
15
|
+
* Receives token params and returns read/write conditions
|
|
16
|
+
*/
|
|
17
|
+
export type ViewProtectionFn<TokenParams> = (params: TokenParams) => ViewProtectionConfig;
|
|
18
|
+
/**
|
|
19
|
+
* View protection configuration
|
|
20
|
+
*/
|
|
21
|
+
export type ViewProtection = {
|
|
22
|
+
token: ArcTokenAny;
|
|
23
|
+
protectionFn: ViewProtectionFn<any>;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* View data configuration
|
|
27
|
+
* Contains all generic types and non-generic configuration in one object
|
|
28
|
+
*/
|
|
29
|
+
export type ArcViewData = {
|
|
30
|
+
name: string;
|
|
31
|
+
id: any;
|
|
32
|
+
schema: ArcObjectAny;
|
|
33
|
+
elements: ArcContextElement<any>[];
|
|
34
|
+
handler: Record<string, (ctx: any, event: any) => Promise<void>>;
|
|
35
|
+
description?: string;
|
|
36
|
+
isAsync?: boolean;
|
|
37
|
+
version?: number;
|
|
38
|
+
protections?: ViewProtection[];
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=view-data.d.ts.map
|