@alepha/react 0.12.1 → 0.13.1

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 (44) hide show
  1. package/dist/auth/index.browser.js +4 -1642
  2. package/dist/auth/index.browser.js.map +1 -1
  3. package/dist/auth/index.d.ts +1 -1
  4. package/dist/auth/index.js +4 -1642
  5. package/dist/auth/index.js.map +1 -1
  6. package/dist/core/index.d.ts +83 -83
  7. package/dist/form/index.d.ts +1 -1
  8. package/dist/form/index.js +3 -1642
  9. package/dist/form/index.js.map +1 -1
  10. package/dist/head/index.browser.js +3 -1654
  11. package/dist/head/index.browser.js.map +1 -1
  12. package/dist/head/index.d.ts +149 -885
  13. package/dist/head/index.js +4 -1654
  14. package/dist/head/index.js.map +1 -1
  15. package/dist/i18n/index.js +3 -1653
  16. package/dist/i18n/index.js.map +1 -1
  17. package/dist/websocket/index.d.ts +159 -3
  18. package/dist/websocket/index.js +2 -1654
  19. package/dist/websocket/index.js.map +1 -1
  20. package/package.json +9 -15
  21. package/dist/auth/chunk-DhGyd7sr.js +0 -28
  22. package/dist/auth/index.cjs +0 -1800
  23. package/dist/auth/index.cjs.map +0 -1
  24. package/dist/auth/index.d.cts +0 -1274
  25. package/dist/core/chunk-DhGyd7sr.js +0 -28
  26. package/dist/core/index.cjs +0 -2087
  27. package/dist/core/index.cjs.map +0 -1
  28. package/dist/core/index.d.cts +0 -2763
  29. package/dist/form/chunk-DhGyd7sr.js +0 -28
  30. package/dist/form/index.cjs +0 -2074
  31. package/dist/form/index.cjs.map +0 -1
  32. package/dist/form/index.d.cts +0 -419
  33. package/dist/head/chunk-DhGyd7sr.js +0 -28
  34. package/dist/head/index.cjs +0 -1912
  35. package/dist/head/index.cjs.map +0 -1
  36. package/dist/head/index.d.cts +0 -1801
  37. package/dist/i18n/chunk-DhGyd7sr.js +0 -28
  38. package/dist/i18n/index.cjs +0 -1899
  39. package/dist/i18n/index.cjs.map +0 -1
  40. package/dist/i18n/index.d.cts +0 -437
  41. package/dist/websocket/index.cjs +0 -1787
  42. package/dist/websocket/index.cjs.map +0 -1
  43. package/dist/websocket/index.d.cts +0 -118
  44. package/src/i18n/README.md +0 -76
@@ -1,419 +0,0 @@
1
- import * as alepha8 from "alepha";
2
- import { Alepha, LogLevel, LoggerInterface, Static, TObject, TSchema, TypeBoxError } from "alepha";
3
- import { InputHTMLAttributes, ReactNode } from "react";
4
- import dayjsDuration from "dayjs/plugin/duration.js";
5
- import DayjsApi, { Dayjs, ManipulateType, PluginFunc } from "dayjs";
6
-
7
- //#region ../alepha/src/logger/schemas/logEntrySchema.d.ts
8
- declare const logEntrySchema: alepha8.TObject<{
9
- level: alepha8.TUnsafe<"SILENT" | "TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR">;
10
- message: alepha8.TString;
11
- service: alepha8.TString;
12
- module: alepha8.TString;
13
- context: alepha8.TOptional<alepha8.TString>;
14
- app: alepha8.TOptional<alepha8.TString>;
15
- data: alepha8.TOptional<alepha8.TAny>;
16
- timestamp: alepha8.TNumber;
17
- }>;
18
- type LogEntry = Static<typeof logEntrySchema>;
19
- //#endregion
20
- //#region ../alepha/src/datetime/providers/DateTimeProvider.d.ts
21
- type DateTime = DayjsApi.Dayjs;
22
- type Duration = dayjsDuration.Duration;
23
- type DurationLike = number | dayjsDuration.Duration | [number, ManipulateType];
24
- declare class DateTimeProvider {
25
- static PLUGINS: Array<PluginFunc<any>>;
26
- protected alepha: Alepha;
27
- protected ref: DateTime | null;
28
- protected readonly timeouts: Timeout[];
29
- protected readonly intervals: Interval[];
30
- constructor();
31
- protected readonly onStart: alepha8.HookDescriptor<"start">;
32
- protected readonly onStop: alepha8.HookDescriptor<"stop">;
33
- setLocale(locale: string): void;
34
- isDateTime(value: unknown): value is DateTime;
35
- /**
36
- * Create a new UTC DateTime instance.
37
- */
38
- utc(date: string | number | Date | Dayjs | null | undefined): DateTime;
39
- /**
40
- * Create a new DateTime instance.
41
- */
42
- of(date: string | number | Date | Dayjs | null | undefined): DateTime;
43
- /**
44
- * Get the current date as a string.
45
- */
46
- toISOString(date?: Date | string | DateTime): string;
47
- /**
48
- * Get the current date.
49
- */
50
- now(): DateTime;
51
- /**
52
- * Get the current date as a string.
53
- *
54
- * This is much faster than `DateTimeProvider.now().toISOString()` as it avoids creating a DateTime instance.
55
- */
56
- nowISOString(): string;
57
- /**
58
- * Get the current date as milliseconds since epoch.
59
- *
60
- * This is much faster than `DateTimeProvider.now().valueOf()` as it avoids creating a DateTime instance.
61
- */
62
- nowMillis(): number;
63
- /**
64
- * Get the current date as a string.
65
- *
66
- * @protected
67
- */
68
- protected getCurrentDate(): DateTime;
69
- /**
70
- * Create a new Duration instance.
71
- */
72
- duration: (duration: DurationLike, unit?: ManipulateType) => Duration;
73
- isDurationLike(value: unknown): value is DurationLike;
74
- /**
75
- * Return a promise that resolves after the next tick.
76
- * It uses `setTimeout` with 0 ms delay.
77
- */
78
- tick(): Promise<void>;
79
- /**
80
- * Wait for a certain duration.
81
- *
82
- * You can clear the timeout by using the `AbortSignal` API.
83
- * Aborted signal will resolve the promise immediately, it does not reject it.
84
- */
85
- wait(duration: DurationLike, options?: {
86
- signal?: AbortSignal;
87
- now?: number;
88
- }): Promise<void>;
89
- createInterval(run: () => unknown, duration: DurationLike, start?: boolean): Interval;
90
- /**
91
- * Run a callback after a certain duration.
92
- */
93
- createTimeout(callback: () => void, duration: DurationLike, now?: number): Timeout;
94
- clearTimeout(timeout: Timeout): void;
95
- clearInterval(interval: Interval): void;
96
- /**
97
- * Run a function with a deadline.
98
- */
99
- deadline<T>(fn: (signal: AbortSignal) => Promise<T>, duration: DurationLike): Promise<T>;
100
- /**
101
- * Add time to the current date.
102
- */
103
- travel(duration: DurationLike, unit?: ManipulateType): Promise<void>;
104
- /**
105
- * Stop the time.
106
- */
107
- pause(): DateTime;
108
- /**
109
- * Reset the reference date.
110
- */
111
- reset(): void;
112
- }
113
- interface Interval {
114
- timer?: any;
115
- duration: number;
116
- run: () => unknown;
117
- }
118
- interface Timeout {
119
- now: number;
120
- timer?: any;
121
- duration: number;
122
- callback: () => void;
123
- clear: () => void;
124
- }
125
- //#endregion
126
- //#region ../alepha/src/logger/providers/LogDestinationProvider.d.ts
127
- declare abstract class LogDestinationProvider {
128
- abstract write(message: string, entry: LogEntry): void;
129
- }
130
- //#endregion
131
- //#region ../alepha/src/logger/providers/LogFormatterProvider.d.ts
132
- declare abstract class LogFormatterProvider {
133
- abstract format(entry: LogEntry): string;
134
- }
135
- //#endregion
136
- //#region ../alepha/src/logger/services/Logger.d.ts
137
- declare class Logger implements LoggerInterface {
138
- protected readonly alepha: Alepha;
139
- protected readonly formatter: LogFormatterProvider;
140
- protected readonly destination: LogDestinationProvider;
141
- protected readonly dateTimeProvider: DateTimeProvider;
142
- protected readonly levels: Record<string, number>;
143
- protected readonly service: string;
144
- protected readonly module: string;
145
- protected readonly app?: string;
146
- protected appLogLevel: string;
147
- protected logLevel: LogLevel;
148
- constructor(service: string, module: string);
149
- get context(): string | undefined;
150
- get level(): string;
151
- parseLevel(level: string, app: string): LogLevel;
152
- private matchesPattern;
153
- asLogLevel(something: string): LogLevel;
154
- error(message: string, data?: unknown): void;
155
- warn(message: string, data?: unknown): void;
156
- info(message: string, data?: unknown): void;
157
- debug(message: string, data?: unknown): void;
158
- trace(message: string, data?: unknown): void;
159
- protected log(level: LogLevel, message: string, data?: unknown): void;
160
- protected emit(entry: LogEntry, message?: string): void;
161
- }
162
- //#endregion
163
- //#region ../alepha/src/logger/index.d.ts
164
- declare const envSchema: alepha8.TObject<{
165
- /**
166
- * Default log level for the application.
167
- *
168
- * Default by environment:
169
- * - dev = info
170
- * - prod = info
171
- * - test = error
172
- *
173
- * Levels are: "trace" | "debug" | "info" | "warn" | "error" | "silent"
174
- *
175
- * Level can be set for a specific module:
176
- *
177
- * @example
178
- * LOG_LEVEL=my.module.name:debug,info # Set debug level for my.module.name and info for all other modules
179
- * LOG_LEVEL=alepha:trace, info # Set trace level for all alepha modules and info for all other modules
180
- */
181
- LOG_LEVEL: alepha8.TOptional<alepha8.TString>;
182
- /**
183
- * Built-in log formats.
184
- * - "json" - JSON format, useful for structured logging and log aggregation. {@link JsonFormatterProvider}
185
- * - "pretty" - Simple text format, human-readable, with colors. {@link SimpleFormatterProvider}
186
- * - "raw" - Raw format, no formatting, just the message. {@link RawFormatterProvider}
187
- */
188
- LOG_FORMAT: alepha8.TOptional<alepha8.TUnsafe<"json" | "pretty" | "raw">>;
189
- }>;
190
- declare module "alepha" {
191
- interface Env extends Partial<Static<typeof envSchema>> {}
192
- interface State {
193
- /**
194
- * Current log level for the application or specific modules.
195
- */
196
- "alepha.logger.level"?: string;
197
- }
198
- interface Hooks {
199
- log: {
200
- message?: string;
201
- entry: LogEntry;
202
- };
203
- }
204
- }
205
- //#endregion
206
- //#region src/form/services/FormModel.d.ts
207
- /**
208
- * FormModel is a dynamic form handler that generates form inputs based on a provided TypeBox schema.
209
- * It manages form state, handles input changes, and processes form submissions with validation.
210
- *
211
- * It means to be injected and used within React components to provide a structured way to create and manage forms.
212
- *
213
- * @see {@link useForm}
214
- */
215
- declare class FormModel<T extends TObject> {
216
- readonly id: string;
217
- readonly options: FormCtrlOptions<T>;
218
- protected readonly log: Logger;
219
- protected readonly alepha: Alepha;
220
- protected readonly values: Record<string, any>;
221
- protected submitInProgress: boolean;
222
- input: SchemaToInput<T>;
223
- get submitting(): boolean;
224
- constructor(id: string, options: FormCtrlOptions<T>);
225
- get element(): HTMLFormElement;
226
- get currentValues(): Record<string, any>;
227
- get props(): {
228
- id: string;
229
- noValidate: boolean;
230
- onSubmit: (ev?: FormEventLike) => void;
231
- onReset: (event: FormEventLike) => Promise<void>;
232
- };
233
- readonly reset: (event: FormEventLike) => Promise<void>;
234
- readonly submit: () => Promise<void>;
235
- /**
236
- * Restructures flat keys like "address.city" into nested objects like { address: { city: ... } }
237
- * Values are already typed from onChange, so no conversion is needed.
238
- */
239
- protected restructureValues(store: Record<string, any>): Record<string, any>;
240
- /**
241
- * Helper to restructure a flat key like "address.city" into nested object structure.
242
- * The value is already typed, so we just assign it to the nested path.
243
- */
244
- protected restructureNestedValue(values: Record<string, any>, key: string, value: any): void;
245
- protected createProxyFromSchema<T extends TObject>(options: FormCtrlOptions<T>, schema: TSchema, context: {
246
- parent: string;
247
- store: Record<string, any>;
248
- }): SchemaToInput<T>;
249
- protected createInputFromSchema<T extends TObject>(name: keyof Static<T> & string, options: FormCtrlOptions<T>, schema: TObject, required: boolean, context: {
250
- parent: string;
251
- store: Record<string, any>;
252
- }): InputField;
253
- /**
254
- * Convert an input value to the correct type based on the schema.
255
- * Handles raw DOM values (strings, booleans from checkboxes, Files, etc.)
256
- */
257
- protected getValueFromInput(input: any, schema: TSchema): any;
258
- protected valueToInputEntry(value: any): string | number | boolean;
259
- }
260
- type SchemaToInput<T extends TObject> = { [K in keyof T["properties"]]: T["properties"][K] extends TObject ? SchemaToInput<T["properties"][K]> : InputField };
261
- interface FormEventLike {
262
- preventDefault?: () => void;
263
- stopPropagation?: () => void;
264
- }
265
- interface InputField {
266
- path: string;
267
- required: boolean;
268
- props: InputHTMLAttributesLike;
269
- schema: TSchema;
270
- set: (value: any) => void;
271
- form: FormModel<any>;
272
- }
273
- type InputHTMLAttributesLike = Pick<InputHTMLAttributes<unknown>, "id" | "name" | "type" | "value" | "defaultValue" | "required" | "maxLength" | "minLength" | "aria-label" | "autoComplete"> & {
274
- value?: any;
275
- defaultValue?: any;
276
- onChange?: (event: any) => void;
277
- };
278
- type FormCtrlOptions<T extends TObject> = {
279
- /**
280
- * The schema defining the structure and validation rules for the form.
281
- * This should be a TypeBox schema object.
282
- */
283
- schema: T;
284
- /**
285
- * Callback function to handle form submission.
286
- * This function will receive the parsed and validated form values.
287
- */
288
- handler: (values: Static<T>, args: {
289
- form: HTMLFormElement;
290
- }) => unknown;
291
- /**
292
- * Optional initial values for the form fields.
293
- * This can be used to pre-populate the form with existing data.
294
- */
295
- initialValues?: Partial<Static<T>>;
296
- /**
297
- * Optional function to create custom field attributes.
298
- * This can be used to add custom validation, styles, or other attributes.
299
- */
300
- onCreateField?: (name: keyof Static<T> & string, schema: TSchema) => InputHTMLAttributes<unknown>;
301
- /**
302
- * If defined, this will generate a unique ID for each field, prefixed with this string.
303
- *
304
- * > "username" with id="form-123" will become "form-123-username".
305
- *
306
- * If omitted, IDs will not be generated.
307
- */
308
- id?: string;
309
- onError?: (error: Error, args: {
310
- form: HTMLFormElement;
311
- }) => void;
312
- onChange?: (key: string, value: any, store: Record<string, any>) => void;
313
- onReset?: () => void;
314
- };
315
- //#endregion
316
- //#region src/form/components/FormState.d.ts
317
- declare const FormState: <T extends TObject>(props: {
318
- form: FormModel<T>;
319
- children: (state: {
320
- loading: boolean;
321
- dirty: boolean;
322
- }) => ReactNode;
323
- }) => ReactNode;
324
- //#endregion
325
- //#region src/form/hooks/useForm.d.ts
326
- /**
327
- * Custom hook to create a form with validation and field management.
328
- * This hook uses TypeBox schemas to define the structure and validation rules for the form.
329
- * It provides a way to handle form submission, field creation, and value management.
330
- *
331
- * @example
332
- * ```tsx
333
- * import { t } from "alepha";
334
- *
335
- * const form = useForm({
336
- * schema: t.object({
337
- * username: t.text(),
338
- * password: t.text(),
339
- * }),
340
- * handler: (values) => {
341
- * console.log("Form submitted with values:", values);
342
- * },
343
- * });
344
- *
345
- * return (
346
- * <form {...form.props}>
347
- * <input {...form.input.username.props} />
348
- * <input {...form.input.password.props} />
349
- * <button type="submit">Submit</button>
350
- * </form>
351
- * );
352
- * ```
353
- */
354
- declare const useForm: <T extends TObject>(options: FormCtrlOptions<T>, deps?: any[]) => FormModel<T>;
355
- //#endregion
356
- //#region src/form/hooks/useFormState.d.ts
357
- interface UseFormStateReturn {
358
- loading: boolean;
359
- dirty: boolean;
360
- values?: Record<string, any>;
361
- error?: Error;
362
- }
363
- declare const useFormState: <T extends TObject, Keys extends keyof UseFormStateReturn>(target: FormModel<T> | {
364
- form: FormModel<T>;
365
- path: string;
366
- }, _events?: Keys[]) => Pick<UseFormStateReturn, Keys>;
367
- //#endregion
368
- //#region src/form/errors/FormValidationError.d.ts
369
- declare class FormValidationError extends TypeBoxError {
370
- readonly name = "ValidationError";
371
- constructor(options: {
372
- message: string;
373
- path: string;
374
- });
375
- }
376
- //#endregion
377
- //#region src/form/index.d.ts
378
- declare module "alepha" {
379
- interface Hooks {
380
- "form:change": {
381
- id: string;
382
- path: string;
383
- value: any;
384
- };
385
- "form:reset": {
386
- id: string;
387
- values: Record<string, any>;
388
- };
389
- "form:submit:begin": {
390
- id: string;
391
- };
392
- "form:submit:success": {
393
- id: string;
394
- values: Record<string, any>;
395
- };
396
- "form:submit:error": {
397
- id: string;
398
- error: Error;
399
- };
400
- "form:submit:end": {
401
- id: string;
402
- };
403
- }
404
- }
405
- /**
406
- * React hooks for managing forms in Alepha applications.
407
- *
408
- * This module provides a set of hooks to simplify form handling, validation, and submission in React applications built with Alepha.
409
- *
410
- * It includes:
411
- * - `useForm`: A hook for managing form state, validation, and submission.
412
- *
413
- * @see {@link useForm}
414
- * @module alepha.react.form
415
- */
416
- declare const AlephaReactForm: alepha8.Service<alepha8.Module>;
417
- //#endregion
418
- export { AlephaReactForm, FormCtrlOptions, FormEventLike, FormModel, FormState, FormValidationError, InputField, InputHTMLAttributesLike, SchemaToInput, UseFormStateReturn, useForm, useFormState };
419
- //# sourceMappingURL=index.d.cts.map
@@ -1,28 +0,0 @@
1
- //#region rolldown:runtime
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from === "object" || typeof from === "function") {
10
- for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
- key = keys[i];
12
- if (!__hasOwnProp.call(to, key) && key !== except) {
13
- __defProp(to, key, {
14
- get: ((k) => from[k]).bind(null, key),
15
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
- });
17
- }
18
- }
19
- }
20
- return to;
21
- };
22
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
- value: mod,
24
- enumerable: true
25
- }) : target, mod));
26
-
27
- //#endregion
28
- export { };