From 488a021accba2bf52fc974074b9c3361679f6cb1 Mon Sep 17 00:00:00 2001 From: Joshua Sosso Date: Sat, 17 Aug 2024 13:19:01 -0500 Subject: [PATCH 1/3] clean up dependency graph for better "affected" detection --- languages/dart/dart-codegen/package.json | 14 +- languages/kotlin/kotlin-codegen/package.json | 17 +- languages/rust/rust-codegen/package.json | 15 +- languages/swift/swift-codegen/package.json | 17 +- languages/ts/ts-codegen/package.json | 16 +- languages/ts/ts-codegen/src/_index.test.ts | 2 - package.json | 2 + pnpm-lock.yaml | 23 -- tests/clients/dart/project.json | 2 +- tests/clients/kotlin/project.json | 2 +- tests/clients/rust/project.json | 2 +- tests/clients/swift/project.json | 2 +- tests/clients/ts/project.json | 2 +- tooling/codegen-utils/build.config.ts | 2 +- tooling/codegen-utils/package.json | 17 +- tooling/codegen-utils/src/index.ts | 3 +- tooling/codegen-utils/src/testModels.ts | 254 ------------------- 17 files changed, 77 insertions(+), 315 deletions(-) delete mode 100644 tooling/codegen-utils/src/testModels.ts diff --git a/languages/dart/dart-codegen/package.json b/languages/dart/dart-codegen/package.json index 39ab4b2d..13296780 100644 --- a/languages/dart/dart-codegen/package.json +++ b/languages/dart/dart-codegen/package.json @@ -3,8 +3,13 @@ "version": "0.60.1", "type": "module", "license": "MIT", - "author": { "name": "joshmossas", "url": "https://github.com/joshmossas" }, - "bugs": { "url": "https://github.com/modiimedia/arri/issues" }, + "author": { + "name": "joshmossas", + "url": "https://github.com/joshmossas" + }, + "bugs": { + "url": "https://github.com/modiimedia/arri/issues" + }, "repository": { "type": "git", "url": "https://github.com/modiimedia/arri.git", @@ -13,10 +18,11 @@ "main": "./dist/index.cjs", "module": "./dist/index.mjs", "types": "./dist/index.d.ts", - "files": ["dist"], + "files": [ + "dist" + ], "dependencies": { "@arrirpc/codegen-utils": "workspace:*", - "@arrirpc/schema": "workspace:*", "pathe": "^1.1.2" } } diff --git a/languages/kotlin/kotlin-codegen/package.json b/languages/kotlin/kotlin-codegen/package.json index 3a1b63f2..cffc75db 100644 --- a/languages/kotlin/kotlin-codegen/package.json +++ b/languages/kotlin/kotlin-codegen/package.json @@ -3,8 +3,13 @@ "version": "0.60.1", "type": "module", "license": "MIT", - "author": { "name": "joshmossas", "url": "https://github.com/joshmossas" }, - "bugs": { "url": "https://github.com/modiimedia/arri/issues" }, + "author": { + "name": "joshmossas", + "url": "https://github.com/joshmossas" + }, + "bugs": { + "url": "https://github.com/modiimedia/arri/issues" + }, "repository": { "type": "git", "url": "https://github.com/modiimedia/arri.git", @@ -13,10 +18,10 @@ "main": "./dist/index.cjs", "module": "./dist/index.mjs", "types": "./dist/index.d.ts", - "files": ["dist"], + "files": [ + "dist" + ], "dependencies": { - "@arrirpc/codegen-utils": "workspace:*", - "@arrirpc/schema": "workspace:*", - "json-schema-to-jtd": "workspace:*" + "@arrirpc/codegen-utils": "workspace:*" } } diff --git a/languages/rust/rust-codegen/package.json b/languages/rust/rust-codegen/package.json index 1ae73707..03882144 100644 --- a/languages/rust/rust-codegen/package.json +++ b/languages/rust/rust-codegen/package.json @@ -2,8 +2,13 @@ "name": "@arrirpc/codegen-rust", "type": "module", "license": "MIT", - "author": { "name": "joshmossas", "url": "https://github.com/joshmossas" }, - "bugs": { "url": "https://github.com/modiimedia/arri/issues" }, + "author": { + "name": "joshmossas", + "url": "https://github.com/joshmossas" + }, + "bugs": { + "url": "https://github.com/modiimedia/arri/issues" + }, "repository": { "type": "git", "url": "https://github.com/modiimedia/arri.git", @@ -12,11 +17,13 @@ "main": "./dist/index.cjs", "module": "./dist/index.mjs", "types": "./dist/index.d.ts", - "files": ["dist"], + "files": [ + "dist" + ], "dependencies": { "@arrirpc/codegen-utils": "workspace:*", "pathe": "^1.1.2" }, - "devDependencies": { "@arrirpc/schema": "workspace:*" }, + "devDependencies": {}, "version": "0.60.1" } diff --git a/languages/swift/swift-codegen/package.json b/languages/swift/swift-codegen/package.json index 3ce93b6e..9788fcd8 100644 --- a/languages/swift/swift-codegen/package.json +++ b/languages/swift/swift-codegen/package.json @@ -3,8 +3,13 @@ "version": "0.60.1", "type": "module", "license": "MIT", - "author": { "name": "joshmossas", "url": "https://github.com/joshmossas" }, - "bugs": { "url": "https://github.com/modiimedia/arri/issues" }, + "author": { + "name": "joshmossas", + "url": "https://github.com/joshmossas" + }, + "bugs": { + "url": "https://github.com/modiimedia/arri/issues" + }, "repository": { "type": "git", "url": "https://github.com/modiimedia/arri.git", @@ -13,7 +18,11 @@ "main": "./dist/index.cjs", "module": "./dist/index.mjs", "types": "./dist/index.d.ts", - "files": ["dist"], - "dependencies": { "@arrirpc/codegen-utils": "workspace:*" }, + "files": [ + "dist" + ], + "dependencies": { + "@arrirpc/codegen-utils": "workspace:*" + }, "devDependencies": {} } diff --git a/languages/ts/ts-codegen/package.json b/languages/ts/ts-codegen/package.json index fce77961..68d96567 100644 --- a/languages/ts/ts-codegen/package.json +++ b/languages/ts/ts-codegen/package.json @@ -3,8 +3,13 @@ "version": "0.60.1", "type": "module", "license": "MIT", - "author": { "name": "joshmossas", "url": "https://github.com/joshmossas" }, - "bugs": { "url": "https://github.com/modiimedia/arri/issues" }, + "author": { + "name": "joshmossas", + "url": "https://github.com/joshmossas" + }, + "bugs": { + "url": "https://github.com/modiimedia/arri/issues" + }, "repository": { "type": "git", "url": "https://github.com/modiimedia/arri.git", @@ -13,11 +18,12 @@ "main": "./dist/index.cjs", "module": "./dist/index.mjs", "types": "./dist/index.d.ts", - "files": ["dist"], + "files": [ + "dist" + ], "dependencies": { "@arrirpc/codegen-utils": "workspace:*", - "@arrirpc/schema": "workspace:*", "prettier": "^3.3.3" }, - "devDependencies": { "@arrirpc/client": "workspace:*" } + "devDependencies": {} } diff --git a/languages/ts/ts-codegen/src/_index.test.ts b/languages/ts/ts-codegen/src/_index.test.ts index eb010154..4a4c6fd0 100644 --- a/languages/ts/ts-codegen/src/_index.test.ts +++ b/languages/ts/ts-codegen/src/_index.test.ts @@ -1,5 +1,3 @@ -// TODO - import { AppDefinition, normalizeWhitespace } from "@arrirpc/codegen-utils"; import fs from "fs"; import path from "path"; diff --git a/package.json b/package.json index 4343d876..fabaff03 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,8 @@ "integration-tests": "start-server-and-test 'integration-tests:start-server' http-get://127.0.0.1:2020/status 'integration-tests:run-tests'", "integration-tests:start-server": "nx build-server test-server && node tests/server/.output/server.mjs --host", "integration-tests:run-tests": "nx run-many -t integration-test --parallel=false", + "integration-tests:affected": "start-server-and-test 'integration-tests:start-server' http-get://127.0.0.1:2020/status 'integration-tests:affected:run-tests'", + "integration-tests:affected:run-tests": "nx affected -t integration-test --parallel=false", "scaffold": "jiti internal/scripts/scaffold-package.ts", "postversion": "jiti internal/scripts/version-sync.ts", "gen-test-utils": "jiti internal/scripts/generate-test-utils.ts", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d0a280a5..41a670b9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -110,9 +110,6 @@ importers: '@arrirpc/codegen-utils': specifier: workspace:* version: link:../../../tooling/codegen-utils - '@arrirpc/schema': - specifier: workspace:* - version: link:../../../tooling/schema pathe: specifier: ^1.1.2 version: 1.1.2 @@ -122,12 +119,6 @@ importers: '@arrirpc/codegen-utils': specifier: workspace:* version: link:../../../tooling/codegen-utils - '@arrirpc/schema': - specifier: workspace:* - version: link:../../../tooling/schema - json-schema-to-jtd: - specifier: workspace:* - version: link:../../../tooling/json-schema-to-jtd languages/rust/rust-codegen: dependencies: @@ -137,10 +128,6 @@ importers: pathe: specifier: ^1.1.2 version: 1.1.2 - devDependencies: - '@arrirpc/schema': - specifier: workspace:* - version: link:../../../tooling/schema languages/swift/swift-codegen: dependencies: @@ -172,16 +159,9 @@ importers: '@arrirpc/codegen-utils': specifier: workspace:* version: link:../../../tooling/codegen-utils - '@arrirpc/schema': - specifier: workspace:* - version: link:../../../tooling/schema prettier: specifier: ^3.3.3 version: 3.3.3 - devDependencies: - '@arrirpc/client': - specifier: workspace:* - version: link:../ts-client languages/ts/ts-codegen-reference: dependencies: @@ -357,9 +337,6 @@ importers: tooling/codegen-utils: dependencies: - '@arrirpc/schema': - specifier: workspace:* - version: link:../schema jtd-utils: specifier: workspace:* version: link:../jtd-utils diff --git a/tests/clients/dart/project.json b/tests/clients/dart/project.json index 52f1622c..5e8e518c 100644 --- a/tests/clients/dart/project.json +++ b/tests/clients/dart/project.json @@ -1,7 +1,7 @@ { "name": "test-client-dart", "$schema": "../../../node_modules/nx/schemas/project-schema.json", - "implicitDependencies": ["dart-client", "test-server"], + "implicitDependencies": ["dart-client", "dart-codegen"], "targets": { "pub": { "executor": "nx:run-commands", diff --git a/tests/clients/kotlin/project.json b/tests/clients/kotlin/project.json index 34c0140d..e0d94ccb 100644 --- a/tests/clients/kotlin/project.json +++ b/tests/clients/kotlin/project.json @@ -1,7 +1,7 @@ { "name": "test-client-kotlin", "$schema": "../../../node_modules/nx/schemas/project-schema.json", - "implicitDependencies": ["test-server"], + "implicitDependencies": ["kotlin-codegen"], "targets": { "integration-test": { "executor": "nx:run-commands", diff --git a/tests/clients/rust/project.json b/tests/clients/rust/project.json index a88efe1c..c53de561 100644 --- a/tests/clients/rust/project.json +++ b/tests/clients/rust/project.json @@ -1,7 +1,7 @@ { "name": "test-client-rust", "$schema": "../../../node_modules/nx/schemas/project-schema.json", - "implicitDependencies": ["test-server", "rust-client"], + "implicitDependencies": ["rust-codegen", "rust-client"], "targets": { "integration-test": { "executor": "nx:run-commands", diff --git a/tests/clients/swift/project.json b/tests/clients/swift/project.json index dc7692c1..b7fc8d8c 100644 --- a/tests/clients/swift/project.json +++ b/tests/clients/swift/project.json @@ -1,7 +1,7 @@ { "name": "test-client-swift", "$schema": "../../../node_modules/nx/schemas/project-schema.json", - "implicitDependencies": ["test-server", "swift-client"], + "implicitDependencies": ["swift-codegen", "swift-client"], "targets": { "integration-test": { "executor": "nx:run-commands", diff --git a/tests/clients/ts/project.json b/tests/clients/ts/project.json index 8d22da71..ebf54ea6 100644 --- a/tests/clients/ts/project.json +++ b/tests/clients/ts/project.json @@ -1,7 +1,7 @@ { "name": "test-client-ts", "$schema": "../../../node_modules/nx/schemas/project-schema.json", - "implicitDependencies": ["test-server", "ts-client"], + "implicitDependencies": ["ts-codegen", "ts-client"], "targets": { "integration-test": { "executor": "@nx/vite:test", diff --git a/tooling/codegen-utils/build.config.ts b/tooling/codegen-utils/build.config.ts index 8bda70c0..a774b7dd 100644 --- a/tooling/codegen-utils/build.config.ts +++ b/tooling/codegen-utils/build.config.ts @@ -1,7 +1,7 @@ import { defineBuildConfig } from "unbuild"; export default defineBuildConfig({ - entries: ["./src/index", "./src/testModels.ts"], + entries: ["./src/index"], rollup: { emitCJS: true, dts: { diff --git a/tooling/codegen-utils/package.json b/tooling/codegen-utils/package.json index 576a85b0..4fd55fb6 100644 --- a/tooling/codegen-utils/package.json +++ b/tooling/codegen-utils/package.json @@ -2,8 +2,13 @@ "name": "@arrirpc/codegen-utils", "version": "0.60.1", "license": "MIT", - "author": { "name": "joshmossas", "url": "https://github.com/joshmossas" }, - "bugs": { "url": "https://github.com/modiimedia/arri/issues" }, + "author": { + "name": "joshmossas", + "url": "https://github.com/joshmossas" + }, + "bugs": { + "url": "https://github.com/modiimedia/arri/issues" + }, "repository": { "type": "git", "url": "https://github.com/modiimedia/arri.git", @@ -13,10 +18,12 @@ "main": "./dist/index.cjs", "module": "./dist/index.mjs", "types": "./dist/index.d.ts", - "files": ["dist"], + "files": [ + "dist" + ], "dependencies": { - "@arrirpc/schema": "workspace:*", "jtd-utils": "workspace:*", "scule": "^1.3.0" - } + }, + "devDependencies": {} } diff --git a/tooling/codegen-utils/src/index.ts b/tooling/codegen-utils/src/index.ts index de1e6319..e5827016 100644 --- a/tooling/codegen-utils/src/index.ts +++ b/tooling/codegen-utils/src/index.ts @@ -21,7 +21,6 @@ export const isHttpMethod = (input: any): input is HttpMethod => { if (typeof input !== "string") { return false; } - // eslint-disable-next-line @typescript-eslint/no-unsafe-argument return HttpMethodValues.includes(input as any); }; @@ -147,7 +146,7 @@ export function isServiceDefinition(input: any): input is ServiceDefinition { if (typeof input !== "object") { return false; } - // eslint-disable-next-line @typescript-eslint/no-unsafe-argument + for (const key of Object.keys(input)) { if (typeof input[key] !== "object") { return false; diff --git a/tooling/codegen-utils/src/testModels.ts b/tooling/codegen-utils/src/testModels.ts deleted file mode 100644 index 9163a898..00000000 --- a/tooling/codegen-utils/src/testModels.ts +++ /dev/null @@ -1,254 +0,0 @@ -import { a } from "@arrirpc/schema"; - -import { type AppDefinition } from "./index"; - -export const TestUserSettingsSchema = a.object("UserSettings", { - notificationsEnabled: a.boolean(), - preferredTheme: a.stringEnum(["dark-mode", "light-mode", "system"], { - isDeprecated: true, - }), -}); - -export const TestUserPhotoSchema = a.object( - { - url: a.string(), - width: a.number(), - height: a.number(), - bytes: a.int64(), - nanoseconds: a.uint64({ - description: "When the photo was last updated in nanoseconds", - }), - }, - { id: "UserPhoto", description: "A profile picture" }, -); - -export const TestUserNotificationSchema = a.discriminator( - "UserNotification", - "notificationType", - { - POST_LIKE: a.object({ - postId: a.string(), - userId: a.string(), - }), - POST_COMMENT: a.object({ - postId: a.string(), - userId: a.string(), - commentText: a.string(), - }), - }, -); - -interface BinaryTree { - left: BinaryTree | null; - right: BinaryTree | null; -} - -export const TestUserSchema = a.object("User", { - id: a.string(), - role: a.stringEnum(["standard", "admin"]), - photo: a.nullable(TestUserPhotoSchema), - createdAt: a.timestamp(), - numFollowers: a.int32(), - settings: TestUserSettingsSchema, - lastNotification: a.nullable(TestUserNotificationSchema), - recentNotifications: a.array(TestUserNotificationSchema), - bookmarks: a.record(a.object({ postId: a.string(), userId: a.string() })), - bio: a.optional(a.string()), - metadata: a.record(a.any()), - randomList: a.array(a.any()), - binaryTree: a.recursive( - (self) => - a.object({ - left: a.nullable(self), - right: a.nullable(self), - }), - { id: "BinaryTree" }, - ), -}); - -export const TestUserParams = a.object("UserParams", { - userId: a.string(), -}); - -export const TestUpdateUserParams = a.pick( - TestUserSchema, - ["id", "bio", "photo"], - { - id: "UpdateUserParams", - }, -); - -export const TestAppDefinition: AppDefinition = { - schemaVersion: "0.0.7", - info: { - title: "Test App Client", - description: "This is a example app definition", - version: "11", - }, - procedures: { - getStatus: { - transport: "http", - path: "/status", - method: "get", - params: undefined, - response: "GetStatusResponse", - }, - "users.getUser": { - transport: "http", - path: "/users/get-user", - method: "get", - params: "UserParams", - response: "User", - description: "Get a user by id", - }, - "users.updateUser": { - transport: "http", - path: "/users/update-user", - method: "post", - params: "UpdateUserParams", - response: "User", - description: "Update a user", - }, - "users.watchUser": { - transport: "http", - path: "/users/watch-user", - method: "get", - params: "UserParams", - response: "User", - isEventStream: true, - description: "Watch a user", - }, - "users.createConnection": { - transport: "ws", - path: "/users/create-connection", - params: "UserParams", - response: "User", - }, - "users.settings.getUserSettings": { - transport: "http", - path: "/users/settings/get-user-settings", - method: "get", - params: undefined, - response: undefined, - isDeprecated: true, - }, - }, - definitions: { - GetStatusResponse: a.object({ - message: a.string(), - }), - User: TestUserSchema, - UserParams: TestUserParams, - UpdateUserParams: TestUpdateUserParams, - }, -}; - -const ExampleEnum = a.enumerator(["FOO", "BAR", "BAZ"], { id: "ExampleEnum" }); - -const ExampleObject = a.object( - { - id: a.string(), - content: a.string(), - }, - { - id: "ExampleObject", - }, -); - -const ExamplePayload = a.object( - { - string: a.string(), - boolean: a.boolean(), - timestamp: a.timestamp(), - float32: a.float32(), - float64: a.float64(), - int8: a.int8(), - uint8: a.uint8(), - int16: a.int16(), - uint16: a.uint16(), - int32: a.int32(), - uint32: a.uint32(), - int64: a.int64(), - uint64: a.uint64(), - enum: ExampleEnum, - object: ExampleObject, - array: a.array(a.boolean()), - record: a.record(a.boolean()), - any: a.any(), - }, - { - id: "ExamplePayload", - }, -); - -export const ExamplePayloadNullable = a.object( - { - string: a.nullable(a.string()), - boolean: a.nullable(a.boolean()), - timestamp: a.nullable(a.timestamp()), - float32: a.nullable(a.float32()), - float64: a.nullable(a.float64()), - int8: a.nullable(a.int8()), - uint8: a.nullable(a.uint8()), - int16: a.nullable(a.int16()), - uint16: a.nullable(a.uint16()), - int32: a.nullable(a.int32()), - uint32: a.nullable(a.uint32()), - int64: a.nullable(a.int64()), - uint64: a.nullable(a.uint64()), - enum: a.nullable(ExampleEnum), - object: ExampleObject, - array: a.nullable(a.array(a.boolean())), - record: a.nullable(a.record(a.boolean())), - any: a.nullable(a.any()), - }, - { - id: "ExamplePayloadNullable", - }, -); - -export const ExampleDiscriminator = a.discriminator( - "typeName", - { - A: a.object({ - id: a.string(), - }), - B: a.object({ - id: a.string(), - name: a.string(), - }), - C: a.object({ - id: a.string(), - name: a.string(), - date: a.timestamp(), - }), - }, - { - id: "ExampleDiscriminator", - }, -); - -export interface ExampleRecursive { - left: ExampleRecursive | null; - right: ExampleRecursive | null; -} - -export const ExampleRecursive = a.recursive( - (self) => - a.object({ - left: a.nullable(self), - right: a.nullable(self), - }), - { id: "ExampleRecursive" }, -); - -export const ReferenceAppDefinition: AppDefinition = { - schemaVersion: "0.0.7", - procedures: {}, - definitions: { - ExamplePayload, - ExamplePayloadNullable, - ExampleDiscriminator, - BinaryTree: ExampleRecursive, - }, -}; From e48894c8731433d1bc9e051c388ff8f60ae7e63b Mon Sep 17 00:00:00 2001 From: Joshua Sosso Date: Sat, 17 Aug 2024 13:28:31 -0500 Subject: [PATCH 2/3] update integration-test command --- .github/workflows/tests.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index aad19a24..99427eb6 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -114,4 +114,4 @@ jobs: run: pnpm nx run-many -t pub -- get # install dart dependencies in all dart projects - run: pnpm run build - run: pnpm i -r - - run: pnpm run integration-tests + - run: pnpm run integration-tests:affected From 1ca49b6ea10b7df0dfacb6ff22541a2d81e4dc4e Mon Sep 17 00:00:00 2001 From: Joshua Sosso Date: Sat, 17 Aug 2024 13:34:10 -0500 Subject: [PATCH 3/3] Setup nx for the integration-tests --- .github/workflows/tests.yaml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 99427eb6..7b30e45d 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -30,7 +30,7 @@ jobs: - name: Install Node Dependencies run: pnpm i -r --frozen-lockfile - name: Set NX Shas - uses: nrwl/nx-set-shas@v3 + uses: nrwl/nx-set-shas@v4 with: main-branch-name: master - run: pnpm nx affected -t pub -- get # install dart dependencies for affected projects @@ -70,7 +70,7 @@ jobs: - name: Install Node Dependencies run: pnpm i -r --frozen-lockfile - name: Set NX Shas - uses: nrwl/nx-set-shas@v3 + uses: nrwl/nx-set-shas@v4 with: main-branch-name: master - run: pnpm nx affected -t pub -- get # install dart dependencies for affected projects @@ -110,6 +110,10 @@ jobs: cache: pnpm - name: Install Node Dependencies run: pnpm i -r --frozen-lockfile + - name: Set NX Shas + uses: nrwl/nx-set-shas@v4 + with: + main-branch-name: master - name: Install dart dependencies run: pnpm nx run-many -t pub -- get # install dart dependencies in all dart projects - run: pnpm run build