@archtx/core 1.1.10 → 1.1.12
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/dist/exports.d.ts +2 -1
- package/dist/exports.js +2 -1
- package/dist/exports.js.map +1 -1
- package/dist/src/Entity/Entity.benchmark.test.d.ts +1 -0
- package/dist/src/Entity/Entity.benchmark.test.js +283 -0
- package/dist/src/Entity/Entity.benchmark.test.js.map +1 -0
- package/dist/src/Entity/Entity.d.ts +21 -0
- package/dist/src/Entity/Entity.js +229 -0
- package/dist/src/Entity/Entity.js.map +1 -0
- package/dist/src/Entity/Entity.test.d.ts +1 -0
- package/dist/src/Entity/Entity.test.js +238 -0
- package/dist/src/Entity/Entity.test.js.map +1 -0
- package/dist/src/Entity/utils.d.ts +6 -0
- package/dist/src/Entity/utils.js +12 -0
- package/dist/src/Entity/utils.js.map +1 -0
- package/dist/src/errors/AuthError.d.ts +2 -2
- package/dist/src/errors/AuthError.js.map +1 -1
- package/dist/src/errors/RootError.d.ts +2 -2
- package/dist/src/errors/RootError.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from 'vitest';
|
|
2
|
+
import { Entity } from './Entity.js';
|
|
3
|
+
describe('Entity', () => {
|
|
4
|
+
afterEach(() => {
|
|
5
|
+
process.env.NODE_ENV = 'development';
|
|
6
|
+
});
|
|
7
|
+
describe('Initialization', () => {
|
|
8
|
+
it('should initialize with props', () => {
|
|
9
|
+
class Profile extends Entity {
|
|
10
|
+
static create(props) {
|
|
11
|
+
return new Profile(props);
|
|
12
|
+
}
|
|
13
|
+
validate() {
|
|
14
|
+
if (this.props.name.length === 0) {
|
|
15
|
+
throw new Error('Name cannot be empty');
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
const profile = Profile.create({ id: '123', name: 'Test' });
|
|
20
|
+
expect(profile.props).toEqual({ id: '123', name: 'Test' });
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
describe('Props Immutability', () => {
|
|
24
|
+
it('should make props immutable in development mode', () => {
|
|
25
|
+
class Profile extends Entity {
|
|
26
|
+
static create(props) {
|
|
27
|
+
return new Profile({
|
|
28
|
+
...props,
|
|
29
|
+
tags: props.tags || [],
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
validate() {
|
|
33
|
+
if (this.props.name.length === 0) {
|
|
34
|
+
throw new Error('Name cannot be empty');
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const profile = Profile.create({ id: '123', name: 'Test' });
|
|
39
|
+
// Direct modification attempts should throw errors in strict mode
|
|
40
|
+
expect(() => {
|
|
41
|
+
// @ts-expect-error - Intentionally trying to modify readonly property
|
|
42
|
+
profile.props.name = 'Modified';
|
|
43
|
+
}).toThrow();
|
|
44
|
+
expect(() => {
|
|
45
|
+
// @ts-expect-error - Intentionally trying to modify readonly property
|
|
46
|
+
profile.props.tags.push('tag3');
|
|
47
|
+
}).toThrow();
|
|
48
|
+
expect(() => {
|
|
49
|
+
// @ts-expect-error - Intentionally trying to modify readonly property
|
|
50
|
+
profile.props.metadata.email = 'cory@therms.io';
|
|
51
|
+
}).toThrow();
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
describe('set() method', () => {
|
|
55
|
+
it('should not allow setting the ID property', () => {
|
|
56
|
+
class Profile extends Entity {
|
|
57
|
+
static create(props) {
|
|
58
|
+
return new Profile(props);
|
|
59
|
+
}
|
|
60
|
+
validate() {
|
|
61
|
+
if (this.props.name.length === 0) {
|
|
62
|
+
throw new Error('Name cannot be empty');
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const profile = Profile.create({ id: '123', name: 'Test' });
|
|
67
|
+
expect(() => {
|
|
68
|
+
// @ts-expect-error - Intentionally trying to set ID
|
|
69
|
+
profile.set('id', '456');
|
|
70
|
+
}).toThrow('Cannot set ID');
|
|
71
|
+
});
|
|
72
|
+
it('should update a property value', () => {
|
|
73
|
+
class Profile extends Entity {
|
|
74
|
+
static create(props) {
|
|
75
|
+
return new Profile({
|
|
76
|
+
...props,
|
|
77
|
+
tags: props.tags || [],
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
validate() {
|
|
81
|
+
if (this.props.name.length === 0) {
|
|
82
|
+
throw new Error('Name cannot be empty');
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const profile = Profile.create({ id: '123', name: 'Test' });
|
|
87
|
+
profile.set('name', 'Updated');
|
|
88
|
+
expect(profile.props.name).toBe('Updated');
|
|
89
|
+
});
|
|
90
|
+
it('should allow null/undefined values', () => {
|
|
91
|
+
class Profile extends Entity {
|
|
92
|
+
static create(props) {
|
|
93
|
+
return new Profile(props);
|
|
94
|
+
}
|
|
95
|
+
validate() {
|
|
96
|
+
if (this.props.name.length === 0) {
|
|
97
|
+
throw new Error('Name cannot be empty');
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const profile = Profile.create({ id: '123', name: 'Test' });
|
|
102
|
+
profile.set('maybe', null);
|
|
103
|
+
expect(profile.props.maybe).toBe(null);
|
|
104
|
+
profile.set('maybe', undefined);
|
|
105
|
+
expect(profile.props.maybe).toBe(undefined);
|
|
106
|
+
profile.set('maybe', 'value');
|
|
107
|
+
expect(profile.props.maybe).toBe('value');
|
|
108
|
+
});
|
|
109
|
+
it('should create a new reference when updating props', () => {
|
|
110
|
+
class Profile extends Entity {
|
|
111
|
+
static create(props) {
|
|
112
|
+
return new Profile({
|
|
113
|
+
...props,
|
|
114
|
+
tags: props.tags || [],
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
validate() {
|
|
118
|
+
if (this.props.name.length === 0) {
|
|
119
|
+
throw new Error('Name cannot be empty');
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
const profile = Profile.create({ id: '123', name: 'Test' });
|
|
124
|
+
const originalProps = profile.props;
|
|
125
|
+
profile.set('name', 'Updated');
|
|
126
|
+
// Reference should be different
|
|
127
|
+
expect(profile.props).not.toBe(originalProps);
|
|
128
|
+
});
|
|
129
|
+
it('should deeply clone objects when updating', () => {
|
|
130
|
+
const date = new Date();
|
|
131
|
+
class Profile extends Entity {
|
|
132
|
+
static create(props) {
|
|
133
|
+
return new Profile({
|
|
134
|
+
...props,
|
|
135
|
+
tags: props.tags || [],
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
validate() {
|
|
139
|
+
if (this.props.name.length === 0) {
|
|
140
|
+
throw new Error('Name cannot be empty');
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const profile = Profile.create({ id: '123', name: 'Test' });
|
|
145
|
+
const newMetadata = {
|
|
146
|
+
createdAt: date,
|
|
147
|
+
updatedAt: new Date(),
|
|
148
|
+
nested: {
|
|
149
|
+
value: 100,
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
profile.set('metadata', newMetadata);
|
|
153
|
+
// Modify the original object
|
|
154
|
+
expect(() => {
|
|
155
|
+
newMetadata.nested.value = 200;
|
|
156
|
+
}).toThrow();
|
|
157
|
+
// Entity props should have the original value
|
|
158
|
+
expect(profile.props.metadata?.nested?.value).toBe(100);
|
|
159
|
+
});
|
|
160
|
+
it('should deeply clone arrays when updating', () => {
|
|
161
|
+
class Profile extends Entity {
|
|
162
|
+
static create(props) {
|
|
163
|
+
return new Profile({
|
|
164
|
+
...props,
|
|
165
|
+
tags: props.tags || [],
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
validate() {
|
|
169
|
+
if (this.props.name.length === 0) {
|
|
170
|
+
throw new Error('Name cannot be empty');
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
const tags = ['tag1', 'tag2'];
|
|
175
|
+
const profile = Profile.create({ id: '123', name: 'Test', tags });
|
|
176
|
+
// Modify the original array
|
|
177
|
+
expect(() => { tags.push('tag3'); }).toThrow;
|
|
178
|
+
expect(() => { tags[0] = 'tag4'; }).toThrow;
|
|
179
|
+
// Entity props should have the original value
|
|
180
|
+
expect(profile.props.tags.length).toBe(2);
|
|
181
|
+
expect(profile.props.tags[0]).toBe('tag1');
|
|
182
|
+
profile.set('tags', [...profile.props.tags, 'tag5', 'tag6']);
|
|
183
|
+
// Entity props should have the new value
|
|
184
|
+
expect(profile.props.tags.length).toBe(4);
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
describe('Validation', () => {
|
|
188
|
+
it('should validate properties when setting values', () => {
|
|
189
|
+
class Profile extends Entity {
|
|
190
|
+
static create(props) {
|
|
191
|
+
return new Profile({
|
|
192
|
+
...props,
|
|
193
|
+
tags: props.tags || [],
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
validate(props) {
|
|
197
|
+
if (props.name.length === 0) {
|
|
198
|
+
throw new Error('Name cannot be empty');
|
|
199
|
+
}
|
|
200
|
+
if (!props.tags) {
|
|
201
|
+
throw new Error('Tags cannot be empty');
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
const profile = Profile.create({ id: '123', name: 'Test' });
|
|
206
|
+
// These should pass validation
|
|
207
|
+
expect(() => profile.set('name', 'Valid name')).not.toThrow();
|
|
208
|
+
expect(() => profile.set('tags', ['1', '2'])).not.toThrow();
|
|
209
|
+
// These should fail validation
|
|
210
|
+
expect(() => profile.set('name', '')).toThrow('Name cannot be empty');
|
|
211
|
+
// @ts-expect-error - Intentionally passing undefined
|
|
212
|
+
expect(() => profile.set('tags', undefined)).toThrow('Tags cannot be empty');
|
|
213
|
+
});
|
|
214
|
+
it('should not update props if validation fails', () => {
|
|
215
|
+
class Profile extends Entity {
|
|
216
|
+
static create(props) {
|
|
217
|
+
return new Profile(props);
|
|
218
|
+
}
|
|
219
|
+
validate(props) {
|
|
220
|
+
if (props.name.length === 0) {
|
|
221
|
+
throw new Error('Name cannot be empty');
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
const profile = Profile.create({ id: '123', name: 'Test' });
|
|
226
|
+
// Try to set an invalid value
|
|
227
|
+
try {
|
|
228
|
+
profile.set('name', '');
|
|
229
|
+
}
|
|
230
|
+
catch (error) {
|
|
231
|
+
// Ignore the error
|
|
232
|
+
}
|
|
233
|
+
// Props should not be updated
|
|
234
|
+
expect(profile.props.name).toBe('Test');
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
//# sourceMappingURL=Entity.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Entity.test.js","sourceRoot":"","sources":["../../../src/Entity/Entity.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,QAAQ,CAAC,QAAQ,EAAE,GAAG,EAAE;IACtB,SAAS,CAAC,GAAG,EAAE;QACb,OAAO,CAAC,GAAG,CAAC,QAAQ,GAAG,aAAa,CAAA;IACtC,CAAC,CAAC,CAAA;IAEF,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;QAC9B,EAAE,CAAC,8BAA8B,EAAE,GAAG,EAAE;YACtC,MAAM,OAAQ,SAAQ,MAAoC;gBACxD,MAAM,CAAC,MAAM,CAAC,KAAmC;oBAC/C,OAAO,IAAI,OAAO,CAAC,KAAK,CAAC,CAAA;gBAC3B,CAAC;gBAED,QAAQ;oBACN,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;wBACjC,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAA;oBACzC,CAAC;gBACH,CAAC;aACF;YAED,MAAM,OAAO,GAAG,OAAO,CAAC,MAAM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,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAA;YAE3D,8BAA8B;YAC9B,IAAI,CAAC;gBACH,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;YACzB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,mBAAmB;YACrB,CAAC;YAED,8BAA8B;YAC9B,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QACzC,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Entity } from './Entity.js';
|
|
2
|
+
/**
|
|
3
|
+
* Asserts that an entity exists, throwing a NotFoundError if it does not.
|
|
4
|
+
* @param entity {Entity} - The entity to check.
|
|
5
|
+
*/
|
|
6
|
+
export declare function assertEntityExists<EntityInstance extends Entity<any>>(entity?: EntityInstance): asserts entity is EntityInstance;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { NotFoundError } from '../errors/NotFoundError.js';
|
|
2
|
+
import { Entity } from './Entity.js';
|
|
3
|
+
/**
|
|
4
|
+
* Asserts that an entity exists, throwing a NotFoundError if it does not.
|
|
5
|
+
* @param entity {Entity} - The entity to check.
|
|
6
|
+
*/
|
|
7
|
+
export function assertEntityExists(entity) {
|
|
8
|
+
if (!(entity instanceof Entity)) {
|
|
9
|
+
throw new NotFoundError(null, 'Entity not found');
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/Entity/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAChC,MAAuB;IAEvB,IAAI,CAAC,CAAC,MAAM,YAAY,MAAM,CAAC,EAAE,CAAC;QAChC,MAAM,IAAI,aAAa,CAAC,IAAI,EAAE,kBAAkB,CAAC,CAAA;IACnD,CAAC;AACH,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { RootError } from './RootError.js';
|
|
2
|
-
type ERROR_DESC = 'UNABLE_TO_CHECK_AUTH' | 'NOT_AUTHENTICATED' | 'INVALID_PERMISSIONS';
|
|
2
|
+
type ERROR_DESC = 'UNABLE_TO_CHECK_AUTH' | 'NOT_AUTHENTICATED' | 'INVALID_PERMISSIONS' | 'INVALID_ROLE';
|
|
3
3
|
export declare class AuthError extends RootError {
|
|
4
4
|
errorType?: ERROR_DESC;
|
|
5
|
-
constructor(internalDesc: string | string[] | null, externalDesc: string | undefined, errorType: ERROR_DESC);
|
|
5
|
+
constructor(internalDesc: string | string[] | null, externalDesc: string | undefined | null, errorType: ERROR_DESC);
|
|
6
6
|
}
|
|
7
7
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthError.js","sourceRoot":"","sources":["../../../src/errors/AuthError.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"AuthError.js","sourceRoot":"","sources":["../../../src/errors/AuthError.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAQ1C,MAAM,OAAO,SAAU,SAAQ,SAAS;IAC/B,SAAS,CAAa;IAE7B,YACE,YAAsC,EACtC,YAAuC,EACvC,SAAqB;QAErB,KAAK,CAAC,YAAY,EAAE,YAAY,CAAC,CAAA;QAEjC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAE1B,mGAAmG;QACnG,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,SAAS,CAAC,SAAS,CAAC,CAAA;IAClD,CAAC;CACF"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export declare class RootError extends Error {
|
|
2
|
-
externalDesc?: string;
|
|
2
|
+
externalDesc?: string | null;
|
|
3
3
|
/**
|
|
4
4
|
* Create a RootError
|
|
5
5
|
* @param [internalDesc] Internal message, console, logs, etc.
|
|
6
6
|
* @param [externalDesc] External message is safe to be sent in a response to
|
|
7
7
|
* the client. NOTE: This does not mean it's "human readable".
|
|
8
8
|
*/
|
|
9
|
-
constructor(internalDesc: string | string[] | null | undefined, externalDesc?: string);
|
|
9
|
+
constructor(internalDesc: string | string[] | null | undefined, externalDesc?: string | null);
|
|
10
10
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RootError.js","sourceRoot":"","sources":["../../../src/errors/RootError.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,SAAU,SAAQ,KAAK;IAC3B,YAAY,
|
|
1
|
+
{"version":3,"file":"RootError.js","sourceRoot":"","sources":["../../../src/errors/RootError.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,SAAU,SAAQ,KAAK;IAC3B,YAAY,CAAgB;IAEnC;;;;;OAKG;IACH,YACE,YAAkD,EAClD,YAA4B;QAE5B,IAAI,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,CAAC;YAChC,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;QAChC,CAAC;aAAM,CAAC;YACN,KAAK,CAAC,YAAY,IAAI,YAAY,IAAI,+BAA+B,CAAC,CAAA;QACxE,CAAC;QAED,IAAI,YAAY,EAAE,CAAC;YACjB,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC;gBACxC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC;gBAC9B,CAAC,CAAC,YAAY,CAAA;QAClB,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,OAAO,GAAG,YAAY,IAAI,EAAE,CAAA;QACnC,CAAC;QAED,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;QAEhC,mMAAmM;QACnM,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,SAAS,CAAC,SAAS,CAAC,CAAA;IAClD,CAAC;CACF"}
|