@hypercerts-org/lexicon 0.2.0-beta.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,31 @@
1
+ /**
2
+ * GENERATED CODE - DO NOT MODIFY
3
+ */
4
+ import { type ValidationResult, BlobRef } from '@atproto/lexicon'
5
+ import { CID } from 'multiformats/cid'
6
+ import { validate as _validate } from '../../../../lexicons'
7
+ import {
8
+ type $Typed,
9
+ is$typed as _is$typed,
10
+ type OmitKey,
11
+ } from '../../../../util'
12
+
13
+ const is$typed = _is$typed,
14
+ validate = _validate
15
+ const id = 'com.atproto.repo.strongRef'
16
+
17
+ export interface Main {
18
+ $type?: 'com.atproto.repo.strongRef'
19
+ uri: string
20
+ cid: string
21
+ }
22
+
23
+ const hashMain = 'main'
24
+
25
+ export function isMain<V>(v: V) {
26
+ return is$typed(v, id, hashMain)
27
+ }
28
+
29
+ export function validateMain<V>(v: V) {
30
+ return validate<Main & V>(v, id, hashMain)
31
+ }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * GENERATED CODE - DO NOT MODIFY
3
+ */
4
+ import { type ValidationResult, BlobRef } from '@atproto/lexicon'
5
+ import { CID } from 'multiformats/cid'
6
+ import { validate as _validate } from '../../../../lexicons'
7
+ import {
8
+ type $Typed,
9
+ is$typed as _is$typed,
10
+ type OmitKey,
11
+ } from '../../../../util'
12
+ import type * as ComAtprotoRepoStrongRef from '../../../com/atproto/repo/strongRef.js'
13
+
14
+ const is$typed = _is$typed,
15
+ validate = _validate
16
+ const id = 'org.hypercerts.claim.contribution'
17
+
18
+ export interface Main {
19
+ $type: 'org.hypercerts.claim.contribution'
20
+ hypercert: ComAtprotoRepoStrongRef.Main
21
+ /** Role or title of the contributor(s). */
22
+ role?: string
23
+ /** List of the contributors (names, pseudonyms, or DIDs). If multiple contributors are stored in the same hypercertContribution, then they would have the exact same role. */
24
+ contributors: string[]
25
+ /** What the contribution concretely achieved */
26
+ description?: string
27
+ /** When this contribution started. This should be a subset of the hypercert timeframe. */
28
+ workTimeframeFrom?: string
29
+ /** When this contribution finished. This should be a subset of the hypercert timeframe. */
30
+ workTimeframeTo?: string
31
+ /** Client-declared timestamp when this record was originally created */
32
+ createdAt: string
33
+ [k: string]: unknown
34
+ }
35
+
36
+ const hashMain = 'main'
37
+
38
+ export function isMain<V>(v: V) {
39
+ return is$typed(v, id, hashMain)
40
+ }
41
+
42
+ export function validateMain<V>(v: V) {
43
+ return validate<Main & V>(v, id, hashMain, true)
44
+ }
45
+
46
+ export {
47
+ type Main as Record,
48
+ isMain as isRecord,
49
+ validateMain as validateRecord,
50
+ }
@@ -0,0 +1,51 @@
1
+ /**
2
+ * GENERATED CODE - DO NOT MODIFY
3
+ */
4
+ import { type ValidationResult, BlobRef } from '@atproto/lexicon'
5
+ import { CID } from 'multiformats/cid'
6
+ import { validate as _validate } from '../../../../lexicons'
7
+ import {
8
+ type $Typed,
9
+ is$typed as _is$typed,
10
+ type OmitKey,
11
+ } from '../../../../util'
12
+ import type * as ComAtprotoRepoStrongRef from '../../../com/atproto/repo/strongRef.js'
13
+ import type * as AppCertifiedDefs from '../../../app/certified/defs.js'
14
+
15
+ const is$typed = _is$typed,
16
+ validate = _validate
17
+ const id = 'org.hypercerts.claim.evaluation'
18
+
19
+ export interface Main {
20
+ $type: 'org.hypercerts.claim.evaluation'
21
+ subject: ComAtprotoRepoStrongRef.Main
22
+ /** DIDs of the evaluators */
23
+ evaluators: string[]
24
+ /** Evaluation data (URIs or blobs) containing detailed reports or methodology */
25
+ evaluations?: (
26
+ | $Typed<AppCertifiedDefs.Uri>
27
+ | $Typed<AppCertifiedDefs.SmallBlob>
28
+ | { $type: string }
29
+ )[]
30
+ /** Brief evaluation summary */
31
+ summary: string
32
+ /** Client-declared timestamp when this record was originally created */
33
+ createdAt: string
34
+ [k: string]: unknown
35
+ }
36
+
37
+ const hashMain = 'main'
38
+
39
+ export function isMain<V>(v: V) {
40
+ return is$typed(v, id, hashMain)
41
+ }
42
+
43
+ export function validateMain<V>(v: V) {
44
+ return validate<Main & V>(v, id, hashMain, true)
45
+ }
46
+
47
+ export {
48
+ type Main as Record,
49
+ isMain as isRecord,
50
+ validateMain as validateRecord,
51
+ }
@@ -0,0 +1,49 @@
1
+ /**
2
+ * GENERATED CODE - DO NOT MODIFY
3
+ */
4
+ import { type ValidationResult, BlobRef } from '@atproto/lexicon'
5
+ import { CID } from 'multiformats/cid'
6
+ import { validate as _validate } from '../../../../lexicons'
7
+ import {
8
+ type $Typed,
9
+ is$typed as _is$typed,
10
+ type OmitKey,
11
+ } from '../../../../util'
12
+ import type * as AppCertifiedDefs from '../../../app/certified/defs.js'
13
+
14
+ const is$typed = _is$typed,
15
+ validate = _validate
16
+ const id = 'org.hypercerts.claim.evidence'
17
+
18
+ export interface Main {
19
+ $type: 'org.hypercerts.claim.evidence'
20
+ content:
21
+ | $Typed<AppCertifiedDefs.Uri>
22
+ | $Typed<AppCertifiedDefs.SmallBlob>
23
+ | { $type: string }
24
+ /** Optional title to describe the nature of the evidence */
25
+ title?: string
26
+ /** Short description explaining what this evidence demonstrates or proves */
27
+ shortDescription: string
28
+ /** Optional longer description describing the impact claim evidence. */
29
+ description?: string
30
+ /** Client-declared timestamp when this hypercert claim was originally created */
31
+ createdAt: string
32
+ [k: string]: unknown
33
+ }
34
+
35
+ const hashMain = 'main'
36
+
37
+ export function isMain<V>(v: V) {
38
+ return is$typed(v, id, hashMain)
39
+ }
40
+
41
+ export function validateMain<V>(v: V) {
42
+ return validate<Main & V>(v, id, hashMain, true)
43
+ }
44
+
45
+ export {
46
+ type Main as Record,
47
+ isMain as isRecord,
48
+ validateMain as validateRecord,
49
+ }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * GENERATED CODE - DO NOT MODIFY
3
+ */
4
+ import { type ValidationResult, BlobRef } from '@atproto/lexicon'
5
+ import { CID } from 'multiformats/cid'
6
+ import { validate as _validate } from '../../../../lexicons'
7
+ import {
8
+ type $Typed,
9
+ is$typed as _is$typed,
10
+ type OmitKey,
11
+ } from '../../../../util'
12
+ import type * as ComAtprotoRepoStrongRef from '../../../com/atproto/repo/strongRef.js'
13
+
14
+ const is$typed = _is$typed,
15
+ validate = _validate
16
+ const id = 'org.hypercerts.claim.measurement'
17
+
18
+ export interface Main {
19
+ $type: 'org.hypercerts.claim.measurement'
20
+ hypercert: ComAtprotoRepoStrongRef.Main
21
+ /** DIDs of the entity (or entities) that measured this data */
22
+ measurers: string[]
23
+ /** The metric being measured */
24
+ metric: string
25
+ /** The measured value */
26
+ value: string
27
+ /** URI to methodology documentation, standard protocol, or measurement procedure */
28
+ measurementMethodURI?: string
29
+ /** URIs to supporting evidence or data */
30
+ evidenceURI?: string[]
31
+ /** Client-declared timestamp when this record was originally created */
32
+ createdAt: string
33
+ [k: string]: unknown
34
+ }
35
+
36
+ const hashMain = 'main'
37
+
38
+ export function isMain<V>(v: V) {
39
+ return is$typed(v, id, hashMain)
40
+ }
41
+
42
+ export function validateMain<V>(v: V) {
43
+ return validate<Main & V>(v, id, hashMain, true)
44
+ }
45
+
46
+ export {
47
+ type Main as Record,
48
+ isMain as isRecord,
49
+ validateMain as validateRecord,
50
+ }
@@ -0,0 +1,44 @@
1
+ /**
2
+ * GENERATED CODE - DO NOT MODIFY
3
+ */
4
+ import { type ValidationResult, BlobRef } from '@atproto/lexicon'
5
+ import { CID } from 'multiformats/cid'
6
+ import { validate as _validate } from '../../../../lexicons'
7
+ import {
8
+ type $Typed,
9
+ is$typed as _is$typed,
10
+ type OmitKey,
11
+ } from '../../../../util'
12
+
13
+ const is$typed = _is$typed,
14
+ validate = _validate
15
+ const id = 'org.hypercerts.claim.rights'
16
+
17
+ export interface Main {
18
+ $type: 'org.hypercerts.claim.rights'
19
+ /** Full name of the rights */
20
+ rightsName: string
21
+ /** Short rights identifier for easier search */
22
+ rightsType: string
23
+ /** Description of the rights of this hypercert */
24
+ rightsDescription: string
25
+ /** Client-declared timestamp when this record was originally created */
26
+ createdAt: string
27
+ [k: string]: unknown
28
+ }
29
+
30
+ const hashMain = 'main'
31
+
32
+ export function isMain<V>(v: V) {
33
+ return is$typed(v, id, hashMain)
34
+ }
35
+
36
+ export function validateMain<V>(v: V) {
37
+ return validate<Main & V>(v, id, hashMain, true)
38
+ }
39
+
40
+ export {
41
+ type Main as Record,
42
+ isMain as isRecord,
43
+ validateMain as validateRecord,
44
+ }
@@ -0,0 +1,58 @@
1
+ /**
2
+ * GENERATED CODE - DO NOT MODIFY
3
+ */
4
+ import { type ValidationResult, BlobRef } from '@atproto/lexicon'
5
+ import { CID } from 'multiformats/cid'
6
+ import { validate as _validate } from '../../../lexicons'
7
+ import { type $Typed, is$typed as _is$typed, type OmitKey } from '../../../util'
8
+ import type * as AppCertifiedDefs from '../../app/certified/defs.js'
9
+ import type * as ComAtprotoRepoStrongRef from '../../com/atproto/repo/strongRef.js'
10
+
11
+ const is$typed = _is$typed,
12
+ validate = _validate
13
+ const id = 'org.hypercerts.claim'
14
+
15
+ export interface Main {
16
+ $type: 'org.hypercerts.claim'
17
+ /** Title of the hypercert */
18
+ title: string
19
+ /** Short blurb of the impact work done. */
20
+ shortDescription: string
21
+ /** Optional longer description of the impact work done. */
22
+ description?: string
23
+ image?:
24
+ | $Typed<AppCertifiedDefs.Uri>
25
+ | $Typed<AppCertifiedDefs.SmallBlob>
26
+ | { $type: string }
27
+ /** Scope of the work performed */
28
+ workScope: string
29
+ /** When the work began */
30
+ workTimeFrameFrom: string
31
+ /** When the work ended */
32
+ workTimeFrameTo: string
33
+ /** Supporting evidence, documentation, or external data URIs */
34
+ evidence?: ComAtprotoRepoStrongRef.Main[]
35
+ /** A strong reference to the contributions done to create the impact in the hypercerts. The record referenced must conform with the lexicon org.hypercerts.claim.contributions */
36
+ contributions?: ComAtprotoRepoStrongRef.Main[]
37
+ rights?: ComAtprotoRepoStrongRef.Main
38
+ location?: ComAtprotoRepoStrongRef.Main
39
+ /** Client-declared timestamp when this record was originally created */
40
+ createdAt: string
41
+ [k: string]: unknown
42
+ }
43
+
44
+ const hashMain = 'main'
45
+
46
+ export function isMain<V>(v: V) {
47
+ return is$typed(v, id, hashMain)
48
+ }
49
+
50
+ export function validateMain<V>(v: V) {
51
+ return validate<Main & V>(v, id, hashMain, true)
52
+ }
53
+
54
+ export {
55
+ type Main as Record,
56
+ isMain as isRecord,
57
+ validateMain as validateRecord,
58
+ }
@@ -0,0 +1,63 @@
1
+ /**
2
+ * GENERATED CODE - DO NOT MODIFY
3
+ */
4
+ import { type ValidationResult, BlobRef } from '@atproto/lexicon'
5
+ import { CID } from 'multiformats/cid'
6
+ import { validate as _validate } from '../../../lexicons'
7
+ import { type $Typed, is$typed as _is$typed, type OmitKey } from '../../../util'
8
+ import type * as AppCertifiedDefs from '../../app/certified/defs.js'
9
+ import type * as ComAtprotoRepoStrongRef from '../../com/atproto/repo/strongRef.js'
10
+
11
+ const is$typed = _is$typed,
12
+ validate = _validate
13
+ const id = 'org.hypercerts.collection'
14
+
15
+ export interface Main {
16
+ $type: 'org.hypercerts.collection'
17
+ /** The title of this collection */
18
+ title: string
19
+ /** A short description of this collection */
20
+ shortDescription?: string
21
+ coverPhoto?:
22
+ | $Typed<AppCertifiedDefs.Uri>
23
+ | $Typed<AppCertifiedDefs.SmallBlob>
24
+ | { $type: string }
25
+ /** Array of claims with their associated weights in this collection */
26
+ claims: ClaimItem[]
27
+ /** Client-declared timestamp when this record was originally created */
28
+ createdAt: string
29
+ [k: string]: unknown
30
+ }
31
+
32
+ const hashMain = 'main'
33
+
34
+ export function isMain<V>(v: V) {
35
+ return is$typed(v, id, hashMain)
36
+ }
37
+
38
+ export function validateMain<V>(v: V) {
39
+ return validate<Main & V>(v, id, hashMain, true)
40
+ }
41
+
42
+ export {
43
+ type Main as Record,
44
+ isMain as isRecord,
45
+ validateMain as validateRecord,
46
+ }
47
+
48
+ export interface ClaimItem {
49
+ $type?: 'org.hypercerts.collection#claimItem'
50
+ claim: ComAtprotoRepoStrongRef.Main
51
+ /** The weight/importance of this hypercert claim in the collection (a percentage from 0-100, stored as a string to avoid float precision issues). The total claim weights should add up to 100. */
52
+ weight: string
53
+ }
54
+
55
+ const hashClaimItem = 'claimItem'
56
+
57
+ export function isClaimItem<V>(v: V) {
58
+ return is$typed(v, id, hashClaimItem)
59
+ }
60
+
61
+ export function validateClaimItem<V>(v: V) {
62
+ return validate<ClaimItem & V>(v, id, hashClaimItem)
63
+ }
package/src/util.ts ADDED
@@ -0,0 +1,82 @@
1
+ /**
2
+ * GENERATED CODE - DO NOT MODIFY
3
+ */
4
+
5
+ import { type ValidationResult } from '@atproto/lexicon'
6
+
7
+ export type OmitKey<T, K extends keyof T> = {
8
+ [K2 in keyof T as K2 extends K ? never : K2]: T[K2]
9
+ }
10
+
11
+ export type $Typed<V, T extends string = string> = V & { $type: T }
12
+ export type Un$Typed<V extends { $type?: string }> = OmitKey<V, '$type'>
13
+
14
+ export type $Type<Id extends string, Hash extends string> = Hash extends 'main'
15
+ ? Id
16
+ : `${Id}#${Hash}`
17
+
18
+ function isObject<V>(v: V): v is V & object {
19
+ return v != null && typeof v === 'object'
20
+ }
21
+
22
+ function is$type<Id extends string, Hash extends string>(
23
+ $type: unknown,
24
+ id: Id,
25
+ hash: Hash,
26
+ ): $type is $Type<Id, Hash> {
27
+ return hash === 'main'
28
+ ? $type === id
29
+ : // $type === `${id}#${hash}`
30
+ typeof $type === 'string' &&
31
+ $type.length === id.length + 1 + hash.length &&
32
+ $type.charCodeAt(id.length) === 35 /* '#' */ &&
33
+ $type.startsWith(id) &&
34
+ $type.endsWith(hash)
35
+ }
36
+
37
+ export type $TypedObject<
38
+ V,
39
+ Id extends string,
40
+ Hash extends string,
41
+ > = V extends {
42
+ $type: $Type<Id, Hash>
43
+ }
44
+ ? V
45
+ : V extends { $type?: string }
46
+ ? V extends { $type?: infer T extends $Type<Id, Hash> }
47
+ ? V & { $type: T }
48
+ : never
49
+ : V & { $type: $Type<Id, Hash> }
50
+
51
+ export function is$typed<V, Id extends string, Hash extends string>(
52
+ v: V,
53
+ id: Id,
54
+ hash: Hash,
55
+ ): v is $TypedObject<V, Id, Hash> {
56
+ return isObject(v) && '$type' in v && is$type(v.$type, id, hash)
57
+ }
58
+
59
+ export function maybe$typed<V, Id extends string, Hash extends string>(
60
+ v: V,
61
+ id: Id,
62
+ hash: Hash,
63
+ ): v is V & object & { $type?: $Type<Id, Hash> } {
64
+ return (
65
+ isObject(v) &&
66
+ ('$type' in v ? v.$type === undefined || is$type(v.$type, id, hash) : true)
67
+ )
68
+ }
69
+
70
+ export type Validator<R = unknown> = (v: unknown) => ValidationResult<R>
71
+ export type ValidatorParam<V extends Validator> =
72
+ V extends Validator<infer R> ? R : never
73
+
74
+ /**
75
+ * Utility function that allows to convert a "validate*" utility function into a
76
+ * type predicate.
77
+ */
78
+ export function asPredicate<V extends Validator>(validate: V) {
79
+ return function <T>(v: T): v is T & ValidatorParam<V> {
80
+ return validate(v).success
81
+ }
82
+ }