Skip to content

Commit

Permalink
Added TSDoc example snippets to all field primitives (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
NuroDev authored Feb 11, 2025
1 parent 04c60d9 commit 14ca1fa
Showing 1 changed file with 97 additions and 0 deletions.
97 changes: 97 additions & 0 deletions src/schema/primitives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,20 @@ const primitive = <T extends ModelField['type']>(type: T) => {
* Creates a string field definition returning an object that includes the field type
* ("string") and attributes.
*
* @example
* ```ts
* import { model, string } from '@ronin/syntax/schema';
*
* const User = model({
* slug: 'user',
*
* fields: {
* name: string(),
* email: string({ required: true, unique: true })
* },
* });
* ```
*
* @param attributes - Optional field attributes.
*
* @returns A field of type "string" with the specified attributes.
Expand All @@ -103,6 +117,20 @@ export const string = primitive('string');
* Creates a number field definition returning an object that includes the field type
* ("number") and attributes.
*
* @example
* ```ts
* import { model, number } from '@ronin/syntax/schema';
*
* const User = model({
* slug: 'user',
*
* fields: {
* points: number(),
* numReferrals: number({ defaultValue: 0 })
* },
* });
* ```
*
* @param attributes - Optional field attributes.
*
* @returns A field of type "number" with the specified attributes.
Expand All @@ -113,6 +141,20 @@ export const number = primitive('number');
* Creates a link field definition returning an object that includes the field type
* ("link") and attributes.
*
* @example
* ```ts
* import { model, link } from '@ronin/syntax/schema';
*
* const User = model({
* slug: 'user',
*
* fields: {
* account: link({ target: 'account' }),
* posts: link({ target: 'post', kind: 'many', required: true })
* },
* });
* ```
*
* @param attributes - Optional field attributes.
*
* @returns A field of type "link" with the specified attributes.
Expand All @@ -123,6 +165,19 @@ export const link = primitive('link');
* Creates a JSON field definition returning an object that includes the field type
* ("json") and attributes.
*
* @example
* ```ts
* import { model, json } from '@ronin/syntax/schema';
*
* const User = model({
* slug: 'user',
*
* fields: {
* settings: json()
* },
* });
* ```
*
* @param attributes - Optional field attributes.
*
* @returns A field of type "json" with the specified attributes.
Expand All @@ -133,6 +188,20 @@ export const json = primitive('json');
* Creates a date field definition returning an object that includes the field type
* ("date") and attributes.
*
* @example
* ```ts
* import { model, date } from '@ronin/syntax/schema';
*
* const User = model({
* slug: 'user',
*
* fields: {
* lastActiveAt: date(),
* deactivatedAt: date({ defaultValue: null })
* },
* });
* ```
*
* @param attributes - Optional field attributes.
*
* @returns A field of type "date" with the specified attributes.
Expand All @@ -143,6 +212,20 @@ export const date = primitive('date');
* Creates a boolean field definition returning an object that includes the field type
* ("boolean") and attributes.
*
* @example
* ```ts
* import { model, boolean } from '@ronin/syntax/schema';
*
* const User = model({
* slug: 'user',
*
* fields: {
* earlyAccess: boolean(),
* isVerified: boolean({ defaultValue: false, required: true })
* },
* });
* ```
*
* @param attributes - Optional field attributes.
*
* @returns A field of type "boolean" with the specified attributes.
Expand All @@ -153,6 +236,20 @@ export const boolean = primitive('boolean');
* Creates a blob field definition returning an object that includes the field type
* ("blob") and attributes.
*
* @example
* ```ts
* import { model, blob } from '@ronin/syntax/schema';
*
* const User = model({
* slug: 'user',
*
* fields: {
* avatar: blob(),
* contents: blob({ required: true })
* },
* });
* ```
*
* @param attributes - Optional field attributes.
*
* @returns A field of type "blob" with the specified attributes.
Expand Down

0 comments on commit 14ca1fa

Please sign in to comment.