@ankhorage/projects 0.0.0-stage → 0.2.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ankhorage
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,18 @@
1
- # Temporary Holding Version
1
+ <!-- markdownlint-disable MD013 MD033 -->
2
+ <!-- This file is generated by Paradox. Do not edit manually. -->
2
3
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
4
+ # @ankhorage/projects
5
+
6
+ ![license: MIT](././paradox/badges/license.svg) ![npm: v0.2.0](././paradox/badges/npm.svg) ![runtime: bun](././paradox/badges/runtime.svg) ![typescript: strict](././paradox/badges/typescript.svg) ![eslint: checked](././paradox/badges/eslint.svg) ![prettier: checked](././paradox/badges/prettier.svg) ![build: checked](././paradox/badges/build.svg) ![tests: configured](././paradox/badges/tests.svg) ![paradox: canonical](././paradox/badges/docs.svg)
7
+
8
+ Standalone project identity and repository actions.
9
+
10
+ ## Generated documentation
11
+
12
+ - [Interactive documentation app](././paradox/index.html)
13
+ - [Public API reference](././paradox/exports.md)
14
+ - [Component registry](././paradox/components.md)
15
+ - [Architecture overview](././paradox/diagrams/architecture-overview.mmd)
16
+ - [Module relationships](././paradox/diagrams/module-relationships.mmd)
17
+ - [Export graph](././paradox/diagrams/export-graph.mmd)
18
+ - [createProjectRepositoryFileSystemAsync sequence](././paradox/diagrams/sequences/create-project-repository-file-system-async.mmd)
@@ -0,0 +1,82 @@
1
+ /*** Publish the canonical descriptors for project repository operations. */
2
+ export declare const CAPABILITIES: readonly [{
3
+ readonly id: "projects.list";
4
+ readonly owner: "@ankhorage/projects";
5
+ readonly access: readonly ["read"];
6
+ readonly binding: {
7
+ readonly kind: "storage";
8
+ readonly bindableAs: readonly ["target"];
9
+ };
10
+ readonly label: "List projects";
11
+ readonly description: "List persisted project identities.";
12
+ }, {
13
+ readonly id: "projects.read";
14
+ readonly owner: "@ankhorage/projects";
15
+ readonly access: readonly ["read"];
16
+ readonly binding: {
17
+ readonly kind: "storage";
18
+ readonly bindableAs: readonly ["target"];
19
+ };
20
+ readonly label: "Read project";
21
+ readonly description: "Read one persisted project by identity.";
22
+ }, {
23
+ readonly id: "projects.create";
24
+ readonly owner: "@ankhorage/projects";
25
+ readonly access: readonly ["write"];
26
+ readonly binding: {
27
+ readonly kind: "storage";
28
+ readonly bindableAs: readonly ["target"];
29
+ };
30
+ readonly label: "Create project";
31
+ readonly description: "Create one persisted project with a canonical identity.";
32
+ }, {
33
+ readonly id: "projects.update";
34
+ readonly owner: "@ankhorage/projects";
35
+ readonly access: readonly ["write"];
36
+ readonly binding: {
37
+ readonly kind: "storage";
38
+ readonly bindableAs: readonly ["target"];
39
+ };
40
+ readonly label: "Update project";
41
+ readonly description: "Update one existing persisted project.";
42
+ }, {
43
+ readonly id: "projects.save";
44
+ readonly owner: "@ankhorage/projects";
45
+ readonly access: readonly ["write"];
46
+ readonly binding: {
47
+ readonly kind: "storage";
48
+ readonly bindableAs: readonly ["target"];
49
+ };
50
+ readonly label: "Save project manifest";
51
+ readonly description: "Persist a validated AppManifest draft as an immutable project revision.";
52
+ }, {
53
+ readonly id: "projects.reload";
54
+ readonly owner: "@ankhorage/projects";
55
+ readonly access: readonly ["read"];
56
+ readonly binding: {
57
+ readonly kind: "storage";
58
+ readonly bindableAs: readonly ["target"];
59
+ };
60
+ readonly label: "Reload project manifest";
61
+ readonly description: "Read the persisted project manifest draft and immutable revision history.";
62
+ }, {
63
+ readonly id: "projects.materialize";
64
+ readonly owner: "@ankhorage/projects";
65
+ readonly access: readonly ["write"];
66
+ readonly binding: {
67
+ readonly kind: "action";
68
+ readonly bindableAs: readonly ["target"];
69
+ };
70
+ readonly label: "Materialize project revision";
71
+ readonly description: "Materialize one stored immutable project revision through an injected owner generator.";
72
+ }, {
73
+ readonly id: "projects.delete";
74
+ readonly owner: "@ankhorage/projects";
75
+ readonly access: readonly ["write"];
76
+ readonly binding: {
77
+ readonly kind: "storage";
78
+ readonly bindableAs: readonly ["target"];
79
+ };
80
+ readonly label: "Delete project";
81
+ readonly description: "Delete one persisted project by identity.";
82
+ }];
@@ -0,0 +1,67 @@
1
+ /*** Publish the canonical descriptors for project repository operations. */
2
+ export const CAPABILITIES = [
3
+ {
4
+ id: 'projects.list',
5
+ owner: '@ankhorage/projects',
6
+ access: ['read'],
7
+ binding: { kind: 'storage', bindableAs: ['target'] },
8
+ label: 'List projects',
9
+ description: 'List persisted project identities.',
10
+ },
11
+ {
12
+ id: 'projects.read',
13
+ owner: '@ankhorage/projects',
14
+ access: ['read'],
15
+ binding: { kind: 'storage', bindableAs: ['target'] },
16
+ label: 'Read project',
17
+ description: 'Read one persisted project by identity.',
18
+ },
19
+ {
20
+ id: 'projects.create',
21
+ owner: '@ankhorage/projects',
22
+ access: ['write'],
23
+ binding: { kind: 'storage', bindableAs: ['target'] },
24
+ label: 'Create project',
25
+ description: 'Create one persisted project with a canonical identity.',
26
+ },
27
+ {
28
+ id: 'projects.update',
29
+ owner: '@ankhorage/projects',
30
+ access: ['write'],
31
+ binding: { kind: 'storage', bindableAs: ['target'] },
32
+ label: 'Update project',
33
+ description: 'Update one existing persisted project.',
34
+ },
35
+ {
36
+ id: 'projects.save',
37
+ owner: '@ankhorage/projects',
38
+ access: ['write'],
39
+ binding: { kind: 'storage', bindableAs: ['target'] },
40
+ label: 'Save project manifest',
41
+ description: 'Persist a validated AppManifest draft as an immutable project revision.',
42
+ },
43
+ {
44
+ id: 'projects.reload',
45
+ owner: '@ankhorage/projects',
46
+ access: ['read'],
47
+ binding: { kind: 'storage', bindableAs: ['target'] },
48
+ label: 'Reload project manifest',
49
+ description: 'Read the persisted project manifest draft and immutable revision history.',
50
+ },
51
+ {
52
+ id: 'projects.materialize',
53
+ owner: '@ankhorage/projects',
54
+ access: ['write'],
55
+ binding: { kind: 'action', bindableAs: ['target'] },
56
+ label: 'Materialize project revision',
57
+ description: 'Materialize one stored immutable project revision through an injected owner generator.',
58
+ },
59
+ {
60
+ id: 'projects.delete',
61
+ owner: '@ankhorage/projects',
62
+ access: ['write'],
63
+ binding: { kind: 'storage', bindableAs: ['target'] },
64
+ label: 'Delete project',
65
+ description: 'Delete one persisted project by identity.',
66
+ },
67
+ ];
@@ -0,0 +1,13 @@
1
+ import type { ProjectRepository } from '../ports/ProjectRepository.js';
2
+ type FileSystemProjectRepositoryOptions = Readonly<{
3
+ directory: string;
4
+ }>;
5
+ /***
6
+ * Create a path-isolated filesystem implementation of the project repository port.
7
+ *
8
+ * The keyed mutex coordinates mutations only through this adapter instance in one Node.js process.
9
+ * Assign each storage directory to one writer; coordinating separate adapter instances or processes
10
+ * requires external locking and is unsupported by this adapter.
11
+ */
12
+ export declare function createProjectRepositoryFileSystemAsync(options: FileSystemProjectRepositoryOptions): Promise<ProjectRepository>;
13
+ export {};
@@ -0,0 +1,225 @@
1
+ import { constants, link, mkdir, open, readdir, rename, rm } from 'node:fs/promises';
2
+ import { join } from 'node:path';
3
+ import { isAppManifest } from '@ankhorage/contracts';
4
+ import { createKeyedAsyncMutex } from '@ankhorage/utility/concurrency';
5
+ import { isRecord } from '@ankhorage/utility/object';
6
+ /***
7
+ * Create a path-isolated filesystem implementation of the project repository port.
8
+ *
9
+ * The keyed mutex coordinates mutations only through this adapter instance in one Node.js process.
10
+ * Assign each storage directory to one writer; coordinating separate adapter instances or processes
11
+ * requires external locking and is unsupported by this adapter.
12
+ */
13
+ export async function createProjectRepositoryFileSystemAsync(options) {
14
+ const directory = join(options.directory, 'projects');
15
+ await mkdir(directory, { recursive: true, mode: 0o700 });
16
+ await assertStorageDirectoryAsync(directory);
17
+ const mutations = createKeyedAsyncMutex({
18
+ createBusyError: (id) => new Error(`Project identity '${id}' is busy.`),
19
+ });
20
+ return {
21
+ listAsync: async () => {
22
+ const entries = await readdir(directory, { withFileTypes: true });
23
+ const projects = await Promise.all(entries
24
+ .filter((entry) => entry.isFile() && entry.name.endsWith('.json'))
25
+ .map(async (entry) => readProjectWithMigrationAsync(directory, mutations, entry.name)));
26
+ return projects
27
+ .filter((project) => project !== null)
28
+ .sort((left, right) => left.id.localeCompare(right.id));
29
+ },
30
+ readAsync: async (id) => readProjectWithMigrationAsync(directory, mutations, projectFileName(id)),
31
+ createAsync: async (project) => mutations.run(project.id, async () => writeProjectAsync(directory, project, true)),
32
+ updateAsync: async (id, update) => mutations.run(id, async () => {
33
+ const result = await readProjectAsync(directory, projectFileName(id));
34
+ if (result === null)
35
+ return null;
36
+ const updated = update(result.project);
37
+ if (updated.id !== id)
38
+ throw new Error('Project update cannot change identity.');
39
+ await writeProjectAsync(directory, updated, false);
40
+ return updated;
41
+ }),
42
+ deleteAsync: async (id) => mutations.run(id, async () => deleteProjectAsync(directory, id)),
43
+ };
44
+ }
45
+ /*** Confirm that the storage directory itself cannot be a symlink. */
46
+ async function assertStorageDirectoryAsync(directory) {
47
+ const handle = await open(directory, constants.O_RDONLY | constants.O_DIRECTORY | constants.O_NOFOLLOW);
48
+ try {
49
+ if (!(await handle.stat()).isDirectory()) {
50
+ throw new Error('Project storage must be a directory.');
51
+ }
52
+ }
53
+ finally {
54
+ await handle.close();
55
+ }
56
+ }
57
+ /*** Read a regular, schema-valid project file through a no-follow file handle. */
58
+ async function readProjectAsync(directory, fileName, expectedFileName = fileName) {
59
+ const path = join(directory, fileName);
60
+ let handle;
61
+ try {
62
+ handle = await open(path, constants.O_RDONLY | constants.O_NOFOLLOW);
63
+ if (!(await handle.stat()).isFile())
64
+ throw new Error(`Project storage entry '${fileName}' must be a regular file.`);
65
+ const stored = JSON.parse(await handle.readFile({ encoding: 'utf8' }));
66
+ if (!isStoredProject(stored) || projectFileName(stored.project.id) !== expectedFileName) {
67
+ throw new Error(`Project storage entry '${fileName}' is invalid.`);
68
+ }
69
+ if (isStoredProjectW1(stored)) {
70
+ return {
71
+ project: { ...stored.project, manifest: { draft: null, revisions: [] } },
72
+ requiresMigration: true,
73
+ };
74
+ }
75
+ return { project: stored.project, requiresMigration: false };
76
+ }
77
+ catch (error) {
78
+ if (isMissingFileError(error))
79
+ return null;
80
+ if (isSymlinkError(error)) {
81
+ throw new Error(`Project storage entry '${fileName}' must be a regular file.`, {
82
+ cause: error,
83
+ });
84
+ }
85
+ throw error;
86
+ }
87
+ finally {
88
+ await handle?.close();
89
+ }
90
+ }
91
+ /*** Read a project and atomically persist the one supported W1-to-W2 document migration. */
92
+ async function readProjectWithMigrationAsync(directory, mutations, fileName) {
93
+ const result = await readProjectAsync(directory, fileName);
94
+ if (result === null)
95
+ return null;
96
+ if (!result.requiresMigration)
97
+ return result.project;
98
+ return mutations.run(result.project.id, async () => {
99
+ const current = await readProjectAsync(directory, fileName);
100
+ if (current === null)
101
+ return null;
102
+ if (current.requiresMigration)
103
+ await writeProjectAsync(directory, current.project, false);
104
+ return current.project;
105
+ });
106
+ }
107
+ /*** Atomically create or replace a project file without exposing a partial document. */
108
+ async function writeProjectAsync(directory, project, createOnly) {
109
+ const fileName = projectFileName(project.id);
110
+ const target = join(directory, fileName);
111
+ const temporary = join(directory, `.${fileName}.${crypto.randomUUID()}.tmp`);
112
+ await writeTemporaryProjectAsync(temporary, project);
113
+ try {
114
+ if (createOnly)
115
+ await link(temporary, target);
116
+ else
117
+ await rename(temporary, target);
118
+ }
119
+ finally {
120
+ await rm(temporary, { force: true });
121
+ }
122
+ }
123
+ /*** Write a private temporary project file without following or replacing an existing entry. */
124
+ async function writeTemporaryProjectAsync(temporary, project) {
125
+ const handle = await open(temporary, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | constants.O_NOFOLLOW, 0o600);
126
+ try {
127
+ await handle.writeFile(JSON.stringify({ version: 1, project }), 'utf8');
128
+ }
129
+ finally {
130
+ await handle.close();
131
+ }
132
+ }
133
+ /*** Atomically detach a project, restoring it when validation or deletion cannot complete. */
134
+ async function deleteProjectAsync(directory, id) {
135
+ const fileName = projectFileName(id);
136
+ const target = join(directory, fileName);
137
+ const temporary = join(directory, `.${fileName}.${crypto.randomUUID()}.delete`);
138
+ try {
139
+ await rename(target, temporary);
140
+ }
141
+ catch (error) {
142
+ if (isMissingFileError(error))
143
+ return null;
144
+ throw error;
145
+ }
146
+ try {
147
+ const result = await readProjectAsync(directory, temporary.slice(directory.length + 1), fileName);
148
+ if (result === null)
149
+ throw new Error(`Project storage entry '${fileName}' disappeared.`);
150
+ await rm(temporary);
151
+ return result.project;
152
+ }
153
+ catch (error) {
154
+ await rename(temporary, target);
155
+ throw error;
156
+ }
157
+ }
158
+ /*** Convert only canonical project identities into a local storage filename. */
159
+ function projectFileName(id) {
160
+ if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(id)) {
161
+ throw new Error('Project identity is invalid.');
162
+ }
163
+ return `${id}.json`;
164
+ }
165
+ /*** Verify a parsed current or published-W1 storage document before it enters the application. */
166
+ function isStoredProject(value) {
167
+ return isStoredProjectW1(value) || isStoredProjectW2(value);
168
+ }
169
+ /*** Recognize only the published W1 document shape that has no persisted manifest field. */
170
+ function isStoredProjectW1(value) {
171
+ if (!isRecord(value))
172
+ return false;
173
+ const { project } = value;
174
+ return (value.version === 1 &&
175
+ isRecord(project) &&
176
+ typeof project.id === 'string' &&
177
+ typeof project.name === 'string' &&
178
+ typeof project.createdAt === 'string' &&
179
+ typeof project.updatedAt === 'string' &&
180
+ !('manifest' in project));
181
+ }
182
+ /*** Validate the current persisted project document at the filesystem boundary. */
183
+ function isStoredProjectW2(value) {
184
+ if (!isRecord(value))
185
+ return false;
186
+ const { project } = value;
187
+ return (value.version === 1 &&
188
+ isRecord(project) &&
189
+ typeof project.id === 'string' &&
190
+ typeof project.name === 'string' &&
191
+ typeof project.createdAt === 'string' &&
192
+ typeof project.updatedAt === 'string' &&
193
+ isProjectManifest(project.manifest));
194
+ }
195
+ /*** Validate persisted manifest draft and revision invariants at the filesystem boundary. */
196
+ function isProjectManifest(value) {
197
+ if (!isRecord(value) || !Array.isArray(value.revisions))
198
+ return false;
199
+ const { revisions, draft } = value;
200
+ const ids = new Set();
201
+ const areRevisionsValid = revisions.every((revision) => isRecord(revision) &&
202
+ typeof revision.id === 'string' &&
203
+ typeof revision.savedAt === 'string' &&
204
+ isAppManifest(revision.manifest) &&
205
+ !ids.has(revision.id) &&
206
+ (ids.add(revision.id), true));
207
+ if (!areRevisionsValid || (draft !== null && !isRecord(draft)))
208
+ return false;
209
+ return (draft === null ||
210
+ (typeof draft.revisionId === 'string' &&
211
+ typeof draft.savedAt === 'string' &&
212
+ isAppManifest(draft.manifest) &&
213
+ revisions.some((revision) => isRecord(revision) &&
214
+ revision.id === draft.revisionId &&
215
+ revision.savedAt === draft.savedAt &&
216
+ JSON.stringify(revision.manifest) === JSON.stringify(draft.manifest))));
217
+ }
218
+ /*** Identify the missing-file condition that represents an absent project. */
219
+ function isMissingFileError(error) {
220
+ return typeof error === 'object' && error !== null && 'code' in error && error.code === 'ENOENT';
221
+ }
222
+ /*** Identify no-follow failures caused by a symbolic link at the opened path. */
223
+ function isSymlinkError(error) {
224
+ return typeof error === 'object' && error !== null && 'code' in error && error.code === 'ELOOP';
225
+ }
@@ -0,0 +1,13 @@
1
+ import type { CreateProjectInput, MaterializeProjectRevisionInput, Project, ProjectManifest, ProjectManifestRevision, ReloadProjectManifestInput, SaveProjectManifestInput, UpdateProjectInput } from '../../../types/projects.js';
2
+ import type { ProjectMaterializer, ProjectRepository } from '../ports/ProjectRepository.js';
3
+ /*** Expose the project repository actions through an explicit port. */
4
+ export declare const projects: {
5
+ list: (repository: ProjectRepository) => Promise<readonly Project[]>;
6
+ read: (repository: ProjectRepository, id: string) => Promise<Project | null>;
7
+ create: (repository: ProjectRepository, input: CreateProjectInput, now?: Date) => Promise<Project>;
8
+ update: (repository: ProjectRepository, input: UpdateProjectInput, now?: Date) => Promise<Project | null>;
9
+ save: (repository: ProjectRepository, input: SaveProjectManifestInput, now?: Date) => Promise<Project | null>;
10
+ reload: (repository: ProjectRepository, input: ReloadProjectManifestInput) => Promise<ProjectManifest | null>;
11
+ materialize: (repository: ProjectRepository, materializer: ProjectMaterializer, input: MaterializeProjectRevisionInput) => Promise<ProjectManifestRevision | null>;
12
+ delete: (repository: ProjectRepository, id: string) => Promise<Project | null>;
13
+ };
@@ -0,0 +1,29 @@
1
+ import { createProject } from '../domain/createProject.js';
2
+ import { saveProjectManifest } from '../domain/saveProjectManifest.js';
3
+ import { updateProject } from '../domain/updateProject.js';
4
+ /*** Expose the project repository actions through an explicit port. */
5
+ export const projects = {
6
+ list: async (repository) => repository.listAsync(),
7
+ read: async (repository, id) => repository.readAsync(id),
8
+ create: async (repository, input, now = new Date()) => {
9
+ const project = createProject(input, now);
10
+ const existing = await repository.listAsync();
11
+ if (existing.some((candidate) => candidate.id === project.id)) {
12
+ throw new Error(`Project identity '${project.id}' already exists.`);
13
+ }
14
+ await repository.createAsync(project);
15
+ return project;
16
+ },
17
+ update: async (repository, input, now = new Date()) => repository.updateAsync(input.id, (project) => updateProject(project, input, now)),
18
+ save: async (repository, input, now = new Date()) => repository.updateAsync(input.id, (project) => saveProjectManifest(project, input, now)),
19
+ reload: async (repository, input) => (await repository.readAsync(input.id))?.manifest ?? null,
20
+ materialize: async (repository, materializer, input) => {
21
+ const project = await repository.readAsync(input.id);
22
+ const revision = project?.manifest.revisions.find((candidate) => candidate.id === input.revisionId);
23
+ if (project === null || revision === undefined)
24
+ return null;
25
+ await materializer.materializeAsync({ project, revision });
26
+ return revision;
27
+ },
28
+ delete: async (repository, id) => repository.deleteAsync(id),
29
+ };
@@ -0,0 +1,3 @@
1
+ import type { CreateProjectInput, Project } from '../../../types/projects.js';
2
+ /*** Create a valid project with an immutable identity. */
3
+ export declare function createProject(input: CreateProjectInput, now: Date): Project;
@@ -0,0 +1,21 @@
1
+ import { deriveProjectIdentity } from './deriveProjectIdentity.js';
2
+ /*** Create a valid project with an immutable identity. */
3
+ export function createProject(input, now) {
4
+ const name = normalizeProjectName(input.name);
5
+ const timestamp = now.toISOString();
6
+ return {
7
+ id: deriveProjectIdentity(name),
8
+ name,
9
+ createdAt: timestamp,
10
+ updatedAt: timestamp,
11
+ manifest: { draft: null, revisions: [] },
12
+ };
13
+ }
14
+ /*** Normalize a project name at the domain boundary. */
15
+ function normalizeProjectName(name) {
16
+ const normalized = name.trim();
17
+ if (normalized.length === 0 || normalized.length > 120) {
18
+ throw new Error('A project name must contain between 1 and 120 characters.');
19
+ }
20
+ return normalized;
21
+ }
@@ -0,0 +1,2 @@
1
+ /*** Derive the canonical path-safe project identity from a project name. */
2
+ export declare function deriveProjectIdentity(name: string): string;
@@ -0,0 +1,9 @@
1
+ import { slugifyAscii } from '@ankhorage/utility/string';
2
+ /*** Derive the canonical path-safe project identity from a project name. */
3
+ export function deriveProjectIdentity(name) {
4
+ const id = slugifyAscii(name);
5
+ if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(id)) {
6
+ throw new Error('A project name must derive a lowercase hyphenated identity.');
7
+ }
8
+ return id;
9
+ }
@@ -0,0 +1,3 @@
1
+ import type { Project, SaveProjectManifestInput } from '../../../types/projects.js';
2
+ /*** Save a validated AppManifest as the next immutable revision after checking the draft version. */
3
+ export declare function saveProjectManifest(project: Project, input: SaveProjectManifestInput, now: Date): Project;
@@ -0,0 +1,23 @@
1
+ import { parseAppManifest } from '@ankhorage/contracts';
2
+ /*** Save a validated AppManifest as the next immutable revision after checking the draft version. */
3
+ export function saveProjectManifest(project, input, now) {
4
+ const parsed = parseAppManifest(input.manifest);
5
+ if (!parsed.ok)
6
+ throw new Error(parsed.message);
7
+ const currentRevisionId = project.manifest.draft?.revisionId ?? null;
8
+ if (input.expectedRevisionId !== currentRevisionId) {
9
+ throw new Error(`Project manifest revision conflict: expected '${input.expectedRevisionId}', found '${currentRevisionId}'.`);
10
+ }
11
+ const savedAt = now.toISOString();
12
+ const id = `revision-${project.manifest.revisions.length + 1}`;
13
+ const manifest = structuredClone(parsed.manifest);
14
+ const revision = { id, manifest, savedAt };
15
+ return {
16
+ ...project,
17
+ updatedAt: savedAt,
18
+ manifest: {
19
+ draft: { revisionId: id, manifest, savedAt },
20
+ revisions: [...project.manifest.revisions, revision],
21
+ },
22
+ };
23
+ }
@@ -0,0 +1,3 @@
1
+ import type { Project, UpdateProjectInput } from '../../../types/projects.js';
2
+ /*** Apply a valid mutable project change while preserving identity. */
3
+ export declare function updateProject(project: Project, input: UpdateProjectInput, now: Date): Project;
@@ -0,0 +1,13 @@
1
+ /*** Apply a valid mutable project change while preserving identity. */
2
+ export function updateProject(project, input, now) {
3
+ const name = normalizeProjectName(input.name);
4
+ return { ...project, name, updatedAt: now.toISOString() };
5
+ }
6
+ /*** Normalize a project name at the domain boundary. */
7
+ function normalizeProjectName(name) {
8
+ const normalized = name.trim();
9
+ if (normalized.length === 0 || normalized.length > 120) {
10
+ throw new Error('A project name must contain between 1 and 120 characters.');
11
+ }
12
+ return normalized;
13
+ }
@@ -0,0 +1,14 @@
1
+ import type { Project, ProjectManifestRevision } from '../../../types/projects.js';
2
+ export interface ProjectMaterializer {
3
+ materializeAsync(input: Readonly<{
4
+ project: Project;
5
+ revision: ProjectManifestRevision;
6
+ }>): Promise<void>;
7
+ }
8
+ export interface ProjectRepository {
9
+ listAsync(): Promise<readonly Project[]>;
10
+ readAsync(id: string): Promise<Project | null>;
11
+ createAsync(project: Project): Promise<void>;
12
+ updateAsync(id: string, update: (project: Project) => Project): Promise<Project | null>;
13
+ deleteAsync(id: string): Promise<Project | null>;
14
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ export { createProjectRepositoryFileSystemAsync } from './features/projects/adapters/createProjectRepositoryFileSystemAsync.js';
2
+ export { projects } from './features/projects/application/projects.js';
3
+ export type { ProjectMaterializer, ProjectRepository, } from './features/projects/ports/ProjectRepository.js';
4
+ export type { CreateProjectInput, MaterializeProjectRevisionInput, Project, ProjectManifest, ProjectManifestDraft, ProjectManifestRevision, ReloadProjectManifestInput, SaveProjectManifestInput, UpdateProjectInput, } from './types/projects.js';
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { createProjectRepositoryFileSystemAsync } from './features/projects/adapters/createProjectRepositoryFileSystemAsync.js';
2
+ export { projects } from './features/projects/application/projects.js';
@@ -0,0 +1,44 @@
1
+ import type { AppManifest } from '@ankhorage/contracts';
2
+ export type Project = Readonly<{
3
+ id: string;
4
+ name: string;
5
+ createdAt: string;
6
+ updatedAt: string;
7
+ manifest: ProjectManifest;
8
+ }>;
9
+ export type CreateProjectInput = Readonly<{
10
+ name: string;
11
+ }>;
12
+ export type UpdateProjectInput = Readonly<{
13
+ id: string;
14
+ name: string;
15
+ }>;
16
+ /*** Persisted draft pointer and immutable AppManifest revision history for one project. */
17
+ export type ProjectManifest = Readonly<{
18
+ draft: ProjectManifestDraft | null;
19
+ revisions: readonly ProjectManifestRevision[];
20
+ }>;
21
+ /*** A persisted draft always points at the immutable revision produced by its last save. */
22
+ export type ProjectManifestDraft = Readonly<{
23
+ revisionId: string;
24
+ manifest: AppManifest;
25
+ savedAt: string;
26
+ }>;
27
+ /*** An immutable, project-local AppManifest snapshot. */
28
+ export type ProjectManifestRevision = Readonly<{
29
+ id: string;
30
+ manifest: AppManifest;
31
+ savedAt: string;
32
+ }>;
33
+ export type SaveProjectManifestInput = Readonly<{
34
+ id: string;
35
+ manifest: AppManifest;
36
+ expectedRevisionId: string | null;
37
+ }>;
38
+ export type ReloadProjectManifestInput = Readonly<{
39
+ id: string;
40
+ }>;
41
+ export type MaterializeProjectRevisionInput = Readonly<{
42
+ id: string;
43
+ revisionId: string;
44
+ }>;
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,192 @@
1
1
  {
2
2
  "name": "@ankhorage/projects",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "description": "Standalone project identity and repository actions.",
5
+ "keywords": [
6
+ "ankhorage",
7
+ "projects",
8
+ "persistence"
9
+ ],
10
+ "license": "MIT",
11
+ "homepage": "https://github.com/ankhorage/projects#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/ankhorage/projects/issues"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/ankhorage/projects.git"
18
+ },
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "type": "module",
23
+ "sideEffects": false,
24
+ "files": [
25
+ "dist",
26
+ "LICENSE"
27
+ ],
28
+ "main": "./dist/index.js",
29
+ "types": "./dist/index.d.ts",
30
+ "exports": {
31
+ ".": {
32
+ "types": "./dist/index.d.ts",
33
+ "import": "./dist/index.js"
34
+ },
35
+ "./capabilities": {
36
+ "types": "./dist/capabilities/index.d.ts",
37
+ "import": "./dist/capabilities/index.js"
38
+ }
39
+ },
40
+ "packageManager": "bun@1.4.2",
41
+ "scripts": {
42
+ "build": "rm -rf dist tsconfig.tsbuildinfo tsconfig.build.tsbuildinfo && bun x tsc -p tsconfig.build.json",
43
+ "check-types": "bun x tsc --noEmit -p tsconfig.json",
44
+ "typecheck": "bun run check-types",
45
+ "test": "bun test",
46
+ "lint": "ankhorage-eslint . --max-warnings=0",
47
+ "knip:check": "ankhorage-knip",
48
+ "format": "ankhorage-prettier --write .",
49
+ "format:check": "ankhorage-prettier --check .",
50
+ "changeset": "ankhorage-changeset",
51
+ "changeset:status": "ankhorage-changeset status --since=origin/main",
52
+ "docs": "paradox",
53
+ "lint:fix": "ankhorage-eslint . --fix --max-warnings=0",
54
+ "version-packages": "ankhorage-changeset version"
55
+ },
56
+ "devDependencies": {
57
+ "@ankhorage/devtools": "^2.5.0",
58
+ "@ankhorage/paradox": "^0.3.6",
59
+ "@types/bun": "^1.4.2",
60
+ "@types/node": "^26.6.6",
61
+ "typescript": "~6.0.3"
62
+ },
63
+ "dependencies": {
64
+ "@ankhorage/contracts": "^26.10.0",
65
+ "@ankhorage/utility": "^1.10.0"
66
+ },
67
+ "ankh": {
68
+ "category": "projects",
69
+ "capabilities": [
70
+ {
71
+ "id": "projects.list",
72
+ "owner": "@ankhorage/projects",
73
+ "access": [
74
+ "read"
75
+ ],
76
+ "binding": {
77
+ "kind": "storage",
78
+ "bindableAs": [
79
+ "target"
80
+ ]
81
+ },
82
+ "label": "List projects",
83
+ "description": "List persisted project identities."
84
+ },
85
+ {
86
+ "id": "projects.read",
87
+ "owner": "@ankhorage/projects",
88
+ "access": [
89
+ "read"
90
+ ],
91
+ "binding": {
92
+ "kind": "storage",
93
+ "bindableAs": [
94
+ "target"
95
+ ]
96
+ },
97
+ "label": "Read project",
98
+ "description": "Read one persisted project by identity."
99
+ },
100
+ {
101
+ "id": "projects.create",
102
+ "owner": "@ankhorage/projects",
103
+ "access": [
104
+ "write"
105
+ ],
106
+ "binding": {
107
+ "kind": "storage",
108
+ "bindableAs": [
109
+ "target"
110
+ ]
111
+ },
112
+ "label": "Create project",
113
+ "description": "Create one persisted project with a canonical identity."
114
+ },
115
+ {
116
+ "id": "projects.update",
117
+ "owner": "@ankhorage/projects",
118
+ "access": [
119
+ "write"
120
+ ],
121
+ "binding": {
122
+ "kind": "storage",
123
+ "bindableAs": [
124
+ "target"
125
+ ]
126
+ },
127
+ "label": "Update project",
128
+ "description": "Update one existing persisted project."
129
+ },
130
+ {
131
+ "id": "projects.save",
132
+ "owner": "@ankhorage/projects",
133
+ "access": [
134
+ "write"
135
+ ],
136
+ "binding": {
137
+ "kind": "storage",
138
+ "bindableAs": [
139
+ "target"
140
+ ]
141
+ },
142
+ "label": "Save project manifest",
143
+ "description": "Persist a validated AppManifest draft as an immutable project revision."
144
+ },
145
+ {
146
+ "id": "projects.reload",
147
+ "owner": "@ankhorage/projects",
148
+ "access": [
149
+ "read"
150
+ ],
151
+ "binding": {
152
+ "kind": "storage",
153
+ "bindableAs": [
154
+ "target"
155
+ ]
156
+ },
157
+ "label": "Reload project manifest",
158
+ "description": "Read the persisted project manifest draft and immutable revision history."
159
+ },
160
+ {
161
+ "id": "projects.materialize",
162
+ "owner": "@ankhorage/projects",
163
+ "access": [
164
+ "write"
165
+ ],
166
+ "binding": {
167
+ "kind": "action",
168
+ "bindableAs": [
169
+ "target"
170
+ ]
171
+ },
172
+ "label": "Materialize project revision",
173
+ "description": "Materialize one stored immutable project revision through an injected owner generator."
174
+ },
175
+ {
176
+ "id": "projects.delete",
177
+ "owner": "@ankhorage/projects",
178
+ "access": [
179
+ "write"
180
+ ],
181
+ "binding": {
182
+ "kind": "storage",
183
+ "bindableAs": [
184
+ "target"
185
+ ]
186
+ },
187
+ "label": "Delete project",
188
+ "description": "Delete one persisted project by identity."
189
+ }
190
+ ]
191
+ }
192
+ }