Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
346 additions
and
21 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
name: Publish OPL typelib to npm | ||
|
||
on: | ||
release: | ||
types: | ||
- created | ||
workflow_dispatch: | ||
inputs: | ||
version: | ||
required: true | ||
description: The version to release | ||
|
||
jobs: | ||
btp: | ||
runs-on: ubuntu-latest | ||
name: Publish | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: "14" | ||
registry-url: "https://registry.npmjs.org" | ||
- run: sudo npm i -g npm@7 | ||
- name: Bump version | ||
run: |- | ||
cd contrib/namespace-type-lib | ||
cat <<< $(jq '.version = (env.RELEASE_VERSION | sub("(^refs/tags/v)|(^v)"; ""))' package.json) > package.json | ||
env: | ||
RELEASE_VERSION: ${{ github.event.inputs.version || github.ref }} | ||
- run: |- | ||
git config --global user.email "60093411+ory-bot@users.noreply.github.com" | ||
git config --global user.name "ory-bot" | ||
git add contrib/namespace-type-lib/package.json | ||
git commit -m "autogen: bump OPL typelib" | ||
- run: |- | ||
cd contrib/namespace-type-lib | ||
npm publish --access public | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN_AENEASR }} |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/// <reference no-default-lib="true"/> | ||
|
||
declare interface Boolean {} | ||
declare interface String {} | ||
declare interface Number {} | ||
declare interface Function {} | ||
declare interface Object {} | ||
declare interface IArguments {} | ||
declare interface RegExp {} | ||
|
||
declare interface Array<T extends namespace> { | ||
includes(element: T): boolean | ||
traverse(iteratorfn: (element: T) => boolean): boolean | ||
} | ||
|
||
interface context { | ||
subject: never | ||
} | ||
|
||
interface namespace { | ||
related?: { [relation: string]: namespace[] } | ||
permits?: { [method: string]: (ctx: context) => boolean } | ||
} | ||
|
||
declare module "@ory/keto-namespace-types" { | ||
export type Context = context | ||
|
||
export type Namespace = namespace | ||
|
||
export type SubjectSet< | ||
A extends Namespace, | ||
R extends keyof A["related"], | ||
> = A["related"][R] extends Array<infer T> ? T : never | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "@ory/keto-namespace-types", | ||
"version": "0.9.0-alpha.0", | ||
"description": "TypeScript definitions for Ory Keto Namespaces", | ||
"homepage": "https://www.ory.sh/keto", | ||
"bugs": "https://github.com/ory/keto/issues", | ||
"main": "", | ||
"types": "index.d.ts", | ||
"files": [ | ||
"index.d.ts", | ||
"tsconfig.json" | ||
], | ||
"scripts": { | ||
"test": "tsc --types --noEmit --noLib test.ts" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"@ory/keto-namespace-types": "file:./", | ||
"typescript": "^4.7.4" | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { Namespace, SubjectSet, Context } from "@ory/keto-namespace-types" | ||
|
||
// This test is not really a valid config, but rather a check of the types. | ||
class User implements Namespace { | ||
related: { | ||
friends: User[] | ||
} | ||
} | ||
|
||
class Group implements Namespace { | ||
related: { | ||
members: (User | Group)[] | ||
} | ||
|
||
permits = { | ||
isMember: (ctx: Context): boolean => | ||
this.related.members.traverse((m) => | ||
m instanceof User ? m == ctx.subject : m.permits.isMember(ctx), | ||
), | ||
} | ||
} | ||
|
||
class File implements Namespace { | ||
related: { | ||
viewers: (User | SubjectSet<Group, "members">)[] | ||
} | ||
|
||
permits = { | ||
view: (ctx: Context): boolean => | ||
this.related.viewers.traverse((p) => | ||
p instanceof User | ||
? p.related.friends.includes(ctx.subject) | ||
: p.permits.isMember(ctx), | ||
) || this.related.viewers.includes(ctx.subject), | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"compilerOptions": { | ||
"noLib": true, | ||
"noEmit": true, | ||
"types": [] | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { Namespace, SubjectSet, Context } from "@ory/keto-namespace-types" | ||
|
||
// Declare new namespaces as classes that implement `Namespaces` | ||
class User implements Namespace { | ||
related: { | ||
// Define relations to other objects here. | ||
// Examples: | ||
// | ||
// parents: (File | Folder)[] | ||
// viewers: SubjectSet<Group, "members">[] | ||
} | ||
|
||
permits = { | ||
// Define permissions here. These can be derived from the relations above. | ||
// Examples: | ||
// | ||
// view: (ctx: Context): boolean => | ||
// this.related.viewers.includes(ctx.subject) || | ||
// this.related.parents.traverse((p) => p.permits.view(ctx)), | ||
} | ||
} | ||
|
||
class Group implements Namespace { | ||
related: { | ||
// Define relations to other objects here. | ||
// Examples: | ||
// | ||
// parents: (File | Folder)[] | ||
// viewers: SubjectSet<Group, "members">[] | ||
} | ||
|
||
permits = { | ||
// Define permissions here. These can be derived from the relations above. | ||
// Examples: | ||
// | ||
// view: (ctx: Context): boolean => | ||
// this.related.viewers.includes(ctx.subject) || | ||
// this.related.parents.traverse((p) => p.permits.view(ctx)), | ||
} | ||
} | ||
|
||
class Folder implements Namespace { | ||
related: { | ||
// Define relations to other objects here. | ||
// Examples: | ||
// | ||
// parents: (File | Folder)[] | ||
// viewers: SubjectSet<Group, "members">[] | ||
} | ||
|
||
permits = { | ||
// Define permissions here. These can be derived from the relations above. | ||
// Examples: | ||
// | ||
// view: (ctx: Context): boolean => | ||
// this.related.viewers.includes(ctx.subject) || | ||
// this.related.parents.traverse((p) => p.permits.view(ctx)), | ||
} | ||
} | ||
|
||
class File implements Namespace { | ||
related: { | ||
// Define relations to other objects here. | ||
// Examples: | ||
// | ||
// parents: (File | Folder)[] | ||
// viewers: SubjectSet<Group, "members">[] | ||
} | ||
|
||
permits = { | ||
// Define permissions here. These can be derived from the relations above. | ||
// Examples: | ||
// | ||
// view: (ctx: Context): boolean => | ||
// this.related.viewers.includes(ctx.subject) || | ||
// this.related.parents.traverse((p) => p.permits.view(ctx)), | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"private": true, | ||
"devDependencies": { | ||
"@ory/keto-namespace-types": "file:../namespace-type-lib", | ||
"typescript": "latest" | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"compilerOptions": { | ||
"noLib": true, | ||
"noEmit": true, | ||
"types": [] | ||
} | ||
} |