From 2f04e49b62acd67a7037aeaafe11f3cae029b42b Mon Sep 17 00:00:00 2001 From: Tobias Herber <22559657+herber@users.noreply.github.com> Date: Wed, 31 Dec 2025 14:04:20 +0100 Subject: [PATCH] Rename instance to tenant --- README.md | 44 +++++++++---------- bun.lock | 4 +- clients/typescript/package.json | 2 +- packages/build/src/util/function.ts | 2 +- service/package.json | 2 +- service/prisma/schema.prisma | 16 +++---- service/src/controllers/function.ts | 26 +++++------ service/src/controllers/functionDeployment.ts | 10 ++--- service/src/controllers/functionInvocation.ts | 4 +- service/src/controllers/functionVersion.ts | 4 +- service/src/controllers/index.ts | 4 +- service/src/controllers/instance.ts | 42 ------------------ service/src/controllers/runtime.ts | 2 +- service/src/controllers/tenant.ts | 42 ++++++++++++++++++ service/src/forge.ts | 32 +++++++------- service/src/id.ts | 2 +- service/src/presenters/index.ts | 2 +- service/src/presenters/instance.ts | 11 ----- service/src/presenters/tenant.ts | 11 +++++ service/src/queues/build.ts | 16 +++---- service/src/services/function.ts | 18 ++++---- service/src/services/functionDeployment.ts | 8 ++-- service/src/services/functionInvocation.ts | 10 ++--- service/src/services/index.ts | 2 +- .../src/services/{instance.ts => tenant.ts} | 22 +++++----- 25 files changed, 169 insertions(+), 169 deletions(-) delete mode 100644 service/src/controllers/instance.ts create mode 100644 service/src/controllers/tenant.ts delete mode 100644 service/src/presenters/instance.ts create mode 100644 service/src/presenters/tenant.ts rename service/src/services/{instance.ts => tenant.ts} (58%) diff --git a/README.md b/README.md index 01f764e..8f82e11 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Function Bay is a serverless function deployment and orchestration service that - **Runtime Support**: Multiple runtime environments including Node.js, Python, Ruby, and Java - **Function Invocation**: Direct function invocation with payload support and detailed logging - **Version Control**: Track and manage different versions of your functions -- **Instance Isolation**: Multi-tenant support with instance-based resource isolation +- **Tenant Isolation**: Multi-tenant architecture for isolated projects - **Configuration Management**: Memory, timeout, and environment variable configuration per deployment ## Quick Start @@ -163,20 +163,20 @@ let client = createFunctionBayClient({ ### Core API Examples -#### 1. Instance Management +#### 1. Tenant Management -Instances represent isolated tenants or projects: +Tenants represent isolated tenants or projects: ```typescript -// Create/update an instance -let instance = await client.instance.upsert({ +// Create/update an tenant +let tenant = await client.tenant.upsert({ name: 'My Project', identifier: 'my-project', }); -// Get an instance -let retrievedInstance = await client.instance.get({ - instanceId: instance.id, +// Get an tenant +let retrievedTenant = await client.tenant.get({ + tenantId: tenant.id, }); ``` @@ -187,7 +187,7 @@ List available runtimes for your functions: ```typescript // List available runtimes let runtimes = await client.runtime.list({ - instanceId: instance.id, + tenantId: tenant.id, limit: 10, order: 'desc', }); @@ -208,27 +208,27 @@ Functions define serverless function resources: ```typescript // Create/update a function let func = await client.function.upsert({ - instanceId: instance.id, + tenantId: tenant.id, name: 'My API Handler', identifier: 'api-handler', }); // List functions let functions = await client.function.list({ - instanceId: instance.id, + tenantId: tenant.id, limit: 10, order: 'desc', }); // Get a specific function let functionDetails = await client.function.get({ - instanceId: instance.id, + tenantId: tenant.id, functionId: func.id, }); // Update a function let updated = await client.function.update({ - instanceId: instance.id, + tenantId: tenant.id, functionId: func.id, name: 'Updated API Handler', }); @@ -241,7 +241,7 @@ Deploy function code with specific runtime and configuration: ```typescript // Create a deployment let deployment = await client.functionDeployment.create({ - instanceId: instance.id, + tenantId: tenant.id, functionId: func.id, name: 'v1.0.0', runtime: { @@ -285,7 +285,7 @@ console.log('Status:', deployment.status); // List deployments let deployments = await client.functionDeployment.list({ - instanceId: instance.id, + tenantId: tenant.id, functionId: func.id, limit: 20, order: 'desc', @@ -293,7 +293,7 @@ let deployments = await client.functionDeployment.list({ // Get deployment details let deploymentDetails = await client.functionDeployment.get({ - instanceId: instance.id, + tenantId: tenant.id, functionId: func.id, functionDeploymentId: deployment.id, }); @@ -310,7 +310,7 @@ Retrieve build and deployment logs: ```typescript // Get all deployment step outputs let outputs = await client.functionDeployment.getOutput({ - instanceId: instance.id, + tenantId: tenant.id, functionId: func.id, functionDeploymentId: deployment.id, }); @@ -334,7 +334,7 @@ List and manage deployed function versions: ```typescript // List function versions let versions = await client.functionVersion.list({ - instanceId: instance.id, + tenantId: tenant.id, functionId: func.id, limit: 10, order: 'desc', @@ -349,7 +349,7 @@ for (let version of versions.items) { // Get a specific version let version = await client.functionVersion.get({ - instanceId: instance.id, + tenantId: tenant.id, functionId: func.id, functionVersionId: versions.items[0].id, }); @@ -362,7 +362,7 @@ Execute deployed functions with custom payloads: ```typescript // Invoke a function let invocation = await client.function.invoke({ - instanceId: instance.id, + tenantId: tenant.id, functionId: func.id, payload: { action: 'process', @@ -384,7 +384,7 @@ View invocation logs and metrics: ```typescript // List function invocations let invocations = await client.functionInvocation.list({ - instanceId: instance.id, + tenantId: tenant.id, functionId: func.id, limit: 20, order: 'desc', @@ -403,7 +403,7 @@ for (let inv of invocations.items) { // Get detailed invocation information let invocationDetails = await client.functionInvocation.get({ - instanceId: instance.id, + tenantId: tenant.id, functionId: func.id, functionInvocationId: invocations.items[0].id, }); diff --git a/bun.lock b/bun.lock index c7174d7..52b97e7 100644 --- a/bun.lock +++ b/bun.lock @@ -140,7 +140,7 @@ "@lowerdeck/service": "^1.0.3", "@lowerdeck/slugify": "^1.0.4", "@lowerdeck/validation": "^1.0.4", - "@metorial-services/forge-client": "^1.0.1", + "@metorial-services/forge-client": "^1.0.3", "@prisma/adapter-pg": "^7.2.0", "@prisma/client": "^7.2.0", "date-fns": "^4.1.0", @@ -1958,7 +1958,7 @@ "function-bay/typescript": ["typescript@5.9.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw=="], - "function-bay-service/@metorial-services/forge-client": ["@metorial-services/forge-client@1.0.1", "", { "dependencies": { "@lowerdeck/rpc-client": "^1.0.2" } }, "sha512-D7B/vHy+AyCyxljsMyLP58hnZcMR0dg8q2dHwS4RcD2pEuh+PC11jVq2mLni2acWNKs3TV6s/Y+x9CXAdqwDTQ=="], + "function-bay-service/@metorial-services/forge-client": ["@metorial-services/forge-client@1.0.3", "", { "dependencies": { "@lowerdeck/rpc-client": "^1.0.2" } }, "sha512-r+OzWCJLpcu40tKg9+o+8YW/TK2ANVHM0cW1nk3RDyT95ZyLvB7Lj8xjqX/y4LSIBY7hMOOsoE9qSwrOWophbw=="], "gzip-size/duplexer": ["duplexer@0.1.2", "", {}, "sha512-jtD6YG370ZCIi/9GTaJKQxWTZD045+4R4hTk/x1UyoqadyJ9x9CgSi1RlVDQF8U2sxLLSnFkCaMihqljHIWgMg=="], diff --git a/clients/typescript/package.json b/clients/typescript/package.json index c07b80a..7c6a244 100644 --- a/clients/typescript/package.json +++ b/clients/typescript/package.json @@ -1,6 +1,6 @@ { "name": "@metorial-services/function-bay-client", - "version": "1.0.0", + "version": "1.0.1", "publishConfig": { "access": "public" }, diff --git a/packages/build/src/util/function.ts b/packages/build/src/util/function.ts index 6b79019..5dde3ef 100644 --- a/packages/build/src/util/function.ts +++ b/packages/build/src/util/function.ts @@ -27,7 +27,7 @@ export class Function { private constructor(func: FunctionDefinition) { if (existingFunctionRef.current) { - throw new Error('Only one Function instance can be created per build.'); + throw new Error('Only one Function tenant can be created per build.'); } existingFunctionRef.current = true; diff --git a/service/package.json b/service/package.json index 322aba0..583b5cc 100644 --- a/service/package.json +++ b/service/package.json @@ -35,7 +35,7 @@ "@lowerdeck/service": "^1.0.3", "@lowerdeck/slugify": "^1.0.4", "@lowerdeck/validation": "^1.0.4", - "@metorial-services/forge-client": "^1.0.1", + "@metorial-services/forge-client": "^1.0.3", "@prisma/adapter-pg": "^7.2.0", "@prisma/client": "^7.2.0", "date-fns": "^4.1.0", diff --git a/service/prisma/schema.prisma b/service/prisma/schema.prisma index 7600478..841cd4c 100644 --- a/service/prisma/schema.prisma +++ b/service/prisma/schema.prisma @@ -17,7 +17,7 @@ generator json { provider = "prisma-json-types-generator" } -model Instance { +model Tenant { oid BigInt @id id String @unique @@ -69,14 +69,14 @@ model RuntimeForgeWorkflow { runtimeOid BigInt runtime Runtime @relation(fields: [runtimeOid], references: [oid]) - instanceOid BigInt - instance Instance @relation(fields: [instanceOid], references: [oid]) + tenantOid BigInt + tenant Tenant @relation(fields: [tenantOid], references: [oid]) forgeWorkflowId String - forgeInstanceId String + forgeTenantId String forgeWorkflowVersionId String - @@unique([runtimeOid, instanceOid]) + @@unique([runtimeOid, tenantOid]) } enum FunctionStatus { @@ -96,8 +96,8 @@ model Function { currentVersionOid BigInt? currentVersion FunctionVersion? @relation(fields: [currentVersionOid], references: [oid], name: "CurrentVersion") - instanceOid BigInt - instance Instance @relation(fields: [instanceOid], references: [oid]) + tenantOid BigInt + tenant Tenant @relation(fields: [tenantOid], references: [oid]) createdAt DateTime @default(now()) updatedAt DateTime @default(now()) @updatedAt @@ -108,7 +108,7 @@ model Function { runtimeOid BigInt? functionBundles FunctionBundle[] - @@unique([identifier, instanceOid]) + @@unique([identifier, tenantOid]) } enum FunctionDeploymentStatus { diff --git a/service/src/controllers/function.ts b/service/src/controllers/function.ts index 783bc90..d587ad4 100644 --- a/service/src/controllers/function.ts +++ b/service/src/controllers/function.ts @@ -4,26 +4,26 @@ import { functionPresenter } from '../presenters/function'; import { functionService } from '../services'; import { functionInvocationService } from '../services/functionInvocation'; import { app } from './_app'; -import { instanceApp } from './instance'; +import { tenantApp } from './tenant'; -export let functionApp = instanceApp.use(async ctx => { +export let functionApp = tenantApp.use(async ctx => { let functionId = ctx.body.functionId; if (!functionId) throw new Error('Function ID is required'); let func = await functionService.getFunctionById({ id: functionId, - instance: ctx.instance + tenant: ctx.tenant }); return { function: func }; }); export let functionController = app.controller({ - upsert: instanceApp + upsert: tenantApp .handler() .input( v.object({ - instanceId: v.string(), + tenantId: v.string(), name: v.string(), identifier: v.string() @@ -31,7 +31,7 @@ export let functionController = app.controller({ ) .do(async ctx => { let func = await functionService.upsertFunction({ - instance: ctx.instance, + tenant: ctx.tenant, input: { name: ctx.input.name, identifier: ctx.input.identifier @@ -40,18 +40,18 @@ export let functionController = app.controller({ return functionPresenter(func); }), - list: instanceApp + list: tenantApp .handler() .input( Paginator.validate( v.object({ - instanceId: v.string() + tenantId: v.string() }) ) ) .do(async ctx => { let paginator = await functionService.listFunctions({ - instance: ctx.instance + tenant: ctx.tenant }); let list = await paginator.run(ctx.input); @@ -63,7 +63,7 @@ export let functionController = app.controller({ .handler() .input( v.object({ - instanceId: v.string(), + tenantId: v.string(), functionId: v.string() }) ) @@ -73,7 +73,7 @@ export let functionController = app.controller({ .handler() .input( v.object({ - instanceId: v.string(), + tenantId: v.string(), functionId: v.string(), name: v.optional(v.string()) @@ -94,7 +94,7 @@ export let functionController = app.controller({ .handler() .input( v.object({ - instanceId: v.string(), + tenantId: v.string(), functionId: v.string(), payload: v.record(v.any()) @@ -104,7 +104,7 @@ export let functionController = app.controller({ async ctx => await functionInvocationService.invokeFunction({ functionId: ctx.input.functionId, - instanceId: ctx.input.instanceId, + tenantId: ctx.input.tenantId, payload: ctx.input.payload }) ) diff --git a/service/src/controllers/functionDeployment.ts b/service/src/controllers/functionDeployment.ts index a111e6f..59475c5 100644 --- a/service/src/controllers/functionDeployment.ts +++ b/service/src/controllers/functionDeployment.ts @@ -23,7 +23,7 @@ export let functionDeploymentController = app.controller({ .handler() .input( v.object({ - instanceId: v.string(), + tenantId: v.string(), functionId: v.string(), name: v.string(), @@ -48,7 +48,7 @@ export let functionDeploymentController = app.controller({ .do(async ctx => { let version = await functionDeploymentService.createFunctionDeployment({ function: ctx.function, - instance: ctx.instance, + tenant: ctx.tenant, input: { name: ctx.input.name, env: ctx.input.env, @@ -66,7 +66,7 @@ export let functionDeploymentController = app.controller({ Paginator.validate( v.object({ functionId: v.string(), - instanceId: v.string() + tenantId: v.string() }) ) ) @@ -84,7 +84,7 @@ export let functionDeploymentController = app.controller({ .handler() .input( v.object({ - instanceId: v.string(), + tenantId: v.string(), functionId: v.string(), functionDeploymentId: v.string() }) @@ -95,7 +95,7 @@ export let functionDeploymentController = app.controller({ .handler() .input( v.object({ - instanceId: v.string(), + tenantId: v.string(), functionId: v.string(), functionDeploymentId: v.string() }) diff --git a/service/src/controllers/functionInvocation.ts b/service/src/controllers/functionInvocation.ts index 1e47a8b..4773c15 100644 --- a/service/src/controllers/functionInvocation.ts +++ b/service/src/controllers/functionInvocation.ts @@ -24,7 +24,7 @@ export let functionInvocationController = app.controller({ Paginator.validate( v.object({ functionId: v.string(), - instanceId: v.string() + tenantId: v.string() }) ) ) @@ -42,7 +42,7 @@ export let functionInvocationController = app.controller({ .handler() .input( v.object({ - instanceId: v.string(), + tenantId: v.string(), functionId: v.string(), functionInvocationId: v.string() }) diff --git a/service/src/controllers/functionVersion.ts b/service/src/controllers/functionVersion.ts index 9cbf59f..4df99f4 100644 --- a/service/src/controllers/functionVersion.ts +++ b/service/src/controllers/functionVersion.ts @@ -24,7 +24,7 @@ export let functionVersionController = app.controller({ Paginator.validate( v.object({ functionId: v.string(), - instanceId: v.string() + tenantId: v.string() }) ) ) @@ -42,7 +42,7 @@ export let functionVersionController = app.controller({ .handler() .input( v.object({ - instanceId: v.string(), + tenantId: v.string(), functionId: v.string(), functionVersionId: v.string() }) diff --git a/service/src/controllers/index.ts b/service/src/controllers/index.ts index 4d5800b..8e0b286 100644 --- a/service/src/controllers/index.ts +++ b/service/src/controllers/index.ts @@ -5,13 +5,13 @@ import { functionController } from './function'; import { functionDeploymentController } from './functionDeployment'; import { functionInvocationController } from './functionInvocation'; import { functionVersionController } from './functionVersion'; -import { instanceController } from './instance'; import { providerController } from './provider'; import { runtimeController } from './runtime'; +import { tenantController } from './tenant'; export let rootController = app.controller({ runtime: runtimeController, - instance: instanceController, + tenant: tenantController, provider: providerController, function: functionController, functionVersion: functionVersionController, diff --git a/service/src/controllers/instance.ts b/service/src/controllers/instance.ts deleted file mode 100644 index 8733390..0000000 --- a/service/src/controllers/instance.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { v } from '@lowerdeck/validation'; -import { instancePresenter } from '../presenters/instance'; -import { instanceService } from '../services'; -import { app } from './_app'; - -export let instanceApp = app.use(async ctx => { - let instanceId = ctx.body.instanceId; - if (!instanceId) throw new Error('Instance ID is required'); - - let instance = await instanceService.getInstanceById({ id: instanceId }); - - return { instance }; -}); - -export let instanceController = app.controller({ - upsert: app - .handler() - .input( - v.object({ - name: v.string(), - identifier: v.string() - }) - ) - .do(async ctx => { - let instance = await instanceService.upsertInstance({ - input: { - name: ctx.input.name, - identifier: ctx.input.identifier - } - }); - return instancePresenter(instance); - }), - - get: instanceApp - .handler() - .input( - v.object({ - instanceId: v.string() - }) - ) - .do(async ctx => instancePresenter(ctx.instance)) -}); diff --git a/service/src/controllers/runtime.ts b/service/src/controllers/runtime.ts index ab496e5..6ffe6f8 100644 --- a/service/src/controllers/runtime.ts +++ b/service/src/controllers/runtime.ts @@ -22,7 +22,7 @@ export let runtimeController = app.controller({ .input( Paginator.validate( v.object({ - instanceId: v.string() + tenantId: v.string() }) ) ) diff --git a/service/src/controllers/tenant.ts b/service/src/controllers/tenant.ts new file mode 100644 index 0000000..25e2e49 --- /dev/null +++ b/service/src/controllers/tenant.ts @@ -0,0 +1,42 @@ +import { v } from '@lowerdeck/validation'; +import { tenantPresenter } from '../presenters/tenant'; +import { tenantService } from '../services'; +import { app } from './_app'; + +export let tenantApp = app.use(async ctx => { + let tenantId = ctx.body.tenantId; + if (!tenantId) throw new Error('Tenant ID is required'); + + let tenant = await tenantService.getTenantById({ id: tenantId }); + + return { tenant }; +}); + +export let tenantController = app.controller({ + upsert: app + .handler() + .input( + v.object({ + name: v.string(), + identifier: v.string() + }) + ) + .do(async ctx => { + let tenant = await tenantService.upsertTenant({ + input: { + name: ctx.input.name, + identifier: ctx.input.identifier + } + }); + return tenantPresenter(tenant); + }), + + get: tenantApp + .handler() + .input( + v.object({ + tenantId: v.string() + }) + ) + .do(async ctx => tenantPresenter(ctx.tenant)) +}); diff --git a/service/src/forge.ts b/service/src/forge.ts index 36c64ba..b9cd876 100644 --- a/service/src/forge.ts +++ b/service/src/forge.ts @@ -1,7 +1,7 @@ import { canonicalize } from '@lowerdeck/canonicalize'; import { Hash } from '@lowerdeck/hash'; import { createForgeClient } from '@metorial-services/forge-client'; -import type { Instance, Runtime } from '../prisma/generated/client'; +import type { Runtime, Tenant } from '../prisma/generated/client'; import { db } from './db'; import { env } from './env'; import { snowflake } from './id'; @@ -31,38 +31,38 @@ export type ForgeWorkflowStep = artifactName: string; }; -export let ensureForgeInstance = async (instance: Instance) => - await forge.instance.upsert({ - name: instance.name, - identifier: instance.identifier +export let ensureForgeTenant = async (tenant: Tenant) => + await forge.tenant.upsert({ + name: tenant.name, + identifier: tenant.identifier }); export let ensureForgeWorkflow = async (d: { - instance: Instance; + tenant: Tenant; runtime: Runtime; steps: ForgeWorkflowStep[]; }) => { let workflow = await db.runtimeForgeWorkflow.findUnique({ where: { - runtimeOid_instanceOid: { + runtimeOid_tenantOid: { runtimeOid: d.runtime.oid, - instanceOid: d.instance.oid + tenantOid: d.tenant.oid } } }); if (workflow) { return await forge.workflow.get({ - instanceId: workflow.forgeInstanceId, + tenantId: workflow.forgeTenantId, workflowId: workflow.forgeWorkflowId }); } - let instance = await ensureForgeInstance(d.instance); + let tenant = await ensureForgeTenant(d.tenant); let createdWorkflow = await forge.workflow.upsert({ - instanceId: instance.id, + tenantId: tenant.id, identifier: `fncbay_builder_${d.runtime.identifier}`, name: `Function Bay Builder for ${d.runtime.name}` }); @@ -70,7 +70,7 @@ export let ensureForgeWorkflow = async (d: { let hash = await Hash.sha256(canonicalize(d.steps)); let version = await forge.workflowVersion.create({ - instanceId: instance.id, + tenantId: tenant.id, workflowId: createdWorkflow.id, name: `Function Bay (${hash.slice(0, 8)})`, steps: d.steps @@ -79,17 +79,17 @@ export let ensureForgeWorkflow = async (d: { // Upsert to avoid race conditions await db.runtimeForgeWorkflow.upsert({ where: { - runtimeOid_instanceOid: { + runtimeOid_tenantOid: { runtimeOid: d.runtime.oid, - instanceOid: d.instance.oid + tenantOid: d.tenant.oid } }, create: { oid: await snowflake.nextId(), runtimeOid: d.runtime.oid, - instanceOid: d.instance.oid, + tenantOid: d.tenant.oid, forgeWorkflowId: createdWorkflow.id, - forgeInstanceId: instance.id, + forgeTenantId: tenant.id, forgeWorkflowVersionId: version.id }, update: {} diff --git a/service/src/id.ts b/service/src/id.ts index 77d55f7..3dd6a78 100644 --- a/service/src/id.ts +++ b/service/src/id.ts @@ -2,7 +2,7 @@ import { createIdGenerator, idType } from '@lowerdeck/id'; import { Worker as SnowflakeId } from 'snowflake-uuid'; export let ID = createIdGenerator({ - instance: idType.sorted('bins_'), + tenant: idType.sorted('bins_'), provider: idType.sorted('bpro_'), runtime: idType.sorted('brtm_'), diff --git a/service/src/presenters/index.ts b/service/src/presenters/index.ts index 4048493..5769f41 100644 --- a/service/src/presenters/index.ts +++ b/service/src/presenters/index.ts @@ -2,6 +2,6 @@ export * from './function'; export * from './functionDeployment'; export * from './functionInvocation'; export * from './functionVersion'; -export * from './instance'; export * from './provider'; export * from './runtime'; +export * from './tenant'; diff --git a/service/src/presenters/instance.ts b/service/src/presenters/instance.ts deleted file mode 100644 index 46c38a6..0000000 --- a/service/src/presenters/instance.ts +++ /dev/null @@ -1,11 +0,0 @@ -import type { Instance } from '../../prisma/generated/client'; - -export let instancePresenter = (instance: Instance) => ({ - object: 'instance', - - id: instance.id, - identifier: instance.identifier, - name: instance.name, - - createdAt: instance.createdAt -}); diff --git a/service/src/presenters/tenant.ts b/service/src/presenters/tenant.ts new file mode 100644 index 0000000..1d71b03 --- /dev/null +++ b/service/src/presenters/tenant.ts @@ -0,0 +1,11 @@ +import type { Tenant } from '../../prisma/generated/client'; + +export let tenantPresenter = (tenant: Tenant) => ({ + object: 'tenant', + + id: tenant.id, + identifier: tenant.identifier, + name: tenant.name, + + createdAt: tenant.createdAt +}); diff --git a/service/src/queues/build.ts b/service/src/queues/build.ts index 73197a0..7bc8edb 100644 --- a/service/src/queues/build.ts +++ b/service/src/queues/build.ts @@ -33,7 +33,7 @@ let startBuildQueueProcessor = startBuildQueue.process(async data => { runtime: true, function: { include: { - instance: true + tenant: true } } } @@ -41,7 +41,7 @@ let startBuildQueueProcessor = startBuildQueue.process(async data => { if (!deployment) throw new QueueRetryError(); let workflow = await ensureForgeWorkflow({ - instance: deployment.function.instance, + tenant: deployment.function.tenant, runtime: deployment.runtime, steps: defaultProvider.workflow }); @@ -54,7 +54,7 @@ let startBuildQueueProcessor = startBuildQueue.process(async data => { ); let run = await forge.workflowRun.create({ - instanceId: deployment.function.instance.identifier, + tenantId: deployment.function.tenant.identifier, workflowId: workflow.id, files: data.files, @@ -78,7 +78,7 @@ let startBuildQueueProcessor = startBuildQueue.process(async data => { deploymentId: deployment.id, runId: run.id, workflowId: workflow.id, - instanceId: deployment.function.instance.identifier + tenantId: deployment.function.tenant.identifier }); }); @@ -87,7 +87,7 @@ let monitorBuildQueue = createQueue<{ deploymentId: string; runId: string; workflowId: string; - instanceId: string; + tenantId: string; }>({ name: 'fbay/build/mon', redisUrl: env.service.REDIS_URL @@ -95,7 +95,7 @@ let monitorBuildQueue = createQueue<{ let monitorBuildQueueProcessor = monitorBuildQueue.process(async data => { let run = await forge.workflowRun.get({ - instanceId: data.instanceId, + tenantId: data.tenantId, workflowId: data.workflowId, workflowRunId: data.runId }); @@ -119,7 +119,7 @@ let workflowFinishedBuildQueue = createQueue<{ deploymentId: string; runId: string; workflowId: string; - instanceId: string; + tenantId: string; }>({ name: 'fbay/build/wfin', redisUrl: env.service.REDIS_URL @@ -127,7 +127,7 @@ let workflowFinishedBuildQueue = createQueue<{ let workflowFinishedBuildQueueProcessor = workflowFinishedBuildQueue.process(async data => { let run = await forge.workflowRun.get({ - instanceId: data.instanceId, + tenantId: data.tenantId, workflowId: data.workflowId, workflowRunId: data.runId }); diff --git a/service/src/services/function.ts b/service/src/services/function.ts index 48f5667..4e6ad0e 100644 --- a/service/src/services/function.ts +++ b/service/src/services/function.ts @@ -1,7 +1,7 @@ import { notFoundError, ServiceError } from '@lowerdeck/error'; import { Paginator } from '@lowerdeck/pagination'; import { Service } from '@lowerdeck/service'; -import type { Function, Instance } from '../../prisma/generated/client'; +import type { Function, Tenant } from '../../prisma/generated/client'; import { db } from '../db'; import { ID, snowflake } from '../id'; @@ -15,13 +15,13 @@ class functionServiceImpl { name: string; identifier: string; }; - instance: Instance; + tenant: Tenant; }) { return await db.function.upsert({ where: { - identifier_instanceOid: { + identifier_tenantOid: { identifier: d.input.identifier, - instanceOid: d.instance.oid + tenantOid: d.tenant.oid }, status: 'active' }, @@ -31,18 +31,18 @@ class functionServiceImpl { id: await ID.generateId('function'), name: d.input.name, identifier: d.input.identifier, - instanceOid: d.instance.oid, + tenantOid: d.tenant.oid, status: 'active' }, include }); } - async getFunctionById(d: { id: string; instance: Instance }) { + async getFunctionById(d: { id: string; tenant: Tenant }) { let func = await db.function.findFirst({ where: { OR: [{ id: d.id }, { identifier: d.id }], - instanceOid: d.instance.oid, + tenantOid: d.tenant.oid, status: 'active' }, include @@ -51,14 +51,14 @@ class functionServiceImpl { return func; } - async listFunctions(d: { instance: Instance }) { + async listFunctions(d: { tenant: Tenant }) { return Paginator.create(({ prisma }) => prisma( async opts => await db.function.findMany({ ...opts, where: { - instanceOid: d.instance.oid, + tenantOid: d.tenant.oid, status: 'active' }, include diff --git a/service/src/services/functionDeployment.ts b/service/src/services/functionDeployment.ts index e502f61..9a0f8fa 100644 --- a/service/src/services/functionDeployment.ts +++ b/service/src/services/functionDeployment.ts @@ -3,7 +3,7 @@ import { notFoundError, ServiceError } from '@lowerdeck/error'; import { generatePlainId } from '@lowerdeck/id'; import { Paginator } from '@lowerdeck/pagination'; import { Service } from '@lowerdeck/service'; -import type { Function, FunctionDeployment, Instance } from '../../prisma/generated/client'; +import type { Function, FunctionDeployment, Tenant } from '../../prisma/generated/client'; import { db } from '../db'; import { encryption } from '../encryption'; import { forge } from '../forge'; @@ -29,7 +29,7 @@ let include = { class functionDeploymentServiceImpl { async createFunctionDeployment(d: { function: Function; - instance: Instance; + tenant: Tenant; input: { name: string; env: Record; @@ -101,7 +101,7 @@ class functionDeploymentServiceImpl { oid: d.deployment.functionOid }, include: { - instance: true + tenant: true } }); @@ -113,7 +113,7 @@ class functionDeploymentServiceImpl { let forgeLogs = d.deployment.forgeRunId ? await forge.workflowRun.getOutput({ - instanceId: func.instance.identifier, + tenantId: func.tenant.identifier, workflowRunId: d.deployment.forgeRunId, workflowId: d.deployment.forgeWorkflowId! }) diff --git a/service/src/services/functionInvocation.ts b/service/src/services/functionInvocation.ts index 3a1ce5f..a4517a7 100644 --- a/service/src/services/functionInvocation.ts +++ b/service/src/services/functionInvocation.ts @@ -13,13 +13,13 @@ let Sentry = getSentry(); let include = { functionVersion: true }; let getFunctionData = createLocallyCachedFunction({ - getHash: (i: { instanceId: string; functionId: string; versionId?: string }) => - `${i.instanceId}:${i.functionId}`, + getHash: (i: { tenantId: string; functionId: string; versionId?: string }) => + `${i.tenantId}:${i.functionId}`, provider: async i => await db.function.findFirst({ where: { OR: [{ id: i.functionId }, { identifier: i.functionId }], - instance: { OR: [{ id: i.instanceId }, { identifier: i.instanceId }] } + tenant: { OR: [{ id: i.tenantId }, { identifier: i.tenantId }] } }, include: { currentVersion: { @@ -38,13 +38,13 @@ let getFunctionData = createLocallyCachedFunction({ class functionInvocationServiceImpl { async invokeFunction(d: { - instanceId: string; + tenantId: string; functionId: string; versionId?: string; payload: Record; }) { let func = await getFunctionData({ - instanceId: d.instanceId, + tenantId: d.tenantId, functionId: d.functionId }); if (!func) throw new ServiceError(notFoundError('function')); diff --git a/service/src/services/index.ts b/service/src/services/index.ts index 4048493..5769f41 100644 --- a/service/src/services/index.ts +++ b/service/src/services/index.ts @@ -2,6 +2,6 @@ export * from './function'; export * from './functionDeployment'; export * from './functionInvocation'; export * from './functionVersion'; -export * from './instance'; export * from './provider'; export * from './runtime'; +export * from './tenant'; diff --git a/service/src/services/instance.ts b/service/src/services/tenant.ts similarity index 58% rename from service/src/services/instance.ts rename to service/src/services/tenant.ts index f7375e3..d240b67 100644 --- a/service/src/services/instance.ts +++ b/service/src/services/tenant.ts @@ -5,19 +5,19 @@ import { ID, snowflake } from '../id'; let include = {}; -class instanceServiceImpl { - async upsertInstance(d: { +class tenantServiceImpl { + async upsertTenant(d: { input: { name: string; identifier: string; }; }) { - return await db.instance.upsert({ + return await db.tenant.upsert({ where: { identifier: d.input.identifier }, update: { name: d.input.name }, create: { oid: snowflake.nextId(), - id: await ID.generateId('instance'), + id: await ID.generateId('tenant'), name: d.input.name, identifier: d.input.identifier }, @@ -25,17 +25,17 @@ class instanceServiceImpl { }); } - async getInstanceById(d: { id: string }) { - let instance = await db.instance.findFirst({ + async getTenantById(d: { id: string }) { + let tenant = await db.tenant.findFirst({ where: { OR: [{ id: d.id }, { identifier: d.id }] }, include }); - if (!instance) throw new ServiceError(notFoundError('instance')); - return instance; + if (!tenant) throw new ServiceError(notFoundError('tenant')); + return tenant; } } -export let instanceService = Service.create( - 'instanceService', - () => new instanceServiceImpl() +export let tenantService = Service.create( + 'tenantService', + () => new tenantServiceImpl() ).build();