Skip to content

Commit

Permalink
refactor: switch to protobuf-es-lite and update deps
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Stewart <christian@aperture.us>
  • Loading branch information
paralin committed May 3, 2024
1 parent f768711 commit f14e386
Show file tree
Hide file tree
Showing 40 changed files with 7,371 additions and 11,249 deletions.
14 changes: 12 additions & 2 deletions .eslintrc.js → .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,20 @@ module.exports = {
'prettier',
],
parserOptions: {
project: './tsconfig.test.json',
project: './tsconfig.json',
},
rules: {
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
}
},
ignorePatterns: [
"node_modules",
"dist",
"coverage",
"bundle",
"runtime",
"vendor",
".eslintrc.js",
"wasm_exec.js"
]
}
1 change: 0 additions & 1 deletion .github/renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"workarounds:all"
],
"branchConcurrentLimit": 0,
"ignorePaths": ["hack"],
"packageRules": [
{
"matchManagers": ["gomod"],
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ vendor/
debug.test
.nyc_output
.aider*
.tools/
1 change: 1 addition & 0 deletions .golangci.yml
1 change: 1 addition & 0 deletions .ignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ vendor/
*.pb.go
*.pb.ts
go.sum
*_*.pb.ts
3 changes: 3 additions & 0 deletions .prettierrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
semi: false
singleQuote: true
experimentalTernaries: true
174 changes: 20 additions & 154 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,165 +1,31 @@
# https://github.com/aperturerobotics/protobuf-project

# https://github.com/aperturerobotics/template
PROJECT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
SHELL:=bash
ESBUILD=hack/bin/esbuild
PROTOWRAP=hack/bin/protowrap
PROTOC_GEN_GO=hack/bin/protoc-gen-go
PROTOC_GEN_STARPC=hack/bin/protoc-gen-go-starpc
PROTOC_GEN_VTPROTO=hack/bin/protoc-gen-go-vtproto
GOIMPORTS=hack/bin/goimports
GOLANGCI_LINT=hack/bin/golangci-lint
GO_MOD_OUTDATED=hack/bin/go-mod-outdated
GOLIST=go list -f "{{ .Dir }}" -m
MAKEFLAGS += --no-print-directory

GO_VENDOR_DIR := ./vendor
COMMON_DIR := $(GO_VENDOR_DIR)/github.com/aperturerobotics/common
COMMON_MAKEFILE := $(COMMON_DIR)/Makefile

export GO111MODULE=on
undefine GOARCH
undefine GOOS

all:

vendor:
go mod vendor

$(ESBUILD):
cd ./hack; \
go build -v \
-o ./bin/esbuild \
github.com/evanw/esbuild/cmd/esbuild

$(PROTOC_GEN_GO):
cd ./hack; \
go build -v \
-o ./bin/protoc-gen-go \
google.golang.org/protobuf/cmd/protoc-gen-go

$(PROTOC_GEN_VTPROTO):
cd ./hack; \
go build -v \
-o ./bin/protoc-gen-go-vtproto \
github.com/planetscale/vtprotobuf/cmd/protoc-gen-go-vtproto

$(PROTOC_GEN_STARPC):
cd ./hack; \
go build -v \
-o ./bin/protoc-gen-go-starpc \
github.com/aperturerobotics/starpc/cmd/protoc-gen-go-starpc

$(GOIMPORTS):
cd ./hack; \
go build -v \
-o ./bin/goimports \
golang.org/x/tools/cmd/goimports

$(PROTOWRAP):
cd ./hack; \
go build -v \
-o ./bin/protowrap \
github.com/aperturerobotics/goprotowrap/cmd/protowrap
.PHONY: $(MAKECMDGOALS)

$(GOLANGCI_LINT):
cd ./hack; \
go build -v \
-o ./bin/golangci-lint \
github.com/golangci/golangci-lint/cmd/golangci-lint

$(GO_MOD_OUTDATED):
cd ./hack; \
go build -v \
-o ./bin/go-mod-outdated \
github.com/psampaz/go-mod-outdated

# Add --go-grpc_out=$$(pwd)/vendor to use the GRPC protoc generator.
# .. and remove the "grpc" option from the vtprotobuf features list.

.PHONY: gengo
gengo: $(GOIMPORTS) $(PROTOWRAP) $(PROTOC_GEN_GO) $(PROTOC_GEN_VTPROTO) $(PROTOC_GEN_STARPC)
shopt -s globstar; \
set -eo pipefail; \
export PROJECT=$$(go list -m); \
export PATH=$$(pwd)/hack/bin:$${PATH}; \
mkdir -p $$(pwd)/vendor/$$(dirname $${PROJECT}); \
rm $$(pwd)/vendor/$${PROJECT} || true; \
ln -s $$(pwd) $$(pwd)/vendor/$${PROJECT} ; \
$(PROTOWRAP) \
-I $$(pwd)/vendor \
--go_out=$$(pwd)/vendor \
--go-vtproto_out=$$(pwd)/vendor \
--go-vtproto_opt=features=marshal+unmarshal+size+equal+clone \
--go-starpc_out=$$(pwd)/vendor \
--proto_path $$(pwd)/vendor \
--print_structure \
--only_specified_files \
$$(\
git \
ls-files "*.proto" |\
xargs printf -- \
"$$(pwd)/vendor/$${PROJECT}/%s "); \
rm $$(pwd)/vendor/$${PROJECT} || true
$(GOIMPORTS) -w ./

node_modules:
yarn install

.PHONY: gents
gents: $(PROTOWRAP) node_modules
shopt -s globstar; \
set -eo pipefail; \
export PROJECT=$$(go list -m); \
export PATH=$$(pwd)/hack/bin:$${PATH}; \
mkdir -p $$(pwd)/vendor/$$(dirname $${PROJECT}); \
rm $$(pwd)/vendor/$${PROJECT} || true; \
ln -s $$(pwd) $$(pwd)/vendor/$${PROJECT} ; \
$(PROTOWRAP) \
-I $$(pwd)/vendor \
--plugin=./node_modules/.bin/protoc-gen-ts_proto \
--ts_proto_out=$$(pwd)/vendor \
--ts_proto_opt=esModuleInterop=true \
--ts_proto_opt=fileSuffix=.pb \
--ts_proto_opt=importSuffix=.js \
--ts_proto_opt=forceLong=long \
--ts_proto_opt=oneof=unions \
--ts_proto_opt=outputServices=default,outputServices=generic-definitions \
--ts_proto_opt=useAbortSignal=true \
--ts_proto_opt=useAsyncIterable=true \
--ts_proto_opt=useDate=true \
--proto_path $$(pwd)/vendor \
--print_structure \
--only_specified_files \
$$(\
git \
ls-files "*.proto" |\
xargs printf -- \
"$$(pwd)/vendor/$${PROJECT}/%s "); \
rm $$(pwd)/vendor/$${PROJECT} || true
npm run format

.PHONY: genproto
genproto: gengo gents

.PHONY: gen
gen: genproto

.PHONY: outdated
outdated: $(GO_MOD_OUTDATED)
go list -mod=mod -u -m -json all | $(GO_MOD_OUTDATED) -update -direct

.PHONY: list
list: $(GO_MOD_OUTDATED)
go list -mod=mod -u -m -json all | $(GO_MOD_OUTDATED)
all:

.PHONY: lint
lint: $(GOLANGCI_LINT)
$(GOLANGCI_LINT) run
$(COMMON_MAKEFILE): vendor
@if [ ! -f $(COMMON_MAKEFILE) ]; then \
echo "Please add github.com/aperturerobotics/common to your go.mod."; \
exit 1; \
fi

.PHONY: fix
fix: $(GOLANGCI_LINT)
$(GOLANGCI_LINT) run --fix
$(MAKECMDGOALS): $(COMMON_MAKEFILE)
@$(MAKE) -C $(COMMON_DIR) PROJECT_DIR="$(PROJECT_DIR)" $@

.PHONY: test
test:
go test -v ./...
%: $(COMMON_MAKEFILE)
@$(MAKE) -C $(COMMON_DIR) PROJECT_DIR="$(PROJECT_DIR)" $@

.PHONY: demo
demo: node_modules vendor $(ESBUILD)
export PATH=$$(pwd)/hack/bin:$${PATH}; \
cd ./example && bash ./example.bash
vendor:
go mod vendor
4 changes: 2 additions & 2 deletions client/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
typeFromAST,
GraphQLType,
} from 'graphql'
import { LookupASTType } from './type-lookup'
import { PrimitiveValue } from '../primitive'
import { LookupASTType } from './type-lookup.js'
import { PrimitiveValue } from '../primitive.js'

interface StringedValue {
value: string
Expand Down
2 changes: 1 addition & 1 deletion client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class Client {
}
if (msg.valueBatch && msg.valueBatch.resultId === this.resultID && msg.valueBatch.values) {
for (const valueBin of msg.valueBatch.values) {
const val = RGQLValue.decode(valueBin)
const val = RGQLValue.fromBinary(valueBin)
this.resultTree.handleValue(val)
}
}
Expand Down
1 change: 1 addition & 0 deletions client/json-decoder.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest'
import { parse, buildSchema, OperationDefinitionNode } from 'graphql'
import { QueryTree } from './query-tree.js'
import { JSONDecoder } from './json-decoder.js'
Expand Down
8 changes: 4 additions & 4 deletions client/json-decoder.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { JSONDecoderHandler } from './json-decoder-handler'
import { Query } from './query'
import { QueryTreeNode } from './query-tree-node'
import { ResultTreeHandler } from './result-tree-handler'
import { JSONDecoderHandler } from './json-decoder-handler.js'
import { Query } from './query.js'
import { QueryTreeNode } from './query-tree-node.js'
import { ResultTreeHandler } from './result-tree-handler.js'

// JSONDecoder is a result handler that decodes the query to JSON.
export class JSONDecoder {
Expand Down
2 changes: 1 addition & 1 deletion client/path-cache.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PathCursor } from './path-cursor'
import { PathCursor } from './path-cursor.js'
import { LRUMap } from 'lru_map'

// PathCacheEvictHandler is called when a cursor is evicted from the cache.
Expand Down
8 changes: 4 additions & 4 deletions client/path-cursor.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { RGQLValue } from '../rgraphql.pb'
import { QueryTreeNode } from './query-tree-node'
import { ResultTreeHandler } from './result-tree-handler'
import { ResultTreeNode } from './result-tree-node'
import { RGQLValue } from '../rgraphql.pb.js'
import { QueryTreeNode } from './query-tree-node.js'
import { ResultTreeHandler } from './result-tree-handler.js'
import { ResultTreeNode } from './result-tree-node.js'

// PathCursor selects a location in the result tree.
export class PathCursor {
Expand Down
4 changes: 2 additions & 2 deletions client/query-attached.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Query } from './query'
import { QueryTreeNode } from './query-tree-node'
import { Query } from './query.js'
import { QueryTreeNode } from './query-tree-node.js'

// AttachedQuery tracks internal information about a query attached to a tree.
export class AttachedQuery {
Expand Down
7 changes: 4 additions & 3 deletions client/query-tree.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { describe, it, expect } from 'vitest'
import { parse, buildSchema, OperationDefinitionNode } from 'graphql'
import { QueryTreeHandler } from './query-tree-handler'
import { RGQLQueryTreeMutation } from 'rgraphql.pb'
import { QueryTree } from './query-tree'
import { QueryTreeHandler } from './query-tree-handler.js'
import { RGQLQueryTreeMutation } from '../rgraphql.pb.js'
import { QueryTree } from './query-tree.js'

function mockSchema() {
return buildSchema(`
Expand Down
4 changes: 2 additions & 2 deletions client/query.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { OperationDefinitionNode } from 'graphql'
import { QueryMap } from './query-map'
import { PrimitiveValue } from 'primitive'
import { QueryMap } from './query-map.js'
import { PrimitiveValue } from 'primitive.js'

// Query is a query operation attached to a query tree.
export class Query {
Expand Down
2 changes: 1 addition & 1 deletion client/query_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func (q *QueryTree) gcSweep() {
Operation: proto.RGQLQueryTreeMutation_SUBTREE_DELETE,
})
}
// TOOD: set query id
// TODO: set query id
q.handler.HandleMutation(&proto.RGQLQueryTreeMutation{
NodeMutation: muts,
})
Expand Down
2 changes: 1 addition & 1 deletion client/result-tree-handler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// HandleResultValue handles the next value in the sequence, optionally
// returning a handler for the next value(s) in the sequence.

import { RGQLValue } from '../rgraphql.pb'
import { RGQLValue } from '../rgraphql.pb.js'

// If val == undefined, delete the value.
export type ResultTreeHandler = ((val: RGQLValue | undefined) => ResultTreeHandler) | null
10 changes: 3 additions & 7 deletions client/result-tree.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { describe, it, expect } from 'vitest'
import { parse, buildSchema, OperationDefinitionNode } from 'graphql'
import { QueryTree } from './query-tree.js'
import { QueryTreeHandler } from './query-tree-handler.js'
import { ResultTree } from './result-tree.js'
import { PackPrimitive } from '../primitive.js'
import {
DeepPartial,
RGQLQueryTreeMutation,
RGQLValue,
RGQLValueInit_CacheStrategy,
} from '../rgraphql.pb.js'
import { RGQLQueryTreeMutation, RGQLValue, RGQLValueInit_CacheStrategy } from '../rgraphql.pb.js'

function mockSchema() {
return buildSchema(`
Expand Down Expand Up @@ -59,7 +55,7 @@ describe('QueryTreeNode', () => {
const queryb = tree.buildQuery(queryAst.definitions[1] as OperationDefinitionNode, {})
// expect(tree.children.length).toBe(3)

const vals: DeepPartial<RGQLValue>[] = [
const vals: RGQLValue[] = [
{ queryNodeId: 1 },
{ queryNodeId: 2, value: PackPrimitive('test') },
{ queryNodeId: 1 },
Expand Down
6 changes: 3 additions & 3 deletions client/running-query.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Query } from './query'
import { ResultTree } from './result-tree'
import { ResultTreeHandler } from './result-tree-handler'
import { Query } from './query.js'
import { ResultTree } from './result-tree.js'
import { ResultTreeHandler } from './result-tree-handler.js'

// IResultHandler handles results.
export interface IResultHandler {
Expand Down
7 changes: 4 additions & 3 deletions client/var-store.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { VariableStore } from './var-store'
import { describe, it, expect, beforeEach } from 'vitest'
import { VariableStore } from './var-store.js'

describe('QueryTreeNode', () => {
describe('VariableStore', () => {
let store: VariableStore

beforeEach(() => {
store = new VariableStore(null)
})

it('should add a variable properly', () => {
it('should get variables properly', () => {
const vari = store.getVariable('test')
expect(vari.name).toEqual('B')
const varb = store.getVariable('test2')
Expand Down
9 changes: 9 additions & 0 deletions deps.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//go:build deps_only
// +build deps_only

package rgraphql

import (
// _ imports common with the Makefile and tools
_ "github.com/aperturerobotics/common"
)
Loading

0 comments on commit f14e386

Please sign in to comment.