@dynamicalsystems/idl 0.11.0 → 0.12.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.
@@ -0,0 +1,219 @@
1
+ // dsg.organization.source/2
2
+ // Closed authoring contracts for an organization source tree. These declarations
3
+ // describe reviewed inputs only: they contain no live principals, grants,
4
+ // admissions, activation state, or deployment authority.
5
+ import { type Static, Type } from "@sinclair/typebox";
6
+ import { closed, NonEmptyString, SafeInt, type ProfileEntry } from "../primitives.js";
7
+
8
+ export const ORGANIZATION_SOURCE_PROFILE = "dsg.organization.source/2" as const;
9
+
10
+ export const OrganizationSpaceSchema = Type.String({
11
+ pattern: "^[a-z][a-z0-9-]*(?:\\.[a-z][a-z0-9-]*)+$",
12
+ });
13
+
14
+ /** A path interpreted relative to the organization source root. Filesystem
15
+ * containment and symlink checks belong to the consumer that opens it. */
16
+ export const OrganizationDocumentPathSchema = Type.String({
17
+ minLength: 1,
18
+ pattern: "^(?!/)(?!.*(?:^|/)\\.\\.(?:/|$))(?!.*//)(?!.*\\\\).+$",
19
+ });
20
+
21
+ export const OrganizationSourceLocationSchema = closed({
22
+ repository: NonEmptyString,
23
+ ref: NonEmptyString,
24
+ subdirectory: OrganizationDocumentPathSchema,
25
+ });
26
+ export type OrganizationSourceLocation = Static<typeof OrganizationSourceLocationSchema>;
27
+ const OrganizationSourceLocationV1Schema = closed({
28
+ repository: Type.String(),
29
+ ref: Type.String(),
30
+ subdirectory: Type.String(),
31
+ });
32
+ export type OrganizationSourceLocationV1 = Static<typeof OrganizationSourceLocationV1Schema>;
33
+
34
+ export const ProjectSourceSchema = closed({
35
+ repository: NonEmptyString,
36
+ revision: Type.String({ pattern: "^(?:[0-9a-f]{40}|[0-9a-f]{64})$" }),
37
+ });
38
+ export type ProjectSource = Static<typeof ProjectSourceSchema>;
39
+
40
+ const UniquePaths = () => Type.Array(OrganizationDocumentPathSchema, { uniqueItems: true });
41
+ const UniqueNames = () => Type.Array(NonEmptyString, { uniqueItems: true });
42
+
43
+ /** Frozen compatibility shape. Version one is loaded only through the explicit
44
+ * compatibility path; it is never silently reinterpreted as version two. */
45
+ export const OrganizationRootV1Schema = closed({
46
+ schemaVersion: Type.Literal(1),
47
+ kind: Type.Literal("organization"),
48
+ org: NonEmptyString,
49
+ space: OrganizationSpaceSchema,
50
+ identity: closed({
51
+ principals: NonEmptyString,
52
+ qualifications: NonEmptyString,
53
+ designations: NonEmptyString,
54
+ }),
55
+ policies: NonEmptyString,
56
+ vocabulary: NonEmptyString,
57
+ admissions: NonEmptyString,
58
+ deployment: NonEmptyString,
59
+ source: Type.Optional(OrganizationSourceLocationV1Schema),
60
+ });
61
+ export type OrganizationRootV1 = Static<typeof OrganizationRootV1Schema>;
62
+
63
+ export const OrganizationInstructionSchema = closed({
64
+ layer: Type.Union([
65
+ Type.Literal("constitution"),
66
+ Type.Literal("profile"),
67
+ Type.Literal("project"),
68
+ ]),
69
+ source: OrganizationDocumentPathSchema,
70
+ provenance: OrganizationDocumentPathSchema,
71
+ });
72
+ export type OrganizationInstruction = Static<typeof OrganizationInstructionSchema>;
73
+
74
+ /** The generic root requires only stable identity, accountability, purpose and
75
+ * a selected profile. Optional declaration groups become required only when
76
+ * that profile says so. */
77
+ export const OrganizationRootSchema = closed({
78
+ schemaVersion: Type.Literal(2),
79
+ kind: Type.Literal("organization"),
80
+ org: NonEmptyString,
81
+ space: OrganizationSpaceSchema,
82
+ owner: closed({
83
+ responsibility: NonEmptyString,
84
+ qualification: Type.Optional(OrganizationDocumentPathSchema),
85
+ designation: Type.Optional(OrganizationDocumentPathSchema),
86
+ }),
87
+ purpose: NonEmptyString,
88
+ profile: closed({
89
+ document: OrganizationDocumentPathSchema,
90
+ facts: Type.Record(
91
+ Type.String({ pattern: "^[a-z][a-z0-9-]*$" }),
92
+ OrganizationDocumentPathSchema,
93
+ { additionalProperties: false },
94
+ ),
95
+ }),
96
+ identity: Type.Optional(
97
+ closed({
98
+ principals: Type.Optional(OrganizationDocumentPathSchema),
99
+ qualifications: Type.Optional(OrganizationDocumentPathSchema),
100
+ designations: Type.Optional(OrganizationDocumentPathSchema),
101
+ eligibility: Type.Optional(OrganizationDocumentPathSchema),
102
+ }),
103
+ ),
104
+ policies: Type.Optional(
105
+ closed({
106
+ sources: Type.Array(OrganizationDocumentPathSchema, { minItems: 1, uniqueItems: true }),
107
+ release: Type.Optional(OrganizationDocumentPathSchema),
108
+ }),
109
+ ),
110
+ vocabulary: Type.Optional(OrganizationDocumentPathSchema),
111
+ admissions: Type.Optional(OrganizationDocumentPathSchema),
112
+ projects: Type.Optional(UniquePaths()),
113
+ capabilities: Type.Optional(UniquePaths()),
114
+ instructions: Type.Optional(Type.Array(OrganizationInstructionSchema)),
115
+ documents: Type.Optional(UniquePaths()),
116
+ archive: Type.Optional(OrganizationDocumentPathSchema),
117
+ releases: Type.Optional(UniquePaths()),
118
+ deployment: Type.Optional(OrganizationDocumentPathSchema),
119
+ source: Type.Optional(OrganizationSourceLocationSchema),
120
+ });
121
+ export type OrganizationRoot = Static<typeof OrganizationRootSchema>;
122
+
123
+ export const WorkspaceProfileSchema = closed({
124
+ schemaVersion: Type.Literal(1),
125
+ kind: Type.Literal("workspace-profile"),
126
+ id: NonEmptyString,
127
+ profile: Type.Literal(ORGANIZATION_SOURCE_PROFILE),
128
+ version: Type.String({ pattern: "^[1-9][0-9]*\\.[0-9]+\\.[0-9]+$" }),
129
+ requirements: closed({
130
+ facts: UniqueNames(),
131
+ minimumProjects: SafeInt,
132
+ requiredCapabilities: UniqueNames(),
133
+ instructions: Type.Boolean(),
134
+ }),
135
+ allowedCapabilityOrigins: Type.Array(
136
+ Type.Union([Type.Literal("workspace"), Type.Literal("official"), Type.Literal("curated")]),
137
+ { uniqueItems: true },
138
+ ),
139
+ handling: closed({ required: Type.Boolean() }),
140
+ readinessChecks: UniquePaths(),
141
+ });
142
+ export type WorkspaceProfile = Static<typeof WorkspaceProfileSchema>;
143
+
144
+ export const ProjectMembershipSchema = closed({
145
+ schemaVersion: Type.Literal(1),
146
+ kind: Type.Literal("project-membership"),
147
+ id: NonEmptyString,
148
+ mode: Type.Union([Type.Literal("managed"), Type.Literal("independent")]),
149
+ source: ProjectSourceSchema,
150
+ role: NonEmptyString,
151
+ contract: OrganizationDocumentPathSchema,
152
+ handling: OrganizationDocumentPathSchema,
153
+ state: Type.Union([Type.Literal("active"), Type.Literal("suspended"), Type.Literal("removed")]),
154
+ });
155
+ export type ProjectMembership = Static<typeof ProjectMembershipSchema>;
156
+
157
+ export const CapabilityOriginSchema = Type.Union([
158
+ Type.Literal("workspace"),
159
+ Type.Literal("official"),
160
+ Type.Literal("curated"),
161
+ ]);
162
+ export type CapabilityOrigin = Static<typeof CapabilityOriginSchema>;
163
+
164
+ /** `declaration` and component `reference` point to their owning existing
165
+ * capability/Definition formats; this schema does not duplicate them. */
166
+ export const CapabilitySelectionSchema = closed({
167
+ schemaVersion: Type.Literal(1),
168
+ kind: Type.Literal("capability-selection"),
169
+ id: NonEmptyString,
170
+ declaration: OrganizationDocumentPathSchema,
171
+ components: Type.Array(
172
+ closed({ id: NonEmptyString, reference: OrganizationDocumentPathSchema }),
173
+ { uniqueItems: true },
174
+ ),
175
+ origin: CapabilityOriginSchema,
176
+ dependencyLock: OrganizationDocumentPathSchema,
177
+ requiredDispositions: UniqueNames(),
178
+ });
179
+ export type CapabilitySelection = Static<typeof CapabilitySelectionSchema>;
180
+
181
+ export const ReleaseMemberKindSchema = Type.Union([
182
+ Type.Literal("policy"),
183
+ Type.Literal("capability-admission"),
184
+ Type.Literal("workflow-publication"),
185
+ Type.Literal("contract-check"),
186
+ Type.Literal("target-readiness"),
187
+ Type.Literal("setup-condition"),
188
+ ]);
189
+ export type ReleaseMemberKind = Static<typeof ReleaseMemberKindSchema>;
190
+
191
+ export const ReleaseDeclarationSchema = closed({
192
+ schemaVersion: Type.Literal(1),
193
+ kind: Type.Literal("release-declaration"),
194
+ name: NonEmptyString,
195
+ selection: closed({ projects: UniqueNames(), capabilities: UniqueNames() }),
196
+ members: Type.Array(
197
+ closed({
198
+ key: NonEmptyString,
199
+ artifact: OrganizationDocumentPathSchema,
200
+ kind: ReleaseMemberKindSchema,
201
+ required: Type.Boolean(),
202
+ acceptableDispositions: Type.Array(NonEmptyString, { minItems: 1, uniqueItems: true }),
203
+ }),
204
+ ),
205
+ predecessors: UniqueNames(),
206
+ });
207
+ export type ReleaseDeclaration = Static<typeof ReleaseDeclarationSchema>;
208
+
209
+ export const organizationSourceV2: ProfileEntry = {
210
+ literal: ORGANIZATION_SOURCE_PROFILE,
211
+ rootDocument: "organization",
212
+ documents: {
213
+ organization: OrganizationRootSchema,
214
+ workspaceProfile: WorkspaceProfileSchema,
215
+ projectMembership: ProjectMembershipSchema,
216
+ capabilitySelection: CapabilitySelectionSchema,
217
+ releaseDeclaration: ReleaseDeclarationSchema,
218
+ },
219
+ };