@relax.js/core 1.0.3 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +194 -188
- package/dist/DependencyInjection.d.ts +45 -27
- package/dist/collections/LinkedList.d.ts +9 -8
- package/dist/collections/index.js +1 -1
- package/dist/collections/index.js.map +3 -3
- package/dist/collections/index.mjs +1 -1
- package/dist/collections/index.mjs.map +3 -3
- package/dist/di/index.js +1 -1
- package/dist/di/index.js.map +3 -3
- package/dist/di/index.mjs +1 -1
- package/dist/di/index.mjs.map +3 -3
- package/dist/elements/index.js +1 -1
- package/dist/elements/index.js.map +1 -1
- package/dist/errors.d.ts +20 -0
- package/dist/forms/FormValidator.d.ts +3 -22
- package/dist/forms/ValidationRules.d.ts +4 -6
- package/dist/forms/index.js +1 -1
- package/dist/forms/index.js.map +4 -4
- package/dist/forms/index.mjs +1 -1
- package/dist/forms/index.mjs.map +4 -4
- package/dist/forms/setFormData.d.ts +39 -1
- package/dist/html/TableRenderer.d.ts +1 -0
- package/dist/html/index.js +1 -1
- package/dist/html/index.js.map +3 -3
- package/dist/html/index.mjs +1 -1
- package/dist/html/index.mjs.map +3 -3
- package/dist/html/template.d.ts +4 -0
- package/dist/http/ServerSentEvents.d.ts +1 -1
- package/dist/http/SimpleWebSocket.d.ts +1 -1
- package/dist/http/http.d.ts +1 -0
- package/dist/http/index.js +1 -1
- package/dist/http/index.js.map +3 -3
- package/dist/http/index.mjs +1 -1
- package/dist/http/index.mjs.map +3 -3
- package/dist/i18n/icu.d.ts +1 -1
- package/dist/i18n/index.js +1 -1
- package/dist/i18n/index.js.map +2 -2
- package/dist/i18n/index.mjs +1 -1
- package/dist/i18n/index.mjs.map +2 -2
- package/dist/index.js +3 -3
- package/dist/index.js.map +3 -3
- package/dist/index.mjs +3 -3
- package/dist/index.mjs.map +3 -3
- package/dist/routing/NavigateRouteEvent.d.ts +4 -4
- package/dist/routing/index.js +3 -3
- package/dist/routing/index.js.map +3 -3
- package/dist/routing/index.mjs +3 -3
- package/dist/routing/index.mjs.map +3 -3
- package/dist/routing/navigation.d.ts +1 -1
- package/dist/routing/routeTargetRegistry.d.ts +1 -0
- package/dist/routing/types.d.ts +2 -1
- package/dist/templates/NodeTemplate.d.ts +3 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +1 -1
- package/dist/utils/index.js.map +3 -3
- package/dist/utils/index.mjs +1 -1
- package/dist/utils/index.mjs.map +3 -3
- package/docs/Architecture.md +333 -333
- package/docs/DependencyInjection.md +277 -237
- package/docs/Errors.md +87 -87
- package/docs/GettingStarted.md +238 -231
- package/docs/Pipes.md +5 -5
- package/docs/Translations.md +167 -312
- package/docs/WhyRelaxjs.md +336 -336
- package/docs/api.json +93193 -0
- package/docs/elements/dom.md +102 -102
- package/docs/forms/creating-form-components.md +924 -924
- package/docs/forms/form-api.md +94 -94
- package/docs/forms/forms.md +99 -99
- package/docs/forms/patterns.md +311 -311
- package/docs/forms/reading-writing.md +465 -365
- package/docs/forms/validation.md +351 -351
- package/docs/html/TableRenderer.md +291 -291
- package/docs/html/html.md +175 -175
- package/docs/html/index.md +54 -54
- package/docs/html/template.md +422 -422
- package/docs/http/HttpClient.md +459 -459
- package/docs/http/ServerSentEvents.md +184 -184
- package/docs/http/index.md +109 -109
- package/docs/i18n/i18n.md +49 -4
- package/docs/i18n/intl-standard.md +178 -178
- package/docs/routing/RouteLink.md +98 -98
- package/docs/routing/Routing.md +332 -332
- package/docs/routing/layouts.md +207 -207
- package/docs/setup/bootstrapping.md +154 -0
- package/docs/setup/build-and-deploy.md +183 -0
- package/docs/setup/project-structure.md +170 -0
- package/docs/setup/vite.md +175 -0
- package/docs/utilities.md +143 -143
- package/package.json +4 -2
package/docs/utilities.md
CHANGED
|
@@ -1,143 +1,143 @@
|
|
|
1
|
-
# Utilities
|
|
2
|
-
|
|
3
|
-
Small helper functions and data structures exported from
|
|
4
|
-
|
|
5
|
-
## generateSequentialId
|
|
6
|
-
|
|
7
|
-
Generates compact, time-ordered unique identifiers. IDs sort lexicographically in creation order, making them useful for ordered collections and databases.
|
|
8
|
-
|
|
9
|
-
```typescript
|
|
10
|
-
import { generateSequentialId } from '
|
|
11
|
-
|
|
12
|
-
const id = generateSequentialId(1);
|
|
13
|
-
// Returns a Base36 string like 'k2j8m3n5p'
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
### Parameters
|
|
17
|
-
|
|
18
|
-
| Parameter | Type | Description |
|
|
19
|
-
|-----------|------|-------------|
|
|
20
|
-
| `baseId` | `number` | Unique identifier for the client/process (0 to 1,048,575) |
|
|
21
|
-
|
|
22
|
-
Use different `baseId` values for different servers or processes to avoid collisions:
|
|
23
|
-
|
|
24
|
-
```typescript
|
|
25
|
-
const SERVER_ID = parseInt(process.env.SERVER_ID || '0');
|
|
26
|
-
const orderId = generateSequentialId(SERVER_ID);
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
### Structure
|
|
30
|
-
|
|
31
|
-
Each ID encodes 58 bits of data in Base36:
|
|
32
|
-
|
|
33
|
-
| Bits | Field | Range |
|
|
34
|
-
|------|-------|-------|
|
|
35
|
-
| 30 | Timestamp (seconds since 2025-01-01) | Until ~2059 |
|
|
36
|
-
| 8 | Per-second counter | 256 IDs/second |
|
|
37
|
-
| 20 | Client identifier | ~1M unique sources |
|
|
38
|
-
|
|
39
|
-
### Time-Sortable
|
|
40
|
-
|
|
41
|
-
IDs generated later sort after earlier IDs:
|
|
42
|
-
|
|
43
|
-
```typescript
|
|
44
|
-
const id1 = generateSequentialId(0);
|
|
45
|
-
// ... wait ...
|
|
46
|
-
const id2 = generateSequentialId(0);
|
|
47
|
-
console.log(id1 < id2); // true
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
### Errors
|
|
51
|
-
|
|
52
|
-
- Throws if `baseId` is out of range (0 to 1,048,575)
|
|
53
|
-
- Throws if more than 256 IDs are generated in a single second
|
|
54
|
-
- Throws if timestamp exceeds range (after ~2059)
|
|
55
|
-
|
|
56
|
-
## resolveValue
|
|
57
|
-
|
|
58
|
-
Safely navigates nested object properties using a path array. Returns `undefined` if any segment is null or missing (no exceptions thrown).
|
|
59
|
-
|
|
60
|
-
```typescript
|
|
61
|
-
import { resolveValue } from '
|
|
62
|
-
|
|
63
|
-
const user = { address: { city: 'Stockholm' } };
|
|
64
|
-
|
|
65
|
-
resolveValue(['address', 'city'], user);
|
|
66
|
-
// Returns: 'Stockholm'
|
|
67
|
-
|
|
68
|
-
resolveValue(['address', 'zip'], user);
|
|
69
|
-
// Returns: undefined
|
|
70
|
-
|
|
71
|
-
// Safe with null values
|
|
72
|
-
const data = { user: null };
|
|
73
|
-
resolveValue(['user', 'name'], data);
|
|
74
|
-
// Returns: undefined (no error)
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
### Use with Dot-Notation Paths
|
|
78
|
-
|
|
79
|
-
```typescript
|
|
80
|
-
const path = 'user.profile.avatar'.split('.');
|
|
81
|
-
const avatar = resolveValue(path, context);
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
## LinkedList
|
|
85
|
-
|
|
86
|
-
A doubly-linked list with O(1) insertion and removal at both ends.
|
|
87
|
-
|
|
88
|
-
```typescript
|
|
89
|
-
import { LinkedList } from '
|
|
90
|
-
|
|
91
|
-
const list = new LinkedList<string>();
|
|
92
|
-
|
|
93
|
-
list.addFirst('A');
|
|
94
|
-
list.addLast('B');
|
|
95
|
-
list.addLast('C');
|
|
96
|
-
|
|
97
|
-
console.log(list.length); // 3
|
|
98
|
-
console.log(list.firstValue); // 'A'
|
|
99
|
-
console.log(list.lastValue); // 'C'
|
|
100
|
-
|
|
101
|
-
list.removeFirst(); // Returns 'A'
|
|
102
|
-
list.removeLast(); // Returns 'C'
|
|
103
|
-
console.log(list.length); // 1
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
### Node Access
|
|
107
|
-
|
|
108
|
-
Access the internal `Node` wrappers to traverse or remove specific nodes:
|
|
109
|
-
|
|
110
|
-
```typescript
|
|
111
|
-
let node = list.first;
|
|
112
|
-
while (node) {
|
|
113
|
-
console.log(node.value);
|
|
114
|
-
node = node.next;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// Remove a specific node
|
|
118
|
-
const node = list.first;
|
|
119
|
-
node.remove(); // Removes from list and updates length
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
### API
|
|
123
|
-
|
|
124
|
-
| Method/Property | Description |
|
|
125
|
-
|-----------------|-------------|
|
|
126
|
-
| `addFirst(value)` | Insert at the beginning |
|
|
127
|
-
| `addLast(value)` | Insert at the end |
|
|
128
|
-
| `removeFirst()` | Remove and return the first value |
|
|
129
|
-
| `removeLast()` | Remove and return the last value |
|
|
130
|
-
| `length` | Number of nodes |
|
|
131
|
-
| `first` | First `Node` (or `undefined`) |
|
|
132
|
-
| `last` | Last `Node` (or `undefined`) |
|
|
133
|
-
| `firstValue` | Value of the first node |
|
|
134
|
-
| `lastValue` | Value of the last node |
|
|
135
|
-
|
|
136
|
-
### Node Properties
|
|
137
|
-
|
|
138
|
-
| Property | Description |
|
|
139
|
-
|----------|-------------|
|
|
140
|
-
| `value` | The stored value |
|
|
141
|
-
| `next` | Next node (or `null`) |
|
|
142
|
-
| `prev` | Previous node (or `null`) |
|
|
143
|
-
| `remove()` | Remove this node from the list |
|
|
1
|
+
# Utilities
|
|
2
|
+
|
|
3
|
+
Small helper functions and data structures exported from `@relax.js/core/utils`.
|
|
4
|
+
|
|
5
|
+
## generateSequentialId
|
|
6
|
+
|
|
7
|
+
Generates compact, time-ordered unique identifiers. IDs sort lexicographically in creation order, making them useful for ordered collections and databases.
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
import { generateSequentialId } from '@relax.js/core/utils';
|
|
11
|
+
|
|
12
|
+
const id = generateSequentialId(1);
|
|
13
|
+
// Returns a Base36 string like 'k2j8m3n5p'
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
### Parameters
|
|
17
|
+
|
|
18
|
+
| Parameter | Type | Description |
|
|
19
|
+
|-----------|------|-------------|
|
|
20
|
+
| `baseId` | `number` | Unique identifier for the client/process (0 to 1,048,575) |
|
|
21
|
+
|
|
22
|
+
Use different `baseId` values for different servers or processes to avoid collisions:
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
const SERVER_ID = parseInt(process.env.SERVER_ID || '0');
|
|
26
|
+
const orderId = generateSequentialId(SERVER_ID);
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Structure
|
|
30
|
+
|
|
31
|
+
Each ID encodes 58 bits of data in Base36:
|
|
32
|
+
|
|
33
|
+
| Bits | Field | Range |
|
|
34
|
+
|------|-------|-------|
|
|
35
|
+
| 30 | Timestamp (seconds since 2025-01-01) | Until ~2059 |
|
|
36
|
+
| 8 | Per-second counter | 256 IDs/second |
|
|
37
|
+
| 20 | Client identifier | ~1M unique sources |
|
|
38
|
+
|
|
39
|
+
### Time-Sortable
|
|
40
|
+
|
|
41
|
+
IDs generated later sort after earlier IDs:
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
const id1 = generateSequentialId(0);
|
|
45
|
+
// ... wait ...
|
|
46
|
+
const id2 = generateSequentialId(0);
|
|
47
|
+
console.log(id1 < id2); // true
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Errors
|
|
51
|
+
|
|
52
|
+
- Throws if `baseId` is out of range (0 to 1,048,575)
|
|
53
|
+
- Throws if more than 256 IDs are generated in a single second
|
|
54
|
+
- Throws if timestamp exceeds range (after ~2059)
|
|
55
|
+
|
|
56
|
+
## resolveValue
|
|
57
|
+
|
|
58
|
+
Safely navigates nested object properties using a path array. Returns `undefined` if any segment is null or missing (no exceptions thrown).
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
import { resolveValue } from '@relax.js/core/utils';
|
|
62
|
+
|
|
63
|
+
const user = { address: { city: 'Stockholm' } };
|
|
64
|
+
|
|
65
|
+
resolveValue(['address', 'city'], user);
|
|
66
|
+
// Returns: 'Stockholm'
|
|
67
|
+
|
|
68
|
+
resolveValue(['address', 'zip'], user);
|
|
69
|
+
// Returns: undefined
|
|
70
|
+
|
|
71
|
+
// Safe with null values
|
|
72
|
+
const data = { user: null };
|
|
73
|
+
resolveValue(['user', 'name'], data);
|
|
74
|
+
// Returns: undefined (no error)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Use with Dot-Notation Paths
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
const path = 'user.profile.avatar'.split('.');
|
|
81
|
+
const avatar = resolveValue(path, context);
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## LinkedList
|
|
85
|
+
|
|
86
|
+
A doubly-linked list with O(1) insertion and removal at both ends.
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
import { LinkedList } from '@relax.js/core/utils';
|
|
90
|
+
|
|
91
|
+
const list = new LinkedList<string>();
|
|
92
|
+
|
|
93
|
+
list.addFirst('A');
|
|
94
|
+
list.addLast('B');
|
|
95
|
+
list.addLast('C');
|
|
96
|
+
|
|
97
|
+
console.log(list.length); // 3
|
|
98
|
+
console.log(list.firstValue); // 'A'
|
|
99
|
+
console.log(list.lastValue); // 'C'
|
|
100
|
+
|
|
101
|
+
list.removeFirst(); // Returns 'A'
|
|
102
|
+
list.removeLast(); // Returns 'C'
|
|
103
|
+
console.log(list.length); // 1
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Node Access
|
|
107
|
+
|
|
108
|
+
Access the internal `Node` wrappers to traverse or remove specific nodes:
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
let node = list.first;
|
|
112
|
+
while (node) {
|
|
113
|
+
console.log(node.value);
|
|
114
|
+
node = node.next;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Remove a specific node
|
|
118
|
+
const node = list.first;
|
|
119
|
+
node.remove(); // Removes from list and updates length
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### API
|
|
123
|
+
|
|
124
|
+
| Method/Property | Description |
|
|
125
|
+
|-----------------|-------------|
|
|
126
|
+
| `addFirst(value)` | Insert at the beginning |
|
|
127
|
+
| `addLast(value)` | Insert at the end |
|
|
128
|
+
| `removeFirst()` | Remove and return the first value |
|
|
129
|
+
| `removeLast()` | Remove and return the last value |
|
|
130
|
+
| `length` | Number of nodes |
|
|
131
|
+
| `first` | First `Node` (or `undefined`) |
|
|
132
|
+
| `last` | Last `Node` (or `undefined`) |
|
|
133
|
+
| `firstValue` | Value of the first node |
|
|
134
|
+
| `lastValue` | Value of the last node |
|
|
135
|
+
|
|
136
|
+
### Node Properties
|
|
137
|
+
|
|
138
|
+
| Property | Description |
|
|
139
|
+
|----------|-------------|
|
|
140
|
+
| `value` | The stored value |
|
|
141
|
+
| `next` | Next node (or `null`) |
|
|
142
|
+
| `prev` | Previous node (or `null`) |
|
|
143
|
+
| `remove()` | Remove this node from the list |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@relax.js/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "Ship faster with less code. Web Component library with routing, forms, DI, templating, and i18n. No virtual DOM, no build magic, no surprise re-renders.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"test:ui": "vitest --ui",
|
|
13
13
|
"buildOld": "tsc",
|
|
14
14
|
"build": "tsc --emitDeclarationOnly && node build.js",
|
|
15
|
+
"docs": "npx typedoc",
|
|
15
16
|
"yalc:publish": "yalc publish && yalc push",
|
|
16
17
|
"yalc:watch": "nodemon --ext ts,js,json --exec \"npm run yalc:publish\"",
|
|
17
18
|
"bp": "npm run build && npm run yalc:publish",
|
|
@@ -19,7 +20,7 @@
|
|
|
19
20
|
},
|
|
20
21
|
"keywords": [],
|
|
21
22
|
"author": "",
|
|
22
|
-
"license": "
|
|
23
|
+
"license": "MIT",
|
|
23
24
|
"dependencies": {
|
|
24
25
|
"reflect-metadata": "^0.2.2"
|
|
25
26
|
},
|
|
@@ -29,6 +30,7 @@
|
|
|
29
30
|
"esbuild": "^0.25.0",
|
|
30
31
|
"eslint": "^9.17.0",
|
|
31
32
|
"jsdom": "^26.1.0",
|
|
33
|
+
"typedoc": "^0.28.18",
|
|
32
34
|
"typescript": "^5.7.3",
|
|
33
35
|
"vite": "^6.0.7",
|
|
34
36
|
"vite-plugin-ts": "^1.3.2-1",
|