Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 6 additions & 62 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,67 +10,6 @@ Install this generator in your typespec project:

Then, annotate your models using `@entity`, `@index`, `@createdAt`, `@updatedAt`, `@label`

## Documentation

See [./tsp/main.tsp](/tsp/main.tsp) for the type definitions of the annotations.

```typespec

/**
* Generates a DynamoDB entity definition for this model.
*/
extern dec entity(
target: Model,
entity: string,
service: string,
version?: int32
);

/**
* Adds the ElectroDB "label" property to the attribute definition.
* See https://electrodb.dev/en/modeling/attributes/#label
*/
extern dec label(target: ModelProperty, label: string);

/**
* Define a "createdAt" timestamp. See https://electrodb.dev/en/recipes/created-at-updated-at/
*/
extern dec createdAt(target: ModelProperty, label?: string);

/**
* Define a "updatedAt" timestamp. See https://electrodb.dev/en/recipes/created-at-updated-at/
*/
extern dec updatedAt(target: ModelProperty, label?: string);

/**
* Define an ElectroDB index. See https://electrodb.dev/en/modeling/indexes/
*
* Use either shorthand definition:
*
* `@index("persons", { pk: [Persons.pk] })`
*
* Or full access pattern:
*

model AccessPattern {
index?: string;
collection?: string | string[];
type?: IndexType = IndexType.isolated;
pk?: ModelProperty[] | {
field?: string = "pk";
composite: ModelProperty[];
};
sk?: ModelProperty[] | {
field?: string = "sk";
composite: ModelProperty[] = #[];
};
}
*
*/
extern dec index(target: Model, name: string, accessPattern: AccessPattern);

```

## Example

Take a peek at the [./demo/main.tsp](./demo/main.tsp) for an of how this works:
Expand Down Expand Up @@ -279,5 +218,10 @@ export declare const Person: {
readonly version: "1";
};
};

```

## Documentation

This extension itself is driven by TypeSpec type definitions, mostly pieced together by reading existing (REST) extensions and https://typespec.io/docs/extending-typespec/create-decorators/

See [./tsp/main.tsp](/tsp/main.tsp) for the type definitions of the annotations.