alepha 0.13.5 → 0.13.7

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.
Files changed (136) hide show
  1. package/dist/api-audits/index.browser.js +116 -0
  2. package/dist/api-audits/index.browser.js.map +1 -0
  3. package/dist/api-audits/index.d.ts +1194 -0
  4. package/dist/api-audits/index.js +674 -0
  5. package/dist/api-audits/index.js.map +1 -0
  6. package/dist/api-notifications/index.d.ts +147 -147
  7. package/dist/api-parameters/index.browser.js +36 -5
  8. package/dist/api-parameters/index.browser.js.map +1 -1
  9. package/dist/api-parameters/index.d.ts +711 -33
  10. package/dist/api-parameters/index.js +831 -17
  11. package/dist/api-parameters/index.js.map +1 -1
  12. package/dist/api-users/index.d.ts +16 -3
  13. package/dist/api-users/index.js +699 -19
  14. package/dist/api-users/index.js.map +1 -1
  15. package/dist/api-verifications/index.js +2 -1
  16. package/dist/api-verifications/index.js.map +1 -1
  17. package/dist/bin/index.js +1 -0
  18. package/dist/bin/index.js.map +1 -1
  19. package/dist/cli/index.d.ts +85 -31
  20. package/dist/cli/index.js +205 -33
  21. package/dist/cli/index.js.map +1 -1
  22. package/dist/command/index.d.ts +67 -6
  23. package/dist/command/index.js +30 -3
  24. package/dist/command/index.js.map +1 -1
  25. package/dist/core/index.browser.js +241 -61
  26. package/dist/core/index.browser.js.map +1 -1
  27. package/dist/core/index.d.ts +170 -90
  28. package/dist/core/index.js +264 -67
  29. package/dist/core/index.js.map +1 -1
  30. package/dist/core/index.native.js +248 -65
  31. package/dist/core/index.native.js.map +1 -1
  32. package/dist/email/index.js +15 -10554
  33. package/dist/email/index.js.map +1 -1
  34. package/dist/logger/index.d.ts +4 -4
  35. package/dist/logger/index.js +77 -72
  36. package/dist/logger/index.js.map +1 -1
  37. package/dist/orm/index.d.ts +5 -1
  38. package/dist/orm/index.js +24 -7
  39. package/dist/orm/index.js.map +1 -1
  40. package/dist/queue/index.d.ts +4 -4
  41. package/dist/redis/index.d.ts +10 -10
  42. package/dist/security/index.d.ts +28 -28
  43. package/dist/server/index.d.ts +10 -1
  44. package/dist/server/index.js +20 -6
  45. package/dist/server/index.js.map +1 -1
  46. package/dist/server-auth/index.d.ts +163 -152
  47. package/dist/server-auth/index.js +40 -10
  48. package/dist/server-auth/index.js.map +1 -1
  49. package/dist/server-cookies/index.js +5 -1
  50. package/dist/server-cookies/index.js.map +1 -1
  51. package/dist/server-links/index.d.ts +33 -33
  52. package/dist/server-security/index.d.ts +9 -9
  53. package/dist/thread/index.js +2 -2
  54. package/dist/thread/index.js.map +1 -1
  55. package/dist/vite/index.d.ts +2 -2
  56. package/dist/vite/index.js +102 -45
  57. package/dist/vite/index.js.map +1 -1
  58. package/dist/websocket/index.browser.js +3 -3
  59. package/dist/websocket/index.browser.js.map +1 -1
  60. package/dist/websocket/index.d.ts +7 -7
  61. package/dist/websocket/index.js +4 -4
  62. package/dist/websocket/index.js.map +1 -1
  63. package/package.json +14 -9
  64. package/src/api-audits/controllers/AuditController.ts +186 -0
  65. package/src/api-audits/entities/audits.ts +132 -0
  66. package/src/api-audits/index.browser.ts +18 -0
  67. package/src/api-audits/index.ts +58 -0
  68. package/src/api-audits/primitives/$audit.ts +159 -0
  69. package/src/api-audits/schemas/auditQuerySchema.ts +23 -0
  70. package/src/api-audits/schemas/auditResourceSchema.ts +9 -0
  71. package/src/api-audits/schemas/createAuditSchema.ts +27 -0
  72. package/src/api-audits/services/AuditService.ts +412 -0
  73. package/src/api-parameters/controllers/ConfigController.ts +324 -0
  74. package/src/api-parameters/entities/parameters.ts +93 -10
  75. package/src/api-parameters/index.ts +43 -4
  76. package/src/api-parameters/primitives/$config.ts +291 -19
  77. package/src/api-parameters/schedulers/ConfigActivationScheduler.ts +30 -0
  78. package/src/api-parameters/services/ConfigStore.ts +491 -0
  79. package/src/api-users/atoms/realmAuthSettingsAtom.ts +19 -0
  80. package/src/api-users/controllers/UserRealmController.ts +0 -2
  81. package/src/api-users/index.ts +2 -0
  82. package/src/api-users/primitives/$userRealm.ts +18 -3
  83. package/src/api-users/providers/UserRealmProvider.ts +6 -3
  84. package/src/api-users/services/RegistrationService.ts +2 -1
  85. package/src/api-users/services/SessionService.ts +4 -0
  86. package/src/api-users/services/UserService.ts +3 -0
  87. package/src/api-verifications/index.ts +7 -1
  88. package/src/bin/index.ts +1 -0
  89. package/src/cli/assets/biomeJson.ts +1 -1
  90. package/src/cli/assets/dummySpecTs.ts +7 -0
  91. package/src/cli/assets/editorconfig.ts +13 -0
  92. package/src/cli/assets/mainTs.ts +14 -0
  93. package/src/cli/commands/BiomeCommands.ts +2 -0
  94. package/src/cli/commands/CoreCommands.ts +28 -9
  95. package/src/cli/commands/VerifyCommands.ts +2 -1
  96. package/src/cli/commands/ViteCommands.ts +8 -9
  97. package/src/cli/services/AlephaCliUtils.ts +214 -23
  98. package/src/command/helpers/Asker.ts +0 -1
  99. package/src/command/primitives/$command.ts +67 -0
  100. package/src/command/providers/CliProvider.ts +39 -8
  101. package/src/core/Alepha.ts +40 -30
  102. package/src/core/helpers/jsonSchemaToTypeBox.ts +307 -0
  103. package/src/core/index.shared.ts +1 -0
  104. package/src/core/index.ts +30 -3
  105. package/src/core/providers/EventManager.ts +1 -1
  106. package/src/core/providers/StateManager.ts +23 -12
  107. package/src/core/providers/TypeProvider.ts +26 -34
  108. package/src/logger/index.ts +8 -6
  109. package/src/logger/primitives/$logger.ts +1 -1
  110. package/src/logger/providers/{SimpleFormatterProvider.ts → PrettyFormatterProvider.ts} +10 -1
  111. package/src/orm/index.ts +6 -0
  112. package/src/orm/services/PgRelationManager.ts +2 -2
  113. package/src/orm/services/PostgresModelBuilder.ts +11 -7
  114. package/src/orm/services/Repository.ts +16 -7
  115. package/src/orm/services/SqliteModelBuilder.ts +10 -0
  116. package/src/server/index.ts +6 -0
  117. package/src/server/primitives/$action.ts +10 -1
  118. package/src/server/providers/ServerBodyParserProvider.ts +11 -5
  119. package/src/server/providers/ServerRouterProvider.ts +13 -7
  120. package/src/server-auth/primitives/$auth.ts +7 -0
  121. package/src/server-auth/providers/ServerAuthProvider.ts +51 -8
  122. package/src/server-cookies/index.ts +2 -1
  123. package/src/thread/primitives/$thread.ts +2 -2
  124. package/src/vite/index.ts +0 -2
  125. package/src/vite/tasks/buildServer.ts +3 -4
  126. package/src/vite/tasks/generateCloudflare.ts +35 -19
  127. package/src/vite/tasks/generateDocker.ts +18 -4
  128. package/src/vite/tasks/generateSitemap.ts +5 -7
  129. package/src/vite/tasks/generateVercel.ts +76 -41
  130. package/src/vite/tasks/runAlepha.ts +16 -1
  131. package/src/websocket/providers/NodeWebSocketServerProvider.ts +3 -11
  132. package/src/websocket/services/WebSocketClient.ts +3 -3
  133. package/dist/cli/dist-BlfFtOk2.js +0 -2770
  134. package/dist/cli/dist-BlfFtOk2.js.map +0 -1
  135. package/src/api-parameters/controllers/ParameterController.ts +0 -45
  136. package/src/api-parameters/services/ParameterStore.ts +0 -23
@@ -1,34 +1,120 @@
1
- import * as alepha1 from "alepha";
2
- import { Primitive, Static, TObject } from "alepha";
3
- import * as alepha_orm0 from "alepha/orm";
1
+ import * as alepha317 from "alepha";
2
+ import { KIND, Primitive, Static, TObject } from "alepha";
3
+ import * as alepha_server0 from "alepha/server";
4
+ import { DateTimeProvider } from "alepha/datetime";
5
+ import * as alepha_logger1 from "alepha/logger";
6
+ import * as alepha_orm14 from "alepha/orm";
7
+ import * as alepha_topic0 from "alepha/topic";
8
+ import * as alepha_scheduler0 from "alepha/scheduler";
4
9
  import { UserAccount } from "alepha/security";
5
10
 
6
11
  //#region ../../src/api-parameters/entities/parameters.d.ts
7
- declare const parameters: alepha_orm0.EntityPrimitive<alepha1.TObject<{
8
- id: alepha_orm0.PgAttr<alepha_orm0.PgAttr<alepha1.TString, typeof alepha_orm0.PG_PRIMARY_KEY>, typeof alepha_orm0.PG_DEFAULT>;
9
- createdAt: alepha_orm0.PgAttr<alepha_orm0.PgAttr<alepha1.TString, typeof alepha_orm0.PG_CREATED_AT>, typeof alepha_orm0.PG_DEFAULT>;
10
- updatedAt: alepha_orm0.PgAttr<alepha_orm0.PgAttr<alepha1.TString, typeof alepha_orm0.PG_UPDATED_AT>, typeof alepha_orm0.PG_DEFAULT>;
11
- name: alepha1.TString;
12
- content: alepha1.TRecord<string, alepha1.TAny>;
13
- tags: alepha1.TOptional<alepha1.TArray<alepha1.TString>>;
14
- creatorId: alepha1.TOptional<alepha1.TString>;
15
- creatorName: alepha1.TOptional<alepha1.TString>;
16
- activationDate: alepha1.TString;
12
+ /**
13
+ * Parameter status values.
14
+ *
15
+ * - EXPIRED: Past version, no longer active
16
+ * - CURRENT: Currently active version
17
+ * - NEXT: Scheduled to become active (closest future date)
18
+ * - FUTURE: Scheduled for activation after NEXT
19
+ */
20
+ type ParameterStatus = "expired" | "current" | "next" | "future";
21
+ /**
22
+ * Configuration parameter entity for versioned configuration management.
23
+ *
24
+ * Stores all versions of configuration parameters with:
25
+ * - Automatic status management (expired, current, next, future)
26
+ * - Schema versioning for migrations
27
+ * - Activation scheduling
28
+ * - Audit trail (creator info)
29
+ */
30
+ declare const parameters: alepha_orm14.EntityPrimitive<alepha317.TObject<{
31
+ id: alepha_orm14.PgAttr<alepha_orm14.PgAttr<alepha317.TString, typeof alepha_orm14.PG_PRIMARY_KEY>, typeof alepha_orm14.PG_DEFAULT>;
32
+ createdAt: alepha_orm14.PgAttr<alepha_orm14.PgAttr<alepha317.TString, typeof alepha_orm14.PG_CREATED_AT>, typeof alepha_orm14.PG_DEFAULT>;
33
+ updatedAt: alepha_orm14.PgAttr<alepha_orm14.PgAttr<alepha317.TString, typeof alepha_orm14.PG_UPDATED_AT>, typeof alepha_orm14.PG_DEFAULT>;
34
+ /**
35
+ * Configuration name using dot notation for tree hierarchy.
36
+ * Examples: "app.features", "app.pricing.tiers", "system.limits"
37
+ */
38
+ name: alepha317.TString;
39
+ /**
40
+ * The configuration content as JSON.
41
+ */
42
+ content: alepha317.TRecord<string, alepha317.TAny>;
43
+ /**
44
+ * Schema version hash for detecting schema changes.
45
+ * Used for auto-migration when schema evolves.
46
+ */
47
+ schemaHash: alepha317.TString;
48
+ /**
49
+ * Current status of this parameter version.
50
+ */
51
+ status: alepha_orm14.PgAttr<alepha317.TUnsafe<"expired" | "current" | "next" | "future">, typeof alepha_orm14.PG_DEFAULT>;
52
+ /**
53
+ * When this version should become active.
54
+ * Default is immediate (now).
55
+ */
56
+ activationDate: alepha317.TString;
57
+ /**
58
+ * When this version was deactivated (became expired).
59
+ * Null if still active or scheduled.
60
+ */
61
+ expiredAt: alepha317.TOptional<alepha317.TString>;
62
+ /**
63
+ * Version number for this configuration.
64
+ * Auto-incremented per config name.
65
+ */
66
+ version: alepha317.TInteger;
67
+ /**
68
+ * Optional description of changes in this version.
69
+ */
70
+ changeDescription: alepha317.TOptional<alepha317.TString>;
71
+ /**
72
+ * Optional tags for filtering/categorization.
73
+ */
74
+ tags: alepha317.TOptional<alepha317.TArray<alepha317.TString>>;
75
+ /**
76
+ * Creator user ID (if available).
77
+ */
78
+ creatorId: alepha317.TOptional<alepha317.TString>;
79
+ /**
80
+ * Creator display name for audit trail.
81
+ */
82
+ creatorName: alepha317.TOptional<alepha317.TString>;
83
+ /**
84
+ * Previous content before this change (for rollback reference).
85
+ */
86
+ previousContent: alepha317.TOptional<alepha317.TRecord<string, alepha317.TAny>>;
87
+ /**
88
+ * Migration log if schema changed.
89
+ */
90
+ migrationLog: alepha317.TOptional<alepha317.TString>;
17
91
  }>>;
18
- type ParameterEntity = Static<typeof parameters.schema>;
92
+ type Parameter = Static<typeof parameters.schema>;
93
+ type ParameterInsert = Omit<Parameter, "id" | "createdAt" | "updatedAt">;
19
94
  //#endregion
20
95
  //#region ../../src/api-parameters/primitives/$config.d.ts
21
96
  /**
22
- * Creates a configuration parameter primitive for managing application settings.
97
+ * Creates a versioned configuration primitive for managing application settings.
98
+ *
99
+ * Provides type-safe, versioned configuration with:
100
+ * - Schema validation with auto-migration detection
101
+ * - Default values for initial state
102
+ * - Scheduled activation (FUTURE, NEXT, CURRENT, EXPIRED statuses)
103
+ * - PostgreSQL persistence with full version history
104
+ * - Cross-instance synchronization via topic
105
+ * - Tree view support via dot-notation naming (e.g., "app.features.flags")
23
106
  *
24
- * Provides type-safe, versioned configuration with schema validation, default values,
25
- * and scheduled activation. Useful for feature flags, system parameters, and runtime settings.
107
+ * Integrates with Alepha's atom system for state management:
108
+ * - Uses `alepha.set(atom, value)` for mutations
109
+ * - Listens to `state:mutate` events to detect changes
110
+ * - Auto-persists changes to database
111
+ * - Syncs across instances via topic
26
112
  *
27
113
  * @example
28
114
  * ```ts
29
115
  * class AppConfig {
30
116
  * features = $config({
31
- * name: "feature-flags",
117
+ * name: "app.features.flags",
32
118
  * schema: t.object({
33
119
  * enableBeta: t.boolean(),
34
120
  * maxUploadSize: t.number()
@@ -36,48 +122,640 @@ type ParameterEntity = Static<typeof parameters.schema>;
36
122
  * default: { enableBeta: false, maxUploadSize: 10485760 }
37
123
  * });
38
124
  *
39
- * async updateFeatures() {
125
+ * async enableBeta() {
126
+ * // Immediate activation
127
+ * await this.features.set({ enableBeta: true, maxUploadSize: 20971520 });
128
+ * }
129
+ *
130
+ * async scheduleBetaRelease() {
131
+ * // Schedule for future activation
40
132
  * await this.features.set(
41
133
  * { enableBeta: true, maxUploadSize: 20971520 },
42
- * { user: currentUser, activationDate: tomorrow }
134
+ * { activationDate: new Date('2024-03-01') }
43
135
  * );
44
136
  * }
45
137
  * }
46
138
  * ```
47
139
  */
48
140
  interface ConfigPrimitiveOptions<T extends TObject> {
141
+ /**
142
+ * Configuration name using dot notation for tree hierarchy.
143
+ * Examples: "app.features", "app.pricing.tiers", "system.limits"
144
+ */
49
145
  name?: string;
146
+ /**
147
+ * Human-readable description of the configuration.
148
+ */
50
149
  description?: string;
150
+ /**
151
+ * TypeBox schema defining the configuration structure.
152
+ */
51
153
  schema: T;
154
+ /**
155
+ * Default value used when no configuration exists in database.
156
+ */
52
157
  default: Static<T>;
53
158
  }
54
159
  declare class ConfigPrimitive<T extends TObject> extends Primitive<ConfigPrimitiveOptions<T>> {
160
+ protected readonly log: alepha_logger1.Logger;
161
+ protected readonly store: ConfigStore;
162
+ /** Internal atom key for state management */
163
+ protected atomKey: string;
164
+ /** Schema hash for migration detection */
165
+ protected schemaHash: string;
166
+ /** Whether we're currently syncing (to avoid loops) */
167
+ protected syncing: boolean;
168
+ /** Whether initial load has completed */
169
+ protected loaded: boolean;
170
+ /**
171
+ * Configuration name (uses property key if not specified).
172
+ */
55
173
  get name(): string;
174
+ /**
175
+ * The TypeBox schema for this configuration.
176
+ */
56
177
  get schema(): T;
178
+ /**
179
+ * Get the current configuration value.
180
+ */
57
181
  get current(): Static<T>;
58
- get next(): Static<T> | undefined;
182
+ /**
183
+ * Get a specific field from the current configuration.
184
+ */
59
185
  get<Key extends keyof Static<T>>(key: Key): Static<T>[Key];
60
186
  /**
61
- * Apply a new configuration object.
187
+ * Set a new configuration value.
188
+ *
189
+ * @param value - The new configuration value
190
+ * @param options - Optional settings (activation date, creator info, etc.)
191
+ */
192
+ set(value: Static<T>, options?: SetConfigOptions): Promise<void>;
193
+ /**
194
+ * Subscribe to configuration changes.
195
+ */
196
+ sub(fn: (curr: Static<T>) => void): () => void;
197
+ /**
198
+ * Reload configuration from database.
199
+ * Called when scheduled config activates or sync message received.
200
+ */
201
+ reload(): Promise<void>;
202
+ /**
203
+ * Update from sync message (called by ConfigStore).
204
+ * Uses skipEvents to avoid infinite loops.
205
+ */
206
+ updateFromSync(content: unknown): Promise<void>;
207
+ /**
208
+ * Get version history for this configuration.
209
+ */
210
+ getHistory(): Promise<{
211
+ expiredAt?: string | undefined;
212
+ changeDescription?: string | undefined;
213
+ tags?: string[] | undefined;
214
+ creatorId?: string | undefined;
215
+ creatorName?: string | undefined;
216
+ previousContent?: Record<string, any> | undefined;
217
+ migrationLog?: string | undefined;
218
+ id: string;
219
+ createdAt: string;
220
+ updatedAt: string;
221
+ name: string;
222
+ content: Record<string, any>;
223
+ schemaHash: string;
224
+ status: "expired" | "current" | "next" | "future";
225
+ activationDate: string;
226
+ version: number;
227
+ }[]>;
228
+ /**
229
+ * Rollback to a specific version.
230
+ */
231
+ rollback(version: number, options?: SetConfigOptions): Promise<void>;
232
+ /**
233
+ * Hook to load initial value from database on start.
234
+ */
235
+ protected readonly onStart: alepha317.HookPrimitive<"start">;
236
+ /**
237
+ * Called after primitive creation to initialize.
238
+ */
239
+ protected onInit(): void;
240
+ /**
241
+ * Load initial value from database.
62
242
  */
63
- set(value: Static<T>, options: {
64
- user?: UserAccount;
65
- activationDate?: Date;
66
- }): Promise<void>;
67
- sub(fn: (curr: Static<T>) => void): void;
243
+ protected loadInitial(): Promise<void>;
244
+ /**
245
+ * Calculate a hash of the schema for migration detection.
246
+ */
247
+ protected calculateSchemaHash(): string;
248
+ }
249
+ declare const $config: {
250
+ <T extends TObject>(options: ConfigPrimitiveOptions<T>): ConfigPrimitive<T>;
251
+ [KIND]: typeof ConfigPrimitive;
252
+ };
253
+ interface SetConfigOptions {
254
+ /**
255
+ * User making the change (for audit trail).
256
+ */
257
+ user?: Pick<UserAccount, "id" | "email" | "name">;
258
+ /**
259
+ * When this configuration should become active.
260
+ * Default is immediate (now).
261
+ */
262
+ activationDate?: Date;
263
+ /**
264
+ * Description of the change.
265
+ */
266
+ changeDescription?: string;
267
+ /**
268
+ * Tags for filtering/categorization.
269
+ */
270
+ tags?: string[];
271
+ }
272
+ //#endregion
273
+ //#region ../../src/api-parameters/services/ConfigStore.d.ts
274
+ /**
275
+ * Payload for config sync events across instances.
276
+ */
277
+ interface ConfigSyncPayload {
278
+ name: string;
279
+ version: number;
280
+ content: unknown;
281
+ status: ParameterStatus;
282
+ instanceId: string;
283
+ }
284
+ /**
285
+ * ConfigStore manages versioned configuration persistence and synchronization.
286
+ *
287
+ * Features:
288
+ * - Stores all config versions in PostgreSQL
289
+ * - Manages status transitions (future → next → current → expired)
290
+ * - Provides cross-instance sync via topic
291
+ * - Supports schema migrations via hash comparison
292
+ * - Auto-activates scheduled configs
293
+ */
294
+ declare class ConfigStore {
295
+ protected readonly log: alepha_logger1.Logger;
296
+ protected readonly dateTimeProvider: DateTimeProvider;
297
+ protected readonly repo: alepha_orm14.Repository<TObject<{
298
+ id: alepha_orm14.PgAttr<alepha_orm14.PgAttr<alepha317.TString, typeof alepha_orm14.PG_PRIMARY_KEY>, typeof alepha_orm14.PG_DEFAULT>;
299
+ createdAt: alepha_orm14.PgAttr<alepha_orm14.PgAttr<alepha317.TString, typeof alepha_orm14.PG_CREATED_AT>, typeof alepha_orm14.PG_DEFAULT>;
300
+ updatedAt: alepha_orm14.PgAttr<alepha_orm14.PgAttr<alepha317.TString, typeof alepha_orm14.PG_UPDATED_AT>, typeof alepha_orm14.PG_DEFAULT>;
301
+ name: alepha317.TString;
302
+ content: alepha317.TRecord<string, alepha317.TAny>;
303
+ schemaHash: alepha317.TString;
304
+ status: alepha_orm14.PgAttr<alepha317.TUnsafe<"expired" | "current" | "next" | "future">, typeof alepha_orm14.PG_DEFAULT>;
305
+ activationDate: alepha317.TString;
306
+ expiredAt: alepha317.TOptional<alepha317.TString>;
307
+ version: alepha317.TInteger;
308
+ changeDescription: alepha317.TOptional<alepha317.TString>;
309
+ tags: alepha317.TOptional<alepha317.TArray<alepha317.TString>>;
310
+ creatorId: alepha317.TOptional<alepha317.TString>;
311
+ creatorName: alepha317.TOptional<alepha317.TString>;
312
+ previousContent: alepha317.TOptional<alepha317.TRecord<string, alepha317.TAny>>;
313
+ migrationLog: alepha317.TOptional<alepha317.TString>;
314
+ }>>;
315
+ /** Unique identifier for this instance (to avoid self-updates) */
316
+ protected readonly instanceId: `${string}-${string}-${string}-${string}-${string}`;
317
+ /** In-memory cache of registered configs */
318
+ protected readonly configs: Map<string, ConfigPrimitive<any>>;
319
+ /** Topic for cross-instance synchronization */
320
+ readonly syncTopic: alepha_topic0.TopicPrimitive<{
321
+ payload: TObject<{
322
+ name: alepha317.TString;
323
+ version: alepha317.TInteger;
324
+ content: alepha317.TRecord<string, alepha317.TAny>;
325
+ status: alepha317.TUnsafe<"expired" | "current" | "next" | "future">;
326
+ instanceId: alepha317.TString;
327
+ }>;
328
+ }>;
329
+ /**
330
+ * Register a config primitive with the store.
331
+ */
332
+ register(config: ConfigPrimitive<any>): void;
333
+ /**
334
+ * Load the current config value from database.
335
+ * Returns the current or next version if no current exists.
336
+ */
337
+ load<T extends TObject>(name: string): Promise<Static<T> | null>;
338
+ /**
339
+ * Save a new config version.
340
+ *
341
+ * @param name - Config name (e.g., "app.features.flags")
342
+ * @param content - New config content
343
+ * @param schemaHash - Hash of the schema for migration detection
344
+ * @param options - Additional options (activation date, creator info, etc.)
345
+ */
346
+ save<T extends TObject>(name: string, content: Static<T>, schemaHash: string, options?: SaveConfigOptions): Promise<Parameter>;
347
+ /**
348
+ * Get all versions of a config.
349
+ */
350
+ getHistory(name: string): Promise<Parameter[]>;
351
+ /**
352
+ * Get a specific version of a config.
353
+ */
354
+ getVersion(name: string, version: number): Promise<Parameter | null>;
355
+ /**
356
+ * Rollback to a previous version by creating a new version with old content.
357
+ */
358
+ rollback(name: string, targetVersion: number, options?: SaveConfigOptions): Promise<Parameter>;
359
+ /**
360
+ * Get all configs by status.
361
+ */
362
+ getByStatus(status: ParameterStatus): Promise<Parameter[]>;
363
+ /**
364
+ * Get current config value with fallback to default from registered primitive.
365
+ * Returns the in-memory current value which may be the default if never saved.
366
+ */
367
+ getCurrentValue(name: string): {
368
+ content: unknown;
369
+ isDefault: boolean;
370
+ } | null;
371
+ /**
372
+ * Get config info including current value with default fallback.
373
+ */
374
+ getCurrentWithDefault(name: string): Promise<{
375
+ current: Parameter | null;
376
+ next: Parameter | null;
377
+ defaultValue: unknown | null;
378
+ currentValue: unknown | null;
379
+ schema: TObject | null;
380
+ }>;
381
+ /**
382
+ * Get all unique config names (for tree view).
383
+ */
384
+ getConfigNames(): Promise<string[]>;
385
+ /**
386
+ * Build a tree structure from config names for UI.
387
+ * Includes both database configs and registered (but not yet saved) configs.
388
+ */
389
+ getConfigTree(): Promise<ConfigTreeNode[]>;
390
+ /**
391
+ * Check and activate scheduled configs that are due.
392
+ * Should be called periodically (e.g., via scheduler).
393
+ */
394
+ activateScheduledConfigs(): Promise<void>;
395
+ /**
396
+ * Transition config statuses when a new current is activated.
397
+ */
398
+ protected transitionStatuses(name: string, now: Date): Promise<void>;
399
+ /**
400
+ * Recalculate statuses based on activation dates.
401
+ */
402
+ protected recalculateStatuses(name: string): Promise<void>;
403
+ /**
404
+ * Publish sync event to other instances.
405
+ */
406
+ protected publishSync(name: string, version: number, content: unknown, status: ParameterStatus): Promise<void>;
407
+ /**
408
+ * Handle incoming sync message from other instances.
409
+ */
410
+ protected handleSyncMessage(payload: ConfigSyncPayload): Promise<void>;
411
+ /**
412
+ * Build tree structure from dot-notation names.
413
+ */
414
+ protected buildTree(names: string[]): ConfigTreeNode[];
415
+ }
416
+ interface SaveConfigOptions {
417
+ activationDate?: Date;
418
+ changeDescription?: string;
419
+ tags?: string[];
420
+ creatorId?: string;
421
+ creatorName?: string;
422
+ }
423
+ interface ConfigTreeNode {
424
+ name: string;
425
+ path: string;
426
+ isLeaf: boolean;
427
+ children: ConfigTreeNode[];
428
+ }
429
+ //#endregion
430
+ //#region ../../src/api-parameters/controllers/ConfigController.d.ts
431
+ /**
432
+ * REST API controller for versioned configuration management.
433
+ *
434
+ * Provides endpoints for:
435
+ * - Listing all configurations (tree view support)
436
+ * - Getting configuration history (all versions)
437
+ * - Getting current/next configuration values
438
+ * - Creating new configuration versions (immediate or scheduled)
439
+ * - Rolling back to previous versions
440
+ * - Activating scheduled versions immediately
441
+ */
442
+ declare class ConfigController {
443
+ protected readonly store: ConfigStore;
444
+ /**
445
+ * Get tree structure of all configuration names.
446
+ * Useful for admin UI navigation.
447
+ */
448
+ getConfigTree: alepha_server0.ActionPrimitiveFn<{
449
+ response: alepha317.TArray<any>;
450
+ }>;
451
+ /**
452
+ * List all unique configuration names.
453
+ */
454
+ listConfigNames: alepha_server0.ActionPrimitiveFn<{
455
+ response: alepha317.TObject<{
456
+ names: alepha317.TArray<alepha317.TString>;
457
+ }>;
458
+ }>;
459
+ /**
460
+ * Get configurations by status.
461
+ */
462
+ getByStatus: alepha_server0.ActionPrimitiveFn<{
463
+ params: alepha317.TObject<{
464
+ status: alepha317.TUnsafe<"expired" | "current" | "next" | "future">;
465
+ }>;
466
+ response: alepha317.TObject<{
467
+ configs: alepha317.TArray<alepha317.TObject<{
468
+ id: alepha317.TString;
469
+ createdAt: alepha317.TString;
470
+ updatedAt: alepha317.TString;
471
+ name: alepha317.TString;
472
+ content: alepha317.TRecord<string, alepha317.TAny>;
473
+ schemaHash: alepha317.TString;
474
+ status: alepha317.TUnsafe<"expired" | "current" | "next" | "future">;
475
+ activationDate: alepha317.TString;
476
+ expiredAt: alepha317.TOptional<alepha317.TString>;
477
+ version: alepha317.TInteger;
478
+ changeDescription: alepha317.TOptional<alepha317.TString>;
479
+ tags: alepha317.TOptional<alepha317.TArray<alepha317.TString>>;
480
+ creatorId: alepha317.TOptional<alepha317.TString>;
481
+ creatorName: alepha317.TOptional<alepha317.TString>;
482
+ previousContent: alepha317.TOptional<alepha317.TRecord<string, alepha317.TAny>>;
483
+ migrationLog: alepha317.TOptional<alepha317.TString>;
484
+ }>>;
485
+ }>;
486
+ }>;
487
+ /**
488
+ * Get version history for a specific configuration.
489
+ */
490
+ getHistory: alepha_server0.ActionPrimitiveFn<{
491
+ params: alepha317.TObject<{
492
+ name: alepha317.TString;
493
+ }>;
494
+ response: alepha317.TObject<{
495
+ versions: alepha317.TArray<alepha317.TObject<{
496
+ id: alepha317.TString;
497
+ createdAt: alepha317.TString;
498
+ updatedAt: alepha317.TString;
499
+ name: alepha317.TString;
500
+ content: alepha317.TRecord<string, alepha317.TAny>;
501
+ schemaHash: alepha317.TString;
502
+ status: alepha317.TUnsafe<"expired" | "current" | "next" | "future">;
503
+ activationDate: alepha317.TString;
504
+ expiredAt: alepha317.TOptional<alepha317.TString>;
505
+ version: alepha317.TInteger;
506
+ changeDescription: alepha317.TOptional<alepha317.TString>;
507
+ tags: alepha317.TOptional<alepha317.TArray<alepha317.TString>>;
508
+ creatorId: alepha317.TOptional<alepha317.TString>;
509
+ creatorName: alepha317.TOptional<alepha317.TString>;
510
+ previousContent: alepha317.TOptional<alepha317.TRecord<string, alepha317.TAny>>;
511
+ migrationLog: alepha317.TOptional<alepha317.TString>;
512
+ }>>;
513
+ }>;
514
+ }>;
515
+ /**
516
+ * Get current and next values for a configuration.
517
+ * Includes defaultValue and currentValue from the registered primitive
518
+ * even if no versions exist in the database yet.
519
+ */
520
+ getCurrent: alepha_server0.ActionPrimitiveFn<{
521
+ params: alepha317.TObject<{
522
+ name: alepha317.TString;
523
+ }>;
524
+ response: alepha317.TObject<{
525
+ current: alepha317.TOptional<alepha317.TObject<{
526
+ id: alepha317.TString;
527
+ createdAt: alepha317.TString;
528
+ updatedAt: alepha317.TString;
529
+ name: alepha317.TString;
530
+ content: alepha317.TRecord<string, alepha317.TAny>;
531
+ schemaHash: alepha317.TString;
532
+ status: alepha317.TUnsafe<"expired" | "current" | "next" | "future">;
533
+ activationDate: alepha317.TString;
534
+ expiredAt: alepha317.TOptional<alepha317.TString>;
535
+ version: alepha317.TInteger;
536
+ changeDescription: alepha317.TOptional<alepha317.TString>;
537
+ tags: alepha317.TOptional<alepha317.TArray<alepha317.TString>>;
538
+ creatorId: alepha317.TOptional<alepha317.TString>;
539
+ creatorName: alepha317.TOptional<alepha317.TString>;
540
+ previousContent: alepha317.TOptional<alepha317.TRecord<string, alepha317.TAny>>;
541
+ migrationLog: alepha317.TOptional<alepha317.TString>;
542
+ }>>;
543
+ next: alepha317.TOptional<alepha317.TObject<{
544
+ id: alepha317.TString;
545
+ createdAt: alepha317.TString;
546
+ updatedAt: alepha317.TString;
547
+ name: alepha317.TString;
548
+ content: alepha317.TRecord<string, alepha317.TAny>;
549
+ schemaHash: alepha317.TString;
550
+ status: alepha317.TUnsafe<"expired" | "current" | "next" | "future">;
551
+ activationDate: alepha317.TString;
552
+ expiredAt: alepha317.TOptional<alepha317.TString>;
553
+ version: alepha317.TInteger;
554
+ changeDescription: alepha317.TOptional<alepha317.TString>;
555
+ tags: alepha317.TOptional<alepha317.TArray<alepha317.TString>>;
556
+ creatorId: alepha317.TOptional<alepha317.TString>;
557
+ creatorName: alepha317.TOptional<alepha317.TString>;
558
+ previousContent: alepha317.TOptional<alepha317.TRecord<string, alepha317.TAny>>;
559
+ migrationLog: alepha317.TOptional<alepha317.TString>;
560
+ }>>;
561
+ defaultValue: alepha317.TOptional<alepha317.TRecord<string, alepha317.TAny>>;
562
+ currentValue: alepha317.TOptional<alepha317.TRecord<string, alepha317.TAny>>;
563
+ schema: alepha317.TOptional<alepha317.TRecord<string, alepha317.TAny>>;
564
+ }>;
565
+ }>;
566
+ /**
567
+ * Get a specific version of a configuration.
568
+ */
569
+ getVersion: alepha_server0.ActionPrimitiveFn<{
570
+ params: alepha317.TObject<{
571
+ name: alepha317.TString;
572
+ version: alepha317.TInteger;
573
+ }>;
574
+ response: alepha317.TObject<{
575
+ config: alepha317.TOptional<alepha317.TObject<{
576
+ id: alepha317.TString;
577
+ createdAt: alepha317.TString;
578
+ updatedAt: alepha317.TString;
579
+ name: alepha317.TString;
580
+ content: alepha317.TRecord<string, alepha317.TAny>;
581
+ schemaHash: alepha317.TString;
582
+ status: alepha317.TUnsafe<"expired" | "current" | "next" | "future">;
583
+ activationDate: alepha317.TString;
584
+ expiredAt: alepha317.TOptional<alepha317.TString>;
585
+ version: alepha317.TInteger;
586
+ changeDescription: alepha317.TOptional<alepha317.TString>;
587
+ tags: alepha317.TOptional<alepha317.TArray<alepha317.TString>>;
588
+ creatorId: alepha317.TOptional<alepha317.TString>;
589
+ creatorName: alepha317.TOptional<alepha317.TString>;
590
+ previousContent: alepha317.TOptional<alepha317.TRecord<string, alepha317.TAny>>;
591
+ migrationLog: alepha317.TOptional<alepha317.TString>;
592
+ }>>;
593
+ }>;
594
+ }>;
595
+ /**
596
+ * Create a new configuration version.
597
+ */
598
+ createVersion: alepha_server0.ActionPrimitiveFn<{
599
+ params: alepha317.TObject<{
600
+ name: alepha317.TString;
601
+ }>;
602
+ body: alepha317.TObject<{
603
+ content: alepha317.TRecord<string, alepha317.TAny>;
604
+ schemaHash: alepha317.TString;
605
+ activationDate: alepha317.TOptional<alepha317.TString>;
606
+ changeDescription: alepha317.TOptional<alepha317.TString>;
607
+ tags: alepha317.TOptional<alepha317.TArray<alepha317.TString>>;
608
+ creatorId: alepha317.TOptional<alepha317.TString>;
609
+ creatorName: alepha317.TOptional<alepha317.TString>;
610
+ }>;
611
+ response: alepha317.TObject<{
612
+ id: alepha317.TString;
613
+ createdAt: alepha317.TString;
614
+ updatedAt: alepha317.TString;
615
+ name: alepha317.TString;
616
+ content: alepha317.TRecord<string, alepha317.TAny>;
617
+ schemaHash: alepha317.TString;
618
+ status: alepha317.TUnsafe<"expired" | "current" | "next" | "future">;
619
+ activationDate: alepha317.TString;
620
+ expiredAt: alepha317.TOptional<alepha317.TString>;
621
+ version: alepha317.TInteger;
622
+ changeDescription: alepha317.TOptional<alepha317.TString>;
623
+ tags: alepha317.TOptional<alepha317.TArray<alepha317.TString>>;
624
+ creatorId: alepha317.TOptional<alepha317.TString>;
625
+ creatorName: alepha317.TOptional<alepha317.TString>;
626
+ previousContent: alepha317.TOptional<alepha317.TRecord<string, alepha317.TAny>>;
627
+ migrationLog: alepha317.TOptional<alepha317.TString>;
628
+ }>;
629
+ }>;
630
+ /**
631
+ * Rollback to a previous version.
632
+ */
633
+ rollback: alepha_server0.ActionPrimitiveFn<{
634
+ params: alepha317.TObject<{
635
+ name: alepha317.TString;
636
+ }>;
637
+ body: alepha317.TObject<{
638
+ targetVersion: alepha317.TInteger;
639
+ changeDescription: alepha317.TOptional<alepha317.TString>;
640
+ creatorId: alepha317.TOptional<alepha317.TString>;
641
+ creatorName: alepha317.TOptional<alepha317.TString>;
642
+ }>;
643
+ response: alepha317.TObject<{
644
+ id: alepha317.TString;
645
+ createdAt: alepha317.TString;
646
+ updatedAt: alepha317.TString;
647
+ name: alepha317.TString;
648
+ content: alepha317.TRecord<string, alepha317.TAny>;
649
+ schemaHash: alepha317.TString;
650
+ status: alepha317.TUnsafe<"expired" | "current" | "next" | "future">;
651
+ activationDate: alepha317.TString;
652
+ expiredAt: alepha317.TOptional<alepha317.TString>;
653
+ version: alepha317.TInteger;
654
+ changeDescription: alepha317.TOptional<alepha317.TString>;
655
+ tags: alepha317.TOptional<alepha317.TArray<alepha317.TString>>;
656
+ creatorId: alepha317.TOptional<alepha317.TString>;
657
+ creatorName: alepha317.TOptional<alepha317.TString>;
658
+ previousContent: alepha317.TOptional<alepha317.TRecord<string, alepha317.TAny>>;
659
+ migrationLog: alepha317.TOptional<alepha317.TString>;
660
+ }>;
661
+ }>;
662
+ /**
663
+ * Activate a scheduled version immediately.
664
+ */
665
+ activateNow: alepha_server0.ActionPrimitiveFn<{
666
+ params: alepha317.TObject<{
667
+ name: alepha317.TString;
668
+ }>;
669
+ body: alepha317.TObject<{
670
+ version: alepha317.TInteger;
671
+ creatorId: alepha317.TOptional<alepha317.TString>;
672
+ creatorName: alepha317.TOptional<alepha317.TString>;
673
+ }>;
674
+ response: alepha317.TObject<{
675
+ id: alepha317.TString;
676
+ createdAt: alepha317.TString;
677
+ updatedAt: alepha317.TString;
678
+ name: alepha317.TString;
679
+ content: alepha317.TRecord<string, alepha317.TAny>;
680
+ schemaHash: alepha317.TString;
681
+ status: alepha317.TUnsafe<"expired" | "current" | "next" | "future">;
682
+ activationDate: alepha317.TString;
683
+ expiredAt: alepha317.TOptional<alepha317.TString>;
684
+ version: alepha317.TInteger;
685
+ changeDescription: alepha317.TOptional<alepha317.TString>;
686
+ tags: alepha317.TOptional<alepha317.TArray<alepha317.TString>>;
687
+ creatorId: alepha317.TOptional<alepha317.TString>;
688
+ creatorName: alepha317.TOptional<alepha317.TString>;
689
+ previousContent: alepha317.TOptional<alepha317.TRecord<string, alepha317.TAny>>;
690
+ migrationLog: alepha317.TOptional<alepha317.TString>;
691
+ }>;
692
+ }>;
693
+ /**
694
+ * Trigger activation check for all scheduled configs.
695
+ * Normally called by a scheduler, but exposed for manual triggering.
696
+ */
697
+ checkScheduled: alepha_server0.ActionPrimitiveFn<{
698
+ response: alepha317.TObject<{
699
+ message: alepha317.TString;
700
+ }>;
701
+ }>;
702
+ }
703
+ //#endregion
704
+ //#region ../../src/api-parameters/schedulers/ConfigActivationScheduler.d.ts
705
+ /**
706
+ * Scheduler that periodically checks for scheduled configurations
707
+ * that should be activated.
708
+ *
709
+ * Runs every minute to check if any NEXT configurations have reached
710
+ * their activation date and need to be promoted to CURRENT.
711
+ */
712
+ declare class ConfigActivationScheduler {
713
+ protected readonly log: alepha_logger1.Logger;
714
+ protected readonly store: ConfigStore;
715
+ /**
716
+ * Check for scheduled configurations every minute.
717
+ */
718
+ checkActivations: alepha_scheduler0.SchedulerPrimitive;
68
719
  }
69
- declare const $config: <T extends TObject>(options: ConfigPrimitiveOptions<T>) => ConfigPrimitive<T>;
70
720
  //#endregion
71
721
  //#region ../../src/api-parameters/index.d.ts
72
722
  /**
73
- * Provides parameter management API endpoints for Alepha applications.
723
+ * Provides versioned configuration management for Alepha applications.
724
+ *
725
+ * Features:
726
+ * - Type-safe, versioned configuration with `$config` primitive
727
+ * - Schema validation with auto-migration detection
728
+ * - Scheduled activation (FUTURE, NEXT, CURRENT, EXPIRED statuses)
729
+ * - PostgreSQL persistence with full version history
730
+ * - Cross-instance synchronization via topic
731
+ * - Tree view support via dot-notation naming
732
+ * - REST API for configuration management
733
+ * - Automatic activation scheduler
734
+ *
735
+ * @example
736
+ * ```ts
737
+ * import { Alepha } from "alepha";
738
+ * import { AlephaApiParameters } from "alepha/api-parameters";
739
+ *
740
+ * const alepha = Alepha.create();
741
+ * alepha.with(AlephaApiParameters);
74
742
  *
75
- * This module includes configuration parameter storage, retrieval,
76
- * and dynamic application settings management.
743
+ * // Then use $config in your services:
744
+ * class AppConfig {
745
+ * features = $config({
746
+ * name: "app.features.flags",
747
+ * schema: t.object({
748
+ * enableBeta: t.boolean(),
749
+ * maxUploadSize: t.number()
750
+ * }),
751
+ * default: { enableBeta: false, maxUploadSize: 10485760 }
752
+ * });
753
+ * }
754
+ * ```
77
755
  *
78
756
  * @module alepha.api.parameters
79
757
  */
80
- declare const AlephaApiParameters: alepha1.Service<alepha1.Module>;
758
+ declare const AlephaApiParameters: alepha317.Service<alepha317.Module>;
81
759
  //#endregion
82
- export { $config, AlephaApiParameters, ConfigPrimitive, ConfigPrimitiveOptions, ParameterEntity, parameters };
760
+ export { $config, AlephaApiParameters, ConfigActivationScheduler, ConfigController, ConfigPrimitive, ConfigPrimitiveOptions, ConfigStore, ConfigSyncPayload, ConfigTreeNode, Parameter, ParameterInsert, ParameterStatus, SaveConfigOptions, SetConfigOptions, parameters };
83
761
  //# sourceMappingURL=index.d.ts.map