@manya-os/contracts 1.0.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.
Files changed (46) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/LICENSE +20 -0
  3. package/README.md +223 -0
  4. package/dist/cjs/index.js +4 -0
  5. package/dist/cjs/index.js.map +6 -0
  6. package/dist/cjs/package.json +1 -0
  7. package/dist/esm/index.mjs +4 -0
  8. package/dist/esm/index.mjs.map +6 -0
  9. package/dist/esm/package.json +1 -0
  10. package/dist/types/api/api.d.ts +43 -0
  11. package/dist/types/api/api.d.ts.map +1 -0
  12. package/dist/types/api/index.d.ts +2 -0
  13. package/dist/types/api/index.d.ts.map +1 -0
  14. package/dist/types/boundaries/boundaries.d.ts +62 -0
  15. package/dist/types/boundaries/boundaries.d.ts.map +1 -0
  16. package/dist/types/boundaries/index.d.ts +3 -0
  17. package/dist/types/boundaries/index.d.ts.map +1 -0
  18. package/dist/types/compatibility/compatibility.d.ts +58 -0
  19. package/dist/types/compatibility/compatibility.d.ts.map +1 -0
  20. package/dist/types/compatibility/index.d.ts +2 -0
  21. package/dist/types/compatibility/index.d.ts.map +1 -0
  22. package/dist/types/errors.d.ts +65 -0
  23. package/dist/types/errors.d.ts.map +1 -0
  24. package/dist/types/index.d.ts +34 -0
  25. package/dist/types/index.d.ts.map +1 -0
  26. package/dist/types/logging.d.ts +38 -0
  27. package/dist/types/logging.d.ts.map +1 -0
  28. package/dist/types/manifest/index.d.ts +2 -0
  29. package/dist/types/manifest/index.d.ts.map +1 -0
  30. package/dist/types/manifest/manifest.d.ts +24 -0
  31. package/dist/types/manifest/manifest.d.ts.map +1 -0
  32. package/dist/types/reporting/index.d.ts +2 -0
  33. package/dist/types/reporting/index.d.ts.map +1 -0
  34. package/dist/types/reporting/reporting.d.ts +37 -0
  35. package/dist/types/reporting/reporting.d.ts.map +1 -0
  36. package/dist/types/schema/index.d.ts +3 -0
  37. package/dist/types/schema/index.d.ts.map +1 -0
  38. package/dist/types/schema/schema.d.ts +77 -0
  39. package/dist/types/schema/schema.d.ts.map +1 -0
  40. package/dist/types/sync/index.d.ts +2 -0
  41. package/dist/types/sync/index.d.ts.map +1 -0
  42. package/dist/types/sync/sync.d.ts +36 -0
  43. package/dist/types/sync/sync.d.ts.map +1 -0
  44. package/dist/types/types.d.ts +215 -0
  45. package/dist/types/types.d.ts.map +1 -0
  46. package/package.json +47 -0
@@ -0,0 +1,215 @@
1
+ /**
2
+ * @manya-os/contracts — shared type definitions.
3
+ *
4
+ * Defines every public type used across the contracts package: schema
5
+ * primitives, manifests, semver versions, API contracts, schema diffs,
6
+ * boundary policies, and validation reports.
7
+ *
8
+ * Copyright 2024 Manya Hael Foundation. All rights reserved.
9
+ * Licensed under the Apache License, Version 2.0.
10
+ */
11
+ /**
12
+ * The set of schema type names supported by the contracts schema language.
13
+ *
14
+ * - `string` / `number` / `boolean` — JSON primitives.
15
+ * - `null` — the explicit null value.
16
+ * - `object` — a nested record (use `fields` on the `SchemaField`).
17
+ * - `array` — a homogeneous list (use `of` on the `SchemaField`).
18
+ * - `enum` — one of a fixed set of values (use `enum` on the `SchemaField`).
19
+ * - `ref` — a reference to another `InterfaceSchema` by name (use `ref`).
20
+ * - `union` — one of several types (use `oneOf`).
21
+ * - `intersection` — all of several types (use `allOf`).
22
+ */
23
+ export type SchemaType = 'string' | 'number' | 'boolean' | 'null' | 'object' | 'array' | 'enum' | 'ref' | 'union' | 'intersection';
24
+ /**
25
+ * A single field on an `InterfaceSchema`. The base shape matches the public
26
+ * spec; the extension fields (`of`, `ref`, `oneOf`, `allOf`, `fields`) are
27
+ * used to express composite types and are ignored when not applicable.
28
+ */
29
+ export interface SchemaField {
30
+ /** Field name. */
31
+ name: string;
32
+ /** Field type discriminator. */
33
+ type: SchemaType;
34
+ /** Whether the field must be present (and non-`undefined`). */
35
+ required: boolean;
36
+ /** Human-readable description. */
37
+ description?: string;
38
+ /** Default value applied when the field is missing and not required. */
39
+ default?: unknown;
40
+ /** Allowed values for `enum` fields. */
41
+ enum?: unknown[];
42
+ /** Element type for `array` fields. */
43
+ of?: SchemaField;
44
+ /** Referenced schema name for `ref` fields. */
45
+ ref?: string;
46
+ /** Member types for `union` fields. */
47
+ oneOf?: SchemaField[];
48
+ /** Member types for `intersection` fields. */
49
+ allOf?: SchemaField[];
50
+ /** Nested fields for `object` fields. */
51
+ fields?: SchemaField[];
52
+ }
53
+ /** A named, versioned interface schema. */
54
+ export interface InterfaceSchema {
55
+ /** Schema name (PascalCase by convention). */
56
+ name: string;
57
+ /** Schema version (semver). */
58
+ version: string;
59
+ /** Field list. */
60
+ fields: SchemaField[];
61
+ /** Human-readable description. */
62
+ description?: string;
63
+ }
64
+ /**
65
+ * A parsed semantic version. Follows semver.org: `MAJOR.MINOR.PATCH` with an
66
+ * optional `-prerelease` suffix.
67
+ */
68
+ export interface SemverVersion {
69
+ major: number;
70
+ minor: number;
71
+ patch: number;
72
+ prerelease?: string;
73
+ }
74
+ /** A package manifest describing name, version, dependencies, and surface. */
75
+ export interface Manifest {
76
+ /** Package name (lowercase, scoped or unscoped). */
77
+ name: string;
78
+ /** Semver version string. */
79
+ version: string;
80
+ /** Map of dependency name → version range. */
81
+ dependencies?: Record<string, string>;
82
+ /** Exported symbols or paths. */
83
+ exports?: string[];
84
+ /** Imported symbols or paths. */
85
+ imports?: string[];
86
+ /** Declared capabilities (e.g. `crypto`, `network`, `filesystem`). */
87
+ capabilities?: string[];
88
+ }
89
+ /** A single validation error with a stable `code` for programmatic handling. */
90
+ export interface ValidationError {
91
+ /** Dotted path to the offending field (e.g. `user.address.zip`). */
92
+ path: string;
93
+ /** Human-readable error message. */
94
+ message: string;
95
+ /** Stable machine code (often an `*Error` code from `errors.ts`). */
96
+ code: string;
97
+ /** Expected type or shape. */
98
+ expected?: string;
99
+ /** Actual type or value observed. */
100
+ actual?: string;
101
+ }
102
+ /** The result of any validation routine. */
103
+ export interface ValidationResult {
104
+ /** Whether validation succeeded. */
105
+ valid: boolean;
106
+ /** Errors produced during validation (empty iff `valid === true`). */
107
+ errors: ValidationError[];
108
+ }
109
+ /**
110
+ * A breaking change detected by `checkBackwardCompat`.
111
+ *
112
+ * - `field_removed` — a field that existed in the old schema is gone.
113
+ * - `type_changed` — a field's type changed incompatibly.
114
+ * - `required_added` — a new required field was added (callers can't satisfy it).
115
+ * - `enum_value_removed` — an `enum` field lost a value.
116
+ */
117
+ export interface BreakingChange {
118
+ type: 'field_removed' | 'type_changed' | 'required_added' | 'enum_value_removed';
119
+ /** Field path the change applies to. */
120
+ field?: string;
121
+ /** Previous value/type description. */
122
+ from?: string;
123
+ /** New value/type description. */
124
+ to?: string;
125
+ }
126
+ /**
127
+ * An API endpoint contract.
128
+ */
129
+ export interface ApiEndpoint {
130
+ /** HTTP method. */
131
+ method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
132
+ /** Route path (e.g. `/users/:id`). */
133
+ path: string;
134
+ /** Optional request body schema. */
135
+ requestSchema?: InterfaceSchema;
136
+ /** Response body schema (required). */
137
+ responseSchema: InterfaceSchema;
138
+ }
139
+ /** A named, versioned collection of API endpoints. */
140
+ export interface ApiContract {
141
+ /** Contract name. */
142
+ name: string;
143
+ /** Contract version (semver). */
144
+ version: string;
145
+ /** Endpoint list. */
146
+ endpoints: ApiEndpoint[];
147
+ }
148
+ /**
149
+ * A diff between two schemas. `removed` is a list of field names; `added` and
150
+ * `changed` carry full field descriptors.
151
+ */
152
+ export interface SchemaDiff {
153
+ /** Fields present in `newSchema` but not `oldSchema`. */
154
+ added: SchemaField[];
155
+ /** Field names present in `oldSchema` but not `newSchema`. */
156
+ removed: string[];
157
+ /** Fields present in both whose definition changed. */
158
+ changed: Array<{
159
+ field: string;
160
+ from: SchemaField;
161
+ to: SchemaField;
162
+ }>;
163
+ }
164
+ /** A conflict between two schema versions of the same field. */
165
+ export interface SchemaConflict {
166
+ /** Field path that conflicts. */
167
+ field: string;
168
+ /** Local field type name. */
169
+ localType: string;
170
+ /** Remote field type name. */
171
+ remoteType: string;
172
+ /** How the conflict was (or should be) resolved. */
173
+ resolution: 'local' | 'remote' | 'manual';
174
+ }
175
+ /** A single boundary rule: `from` may call `to` iff `allowed === true`. */
176
+ export interface BoundaryRule {
177
+ /** Caller module name. */
178
+ from: string;
179
+ /** Callee module name. */
180
+ to: string;
181
+ /** Whether the call is allowed. */
182
+ allowed: boolean;
183
+ /** Optional human-readable reason. */
184
+ reason?: string;
185
+ }
186
+ /** A named boundary policy: a list of rules plus a default-allow flag. */
187
+ export interface BoundaryPolicy {
188
+ /** Policy name. */
189
+ name: string;
190
+ /** Rule list. */
191
+ rules: BoundaryRule[];
192
+ /** Default action when no rule matches. */
193
+ defaultAllow: boolean;
194
+ }
195
+ /** A single section in a `ValidationReport`. */
196
+ export interface ValidationReportSection {
197
+ /** Section name (e.g. `manifest`, `schema`, `compatibility`). */
198
+ name: string;
199
+ /** Whether this section passed. */
200
+ passed: boolean;
201
+ /** Errors produced by this section. */
202
+ errors: ValidationError[];
203
+ }
204
+ /** A complete validation report. */
205
+ export interface ValidationReport {
206
+ /** Report name (typically the artifact under validation). */
207
+ name: string;
208
+ /** Overall pass/fail (true iff every section passed). */
209
+ passed: boolean;
210
+ /** Per-section results. */
211
+ sections: ValidationReportSection[];
212
+ /** ISO 8601 timestamp. */
213
+ generatedAt: string;
214
+ }
215
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,UAAU,GAClB,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,MAAM,GACxC,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,KAAK,GACnC,OAAO,GAAG,cAAc,CAAC;AAE7B;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC1B,kBAAkB;IAClB,IAAI,EAAE,MAAM,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M,CAAC;IACb,yDAAyD;IACzD,MAAM,EAAE,OAAO,CAAC;IAChB,2BAA2B;IAC3B,QAAQ,EAAE,uBAAuB,EAAE,CAAC;IACpC,0BAA0B;IAC1B,WAAW,EAAE,MAAM,CAAC;CACrB"}
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@manya-os/contracts",
3
+ "version": "1.0.0",
4
+ "description": "Universal contract and schema validation for the MANYA Intelligence OS — interface schemas, manifests, semver compatibility, API contracts, schema sync, boundary enforcement, and validation reports.",
5
+ "main": "dist/cjs/index.js",
6
+ "types": "dist/types/index.d.ts",
7
+ "scripts": {
8
+ "build": "node ../../scripts/build-package.js contracts",
9
+ "test": "jest",
10
+ "clean": "rm -rf dist build node_modules",
11
+ "build:types": "node ../../scripts/build-types.js contracts",
12
+ "build:bundle": "node ../../scripts/build-package.js contracts --no-types && node ../../scripts/build-types.js contracts"
13
+ },
14
+ "keywords": [
15
+ "manya",
16
+ "contracts",
17
+ "schema",
18
+ "validation",
19
+ "manifest",
20
+ "semver",
21
+ "compatibility",
22
+ "api",
23
+ "boundaries",
24
+ "interface"
25
+ ],
26
+ "author": "Uviwe Menyiwe (Azura Daemon) <foundation@manyahael.org>",
27
+ "license": "Apache-2.0",
28
+ "dependencies": {},
29
+ "devDependencies": {},
30
+ "module": "dist/esm/index.mjs",
31
+ "exports": {
32
+ ".": {
33
+ "types": "./dist/types/index.d.ts",
34
+ "require": "./dist/cjs/index.js",
35
+ "import": "./dist/esm/index.mjs",
36
+ "default": "./dist/cjs/index.js"
37
+ },
38
+ "./package.json": "./package.json"
39
+ },
40
+ "sideEffects": false,
41
+ "files": [
42
+ "dist",
43
+ "README.md",
44
+ "CHANGELOG.md",
45
+ "LICENSE"
46
+ ]
47
+ }