@originals/sdk 1.2.0 → 1.4.2
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/package.json +1 -1
- package/src/did/DIDManager.ts +1 -1
- package/src/did/WebVHManager.ts +11 -2
- package/src/examples/create-module-original.ts +435 -0
- package/src/examples/full-lifecycle-flow.ts +514 -0
- package/src/examples/run.ts +59 -4
- package/src/index.ts +69 -3
- package/src/kinds/KindRegistry.ts +290 -0
- package/src/kinds/index.ts +74 -0
- package/src/kinds/types.ts +470 -0
- package/src/kinds/validators/AgentValidator.ts +257 -0
- package/src/kinds/validators/AppValidator.ts +211 -0
- package/src/kinds/validators/DatasetValidator.ts +242 -0
- package/src/kinds/validators/DocumentValidator.ts +311 -0
- package/src/kinds/validators/MediaValidator.ts +269 -0
- package/src/kinds/validators/ModuleValidator.ts +225 -0
- package/src/kinds/validators/base.ts +276 -0
- package/src/kinds/validators/index.ts +12 -0
- package/src/lifecycle/LifecycleManager.ts +909 -1
- package/src/resources/ResourceManager.ts +655 -0
- package/src/resources/index.ts +21 -0
- package/src/resources/types.ts +202 -0
- package/src/types/common.ts +1 -1
- package/src/vc/CredentialManager.ts +647 -2
- package/tests/integration/createTypedOriginal.test.ts +379 -0
- package/tests/performance/BatchOperations.perf.test.ts +2 -2
- package/tests/unit/kinds/KindRegistry.test.ts +329 -0
- package/tests/unit/kinds/types.test.ts +409 -0
- package/tests/unit/kinds/validators.test.ts +651 -0
- package/tests/unit/lifecycle/LifecycleManager.cleanapi.test.ts +441 -0
- package/tests/unit/resources/ResourceManager.test.ts +740 -0
- package/tests/unit/vc/CredentialManager.helpers.test.ts +527 -0
- package/.turbo/turbo-build.log +0 -1
- package/dist/adapters/FeeOracleMock.d.ts +0 -6
- package/dist/adapters/FeeOracleMock.js +0 -8
- package/dist/adapters/index.d.ts +0 -4
- package/dist/adapters/index.js +0 -4
- package/dist/adapters/providers/OrdHttpProvider.d.ts +0 -56
- package/dist/adapters/providers/OrdHttpProvider.js +0 -110
- package/dist/adapters/providers/OrdMockProvider.d.ts +0 -70
- package/dist/adapters/providers/OrdMockProvider.js +0 -75
- package/dist/adapters/types.d.ts +0 -71
- package/dist/adapters/types.js +0 -1
- package/dist/bitcoin/BitcoinManager.d.ts +0 -15
- package/dist/bitcoin/BitcoinManager.js +0 -262
- package/dist/bitcoin/BroadcastClient.d.ts +0 -30
- package/dist/bitcoin/BroadcastClient.js +0 -35
- package/dist/bitcoin/OrdinalsClient.d.ts +0 -21
- package/dist/bitcoin/OrdinalsClient.js +0 -105
- package/dist/bitcoin/PSBTBuilder.d.ts +0 -24
- package/dist/bitcoin/PSBTBuilder.js +0 -80
- package/dist/bitcoin/fee-calculation.d.ts +0 -14
- package/dist/bitcoin/fee-calculation.js +0 -31
- package/dist/bitcoin/providers/OrdNodeProvider.d.ts +0 -38
- package/dist/bitcoin/providers/OrdNodeProvider.js +0 -67
- package/dist/bitcoin/providers/OrdinalsProvider.d.ts +0 -33
- package/dist/bitcoin/providers/OrdinalsProvider.js +0 -50
- package/dist/bitcoin/providers/types.d.ts +0 -63
- package/dist/bitcoin/providers/types.js +0 -1
- package/dist/bitcoin/transactions/commit.d.ts +0 -89
- package/dist/bitcoin/transactions/commit.js +0 -311
- package/dist/bitcoin/transactions/index.d.ts +0 -7
- package/dist/bitcoin/transactions/index.js +0 -8
- package/dist/bitcoin/transfer.d.ts +0 -9
- package/dist/bitcoin/transfer.js +0 -26
- package/dist/bitcoin/utxo-selection.d.ts +0 -78
- package/dist/bitcoin/utxo-selection.js +0 -237
- package/dist/bitcoin/utxo.d.ts +0 -26
- package/dist/bitcoin/utxo.js +0 -78
- package/dist/contexts/credentials-v1.json +0 -195
- package/dist/contexts/credentials-v2-examples.json +0 -5
- package/dist/contexts/credentials-v2.json +0 -301
- package/dist/contexts/credentials.json +0 -195
- package/dist/contexts/data-integrity-v2.json +0 -81
- package/dist/contexts/dids.json +0 -57
- package/dist/contexts/ed255192020.json +0 -93
- package/dist/contexts/ordinals-plus.json +0 -23
- package/dist/contexts/originals.json +0 -22
- package/dist/core/OriginalsSDK.d.ts +0 -158
- package/dist/core/OriginalsSDK.js +0 -274
- package/dist/crypto/Multikey.d.ts +0 -30
- package/dist/crypto/Multikey.js +0 -149
- package/dist/crypto/Signer.d.ts +0 -21
- package/dist/crypto/Signer.js +0 -196
- package/dist/crypto/noble-init.d.ts +0 -18
- package/dist/crypto/noble-init.js +0 -106
- package/dist/did/BtcoDidResolver.d.ts +0 -57
- package/dist/did/BtcoDidResolver.js +0 -166
- package/dist/did/DIDManager.d.ts +0 -101
- package/dist/did/DIDManager.js +0 -493
- package/dist/did/Ed25519Verifier.d.ts +0 -30
- package/dist/did/Ed25519Verifier.js +0 -59
- package/dist/did/KeyManager.d.ts +0 -17
- package/dist/did/KeyManager.js +0 -207
- package/dist/did/WebVHManager.d.ts +0 -100
- package/dist/did/WebVHManager.js +0 -304
- package/dist/did/createBtcoDidDocument.d.ts +0 -10
- package/dist/did/createBtcoDidDocument.js +0 -42
- package/dist/did/providers/OrdinalsClientProviderAdapter.d.ts +0 -23
- package/dist/did/providers/OrdinalsClientProviderAdapter.js +0 -51
- package/dist/events/EventEmitter.d.ts +0 -115
- package/dist/events/EventEmitter.js +0 -198
- package/dist/events/index.d.ts +0 -7
- package/dist/events/index.js +0 -6
- package/dist/events/types.d.ts +0 -286
- package/dist/events/types.js +0 -9
- package/dist/examples/basic-usage.d.ts +0 -3
- package/dist/examples/basic-usage.js +0 -62
- package/dist/examples/run.d.ts +0 -1
- package/dist/examples/run.js +0 -4
- package/dist/index.d.ts +0 -39
- package/dist/index.js +0 -47
- package/dist/lifecycle/BatchOperations.d.ts +0 -147
- package/dist/lifecycle/BatchOperations.js +0 -251
- package/dist/lifecycle/LifecycleManager.d.ts +0 -116
- package/dist/lifecycle/LifecycleManager.js +0 -971
- package/dist/lifecycle/OriginalsAsset.d.ts +0 -164
- package/dist/lifecycle/OriginalsAsset.js +0 -380
- package/dist/lifecycle/ProvenanceQuery.d.ts +0 -126
- package/dist/lifecycle/ProvenanceQuery.js +0 -220
- package/dist/lifecycle/ResourceVersioning.d.ts +0 -73
- package/dist/lifecycle/ResourceVersioning.js +0 -127
- package/dist/migration/MigrationManager.d.ts +0 -86
- package/dist/migration/MigrationManager.js +0 -412
- package/dist/migration/audit/AuditLogger.d.ts +0 -51
- package/dist/migration/audit/AuditLogger.js +0 -156
- package/dist/migration/checkpoint/CheckpointManager.d.ts +0 -31
- package/dist/migration/checkpoint/CheckpointManager.js +0 -96
- package/dist/migration/checkpoint/CheckpointStorage.d.ts +0 -26
- package/dist/migration/checkpoint/CheckpointStorage.js +0 -89
- package/dist/migration/index.d.ts +0 -22
- package/dist/migration/index.js +0 -27
- package/dist/migration/operations/BaseMigration.d.ts +0 -48
- package/dist/migration/operations/BaseMigration.js +0 -83
- package/dist/migration/operations/PeerToBtcoMigration.d.ts +0 -25
- package/dist/migration/operations/PeerToBtcoMigration.js +0 -67
- package/dist/migration/operations/PeerToWebvhMigration.d.ts +0 -19
- package/dist/migration/operations/PeerToWebvhMigration.js +0 -46
- package/dist/migration/operations/WebvhToBtcoMigration.d.ts +0 -25
- package/dist/migration/operations/WebvhToBtcoMigration.js +0 -67
- package/dist/migration/rollback/RollbackManager.d.ts +0 -29
- package/dist/migration/rollback/RollbackManager.js +0 -146
- package/dist/migration/state/StateMachine.d.ts +0 -25
- package/dist/migration/state/StateMachine.js +0 -76
- package/dist/migration/state/StateTracker.d.ts +0 -36
- package/dist/migration/state/StateTracker.js +0 -123
- package/dist/migration/types.d.ts +0 -306
- package/dist/migration/types.js +0 -33
- package/dist/migration/validation/BitcoinValidator.d.ts +0 -13
- package/dist/migration/validation/BitcoinValidator.js +0 -83
- package/dist/migration/validation/CredentialValidator.d.ts +0 -13
- package/dist/migration/validation/CredentialValidator.js +0 -46
- package/dist/migration/validation/DIDCompatibilityValidator.d.ts +0 -16
- package/dist/migration/validation/DIDCompatibilityValidator.js +0 -127
- package/dist/migration/validation/LifecycleValidator.d.ts +0 -10
- package/dist/migration/validation/LifecycleValidator.js +0 -52
- package/dist/migration/validation/StorageValidator.d.ts +0 -10
- package/dist/migration/validation/StorageValidator.js +0 -65
- package/dist/migration/validation/ValidationPipeline.d.ts +0 -29
- package/dist/migration/validation/ValidationPipeline.js +0 -180
- package/dist/storage/LocalStorageAdapter.d.ts +0 -11
- package/dist/storage/LocalStorageAdapter.js +0 -53
- package/dist/storage/MemoryStorageAdapter.d.ts +0 -6
- package/dist/storage/MemoryStorageAdapter.js +0 -21
- package/dist/storage/StorageAdapter.d.ts +0 -16
- package/dist/storage/StorageAdapter.js +0 -1
- package/dist/storage/index.d.ts +0 -2
- package/dist/storage/index.js +0 -2
- package/dist/types/bitcoin.d.ts +0 -84
- package/dist/types/bitcoin.js +0 -1
- package/dist/types/common.d.ts +0 -82
- package/dist/types/common.js +0 -1
- package/dist/types/credentials.d.ts +0 -75
- package/dist/types/credentials.js +0 -1
- package/dist/types/did.d.ts +0 -26
- package/dist/types/did.js +0 -1
- package/dist/types/index.d.ts +0 -5
- package/dist/types/index.js +0 -5
- package/dist/types/network.d.ts +0 -78
- package/dist/types/network.js +0 -145
- package/dist/utils/EventLogger.d.ts +0 -71
- package/dist/utils/EventLogger.js +0 -232
- package/dist/utils/Logger.d.ts +0 -106
- package/dist/utils/Logger.js +0 -257
- package/dist/utils/MetricsCollector.d.ts +0 -110
- package/dist/utils/MetricsCollector.js +0 -264
- package/dist/utils/bitcoin-address.d.ts +0 -38
- package/dist/utils/bitcoin-address.js +0 -113
- package/dist/utils/cbor.d.ts +0 -2
- package/dist/utils/cbor.js +0 -9
- package/dist/utils/encoding.d.ts +0 -37
- package/dist/utils/encoding.js +0 -120
- package/dist/utils/hash.d.ts +0 -1
- package/dist/utils/hash.js +0 -5
- package/dist/utils/retry.d.ts +0 -10
- package/dist/utils/retry.js +0 -35
- package/dist/utils/satoshi-validation.d.ts +0 -60
- package/dist/utils/satoshi-validation.js +0 -156
- package/dist/utils/serialization.d.ts +0 -14
- package/dist/utils/serialization.js +0 -76
- package/dist/utils/telemetry.d.ts +0 -17
- package/dist/utils/telemetry.js +0 -24
- package/dist/utils/validation.d.ts +0 -5
- package/dist/utils/validation.js +0 -98
- package/dist/vc/CredentialManager.d.ts +0 -22
- package/dist/vc/CredentialManager.js +0 -227
- package/dist/vc/Issuer.d.ts +0 -27
- package/dist/vc/Issuer.js +0 -70
- package/dist/vc/Verifier.d.ts +0 -16
- package/dist/vc/Verifier.js +0 -50
- package/dist/vc/cryptosuites/bbs.d.ts +0 -44
- package/dist/vc/cryptosuites/bbs.js +0 -213
- package/dist/vc/cryptosuites/bbsSimple.d.ts +0 -9
- package/dist/vc/cryptosuites/bbsSimple.js +0 -12
- package/dist/vc/cryptosuites/eddsa.d.ts +0 -30
- package/dist/vc/cryptosuites/eddsa.js +0 -81
- package/dist/vc/documentLoader.d.ts +0 -16
- package/dist/vc/documentLoader.js +0 -59
- package/dist/vc/proofs/data-integrity.d.ts +0 -21
- package/dist/vc/proofs/data-integrity.js +0 -15
- package/dist/vc/utils/jsonld.d.ts +0 -2
- package/dist/vc/utils/jsonld.js +0 -15
- package/test/logs/did_webvh_QmNTn9Kkp8dQ75WrF9xqJ2kuDp9QhKc3aPiERRMj8XoTBN_example_com.jsonl +0 -1
- package/test/logs/did_webvh_QmNu4MNr8Lr5txx5gYNhuhZDchXsZEu3hJXKYuphpWTPDp_example_com_users_etc_passwd.jsonl +0 -1
- package/test/logs/did_webvh_QmR9MrGZACzjKETA8SBRNCKG11HxU85c4bVR2qN5eDCfsD_example_com.jsonl +0 -1
- package/test/logs/did_webvh_QmUc5suaqRM2P4nrXxZwqYMfqzhdMqjuL7oJaJbEpCQVCd_example_com_users_etc_passwd.jsonl +0 -1
- package/test/logs/did_webvh_QmUkiB2RCV2VZ1RTXsCebWN25Eiy9TLvpzDWAJNjhgvB4X_example_com_etc_passwd.jsonl +0 -1
- package/test/logs/did_webvh_QmUoRTe8UMwpAQXZSAW7pjAgZK1tq2X3C6Kfxq3UXGcaGy_example_com_secret.jsonl +0 -1
- package/test/logs/did_webvh_QmWWot3chx1t6KwTmcE5i2FeDZ5JMkQw3qXycsKDVmJ9Be_example_com_users_alice.jsonl +0 -1
- package/test/logs/did_webvh_QmWvVgALL5kjZdpgR7KZay7J8UiiUr834kkRmWeFAxjAuC_example_com_users_etc_passwd.jsonl +0 -1
- package/test/logs/did_webvh_QmWwaRQHUZAFcKihFC6xR6tRTTrQhHPTku6azf1egWbpy1_example_com_users_alice.jsonl +0 -1
- package/test/logs/did_webvh_QmXJLtkz23r7AozbtXsZMKWnVU6rd38CkVtjdWuATU3Yp6_example_com_users_alice123_profile.jsonl +0 -1
- package/test/logs/did_webvh_QmYsce448po14oDE1wXbyaP6wY9HQgHSKLwdezn1k577SF_example_com_my_org_user_name_test_123.jsonl +0 -1
- package/test/logs/did_webvh_QmZBeNzzqajxdfwcDUPZ4P8C5YSXyRztrAwmPiKuKUxmAK_example_com.jsonl +0 -1
- package/test/logs/did_webvh_QmZhJsqxizwVbRtqCUkmE6XQunSxtxMt3gbTYadVBNAaEq_example_com.jsonl +0 -1
- package/test/logs/did_webvh_QmZk7NHU2D57RzzbMq4tWW9gBa9AqtVTWfiRM6RFdwGVj2_example_com.jsonl +0 -1
- package/test/logs/did_webvh_QmZshSXp9w8ovH62zGGBS1b5pGGPsuYiu1VQ935sga2hWF_example_com_level1_level2.jsonl +0 -1
- package/test/logs/did_webvh_QmbWAmw7HQL7vKJyCsctZihXf1rmT4sGvggKCPKWcUWjw1_example_com.jsonl +0 -1
- package/test/logs/did_webvh_QmbdLUMbYs3juR39TLB6hhrFWLcNg45ybUzeBJCS1MhCh1_example_com_C_Windows_System32.jsonl +0 -1
- package/test/logs/did_webvh_QmcaQ1Ma4gkSbae85aCm8Mv4rvdT2Sb2RR3JzYwrm5XBq8_example_com_etc_passwd.jsonl +0 -1
- package/test/logs/did_webvh_QmcbA7WQhsBqZSoDpKJHjV8Q5o53h8vmgJhQfo6rqTY5ho_example_com.jsonl +0 -1
- package/test/logs/did_webvh_Qmdy8uWr2gkUJrXsThynAug3DASTWwb3onEj89LKmMGZYB_example_com.jsonl +0 -1
- package/tests/e2e/README.md +0 -97
- package/tests/e2e/example.spec.ts +0 -78
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kind Registry
|
|
3
|
+
*
|
|
4
|
+
* Central registry for Original kinds, providing validation and type management.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
OriginalKind,
|
|
9
|
+
type OriginalManifest,
|
|
10
|
+
type ValidationResult,
|
|
11
|
+
type CreateTypedOriginalOptions,
|
|
12
|
+
} from './types';
|
|
13
|
+
import {
|
|
14
|
+
type KindValidator,
|
|
15
|
+
ValidationUtils,
|
|
16
|
+
AppValidator,
|
|
17
|
+
AgentValidator,
|
|
18
|
+
ModuleValidator,
|
|
19
|
+
DatasetValidator,
|
|
20
|
+
MediaValidator,
|
|
21
|
+
DocumentValidator,
|
|
22
|
+
} from './validators';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Registry for Original kinds
|
|
26
|
+
*
|
|
27
|
+
* Provides centralized validation and type information for all kinds.
|
|
28
|
+
*/
|
|
29
|
+
export class KindRegistry {
|
|
30
|
+
private static instance: KindRegistry;
|
|
31
|
+
private validators: Map<OriginalKind, KindValidator<OriginalKind>>;
|
|
32
|
+
|
|
33
|
+
private constructor() {
|
|
34
|
+
this.validators = new Map();
|
|
35
|
+
this.registerDefaultValidators();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Get the singleton instance
|
|
40
|
+
*/
|
|
41
|
+
static getInstance(): KindRegistry {
|
|
42
|
+
if (!KindRegistry.instance) {
|
|
43
|
+
KindRegistry.instance = new KindRegistry();
|
|
44
|
+
}
|
|
45
|
+
return KindRegistry.instance;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Register default validators for all built-in kinds
|
|
50
|
+
*/
|
|
51
|
+
private registerDefaultValidators(): void {
|
|
52
|
+
this.validators.set(OriginalKind.App, new AppValidator());
|
|
53
|
+
this.validators.set(OriginalKind.Agent, new AgentValidator());
|
|
54
|
+
this.validators.set(OriginalKind.Module, new ModuleValidator());
|
|
55
|
+
this.validators.set(OriginalKind.Dataset, new DatasetValidator());
|
|
56
|
+
this.validators.set(OriginalKind.Media, new MediaValidator());
|
|
57
|
+
this.validators.set(OriginalKind.Document, new DocumentValidator());
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Register a custom validator for a kind
|
|
62
|
+
* Can be used to override built-in validators or add new kinds
|
|
63
|
+
*/
|
|
64
|
+
registerValidator<K extends OriginalKind>(
|
|
65
|
+
kind: K,
|
|
66
|
+
validator: KindValidator<K>
|
|
67
|
+
): void {
|
|
68
|
+
this.validators.set(kind, validator as KindValidator<OriginalKind>);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Get the validator for a kind
|
|
73
|
+
*/
|
|
74
|
+
getValidator<K extends OriginalKind>(kind: K): KindValidator<K> | undefined {
|
|
75
|
+
return this.validators.get(kind) as KindValidator<K> | undefined;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Check if a kind is registered
|
|
80
|
+
*/
|
|
81
|
+
hasKind(kind: OriginalKind): boolean {
|
|
82
|
+
return this.validators.has(kind);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Get all registered kinds
|
|
87
|
+
*/
|
|
88
|
+
getRegisteredKinds(): OriginalKind[] {
|
|
89
|
+
return Array.from(this.validators.keys());
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Validate a manifest
|
|
94
|
+
*
|
|
95
|
+
* @param manifest - The manifest to validate
|
|
96
|
+
* @param options - Validation options
|
|
97
|
+
* @returns Validation result
|
|
98
|
+
*/
|
|
99
|
+
validate<K extends OriginalKind>(
|
|
100
|
+
manifest: OriginalManifest<K>,
|
|
101
|
+
options?: CreateTypedOriginalOptions
|
|
102
|
+
): ValidationResult {
|
|
103
|
+
// First check if kind is valid
|
|
104
|
+
if (!manifest.kind) {
|
|
105
|
+
return ValidationUtils.failure([
|
|
106
|
+
ValidationUtils.error('MISSING_KIND', 'Manifest must specify a kind', 'kind'),
|
|
107
|
+
]);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Check if kind is registered
|
|
111
|
+
if (!this.hasKind(manifest.kind)) {
|
|
112
|
+
return ValidationUtils.failure([
|
|
113
|
+
ValidationUtils.error(
|
|
114
|
+
'UNKNOWN_KIND',
|
|
115
|
+
`Unknown kind: "${manifest.kind}". Registered kinds: ${this.getRegisteredKinds().join(', ')}`,
|
|
116
|
+
'kind',
|
|
117
|
+
manifest.kind,
|
|
118
|
+
),
|
|
119
|
+
]);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Get validator and run validation
|
|
123
|
+
const validator = this.getValidator(manifest.kind);
|
|
124
|
+
if (!validator) {
|
|
125
|
+
return ValidationUtils.failure([
|
|
126
|
+
ValidationUtils.error('VALIDATOR_NOT_FOUND', `No validator found for kind: ${manifest.kind}`, 'kind'),
|
|
127
|
+
]);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const result = validator.validate(manifest);
|
|
131
|
+
|
|
132
|
+
// In strict mode, treat warnings as errors
|
|
133
|
+
if (options?.strictMode && result.warnings.length > 0) {
|
|
134
|
+
const warningErrors = result.warnings.map(w =>
|
|
135
|
+
ValidationUtils.error(
|
|
136
|
+
`STRICT_${w.code}`,
|
|
137
|
+
`[Warning treated as error] ${w.message}`,
|
|
138
|
+
w.path,
|
|
139
|
+
)
|
|
140
|
+
);
|
|
141
|
+
return ValidationUtils.failure([...result.errors, ...warningErrors], []);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return result;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Validate a manifest and throw if invalid
|
|
149
|
+
*/
|
|
150
|
+
validateOrThrow<K extends OriginalKind>(
|
|
151
|
+
manifest: OriginalManifest<K>,
|
|
152
|
+
options?: CreateTypedOriginalOptions
|
|
153
|
+
): void {
|
|
154
|
+
if (options?.skipValidation) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const result = this.validate(manifest, options);
|
|
159
|
+
|
|
160
|
+
if (!result.isValid) {
|
|
161
|
+
const errorMessages = result.errors.map(e => {
|
|
162
|
+
const path = e.path ? ` at ${e.path}` : '';
|
|
163
|
+
return `[${e.code}]${path}: ${e.message}`;
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
throw new Error(`Manifest validation failed:\n${errorMessages.join('\n')}`);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Check if a value is a valid OriginalKind
|
|
172
|
+
*/
|
|
173
|
+
static isValidKind(value: unknown): value is OriginalKind {
|
|
174
|
+
return typeof value === 'string' && Object.values(OriginalKind).includes(value as OriginalKind);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Parse a kind string to OriginalKind
|
|
179
|
+
* Accepts both full URIs (originals:kind:app) and short names (app)
|
|
180
|
+
*/
|
|
181
|
+
static parseKind(value: string): OriginalKind | null {
|
|
182
|
+
// Check if it's already a full kind URI
|
|
183
|
+
if (KindRegistry.isValidKind(value)) {
|
|
184
|
+
return value;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// Try to match short name
|
|
188
|
+
const normalized = value.toLowerCase().trim();
|
|
189
|
+
for (const kind of Object.values(OriginalKind)) {
|
|
190
|
+
const shortName = kind.split(':').pop()?.toLowerCase();
|
|
191
|
+
if (shortName === normalized) {
|
|
192
|
+
return kind;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Get the short name of a kind (e.g., "app" from "originals:kind:app")
|
|
201
|
+
*/
|
|
202
|
+
static getShortName(kind: OriginalKind): string {
|
|
203
|
+
return kind.split(':').pop() || kind;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Get human-readable display name for a kind
|
|
208
|
+
*/
|
|
209
|
+
static getDisplayName(kind: OriginalKind): string {
|
|
210
|
+
const shortName = KindRegistry.getShortName(kind);
|
|
211
|
+
return shortName.charAt(0).toUpperCase() + shortName.slice(1);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Create an empty manifest template for a kind
|
|
216
|
+
* Useful for scaffolding new Originals
|
|
217
|
+
*/
|
|
218
|
+
static createTemplate<K extends OriginalKind>(
|
|
219
|
+
kind: K,
|
|
220
|
+
name: string,
|
|
221
|
+
version = '1.0.0'
|
|
222
|
+
): Partial<OriginalManifest<K>> {
|
|
223
|
+
const base = {
|
|
224
|
+
kind,
|
|
225
|
+
name,
|
|
226
|
+
version,
|
|
227
|
+
resources: [],
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
// Add kind-specific metadata templates
|
|
231
|
+
switch (kind) {
|
|
232
|
+
case OriginalKind.App:
|
|
233
|
+
return {
|
|
234
|
+
...base,
|
|
235
|
+
metadata: {
|
|
236
|
+
runtime: 'node',
|
|
237
|
+
entrypoint: 'index.js',
|
|
238
|
+
} as any,
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
case OriginalKind.Agent:
|
|
242
|
+
return {
|
|
243
|
+
...base,
|
|
244
|
+
metadata: {
|
|
245
|
+
capabilities: [],
|
|
246
|
+
} as any,
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
case OriginalKind.Module:
|
|
250
|
+
return {
|
|
251
|
+
...base,
|
|
252
|
+
metadata: {
|
|
253
|
+
format: 'esm',
|
|
254
|
+
main: 'index.js',
|
|
255
|
+
} as any,
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
case OriginalKind.Dataset:
|
|
259
|
+
return {
|
|
260
|
+
...base,
|
|
261
|
+
metadata: {
|
|
262
|
+
format: 'json',
|
|
263
|
+
schema: {},
|
|
264
|
+
} as any,
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
case OriginalKind.Media:
|
|
268
|
+
return {
|
|
269
|
+
...base,
|
|
270
|
+
metadata: {
|
|
271
|
+
mediaType: 'image',
|
|
272
|
+
mimeType: 'image/png',
|
|
273
|
+
} as any,
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
case OriginalKind.Document:
|
|
277
|
+
return {
|
|
278
|
+
...base,
|
|
279
|
+
metadata: {
|
|
280
|
+
format: 'markdown',
|
|
281
|
+
content: 'content',
|
|
282
|
+
} as any,
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
default:
|
|
286
|
+
return base;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Originals Kind System
|
|
3
|
+
*
|
|
4
|
+
* Provides typed "Kinds" for Originals - a classification system that
|
|
5
|
+
* enables kind-specific validation, metadata schemas, and behaviors.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { OriginalKind, KindRegistry } from '@originals/sdk';
|
|
10
|
+
*
|
|
11
|
+
* // Create an App Original manifest
|
|
12
|
+
* const appManifest = {
|
|
13
|
+
* kind: OriginalKind.App,
|
|
14
|
+
* name: 'MyApp',
|
|
15
|
+
* version: '1.0.0',
|
|
16
|
+
* resources: [entrypointResource],
|
|
17
|
+
* metadata: {
|
|
18
|
+
* runtime: 'node',
|
|
19
|
+
* entrypoint: 'index.js',
|
|
20
|
+
* },
|
|
21
|
+
* };
|
|
22
|
+
*
|
|
23
|
+
* // Validate the manifest
|
|
24
|
+
* const registry = KindRegistry.getInstance();
|
|
25
|
+
* const result = registry.validate(appManifest);
|
|
26
|
+
* if (!result.isValid) {
|
|
27
|
+
* console.error('Validation errors:', result.errors);
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
// Type exports
|
|
33
|
+
export {
|
|
34
|
+
OriginalKind,
|
|
35
|
+
type DependencyRef,
|
|
36
|
+
type BaseManifest,
|
|
37
|
+
type AppMetadata,
|
|
38
|
+
type AgentMetadata,
|
|
39
|
+
type ModuleMetadata,
|
|
40
|
+
type DatasetMetadata,
|
|
41
|
+
type MediaMetadata,
|
|
42
|
+
type DocumentMetadata,
|
|
43
|
+
type KindMetadataMap,
|
|
44
|
+
type KindMetadata,
|
|
45
|
+
type OriginalManifest,
|
|
46
|
+
type AppManifest,
|
|
47
|
+
type AgentManifest,
|
|
48
|
+
type ModuleManifest,
|
|
49
|
+
type DatasetManifest,
|
|
50
|
+
type MediaManifest,
|
|
51
|
+
type DocumentManifest,
|
|
52
|
+
type AnyManifest,
|
|
53
|
+
type ValidationResult,
|
|
54
|
+
type ValidationError,
|
|
55
|
+
type ValidationWarning,
|
|
56
|
+
type CreateTypedOriginalOptions,
|
|
57
|
+
} from './types';
|
|
58
|
+
|
|
59
|
+
// Registry export
|
|
60
|
+
export { KindRegistry } from './KindRegistry';
|
|
61
|
+
|
|
62
|
+
// Validator exports (for extension/customization)
|
|
63
|
+
export {
|
|
64
|
+
type KindValidator,
|
|
65
|
+
BaseKindValidator,
|
|
66
|
+
ValidationUtils,
|
|
67
|
+
AppValidator,
|
|
68
|
+
AgentValidator,
|
|
69
|
+
ModuleValidator,
|
|
70
|
+
DatasetValidator,
|
|
71
|
+
MediaValidator,
|
|
72
|
+
DocumentValidator,
|
|
73
|
+
} from './validators';
|
|
74
|
+
|