-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add schema identity helpers & documentation
- Loading branch information
1 parent
61cfec6
commit db632fe
Showing
1 changed file
with
29 additions
and
2 deletions.
There are no files selected for viewing
31 changes: 29 additions & 2 deletions
31
packages/core-payload-plugins/packages/schema/src/Payload.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,42 @@ | ||
import type { Payload } from '@xyo-network/payload-model' | ||
import { | ||
isPayloadOfSchemaType, isPayloadOfSchemaTypeWithMeta, isPayloadOfSchemaTypeWithSources, type Payload, | ||
} from '@xyo-network/payload-model' | ||
|
||
import type { SchemaSchema } from './Schema.ts' | ||
import { SchemaSchema } from './Schema.ts' | ||
|
||
export type SchemaPayload = Payload<{ | ||
/** | ||
* The schema definition | ||
*/ | ||
definition: { | ||
[key: string]: unknown | ||
$id?: string | ||
} | ||
/** | ||
* The schema this schema extends (if any) | ||
*/ | ||
extends?: string | ||
|
||
/** @deprecated use definition.$id instead */ | ||
name?: string | ||
|
||
/** | ||
* Identifies this payload as a Schema | ||
*/ | ||
schema: SchemaSchema | ||
}> | ||
|
||
/** | ||
* Identity function for determining if an object is an Schema | ||
*/ | ||
export const isSchema = isPayloadOfSchemaType<SchemaPayload>(SchemaSchema) | ||
|
||
/** | ||
* Identity function for determining if an object is an Schema with sources | ||
*/ | ||
export const isSchemaWithSources = isPayloadOfSchemaTypeWithSources<SchemaPayload>(SchemaSchema) | ||
|
||
/** | ||
* Identity function for determining if an object is an Schema with meta | ||
*/ | ||
export const isSchemaWithMeta = isPayloadOfSchemaTypeWithMeta<SchemaPayload>(SchemaSchema) |