Skip to content

Commit

Permalink
fix: generation
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed Feb 5, 2024
1 parent 8e07617 commit db15ba9
Show file tree
Hide file tree
Showing 33 changed files with 862 additions and 1,927 deletions.
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,20 @@ sdk: .bin/swagger .bin/ory node_modules
build:
go build -tags sqlite

.PHONY: proto-clear
proto-clear:
rm proto/ory/keto/opl/v1alpha1/*.ts || true
rm proto/ory/keto/opl/v1alpha1/*.js || true
rm proto/ory/keto/opl/v1alpha1/*.pb.go || true
rm proto/ory/keto/relation_tuples/v1alpha2/*.pb.go || true
rm proto/ory/keto/relation_tuples/v1alpha2/*.ts || true
rm proto/ory/keto/relation_tuples/v1alpha2/*.js || true

#
# Generate APIs and client stubs from the definitions
#
.PHONY: buf-gen
buf-gen: .bin/buf .bin/protoc-gen-doc node_modules
buf-gen: .bin/buf .bin/protoc-gen-doc node_modules proto-clear
buf generate
make format
@echo "All code was generated successfully!"
Expand Down
21 changes: 13 additions & 8 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,27 @@ plugins:
# - outputServices=generic-definitions
# - importSuffix=.js
# - esModuleInterop=true

- plugin: es
opt: target=ts
out: proto
- plugin: connect-es
opt:
- target=js
- js_import_style=legacy_commonjs
- js_import_style=module
out: proto
- plugin: connect-es

- plugin: es
opt: target=dts
out: proto
- plugin: es
# - plugin: es
# opt:
# - target=ts
# - js_import_style=module
# out: proto

- plugin: connect-es
opt:
- target=js
- js_import_style=legacy_commonjs
- js_import_style=module
out: proto
- plugin: es
- plugin: connect-es
opt: target=dts
out: proto
Original file line number Diff line number Diff line change
@@ -1,33 +1,50 @@
// Copyright © 2023 Ory Corp
// SPDX-License-Identifier: Apache-2.0

import grpc from "@ory/keto-grpc-client/node_modules/@grpc/grpc-js/build/src/index.js"
import { relationTuples, write, writeService } from "@ory/keto-grpc-client"
import {
RelationTuple,
RelationTupleDelta,
RelationTupleDelta_Action,
Subject,
SubjectSet,
TransactRelationTuplesRequest,
WriteService,
} from "@ory/keto-grpc-client"
import { createGrpcTransport } from "@connectrpc/connect-node"
import { createPromiseClient } from "@connectrpc/connect"

const transport = createGrpcTransport({
baseUrl: "http://127.0.0.1:4466/",
httpVersion: "1.1",
interceptors: [],
nodeOptions: {
rejectUnauthorized: false,
},
})

const writeClient = new writeService.WriteServiceClient(
"127.0.0.1:4467",
grpc.credentials.createInsecure(),
)
const writeClient = createPromiseClient(WriteService, transport)

const writeRequest = new write.TransactRelationTuplesRequest()
const writeRequest = new TransactRelationTuplesRequest()

const insert = (tuple) => {
const tupleDelta = new write.RelationTupleDelta()
tupleDelta.setAction(write.RelationTupleDelta.Action.ACTION_INSERT)
tupleDelta.setRelationTuple(tuple)
const tupleDelta = new RelationTupleDelta({
action: RelationTupleDelta_Action.ACTION_INSERT,
relationTuple: tuple,
})

writeRequest.addRelationTupleDeltas(tupleDelta)
writeRequest.relationTupleDeltas.push(tupleDelta)
}

const addSimpleTuple = (namespace, object, relation, user) => {
const relationTuple = new relationTuples.RelationTuple()
relationTuple.setNamespace(namespace)
relationTuple.setObject(object)
relationTuple.setRelation(relation)

const sub = new relationTuples.Subject()
sub.setId(user)
relationTuple.setSubject(sub)
const sub = new Subject({
id: user,
})
const relationTuple = new RelationTuple({
namespace,
object,
relation,
subject: sub,
})

insert(relationTuple)
}
Expand All @@ -46,39 +63,45 @@ addSimpleTuple("directories", "/photos", "access", "laura")
["files", "/photos/mountains.jpg"],
["directories", "/photos"],
].forEach(([namespace, object]) => {
const relationTuple = new relationTuples.RelationTuple()
relationTuple.setNamespace(namespace)
relationTuple.setObject(object)
relationTuple.setRelation("access")

const subjectSet = new relationTuples.SubjectSet()
subjectSet.setNamespace(namespace)
subjectSet.setObject(object)
subjectSet.setRelation("owner")

const sub = new relationTuples.Subject()
sub.setSet(subjectSet)
relationTuple.setSubject(sub)
const subjectSet = new SubjectSet({
namespace: "directories",
object: "/photos",
relation: "owner",
})

const sub = new Subject({
set: subjectSet,
})

const relationTuple = new RelationTuple({
namespace,
object,
relation: "access",
subject: sub,
})

insert(relationTuple)
})

// should be subject set rewrite
// access on parent means access on child
;["/photos/beach.jpg", "/photos/mountains.jpg"].forEach((file) => {
const relationTuple = new relationTuples.RelationTuple()
relationTuple.setNamespace("files")
relationTuple.setObject(file)
relationTuple.setRelation("access")

const subjectSet = new relationTuples.SubjectSet()
subjectSet.setNamespace("directories")
subjectSet.setObject("/photos")
subjectSet.setRelation("access")

const sub = new relationTuples.Subject()
sub.setSet(subjectSet)
relationTuple.setSubject(sub)
const subjectSet = new SubjectSet({
namespace: "directories",
object: "/photos",
relation: "access",
})

const sub = new Subject({
set: subjectSet,
})

const relationTuple = new RelationTuple({
namespace: "files",
object: file,
relation: "access",
subject: sub,
})

insert(relationTuple)
})
Expand Down
10 changes: 10 additions & 0 deletions contrib/docs-code-samples/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 18 additions & 4 deletions proto/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
import * as v1alpha2 from './ory/keto/relation_tuples/v1alpha2/check_service'
export * from './ory/keto/relation_tuples/v1alpha2/check_service_pb'
export * from './ory/keto/relation_tuples/v1alpha2/check_service_connect'

declare module '@ory/keto-grpc-client' {
export default v1alpha2
}
export * from './ory/keto/relation_tuples/v1alpha2/expand_service_pb'
export * from './ory/keto/relation_tuples/v1alpha2/expand_service_connect'

export * from './ory/keto/relation_tuples/v1alpha2/namespaces_service_pb'
export * from './ory/keto/relation_tuples/v1alpha2/namespaces_service_connect'

export * from './ory/keto/relation_tuples/v1alpha2/read_service_pb'
export * from './ory/keto/relation_tuples/v1alpha2/read_service_connect'

export * from './ory/keto/relation_tuples/v1alpha2/relation_tuples_pb'

export * from './ory/keto/relation_tuples/v1alpha2/version_pb'
export * from './ory/keto/relation_tuples/v1alpha2/version_connect'

export * from './ory/keto/relation_tuples/v1alpha2/write_service_pb'
export * from './ory/keto/relation_tuples/v1alpha2/write_service_connect'
9 changes: 0 additions & 9 deletions proto/index.js

This file was deleted.

19 changes: 19 additions & 0 deletions proto/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export * from "./ory/keto/relation_tuples/v1alpha2/check_service_pb.js"
export * from "./ory/keto/relation_tuples/v1alpha2/check_service_connect.js"

export * from "./ory/keto/relation_tuples/v1alpha2/expand_service_pb.js"
export * from "./ory/keto/relation_tuples/v1alpha2/expand_service_connect.js"

export * from "./ory/keto/relation_tuples/v1alpha2/namespaces_service_pb.js"
export * from "./ory/keto/relation_tuples/v1alpha2/namespaces_service_connect.js"

export * from "./ory/keto/relation_tuples/v1alpha2/read_service_pb.js"
export * from "./ory/keto/relation_tuples/v1alpha2/read_service_connect.js"

export * from "./ory/keto/relation_tuples/v1alpha2/relation_tuples_pb.js"

export * from "./ory/keto/relation_tuples/v1alpha2/version_pb.js"
export * from "./ory/keto/relation_tuples/v1alpha2/version_connect.js"

export * from "./ory/keto/relation_tuples/v1alpha2/write_service_pb.js"
export * from "./ory/keto/relation_tuples/v1alpha2/write_service_connect.js"
13 changes: 0 additions & 13 deletions proto/index.ts

This file was deleted.

13 changes: 4 additions & 9 deletions proto/ory/keto/opl/v1alpha1/syntax_service_connect.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
// @generated by protoc-gen-connect-es v1.3.0 with parameter "target=js,js_import_style=legacy_commonjs"
// @generated by protoc-gen-connect-es v1.3.0 with parameter "target=js,js_import_style=module"
// @generated from file ory/keto/opl/v1alpha1/syntax_service.proto (package ory.keto.opl.v1alpha1, syntax proto3)
/* eslint-disable */
// @ts-nocheck

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

const { CheckRequest, CheckResponse } = require("./syntax_service_pb.js");
const { MethodKind } = require("@bufbuild/protobuf");
import { CheckRequest, CheckResponse } from "./syntax_service_pb.js";
import { MethodKind } from "@bufbuild/protobuf";

/**
* The service that checks the syntax of an OPL file.
*
* @generated from service ory.keto.opl.v1alpha1.SyntaxService
*/
const SyntaxService = {
export const SyntaxService = {
typeName: "ory.keto.opl.v1alpha1.SyntaxService",
methods: {
/**
Expand All @@ -31,5 +28,3 @@ const SyntaxService = {
}
};


exports.SyntaxService = SyntaxService;
20 changes: 6 additions & 14 deletions proto/ory/keto/opl/v1alpha1/syntax_service_pb.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit db15ba9

Please sign in to comment.