@agentdocstore/core 0.3.0 → 0.3.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.
- package/dist/errors.d.ts +15 -2
- package/dist/errors.js +52 -12
- package/package.json +2 -2
package/dist/errors.d.ts
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Typed core errors. Each carries a discriminant `name` (for `switch (e.name)`)
|
|
3
|
-
* and a stable machine `code`.
|
|
4
|
-
*
|
|
3
|
+
* and a stable machine `code`.
|
|
4
|
+
*
|
|
5
|
+
* `instanceof` works across copies of this package. A third-party provider
|
|
6
|
+
* imports @agentdocstore/core itself, and under npx or a global install that is
|
|
7
|
+
* not the copy the CLI loads, so its classes are different objects. Each error
|
|
8
|
+
* therefore carries a mark under a registered symbol, which every copy in the
|
|
9
|
+
* process shares, and each class's `instanceof` also accepts an error with its
|
|
10
|
+
* mark from another copy. The fields are read the same way from either copy, so
|
|
11
|
+
* changing a field is a breaking change for providers built against another
|
|
12
|
+
* version of core.
|
|
5
13
|
*/
|
|
6
14
|
export type ErrorCode = 'VERSION_CONFLICT' | 'NOT_FOUND' | 'VALIDATION' | 'CONTENT_TOO_LARGE' | 'OFFLINE_VIOLATION';
|
|
7
15
|
/** Raised by CAS `appendVersion` when `expect.latestVersion` is stale. */
|
|
@@ -10,6 +18,7 @@ export declare class VersionConflictError extends Error {
|
|
|
10
18
|
readonly actual?: number | undefined;
|
|
11
19
|
readonly code: "VERSION_CONFLICT";
|
|
12
20
|
constructor(message?: string, expected?: number | undefined, actual?: number | undefined);
|
|
21
|
+
static [Symbol.hasInstance](value: unknown): value is VersionConflictError;
|
|
13
22
|
}
|
|
14
23
|
/**
|
|
15
24
|
* Raised when a resource does not exist OR the caller is not permitted to see
|
|
@@ -19,11 +28,13 @@ export declare class VersionConflictError extends Error {
|
|
|
19
28
|
export declare class NotFoundError extends Error {
|
|
20
29
|
readonly code: "NOT_FOUND";
|
|
21
30
|
constructor(message?: string);
|
|
31
|
+
static [Symbol.hasInstance](value: unknown): value is NotFoundError;
|
|
22
32
|
}
|
|
23
33
|
/** Raised on invalid input (bad language, empty title, oversized field, ...). */
|
|
24
34
|
export declare class ValidationError extends Error {
|
|
25
35
|
readonly code: "VALIDATION";
|
|
26
36
|
constructor(message?: string);
|
|
37
|
+
static [Symbol.hasInstance](value: unknown): value is ValidationError;
|
|
27
38
|
}
|
|
28
39
|
/** Raised when content exceeds a configured size cap (write-time or diff-input). */
|
|
29
40
|
export declare class ContentTooLargeError extends Error {
|
|
@@ -31,6 +42,7 @@ export declare class ContentTooLargeError extends Error {
|
|
|
31
42
|
readonly actual?: number | undefined;
|
|
32
43
|
readonly code: "CONTENT_TOO_LARGE";
|
|
33
44
|
constructor(message?: string, limit?: number | undefined, actual?: number | undefined);
|
|
45
|
+
static [Symbol.hasInstance](value: unknown): value is ContentTooLargeError;
|
|
34
46
|
}
|
|
35
47
|
/**
|
|
36
48
|
* Raised when the configured runtime mode forbids what was asked for — an
|
|
@@ -48,6 +60,7 @@ export declare class OfflineViolationError extends Error {
|
|
|
48
60
|
subject?: string | undefined,
|
|
49
61
|
/** How the operator can proceed deliberately. */
|
|
50
62
|
remedy?: string | undefined);
|
|
63
|
+
static [Symbol.hasInstance](value: unknown): value is OfflineViolationError;
|
|
51
64
|
}
|
|
52
65
|
/** Any core error carrying a known {@link ErrorCode}. */
|
|
53
66
|
export type AgentDocStoreError = VersionConflictError | NotFoundError | ValidationError | ContentTooLargeError | OfflineViolationError;
|
package/dist/errors.js
CHANGED
|
@@ -1,8 +1,38 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Typed core errors. Each carries a discriminant `name` (for `switch (e.name)`)
|
|
3
|
-
* and a stable machine `code`.
|
|
4
|
-
*
|
|
3
|
+
* and a stable machine `code`.
|
|
4
|
+
*
|
|
5
|
+
* `instanceof` works across copies of this package. A third-party provider
|
|
6
|
+
* imports @agentdocstore/core itself, and under npx or a global install that is
|
|
7
|
+
* not the copy the CLI loads, so its classes are different objects. Each error
|
|
8
|
+
* therefore carries a mark under a registered symbol, which every copy in the
|
|
9
|
+
* process shares, and each class's `instanceof` also accepts an error with its
|
|
10
|
+
* mark from another copy. The fields are read the same way from either copy, so
|
|
11
|
+
* changing a field is a breaking change for providers built against another
|
|
12
|
+
* version of core.
|
|
5
13
|
*/
|
|
14
|
+
/** The mark's key. `Symbol.for` returns the same symbol to every copy of core. */
|
|
15
|
+
const CORE_ERROR = Symbol.for('agentdocstore.core-error');
|
|
16
|
+
/**
|
|
17
|
+
* Finish constructing a core error: its name, the prototype of the class
|
|
18
|
+
* actually constructed (so a subclass keeps its own), and the mark.
|
|
19
|
+
*/
|
|
20
|
+
function initCoreError(error, prototype, name, code) {
|
|
21
|
+
error.name = name;
|
|
22
|
+
Object.setPrototypeOf(error, prototype);
|
|
23
|
+
Object.defineProperty(error, CORE_ERROR, { value: code });
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* `instanceof` for a core error class: the prototype chain as usual or, for
|
|
27
|
+
* the core class itself (not a subclass), the mark set by any copy of core.
|
|
28
|
+
*/
|
|
29
|
+
function isCoreError(cls, coreClass, code, value) {
|
|
30
|
+
if (typeof value !== 'object' || value === null)
|
|
31
|
+
return false;
|
|
32
|
+
if (Object.prototype.isPrototypeOf.call(cls.prototype, value))
|
|
33
|
+
return true;
|
|
34
|
+
return cls === coreClass && value[CORE_ERROR] === code;
|
|
35
|
+
}
|
|
6
36
|
/** Raised by CAS `appendVersion` when `expect.latestVersion` is stale. */
|
|
7
37
|
export class VersionConflictError extends Error {
|
|
8
38
|
expected;
|
|
@@ -12,8 +42,10 @@ export class VersionConflictError extends Error {
|
|
|
12
42
|
super(message);
|
|
13
43
|
this.expected = expected;
|
|
14
44
|
this.actual = actual;
|
|
15
|
-
this.
|
|
16
|
-
|
|
45
|
+
initCoreError(this, new.target.prototype, 'VersionConflictError', this.code);
|
|
46
|
+
}
|
|
47
|
+
static [Symbol.hasInstance](value) {
|
|
48
|
+
return isCoreError(this, VersionConflictError, 'VERSION_CONFLICT', value);
|
|
17
49
|
}
|
|
18
50
|
}
|
|
19
51
|
/**
|
|
@@ -25,8 +57,10 @@ export class NotFoundError extends Error {
|
|
|
25
57
|
code = 'NOT_FOUND';
|
|
26
58
|
constructor(message = 'Not found') {
|
|
27
59
|
super(message);
|
|
28
|
-
this.
|
|
29
|
-
|
|
60
|
+
initCoreError(this, new.target.prototype, 'NotFoundError', this.code);
|
|
61
|
+
}
|
|
62
|
+
static [Symbol.hasInstance](value) {
|
|
63
|
+
return isCoreError(this, NotFoundError, 'NOT_FOUND', value);
|
|
30
64
|
}
|
|
31
65
|
}
|
|
32
66
|
/** Raised on invalid input (bad language, empty title, oversized field, ...). */
|
|
@@ -34,8 +68,10 @@ export class ValidationError extends Error {
|
|
|
34
68
|
code = 'VALIDATION';
|
|
35
69
|
constructor(message = 'Validation failed') {
|
|
36
70
|
super(message);
|
|
37
|
-
this.
|
|
38
|
-
|
|
71
|
+
initCoreError(this, new.target.prototype, 'ValidationError', this.code);
|
|
72
|
+
}
|
|
73
|
+
static [Symbol.hasInstance](value) {
|
|
74
|
+
return isCoreError(this, ValidationError, 'VALIDATION', value);
|
|
39
75
|
}
|
|
40
76
|
}
|
|
41
77
|
/** Raised when content exceeds a configured size cap (write-time or diff-input). */
|
|
@@ -47,8 +83,10 @@ export class ContentTooLargeError extends Error {
|
|
|
47
83
|
super(message);
|
|
48
84
|
this.limit = limit;
|
|
49
85
|
this.actual = actual;
|
|
50
|
-
this.
|
|
51
|
-
|
|
86
|
+
initCoreError(this, new.target.prototype, 'ContentTooLargeError', this.code);
|
|
87
|
+
}
|
|
88
|
+
static [Symbol.hasInstance](value) {
|
|
89
|
+
return isCoreError(this, ContentTooLargeError, 'CONTENT_TOO_LARGE', value);
|
|
52
90
|
}
|
|
53
91
|
}
|
|
54
92
|
/**
|
|
@@ -68,8 +106,10 @@ export class OfflineViolationError extends Error {
|
|
|
68
106
|
super(message);
|
|
69
107
|
this.subject = subject;
|
|
70
108
|
this.remedy = remedy;
|
|
71
|
-
this.
|
|
72
|
-
|
|
109
|
+
initCoreError(this, new.target.prototype, 'OfflineViolationError', this.code);
|
|
110
|
+
}
|
|
111
|
+
static [Symbol.hasInstance](value) {
|
|
112
|
+
return isCoreError(this, OfflineViolationError, 'OFFLINE_VIOLATION', value);
|
|
73
113
|
}
|
|
74
114
|
}
|
|
75
115
|
//# sourceMappingURL=errors.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentdocstore/core",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "AgentDocStore core: domain model, storage provider SPI, authorization, credential scanner and diff engine.",
|
|
5
5
|
"homepage": "https://github.com/koushikginjupally/agentdocstore/tree/main/packages/core#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"provenance": true
|
|
32
32
|
},
|
|
33
33
|
"engines": {
|
|
34
|
-
"node": ">=
|
|
34
|
+
"node": ">=22"
|
|
35
35
|
},
|
|
36
36
|
"keywords": [
|
|
37
37
|
"agentdocstore",
|