@tomradex/domain 0.0.0-stage → 0.2.0
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/LICENSE +204 -0
- package/README.md +2 -2
- package/dist/delivery.d.ts +70 -0
- package/dist/delivery.js +7 -0
- package/dist/derive.d.ts +8 -0
- package/dist/derive.js +14 -0
- package/dist/errors.d.ts +53 -0
- package/dist/errors.js +99 -0
- package/dist/fields.d.ts +54 -0
- package/dist/fields.js +104 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +8 -0
- package/dist/query.d.ts +65 -0
- package/dist/query.js +99 -0
- package/dist/schema.d.ts +118 -0
- package/dist/schema.js +54 -0
- package/dist/types.d.ts +302 -0
- package/dist/types.js +8 -0
- package/dist/view-kinds.d.ts +13 -0
- package/dist/view-kinds.js +12 -0
- package/package.json +26 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
Copyright 2026 Haoyuan Tang
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
Apache License
|
|
5
|
+
Version 2.0, January 2004
|
|
6
|
+
http://www.apache.org/licenses/
|
|
7
|
+
|
|
8
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
9
|
+
|
|
10
|
+
1. Definitions.
|
|
11
|
+
|
|
12
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
13
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
14
|
+
|
|
15
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
16
|
+
the copyright owner that is granting the License.
|
|
17
|
+
|
|
18
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
19
|
+
other entities that control, are controlled by, or are under common
|
|
20
|
+
control with that entity. For the purposes of this definition,
|
|
21
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
22
|
+
direction or management of such entity, whether by contract or
|
|
23
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
24
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
25
|
+
|
|
26
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
27
|
+
exercising permissions granted by this License.
|
|
28
|
+
|
|
29
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
30
|
+
including but not limited to software source code, documentation
|
|
31
|
+
source, and configuration files.
|
|
32
|
+
|
|
33
|
+
"Object" form shall mean any form resulting from mechanical
|
|
34
|
+
transformation or translation of a Source form, including but
|
|
35
|
+
not limited to compiled object code, generated documentation,
|
|
36
|
+
and conversions to other media types.
|
|
37
|
+
|
|
38
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
39
|
+
Object form, made available under the License, as indicated by a
|
|
40
|
+
copyright notice that is included in or attached to the work
|
|
41
|
+
(an example is provided in the Appendix below).
|
|
42
|
+
|
|
43
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
44
|
+
form, that is based on (or derived from) the Work and for which the
|
|
45
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
46
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
47
|
+
of this License, Derivative Works shall not include works that remain
|
|
48
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
49
|
+
the Work and Derivative Works thereof.
|
|
50
|
+
|
|
51
|
+
"Contribution" shall mean any work of authorship, including
|
|
52
|
+
the original version of the Work and any modifications or additions
|
|
53
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
54
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
55
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
56
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
57
|
+
means any form of electronic, verbal, or written communication sent
|
|
58
|
+
to the Licensor or its representatives, including but not limited to
|
|
59
|
+
communication on electronic mailing lists, source code control systems,
|
|
60
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
61
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
62
|
+
excluding communication that is conspicuously marked or otherwise
|
|
63
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
64
|
+
|
|
65
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
66
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
67
|
+
subsequently incorporated within the Work.
|
|
68
|
+
|
|
69
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
70
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
71
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
72
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
73
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
74
|
+
Work and such Derivative Works in Source or Object form.
|
|
75
|
+
|
|
76
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
77
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
78
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
79
|
+
(except as stated in this section) patent license to make, have made,
|
|
80
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
81
|
+
where such license applies only to those patent claims licensable
|
|
82
|
+
by such Contributor that are necessarily infringed by their
|
|
83
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
84
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
85
|
+
institute patent litigation against any entity (including a
|
|
86
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
87
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
88
|
+
or contributory patent infringement, then any patent licenses
|
|
89
|
+
granted to You under this License for that Work shall terminate
|
|
90
|
+
as of the date such litigation is filed.
|
|
91
|
+
|
|
92
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
93
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
94
|
+
modifications, and in Source or Object form, provided that You
|
|
95
|
+
meet the following conditions:
|
|
96
|
+
|
|
97
|
+
(a) You must give any other recipients of the Work or
|
|
98
|
+
Derivative Works a copy of this License; and
|
|
99
|
+
|
|
100
|
+
(b) You must cause any modified files to carry prominent notices
|
|
101
|
+
stating that You changed the files; and
|
|
102
|
+
|
|
103
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
104
|
+
that You distribute, all copyright, patent, trademark, and
|
|
105
|
+
attribution notices from the Source form of the Work,
|
|
106
|
+
excluding those notices that do not pertain to any part of
|
|
107
|
+
the Derivative Works; and
|
|
108
|
+
|
|
109
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
110
|
+
distribution, then any Derivative Works that You distribute must
|
|
111
|
+
include a readable copy of the attribution notices contained
|
|
112
|
+
within such NOTICE file, excluding those notices that do not
|
|
113
|
+
pertain to any part of the Derivative Works, in at least one
|
|
114
|
+
of the following places: within a NOTICE text file distributed
|
|
115
|
+
as part of the Derivative Works; within the Source form or
|
|
116
|
+
documentation, if provided along with the Derivative Works; or,
|
|
117
|
+
within a display generated by the Derivative Works, if and
|
|
118
|
+
wherever such third-party notices normally appear. The contents
|
|
119
|
+
of the NOTICE file are for informational purposes only and
|
|
120
|
+
do not modify the License. You may add Your own attribution
|
|
121
|
+
notices within Derivative Works that You distribute, alongside
|
|
122
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
123
|
+
that such additional attribution notices cannot be construed
|
|
124
|
+
as modifying the License.
|
|
125
|
+
|
|
126
|
+
You may add Your own copyright statement to Your modifications and
|
|
127
|
+
may provide additional or different license terms and conditions
|
|
128
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
129
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
130
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
131
|
+
the conditions stated in this License.
|
|
132
|
+
|
|
133
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
134
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
135
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
136
|
+
this License, without any additional terms or conditions.
|
|
137
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
138
|
+
the terms of any separate license agreement you may have executed
|
|
139
|
+
with Licensor regarding such Contributions.
|
|
140
|
+
|
|
141
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
142
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
143
|
+
except as required for reasonable and customary use in describing the
|
|
144
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
145
|
+
|
|
146
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
147
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
148
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
149
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
150
|
+
implied, including, without limitation, any warranties or conditions
|
|
151
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
152
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
153
|
+
appropriateness of using or redistributing the Work and assume any
|
|
154
|
+
risks associated with Your exercise of permissions under this License.
|
|
155
|
+
|
|
156
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
157
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
158
|
+
unless required by applicable law (such as deliberate and grossly
|
|
159
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
160
|
+
liable to You for damages, including any direct, indirect, special,
|
|
161
|
+
incidental, or consequential damages of any character arising as a
|
|
162
|
+
result of this License or out of the use or inability to use the
|
|
163
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
164
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
165
|
+
other commercial damages or losses), even if such Contributor
|
|
166
|
+
has been advised of the possibility of such damages.
|
|
167
|
+
|
|
168
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
169
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
170
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
171
|
+
or other liability obligations and/or rights consistent with this
|
|
172
|
+
License. However, in accepting such obligations, You may act only
|
|
173
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
174
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
175
|
+
defend, and hold each Contributor harmless for any liability
|
|
176
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
177
|
+
of your accepting any such warranty or additional liability.
|
|
178
|
+
|
|
179
|
+
END OF TERMS AND CONDITIONS
|
|
180
|
+
|
|
181
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
182
|
+
|
|
183
|
+
To apply the Apache License to your work, attach the following
|
|
184
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
185
|
+
replaced with your own identifying information. (Don't include
|
|
186
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
187
|
+
comment syntax for the file format. We also recommend that a
|
|
188
|
+
file or class name and description of purpose be included on the
|
|
189
|
+
same "printed page" as the copyright notice for easier
|
|
190
|
+
identification within third-party archives.
|
|
191
|
+
|
|
192
|
+
Copyright [yyyy] [name of copyright owner]
|
|
193
|
+
|
|
194
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
195
|
+
you may not use this file except in compliance with the License.
|
|
196
|
+
You may obtain a copy of the License at
|
|
197
|
+
|
|
198
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
199
|
+
|
|
200
|
+
Unless required by applicable law or agreed to in writing, software
|
|
201
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
202
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
203
|
+
See the License for the specific language governing permissions and
|
|
204
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @tomradex/domain
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The types a Tomrade plugin reads: issues (`Item`), fields, boards, views, projects and the history (`OplogEntry`), with the zod schemas and typed errors behind them. Plugins normally get these through [`@tomradex/plugin-sdk`](https://www.npmjs.com/package/@tomradex/plugin-sdk), which re-exports them.
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { Author } from "./types.js";
|
|
3
|
+
/** Metadata only. File bytes and immutable versions belong to the Files plugin. */
|
|
4
|
+
export interface FileReference {
|
|
5
|
+
fileId: string;
|
|
6
|
+
versionId: string;
|
|
7
|
+
}
|
|
8
|
+
export interface DeliveryResource {
|
|
9
|
+
id: string;
|
|
10
|
+
name: string;
|
|
11
|
+
role: "input" | "output";
|
|
12
|
+
deliveryId: string | null;
|
|
13
|
+
file: FileReference;
|
|
14
|
+
createdBy: Author;
|
|
15
|
+
createdAt: number;
|
|
16
|
+
}
|
|
17
|
+
export interface DeliverySubmission {
|
|
18
|
+
id: string;
|
|
19
|
+
deliveryId: string;
|
|
20
|
+
report: string;
|
|
21
|
+
artifactIds: string[];
|
|
22
|
+
submittedBy: Author;
|
|
23
|
+
submittedAt: number;
|
|
24
|
+
}
|
|
25
|
+
export interface DeliveryReview {
|
|
26
|
+
id: string;
|
|
27
|
+
submissionId: string;
|
|
28
|
+
decision: "accepted" | "changes-requested";
|
|
29
|
+
comment: string;
|
|
30
|
+
reviewedBy: "human";
|
|
31
|
+
reviewedAt: number;
|
|
32
|
+
}
|
|
33
|
+
export interface TicketEvidence {
|
|
34
|
+
resources: DeliveryResource[];
|
|
35
|
+
submissions: DeliverySubmission[];
|
|
36
|
+
reviews: DeliveryReview[];
|
|
37
|
+
}
|
|
38
|
+
export declare const emptyEvidence: () => TicketEvidence;
|
|
39
|
+
export declare const fileReferenceSchema: z.ZodObject<{
|
|
40
|
+
fileId: z.ZodString;
|
|
41
|
+
versionId: z.ZodString;
|
|
42
|
+
}, z.core.$strip>;
|
|
43
|
+
export declare const addResourceSchema: z.ZodObject<{
|
|
44
|
+
name: z.ZodString;
|
|
45
|
+
role: z.ZodEnum<{
|
|
46
|
+
input: "input";
|
|
47
|
+
output: "output";
|
|
48
|
+
}>;
|
|
49
|
+
file: z.ZodObject<{
|
|
50
|
+
fileId: z.ZodString;
|
|
51
|
+
versionId: z.ZodString;
|
|
52
|
+
}, z.core.$strip>;
|
|
53
|
+
}, z.core.$strip>;
|
|
54
|
+
export declare const submitDeliverySchema: z.ZodObject<{
|
|
55
|
+
report: z.ZodString;
|
|
56
|
+
artifactIds: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
57
|
+
}, z.core.$strip>;
|
|
58
|
+
export declare const reviewDeliverySchema: z.ZodObject<{
|
|
59
|
+
submissionId: z.ZodString;
|
|
60
|
+
decision: z.ZodEnum<{
|
|
61
|
+
accepted: "accepted";
|
|
62
|
+
"changes-requested": "changes-requested";
|
|
63
|
+
}>;
|
|
64
|
+
comment: z.ZodDefault<z.ZodString>;
|
|
65
|
+
}, z.core.$strip>;
|
|
66
|
+
/** The future Files plugin supplies this resolver; no fallback file store exists. */
|
|
67
|
+
export interface FilesResolver {
|
|
68
|
+
getVersion(projectId: string, reference: FileReference): Promise<FileReference | null>;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=delivery.d.ts.map
|
package/dist/delivery.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export const emptyEvidence = () => ({ resources: [], submissions: [], reviews: [] });
|
|
3
|
+
export const fileReferenceSchema = z.object({ fileId: z.string().min(1), versionId: z.string().min(1) });
|
|
4
|
+
export const addResourceSchema = z.object({ name: z.string().trim().min(1), role: z.enum(["input", "output"]), file: fileReferenceSchema });
|
|
5
|
+
export const submitDeliverySchema = z.object({ report: z.string().trim().min(1), artifactIds: z.array(z.string()).default([]) });
|
|
6
|
+
export const reviewDeliverySchema = z.object({ submissionId: z.string().min(1), decision: z.enum(["accepted", "changes-requested"]), comment: z.string().default("") });
|
|
7
|
+
//# sourceMappingURL=delivery.js.map
|
package/dist/derive.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Author, Item, Provenance } from "./types.js";
|
|
2
|
+
export declare const isAi: (by: Author | string) => boolean;
|
|
3
|
+
export declare const isSync: (by: Author | string) => boolean;
|
|
4
|
+
/** Derived, never stored: a locked item reads as locked whoever wrote it last. */
|
|
5
|
+
export declare function provenanceOf(item: Pick<Item, "humanLocked" | "updatedBy">): Provenance;
|
|
6
|
+
/** 'Tomrade Next' -> 'TOM'. Falls back to a generic prefix for nameless input. */
|
|
7
|
+
export declare function keyPrefixFor(name: string): string;
|
|
8
|
+
//# sourceMappingURL=derive.d.ts.map
|
package/dist/derive.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const isAi = (by) => by.startsWith("ai:");
|
|
2
|
+
export const isSync = (by) => by.startsWith("sync:");
|
|
3
|
+
/** Derived, never stored: a locked item reads as locked whoever wrote it last. */
|
|
4
|
+
export function provenanceOf(item) {
|
|
5
|
+
if (item.humanLocked)
|
|
6
|
+
return "locked";
|
|
7
|
+
return isAi(item.updatedBy) ? "ai" : isSync(item.updatedBy) ? "sync" : "human";
|
|
8
|
+
}
|
|
9
|
+
/** 'Tomrade Next' -> 'TOM'. Falls back to a generic prefix for nameless input. */
|
|
10
|
+
export function keyPrefixFor(name) {
|
|
11
|
+
const letters = name.toUpperCase().replace(/[^A-Z]/g, "");
|
|
12
|
+
return letters.slice(0, 3) || "ISS";
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=derive.js.map
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export declare class ConflictError extends Error {
|
|
2
|
+
readonly itemId: string;
|
|
3
|
+
readonly expectedVersion: number;
|
|
4
|
+
readonly actualVersion: number;
|
|
5
|
+
constructor(itemId: string, expectedVersion: number, actualVersion: number);
|
|
6
|
+
}
|
|
7
|
+
export declare class HumanLockedError extends Error {
|
|
8
|
+
readonly itemId: string;
|
|
9
|
+
readonly fields: string[];
|
|
10
|
+
constructor(itemId: string, fields: string[]);
|
|
11
|
+
}
|
|
12
|
+
export declare class NotFoundError extends Error {
|
|
13
|
+
readonly itemId: string;
|
|
14
|
+
constructor(itemId: string);
|
|
15
|
+
}
|
|
16
|
+
/** The permanent delete refused because the caller is not a human. */
|
|
17
|
+
export declare class PurgeNotPermittedError extends Error {
|
|
18
|
+
readonly itemId: string;
|
|
19
|
+
readonly by: string;
|
|
20
|
+
constructor(itemId: string, by: string);
|
|
21
|
+
}
|
|
22
|
+
/** An extension claimed a human's authorship outside a human-initiated call. */
|
|
23
|
+
export declare class ExtensionAuthorError extends Error {
|
|
24
|
+
readonly pluginId: string;
|
|
25
|
+
readonly entity: string;
|
|
26
|
+
readonly op: string;
|
|
27
|
+
constructor(pluginId: string, entity: string, op: string);
|
|
28
|
+
}
|
|
29
|
+
/** A blocks edit refused because "blocked until done" only means something on a DAG. */
|
|
30
|
+
export declare class DependencyCycleError extends Error {
|
|
31
|
+
readonly itemId: string;
|
|
32
|
+
readonly path: string[];
|
|
33
|
+
constructor(itemId: string, path: string[]);
|
|
34
|
+
}
|
|
35
|
+
/** A destructive write refused because something still depends on the target. */
|
|
36
|
+
export declare class InUseError extends Error {
|
|
37
|
+
readonly entityId: string;
|
|
38
|
+
readonly reason: string;
|
|
39
|
+
constructor(entityId: string, reason: string);
|
|
40
|
+
}
|
|
41
|
+
/** A custom-field write refused: unknown field, wrong type, or an option the field does not have. */
|
|
42
|
+
export declare class FieldValueError extends Error {
|
|
43
|
+
readonly fieldId: string;
|
|
44
|
+
readonly reason: string;
|
|
45
|
+
constructor(fieldId: string, reason: string);
|
|
46
|
+
}
|
|
47
|
+
/** A field definition change refused: a built-in, a taken name, an option on a non-select. */
|
|
48
|
+
export declare class FieldDefinitionError extends Error {
|
|
49
|
+
readonly fieldId: string;
|
|
50
|
+
readonly reason: string;
|
|
51
|
+
constructor(fieldId: string, reason: string);
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=errors.d.ts.map
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
export class ConflictError extends Error {
|
|
2
|
+
itemId;
|
|
3
|
+
expectedVersion;
|
|
4
|
+
actualVersion;
|
|
5
|
+
constructor(itemId, expectedVersion, actualVersion) {
|
|
6
|
+
super(`Item ${itemId} version conflict: expected ${expectedVersion}, got ${actualVersion} (it was edited by someone else)`);
|
|
7
|
+
this.itemId = itemId;
|
|
8
|
+
this.expectedVersion = expectedVersion;
|
|
9
|
+
this.actualVersion = actualVersion;
|
|
10
|
+
this.name = "ConflictError";
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export class HumanLockedError extends Error {
|
|
14
|
+
itemId;
|
|
15
|
+
fields;
|
|
16
|
+
constructor(itemId, fields) {
|
|
17
|
+
super(`Item ${itemId} is human-locked; AI may not edit fields: ${fields.join(", ")}`);
|
|
18
|
+
this.itemId = itemId;
|
|
19
|
+
this.fields = fields;
|
|
20
|
+
this.name = "HumanLockedError";
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export class NotFoundError extends Error {
|
|
24
|
+
itemId;
|
|
25
|
+
constructor(itemId) {
|
|
26
|
+
super(`Item ${itemId} not found`);
|
|
27
|
+
this.itemId = itemId;
|
|
28
|
+
this.name = "NotFoundError";
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/** The permanent delete refused because the caller is not a human. */
|
|
32
|
+
export class PurgeNotPermittedError extends Error {
|
|
33
|
+
itemId;
|
|
34
|
+
by;
|
|
35
|
+
constructor(itemId, by) {
|
|
36
|
+
super(`Item ${itemId} may only be permanently deleted by a human; ${by} must use the reversible delete`);
|
|
37
|
+
this.itemId = itemId;
|
|
38
|
+
this.by = by;
|
|
39
|
+
this.name = "PurgeNotPermittedError";
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/** An extension claimed a human's authorship outside a human-initiated call. */
|
|
43
|
+
export class ExtensionAuthorError extends Error {
|
|
44
|
+
pluginId;
|
|
45
|
+
entity;
|
|
46
|
+
op;
|
|
47
|
+
constructor(pluginId, entity, op) {
|
|
48
|
+
super(`Extension ${pluginId} may not write as a human (${entity} ${op}) unless a person asked for it`);
|
|
49
|
+
this.pluginId = pluginId;
|
|
50
|
+
this.entity = entity;
|
|
51
|
+
this.op = op;
|
|
52
|
+
this.name = "ExtensionAuthorError";
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/** A blocks edit refused because "blocked until done" only means something on a DAG. */
|
|
56
|
+
export class DependencyCycleError extends Error {
|
|
57
|
+
itemId;
|
|
58
|
+
path;
|
|
59
|
+
constructor(itemId, path) {
|
|
60
|
+
super(`Blocking ${path[path.length - 1]} would close a cycle: ${path.join(" → ")}`);
|
|
61
|
+
this.itemId = itemId;
|
|
62
|
+
this.path = path;
|
|
63
|
+
this.name = "DependencyCycleError";
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/** A destructive write refused because something still depends on the target. */
|
|
67
|
+
export class InUseError extends Error {
|
|
68
|
+
entityId;
|
|
69
|
+
reason;
|
|
70
|
+
constructor(entityId, reason) {
|
|
71
|
+
super(reason);
|
|
72
|
+
this.entityId = entityId;
|
|
73
|
+
this.reason = reason;
|
|
74
|
+
this.name = "InUseError";
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/** A custom-field write refused: unknown field, wrong type, or an option the field does not have. */
|
|
78
|
+
export class FieldValueError extends Error {
|
|
79
|
+
fieldId;
|
|
80
|
+
reason;
|
|
81
|
+
constructor(fieldId, reason) {
|
|
82
|
+
super(`Field ${fieldId}: ${reason}`);
|
|
83
|
+
this.fieldId = fieldId;
|
|
84
|
+
this.reason = reason;
|
|
85
|
+
this.name = "FieldValueError";
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/** A field definition change refused: a built-in, a taken name, an option on a non-select. */
|
|
89
|
+
export class FieldDefinitionError extends Error {
|
|
90
|
+
fieldId;
|
|
91
|
+
reason;
|
|
92
|
+
constructor(fieldId, reason) {
|
|
93
|
+
super(`Field ${fieldId}: ${reason}`);
|
|
94
|
+
this.fieldId = fieldId;
|
|
95
|
+
this.reason = reason;
|
|
96
|
+
this.name = "FieldDefinitionError";
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=errors.js.map
|
package/dist/fields.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { FieldValue, Item, Patch } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Every attribute a view can filter, sort or group by is a field. Built-in
|
|
4
|
+
* fields are columns on `items` and are the same for every project; custom
|
|
5
|
+
* fields are rows in `fields` and their values live in `item_values`.
|
|
6
|
+
*/
|
|
7
|
+
export type FieldType = "text" | "number" | "date" | "select" | "checkbox" | "labels" | "item";
|
|
8
|
+
/** The types a user may create. The rest are built-in only. */
|
|
9
|
+
export declare const CUSTOM_FIELD_TYPES: readonly FieldType[];
|
|
10
|
+
/** A checkbox is stored only when ticked; unticked is the absence of a value. */
|
|
11
|
+
export declare const CHECKED = 1;
|
|
12
|
+
export interface FieldOption {
|
|
13
|
+
id: string;
|
|
14
|
+
name: string;
|
|
15
|
+
description: string | null;
|
|
16
|
+
rank: number;
|
|
17
|
+
}
|
|
18
|
+
export interface FieldDef {
|
|
19
|
+
id: string;
|
|
20
|
+
/** Null for a built-in: it exists in every project. */
|
|
21
|
+
projectId: string | null;
|
|
22
|
+
name: string;
|
|
23
|
+
type: FieldType;
|
|
24
|
+
builtin: boolean;
|
|
25
|
+
/** Fixed options for a select. Empty when they come from `optionsFrom`. */
|
|
26
|
+
options: FieldOption[];
|
|
27
|
+
/** Built-in selects whose options are rows elsewhere; the caller resolves them. */
|
|
28
|
+
optionsFrom?: "boards" | "epics";
|
|
29
|
+
/** Derived or system-owned: shown and sortable, never written. */
|
|
30
|
+
readonly: boolean;
|
|
31
|
+
can: {
|
|
32
|
+
filter: boolean;
|
|
33
|
+
sort: boolean;
|
|
34
|
+
group: boolean;
|
|
35
|
+
};
|
|
36
|
+
rank: number;
|
|
37
|
+
}
|
|
38
|
+
export type BuiltinFieldId = "title" | "status" | "workType" | "priority" | "epic" | "labels" | "board" | "updated" | "key" | "provenance";
|
|
39
|
+
/** The fields every project has, in display order. Ids are reserved: a custom field can never claim one. */
|
|
40
|
+
export declare const BUILTIN_FIELDS: readonly FieldDef[];
|
|
41
|
+
export declare const BUILTIN_FIELD_IDS: Set<string>;
|
|
42
|
+
export declare const isBuiltinFieldId: (id: string) => id is BuiltinFieldId;
|
|
43
|
+
/** The empty-value sentinel a group key uses, and the literal a filter may name. */
|
|
44
|
+
export declare const EMPTY_KEY = "none";
|
|
45
|
+
/**
|
|
46
|
+
* The raw value of a field on an item, built-in or custom. Labels are the one
|
|
47
|
+
* multi-valued field; everything else is a scalar or null.
|
|
48
|
+
*/
|
|
49
|
+
export declare function fieldValueOf(item: Item, fieldId: string): FieldValue | FieldValue[] | null;
|
|
50
|
+
/** Which column or swimlane an item falls into for a groupable field. */
|
|
51
|
+
export declare function groupKeyOf(item: Item, fieldId: string): string;
|
|
52
|
+
/** The patch a drop into `key` writes, for a groupable field; null when the field cannot be written. */
|
|
53
|
+
export declare function patchForGroup(fieldId: string, key: string, def: FieldDef | undefined): Patch | null;
|
|
54
|
+
//# sourceMappingURL=fields.d.ts.map
|
package/dist/fields.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { ITEM_STATUSES } from "./types.js";
|
|
2
|
+
/** The types a user may create. The rest are built-in only. */
|
|
3
|
+
export const CUSTOM_FIELD_TYPES = ["text", "number", "date", "select", "checkbox"];
|
|
4
|
+
/** A checkbox is stored only when ticked; unticked is the absence of a value. */
|
|
5
|
+
export const CHECKED = 1;
|
|
6
|
+
const PRIORITY_NAMES = ["None", "Low", "Medium", "High", "Urgent"];
|
|
7
|
+
const STATUS_NAMES = { backlog: "Backlog", todo: "To Do", doing: "Doing", verifying: "Verifying", done: "Done", cancelled: "Cancelled" };
|
|
8
|
+
const staticOptions = (ids, name) => ids.map((id, rank) => ({ id, name: name(id), description: null, rank }));
|
|
9
|
+
const builtin = (id, name, type, rank, extra = {}) => ({
|
|
10
|
+
id,
|
|
11
|
+
projectId: null,
|
|
12
|
+
name,
|
|
13
|
+
type,
|
|
14
|
+
builtin: true,
|
|
15
|
+
options: extra.options ?? [],
|
|
16
|
+
optionsFrom: extra.optionsFrom,
|
|
17
|
+
readonly: extra.readonly ?? false,
|
|
18
|
+
can: extra.can ?? { filter: true, sort: true, group: type === "select" || type === "item" },
|
|
19
|
+
rank
|
|
20
|
+
});
|
|
21
|
+
/** The fields every project has, in display order. Ids are reserved: a custom field can never claim one. */
|
|
22
|
+
export const BUILTIN_FIELDS = [
|
|
23
|
+
builtin("title", "Title", "text", 0, { can: { filter: true, sort: true, group: false } }),
|
|
24
|
+
builtin("status", "Status", "select", 1, { options: staticOptions(ITEM_STATUSES, (s) => STATUS_NAMES[s]) }),
|
|
25
|
+
builtin("workType", "Work type", "select", 9, { options: staticOptions(["coding", "general"], (s) => s === "coding" ? "Coding" : "General") }),
|
|
26
|
+
// Urgent first: the column order a priority board reads in.
|
|
27
|
+
builtin("priority", "Priority", "select", 2, { options: staticOptions(["4", "3", "2", "1", "0"], (p) => PRIORITY_NAMES[Number(p)]) }),
|
|
28
|
+
builtin("epic", "Epic", "item", 3, { optionsFrom: "epics" }),
|
|
29
|
+
builtin("labels", "Labels", "labels", 4, { can: { filter: true, sort: false, group: false } }),
|
|
30
|
+
builtin("board", "Workstream", "select", 5, { optionsFrom: "boards" }),
|
|
31
|
+
builtin("updated", "Updated", "date", 6, { readonly: true, can: { filter: true, sort: true, group: false } }),
|
|
32
|
+
builtin("key", "Key", "number", 7, { readonly: true, can: { filter: false, sort: true, group: false } }),
|
|
33
|
+
builtin("provenance", "Last write", "select", 8, {
|
|
34
|
+
readonly: true,
|
|
35
|
+
options: staticOptions(["human", "ai", "sync", "locked"], (p) => ({ human: "human", ai: "ai", sync: "sync", locked: "human-locked" })[p])
|
|
36
|
+
})
|
|
37
|
+
];
|
|
38
|
+
export const BUILTIN_FIELD_IDS = new Set(BUILTIN_FIELDS.map((f) => f.id));
|
|
39
|
+
export const isBuiltinFieldId = (id) => BUILTIN_FIELD_IDS.has(id);
|
|
40
|
+
/** The empty-value sentinel a group key uses, and the literal a filter may name. */
|
|
41
|
+
export const EMPTY_KEY = "none";
|
|
42
|
+
const provenanceOf = (item) => item.humanLocked ? "locked" : item.updatedBy.startsWith("ai:") ? "ai" : item.updatedBy.startsWith("sync:") ? "sync" : "human";
|
|
43
|
+
/**
|
|
44
|
+
* The raw value of a field on an item, built-in or custom. Labels are the one
|
|
45
|
+
* multi-valued field; everything else is a scalar or null.
|
|
46
|
+
*/
|
|
47
|
+
export function fieldValueOf(item, fieldId) {
|
|
48
|
+
switch (fieldId) {
|
|
49
|
+
case "title":
|
|
50
|
+
return item.title;
|
|
51
|
+
case "status":
|
|
52
|
+
return item.status;
|
|
53
|
+
case "workType":
|
|
54
|
+
return item.workType;
|
|
55
|
+
case "priority":
|
|
56
|
+
return String(item.priority);
|
|
57
|
+
case "epic":
|
|
58
|
+
return item.parentId;
|
|
59
|
+
case "labels":
|
|
60
|
+
return item.labels;
|
|
61
|
+
case "board":
|
|
62
|
+
return item.boardId;
|
|
63
|
+
case "updated":
|
|
64
|
+
return item.updatedAt;
|
|
65
|
+
case "key":
|
|
66
|
+
return item.keyNum;
|
|
67
|
+
case "provenance":
|
|
68
|
+
return provenanceOf(item);
|
|
69
|
+
default:
|
|
70
|
+
return item.fields[fieldId] ?? null;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/** Which column or swimlane an item falls into for a groupable field. */
|
|
74
|
+
export function groupKeyOf(item, fieldId) {
|
|
75
|
+
const v = fieldValueOf(item, fieldId);
|
|
76
|
+
if (v === null || Array.isArray(v))
|
|
77
|
+
return EMPTY_KEY;
|
|
78
|
+
return String(v);
|
|
79
|
+
}
|
|
80
|
+
/** The patch a drop into `key` writes, for a groupable field; null when the field cannot be written. */
|
|
81
|
+
export function patchForGroup(fieldId, key, def) {
|
|
82
|
+
const empty = key === EMPTY_KEY;
|
|
83
|
+
switch (fieldId) {
|
|
84
|
+
case "status":
|
|
85
|
+
return empty ? null : { status: key };
|
|
86
|
+
case "workType":
|
|
87
|
+
return key === "coding" || key === "general" ? { workType: key } : null;
|
|
88
|
+
case "priority":
|
|
89
|
+
return empty ? null : { priority: Number(key) };
|
|
90
|
+
case "epic":
|
|
91
|
+
return { parentId: empty ? null : key };
|
|
92
|
+
case "board":
|
|
93
|
+
return empty ? null : { boardId: key };
|
|
94
|
+
default:
|
|
95
|
+
if (!def || def.builtin)
|
|
96
|
+
return null;
|
|
97
|
+
if (def.type === "select")
|
|
98
|
+
return { fields: { [fieldId]: empty ? null : key } };
|
|
99
|
+
if (def.type === "checkbox")
|
|
100
|
+
return { fields: { [fieldId]: empty ? null : CHECKED } };
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=fields.js.map
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED