@micacms/runtime 0.4.0 → 0.5.0-rc.1

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.
Files changed (102) hide show
  1. package/README.md +2 -2
  2. package/dist/app.d.ts +8 -37
  3. package/dist/app.d.ts.map +1 -1
  4. package/dist/app.js +7 -42
  5. package/dist/app.js.map +1 -1
  6. package/dist/config.d.ts +12 -82
  7. package/dist/config.d.ts.map +1 -1
  8. package/dist/config.js +14 -82
  9. package/dist/config.js.map +1 -1
  10. package/dist/context.d.ts +37 -66
  11. package/dist/context.d.ts.map +1 -1
  12. package/dist/context.js +24 -75
  13. package/dist/context.js.map +1 -1
  14. package/dist/http.d.ts +8 -16
  15. package/dist/http.d.ts.map +1 -1
  16. package/dist/http.js +6 -13
  17. package/dist/http.js.map +1 -1
  18. package/dist/index.d.ts +13 -14
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +12 -14
  21. package/dist/index.js.map +1 -1
  22. package/dist/routes/admin-content.d.ts +4 -17
  23. package/dist/routes/admin-content.d.ts.map +1 -1
  24. package/dist/routes/admin-content.js +11 -51
  25. package/dist/routes/admin-content.js.map +1 -1
  26. package/dist/routes/admin-media.d.ts +3 -14
  27. package/dist/routes/admin-media.d.ts.map +1 -1
  28. package/dist/routes/admin-media.js +7 -29
  29. package/dist/routes/admin-media.js.map +1 -1
  30. package/dist/routes/admin-staging.d.ts +4 -9
  31. package/dist/routes/admin-staging.d.ts.map +1 -1
  32. package/dist/routes/admin-staging.js +31 -18
  33. package/dist/routes/admin-staging.js.map +1 -1
  34. package/dist/routes/admin-system.d.ts +2 -8
  35. package/dist/routes/admin-system.d.ts.map +1 -1
  36. package/dist/routes/admin-system.js +9 -44
  37. package/dist/routes/admin-system.js.map +1 -1
  38. package/dist/routes/health.d.ts +3 -10
  39. package/dist/routes/health.d.ts.map +1 -1
  40. package/dist/routes/health.js +9 -26
  41. package/dist/routes/health.js.map +1 -1
  42. package/dist/schema.d.ts +10 -38
  43. package/dist/schema.d.ts.map +1 -1
  44. package/dist/schema.js +14 -65
  45. package/dist/schema.js.map +1 -1
  46. package/dist/server.d.ts +2 -10
  47. package/dist/server.d.ts.map +1 -1
  48. package/dist/server.js +3 -9
  49. package/dist/server.js.map +1 -1
  50. package/dist/services/changes.d.ts +150 -0
  51. package/dist/services/changes.d.ts.map +1 -0
  52. package/dist/services/changes.js +339 -0
  53. package/dist/services/changes.js.map +1 -0
  54. package/dist/services/content-store.d.ts +61 -0
  55. package/dist/services/content-store.d.ts.map +1 -0
  56. package/dist/services/content-store.js +330 -0
  57. package/dist/services/content-store.js.map +1 -0
  58. package/dist/services/media.d.ts +9 -29
  59. package/dist/services/media.d.ts.map +1 -1
  60. package/dist/services/media.js +17 -57
  61. package/dist/services/media.js.map +1 -1
  62. package/dist/services/staging.d.ts +35 -167
  63. package/dist/services/staging.d.ts.map +1 -1
  64. package/dist/services/staging.js +195 -458
  65. package/dist/services/staging.js.map +1 -1
  66. package/dist/workspace/developer.d.ts +14 -0
  67. package/dist/workspace/developer.d.ts.map +1 -0
  68. package/dist/workspace/developer.js +31 -0
  69. package/dist/workspace/developer.js.map +1 -0
  70. package/dist/workspace/files.d.ts +70 -0
  71. package/dist/workspace/files.d.ts.map +1 -0
  72. package/dist/workspace/files.js +176 -0
  73. package/dist/workspace/files.js.map +1 -0
  74. package/dist/workspace/git.d.ts +45 -0
  75. package/dist/workspace/git.d.ts.map +1 -0
  76. package/dist/workspace/git.js +68 -0
  77. package/dist/workspace/git.js.map +1 -0
  78. package/dist/workspace/locks.d.ts +33 -0
  79. package/dist/workspace/locks.d.ts.map +1 -0
  80. package/dist/workspace/locks.js +76 -0
  81. package/dist/workspace/locks.js.map +1 -0
  82. package/dist/workspace/policy.d.ts +92 -0
  83. package/dist/workspace/policy.d.ts.map +1 -0
  84. package/dist/workspace/policy.js +7 -0
  85. package/dist/workspace/policy.js.map +1 -0
  86. package/dist/workspace/tree.d.ts +73 -0
  87. package/dist/workspace/tree.d.ts.map +1 -0
  88. package/dist/workspace/tree.js +229 -0
  89. package/dist/workspace/tree.js.map +1 -0
  90. package/package.json +2 -3
  91. package/dist/db/driver.d.ts +0 -35
  92. package/dist/db/driver.d.ts.map +0 -1
  93. package/dist/db/driver.js +0 -95
  94. package/dist/db/driver.js.map +0 -1
  95. package/dist/lib/git.d.ts +0 -29
  96. package/dist/lib/git.d.ts.map +0 -1
  97. package/dist/lib/git.js +0 -62
  98. package/dist/lib/git.js.map +0 -1
  99. package/dist/services/staging-local.d.ts +0 -58
  100. package/dist/services/staging-local.d.ts.map +0 -1
  101. package/dist/services/staging-local.js +0 -391
  102. package/dist/services/staging-local.js.map +0 -1
@@ -1,174 +1,42 @@
1
1
  /**
2
- * Content staging: the orchestration between "saved" and "published".
3
- *
4
- * Two implementations of one service, because the two deployment shapes have
5
- * genuinely different draft workspaces:
6
- *
7
- * - working tree (`staging-local.ts`): the checkout is the draft. Autosave
8
- * writes files the Astro dev server can hot-reload, which is the whole
9
- * value of local mode; Recent changes is `git status`, and Publish is a
10
- * real commit and push through the developer's own Git.
11
- * - draft store (this file): the repository is remote and writing through
12
- * its API would already be a commit, so saves accumulate in SQLite and
13
- * Publish turns the whole set into one provider-side commit.
14
- *
15
- * The editor sees one API either way. What differs is only what Saved means —
16
- * and the two must stay visibly different words in the UI, because in neither
17
- * mode does Saved imply that a change is in Git.
2
+ * The staging service on a Git working tree. Autosave has already written the
3
+ * files; Publish commits the reviewed paths.
4
+ *
5
+ * - Every Git operation is limited to an explicit path set, so other work in
6
+ * the same checkout is never swept in.
7
+ * - Only the reviewed files are published, as the editor saw them. Drafts of
8
+ * other entries stay drafts.
9
+ * - When the push fails, the commit stays as `committed-pending-push`; a
10
+ * retry pushes and never commits again.
18
11
  */
19
- import type { Author, RepositoryConnector } from "@micacms/connectors";
20
- import { type ContentChange, type ContentSource, type DraftStore, type FieldIssue, type PublishResult, type Site } from "@micacms/core";
21
- /** Where the change happened, in words an editor recognises. */
22
- export type ChangeOwner = {
23
- kind: "entry";
24
- collection: string;
25
- slug: string;
26
- label: string;
27
- /** The slug before a pending rename. Set on the files of both slugs. */
28
- renamedFrom?: string;
29
- } | {
30
- kind: "singleton";
31
- name: string;
32
- label: string;
33
- } | {
34
- kind: "order";
35
- collection: string;
36
- label: string;
37
- } | {
38
- kind: "media";
39
- label: string;
40
- } | {
41
- kind: "other";
42
- label: string;
43
- };
44
- export interface AnnotatedChange extends ContentChange {
45
- owner: ChangeOwner;
46
- }
47
- /** One thing that would make the staged result unpublishable. */
48
- export interface StagingProblem {
49
- /** The file the problem is about, relative to the content root. */
50
- path: string;
51
- label: string;
52
- issues: FieldIssue[];
53
- }
54
- export interface StagingValidation {
55
- ok: boolean;
56
- problems: StagingProblem[];
57
- }
58
- export interface StagingStatus {
59
- /** How this deployment stages. The UI words differ with it. */
60
- workspace: "working-tree" | "draft-store";
61
- publish: {
62
- enabled: boolean;
63
- reason?: string;
64
- };
12
+ import { type Site } from "@micacms/core";
13
+ import type { Logger } from "../lib/logger.js";
14
+ import type { ContentFiles } from "../workspace/files.js";
15
+ import { type WorkspaceLocks } from "../workspace/locks.js";
16
+ import type { OwnerPolicy } from "../workspace/policy.js";
17
+ import { type GitTree } from "../workspace/tree.js";
18
+ import { type ContentStagingService } from "./changes.js";
19
+ export interface WorkingTreeStagingDeps {
20
+ model: Site;
65
21
  /**
66
- * What the pending changes are based on: HEAD for a working tree, the
67
- * branch head for a draft store. Sent back with Publish as `expectedBase`.
22
+ * The working tree's files without the lock wrapper: this service holds the
23
+ * locks around whole operations.
68
24
  */
69
- baseRevision: string | null;
70
- /** The branch a publication lands on, where the workspace knows it. */
71
- branch: string | null;
72
- /** Commits created and not yet pushed. Working tree only. */
73
- ahead: number | null;
74
- changes: AnnotatedChange[];
75
- validation: StagingValidation;
76
- /** When the pending set last moved. Null when nothing is pending. */
77
- updatedAt: string | null;
78
- }
79
- export interface PublishInput {
80
- /** Subject line of the commit. Written by the editor, for `git log`. */
81
- message: string;
82
- /** The base the editor reviewed. A repository that moved past it refuses. */
83
- expectedBase: string | null;
84
- author?: Author;
85
- }
86
- export interface ContentStagingService {
87
- status(): Promise<StagingStatus>;
88
- publish(input: PublishInput): Promise<PublishResult>;
89
- discard(paths: string[]): Promise<{
90
- discarded: string[];
91
- }>;
92
- /** Retries the push after `committed-pending-push`. Working tree only. */
93
- push(): Promise<PublishResult>;
94
- /** The document a pending change touches, before and after that change. */
95
- compare(target: CompareTarget): Promise<Comparison>;
96
- }
97
- /** One thing an editor recognises on the Publish page, named for comparison. */
98
- export type CompareTarget =
99
- /** `from` names the published slug of a renamed entry. */
100
- {
101
- kind: "entry";
102
- collection: string;
103
- slug: string;
104
- from?: string;
105
- } | {
106
- kind: "singleton";
107
- name: string;
108
- } | {
109
- kind: "order";
110
- collection: string;
111
- };
112
- /**
113
- * A document on both sides of the pending change set.
114
- *
115
- * Raw field data, deliberately: the editor holds the model and can name,
116
- * order and render every field, so the friendly comparison is its job. What
117
- * only the server can do is read the same document from two places.
118
- */
119
- export interface Comparison {
120
- /** As the repository has it — null when the change creates the document. */
121
- before: Record<string, unknown> | null;
122
- /** As staged for publication — null when the change deletes it. */
123
- after: Record<string, unknown> | null;
124
- }
125
- /**
126
- * Reads one document from the repository (`published`) and from the pending
127
- * workspace (`staged`) — the whole of a before/after comparison, shared by
128
- * both staging implementations since a `ContentSource` is all it needs.
129
- *
130
- * An order target compares the collection's ordering rather than a document:
131
- * each side becomes `{ order: [{ slug, title }] }`, in position order.
132
- */
133
- export declare function compareSources(model: Site, published: ContentSource, staged: ContentSource, target: CompareTarget): Promise<Comparison>;
134
- /**
135
- * Annotates a change set with owners and validates the entries it touches.
136
- *
137
- * One pass on purpose: naming a change and validating it both need the same
138
- * read of the same entries, and content trees are small enough to read the
139
- * affected collections whole.
140
- *
141
- * Validation is scoped to *changed* documents. Content that was already in
142
- * the repository is not this publication's problem — refusing
143
- * to publish a fixed typo because somebody once hand-committed a broken entry
144
- * elsewhere would make the editor hostage to history it cannot touch.
145
- */
146
- export declare function analyseChanges(model: Site, source: ContentSource, changes: ContentChange[],
147
- /** The repository's side. When given, renamed entries are detected. */
148
- published?: ContentSource): Promise<{
149
- changes: AnnotatedChange[];
150
- validation: StagingValidation;
151
- }>;
152
- /**
153
- * Which piece of content a file belongs to.
154
- *
155
- * The path layout is the model's own (`layout.ts`), so this is a reading of
156
- * it, not a second convention: `collection/slug/…` or `collection/slug.json`,
157
- * `singleton.json` or `singleton/…`, and the shared `media/` directory.
158
- */
159
- export declare function classifyPath(model: Site, path: string): ChangeOwner;
160
- export interface DraftStagingDeps {
161
- model: Site;
162
- drafts: DraftStore;
163
- /** The real repository. The one thing here that writes to it. */
164
- repository: RepositoryConnector;
165
- /** The staged overlay the rest of the application reads through. */
166
- overlay: RepositoryConnector;
167
- /** Revision of `.mica/schema.json` when the model was loaded. */
25
+ files: ContentFiles;
26
+ contentRoot: string;
168
27
  schemaRevision: string | null;
28
+ /** `MICA_LOCAL_PUBLISH`, for the default developer policy. */
29
+ publishEnabled: boolean;
30
+ logger: Logger;
31
+ /** Defaults to the developer. */
32
+ policy?: OwnerPolicy;
33
+ /** Shared with the services that write content. */
34
+ locks?: WorkspaceLocks;
35
+ /**
36
+ * Set by a managed clone, whose Git runs in an isolated environment. Without
37
+ * it, the developer's Git finds the tree.
38
+ */
39
+ tree?: GitTree;
169
40
  }
170
- export declare function createDraftStagingService(deps: DraftStagingDeps): ContentStagingService;
171
- export declare function describeProblems(problems: StagingProblem[]): string;
172
- /** Field issues with the file path folded in, for the flat API envelope. */
173
- export declare function flattenProblems(problems: StagingProblem[]): FieldIssue[];
41
+ export declare function createWorkingTreeStagingService(deps: WorkingTreeStagingDeps): ContentStagingService;
174
42
  //# sourceMappingURL=staging.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"staging.d.ts","sourceRoot":"","sources":["../../src/services/staging.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,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