@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
@@ -0,0 +1,92 @@
1
+ /**
2
+ * What changes with the owner of a working tree: whether Publish may run and
3
+ * how a commit reaches the remote. The app that keeps a managed clone supplies
4
+ * its policy; `developer.ts` is the developer's.
5
+ */
6
+ import type { PublishResult } from "@micacms/core";
7
+ import type { Author } from "./files.js";
8
+ import type { GitTree } from "./tree.js";
9
+ export type PublishAvailability = {
10
+ enabled: true;
11
+ } | {
12
+ enabled: false;
13
+ reason: string;
14
+ };
15
+ /** One piece of content that an editor changed and the website changed too. */
16
+ export interface SyncConflict {
17
+ /** Identifies the group in `resolve`. */
18
+ group: string;
19
+ label: string;
20
+ /** Content-relative paths of the group, on either side. */
21
+ paths: string[];
22
+ upstream: "changed" | "deleted" | "added";
23
+ /** What the comparison shows, when the group is one document. */
24
+ target?: {
25
+ kind: "entry";
26
+ collection: string;
27
+ slug: string;
28
+ } | {
29
+ kind: "singleton";
30
+ name: string;
31
+ } | {
32
+ kind: "order";
33
+ collection: string;
34
+ };
35
+ }
36
+ /** Where a clone that Mica keeps stands against its remote. Managed owners only. */
37
+ export interface SyncStatus {
38
+ lastSyncAt: string | null;
39
+ /** Upstream commits not yet in the clone. */
40
+ behind: number;
41
+ error: {
42
+ code: string;
43
+ message: string;
44
+ since: string;
45
+ } | null;
46
+ /** The content model changed upstream; a restart applies it. */
47
+ restartRequired: boolean;
48
+ /** A publication committed and not yet pushed. Mica retries it. */
49
+ pendingPush: {
50
+ revision: string;
51
+ reason: string;
52
+ } | null;
53
+ /** The last publication the host refused; it is a draft again. */
54
+ refused: {
55
+ reason: string;
56
+ at: string;
57
+ } | null;
58
+ conflicts: SyncConflict[];
59
+ }
60
+ /** What the System page says about the repository, beyond what the runtime knows. */
61
+ export interface RepositoryDescription {
62
+ /** The remote URL, without credentials. */
63
+ url: string;
64
+ branch: string;
65
+ /** Bytes the clone takes on the data volume. */
66
+ cloneBytes: number | null;
67
+ }
68
+ export interface OwnerPolicy {
69
+ readonly owner: "developer" | "managed";
70
+ publishAvailability(): PublishAvailability;
71
+ /**
72
+ * Runs with the remote lock held, before the tree lock. A managed clone syncs
73
+ * here and must not take the remote lock again. Throws an `ApiError` when
74
+ * Publish must wait.
75
+ */
76
+ prepare(tree: GitTree): Promise<void>;
77
+ /** Who a commit names as its author, given the signed-in editor. Undefined leaves it to Git. */
78
+ commitAuthor(editor: Author | undefined): Author | undefined;
79
+ /**
80
+ * Sends HEAD to the remote. A failure returns `committed-pending-push`, not
81
+ * an exception: the commit is real.
82
+ */
83
+ push(tree: GitTree, revision: string): Promise<PublishResult>;
84
+ syncStatus?(): SyncStatus;
85
+ sync?(): Promise<void>;
86
+ /** Keeps the editor's version of a conflicting group, or takes the website's. */
87
+ resolve?(group: string, choice: "mine" | "website"): Promise<void>;
88
+ /** The ref that holds the website's version, for a conflict's comparison. */
89
+ upstreamRef?: string;
90
+ describe?(): Promise<RepositoryDescription>;
91
+ }
92
+ //# sourceMappingURL=policy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["../../src/workspace/policy.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEzC,OAA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,IAAI,CAAC;IAC/C,SAAS,EAAE,YAAY,EAAE,CAAC;CAC3B;AAED,qFAAqF;AACrF,MAAM,WAAW,qBAAqB;IACpC,2CAA2C;IAC3C,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,gDAAgD;IAChD,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,KAAK,EAAE,WAAW,GAAG,SAAS,CAAC;IACxC,mBAAmB,IAAI,mBAAmB,CAAC;IAC3C;;;;OAIG;IACH,OAAO,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtC,gGAAgG;IAChG,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAAC;IAC7D;;;OAGG;IACH,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IAI9D,UAAU,CAAC,IAAI,UAAU,CAAC;IAC1B,IAAI,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,iFAAiF;IACjF,OAAO,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnE,6EAA6E;IAC7E,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,IAAI,OAAO,CAAC,qBAAqB,CAAC,CAAC;CAC7C"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * What changes with the owner of a working tree: whether Publish may run and
3
+ * how a commit reaches the remote. The app that keeps a managed clone supplies
4
+ * its policy; `developer.ts` is the developer's.
5
+ */
6
+ export {};
7
+ //# sourceMappingURL=policy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policy.js","sourceRoot":"","sources":["../../src/workspace/policy.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Git operations on a working tree whose content root is the draft workspace.
3
+ * The owner policy does the push. Every operation is limited to paths under the
4
+ * content root, never `git add -A` over the repository, so other work in the
5
+ * same checkout is never swept into a commit.
6
+ */
7
+ import type { ContentChange, ContentSource } from "@micacms/core";
8
+ import type { Author } from "./files.js";
9
+ import { type GitRunner, type GitRunnerOptions } from "./git.js";
10
+ /**
11
+ * Makes every path argument literal: `tour[1].json` is not a pattern that also
12
+ * matches `tour1.json`.
13
+ */
14
+ export declare const LITERAL = "--literal-pathspecs";
15
+ /** A content root inside a Git repository. */
16
+ export interface GitTree {
17
+ /** Runs in the repository root. */
18
+ git: GitRunner;
19
+ /** Content root relative to the repository root; "" when they coincide. */
20
+ prefix: string;
21
+ /** Absolute path of the content root. */
22
+ contentRoot: string;
23
+ }
24
+ /** A changed file plus what only Git status knows about it. */
25
+ export interface TreeChange extends ContentChange {
26
+ /** Not yet known to Git — discarding means deleting, not restoring. */
27
+ untracked: boolean;
28
+ /** Mid-merge conflict markers. Unpublishable until resolved with Git tools. */
29
+ conflicted: boolean;
30
+ }
31
+ /**
32
+ * Finds the repository the content root sits in, freshly each time: a
33
+ * `git init` after startup should start working, not require a restart.
34
+ */
35
+ export declare function locateTree(contentRoot: string, options?: GitRunnerOptions): Promise<GitTree | {
36
+ reason: string;
37
+ }>;
38
+ /** The content root's changes, as `git status` sees them. */
39
+ export declare function listTreeChanges(tree: GitTree): Promise<TreeChange[]>;
40
+ /**
41
+ * Stages and commits only `paths` (content-root relative) and returns the new
42
+ * HEAD. The pathspec limits both steps, so all other staged or unstaged work
43
+ * stays. Without `author`, Git's configured identity applies.
44
+ */
45
+ export declare function commitPaths(tree: GitTree, paths: string[], message: string, author?: Author): Promise<string>;
46
+ /**
47
+ * Commits `paths` again with the message, author and date of `original`, after
48
+ * a rejected push. Returns the new HEAD.
49
+ */
50
+ export declare function recommitPaths(tree: GitTree, paths: string[], original: string): Promise<string>;
51
+ /** Puts one changed file back to its HEAD version, or removes it if HEAD has none. */
52
+ export declare function discardChange(tree: GitTree, change: TreeChange): Promise<void>;
53
+ /** HEAD's commit id, or null before the first commit. */
54
+ export declare function headRevision(tree: GitTree): Promise<string | null>;
55
+ /** The checked-out branch, or null when there is none to name. */
56
+ export declare function currentBranch(tree: GitTree): Promise<string | null>;
57
+ /** Commits waiting to be pushed, or null when there is no upstream to say. */
58
+ export declare function aheadOfUpstream(tree: GitTree): Promise<number | null>;
59
+ /**
60
+ * The content root as `ref` has it, read from Git's object store, because the
61
+ * working tree holds the drafts.
62
+ */
63
+ export declare function headSource(tree: GitTree, ref?: string): ContentSource;
64
+ /**
65
+ * Parses `git status --porcelain=v1 -z` into content-root-relative changes.
66
+ * `-z` never changes a path; a rename is two fields and becomes a create and a
67
+ * delete. `.mica/` is excluded: the developer commits the manifest, and the
68
+ * drift check guards model changes.
69
+ */
70
+ export declare function parseStatus(raw: string, prefix: string): TreeChange[];
71
+ /** A content-root-relative path as Git sees it, from the repository root. */
72
+ export declare function inRepo(prefix: string, path: string): string;
73
+ //# sourceMappingURL=tree.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tree.d.ts","sourceRoot":"","sources":["../../src/workspace/tree.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAkB,MAAM,eAAe,CAAC;AAGlF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAuB,KAAK,SAAS,EAAE,KAAK,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAEtF;;;GAGG;AACH,eAAO,MAAM,OAAO,wBAAwB,CAAC;AAE7C,8CAA8C;AAC9C,MAAM,WAAW,OAAO;IACtB,mCAAmC;IACnC,GAAG,EAAE,SAAS,CAAC;IACf,2EAA2E;IAC3E,MAAM,EAAE,MAAM,CAAC;IACf,yCAAyC;IACzC,WAAW,EAAE,MAAM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,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,SAAS,GAAG,aAAa,CAyBrE;AAQD;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,UAAU,EAAE,CAsDrE;AAQD,6EAA6E;AAC7E,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAE3D"}
@@ -0,0 +1,229 @@
1
+ /**
2
+ * Git operations on a working tree whose content root is the draft workspace.
3
+ * The owner policy does the push. Every operation is limited to paths under the
4
+ * content root, never `git add -A` over the repository, so other work in the
5
+ * same checkout is never swept into a commit.
6
+ */
7
+ import { existsSync } from "node:fs";
8
+ import { realpath, rm } from "node:fs/promises";
9
+ import { join, relative, sep } from "node:path";
10
+ import { within } from "@micacms/core/node";
11
+ import { GitError, gitRunner } from "./git.js";
12
+ /**
13
+ * Makes every path argument literal: `tour[1].json` is not a pattern that also
14
+ * matches `tour1.json`.
15
+ */
16
+ export const LITERAL = "--literal-pathspecs";
17
+ /**
18
+ * Finds the repository the content root sits in, freshly each time: a
19
+ * `git init` after startup should start working, not require a restart.
20
+ */
21
+ export async function locateTree(contentRoot, options = {}) {
22
+ const probe = gitRunner(contentRoot, options);
23
+ try {
24
+ const repoRoot = await probe.run(["rev-parse", "--show-toplevel"]);
25
+ // Git resolves symlinks in the toplevel (`/private/var` for `/var` on
26
+ // macOS); do the same, or the prefix is wrong.
27
+ const resolved = await realpath(contentRoot);
28
+ return {
29
+ git: gitRunner(repoRoot, options),
30
+ prefix: toPosix(relative(repoRoot, resolved)),
31
+ contentRoot,
32
+ };
33
+ }
34
+ catch (error) {
35
+ return {
36
+ reason: error instanceof GitError && error.exitCode === null
37
+ ? error.message
38
+ : "The content directory is not inside a Git repository.",
39
+ };
40
+ }
41
+ }
42
+ /** The content root's changes, as `git status` sees them. */
43
+ export async function listTreeChanges(tree) {
44
+ // `-uall`: Git otherwise collapses a new, untracked entry directory to one line.
45
+ // `GIT_OPTIONAL_LOCKS=0`: no `index.lock`, so a parallel commit cannot fail on it.
46
+ const raw = await tree.git.run([LITERAL, "status", "--porcelain=v1", "-z", "-uall", "--", tree.prefix === "" ? "." : tree.prefix], { env: { GIT_OPTIONAL_LOCKS: "0" } });
47
+ return parseStatus(raw, tree.prefix);
48
+ }
49
+ /**
50
+ * Stages and commits only `paths` (content-root relative) and returns the new
51
+ * HEAD. The pathspec limits both steps, so all other staged or unstaged work
52
+ * stays. Without `author`, Git's configured identity applies.
53
+ */
54
+ export async function commitPaths(tree, paths, message, author) {
55
+ const inRepository = await stagePaths(tree, paths);
56
+ const as = author ? [`--author=${author.name} <${author.email}>`] : [];
57
+ await tree.git.run([LITERAL, "commit", "-m", message, ...as, "--", ...inRepository]);
58
+ return tree.git.run(["rev-parse", "HEAD"]);
59
+ }
60
+ /**
61
+ * Commits `paths` again with the message, author and date of `original`, after
62
+ * a rejected push. Returns the new HEAD.
63
+ */
64
+ export async function recommitPaths(tree, paths, original) {
65
+ const inRepository = await stagePaths(tree, paths);
66
+ await tree.git.run([LITERAL, "commit", "-C", original, "--", ...inRepository]);
67
+ return tree.git.run(["rev-parse", "HEAD"]);
68
+ }
69
+ /**
70
+ * Stages `paths`, because `git commit -- <paths>` refuses a file Git has never
71
+ * seen. A path gone from the disk uses `rm --cached`, because `git add` refuses
72
+ * a deletion that is already staged (as `reset --soft` leaves it).
73
+ */
74
+ async function stagePaths(tree, paths) {
75
+ const present = [];
76
+ const gone = [];
77
+ for (const path of paths) {
78
+ (existsSync(within(tree.contentRoot, path)) ? present : gone).push(inRepo(tree.prefix, path));
79
+ }
80
+ for (const batch of chunked(present, 500)) {
81
+ await tree.git.run([LITERAL, "add", "-A", "--", ...batch]);
82
+ }
83
+ for (const batch of chunked(gone, 500)) {
84
+ await tree.git.run([LITERAL, "rm", "--cached", "--ignore-unmatch", "--quiet", "--", ...batch]);
85
+ }
86
+ return paths.map((path) => inRepo(tree.prefix, path));
87
+ }
88
+ /** Puts one changed file back to its HEAD version, or removes it if HEAD has none. */
89
+ export async function discardChange(tree, change) {
90
+ if (change.kind === "create") {
91
+ // Unstage a staged creation first, so the index does not point at a deleted file.
92
+ if (!change.untracked) {
93
+ await tree.git.tryRun([LITERAL, "rm", "--cached", "--force", "--", inRepo(tree.prefix, change.path)]);
94
+ }
95
+ await rm(within(tree.contentRoot, change.path), { force: true });
96
+ return;
97
+ }
98
+ await tree.git.run([
99
+ LITERAL,
100
+ "restore",
101
+ "--source=HEAD",
102
+ "--staged",
103
+ "--worktree",
104
+ "--",
105
+ inRepo(tree.prefix, change.path),
106
+ ]);
107
+ }
108
+ /** HEAD's commit id, or null before the first commit. */
109
+ export function headRevision(tree) {
110
+ return tree.git.tryRun(["rev-parse", "HEAD"]);
111
+ }
112
+ /** The checked-out branch, or null when there is none to name. */
113
+ export function currentBranch(tree) {
114
+ return tree.git.tryRun(["rev-parse", "--abbrev-ref", "HEAD"]);
115
+ }
116
+ /** Commits waiting to be pushed, or null when there is no upstream to say. */
117
+ export async function aheadOfUpstream(tree) {
118
+ const counted = await tree.git.tryRun(["rev-list", "--count", "@{upstream}..HEAD"]);
119
+ if (counted === null)
120
+ return null;
121
+ const ahead = Number(counted);
122
+ return Number.isFinite(ahead) ? ahead : null;
123
+ }
124
+ /**
125
+ * The content root as `ref` has it, read from Git's object store, because the
126
+ * working tree holds the drafts.
127
+ */
128
+ export function headSource(tree, ref = "HEAD") {
129
+ const at = (path) => `${ref}:${path === "" ? tree.prefix : inRepo(tree.prefix, path)}`;
130
+ return {
131
+ origin: ref,
132
+ async read(path) {
133
+ // "Not in HEAD" and "no commits yet" both mean that there is no published version.
134
+ return tree.git.tryRun(["show", at(path)]);
135
+ },
136
+ async list(path) {
137
+ const raw = await tree.git.tryRun(["ls-tree", "-z", at(path)]);
138
+ if (raw === null)
139
+ return [];
140
+ const entries = [];
141
+ for (const field of raw.split("\0")) {
142
+ const tab = field.indexOf("\t");
143
+ if (tab === -1)
144
+ continue;
145
+ const type = field.slice(0, tab).split(" ")[1];
146
+ entries.push({ name: field.slice(tab + 1), type: type === "tree" ? "directory" : "file" });
147
+ }
148
+ return entries;
149
+ },
150
+ };
151
+ }
152
+ /**
153
+ * A save's temporary file (`*.mica-<pid>-<n>`), seen during a save or after a
154
+ * crash. Never content.
155
+ */
156
+ const TEMPORARY_FILE = /\.mica-\d+-\d+$/;
157
+ /**
158
+ * Parses `git status --porcelain=v1 -z` into content-root-relative changes.
159
+ * `-z` never changes a path; a rename is two fields and becomes a create and a
160
+ * delete. `.mica/` is excluded: the developer commits the manifest, and the
161
+ * drift check guards model changes.
162
+ */
163
+ export function parseStatus(raw, prefix) {
164
+ const fields = raw.split("\0").filter((field) => field !== "");
165
+ const changes = [];
166
+ const push = (repoPath, kind, flags = {}) => {
167
+ const path = relativeToContent(repoPath, prefix);
168
+ if (path === null || path === ".mica" || path.startsWith(".mica/"))
169
+ return;
170
+ if (TEMPORARY_FILE.test(path))
171
+ return;
172
+ changes.push({
173
+ path,
174
+ kind,
175
+ untracked: flags.untracked ?? false,
176
+ conflicted: flags.conflicted ?? false,
177
+ });
178
+ };
179
+ for (let at = 0; at < fields.length; at += 1) {
180
+ const field = fields[at];
181
+ const x = field[0] ?? " ";
182
+ const y = field[1] ?? " ";
183
+ const repoPath = field.slice(3);
184
+ if (x === "?" && y === "?") {
185
+ push(repoPath, "create", { untracked: true });
186
+ continue;
187
+ }
188
+ // A merge conflict state, whatever the tree holds.
189
+ if (x === "U" || y === "U" || (x === "A" && y === "A") || (x === "D" && y === "D")) {
190
+ push(repoPath, "update", { conflicted: true });
191
+ continue;
192
+ }
193
+ if (x === "R" || x === "C") {
194
+ // The next field is the source path; only a rename deletes it.
195
+ const from = fields[++at];
196
+ push(repoPath, "create");
197
+ if (x === "R")
198
+ push(from, "delete");
199
+ continue;
200
+ }
201
+ if (x === "D" || y === "D") {
202
+ push(repoPath, "delete");
203
+ continue;
204
+ }
205
+ push(repoPath, x === "A" ? "create" : "update");
206
+ }
207
+ return changes;
208
+ }
209
+ function relativeToContent(repoPath, prefix) {
210
+ if (prefix === "")
211
+ return repoPath;
212
+ if (repoPath === prefix)
213
+ return null;
214
+ return repoPath.startsWith(`${prefix}/`) ? repoPath.slice(prefix.length + 1) : null;
215
+ }
216
+ /** A content-root-relative path as Git sees it, from the repository root. */
217
+ export function inRepo(prefix, path) {
218
+ return prefix === "" ? path : join(prefix, path).split(sep).join("/");
219
+ }
220
+ function toPosix(path) {
221
+ return sep === "/" ? path : path.split(sep).join("/");
222
+ }
223
+ function chunked(items, size) {
224
+ const batches = [];
225
+ for (let at = 0; at < items.length; at += size)
226
+ batches.push(items.slice(at, at + size));
227
+ return batches;
228
+ }
229
+ //# sourceMappingURL=tree.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tree.js","sourceRoot":"","sources":["../../src/workspace/tree.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAGhD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAG5C,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAyC,MAAM,UAAU,CAAC;AAEtF;;;GAGG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,qBAAqB,CAAC;AAoB7C;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,WAAmB,EACnB,UAA4B,EAAE;IAE9B,MAAM,KAAK,GAAG,SAAS,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IAC9C,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,iBAAiB,CAAC,CAAC,CAAC;QACnE,sEAAsE;QACt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,CAAC;AAED,SAAS,OAAO,CAAC,IAAY;IAC3B,OAAO,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACxD,CAAC;AAED,SAAS,OAAO,CAAI,KAAU,EAAE,IAAY;IAC1C,MAAM,OAAO,GAAU,EAAE,CAAC;IAC1B,KAAK,IAAI,EAAE,GAAG,CAAC,EAAE,EAAE,GAAG,KAAK,CAAC,MAAM,EAAE,EAAE,IAAI,IAAI;QAAE,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC;IACzF,OAAO,OAAO,CAAC;AACjB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@micacms/runtime",
3
- "version": "0.4.0",
3
+ "version": "0.5.0-rc.1",
4
4
  "type": "module",
5
5
  "description": "The Mica single-site runtime: the Hono API, application services and staging orchestration, authentication-neutral. Composed by @micacms/editor locally and @micacms/self-hosted behind OIDC.",
6
6
  "license": "MIT",
@@ -29,8 +29,7 @@
29
29
  "hono": "^4.13.7",
30
30
  "image-size": "^2.0.3",
31
31
  "zod": "^4.3.6",
32
- "@micacms/connectors": "0.4.0",
33
- "@micacms/core": "0.4.0"
32
+ "@micacms/core": "0.5.0-rc.1"
34
33
  },
35
34
  "devDependencies": {
36
35
  "@types/node": "^22.20.1",
@@ -1,35 +0,0 @@
1
- /**
2
- * SQLite driver.
3
- *
4
- * Everything above this file talks to `SqlDatabase`, never to `node:sqlite`
5
- * directly, so the driver can be swapped (better-sqlite3, libsql, a Postgres
6
- * adapter) without touching the repositories.
7
- *
8
- * `node:sqlite` is the default because it ships with Node — no native build
9
- * step, no prebuilt-binary mismatch inside the container.
10
- */
11
- export type SqlValue = string | number | bigint | null | Uint8Array;
12
- export type SqlParams = readonly SqlValue[];
13
- export interface RunResult {
14
- changes: number;
15
- lastInsertRowid: number | bigint;
16
- }
17
- export interface SqlDatabase {
18
- all<T = Record<string, unknown>>(sql: string, params?: SqlParams): T[];
19
- get<T = Record<string, unknown>>(sql: string, params?: SqlParams): T | undefined;
20
- run(sql: string, params?: SqlParams): RunResult;
21
- exec(sql: string): void;
22
- /** Runs `fn` in a transaction, rolling back if it throws. Safe to nest. */
23
- transaction<T>(fn: () => T): T;
24
- /** Consistent on-line snapshot to `destination`, safe while writes continue. */
25
- snapshot(destination: string): void;
26
- close(): void;
27
- }
28
- export interface SqliteOptions {
29
- /** Milliseconds a blocked writer waits before returning SQLITE_BUSY. */
30
- busyTimeoutMs?: number;
31
- /** WAL is the right default for a server; `false` is useful for :memory:. */
32
- wal?: boolean;
33
- }
34
- export declare function openSqlite(filename: string, options?: SqliteOptions): SqlDatabase;
35
- //# sourceMappingURL=driver.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"driver.d.ts","sourceRoot":"","sources":["../../src/db/driver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,UAAU,CAAC;AACpE,MAAM,MAAM,SAAS,GAAG,SAAS,QAAQ,EAAE,CAAC;AAE5C,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,MAAM,GAAG,MAAM,CAAC;CAClC;AAED,MAAM,WAAW,WAAW;IAC1B,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,SAAS,GAAG,CAAC,EAAE,CAAC;IACvE,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,SAAS,GAAG,CAAC,GAAG,SAAS,CAAC;IACjF,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,SAAS,GAAG,SAAS,CAAC;IAChD,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,2EAA2E;IAC3E,WAAW,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;IAC/B,gFAAgF;IAChF,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,KAAK,IAAI,IAAI,CAAC;CACf;AAED,MAAM,WAAW,aAAa;IAC5B,wEAAwE;IACxE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,6EAA6E;IAC7E,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAED,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,WAAW,CA2FrF"}
package/dist/db/driver.js DELETED
@@ -1,95 +0,0 @@
1
- /**
2
- * SQLite driver.
3
- *
4
- * Everything above this file talks to `SqlDatabase`, never to `node:sqlite`
5
- * directly, so the driver can be swapped (better-sqlite3, libsql, a Postgres
6
- * adapter) without touching the repositories.
7
- *
8
- * `node:sqlite` is the default because it ships with Node — no native build
9
- * step, no prebuilt-binary mismatch inside the container.
10
- */
11
- import { DatabaseSync } from "node:sqlite";
12
- export function openSqlite(filename, options = {}) {
13
- const db = new DatabaseSync(filename);
14
- const cache = new Map();
15
- let depth = 0;
16
- db.exec("PRAGMA foreign_keys = ON");
17
- db.exec(`PRAGMA busy_timeout = ${options.busyTimeoutMs ?? 5000}`);
18
- if (options.wal !== false) {
19
- // WAL lets the Astro build read while an editor writes.
20
- db.exec("PRAGMA journal_mode = WAL");
21
- // NORMAL is durable across process crashes; only an OS-level crash can lose
22
- // the last transactions. The right trade-off for a content database.
23
- db.exec("PRAGMA synchronous = NORMAL");
24
- }
25
- const prepare = (sql) => {
26
- let statement = cache.get(sql);
27
- if (!statement) {
28
- statement = db.prepare(sql);
29
- cache.set(sql, statement);
30
- }
31
- return statement;
32
- };
33
- // Rows arrive as null-prototype objects; callers expect ordinary ones.
34
- const plain = (row) => ({ ...row });
35
- return {
36
- all(sql, params = []) {
37
- return prepare(sql)
38
- .all(...params)
39
- .map((row) => plain(row));
40
- },
41
- get(sql, params = []) {
42
- const row = prepare(sql).get(...params);
43
- return row === undefined ? undefined : plain(row);
44
- },
45
- run(sql, params = []) {
46
- const result = prepare(sql).run(...params);
47
- return {
48
- changes: Number(result.changes),
49
- lastInsertRowid: result.lastInsertRowid,
50
- };
51
- },
52
- exec(sql) {
53
- db.exec(sql);
54
- },
55
- transaction(fn) {
56
- // Nested calls use savepoints so an inner rollback does not discard the
57
- // outer transaction's work.
58
- const name = `sp_${depth}`;
59
- const begin = depth === 0 ? "BEGIN IMMEDIATE" : `SAVEPOINT ${name}`;
60
- const commit = depth === 0 ? "COMMIT" : `RELEASE ${name}`;
61
- const rollback = depth === 0 ? "ROLLBACK" : `ROLLBACK TO ${name}`;
62
- db.exec(begin);
63
- depth++;
64
- try {
65
- const result = fn();
66
- depth--;
67
- db.exec(commit);
68
- return result;
69
- }
70
- catch (error) {
71
- depth--;
72
- try {
73
- db.exec(rollback);
74
- if (depth > 0)
75
- db.exec(`RELEASE ${name}`);
76
- }
77
- catch {
78
- // The rollback itself failing means the connection is unusable;
79
- // surface the original error rather than masking it.
80
- }
81
- throw error;
82
- }
83
- },
84
- snapshot(destination) {
85
- // VACUUM INTO takes a read lock only, so editors are not blocked and the
86
- // resulting file is a defragmented, fully consistent database.
87
- db.exec(`VACUUM INTO '${destination.replace(/'/g, "''")}'`);
88
- },
89
- close() {
90
- cache.clear();
91
- db.close();
92
- },
93
- };
94
- }
95
- //# sourceMappingURL=driver.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"driver.js","sourceRoot":"","sources":["../../src/db/driver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,YAAY,EAAsB,MA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AC;gBAChB,OAAO,MAAM,CAAC;YAChB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,KAAK,EAAE,CAAC;gBACR,IAAI,CAAC;oBACH,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;oBAClB,IAAI,KAAK,GAAG,CAAC;wBAAE,EAAE,CAAC,IAAI,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC;gBAC5C,CAAC;gBAAC,MAAM,CAAC;oBACP,gEAAgE;oBAChE,qDAAqD;gBACvD,CAAC;gBACD,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC;QAED,QAAQ,CAAC,WAAmB;YAC1B,yEAAyE;YACzE,+DAA+D;YAC/D,EAAE,CAAC,IAAI,CAAC,gBAAgB,WAAW,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;QAC9D,CAAC;QAED,KAAK;YACH,KAAK,CAAC,KAAK,EAAE,CAAC;YACd,EAAE,CAAC,KAAK,EAAE,CAAC;QACb,CAAC;KACF,CAAC;AACJ,CAAC"}
package/dist/lib/git.d.ts DELETED
@@ -1,29 +0,0 @@
1
- /**
2
- * Spawning the developer's own `git`.
3
- *
4
- * Deliberately the binary, not a JavaScript Git implementation. The reason is
5
- * credentials: a developer's push already works because of their SSH agent,
6
- * credential helper and remote configuration, and the spawned binary inherits
7
- * all three. A library would have to reimplement them, and would do it worse
8
- * — see decisions.md, "Local publishing spawns the `git` binary".
9
- *
10
- * `GIT_TERMINAL_PROMPT=0` because there is no terminal to answer: a push that
11
- * would ask for credentials must fail with Git's own message rather than hang
12
- * the request that triggered it.
13
- */
14
- export declare class GitError extends Error {
15
- readonly stderr: string;
16
- readonly exitCode: number | null;
17
- name: string;
18
- constructor(message: string, stderr: string, exitCode: number | null);
19
- }
20
- export interface GitRunner {
21
- /** Runs `git` in the runner's directory. Trimmed stdout, or a `GitError`. */
22
- run(args: string[]): Promise<string>;
23
- /** Like `run`, but null instead of a throw — for questions Git may say no to. */
24
- tryRun(args: string[]): Promise<string | null>;
25
- }
26
- export declare function gitRunner(cwd: string): GitRunner;
27
- /** The line a person should see first — Git puts its verdict there. */
28
- export declare function firstLine(text: string): string;
29
- //# sourceMappingURL=git.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"git.d.ts","sourceRoot":"","sources":["../../src/lib/git.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,qBAAa,QAAS,SAAQ,KAAK;IAI/B,QAAQ,CAAC,MAAM,EAAE,MAAM;IACvB,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAJzB,IAAI,SAAc;gBAEzB,OAAO,EAAE,MAAM,EACN,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,GAAG,IAAI;CAInC;AAED,MAAM,WAAW,SAAS;IACxB,6EAA6E;IAC7E,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACrC,iFAAiF;IACjF,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;CAChD;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAyChD;AAED,uEAAuE;AACvE,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAO9C"}