@golemui/core 0.0.2

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 (51) hide show
  1. package/CHANGELOG.md +517 -0
  2. package/README.md +11 -0
  3. package/index.d.ts +18 -0
  4. package/index.js +1598 -0
  5. package/index.umd.cjs +8 -0
  6. package/lib/context/form.context.d.ts +21 -0
  7. package/lib/context/index.d.ts +3 -0
  8. package/lib/context/widget-registry.d.ts +13 -0
  9. package/lib/context/with-widget.type.d.ts +4 -0
  10. package/lib/form-store.d.ts +12 -0
  11. package/lib/form-validator.d.ts +10 -0
  12. package/lib/form-widget.d.ts +93 -0
  13. package/lib/form.d.ts +22 -0
  14. package/lib/i18n.d.ts +87 -0
  15. package/lib/item-renderer.d.ts +24 -0
  16. package/lib/middleware/index.d.ts +2 -0
  17. package/lib/middleware/json-schema/json-schema.d.ts +67 -0
  18. package/lib/middleware/json-schema/json-schema.middleware.d.ts +19 -0
  19. package/lib/shared.d.ts +143 -0
  20. package/lib/store/actions.d.ts +121 -0
  21. package/lib/store/model.d.ts +107 -0
  22. package/lib/store/reducer.d.ts +10 -0
  23. package/lib/store/reducers/add-widget.d.ts +3 -0
  24. package/lib/store/reducers/calculate-current-state.d.ts +2 -0
  25. package/lib/store/reducers/calculate-widget-flags.d.ts +2 -0
  26. package/lib/store/reducers/calculate-widget-props.d.ts +3 -0
  27. package/lib/store/reducers/index.d.ts +13 -0
  28. package/lib/store/reducers/initialize.d.ts +3 -0
  29. package/lib/store/reducers/inject-validation-issues.d.ts +3 -0
  30. package/lib/store/reducers/override-widget-prop.d.ts +3 -0
  31. package/lib/store/reducers/remove-widget.d.ts +3 -0
  32. package/lib/store/reducers/set-data.d.ts +3 -0
  33. package/lib/store/reducers/set-form-health.d.ts +8 -0
  34. package/lib/store/reducers/set-language.d.ts +3 -0
  35. package/lib/store/reducers/set-widget-data.d.ts +3 -0
  36. package/lib/store/reducers/utils.d.ts +32 -0
  37. package/lib/store/reducers/validate-all.d.ts +3 -0
  38. package/lib/store/selectors.d.ts +21 -0
  39. package/lib/utils/array.d.ts +61 -0
  40. package/lib/utils/assert-never.d.ts +5 -0
  41. package/lib/utils/debug.d.ts +3 -0
  42. package/lib/utils/decoder.d.ts +51 -0
  43. package/lib/utils/dot-path.d.ts +16 -0
  44. package/lib/utils/form.d.ts +20 -0
  45. package/lib/utils/function.d.ts +71 -0
  46. package/lib/utils/object.d.ts +140 -0
  47. package/lib/utils/random.d.ts +1 -0
  48. package/lib/utils/repeater.d.ts +2 -0
  49. package/lib/utils/suffixable.d.ts +16 -0
  50. package/lib/utils/types.d.ts +63 -0
  51. package/package.json +30 -0
@@ -0,0 +1,140 @@
1
+ import { DotPath } from '../shared';
2
+ /**
3
+ * Retrieves a value from a nested object using a dot-separated path.
4
+ *
5
+ * This function safely navigates through nested objects and arrays using a dot notation
6
+ * path string. It handles both object properties and array indices.
7
+ *
8
+ * @param obj - The object to retrieve the value from
9
+ * @param path - A dot-separated string path to the desired value (e.g., "user.profile.name" or "items.0.title")
10
+ * @returns The value at the specified path, or undefined if the path doesn't exist
11
+ *
12
+ * @example
13
+ * Basic object navigation:
14
+ * ```typescript
15
+ * const user = { profile: { name: "John", age: 30 } };
16
+ * get(user, "profile.name"); // Returns "John"
17
+ * get(user, "profile.age"); // Returns 30
18
+ * ```
19
+ *
20
+ * @example
21
+ * Array access with indices:
22
+ * ```typescript
23
+ * const data = { users: [{ name: "Alice" }, { name: "Bob" }] };
24
+ * get(data, "users.0.name"); // Returns "Alice"
25
+ * get(data, "users.1.name"); // Returns "Bob"
26
+ * ```
27
+ *
28
+ * @example
29
+ * Mixed object and array navigation:
30
+ * ```typescript
31
+ * const complex = {
32
+ * teams: [
33
+ * { name: "Engineering", members: [{ role: "Lead" }, { role: "Dev" }] },
34
+ * { name: "Design", members: [{ role: "Senior" }] }
35
+ * ]
36
+ * };
37
+ * get(complex, "teams.0.name"); // Returns "Engineering"
38
+ * get(complex, "teams.0.members.1.role"); // Returns "Dev"
39
+ * ```
40
+ *
41
+ * @example
42
+ * Handling non-existent paths:
43
+ * ```typescript
44
+ * const obj = { a: { b: "value" } };
45
+ * get(obj, "a.b"); // Returns "value"
46
+ * get(obj, "a.c"); // Returns undefined
47
+ * get(obj, "x.y.z"); // Returns undefined
48
+ * ```
49
+ */
50
+ export declare const get: <T = any>(obj: Record<string, any>, path: DotPath) => T;
51
+ /**
52
+ * Sets the value at path of object by mutation.
53
+ * If a portion of path doesn't exist, it's created.
54
+ * Arrays are created for missing index properties while objects are created for all other missing properties.
55
+ *
56
+ * @param object - The object to modify
57
+ * @param path - The path of the property to set (dot notation)
58
+ * @param value - The value to set
59
+ * @returns The modified object (mutates the original object)
60
+ *
61
+ * @example
62
+ * Basic property setting:
63
+ * ```typescript
64
+ * const obj = { a: 1 };
65
+ * set(obj, 'b', 2);
66
+ * // Result: { a: 1, b: 2 }
67
+ * ```
68
+ *
69
+ * @example
70
+ * Nested property creation:
71
+ * ```typescript
72
+ * const obj = {};
73
+ * set(obj, 'user.name', 'John');
74
+ * // Result: { user: { name: 'John' } }
75
+ * ```
76
+ *
77
+ * @example
78
+ * Deep nested path creation:
79
+ * ```typescript
80
+ * const obj = {};
81
+ * set(obj, 'config.api.endpoints.users', '/api/v1/users');
82
+ * // Result: { config: { api: { endpoints: { users: '/api/v1/users' } } } }
83
+ * ```
84
+ *
85
+ * @example
86
+ * Array index creation:
87
+ * ```typescript
88
+ * const obj = {};
89
+ * set(obj, 'items.0', 'first item');
90
+ * set(obj, 'items.2', 'third item');
91
+ * // Result: { items: ['first item', undefined, 'third item'] }
92
+ * ```
93
+ *
94
+ * @example
95
+ * Mixed object and array paths:
96
+ * ```typescript
97
+ * const obj = {};
98
+ * set(obj, 'users.0.name', 'Alice');
99
+ * set(obj, 'users.0.age', 25);
100
+ * set(obj, 'users.1.name', 'Bob');
101
+ * // Result: { users: [{ name: 'Alice', age: 25 }, { name: 'Bob' }] }
102
+ * ```
103
+ *
104
+ * @example
105
+ * Overwriting existing values:
106
+ * ```typescript
107
+ * const obj = { user: { name: 'John', age: 30 } };
108
+ * set(obj, 'user.name', 'Jane');
109
+ * set(obj, 'user.email', 'jane@example.com');
110
+ * // Result: { user: { name: 'Jane', age: 30, email: 'jane@example.com' } }
111
+ * ```
112
+ *
113
+ * @example
114
+ * Working with existing arrays:
115
+ * ```typescript
116
+ * const obj = { items: ['a', 'b'] };
117
+ * set(obj, 'items.5', 'f');
118
+ * // Result: { items: ['a', 'b', undefined, undefined, undefined, 'f'] }
119
+ * ```
120
+ */
121
+ export declare const set: (object: Record<string, any>, path: DotPath, value: any) => Record<string, any>;
122
+ /**
123
+ * Deletes a key from an object and returns the same mutated object.
124
+ *
125
+ * @param object - The object to remove the key from.
126
+ * @param key - The property name to delete.
127
+ * @returns The same object, with the specified key removed.
128
+ *
129
+ * @example
130
+ * ```ts
131
+ * const obj = { a: 1, b: 2, c: 3 };
132
+ * deleteKey(obj, "b");
133
+ * console.log(obj); // { a: 1, c: 3 }
134
+ * ```
135
+ */
136
+ export declare const deleteKey: (object: Record<string, any>, key: string) => Record<string, any>;
137
+ /**
138
+ * Cheap JSON.stringify-based clone object utility
139
+ */
140
+ export declare function cloneObject(obj: Record<string, any>): any;
@@ -0,0 +1 @@
1
+ export declare const shortUUID: () => string;
@@ -0,0 +1,2 @@
1
+ import { NonFunctionWidget } from '../form-widget';
2
+ export declare function makeRepeaterItemConfig(widget: NonFunctionWidget<string>, repeaterIndex: number): NonFunctionWidget<string>;
@@ -0,0 +1,16 @@
1
+ type Suffixable<T, K extends keyof T, TSuffixes extends string> = {
2
+ [P in keyof T as P extends K ? never : P]: T[P];
3
+ } & {
4
+ [P in K as P]: T[P];
5
+ } & {
6
+ [P in K as `${string & P}.${TSuffixes}`]?: T[P];
7
+ };
8
+ export type SomeSuffixable<T extends Record<string, any>, P extends Partial<keyof T>, TSuffixes extends string = string> = Suffixable<T, P, TSuffixes>;
9
+ export type AllSuffixable<T extends Record<string, any>, TSuffixes extends string> = Suffixable<T, keyof T, TSuffixes>;
10
+ /**
11
+ * Takes a type T and an exclusion set E
12
+ * @example
13
+ * type OnExceptFocus = AllSuffixableExcept<On, 'focus'>;
14
+ */
15
+ export type AllSuffixableExcept<T extends Record<string, any>, E extends keyof T, TSuffixes extends string> = Suffixable<T, Exclude<keyof T, E>, TSuffixes>;
16
+ export {};
@@ -0,0 +1,63 @@
1
+ /**
2
+ * LooseUnion<T> - Creates a string union that provides autocomplete while accepting any string.
3
+ *
4
+ * This utility type allows you to define a set of recommended string values that appear in
5
+ * IDE autocomplete, while still accepting any arbitrary string value without type errors.
6
+ * This is useful for APIs where you want to suggest common values but not restrict users.
7
+ *
8
+ * @example
9
+ * // Define common HTTP methods with autocomplete, but allow custom methods
10
+ * type HttpMethod = LooseUnion<"GET" | "POST" | "PUT" | "DELETE">;
11
+ *
12
+ * const method1: HttpMethod = "GET"; // Autocomplete suggests: GET, POST, PUT, DELETE
13
+ * const method2: HttpMethod = "PATCH"; // Also accepts any other string
14
+ *
15
+ * @example
16
+ * // CSS color names with autocomplete, but allow hex/rgb values
17
+ * type Color = LooseUnion<"red" | "blue" | "green">;
18
+ *
19
+ * const color1: Color = "red"; // Autocomplete shows common colors
20
+ * const color2: Color = "#ff0000"; // But also accepts custom values
21
+ */
22
+ export type LooseUnion<T extends string> = T | (string & {});
23
+ /**
24
+ * Prettify<T> - Flattens and displays complex TypeScript types in a readable format.
25
+ *
26
+ * This utility type takes a complex type (especially unions of intersections) and
27
+ * "expands" it in IDE tooltips and error messages, making it easier to see all
28
+ * properties at once instead of seeing multiple intersected types.
29
+ *
30
+ * @example
31
+ * type User = { id: number; name: string };
32
+ * type Timestamps = { createdAt: Date; updatedAt: Date };
33
+ *
34
+ * // Without Prettify: IDE shows "User & Timestamps"
35
+ * type UserWithTimestamps = User & Timestamps;
36
+ *
37
+ * // With Prettify: IDE shows the expanded type:
38
+ * // { id: number; name: string; createdAt: Date; updatedAt: Date }
39
+ * type PrettifiedUser = Prettify<User & Timestamps>;
40
+ */
41
+ export type Prettify<T> = {
42
+ [K in keyof T]: T[K];
43
+ } & {};
44
+ /**
45
+ * Recursively makes all properties of a type deeply immutable and read-only.
46
+ *
47
+ * @template T - The type to make immutable
48
+ * @returns A type where:
49
+ * - Arrays are converted to readonly arrays with immutable elements
50
+ * - Objects have all properties converted to readonly with immutable values
51
+ * - Primitive types remain unchanged
52
+ *
53
+ * @example
54
+ * ```typescript
55
+ * type User = { name: string; age: number; tags: string[] };
56
+ * type ImmutableUser = ImmutableRecord<User>;
57
+ * // Result: { readonly name: string; readonly age: number; readonly tags: readonly string[] }
58
+ * ```
59
+ */
60
+ export type ImmutableRecord<T> = T;
61
+ export type _ImmutableRecord<T> = T extends (infer R)[] ? ReadonlyArray<ImmutableRecord<R>> : T extends object ? {
62
+ readonly [P in keyof T]: ImmutableRecord<T[P]>;
63
+ } : T;
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@golemui/core",
3
+ "version": "0.0.2",
4
+ "type": "module",
5
+ "main": "./index.umd.cjs",
6
+ "module": "./index.js",
7
+ "types": "./index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./index.d.ts",
11
+ "import": "./index.js",
12
+ "require": "./index.umd.cjs"
13
+ }
14
+ },
15
+ "files": [
16
+ "lib",
17
+ "index.d.ts",
18
+ "index.js",
19
+ "index.umd.cjs",
20
+ "*.md"
21
+ ],
22
+ "dependencies": {
23
+ "ts.data.json": "^3.3.0"
24
+ },
25
+ "peerDependencies": {
26
+ "subscript": "^10.1.8",
27
+ "rxjs": "^7.8.0",
28
+ "@standard-schema/spec": "^1.0.0"
29
+ }
30
+ }