@ankhorage/projects 0.2.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/capabilities/index.d.ts +11 -1
- package/dist/capabilities/index.js +9 -1
- package/dist/features/projects/application/projects.d.ts +1 -0
- package/dist/features/projects/application/projects.js +4 -0
- package/dist/features/projects/composition/createExpoProjectMaterializer.d.ts +32 -0
- package/dist/features/projects/composition/createExpoProjectMaterializer.js +149 -0
- package/dist/features/projects/composition/createProjectsApiHandlerResolver.d.ts +10 -0
- package/dist/features/projects/composition/createProjectsApiHandlerResolver.js +227 -0
- package/dist/features/projects/ports/ProjectRepository.d.ts +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/package.json +23 -3
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
# @ankhorage/projects
|
|
5
5
|
|
|
6
|
-
         
|
|
7
7
|
|
|
8
8
|
Standalone project identity and repository actions.
|
|
9
9
|
|
|
@@ -59,10 +59,20 @@ export declare const CAPABILITIES: readonly [{
|
|
|
59
59
|
};
|
|
60
60
|
readonly label: "Reload project manifest";
|
|
61
61
|
readonly description: "Read the persisted project manifest draft and immutable revision history.";
|
|
62
|
+
}, {
|
|
63
|
+
readonly id: "projects.revision";
|
|
64
|
+
readonly owner: "@ankhorage/projects";
|
|
65
|
+
readonly access: readonly ["read"];
|
|
66
|
+
readonly binding: {
|
|
67
|
+
readonly kind: "storage";
|
|
68
|
+
readonly bindableAs: readonly ["target"];
|
|
69
|
+
};
|
|
70
|
+
readonly label: "Read project manifest revision";
|
|
71
|
+
readonly description: "Read one immutable project manifest revision by identity.";
|
|
62
72
|
}, {
|
|
63
73
|
readonly id: "projects.materialize";
|
|
64
74
|
readonly owner: "@ankhorage/projects";
|
|
65
|
-
readonly access: readonly ["
|
|
75
|
+
readonly access: readonly ["invoke"];
|
|
66
76
|
readonly binding: {
|
|
67
77
|
readonly kind: "action";
|
|
68
78
|
readonly bindableAs: readonly ["target"];
|
|
@@ -48,10 +48,18 @@ export const CAPABILITIES = [
|
|
|
48
48
|
label: 'Reload project manifest',
|
|
49
49
|
description: 'Read the persisted project manifest draft and immutable revision history.',
|
|
50
50
|
},
|
|
51
|
+
{
|
|
52
|
+
id: 'projects.revision',
|
|
53
|
+
owner: '@ankhorage/projects',
|
|
54
|
+
access: ['read'],
|
|
55
|
+
binding: { kind: 'storage', bindableAs: ['target'] },
|
|
56
|
+
label: 'Read project manifest revision',
|
|
57
|
+
description: 'Read one immutable project manifest revision by identity.',
|
|
58
|
+
},
|
|
51
59
|
{
|
|
52
60
|
id: 'projects.materialize',
|
|
53
61
|
owner: '@ankhorage/projects',
|
|
54
|
-
access: ['
|
|
62
|
+
access: ['invoke'],
|
|
55
63
|
binding: { kind: 'action', bindableAs: ['target'] },
|
|
56
64
|
label: 'Materialize project revision',
|
|
57
65
|
description: 'Materialize one stored immutable project revision through an injected owner generator.',
|
|
@@ -8,6 +8,7 @@ export declare const projects: {
|
|
|
8
8
|
update: (repository: ProjectRepository, input: UpdateProjectInput, now?: Date) => Promise<Project | null>;
|
|
9
9
|
save: (repository: ProjectRepository, input: SaveProjectManifestInput, now?: Date) => Promise<Project | null>;
|
|
10
10
|
reload: (repository: ProjectRepository, input: ReloadProjectManifestInput) => Promise<ProjectManifest | null>;
|
|
11
|
+
revision: (repository: ProjectRepository, input: MaterializeProjectRevisionInput) => Promise<ProjectManifestRevision | null>;
|
|
11
12
|
materialize: (repository: ProjectRepository, materializer: ProjectMaterializer, input: MaterializeProjectRevisionInput) => Promise<ProjectManifestRevision | null>;
|
|
12
13
|
delete: (repository: ProjectRepository, id: string) => Promise<Project | null>;
|
|
13
14
|
};
|
|
@@ -17,6 +17,10 @@ export const projects = {
|
|
|
17
17
|
update: async (repository, input, now = new Date()) => repository.updateAsync(input.id, (project) => updateProject(project, input, now)),
|
|
18
18
|
save: async (repository, input, now = new Date()) => repository.updateAsync(input.id, (project) => saveProjectManifest(project, input, now)),
|
|
19
19
|
reload: async (repository, input) => (await repository.readAsync(input.id))?.manifest ?? null,
|
|
20
|
+
revision: async (repository, input) => {
|
|
21
|
+
const project = await repository.readAsync(input.id);
|
|
22
|
+
return (project?.manifest.revisions.find((candidate) => candidate.id === input.revisionId) ?? null);
|
|
23
|
+
},
|
|
20
24
|
materialize: async (repository, materializer, input) => {
|
|
21
25
|
const project = await repository.readAsync(input.id);
|
|
22
26
|
const revision = project?.manifest.revisions.find((candidate) => candidate.id === input.revisionId);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { AppCategory } from '@ankhorage/contracts';
|
|
2
|
+
import type { NavigatorGenerationBindings, NavigatorRuntimePlatform } from '@ankhorage/contracts/navigator';
|
|
3
|
+
import type { Project, ProjectManifestRevision } from '../../../types/projects.js';
|
|
4
|
+
/*** Inputs fixed by the host before materializing one immutable Projects revision. */
|
|
5
|
+
export interface CreateExpoProjectMaterializerInput {
|
|
6
|
+
readonly targetDirectory: string;
|
|
7
|
+
readonly template: Readonly<{
|
|
8
|
+
category: AppCategory;
|
|
9
|
+
slug: string;
|
|
10
|
+
}>;
|
|
11
|
+
readonly navigator: Readonly<{
|
|
12
|
+
readonly bindings: NavigatorGenerationBindings;
|
|
13
|
+
readonly platform: NavigatorRuntimePlatform;
|
|
14
|
+
readonly expoRouterVersion: string;
|
|
15
|
+
}>;
|
|
16
|
+
}
|
|
17
|
+
/*** The public result of materializing one runnable, self-contained Expo project directory. */
|
|
18
|
+
export interface ExpoProjectMaterializationResult {
|
|
19
|
+
readonly projectId: string;
|
|
20
|
+
readonly revisionId: string;
|
|
21
|
+
readonly targetDirectory: string;
|
|
22
|
+
readonly files: readonly string[];
|
|
23
|
+
}
|
|
24
|
+
/*** A concrete Projects materializer composed solely from released owner APIs. */
|
|
25
|
+
export interface ExpoProjectMaterializer {
|
|
26
|
+
materializeAsync(input: Readonly<{
|
|
27
|
+
project: Project;
|
|
28
|
+
revision: ProjectManifestRevision;
|
|
29
|
+
}>): Promise<ExpoProjectMaterializationResult>;
|
|
30
|
+
}
|
|
31
|
+
/*** Create the public, caller-targeted Expo materializer for stored immutable project revisions. */
|
|
32
|
+
export declare function createExpoProjectMaterializer(input: CreateExpoProjectMaterializerInput): ExpoProjectMaterializer;
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { lstat, mkdir, mkdtemp, readdir, readFile, realpath, rm, writeFile, } from 'node:fs/promises';
|
|
2
|
+
import { basename, dirname, relative, resolve } from 'node:path';
|
|
3
|
+
import { resolveExpoRuntimeGeneratedAppScaffold } from '@ankhorage/expo-runtime/generated-app';
|
|
4
|
+
import { resolveExpoRuntimePlan } from '@ankhorage/expo-runtime/planning';
|
|
5
|
+
import { createNavigatorPlan, generateNavigator } from '@ankhorage/navigator';
|
|
6
|
+
import { materializeTemplateRevision } from '@ankhorage/templates';
|
|
7
|
+
/*** Create the public, caller-targeted Expo materializer for stored immutable project revisions. */
|
|
8
|
+
export function createExpoProjectMaterializer(input) {
|
|
9
|
+
return {
|
|
10
|
+
materializeAsync: async ({ project, revision }) => materializeExpoProjectAsync(input, project, revision),
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/*** Coordinate owner plans and Template output into one prevalidated caller-owned Expo target. */
|
|
14
|
+
async function materializeExpoProjectAsync(input, project, revision) {
|
|
15
|
+
assertReleasedOwnerApis();
|
|
16
|
+
const targetDirectory = await assertEmptyTargetDirectoryAsync(input.targetDirectory);
|
|
17
|
+
const generatedFiles = createGeneratedFiles(revision.manifest, input.navigator);
|
|
18
|
+
const stagingDirectory = await mkdtemp(`${dirname(targetDirectory)}/.ankhorage-projects-`);
|
|
19
|
+
try {
|
|
20
|
+
const template = await ownerApis.materializeTemplateRevision({
|
|
21
|
+
cwd: stagingDirectory,
|
|
22
|
+
projectSlug: revision.manifest.metadata.slug,
|
|
23
|
+
template: input.template,
|
|
24
|
+
manifest: revision.manifest,
|
|
25
|
+
});
|
|
26
|
+
const templateFiles = await readTemplateFilesAsync(template.projectPath, template.createdFiles);
|
|
27
|
+
assertNoPathCollisions(templateFiles.map(({ relativePath }) => relativePath), generatedFiles.map(({ relativePath }) => relativePath));
|
|
28
|
+
await writeFilesAsync(targetDirectory, [...templateFiles, ...generatedFiles]);
|
|
29
|
+
return createMaterializationResult(project, revision, targetDirectory, templateFiles, generatedFiles);
|
|
30
|
+
}
|
|
31
|
+
finally {
|
|
32
|
+
await rm(stagingDirectory, { recursive: true, force: true });
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/*** Produce every Runtime- and Navigator-owned file before Template or target filesystem writes. */
|
|
36
|
+
function createGeneratedFiles(manifest, navigatorInput) {
|
|
37
|
+
const runtimePlan = ownerApis.resolveExpoRuntimePlan(manifest);
|
|
38
|
+
assertNoErrors(runtimePlan.diagnostics, 'Expo Runtime');
|
|
39
|
+
const navigatorPlan = ownerApis.createNavigatorPlan(manifest.navigator, {
|
|
40
|
+
platform: navigatorInput.platform,
|
|
41
|
+
expoRouterVersion: navigatorInput.expoRouterVersion,
|
|
42
|
+
});
|
|
43
|
+
const navigator = ownerApis.generateNavigator(navigatorPlan, navigatorInput.bindings);
|
|
44
|
+
assertNoErrors(navigator.diagnostics, 'Navigator');
|
|
45
|
+
const runtime = ownerApis.resolveExpoRuntimeGeneratedAppScaffold(manifest, runtimePlan);
|
|
46
|
+
const files = [
|
|
47
|
+
...runtime.files.map((file) => ({
|
|
48
|
+
relativePath: file.relativePath,
|
|
49
|
+
source: file.source,
|
|
50
|
+
})),
|
|
51
|
+
...navigator.files.map((file) => ({
|
|
52
|
+
relativePath: file.path,
|
|
53
|
+
source: file.contents,
|
|
54
|
+
})),
|
|
55
|
+
];
|
|
56
|
+
assertUniqueRelativePaths(files.map(({ relativePath }) => relativePath));
|
|
57
|
+
return files;
|
|
58
|
+
}
|
|
59
|
+
/*** Return the stable public materialization identity and complete sorted generated-file inventory. */
|
|
60
|
+
function createMaterializationResult(project, revision, targetDirectory, templateFiles, generatedFiles) {
|
|
61
|
+
return {
|
|
62
|
+
projectId: project.id,
|
|
63
|
+
revisionId: revision.id,
|
|
64
|
+
targetDirectory,
|
|
65
|
+
files: [...templateFiles, ...generatedFiles]
|
|
66
|
+
.map(({ relativePath }) => relativePath)
|
|
67
|
+
.sort((left, right) => left.localeCompare(right)),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/*** Narrow the released owner API boundary so optional peer implementations cannot leak into Projects. */
|
|
71
|
+
const ownerApis = {
|
|
72
|
+
materializeTemplateRevision: materializeTemplateRevision,
|
|
73
|
+
createNavigatorPlan: createNavigatorPlan,
|
|
74
|
+
generateNavigator: generateNavigator,
|
|
75
|
+
resolveExpoRuntimePlan: resolveExpoRuntimePlan,
|
|
76
|
+
resolveExpoRuntimeGeneratedAppScaffold: resolveExpoRuntimeGeneratedAppScaffold,
|
|
77
|
+
};
|
|
78
|
+
/*** Reject unavailable owner emitters rather than reproducing their source in Projects. */
|
|
79
|
+
function assertReleasedOwnerApis() {
|
|
80
|
+
if (typeof ownerApis.materializeTemplateRevision !== 'function' ||
|
|
81
|
+
typeof ownerApis.createNavigatorPlan !== 'function' ||
|
|
82
|
+
typeof ownerApis.generateNavigator !== 'function' ||
|
|
83
|
+
typeof ownerApis.resolveExpoRuntimePlan !== 'function' ||
|
|
84
|
+
typeof ownerApis.resolveExpoRuntimeGeneratedAppScaffold !== 'function') {
|
|
85
|
+
throw new Error('Required released owner materialization API is unavailable.');
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/*** Resolve one existing, empty, non-symlink target directory before writing any output. */
|
|
89
|
+
async function assertEmptyTargetDirectoryAsync(target) {
|
|
90
|
+
const resolvedTarget = resolve(target);
|
|
91
|
+
const stats = await lstat(resolvedTarget);
|
|
92
|
+
if (!stats.isDirectory() || stats.isSymbolicLink()) {
|
|
93
|
+
throw new Error(`Materialization target must be a regular directory: ${resolvedTarget}`);
|
|
94
|
+
}
|
|
95
|
+
if ((await readdir(resolvedTarget)).length > 0) {
|
|
96
|
+
throw new Error(`Materialization target must be empty: ${resolvedTarget}`);
|
|
97
|
+
}
|
|
98
|
+
return realpath(resolvedTarget);
|
|
99
|
+
}
|
|
100
|
+
/*** Reject owner diagnostics that make a generated application invalid before filesystem side effects. */
|
|
101
|
+
function assertNoErrors(diagnostics, owner) {
|
|
102
|
+
const errors = diagnostics.filter(({ severity }) => severity === 'error');
|
|
103
|
+
if (errors.length > 0) {
|
|
104
|
+
throw new Error(`${owner} cannot materialize this revision: ${errors.map(({ message }) => message).join(' ')}`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/*** Read exactly the files reported by Templates while keeping every path inside its staging project. */
|
|
108
|
+
async function readTemplateFilesAsync(projectPath, files) {
|
|
109
|
+
return Promise.all(files.map(async (relativePath) => ({
|
|
110
|
+
relativePath: assertSafeRelativePath(projectPath, relativePath),
|
|
111
|
+
source: await readFile(resolve(projectPath, relativePath)),
|
|
112
|
+
})));
|
|
113
|
+
}
|
|
114
|
+
/*** Write all materialized files with exclusive creation so no existing caller file is overwritten. */
|
|
115
|
+
async function writeFilesAsync(targetDirectory, files) {
|
|
116
|
+
for (const file of files) {
|
|
117
|
+
const relativePath = assertSafeRelativePath(targetDirectory, file.relativePath);
|
|
118
|
+
const targetPath = resolve(targetDirectory, relativePath);
|
|
119
|
+
await mkdir(dirname(targetPath), { recursive: true });
|
|
120
|
+
await writeFile(targetPath, file.source, { flag: 'wx' });
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/*** Ensure an owner-reported project-relative path never crosses its designated directory. */
|
|
124
|
+
function assertSafeRelativePath(directory, candidate) {
|
|
125
|
+
const resolvedPath = resolve(directory, candidate);
|
|
126
|
+
const pathRelative = relative(directory, resolvedPath);
|
|
127
|
+
if (candidate.length === 0 ||
|
|
128
|
+
pathRelative.length === 0 ||
|
|
129
|
+
pathRelative === '..' ||
|
|
130
|
+
pathRelative.startsWith('../') ||
|
|
131
|
+
basename(resolvedPath) === '..') {
|
|
132
|
+
throw new Error(`Materialized file path escapes its target directory: ${candidate}`);
|
|
133
|
+
}
|
|
134
|
+
return pathRelative;
|
|
135
|
+
}
|
|
136
|
+
/*** Reject duplicate paths emitted by one owner before any write can begin. */
|
|
137
|
+
function assertUniqueRelativePaths(paths) {
|
|
138
|
+
if (new Set(paths).size !== paths.length) {
|
|
139
|
+
throw new Error('An owner emitted duplicate generated file paths.');
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/*** Reject a collision across owner outputs instead of silently selecting one producer. */
|
|
143
|
+
function assertNoPathCollisions(templatePaths, generatedPaths) {
|
|
144
|
+
const templatePathSet = new Set(templatePaths);
|
|
145
|
+
const collision = generatedPaths.find((path) => templatePathSet.has(path));
|
|
146
|
+
if (collision !== undefined) {
|
|
147
|
+
throw new Error(`Owner outputs collide at generated file path: ${collision}`);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ApiHandlerResolver } from '@ankhorage/api';
|
|
2
|
+
import type { ProjectMaterializer, ProjectRepository } from '../ports/ProjectRepository.js';
|
|
3
|
+
type CreateProjectsApiHandlerResolverInput = Readonly<{
|
|
4
|
+
repository: ProjectRepository;
|
|
5
|
+
materializer?: ProjectMaterializer;
|
|
6
|
+
allowDelete?: boolean;
|
|
7
|
+
}>;
|
|
8
|
+
/*** Create the Projects-owned resolver for host-approved server API operations. */
|
|
9
|
+
export declare function createProjectsApiHandlerResolver(input: CreateProjectsApiHandlerResolverInput): ApiHandlerResolver;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { isAppManifest } from '@ankhorage/contracts';
|
|
2
|
+
import { isRecord } from '@ankhorage/utility/object';
|
|
3
|
+
import { CAPABILITIES } from '../../../capabilities/index.js';
|
|
4
|
+
import { projects } from '../application/projects.js';
|
|
5
|
+
import { deriveProjectIdentity } from '../domain/deriveProjectIdentity.js';
|
|
6
|
+
/*** Create the Projects-owned resolver for host-approved server API operations. */
|
|
7
|
+
export function createProjectsApiHandlerResolver(input) {
|
|
8
|
+
return (request) => resolveProjectsApiHandler(input, request);
|
|
9
|
+
}
|
|
10
|
+
/*** Resolve only canonical Projects operations declared by the host API definition. */
|
|
11
|
+
function resolveProjectsApiHandler(input, request) {
|
|
12
|
+
const capability = CAPABILITIES.find((candidate) => candidate.id === request.declaration.capability);
|
|
13
|
+
const operation = capability && createProjectsApiOperations(input)[capability.id];
|
|
14
|
+
if (!capability ||
|
|
15
|
+
!operation ||
|
|
16
|
+
request.binding.operationId !== capability.id ||
|
|
17
|
+
request.binding.operation.intent !== operation.intent ||
|
|
18
|
+
request.binding.method !== operation.method ||
|
|
19
|
+
(capability.id === 'projects.delete' && input.allowDelete !== true)) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
capability,
|
|
24
|
+
approval: {
|
|
25
|
+
operationId: request.binding.operationId,
|
|
26
|
+
intent: operation.intent,
|
|
27
|
+
method: operation.method,
|
|
28
|
+
capabilityId: capability.id,
|
|
29
|
+
owner: capability.owner,
|
|
30
|
+
scope: request.context,
|
|
31
|
+
},
|
|
32
|
+
handler: operation.handler,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/*** Bind each fixed Projects capability to its existing owner action. */
|
|
36
|
+
function createProjectsApiOperations(input) {
|
|
37
|
+
return {
|
|
38
|
+
'projects.list': {
|
|
39
|
+
intent: 'read',
|
|
40
|
+
method: 'GET',
|
|
41
|
+
handler: async (_request, context) => ({
|
|
42
|
+
body: (await projects.list(input.repository)).filter((project) => project.id === context.composition?.projectId),
|
|
43
|
+
}),
|
|
44
|
+
},
|
|
45
|
+
'projects.read': createReadOperation(input.repository),
|
|
46
|
+
'projects.create': createCreateOperation(input.repository),
|
|
47
|
+
'projects.update': createUpdateOperation(input.repository),
|
|
48
|
+
'projects.save': createSaveOperation(input.repository),
|
|
49
|
+
'projects.reload': createReloadOperation(input.repository),
|
|
50
|
+
'projects.revision': createRevisionOperation(input.repository),
|
|
51
|
+
'projects.materialize': createMaterializeOperation(input.repository, input.materializer),
|
|
52
|
+
'projects.delete': createDeleteOperation(input.repository),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/*** Read exactly the project selected by the API composition scope. */
|
|
56
|
+
function createReadOperation(repository) {
|
|
57
|
+
return {
|
|
58
|
+
intent: 'read',
|
|
59
|
+
method: 'GET',
|
|
60
|
+
handler: async (request, context) => readProjectResponse(repository, request, context.composition?.projectId),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/*** Create only the project identity selected by the API composition scope. */
|
|
64
|
+
function createCreateOperation(repository) {
|
|
65
|
+
return {
|
|
66
|
+
intent: 'create',
|
|
67
|
+
method: 'POST',
|
|
68
|
+
handler: async (request, context) => {
|
|
69
|
+
const name = readName(request.body);
|
|
70
|
+
const projectId = context.composition?.projectId;
|
|
71
|
+
try {
|
|
72
|
+
if (!name || !projectId || deriveProjectIdentity(name) !== projectId) {
|
|
73
|
+
return invalidResponse('Project creation does not match the composition scope.');
|
|
74
|
+
}
|
|
75
|
+
return { status: 201, body: await projects.create(repository, { name }) };
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
return projectActionFailureResponse(error);
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/*** Update exactly the project selected by the API composition scope. */
|
|
84
|
+
function createUpdateOperation(repository) {
|
|
85
|
+
return {
|
|
86
|
+
intent: 'update',
|
|
87
|
+
method: 'PATCH',
|
|
88
|
+
handler: async (request, context) => {
|
|
89
|
+
const id = readScopedProjectId(request, context.composition?.projectId);
|
|
90
|
+
const name = readName(request.body);
|
|
91
|
+
if (!id || !name)
|
|
92
|
+
return invalidResponse('Project update requires a scoped projectId and name.');
|
|
93
|
+
try {
|
|
94
|
+
return missingResponse(await projects.update(repository, { id, name }));
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
return projectActionFailureResponse(error);
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/*** Save a validated manifest only for the project selected by the composition scope. */
|
|
103
|
+
function createSaveOperation(repository) {
|
|
104
|
+
return {
|
|
105
|
+
intent: 'update',
|
|
106
|
+
method: 'PUT',
|
|
107
|
+
handler: async (request, context) => {
|
|
108
|
+
const id = readScopedProjectId(request, context.composition?.projectId);
|
|
109
|
+
const body = readManifestSaveBody(request.body);
|
|
110
|
+
if (!id || !body)
|
|
111
|
+
return invalidResponse('Manifest save requires a scoped projectId and valid body.');
|
|
112
|
+
try {
|
|
113
|
+
return missingResponse(await projects.save(repository, { id, ...body }));
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
return projectActionFailureResponse(error);
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
/*** Reload the draft and revision history only for the scoped project. */
|
|
122
|
+
function createReloadOperation(repository) {
|
|
123
|
+
return {
|
|
124
|
+
intent: 'read',
|
|
125
|
+
method: 'GET',
|
|
126
|
+
handler: async (request, context) => {
|
|
127
|
+
const id = readScopedProjectId(request, context.composition?.projectId);
|
|
128
|
+
return id
|
|
129
|
+
? missingResponse(await projects.reload(repository, { id }))
|
|
130
|
+
: invalidResponse('Invalid project scope.');
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
/*** Read one immutable revision only from the scoped project. */
|
|
135
|
+
function createRevisionOperation(repository) {
|
|
136
|
+
return {
|
|
137
|
+
intent: 'read',
|
|
138
|
+
method: 'GET',
|
|
139
|
+
handler: async (request, context) => {
|
|
140
|
+
const id = readScopedProjectId(request, context.composition?.projectId);
|
|
141
|
+
const { revisionId } = request.params;
|
|
142
|
+
if (!id || !revisionId)
|
|
143
|
+
return invalidResponse('Revision lookup requires scoped projectId and revisionId.');
|
|
144
|
+
return missingResponse(await projects.revision(repository, { id, revisionId }));
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
/*** Delegate materialization only when the host explicitly provides its owner port. */
|
|
149
|
+
function createMaterializeOperation(repository, materializer) {
|
|
150
|
+
return {
|
|
151
|
+
intent: 'action',
|
|
152
|
+
method: 'POST',
|
|
153
|
+
handler: async (request, context) => {
|
|
154
|
+
const id = readScopedProjectId(request, context.composition?.projectId);
|
|
155
|
+
const { revisionId } = request.params;
|
|
156
|
+
if (!id || !revisionId)
|
|
157
|
+
return invalidResponse('Materialization requires scoped projectId and revisionId.');
|
|
158
|
+
if (!materializer)
|
|
159
|
+
return unavailableResponse();
|
|
160
|
+
return missingResponse(await projects.materialize(repository, materializer, { id, revisionId }));
|
|
161
|
+
},
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
/*** Delete only the scoped project after the host explicitly enables destructive resolution. */
|
|
165
|
+
function createDeleteOperation(repository) {
|
|
166
|
+
return {
|
|
167
|
+
intent: 'delete',
|
|
168
|
+
method: 'DELETE',
|
|
169
|
+
handler: async (request, context) => {
|
|
170
|
+
const id = readScopedProjectId(request, context.composition?.projectId);
|
|
171
|
+
return id
|
|
172
|
+
? missingResponse(await projects.delete(repository, id))
|
|
173
|
+
: invalidResponse('Invalid project scope.');
|
|
174
|
+
},
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
/*** Read one project using only the resource id equal to the approved project scope. */
|
|
178
|
+
async function readProjectResponse(repository, request, projectId) {
|
|
179
|
+
const id = readScopedProjectId(request, projectId);
|
|
180
|
+
return id
|
|
181
|
+
? missingResponse(await projects.read(repository, id))
|
|
182
|
+
: invalidResponse('Invalid project scope.');
|
|
183
|
+
}
|
|
184
|
+
/*** Return a typed missing-resource response without exposing storage details. */
|
|
185
|
+
function missingResponse(value) {
|
|
186
|
+
return value === null
|
|
187
|
+
? { status: 404, body: { error: { code: 'project_not_found' } } }
|
|
188
|
+
: { body: value };
|
|
189
|
+
}
|
|
190
|
+
/*** Return an invalid-request response before a repository action receives untrusted input. */
|
|
191
|
+
function invalidResponse(message) {
|
|
192
|
+
return { status: 400, body: { error: { code: 'invalid_request', message } } };
|
|
193
|
+
}
|
|
194
|
+
/*** Return an explicit blocked result when no host materializer has been configured. */
|
|
195
|
+
function unavailableResponse() {
|
|
196
|
+
return { status: 503, body: { error: { code: 'materialization_unavailable' } } };
|
|
197
|
+
}
|
|
198
|
+
/*** Translate only expected owner-domain failures while preserving unexpected storage failures. */
|
|
199
|
+
function projectActionFailureResponse(error) {
|
|
200
|
+
if (!(error instanceof Error))
|
|
201
|
+
throw error;
|
|
202
|
+
if (error.message.includes('already exists') ||
|
|
203
|
+
error.message.startsWith('Project manifest revision conflict:')) {
|
|
204
|
+
return { status: 409, body: { error: { code: 'project_conflict' } } };
|
|
205
|
+
}
|
|
206
|
+
if (error.message.startsWith('A project name must')) {
|
|
207
|
+
return invalidResponse(error.message);
|
|
208
|
+
}
|
|
209
|
+
throw error;
|
|
210
|
+
}
|
|
211
|
+
/*** Accept only a resource parameter exactly matching the API composition project scope. */
|
|
212
|
+
function readScopedProjectId(request, projectId) {
|
|
213
|
+
const id = request.params.projectId;
|
|
214
|
+
return id && id === projectId ? id : undefined;
|
|
215
|
+
}
|
|
216
|
+
/*** Read a non-empty project name from one untrusted API request body. */
|
|
217
|
+
function readName(value) {
|
|
218
|
+
return isRecord(value) && typeof value.name === 'string' ? value.name : undefined;
|
|
219
|
+
}
|
|
220
|
+
/*** Validate the one manifest-save body shape accepted by the Projects API handler. */
|
|
221
|
+
function readManifestSaveBody(value) {
|
|
222
|
+
if (!isRecord(value) || !isAppManifest(value.manifest))
|
|
223
|
+
return undefined;
|
|
224
|
+
if (value.expectedRevisionId !== null && typeof value.expectedRevisionId !== 'string')
|
|
225
|
+
return undefined;
|
|
226
|
+
return { manifest: value.manifest, expectedRevisionId: value.expectedRevisionId };
|
|
227
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export { createProjectRepositoryFileSystemAsync } from './features/projects/adapters/createProjectRepositoryFileSystemAsync.js';
|
|
2
2
|
export { projects } from './features/projects/application/projects.js';
|
|
3
|
+
export { createExpoProjectMaterializer, type CreateExpoProjectMaterializerInput, type ExpoProjectMaterializationResult, type ExpoProjectMaterializer, } from './features/projects/composition/createExpoProjectMaterializer.js';
|
|
4
|
+
export { createProjectsApiHandlerResolver } from './features/projects/composition/createProjectsApiHandlerResolver.js';
|
|
3
5
|
export type { ProjectMaterializer, ProjectRepository, } from './features/projects/ports/ProjectRepository.js';
|
|
4
6
|
export type { CreateProjectInput, MaterializeProjectRevisionInput, Project, ProjectManifest, ProjectManifestDraft, ProjectManifestRevision, ReloadProjectManifestInput, SaveProjectManifestInput, UpdateProjectInput, } from './types/projects.js';
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
export { createProjectRepositoryFileSystemAsync } from './features/projects/adapters/createProjectRepositoryFileSystemAsync.js';
|
|
2
2
|
export { projects } from './features/projects/application/projects.js';
|
|
3
|
+
export { createExpoProjectMaterializer, } from './features/projects/composition/createExpoProjectMaterializer.js';
|
|
4
|
+
export { createProjectsApiHandlerResolver } from './features/projects/composition/createProjectsApiHandlerResolver.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ankhorage/projects",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Standalone project identity and repository actions.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ankhorage",
|
|
@@ -61,7 +61,12 @@
|
|
|
61
61
|
"typescript": "~6.0.3"
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@ankhorage/
|
|
64
|
+
"@ankhorage/api": "^0.5.1",
|
|
65
|
+
"@ankhorage/contracts": "^26.11.1",
|
|
66
|
+
"@ankhorage/expo-runtime": "^7.4.3",
|
|
67
|
+
"@ankhorage/navigator": "^3.5.22",
|
|
68
|
+
"@ankhorage/permissions": "^0.2.64",
|
|
69
|
+
"@ankhorage/templates": "^12.6.30",
|
|
65
70
|
"@ankhorage/utility": "^1.10.0"
|
|
66
71
|
},
|
|
67
72
|
"ankh": {
|
|
@@ -157,11 +162,26 @@
|
|
|
157
162
|
"label": "Reload project manifest",
|
|
158
163
|
"description": "Read the persisted project manifest draft and immutable revision history."
|
|
159
164
|
},
|
|
165
|
+
{
|
|
166
|
+
"id": "projects.revision",
|
|
167
|
+
"owner": "@ankhorage/projects",
|
|
168
|
+
"access": [
|
|
169
|
+
"read"
|
|
170
|
+
],
|
|
171
|
+
"binding": {
|
|
172
|
+
"kind": "storage",
|
|
173
|
+
"bindableAs": [
|
|
174
|
+
"target"
|
|
175
|
+
]
|
|
176
|
+
},
|
|
177
|
+
"label": "Read project manifest revision",
|
|
178
|
+
"description": "Read one immutable project manifest revision by identity."
|
|
179
|
+
},
|
|
160
180
|
{
|
|
161
181
|
"id": "projects.materialize",
|
|
162
182
|
"owner": "@ankhorage/projects",
|
|
163
183
|
"access": [
|
|
164
|
-
"
|
|
184
|
+
"invoke"
|
|
165
185
|
],
|
|
166
186
|
"binding": {
|
|
167
187
|
"kind": "action",
|