@kindgi/types 0.0.0-bootstrap.0 → 0.1.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/LICENSE +201 -0
- package/README.md +39 -2
- package/SPEC.md +162 -0
- package/dist/filter.d.ts +61 -0
- package/dist/filter.d.ts.map +1 -0
- package/dist/filter.js +4 -0
- package/dist/filter.js.map +1 -0
- package/dist/hash.d.ts +32 -0
- package/dist/hash.d.ts.map +1 -0
- package/dist/hash.js +4 -0
- package/dist/hash.js.map +1 -0
- package/dist/ids.d.ts +171 -0
- package/dist/ids.d.ts.map +1 -0
- package/dist/ids.js +15 -0
- package/dist/ids.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/refs.d.ts +58 -0
- package/dist/refs.d.ts.map +1 -0
- package/dist/refs.js +4 -0
- package/dist/refs.js.map +1 -0
- package/dist/result.d.ts +48 -0
- package/dist/result.d.ts.map +1 -0
- package/dist/result.js +4 -0
- package/dist/result.js.map +1 -0
- package/dist/temporal.d.ts +30 -0
- package/dist/temporal.d.ts.map +1 -0
- package/dist/temporal.js +4 -0
- package/dist/temporal.js.map +1 -0
- package/dist/version.d.ts +36 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +4 -0
- package/dist/version.js.map +1 -0
- package/package.json +46 -4
- package/src/filter.ts +66 -0
- package/src/hash.ts +37 -0
- package/src/ids.test-d.ts +54 -0
- package/src/ids.ts +225 -0
- package/src/index.ts +15 -0
- package/src/refs.test-d.ts +93 -0
- package/src/refs.ts +62 -0
- package/src/result.test-d.ts +59 -0
- package/src/result.ts +42 -0
- package/src/temporal.ts +35 -0
- package/src/version.ts +41 -0
- package/type-manifest.json +99 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Kindgi Inc.
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,40 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@kindgi/types`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Foundational TypeScript types shared across Kindgi. Almost entirely type-only: the single runtime export is `makeEnvName`, the validated constructor for `EnvName`.
|
|
4
|
+
|
|
5
|
+
## Purpose
|
|
6
|
+
|
|
7
|
+
Provide the canonical, branded ID types and reference shapes used across Kindgi, preventing whole classes of bugs at compile time (you cannot pass a `TenantId` where a `UserId` is expected) with no runtime cost.
|
|
8
|
+
|
|
9
|
+
## Exports
|
|
10
|
+
|
|
11
|
+
- **Branded IDs** — `TenantId`, `UserId`, `OrgId`, `TeamId`, `ProjectId`, `ThreadId`, `ConversationId`, `SessionId`, `RunId`, `FlowId`, `NodeId`, `EdgeId`, `AgentId`, `ToolId`, `GuardrailId`, `PolicyId`, `PackId`, `EventId`, `FactId`, `LogEntryId`, `ArtifactId`, `ProvenanceId`, `SubscriptionId`, `ApprovalId`, `ReviewerId`, `SupervisorId`, `ObservationId`, `FixProposalId`, `AuditBundleId`, `ComplianceEvidenceId`, `WaitTokenId`, `DatasetId`, `ScheduleId`, `ProviderId`, `ApiTokenId`, `WebhookId`, `WebhookEndpointId`, `WebhookEventId`, `WebhookDeliveryId`, `InstallationId`, `SigningKeyId`, `TriggerId`.
|
|
12
|
+
- **Environment names** — `EnvName` (`[a-z][a-z0-9-]{0,62}`) and `makeEnvName(raw)`, which returns the branded value or `null` on a grammar violation.
|
|
13
|
+
- **Brand utility** — `Brand<T, B>` for constructing pack-scoped IDs (e.g. a `MatterId` in a pack that tracks legal matters).
|
|
14
|
+
- **Temporal** — `Timestamp` (ISO 8601 UTC branded string), `DurationMs`, `IsoDuration`.
|
|
15
|
+
- **Hash & signature** — `ContentHash` (`sha256:<hex>`), `SignatureValue` (base64 Ed25519), `KeyId`.
|
|
16
|
+
- **References** — `BlobRef` (blob provider handle), `DatasetRef`.
|
|
17
|
+
- **Result** — `Result<T, E>` discriminated union with runtime `kind` tag, plus `OkOf<R>` / `ErrOf<R>` extractors.
|
|
18
|
+
- **Version** — `Semver`, `SchemaMajor`, `VersionedRef<Id>`.
|
|
19
|
+
- **Lists** — `Cursor` (opaque pagination cursor), `Filter<TStatus>` (shared list-filter shape), `Page<T>` (`{ items, nextCursor?, truncated? }`).
|
|
20
|
+
|
|
21
|
+
## Example
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import type { TenantId, Result, BlobRef, ContentHash } from '@kindgi/types';
|
|
25
|
+
|
|
26
|
+
function ingest(tenantId: TenantId, ref: BlobRef): Result<void, { code: string }> {
|
|
27
|
+
if (ref.tenantId !== tenantId) {
|
|
28
|
+
return { kind: 'err', error: { code: 'cross-tenant-blob' } };
|
|
29
|
+
}
|
|
30
|
+
return { kind: 'ok', value: undefined };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const hash: ContentHash = 'sha256:abc123...' as ContentHash;
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Non-goals
|
|
37
|
+
|
|
38
|
+
- **No runtime validation.** Branded types are compile-time only. Validation of wire payloads lives in `@kindgi/schema`; `makeEnvName` is the one exception.
|
|
39
|
+
- **No constructors.** Construction is by `as` cast, except `makeEnvName` for `EnvName`.
|
|
40
|
+
- **No business logic.** Only types that are used by two or more packages belong here. Package-scoped types stay in that package.
|
package/SPEC.md
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# `@kindgi/types` — Specification
|
|
2
|
+
|
|
3
|
+
*Deep spec for humans. Complements the JSON Schemas in `@kindgi/specs` which are wire contracts.*
|
|
4
|
+
|
|
5
|
+
## Design principles
|
|
6
|
+
|
|
7
|
+
1. **Type-only, with one exception.** Every export is a `type` except `makeEnvName`, the validated `EnvName` factory. Consumers pay zero runtime cost for using branded types.
|
|
8
|
+
2. **Nominal typing via brands.** Every entity ID is nominally distinct from any other. A `TenantId` and a `UserId` are both structurally `string`, but statically incompatible. Cross-boundary confusion becomes a compile error.
|
|
9
|
+
3. **Correspondence to JSON Schemas.** Most entity kinds in `@kindgi/specs/*.schema.json` have a branded ID here (eval suites, for one, do not). If a schema defines a new entity kind, its ID goes here. Some IDs (e.g. `ConversationId`, `TriggerId`) name entities that have no schema.
|
|
10
|
+
4. **Two or more consumers rule.** A type belongs in `@kindgi/types` only if two or more packages use it. Package-scoped types stay in that package.
|
|
11
|
+
|
|
12
|
+
## Brand mechanism
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
type Brand<T, B extends string> = T & { readonly __brand: B };
|
|
16
|
+
type TenantId = Brand<string, 'TenantId'>;
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
The `__brand` field is a phantom marker — it does not exist at runtime. TypeScript treats `TenantId` and `UserId` as incompatible because their brand strings differ, even though both are structurally `string`.
|
|
20
|
+
|
|
21
|
+
### Construction
|
|
22
|
+
|
|
23
|
+
A branded type is constructed by cast:
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
const tenant = 'abc' as TenantId;
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
There is no runtime constructor, except `makeEnvName(raw)`, which returns an `EnvName` or `null` when `raw` breaks the `[a-z][a-z0-9-]{0,62}` grammar. Other validated construction (`"abc"` matches the tenant-id pattern before it's accepted) belongs in `@kindgi/schema`.
|
|
30
|
+
|
|
31
|
+
### Interop with strings
|
|
32
|
+
|
|
33
|
+
Branded types are usable anywhere a `string` is, because they are structurally strings:
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
const t: TenantId = 'abc' as TenantId;
|
|
37
|
+
t.length; // number
|
|
38
|
+
t + '-suffix'; // string (unbranded — the operation drops the brand)
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
The brand is lost by any operation that produces a new string. This is intentional — brands convey provenance, not identity, so re-branding requires re-casting.
|
|
42
|
+
|
|
43
|
+
## The canonical scope hierarchy
|
|
44
|
+
|
|
45
|
+
Kindgi models five scoping constructs. Every pack and every UI can rename these in its own vernacular (legal → "matter", HR → "case"), but Kindgi's code and specs always use the canonical terms.
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
Tenant — sovereignty boundary (customer). Cross-tenant access is absolutely denied.
|
|
49
|
+
├── Org (opt) — optional structural subdivision (litigation dept, cardiology). Small tenants ignore.
|
|
50
|
+
├── Team — people-group (a working group). Users can belong to many teams.
|
|
51
|
+
│ Teams hold relations on projects; users inherit access via team membership.
|
|
52
|
+
└── Project — scoped work-context (matter/case/engagement/episode).
|
|
53
|
+
│ Collaborators are users OR teams. Project-level roles (owner, editor, viewer).
|
|
54
|
+
└── Content — facts, artifacts, runs, blobs. Every piece of content belongs to a project.
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Two things worth emphasizing:
|
|
58
|
+
|
|
59
|
+
**Team and Project are orthogonal.** Team is people; Project is context. Same team works on many projects; same project can have many teams collaborating. Conflating them is the classic anti-pattern (Slack channels, most groupware) — separating them cleanly is what makes cross-vertical mapping trivial.
|
|
60
|
+
|
|
61
|
+
**Team ≠ Org.** Org is *structural* (a firm's departments, a hospital's specialties). Team is *operational* (a specific working group formed for specific projects). A large firm has few orgs and many teams; a small firm has no orgs and a handful of teams.
|
|
62
|
+
|
|
63
|
+
## Category tour
|
|
64
|
+
|
|
65
|
+
### IDs (`src/ids.ts`)
|
|
66
|
+
|
|
67
|
+
Entity kinds that appear in `@kindgi/specs/*.schema.json` and their branded IDs; the table lists the main ones (see `src/ids.ts` for the full set, including `ConversationId`, `ReviewerId`, `SupervisorId`, `ObservationId`, `FixProposalId`, `AuditBundleId`, `ScheduleId`, `ProviderId`, `ApiTokenId`, `WebhookId`, `WebhookEndpointId`, `WebhookEventId`, `WebhookDeliveryId`, `InstallationId`, `SigningKeyId`, `TriggerId`):
|
|
68
|
+
|
|
69
|
+
| Schema entity | Type |
|
|
70
|
+
|---|---|
|
|
71
|
+
| Tenant (scope in `memory`, `policy`, `blob`, etc.) | `TenantId` |
|
|
72
|
+
| User | `UserId` |
|
|
73
|
+
| Organization (optional structural subdivision) | `OrgId` |
|
|
74
|
+
| Team (people-group; holds relations, not context) | `TeamId` |
|
|
75
|
+
| Project (matter/case/engagement, vertical-agnostic) | `ProjectId` |
|
|
76
|
+
| Thread | `ThreadId` |
|
|
77
|
+
| Session | `SessionId` |
|
|
78
|
+
| Run (one execution of a flow) | `RunId` |
|
|
79
|
+
| Flow | `FlowId` |
|
|
80
|
+
| Flow node | `NodeId` |
|
|
81
|
+
| Flow edge | `EdgeId` |
|
|
82
|
+
| Agent | `AgentId` |
|
|
83
|
+
| Tool | `ToolId` |
|
|
84
|
+
| Guardrail | `GuardrailId` |
|
|
85
|
+
| Policy document | `PolicyId` |
|
|
86
|
+
| Pack manifest | `PackId` |
|
|
87
|
+
| Event | `EventId` |
|
|
88
|
+
| Fact | `FactId` |
|
|
89
|
+
| Log entry | `LogEntryId` |
|
|
90
|
+
| Artifact (agent output) | `ArtifactId` |
|
|
91
|
+
| Provenance DAG | `ProvenanceId` |
|
|
92
|
+
| Event subscription | `SubscriptionId` |
|
|
93
|
+
| Approval request | `ApprovalId` |
|
|
94
|
+
| Compliance evidence bundle | `ComplianceEvidenceId` |
|
|
95
|
+
| Wait token | `WaitTokenId` |
|
|
96
|
+
| Dataset | `DatasetId` |
|
|
97
|
+
|
|
98
|
+
### Temporal (`src/temporal.ts`)
|
|
99
|
+
|
|
100
|
+
- `Timestamp` — always an ISO 8601 UTC string with `Z` suffix. Kept as a string (not `Date`) for JSON serializability and deterministic lexicographic ordering (which matches temporal order for well-formed ISO 8601).
|
|
101
|
+
- `DurationMs` — branded `number` for millisecond durations.
|
|
102
|
+
- `IsoDuration` — branded string for ISO 8601 durations (e.g. `PT30S`, `P1D`). Preferred in declarative artifacts.
|
|
103
|
+
|
|
104
|
+
### Hash & signature (`src/hash.ts`)
|
|
105
|
+
|
|
106
|
+
- `ContentHash` — `<algo>:<hex>` format (currently `sha256:<64 hex>`). Consumers must reject unknown algorithms so future migration to sha3/blake3 is non-breaking.
|
|
107
|
+
- `SignatureValue` — base64 (padded, non-URL-safe) Ed25519 signature.
|
|
108
|
+
- `KeyId` — opaque, provider-qualified identifier for a signing key; interpreted by whichever key provider resolves it. Keys in a `SigningKeyBinding` (`@kindgi/crypto`) are addressed by `SigningKeyId` instead.
|
|
109
|
+
|
|
110
|
+
### References (`src/refs.ts`)
|
|
111
|
+
|
|
112
|
+
- `BlobRef` — handle to bytes in object storage. Contains provider + bucket + key + size + hash + content type + tenant + timestamps. Never constructed by hand; always produced by the storage layer that wrote the bytes.
|
|
113
|
+
- `DatasetRef` — handle to a versioned dataset: a collection of memory Facts of one declared type (e.g. eval corpora).
|
|
114
|
+
|
|
115
|
+
### Result (`src/result.ts`)
|
|
116
|
+
|
|
117
|
+
Discriminated union with runtime `kind: 'ok' | 'err'` tag. The codebase's standard shape for functions that can fail expectedly (as opposed to throwing for unexpected failure).
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
type Result<T, E> =
|
|
121
|
+
| { readonly kind: 'ok'; readonly value: T }
|
|
122
|
+
| { readonly kind: 'err'; readonly error: E };
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Two helper types:
|
|
126
|
+
- `OkOf<R>` — extract success type from a Result.
|
|
127
|
+
- `ErrOf<R>` — extract error type from a Result.
|
|
128
|
+
|
|
129
|
+
### Version (`src/version.ts`)
|
|
130
|
+
|
|
131
|
+
- `Semver` — branded string matching `<major>.<minor>.<patch>[-prerelease]`.
|
|
132
|
+
- `SchemaMajor` — branded positive integer for use in schema `$id` paths.
|
|
133
|
+
- `VersionedRef<Id>` — combines a branded ID with an exact `Semver`, used for pinning artifacts to specific versions.
|
|
134
|
+
|
|
135
|
+
### Lists (`src/filter.ts`)
|
|
136
|
+
|
|
137
|
+
- `Cursor` — opaque pagination cursor; pass it back verbatim.
|
|
138
|
+
- `Filter<TStatus>` — shared list-filter shape: `status`, `since`, `until`, `limit`, `cursor`.
|
|
139
|
+
- `Page<T>` — shared list-result envelope: `{ items, nextCursor?, truncated? }`.
|
|
140
|
+
|
|
141
|
+
## Test approach
|
|
142
|
+
|
|
143
|
+
Type-only tests via vitest typecheck mode (`vitest run --typecheck`):
|
|
144
|
+
|
|
145
|
+
- `.test-d.ts` files under `src/` are compiled by TS in typecheck mode.
|
|
146
|
+
- Use `expectTypeOf(x).toEqualTypeOf<T>()` for positive assertions.
|
|
147
|
+
- Use `// @ts-expect-error` immediately above lines that MUST fail compilation.
|
|
148
|
+
- No runtime assertions in this package — the one runtime export, `makeEnvName`, is exercised by the `@kindgi/env-inmemory` tests.
|
|
149
|
+
|
|
150
|
+
Coverage includes:
|
|
151
|
+
- ID nominal distinctness (positive + negative).
|
|
152
|
+
- ID structural string behavior (length, `.toString()`).
|
|
153
|
+
- Result narrowing via `kind` discriminator.
|
|
154
|
+
- Result readonly semantics.
|
|
155
|
+
- BlobRef required-field enforcement.
|
|
156
|
+
- Brand utility composition for pack-scoped IDs.
|
|
157
|
+
|
|
158
|
+
## Change discipline
|
|
159
|
+
|
|
160
|
+
Adding a new branded ID or shape is non-breaking. Removing or renaming one is a semver major bump for this package — downstream consumers reference by import name, and rename would break the world.
|
|
161
|
+
|
|
162
|
+
When a new entity kind lands in a `@kindgi/specs/*.schema.json`, its branded ID **must** be added here in the same PR. Enforced by review, not by tooling.
|
package/dist/filter.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { Brand } from './ids.js';
|
|
2
|
+
import type { Timestamp } from './temporal.js';
|
|
3
|
+
/**
|
|
4
|
+
* Opaque pagination cursor. Producers return a `Cursor`; consumers pass
|
|
5
|
+
* it back verbatim to the next list call. The value is implementation-
|
|
6
|
+
* defined (usually a timestamp or opaque token) — callers must not
|
|
7
|
+
* parse or construct one by hand.
|
|
8
|
+
*/
|
|
9
|
+
export type Cursor = Brand<string, 'Cursor'>;
|
|
10
|
+
/**
|
|
11
|
+
* Shared list-filter shape. List inputs extend this (e.g. the team and
|
|
12
|
+
* project bindings in `@kindgi/platform`) so resources share one
|
|
13
|
+
* facet-filter shape.
|
|
14
|
+
*
|
|
15
|
+
* `TStatus` narrows the `status` field per-resource (e.g. the
|
|
16
|
+
* `ApprovalStatus`, `FixProposalStatus` and `ObservationStatus` unions
|
|
17
|
+
* in `@kindgi/api`).
|
|
18
|
+
*
|
|
19
|
+
* All fields are optional. A caller can pass an empty `Filter` to get
|
|
20
|
+
* the default page.
|
|
21
|
+
*/
|
|
22
|
+
export interface Filter<TStatus extends string = string> {
|
|
23
|
+
/**
|
|
24
|
+
* Filter to one status or a set of statuses. The resource-specific
|
|
25
|
+
* input type narrows TStatus so consumers get autocomplete on the
|
|
26
|
+
* allowed values.
|
|
27
|
+
*/
|
|
28
|
+
readonly status?: TStatus | readonly TStatus[];
|
|
29
|
+
/**
|
|
30
|
+
* Lower bound on the resource's canonical timestamp — typically
|
|
31
|
+
* `createdAt` or `observedAt`. Inclusive. Absent = no lower bound.
|
|
32
|
+
*/
|
|
33
|
+
readonly since?: Timestamp;
|
|
34
|
+
/**
|
|
35
|
+
* Upper bound on the resource's canonical timestamp. Inclusive.
|
|
36
|
+
* Absent = no upper bound.
|
|
37
|
+
*/
|
|
38
|
+
readonly until?: Timestamp;
|
|
39
|
+
/**
|
|
40
|
+
* Max items to return. Producers clamp to a resource-specific ceiling
|
|
41
|
+
* (typically 500). Default page size is producer-defined.
|
|
42
|
+
*/
|
|
43
|
+
readonly limit?: number;
|
|
44
|
+
/** Opaque cursor from a prior list call's `nextCursor` field. */
|
|
45
|
+
readonly cursor?: Cursor;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Shared list-result envelope. List producers that use it return
|
|
49
|
+
* `{ items, nextCursor? }`. Consumers keep calling with `cursor:
|
|
50
|
+
* result.nextCursor` until it's absent.
|
|
51
|
+
*
|
|
52
|
+
* `truncated: true` explicitly signals "more items exist beyond the
|
|
53
|
+
* cursor" for aggregators that don't paginate but should still know
|
|
54
|
+
* they missed data.
|
|
55
|
+
*/
|
|
56
|
+
export interface Page<T> {
|
|
57
|
+
readonly items: readonly T[];
|
|
58
|
+
readonly nextCursor?: Cursor;
|
|
59
|
+
readonly truncated?: boolean;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=filter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filter.d.ts","sourceRoot":"","sources":["../src/filter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE/C;;;;;GAKG;AACH,MAAM,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AAE7C;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,MAAM,CAAC,OAAO,SAAS,MAAM,GAAG,MAAM;IACrD;;;;OAIG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,GAAG,SAAS,OAAO,EAAE,CAAC;IAC/C;;;OAGG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,CAAC;IAC3B;;;OAGG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,CAAC;IAC3B;;;OAGG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,iEAAiE;IACjE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,IAAI,CAAC,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC,EAAE,CAAC;IAC7B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;CAC9B"}
|
package/dist/filter.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filter.js","sourceRoot":"","sources":["../src/filter.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,iCAAiC"}
|
package/dist/hash.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Brand } from './ids.js';
|
|
2
|
+
/**
|
|
3
|
+
* A content-addressed hash of a payload, formatted as `<algo>:<hex>`.
|
|
4
|
+
*
|
|
5
|
+
* Current supported algorithms:
|
|
6
|
+
* - `sha256:<64 hex chars>`
|
|
7
|
+
*
|
|
8
|
+
* Meant for content addressing: tamper-evident provenance node content,
|
|
9
|
+
* blob dedup at ingest, memory LogEntry / Fact content hashes.
|
|
10
|
+
*
|
|
11
|
+
* The prefix is significant: consumers must reject hashes without a recognized
|
|
12
|
+
* algorithm prefix, so future migration to sha3 or blake3 is non-breaking.
|
|
13
|
+
*/
|
|
14
|
+
export type ContentHash = Brand<string, 'ContentHash'>;
|
|
15
|
+
/**
|
|
16
|
+
* An Ed25519 signature over some canonical serialization, base64-encoded.
|
|
17
|
+
*
|
|
18
|
+
* Format is padded base64 (RFC 4648 §4). No URL-safe variants — canonical form
|
|
19
|
+
* for interoperability with signing tools.
|
|
20
|
+
*/
|
|
21
|
+
export type SignatureValue = Brand<string, 'SignatureValue'>;
|
|
22
|
+
/**
|
|
23
|
+
* Identifier for a signing key in provider-qualified form. Opaque to Kindgi;
|
|
24
|
+
* interpreted by whichever key provider resolves it. (Keys held in a
|
|
25
|
+
* `SigningKeyBinding` from `@kindgi/crypto` are addressed by `SigningKeyId`.)
|
|
26
|
+
*
|
|
27
|
+
* Convention: `<provider>:<key-name>` (e.g. `ed25519-local:tenant-abc-v1`,
|
|
28
|
+
* `hsm:pkcs11:slot-3:key-42`, `kms:aws:arn:aws:kms:...`). Consumers should
|
|
29
|
+
* treat this string as opaque and let the provider resolve it.
|
|
30
|
+
*/
|
|
31
|
+
export type KeyId = Brand<string, 'KeyId'>;
|
|
32
|
+
//# sourceMappingURL=hash.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEtC;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;AAEvD;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GAAG,KAAK,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;AAE7D;;;;;;;;GAQG;AACH,MAAM,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC"}
|
package/dist/hash.js
ADDED
package/dist/hash.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.js","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,iCAAiC"}
|