|
1 | | -# rbac |
| 1 | +# Turborepo starter |
2 | 2 |
|
3 | | -O(1) type safe role based access control |
| 3 | +This is an official starter Turborepo. |
4 | 4 |
|
5 | | -## Usage |
| 5 | +## Using this example |
6 | 6 |
|
7 | | -create a policy |
| 7 | +Run the following command: |
8 | 8 |
|
9 | | -```ts |
10 | | -const policy = createPolicy({ |
11 | | - name: 'todo', |
12 | | - permissions: { |
13 | | - todo: ['create', 'read', 'update', 'delete'], |
14 | | - comment: ['create', 'read', 'update'], |
15 | | - }, |
16 | | - roles: { |
17 | | - viewer: ['todo.read', 'comment.read'], |
18 | | - editor: ['todo.create', 'todo.update', 'comment.create', 'comment.update'], |
19 | | - }, |
20 | | -}) |
| 9 | +```sh |
| 10 | +npx create-turbo@latest |
21 | 11 | ``` |
22 | 12 |
|
23 | | -permissions are defined as a map of resource to actions |
24 | | -roles are defined as a map of role to permissions |
| 13 | +## What's inside? |
25 | 14 |
|
26 | | -you also can use * to match all resources and actions |
| 15 | +This Turborepo includes the following packages/apps: |
27 | 16 |
|
28 | | -```ts |
29 | | -createPolicy({ |
30 | | - name: 'todo', |
31 | | - permissions: { |
32 | | - todo: ['create', 'read', 'update', 'delete'], |
33 | | - comment: ['create', 'read', 'delete'], |
34 | | - }, |
35 | | - roles: { |
36 | | - viewer: ['todo.read', 'comment.read'], |
37 | | - editor: ['todo.*', 'comment.delete'], |
38 | | - admin: '*', |
39 | | - }, |
40 | | -}) |
| 17 | +### Apps and Packages |
| 18 | + |
| 19 | +- `docs`: a [Next.js](https://nextjs.org/) app |
| 20 | +- `web`: another [Next.js](https://nextjs.org/) app |
| 21 | +- `@repo/ui`: a stub React component library shared by both `web` and `docs` applications |
| 22 | +- `@repo/eslint-config`: `eslint` configurations (includes `eslint-config-next` and `eslint-config-prettier`) |
| 23 | +- `@repo/typescript-config`: `tsconfig.json`s used throughout the monorepo |
| 24 | + |
| 25 | +Each package/app is 100% [TypeScript](https://www.typescriptlang.org/). |
| 26 | + |
| 27 | +### Utilities |
| 28 | + |
| 29 | +This Turborepo has some additional tools already setup for you: |
| 30 | + |
| 31 | +- [TypeScript](https://www.typescriptlang.org/) for static type checking |
| 32 | +- [ESLint](https://eslint.org/) for code linting |
| 33 | +- [Prettier](https://prettier.io) for code formatting |
| 34 | + |
| 35 | +### Build |
| 36 | + |
| 37 | +To build all apps and packages, run the following command: |
| 38 | + |
| 39 | +``` |
| 40 | +cd my-turborepo |
| 41 | +pnpm build |
41 | 42 | ``` |
42 | 43 |
|
43 | | -create a identity |
| 44 | +### Develop |
44 | 45 |
|
45 | | -```ts |
46 | | -const identity = createIdentity({ |
47 | | - policies: [policy], |
48 | | - identities: { |
49 | | - student: ['todo.viewer'], |
50 | | - teacher: ['todo.editor', 'todo.viewer'], |
51 | | - }, |
52 | | -}) |
| 46 | +To develop all apps and packages, run the following command: |
| 47 | + |
| 48 | +``` |
| 49 | +cd my-turborepo |
| 50 | +pnpm dev |
53 | 51 | ``` |
54 | 52 |
|
55 | | -identities are defined as a map of identity to roles |
| 53 | +### Remote Caching |
56 | 54 |
|
57 | | -enforce a permission |
| 55 | +Turborepo can use a technique known as [Remote Caching](https://turbo.build/repo/docs/core-concepts/remote-caching) to share cache artifacts across machines, enabling you to share build caches with your team and CI/CD pipelines. |
58 | 56 |
|
59 | | -```ts |
60 | | -identity.enforce('student', ['todo.todo.read']) // true |
61 | | -identity.enforce('student', ['todo.todo.create']) // false |
| 57 | +By default, Turborepo will cache locally. To enable Remote Caching you will need an account with Vercel. If you don't have an account you can [create one](https://vercel.com/signup), then enter the following commands: |
| 58 | + |
| 59 | +``` |
| 60 | +cd my-turborepo |
| 61 | +npx turbo login |
| 62 | +``` |
| 63 | + |
| 64 | +This will authenticate the Turborepo CLI with your [Vercel account](https://vercel.com/docs/concepts/personal-accounts/overview). |
| 65 | + |
| 66 | +Next, you can link your Turborepo to your Remote Cache by running the following command from the root of your Turborepo: |
| 67 | + |
| 68 | +``` |
| 69 | +npx turbo link |
62 | 70 | ``` |
| 71 | + |
| 72 | +## Useful Links |
| 73 | + |
| 74 | +Learn more about the power of Turborepo: |
| 75 | + |
| 76 | +- [Tasks](https://turbo.build/repo/docs/core-concepts/monorepos/running-tasks) |
| 77 | +- [Caching](https://turbo.build/repo/docs/core-concepts/caching) |
| 78 | +- [Remote Caching](https://turbo.build/repo/docs/core-concepts/remote-caching) |
| 79 | +- [Filtering](https://turbo.build/repo/docs/core-concepts/monorepos/filtering) |
| 80 | +- [Configuration Options](https://turbo.build/repo/docs/reference/configuration) |
| 81 | +- [CLI Usage](https://turbo.build/repo/docs/reference/command-line-reference) |
0 commit comments