@arcote.tech/arc 0.4.6 → 0.4.8

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.
@@ -16,6 +16,16 @@ export declare class ArcContext<const Elements extends ArcContextElement<any>[]>
16
16
  * @returns The element if found, undefined otherwise
17
17
  */
18
18
  get<E extends Elements[number]>(name: E["name"]): E | undefined;
19
+ /**
20
+ * Replace a context element by name with a new element.
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * const accounts = ctx.get("userAccounts")!;
25
+ * const seeded = ctx.replace("userAccounts", accounts.withSeeds([...]));
26
+ * ```
27
+ */
28
+ replace(name: Elements[number]["name"], element: ArcContextElementAny): ArcContext<Elements>;
19
29
  }
20
30
  /**
21
31
  * Create a new context from an array of elements
@@ -9,7 +9,7 @@ import type { ArcObjectAny } from "../../elements/object";
9
9
  import type { ModelAdapters } from "../../model/model-adapters";
10
10
  import type { $type } from "../../utils/types/get-type";
11
11
  import type { ArcViewItem } from "../view/view-context";
12
- import type { AggregateInstanceCtx } from "./aggregate-builder";
12
+ import type { AggregateInstanceCtx } from "./aggregate-element";
13
13
  import type { AggregateEventEntry } from "./aggregate-data";
14
14
  /**
15
15
  * Base class for aggregate instances.
@@ -1,139 +1,12 @@
1
+ /**
2
+ * aggregate() — entry point for creating aggregate context elements.
3
+ *
4
+ * Returns an ArcAggregateElement directly (no .build() needed).
5
+ * Chain methods like .publicEvent(), .mutateMethod(), .clientQuery(), .seedWith()
6
+ * to configure the aggregate — each returns a new immutable instance.
7
+ */
8
+ import { ArcObject, type ArcRawShape } from "../../elements/object";
1
9
  import type { ArcIdAny } from "../../elements/id";
2
- import { ArcObject, type ArcObjectAny, type ArcRawShape } from "../../elements/object";
3
- import type { ArcTokenAny } from "../../token/token";
4
- import type { $type } from "../../utils/types/get-type";
5
- import type { Simplify } from "../../utils";
6
- import { ArcEvent, type ArcEventAny } from "../event/event";
7
- import type { ArcEventInstance } from "../event/instance";
8
- import type { ArcViewHandlerContext } from "../view/view-context";
9
- import type { ViewProtection, ViewProtectionFn } from "../view/view-data";
10
- import { AggregateBase } from "./aggregate-base";
11
- import type { AggregateCronMethodEntry, AggregateEventEntry, AggregateMutateMethodEntry, AggregateQueryMethodEntry } from "./aggregate-data";
12
- type InlineArcEvent<EN extends string, PS extends ArcRawShape> = ArcEvent<{
13
- name: EN;
14
- payload: ArcObject<PS>;
15
- protections: [];
16
- }>;
17
- type AggregateRow<Id extends ArcIdAny, Schema extends ArcObjectAny> = Simplify<$type<Schema> & {
18
- _id: $type<Id>;
19
- }>;
20
- type AggregatePrivateQuery<Id extends ArcIdAny, Schema extends ArcObjectAny> = {
21
- find: (options?: any) => Promise<AggregateRow<Id, Schema>[]>;
22
- findOne: (where?: any) => Promise<AggregateRow<Id, Schema> | undefined>;
23
- };
24
- type MutateMethodContext<Id extends ArcIdAny, Schema extends ArcObjectAny, Events extends AggregateEventEntry[]> = {
25
- [E in Events[number] as E["event"]["name"]]: {
26
- emit: (payload: E["event"]["payload"] extends {
27
- deserialize: (...a: any) => any;
28
- } ? $type<E["event"]["payload"]> : undefined) => Promise<void>;
29
- };
30
- } & {
31
- $auth: {
32
- params: any;
33
- tokenName: string;
34
- };
35
- $query: AggregatePrivateQuery<Id, Schema>;
36
- };
37
- type ClientQueryContext<Id extends ArcIdAny, Schema extends ArcObjectAny> = {
38
- $query: {
39
- find: {
40
- <M extends new (row: AggregateRow<Id, Schema>, adapters: any) => any>(options: any, mapper: M): Promise<InstanceType<M>[]>;
41
- (options?: any): Promise<AggregateRow<Id, Schema>[]>;
42
- };
43
- findOne: {
44
- <M extends new (row: AggregateRow<Id, Schema>, adapters: any) => any>(where: any, mapper: M): Promise<InstanceType<M> | undefined>;
45
- (where?: any): Promise<AggregateRow<Id, Schema> | undefined>;
46
- };
47
- };
48
- $auth: {
49
- params: any;
50
- tokenName: string;
51
- };
52
- };
53
- export type AggregateInstanceCtx<Events extends AggregateEventEntry[]> = {
54
- [E in Events[number] as E["event"]["name"]]: {
55
- emit: (payload: E["event"]["payload"] extends {
56
- deserialize: (...a: any) => any;
57
- } ? $type<E["event"]["payload"]> : undefined) => Promise<void>;
58
- };
59
- };
60
- type PublicEvents<Events extends AggregateEventEntry[]> = Extract<Events[number], {
61
- isPublic: true;
62
- }>;
63
- type PublicEventNames<Events extends AggregateEventEntry[]> = PublicEvents<Events>["event"]["name"];
64
- type GetPublicEvent<Events extends AggregateEventEntry[], Name extends string> = Extract<PublicEvents<Events>, {
65
- event: {
66
- name: Name;
67
- };
68
- }>["event"];
69
- export declare class AggregateBuilder<Name extends string, Id extends ArcIdAny, Schema extends ArcObjectAny, Events extends AggregateEventEntry[], MutateMethods extends AggregateMutateMethodEntry[], QueryMethods extends AggregateQueryMethodEntry[] = []> {
70
- private readonly _name;
71
- private readonly _id;
72
- private readonly _schema;
73
- private readonly _events;
74
- private readonly _protections;
75
- private readonly _mutateMethods;
76
- private readonly _queryMethods;
77
- constructor(name: Name, id: Id, schema: Schema, events?: Events, protections?: ViewProtection[], mutateMethods?: MutateMethods, queryMethods?: QueryMethods);
78
- protectBy<T extends ArcTokenAny>(token: T, protectionFn: ViewProtectionFn<any>): AggregateBuilder<Name, Id, Schema, Events, MutateMethods, QueryMethods>;
79
- event<const EventName extends string, PayloadShape extends ArcRawShape>(eventName: EventName, payload: PayloadShape, handler: (ctx: ArcViewHandlerContext<Id, Schema>, event: ArcEventInstance<InlineArcEvent<EventName, PayloadShape>>) => Promise<void>): AggregateBuilder<Name, Id, Schema, [
80
- ...Events,
81
- AggregateEventEntry<InlineArcEvent<EventName, PayloadShape>, Id, Schema, false>
82
- ], MutateMethods, QueryMethods>;
83
- publicEvent<const EventName extends string, PayloadShape extends ArcRawShape>(eventName: EventName, payload: PayloadShape, handler: (ctx: ArcViewHandlerContext<Id, Schema>, event: ArcEventInstance<InlineArcEvent<EventName, PayloadShape>>) => Promise<void>): AggregateBuilder<Name, Id, Schema, [
84
- ...Events,
85
- AggregateEventEntry<InlineArcEvent<EventName, PayloadShape>, Id, Schema, true>
86
- ], MutateMethods, QueryMethods>;
87
- handleEvent<E extends ArcEventAny>(arcEvent: E, handler: (ctx: ArcViewHandlerContext<Id, Schema>, event: ArcEventInstance<E>) => Promise<void>): AggregateBuilder<Name, Id, Schema, [
88
- ...Events,
89
- AggregateEventEntry<E, ArcIdAny, ArcObjectAny, false>
90
- ], MutateMethods, QueryMethods>;
91
- mutateMethod<const MethodName extends string, ParamsShape extends ArcRawShape, HR = void, R = never>(methodName: MethodName, config: {
92
- params: ParamsShape;
93
- result?: R;
94
- }, handler: ((ctx: MutateMethodContext<Id, Schema, Events>, params: $type<ArcObject<ParamsShape>>) => Promise<HR>) | false): AggregateBuilder<Name, Id, Schema, Events, [
95
- ...MutateMethods,
96
- {
97
- name: MethodName;
98
- params: ArcObject<ParamsShape>;
99
- handler: typeof handler;
100
- handlerReturn: HR;
101
- result: R;
102
- }
103
- ], QueryMethods>;
104
- /**
105
- * Attach a cron schedule to the last declared mutateMethod.
106
- * The CronScheduler will call this method on the given schedule
107
- * for every existing aggregate instance.
108
- *
109
- * @param expression - A cron expression (e.g. "0 *\/6 * * *" for every 6 hours)
110
- */
111
- cron(expression: string): AggregateBuilder<Name, Id, Schema, Events, MutateMethods, QueryMethods>;
112
- clientQuery<const MethodName extends string, H extends (ctx: ClientQueryContext<Id, Schema>, ...args: any[]) => Promise<any>>(methodName: MethodName, handler: H): AggregateBuilder<Name, Id, Schema, Events, MutateMethods, [
113
- ...QueryMethods,
114
- {
115
- name: MethodName;
116
- handler: H;
117
- }
118
- ]>;
119
- build(): AggregateConstructor<Name, Id, Schema, Events, MutateMethods, QueryMethods>;
120
- }
121
- export type AggregateConstructor<Name extends string = string, Id extends ArcIdAny = ArcIdAny, Schema extends ArcObjectAny = ArcObjectAny, Events extends AggregateEventEntry[] = AggregateEventEntry[], MutateMethods extends AggregateMutateMethodEntry[] = AggregateMutateMethodEntry[], QueryMethods extends AggregateQueryMethodEntry[] = AggregateQueryMethodEntry[]> = (new (row: import("../view/view-context").ArcViewItem<Id, Schema>, adapters: import("../../model/model-adapters").ModelAdapters) => AggregateBase<Id, Schema, Events>) & {
122
- readonly __aggregateName: Name;
123
- readonly __aggregateId: Id;
124
- readonly __aggregateSchema: Schema;
125
- readonly __aggregateEvents: Events;
126
- readonly __aggregateProtections: ViewProtection[];
127
- readonly __aggregateMutateMethods: MutateMethods;
128
- readonly __aggregateQueryMethods: QueryMethods;
129
- readonly __aggregateCronMethods: AggregateCronMethodEntry[];
130
- getEvent<EventName extends PublicEventNames<Events>>(name: EventName): GetPublicEvent<Events, EventName>;
131
- };
132
- export type AggregateConstructorAny = AggregateConstructor<any, any, any, any, any, any>;
133
- /** Extract the full row type ({ _id, ...fields }) from an aggregate constructor. */
134
- export type AggregateData<Ctor extends AggregateConstructorAny> = {
135
- _id: $type<Ctor["__aggregateId"]>;
136
- } & $type<Ctor["__aggregateSchema"]>;
137
- export declare function aggregate<const Name extends string, Id extends ArcIdAny, SchemaShape extends ArcRawShape>(name: Name, id: Id, schema: SchemaShape): AggregateBuilder<Name, Id, ArcObject<SchemaShape>, [], [], []>;
138
- export {};
10
+ import { ArcAggregateElement } from "./aggregate-element";
11
+ export declare function aggregate<const Name extends string, Id extends ArcIdAny, SchemaShape extends ArcRawShape>(name: Name, id: Id, schema: SchemaShape): ArcAggregateElement<Name, Id, ArcObject<SchemaShape>, [], [], []>;
139
12
  //# sourceMappingURL=aggregate-builder.d.ts.map
@@ -1,69 +1,183 @@
1
1
  /**
2
- * ArcAggregateElement
2
+ * ArcAggregateElement — unified aggregate builder + context element.
3
3
  *
4
- * Implements ArcContextElement for an aggregate.
5
- * Created by aggregateContextElement(Constructor).
4
+ * aggregate() returns this directly. No .build() or aggregateContextElement() needed.
5
+ * Each builder method returns a new immutable instance.
6
6
  *
7
- * Looks like an ArcView to the rest of the system:
8
- * - queryContext() → find/findOne returning class instances
9
- * - mutateContext() → emit per registered event
10
- * - getHandlers() / getElements() → for eventPublisher.registerViews()
11
- * - databaseStoreSchema() → view table schema
7
+ * From the framework's perspective, behaves like a view:
8
+ * - queryContext() → named query methods
9
+ * - mutateContext() → named mutation methods
10
+ * - getHandlers() / getElements() → for eventPublisher registration
11
+ * - databaseStoreSchema() → table schema
12
12
  */
13
13
  import type { DatabaseStoreSchema } from "../../data-storage/database-store";
14
+ import type { ArcIdAny } from "../../elements/id";
15
+ import { ArcObject, type ArcObjectAny, type ArcRawShape } from "../../elements/object";
14
16
  import type { ModelAdapters } from "../../model/model-adapters";
17
+ import type { Simplify } from "../../utils";
18
+ import type { $type } from "../../utils/types/get-type";
19
+ import type { ArcTokenAny } from "../../token/token";
15
20
  import { ArcContextElement } from "../context-element";
16
- import type { ArcEventAny } from "../event/event";
17
- import type { AggregateConstructorAny } from "./aggregate-builder";
18
- import type { AggregateMutateMethodContext, AggregateQueryContext } from "./aggregate-data";
19
- /**
20
- * ArcAggregateElement single context element for an aggregate.
21
- *
22
- * From the framework's perspective this behaves like a view:
23
- * - eventPublisher.registerViews() accepts it (duck typing via getHandlers/getElements/schema)
24
- * - queryContext provides find/findOne
25
- * - mutateContext provides emit per event
26
- */
27
- export declare class ArcAggregateElement<Ctor extends AggregateConstructorAny> extends ArcContextElement<Ctor["__aggregateName"]> {
28
- private readonly ctor;
21
+ import { ArcEvent, type ArcEventAny } from "../event/event";
22
+ import type { ArcEventInstance } from "../event/instance";
23
+ import type { ArcViewHandlerContext, ArcViewItem } from "../view/view-context";
24
+ import type { ViewProtection, ViewProtectionFn } from "../view/view-data";
25
+ import { AggregateBase } from "./aggregate-base";
26
+ import type { AggregateCronMethodEntry, AggregateEventEntry, AggregateMutateMethodContext, AggregateMutateMethodEntry, AggregateQueryContext, AggregateQueryMethodEntry } from "./aggregate-data";
27
+ type InlineArcEvent<EN extends string, PS extends ArcRawShape> = ArcEvent<{
28
+ name: EN;
29
+ payload: ArcObject<PS>;
30
+ protections: [];
31
+ }>;
32
+ export type AggregateRow<Id extends ArcIdAny, Schema extends ArcObjectAny> = Simplify<$type<Schema> & {
33
+ _id: $type<Id>;
34
+ }>;
35
+ type AggregatePrivateQuery<Id extends ArcIdAny, Schema extends ArcObjectAny> = {
36
+ find: {
37
+ <M extends new (row: AggregateRow<Id, Schema>, adapters: any) => any>(options: any, mapper: M): Promise<InstanceType<M>[]>;
38
+ (options?: any): Promise<AggregateRow<Id, Schema>[]>;
39
+ };
40
+ findOne: {
41
+ <M extends new (row: AggregateRow<Id, Schema>, adapters: any) => any>(where: any, mapper: M): Promise<InstanceType<M> | undefined>;
42
+ (where?: any): Promise<AggregateRow<Id, Schema> | undefined>;
43
+ };
44
+ };
45
+ type MutateMethodContext<Id extends ArcIdAny, Schema extends ArcObjectAny, Events extends AggregateEventEntry[]> = {
46
+ [E in Events[number] as E["event"]["name"]]: {
47
+ emit: (payload: E["event"]["payload"] extends {
48
+ deserialize: (...a: any) => any;
49
+ } ? $type<E["event"]["payload"]> : undefined) => Promise<void>;
50
+ };
51
+ } & {
52
+ $auth: {
53
+ params: any;
54
+ tokenName: string;
55
+ };
56
+ $query: AggregatePrivateQuery<Id, Schema>;
57
+ };
58
+ type ClientQueryContext<Id extends ArcIdAny, Schema extends ArcObjectAny, Events extends AggregateEventEntry[]> = {
59
+ $query: AggregatePrivateQuery<Id, Schema>;
60
+ $auth: {
61
+ params: any;
62
+ tokenName: string;
63
+ };
64
+ Aggregate: AggregateConstructor<Id, Schema, Events>;
65
+ };
66
+ export type AggregateInstanceCtx<Events extends AggregateEventEntry[]> = {
67
+ [E in Events[number] as E["event"]["name"]]: {
68
+ emit: (payload: E["event"]["payload"] extends {
69
+ deserialize: (...a: any) => any;
70
+ } ? $type<E["event"]["payload"]> : undefined) => Promise<void>;
71
+ };
72
+ };
73
+ type PublicEvents<Events extends AggregateEventEntry[]> = Extract<Events[number], {
74
+ isPublic: true;
75
+ }>;
76
+ type PublicEventNames<Events extends AggregateEventEntry[]> = PublicEvents<Events>["event"]["name"];
77
+ type GetPublicEvent<Events extends AggregateEventEntry[], Name extends string> = Extract<PublicEvents<Events>, {
78
+ event: {
79
+ name: Name;
80
+ };
81
+ }>["event"];
82
+ export type AggregateConstructor<Id extends ArcIdAny = ArcIdAny, Schema extends ArcObjectAny = ArcObjectAny, Events extends AggregateEventEntry[] = AggregateEventEntry[]> = (new (row: ArcViewItem<Id, Schema>, adapters: ModelAdapters) => AggregateBase<Id, Schema, Events>) & {
83
+ readonly __aggregateName: string;
84
+ readonly __aggregateId: Id;
85
+ readonly __aggregateSchema: Schema;
86
+ readonly __aggregateEvents: Events;
87
+ readonly __aggregateProtections: ViewProtection[];
88
+ readonly __aggregateMutateMethods: AggregateMutateMethodEntry[];
89
+ readonly __aggregateQueryMethods: AggregateQueryMethodEntry[];
90
+ readonly __aggregateCronMethods: AggregateCronMethodEntry[];
91
+ getEvent<EventName extends PublicEventNames<Events>>(name: EventName): GetPublicEvent<Events, EventName>;
92
+ };
93
+ export type AggregateConstructorAny = AggregateConstructor<any, any, any>;
94
+ /** Extract the full row type from an aggregate element. */
95
+ export type AggregateData<El extends ArcAggregateElement<any, any, any, any, any>> = AggregateRow<El extends ArcAggregateElement<infer _N, infer I, any, any, any> ? I : never, El extends ArcAggregateElement<infer _N, any, infer S, any, any> ? S : never>;
96
+ export declare class ArcAggregateElement<Name extends string = string, Id extends ArcIdAny = ArcIdAny, Schema extends ArcObjectAny = ArcObjectAny, Events extends AggregateEventEntry[] = AggregateEventEntry[], MutateMethods extends AggregateMutateMethodEntry[] = AggregateMutateMethodEntry[], QueryMethods extends AggregateQueryMethodEntry[] = AggregateQueryMethodEntry[]> extends ArcContextElement<Name> {
29
97
  /** Expose schema for eventPublisher view registration (duck typing) */
30
- readonly schema: Ctor["__aggregateSchema"];
31
- constructor(ctor: Ctor);
98
+ readonly schema: Schema;
99
+ private readonly _id_factory;
100
+ private readonly _events;
101
+ private readonly _protections;
102
+ private readonly _mutateMethods;
103
+ private readonly _queryMethods;
104
+ private _ctor?;
105
+ constructor(name: Name, idFactory: Id, schema: Schema, events?: Events, protections?: ViewProtection[], mutateMethods?: MutateMethods, queryMethods?: QueryMethods, seeds?: {
106
+ data: any[];
107
+ version: number;
108
+ });
109
+ protectBy<T extends ArcTokenAny>(token: T, protectionFn: ViewProtectionFn<any>): ArcAggregateElement<Name, Id, Schema, Events, MutateMethods, QueryMethods>;
110
+ event<const EventName extends string, PayloadShape extends ArcRawShape>(eventName: EventName, payload: PayloadShape, handler: (ctx: ArcViewHandlerContext<Id, Schema>, event: ArcEventInstance<InlineArcEvent<EventName, PayloadShape>>) => Promise<void>): ArcAggregateElement<Name, Id, Schema, [
111
+ ...Events,
112
+ AggregateEventEntry<InlineArcEvent<EventName, PayloadShape>, Id, Schema, false>
113
+ ], MutateMethods, QueryMethods>;
114
+ publicEvent<const EventName extends string, PayloadShape extends ArcRawShape>(eventName: EventName, payload: PayloadShape, handler: (ctx: ArcViewHandlerContext<Id, Schema>, event: ArcEventInstance<InlineArcEvent<EventName, PayloadShape>>) => Promise<void>): ArcAggregateElement<Name, Id, Schema, [
115
+ ...Events,
116
+ AggregateEventEntry<InlineArcEvent<EventName, PayloadShape>, Id, Schema, true>
117
+ ], MutateMethods, QueryMethods>;
118
+ handleEvent<E extends ArcEventAny>(arcEvent: E, handler: (ctx: ArcViewHandlerContext<Id, Schema>, event: ArcEventInstance<E>) => Promise<void>): ArcAggregateElement<Name, Id, Schema, [
119
+ ...Events,
120
+ AggregateEventEntry<E, ArcIdAny, ArcObjectAny, false>
121
+ ], MutateMethods, QueryMethods>;
122
+ mutateMethod<const MethodName extends string, ParamsShape extends ArcRawShape, HR = void, R = never>(methodName: MethodName, config: {
123
+ params: ParamsShape;
124
+ result?: R;
125
+ }, handler: ((ctx: MutateMethodContext<Id, Schema, Events>, params: $type<ArcObject<ParamsShape>>) => Promise<HR>) | false): ArcAggregateElement<Name, Id, Schema, Events, [
126
+ ...MutateMethods,
127
+ {
128
+ name: MethodName;
129
+ params: ArcObject<ParamsShape>;
130
+ handler: typeof handler;
131
+ handlerReturn: HR;
132
+ result: R;
133
+ }
134
+ ], QueryMethods>;
135
+ cron(expression: string): ArcAggregateElement<Name, Id, Schema, Events, MutateMethods, QueryMethods>;
136
+ clientQuery<const MethodName extends string, H extends (ctx: ClientQueryContext<Id, Schema, Events>, ...args: any[]) => Promise<any>>(methodName: MethodName, handler: H): ArcAggregateElement<Name, Id, Schema, Events, MutateMethods, [
137
+ ...QueryMethods,
138
+ {
139
+ name: MethodName;
140
+ handler: H;
141
+ }
142
+ ]>;
32
143
  /**
33
- * Returns event handlers keyed by event name.
34
- * Same shape as ArcView.getHandlers().
144
+ * Declare seed data inserted after table creation.
145
+ * Rows with `_id` use it as-is; rows without get auto-generated IDs.
35
146
  */
36
- getHandlers(): Record<string, (ctx: any, event: any) => Promise<void>>;
147
+ seedWith(data: Array<$type<Schema> & {
148
+ _id?: $type<Id>;
149
+ }>, options?: {
150
+ version?: number;
151
+ }): ArcAggregateElement<Name, Id, Schema, Events, MutateMethods, QueryMethods>;
37
152
  /**
38
- * Returns event elements this aggregate listens to.
39
- * Same shape as ArcView.getElements().
153
+ * Return a copy with seed data attached.
154
+ * Use with context.replace() to add seeds to framework-provided aggregates.
40
155
  */
156
+ withSeeds(data: Array<$type<Schema> & {
157
+ _id?: $type<Id>;
158
+ }>, options?: {
159
+ version?: number;
160
+ }): ArcAggregateElement<Name, Id, Schema, Events, MutateMethods, QueryMethods>;
161
+ /** The internal AggregateConstructor class. Use in clientQuery to extend with business methods. */
162
+ get Aggregate(): AggregateConstructor<Id, Schema, Events>;
163
+ private buildConstructor;
164
+ getHandlers(): Record<string, (ctx: any, event: any) => Promise<void>>;
41
165
  getElements(): ArcEventAny[];
42
- /**
43
- * queryContext exposes declared queryMethod entries as callable functions.
44
- *
45
- * Each queryMethod handler receives { $query: { find, findOne }, $auth }
46
- * where $query reads from the appropriate adapter (dataStorage, streamingCache, or queryWire).
47
- * Returns aggregate class instances.
48
- */
49
- queryContext(adapters: ModelAdapters): AggregateQueryContext<Ctor["__aggregateQueryMethods"]>;
50
- /**
51
- * Build private query methods (find/findOne) that work across all adapter modes.
52
- * Used internally by queryMethod handlers via ctx.$query.
53
- */
166
+ /** Public event accessor (same as old static getEvent) */
167
+ getEvent<EventName extends PublicEventNames<Events>>(eventName: EventName): GetPublicEvent<Events, EventName>;
168
+ /** Cron methods for CronScheduler discovery */
169
+ get cronMethods(): AggregateCronMethodEntry[];
170
+ queryContext(adapters: ModelAdapters): AggregateQueryContext<QueryMethods>;
54
171
  private buildPrivateQuery;
172
+ private buildUnrestrictedQuery;
55
173
  private getAuth;
56
- /**
57
- * mutateContext — exposes declared mutateMethod entries as callable functions.
58
- *
59
- * Each mutateMethod becomes a named function: `(params) => Promise<any>`.
60
- * The handler receives a context with emit per event + $auth + $query.
61
- */
62
- mutateContext(adapters: ModelAdapters): AggregateMutateMethodContext<Ctor["__aggregateMutateMethods"]>;
63
- /**
64
- * databaseStoreSchema — same as ArcView.
65
- * Creates a table named after the aggregate with _id + schema fields.
66
- */
174
+ mutateContext(adapters: ModelAdapters): AggregateMutateMethodContext<MutateMethods>;
67
175
  databaseStoreSchema(): DatabaseStoreSchema;
176
+ getSeeds(): {
177
+ idFactory: Id;
178
+ data: any[];
179
+ version: number;
180
+ } | undefined;
68
181
  }
182
+ export {};
69
183
  //# sourceMappingURL=aggregate-element.d.ts.map
@@ -2,30 +2,14 @@
2
2
  * Aggregate module
3
3
  *
4
4
  * Exports:
5
- * - aggregate() — builder entry point
6
- * - aggregateContextElement()creates ArcContextElement from aggregate class
7
- * - AggregateBase — base class for instances
5
+ * - aggregate() — creates ArcAggregateElement directly (no .build() needed)
6
+ * - ArcAggregateElementthe unified builder + context element
7
+ * - AggregateBase — base class for instances (used internally and in clientQuery)
8
8
  * - Types
9
9
  */
10
- export { aggregate, AggregateBuilder } from "./aggregate-builder";
11
- export type { AggregateConstructor, AggregateConstructorAny, AggregateData, AggregateInstanceCtx, } from "./aggregate-builder";
10
+ export { aggregate } from "./aggregate-builder";
11
+ export { ArcAggregateElement, type AggregateConstructor, type AggregateConstructorAny, type AggregateData, type AggregateInstanceCtx, type AggregateRow, } from "./aggregate-element";
12
12
  export { AggregateBase } from "./aggregate-base";
13
- export { ArcAggregateElement } from "./aggregate-element";
14
13
  export type { AggregateCronMethodEntry, AggregateEventEntry, AggregateEventHandler, AggregateMutateMethodContext, AggregateMutateMethodEntry, AggregateQueryContext, AggregateQueryMethodEntry, AggregateStaticConfig, } from "./aggregate-data";
15
14
  export type { ArcEventPayload } from "../event/instance";
16
- import type { AggregateConstructorAny } from "./aggregate-builder";
17
- import { ArcAggregateElement } from "./aggregate-element";
18
- /**
19
- * Create an ArcContextElement from an aggregate class.
20
- *
21
- * @param ctor - Aggregate class (extends the result of aggregate().build())
22
- * @returns ArcAggregateElement ready for context([])
23
- *
24
- * @example
25
- * ```ts
26
- * const taskElement = aggregateContextElement(Task);
27
- * const appContext = context([taskElement]);
28
- * ```
29
- */
30
- export declare function aggregateContextElement<Ctor extends AggregateConstructorAny>(ctor: Ctor): ArcAggregateElement<Ctor>;
31
15
  //# sourceMappingURL=index.d.ts.map
@@ -69,6 +69,13 @@ export declare abstract class ArcContextElement<const Name extends string> exten
69
69
  * - Views: { findOne: (query) => Promise<data>, findMany: (query) => Promise<data[]> }
70
70
  */
71
71
  queryContext?(adapters: ModelAdapters): unknown;
72
+ protected _seeds?: {
73
+ data: any[];
74
+ version: number;
75
+ idFactory?: any;
76
+ };
77
+ /** Get seed data declared via seedWith() or withSeeds(). */
78
+ getSeeds(): typeof this._seeds;
72
79
  }
73
80
  /**
74
81
  * Type helper to extract element name from element type
package/dist/index.js CHANGED
@@ -3,14 +3,23 @@ var TOKEN_PREFIX = "arc:token:";
3
3
  function hasLocalStorage() {
4
4
  return typeof localStorage !== "undefined";
5
5
  }
6
+ function notifyTokenChange(scope) {
7
+ if (typeof window !== "undefined") {
8
+ queueMicrotask(() => {
9
+ window.dispatchEvent(new CustomEvent("arc:token-change", { detail: { scope } }));
10
+ });
11
+ }
12
+ }
6
13
 
7
14
  class AuthAdapter {
8
15
  scopes = new Map;
9
16
  setToken(token, scope = "default") {
10
17
  if (!token) {
11
18
  this.scopes.delete(scope);
12
- if (hasLocalStorage())
19
+ if (hasLocalStorage()) {
13
20
  localStorage.removeItem(TOKEN_PREFIX + scope);
21
+ notifyTokenChange(scope);
22
+ }
14
23
  return;
15
24
  }
16
25
  try {
@@ -31,8 +40,10 @@ class AuthAdapter {
31
40
  exp: payload.exp
32
41
  }
33
42
  });
34
- if (hasLocalStorage())
43
+ if (hasLocalStorage()) {
35
44
  localStorage.setItem(TOKEN_PREFIX + scope, token);
45
+ notifyTokenChange(scope);
46
+ }
36
47
  } catch {
37
48
  this.scopes.delete(scope);
38
49
  if (hasLocalStorage())
@@ -714,6 +725,12 @@ class ArcContext {
714
725
  get(name) {
715
726
  return this.elementMap.get(name);
716
727
  }
728
+ replace(name, element) {
729
+ if (!this.elementMap.has(name))
730
+ throw new Error(`Context element "${name}" not found`);
731
+ const newElements = this.elements.map((el) => el.name === name ? element : el);
732
+ return new ArcContext(newElements);
733
+ }
717
734
  }
718
735
  function context(elements) {
719
736
  return new ArcContext(elements);
@@ -1266,42 +1283,6 @@ class ArcPrimitive extends ArcAbstract {
1266
1283
  }
1267
1284
  }
1268
1285
 
1269
- // src/elements/boolean.ts
1270
- class ArcBoolean extends ArcPrimitive {
1271
- hasToBeTrue() {
1272
- return this.validation("hasToBeTrue", (value) => {
1273
- if (!value)
1274
- return {
1275
- current: value
1276
- };
1277
- });
1278
- }
1279
- validation(name, validator) {
1280
- const instance = this.pipeValidation(name, validator);
1281
- return instance;
1282
- }
1283
- toJsonSchema() {
1284
- const schema = { type: "boolean" };
1285
- if (this._description) {
1286
- schema.description = this._description;
1287
- }
1288
- return schema;
1289
- }
1290
- getColumnData() {
1291
- const storeData = this.getStoreData();
1292
- return {
1293
- type: "boolean",
1294
- storeData: {
1295
- ...storeData,
1296
- isNullable: false
1297
- }
1298
- };
1299
- }
1300
- }
1301
- function boolean() {
1302
- return new ArcBoolean;
1303
- }
1304
-
1305
1286
  // src/elements/string.ts
1306
1287
  var stringValidator = typeValidatorBuilder("string");
1307
1288
 
@@ -1455,6 +1436,66 @@ function string() {
1455
1436
  return new ArcString;
1456
1437
  }
1457
1438
 
1439
+ // src/fragment/arc-fragment.ts
1440
+ class ArcFragmentBase {
1441
+ is(type) {
1442
+ return this.types.includes(type);
1443
+ }
1444
+ }
1445
+
1446
+ // src/context-element/context-element.ts
1447
+ class ArcContextElement extends ArcFragmentBase {
1448
+ name;
1449
+ types = ["context-element"];
1450
+ get id() {
1451
+ return this.name;
1452
+ }
1453
+ constructor(name) {
1454
+ super();
1455
+ this.name = name;
1456
+ }
1457
+ _seeds;
1458
+ getSeeds() {
1459
+ return this._seeds;
1460
+ }
1461
+ }
1462
+
1463
+ // src/elements/boolean.ts
1464
+ class ArcBoolean extends ArcPrimitive {
1465
+ hasToBeTrue() {
1466
+ return this.validation("hasToBeTrue", (value) => {
1467
+ if (!value)
1468
+ return {
1469
+ current: value
1470
+ };
1471
+ });
1472
+ }
1473
+ validation(name, validator) {
1474
+ const instance = this.pipeValidation(name, validator);
1475
+ return instance;
1476
+ }
1477
+ toJsonSchema() {
1478
+ const schema = { type: "boolean" };
1479
+ if (this._description) {
1480
+ schema.description = this._description;
1481
+ }
1482
+ return schema;
1483
+ }
1484
+ getColumnData() {
1485
+ const storeData = this.getStoreData();
1486
+ return {
1487
+ type: "boolean",
1488
+ storeData: {
1489
+ ...storeData,
1490
+ isNullable: false
1491
+ }
1492
+ };
1493
+ }
1494
+ }
1495
+ function boolean() {
1496
+ return new ArcBoolean;
1497
+ }
1498
+
1458
1499
  // src/elements/id.ts
1459
1500
  class ArcCustomId extends ArcBranded {
1460
1501
  createFn;
@@ -1545,26 +1586,6 @@ function number() {
1545
1586
  return new ArcNumber;
1546
1587
  }
1547
1588
 
1548
- // src/fragment/arc-fragment.ts
1549
- class ArcFragmentBase {
1550
- is(type) {
1551
- return this.types.includes(type);
1552
- }
1553
- }
1554
-
1555
- // src/context-element/context-element.ts
1556
- class ArcContextElement extends ArcFragmentBase {
1557
- name;
1558
- types = ["context-element"];
1559
- get id() {
1560
- return this.name;
1561
- }
1562
- constructor(name) {
1563
- super();
1564
- this.name = name;
1565
- }
1566
- }
1567
-
1568
1589
  // src/context-element/event/event.ts
1569
1590
  class ArcEvent extends ArcContextElement {
1570
1591
  data;
@@ -1715,7 +1736,7 @@ class AggregateBase {
1715
1736
  }
1716
1737
  }
1717
1738
 
1718
- // src/context-element/aggregate/aggregate-builder.ts
1739
+ // src/context-element/aggregate/aggregate-element.ts
1719
1740
  function createInlineEvent(eventName, payload) {
1720
1741
  const po = payload instanceof ArcObject ? payload : new ArcObject(payload);
1721
1742
  return new ArcEvent({
@@ -1725,25 +1746,27 @@ function createInlineEvent(eventName, payload) {
1725
1746
  });
1726
1747
  }
1727
1748
 
1728
- class AggregateBuilder {
1729
- _name;
1730
- _id;
1731
- _schema;
1749
+ class ArcAggregateElement extends ArcContextElement {
1750
+ schema;
1751
+ _id_factory;
1732
1752
  _events;
1733
1753
  _protections;
1734
1754
  _mutateMethods;
1735
1755
  _queryMethods;
1736
- constructor(name, id2, schema, events = [], protections = [], mutateMethods = [], queryMethods = []) {
1737
- this._name = name;
1738
- this._id = id2;
1739
- this._schema = schema;
1756
+ _ctor;
1757
+ constructor(name, idFactory, schema, events = [], protections = [], mutateMethods = [], queryMethods = [], seeds) {
1758
+ super(name);
1759
+ this._id_factory = idFactory;
1760
+ this.schema = schema;
1740
1761
  this._events = events;
1741
1762
  this._protections = protections;
1742
1763
  this._mutateMethods = mutateMethods;
1743
1764
  this._queryMethods = queryMethods;
1765
+ if (seeds)
1766
+ this._seeds = { ...seeds, idFactory };
1744
1767
  }
1745
1768
  protectBy(token, protectionFn) {
1746
- return new AggregateBuilder(this._name, this._id, this._schema, this._events, [...this._protections, { token, protectionFn }], this._mutateMethods, this._queryMethods);
1769
+ return new ArcAggregateElement(this.name, this._id_factory, this.schema, this._events, [...this._protections, { token, protectionFn }], this._mutateMethods, this._queryMethods, this._seeds);
1747
1770
  }
1748
1771
  event(eventName, payload, handler) {
1749
1772
  const arcEvent = createInlineEvent(eventName, payload);
@@ -1753,7 +1776,7 @@ class AggregateBuilder {
1753
1776
  isInline: true,
1754
1777
  isPublic: false
1755
1778
  };
1756
- return new AggregateBuilder(this._name, this._id, this._schema, [...this._events, entry], this._protections, this._mutateMethods, this._queryMethods);
1779
+ return new ArcAggregateElement(this.name, this._id_factory, this.schema, [...this._events, entry], this._protections, this._mutateMethods, this._queryMethods, this._seeds);
1757
1780
  }
1758
1781
  publicEvent(eventName, payload, handler) {
1759
1782
  const arcEvent = createInlineEvent(eventName, payload);
@@ -1763,7 +1786,7 @@ class AggregateBuilder {
1763
1786
  isInline: true,
1764
1787
  isPublic: true
1765
1788
  };
1766
- return new AggregateBuilder(this._name, this._id, this._schema, [...this._events, entry], this._protections, this._mutateMethods, this._queryMethods);
1789
+ return new ArcAggregateElement(this.name, this._id_factory, this.schema, [...this._events, entry], this._protections, this._mutateMethods, this._queryMethods, this._seeds);
1767
1790
  }
1768
1791
  handleEvent(arcEvent, handler) {
1769
1792
  const entry = {
@@ -1772,7 +1795,7 @@ class AggregateBuilder {
1772
1795
  isInline: false,
1773
1796
  isPublic: false
1774
1797
  };
1775
- return new AggregateBuilder(this._name, this._id, this._schema, [...this._events, entry], this._protections, this._mutateMethods, this._queryMethods);
1798
+ return new ArcAggregateElement(this.name, this._id_factory, this.schema, [...this._events, entry], this._protections, this._mutateMethods, this._queryMethods, this._seeds);
1776
1799
  }
1777
1800
  mutateMethod(methodName, config, handler) {
1778
1801
  const paramsObj = config.params instanceof ArcObject ? config.params : new ArcObject(config.params);
@@ -1781,28 +1804,39 @@ class AggregateBuilder {
1781
1804
  params: paramsObj,
1782
1805
  handler
1783
1806
  };
1784
- return new AggregateBuilder(this._name, this._id, this._schema, this._events, this._protections, [...this._mutateMethods, entry], this._queryMethods);
1807
+ return new ArcAggregateElement(this.name, this._id_factory, this.schema, this._events, this._protections, [...this._mutateMethods, entry], this._queryMethods, this._seeds);
1785
1808
  }
1786
1809
  cron(expression) {
1787
1810
  if (this._mutateMethods.length === 0) {
1788
1811
  throw new Error("cron() must be called immediately after mutateMethod()");
1789
1812
  }
1790
1813
  const methods = [...this._mutateMethods];
1791
- const lastIndex = methods.length - 1;
1792
- methods[lastIndex] = { ...methods[lastIndex], cronExpression: expression };
1793
- return new AggregateBuilder(this._name, this._id, this._schema, this._events, this._protections, methods, this._queryMethods);
1814
+ methods[methods.length - 1] = { ...methods[methods.length - 1], cronExpression: expression };
1815
+ return new ArcAggregateElement(this.name, this._id_factory, this.schema, this._events, this._protections, methods, this._queryMethods, this._seeds);
1794
1816
  }
1795
1817
  clientQuery(methodName, handler) {
1796
1818
  const entry = {
1797
1819
  name: methodName,
1798
1820
  handler
1799
1821
  };
1800
- return new AggregateBuilder(this._name, this._id, this._schema, this._events, this._protections, this._mutateMethods, [...this._queryMethods, entry]);
1822
+ return new ArcAggregateElement(this.name, this._id_factory, this.schema, this._events, this._protections, this._mutateMethods, [...this._queryMethods, entry], this._seeds);
1823
+ }
1824
+ seedWith(data, options) {
1825
+ return new ArcAggregateElement(this.name, this._id_factory, this.schema, this._events, this._protections, this._mutateMethods, this._queryMethods, { data, version: options?.version ?? 1 });
1826
+ }
1827
+ withSeeds(data, options) {
1828
+ return this.seedWith(data, options);
1829
+ }
1830
+ get Aggregate() {
1831
+ if (!this._ctor) {
1832
+ this._ctor = this.buildConstructor();
1833
+ }
1834
+ return this._ctor;
1801
1835
  }
1802
- build() {
1803
- const name = this._name;
1804
- const id2 = this._id;
1805
- const schema = this._schema;
1836
+ buildConstructor() {
1837
+ const name = this.name;
1838
+ const id2 = this._id_factory;
1839
+ const schema = this.schema;
1806
1840
  const events = this._events;
1807
1841
  const protections = this._protections;
1808
1842
  const mutateMethods = this._mutateMethods;
@@ -1831,52 +1865,52 @@ class AggregateBuilder {
1831
1865
  return entry?.event;
1832
1866
  }
1833
1867
  };
1834
- Object.defineProperty(AggregateClass, "name", {
1835
- value: `${name}Aggregate`
1836
- });
1868
+ Object.defineProperty(AggregateClass, "name", { value: `${name}Aggregate` });
1837
1869
  return AggregateClass;
1838
1870
  }
1839
- }
1840
- function aggregate(name, id2, schema) {
1841
- const schemaObj = schema instanceof ArcObject ? schema : new ArcObject(schema);
1842
- return new AggregateBuilder(name, id2, schemaObj, [], [], [], []);
1843
- }
1844
- // src/context-element/aggregate/aggregate-element.ts
1845
- class ArcAggregateElement extends ArcContextElement {
1846
- ctor;
1847
- schema;
1848
- constructor(ctor) {
1849
- super(ctor.__aggregateName);
1850
- this.ctor = ctor;
1851
- this.schema = ctor.__aggregateSchema;
1852
- }
1853
1871
  getHandlers() {
1854
1872
  const handlers = {};
1855
- for (const entry of this.ctor.__aggregateEvents) {
1873
+ for (const entry of this._events) {
1856
1874
  handlers[entry.event.name] = entry.handler;
1857
1875
  }
1858
1876
  return handlers;
1859
1877
  }
1860
1878
  getElements() {
1861
- return this.ctor.__aggregateEvents.map((e) => e.event);
1879
+ return this._events.map((e) => e.event);
1880
+ }
1881
+ getEvent(eventName) {
1882
+ const entry = this._events.find((e) => e.isPublic && e.event.name === eventName);
1883
+ return entry?.event;
1884
+ }
1885
+ get cronMethods() {
1886
+ const result = [];
1887
+ for (const method of this._mutateMethods) {
1888
+ if (method.cronExpression) {
1889
+ result.push({
1890
+ aggregateName: this.name,
1891
+ methodName: method.name,
1892
+ cronExpression: method.cronExpression
1893
+ });
1894
+ }
1895
+ }
1896
+ return result;
1862
1897
  }
1863
1898
  queryContext(adapters) {
1864
1899
  const privateQuery = this.buildPrivateQuery(adapters);
1865
- const queryMethods = this.ctor.__aggregateQueryMethods ?? [];
1866
1900
  const auth = this.getAuth(adapters);
1901
+ const AggCtor = this.Aggregate;
1867
1902
  const result = {};
1868
- for (const method of queryMethods) {
1903
+ for (const method of this._queryMethods) {
1869
1904
  result[method.name] = (...args) => {
1870
- const ctx = { $query: privateQuery, $auth: auth };
1905
+ const ctx = { $query: privateQuery, $auth: auth, Aggregate: AggCtor };
1871
1906
  return method.handler(ctx, ...args);
1872
1907
  };
1873
1908
  }
1874
1909
  return result;
1875
1910
  }
1876
1911
  buildPrivateQuery(adapters) {
1877
- const viewName = this.ctor.__aggregateName;
1878
- const protections = this.ctor.__aggregateProtections;
1879
- const Ctor = this.ctor;
1912
+ const viewName = this.name;
1913
+ const protections = this._protections;
1880
1914
  const getReadRestrictions = () => {
1881
1915
  if (protections.length === 0)
1882
1916
  return null;
@@ -1906,18 +1940,15 @@ class ArcAggregateElement extends ArcContextElement {
1906
1940
  return { ...options, where };
1907
1941
  };
1908
1942
  const findRows = async (options) => {
1909
- if (adapters.dataStorage) {
1943
+ if (adapters.dataStorage)
1910
1944
  return adapters.dataStorage.getStore(viewName).find(options);
1911
- }
1912
- if (adapters.streamingCache) {
1945
+ if (adapters.streamingCache)
1913
1946
  return adapters.streamingCache.getStore(viewName).find(options);
1914
- }
1915
- if (adapters.queryWire) {
1947
+ if (adapters.queryWire)
1916
1948
  return adapters.queryWire.query(viewName, options);
1917
- }
1918
1949
  return [];
1919
1950
  };
1920
- const schema = this.ctor.__aggregateSchema;
1951
+ const schema = this.schema;
1921
1952
  const deserializeRow = (row) => {
1922
1953
  const { _id, ...rest } = row;
1923
1954
  return { _id, ...schema.deserialize(rest) };
@@ -1943,6 +1974,36 @@ class ArcAggregateElement extends ArcContextElement {
1943
1974
  }
1944
1975
  };
1945
1976
  }
1977
+ buildUnrestrictedQuery(adapters) {
1978
+ const viewName = this.name;
1979
+ const schema = this.schema;
1980
+ const deserializeRow = (row) => {
1981
+ const { _id, ...rest } = row;
1982
+ return { _id, ...schema.deserialize(rest) };
1983
+ };
1984
+ const findRows = async (options) => {
1985
+ if (adapters.dataStorage)
1986
+ return adapters.dataStorage.getStore(viewName).find(options);
1987
+ if (adapters.streamingCache)
1988
+ return adapters.streamingCache.getStore(viewName).find(options);
1989
+ if (adapters.queryWire)
1990
+ return adapters.queryWire.query(viewName, options);
1991
+ return [];
1992
+ };
1993
+ return {
1994
+ find: async (options, mapper) => {
1995
+ const rows = await findRows(options || {});
1996
+ return mapper ? rows.map((row) => new mapper(row, adapters)) : rows.map(deserializeRow);
1997
+ },
1998
+ findOne: async (where, mapper) => {
1999
+ const rows = await findRows({ where });
2000
+ const row = rows[0];
2001
+ if (!row)
2002
+ return;
2003
+ return mapper ? new mapper(row, adapters) : deserializeRow(row);
2004
+ }
2005
+ };
2006
+ }
1946
2007
  getAuth(adapters) {
1947
2008
  if (adapters.authAdapter) {
1948
2009
  const decoded = adapters.authAdapter.getDecoded();
@@ -1951,9 +2012,10 @@ class ArcAggregateElement extends ArcContextElement {
1951
2012
  return { params: {}, tokenName: "" };
1952
2013
  }
1953
2014
  mutateContext(adapters) {
1954
- const events = this.ctor.__aggregateEvents;
1955
- const privateQuery = this.buildPrivateQuery(adapters);
2015
+ const events = this._events;
2016
+ const privateQuery = this.buildUnrestrictedQuery(adapters);
1956
2017
  const auth = this.getAuth(adapters);
2018
+ const aggregateName = this.name;
1957
2019
  const buildMutateMethodCtx = () => {
1958
2020
  const ctx = {};
1959
2021
  for (const entry of events) {
@@ -1978,14 +2040,14 @@ class ArcAggregateElement extends ArcContextElement {
1978
2040
  return ctx;
1979
2041
  };
1980
2042
  const result = {};
1981
- for (const method of this.ctor.__aggregateMutateMethods ?? []) {
2043
+ for (const method of this._mutateMethods) {
1982
2044
  result[method.name] = async (params) => {
1983
2045
  if (!method.handler) {
1984
2046
  if (!adapters.commandWire) {
1985
2047
  throw new Error(`Method "${method.name}" is server-only but no commandWire (WebSocket) is available.`);
1986
2048
  }
1987
2049
  const wireAuth = adapters.scope ? { scope: adapters.scope.scopeName, token: adapters.scope.getToken() } : undefined;
1988
- return adapters.commandWire.executeCommand(`${this.ctor.__aggregateName}.${method.name}`, params, wireAuth);
2050
+ return adapters.commandWire.executeCommand(`${aggregateName}.${method.name}`, params, wireAuth);
1989
2051
  }
1990
2052
  const ctx = buildMutateMethodCtx();
1991
2053
  return method.handler(ctx, params);
@@ -1994,26 +2056,27 @@ class ArcAggregateElement extends ArcContextElement {
1994
2056
  return result;
1995
2057
  }
1996
2058
  databaseStoreSchema() {
1997
- const viewName = this.ctor.__aggregateName;
1998
- const idSchema = new ArcObject({
1999
- _id: new ArcString().primaryKey()
2000
- });
2001
- const viewSchema = idSchema.merge(this.ctor.__aggregateSchema.rawShape || {});
2059
+ const idSchema = new ArcObject({ _id: new ArcString().primaryKey() });
2060
+ const viewSchema = idSchema.merge(this.schema.rawShape || {});
2002
2061
  const eventSchema = ArcEvent.sharedDatabaseStoreSchema();
2003
2062
  return {
2004
2063
  tables: [
2005
- {
2006
- name: viewName,
2007
- schema: viewSchema
2008
- },
2064
+ { name: this.name, schema: viewSchema },
2009
2065
  ...eventSchema.tables
2010
2066
  ]
2011
2067
  };
2012
2068
  }
2069
+ getSeeds() {
2070
+ if (!this._seeds)
2071
+ return;
2072
+ return { ...this._seeds, idFactory: this._id_factory };
2073
+ }
2013
2074
  }
2014
- // src/context-element/aggregate/index.ts
2015
- function aggregateContextElement(ctor) {
2016
- return new ArcAggregateElement(ctor);
2075
+
2076
+ // src/context-element/aggregate/aggregate-builder.ts
2077
+ function aggregate(name, id2, schema) {
2078
+ const schemaObj = schema instanceof ArcObject ? schema : new ArcObject(schema);
2079
+ return new ArcAggregateElement(name, id2, schemaObj);
2017
2080
  }
2018
2081
  // src/context-element/element-context.ts
2019
2082
  function buildElementContext(queryElements, mutationElements, adapters) {
@@ -4967,7 +5030,6 @@ export {
4967
5030
  array,
4968
5031
  applyOrderByAndLimit,
4969
5032
  any,
4970
- aggregateContextElement,
4971
5033
  aggregate,
4972
5034
  Wire,
4973
5035
  TokenInstance,
@@ -5019,6 +5081,5 @@ export {
5019
5081
  ArcAny,
5020
5082
  ArcAggregateElement,
5021
5083
  ArcAbstract,
5022
- AggregateBuilder,
5023
5084
  AggregateBase
5024
5085
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@arcote.tech/arc",
3
3
  "type": "module",
4
- "version": "0.4.6",
4
+ "version": "0.4.8",
5
5
  "private": false,
6
6
  "author": "Przemysław Krasiński [arcote.tech]",
7
7
  "description": "Arc framework core rewrite with improved event emission and type safety",