History

rework naming

Rhys Sullivan committed 7 months ago

Commit da613211 parent f0c45e713 files · +310 −304Browse files

Showing the changes to examples (1 of 13 files). Show all

Unified · Split

examples/sqlite-sdk-consumer/src/sqlite-backend.ts+90−87
@@ -14,10 +14,10 @@ import { · 13 unmodified lines
1414 import {
1515 createExecutorBackend,
1616 type ExecutorBackend,
17− type ExecutorBackendServices,
18− type ExecutorScopeConfigBackend,
19− type ExecutorScopeStateBackend,
20− type ExecutorSourceArtifactBackend,
17+ type ExecutorBackendRepositories,
18+ type ExecutorWorkspaceConfigRepository,
19+ type ExecutorWorkspaceStateRepository,
20+ type ExecutorWorkspaceSourceArtifactRepository,
2121 } from "@executor/platform-sdk";
2222 import type {
2323 AuthArtifact,
@@ -53,10 +53,13 @@ export type CreateSqliteExecutorBackendOptions = { · 29 unmodified lines
5353 actorScopeId?: string;
5454 };
5555
56−type ScopeConfig = Awaited<ReturnType<ExecutorScopeConfigBackend["load"]>>;
57−type ScopeState = Awaited<ReturnType<ExecutorScopeStateBackend["load"]>>;
58−type SourceArtifact = ReturnType<ExecutorSourceArtifactBackend["build"]>;
59−type SourceArtifactBuildInput = Parameters<ExecutorSourceArtifactBackend["build"]>[0];
56+type ScopeConfig = Awaited<ReturnType<ExecutorWorkspaceConfigRepository["load"]>>;
57+type ScopeState = Awaited<ReturnType<ExecutorWorkspaceStateRepository["load"]>>;
58+type SourceArtifact =
59+ ReturnType<ExecutorWorkspaceSourceArtifactRepository["build"]>;
60+type SourceArtifactBuildInput = Parameters<
61+ ExecutorWorkspaceSourceArtifactRepository["build"]
62+>[0];
6063
6164 type SecretMaterialSummary = {
6265 id: string;
@@ -924,7 +927,7 @@ export const createSqliteExecutorBackend = ( · 861 unmodified lines
924927 : (options.databasePath ?? ":memory:");
925928
926929 return createExecutorBackend({
927− loadServices: () => {
930+ loadRepositories: () => {
928931 const store = openSqliteStore(databasePath);
929932 const { auth, secrets, executions } = createStorageDomains(store);
930933
@@ -937,9 +940,21 @@ export const createSqliteExecutorBackend = ( · 6 unmodified lines
937940 databasePath,
938941 },
939942 },
940− storage: {
941− installation: {
942− load: () => {
943+ installation: {
944+ load: () => {
945+ const row = store.db.select().from(installations).where(eq(installations.key, "active")).get();
946+ return row
947+ ? {
948+ scopeId: row.scopeId as LocalInstallation["scopeId"],
949+ actorScopeId: row.actorScopeId as LocalInstallation["actorScopeId"],
950+ resolutionScopeIds: parseJson<LocalInstallation["resolutionScopeIds"]>(
951+ row.resolutionScopeIdsJson,
952+ ),
953+ }
954+ : createInstallation(options);
955+ },
956+ getOrProvision: () => {
957+ const installation = (() => {
943958 const row = store.db.select().from(installations).where(eq(installations.key, "active")).get();
944959 return row
945960 ? {
@@ -950,37 +965,25 @@ export const createSqliteExecutorBackend = ( · 4 unmodified lines
950965 ),
951966 }
952967 : createInstallation(options);
953− },
954− getOrProvision: () => {
955− const installation = (() => {
956− const row = store.db.select().from(installations).where(eq(installations.key, "active")).get();
957− return row
958− ? {
959− scopeId: row.scopeId as LocalInstallation["scopeId"],
960− actorScopeId: row.actorScopeId as LocalInstallation["actorScopeId"],
961− resolutionScopeIds: parseJson<LocalInstallation["resolutionScopeIds"]>(
962− row.resolutionScopeIdsJson,
963− ),
964− }
965− : createInstallation(options);
966− })();
967− store.db.insert(installations).values({
968− key: "active",
968+ })();
969+ store.db.insert(installations).values({
970+ key: "active",
971+ scopeId: installation.scopeId,
972+ actorScopeId: installation.actorScopeId,
973+ resolutionScopeIdsJson: JSON.stringify(installation.resolutionScopeIds),
974+ }).onConflictDoUpdate({
975+ target: installations.key,
976+ set: {
969977 scopeId: installation.scopeId,
970978 actorScopeId: installation.actorScopeId,
971979 resolutionScopeIdsJson: JSON.stringify(installation.resolutionScopeIds),
972− }).onConflictDoUpdate({
973− target: installations.key,
974− set: {
975− scopeId: installation.scopeId,
976− actorScopeId: installation.actorScopeId,
977− resolutionScopeIdsJson: JSON.stringify(installation.resolutionScopeIds),
978− },
979− }).run();
980− return installation;
981− },
980+ },
981+ }).run();
982+ return installation;
982983 },
983− scopeConfig: {
984+ },
985+ workspace: {
986+ config: {
984987 load: () => {
985988 const row = store.db.select().from(scopeConfigs).where(eq(scopeConfigs.key, "project")).get();
986989 const projectConfig = row
@@ -1003,7 +1006,7 @@ export const createSqliteExecutorBackend = ( · 16 unmodified lines
10031006 },
10041007 resolveRelativePath: ({ path, scopeRoot }) => resolvePath(scopeRoot, path),
10051008 },
1006− scopeState: {
1009+ state: {
10071010 load: () => {
10081011 const row = store.db.select().from(scopeStates).where(eq(scopeStates.key, "active")).get();
10091012 return row ? parseJson<ScopeState>(row.stateJson) : defaultScopeState();
@@ -1039,55 +1042,52 @@ export const createSqliteExecutorBackend = ( · 29 unmodified lines
10391042 store.db.delete(sourceArtifacts).where(eq(sourceArtifacts.sourceId, sourceId)).run();
10401043 },
10411044 },
1042− auth,
1043− secrets: {
1044− ...secrets,
1045− resolve: ({ ref }) => {
1046− const material = secrets.getById(
1047− ref.handle as SecretMaterial["id"],
1048− );
1049− if (!material || material.value === null) {
1050− throw new Error(`Missing secret material ${ref.handle}`);
1051− }
1052− return material.value;
1053− },
1054− store: ({ purpose, value, name, providerId }) => {
1055− const now = Date.now();
1056− const id = SecretMaterialIdSchema.make(`secret_${randomUUID()}`);
1057− const material: SecretMaterial = {
1058− id,
1059− providerId: providerId ?? SQLITE_SECRET_PROVIDER_ID,
1060− handle: id,
1061− name: name ?? null,
1062− purpose,
1063− value,
1064− createdAt: now,
1065− updatedAt: now,
1066− };
1067− secrets.upsert(material);
1068− return {
1069− providerId: material.providerId,
1070− handle: material.handle,
1071− } satisfies SecretRef;
1072− },
1073− delete: (ref) =>
1074− secrets.removeById(ref.handle as SecretMaterial["id"]),
1075− update: ({ ref, name, value }) => {
1076− const updated = secrets.updateById(
1077− ref.handle as SecretMaterial["id"],
1078− { name, value },
1079− );
1080− if (!updated) {
1081− throw new Error(`Missing secret material ${ref.handle}`);
1082− }
1083− return updated;
1084− },
1045+ sourceAuth: auth,
1046+ },
1047+ secrets: {
1048+ ...secrets,
1049+ resolve: ({ ref }) => {
1050+ const material = secrets.getById(
1051+ ref.handle as SecretMaterial["id"],
1052+ );
1053+ if (!material || material.value === null) {
1054+ throw new Error(`Missing secret material ${ref.handle}`);
1055+ }
1056+ return material.value;
10851057 },
1086− executions,
1087− close: async () => {
1088− store.close();
1058+ store: ({ purpose, value, name, providerId }) => {
1059+ const now = Date.now();
1060+ const id = SecretMaterialIdSchema.make(`secret_${randomUUID()}`);
1061+ const material: SecretMaterial = {
1062+ id,
1063+ providerId: providerId ?? SQLITE_SECRET_PROVIDER_ID,
1064+ handle: id,
1065+ name: name ?? null,
1066+ purpose,
1067+ value,
1068+ createdAt: now,
1069+ updatedAt: now,
1070+ };
1071+ secrets.upsert(material);
1072+ return {
1073+ providerId: material.providerId,
1074+ handle: material.handle,
1075+ } satisfies SecretRef;
1076+ },
1077+ delete: (ref) =>
1078+ secrets.removeById(ref.handle as SecretMaterial["id"]),
1079+ update: ({ ref, name, value }) => {
1080+ const updated = secrets.updateById(
1081+ ref.handle as SecretMaterial["id"],
1082+ { name, value },
1083+ );
1084+ if (!updated) {
1085+ throw new Error(`Missing secret material ${ref.handle}`);
1086+ }
1087+ return updated;
10891088 },
10901089 },
1090+ executions,
10911091 instanceConfig: {
10921092 resolve: () => ({
10931093 platform: "sqlite-sdk-example",
@@ -1101,7 +1101,10 @@ export const createSqliteExecutorBackend = ( · 7 unmodified lines
11011101 defaultSecretStoreProvider: SQLITE_SECRET_PROVIDER_ID,
11021102 }),
11031103 },
1104− } satisfies ExecutorBackendServices;
1104+ close: async () => {
1105+ store.close();
1106+ },
1107+ } satisfies ExecutorBackendRepositories;
11051108 },
11061109 });
11071110 };