@graview/ship 0.1.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.
Files changed (87) hide show
  1. package/LICENSE +96 -0
  2. package/README.md +95 -0
  3. package/dist/browser-adapter.d.ts +84 -0
  4. package/dist/browser-adapter.d.ts.map +1 -0
  5. package/dist/browser-adapter.js +111 -0
  6. package/dist/browser-adapter.js.map +1 -0
  7. package/dist/browser.d.ts +26 -0
  8. package/dist/browser.d.ts.map +1 -0
  9. package/dist/browser.js +16 -0
  10. package/dist/browser.js.map +1 -0
  11. package/dist/cli.d.ts +48 -0
  12. package/dist/cli.d.ts.map +1 -0
  13. package/dist/cli.js +170 -0
  14. package/dist/cli.js.map +1 -0
  15. package/dist/dev.d.ts +148 -0
  16. package/dist/dev.d.ts.map +1 -0
  17. package/dist/dev.js +286 -0
  18. package/dist/dev.js.map +1 -0
  19. package/dist/door.d.ts +22 -0
  20. package/dist/door.d.ts.map +1 -0
  21. package/dist/door.js +43 -0
  22. package/dist/door.js.map +1 -0
  23. package/dist/export.d.ts +25 -0
  24. package/dist/export.d.ts.map +1 -0
  25. package/dist/export.js +30 -0
  26. package/dist/export.js.map +1 -0
  27. package/dist/file-adapter.d.ts +28 -0
  28. package/dist/file-adapter.d.ts.map +1 -0
  29. package/dist/file-adapter.js +50 -0
  30. package/dist/file-adapter.js.map +1 -0
  31. package/dist/health.d.ts +19 -0
  32. package/dist/health.d.ts.map +1 -0
  33. package/dist/health.js +16 -0
  34. package/dist/health.js.map +1 -0
  35. package/dist/index.d.ts +29 -0
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +15 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/migrations.d.ts +31 -0
  40. package/dist/migrations.d.ts.map +1 -0
  41. package/dist/migrations.js +59 -0
  42. package/dist/migrations.js.map +1 -0
  43. package/dist/open-store.d.ts +57 -0
  44. package/dist/open-store.d.ts.map +1 -0
  45. package/dist/open-store.js +103 -0
  46. package/dist/open-store.js.map +1 -0
  47. package/dist/photos.d.ts +89 -0
  48. package/dist/photos.d.ts.map +1 -0
  49. package/dist/photos.js +102 -0
  50. package/dist/photos.js.map +1 -0
  51. package/dist/presence.d.ts +33 -0
  52. package/dist/presence.d.ts.map +1 -0
  53. package/dist/presence.js +99 -0
  54. package/dist/presence.js.map +1 -0
  55. package/dist/remote.d.ts +73 -0
  56. package/dist/remote.d.ts.map +1 -0
  57. package/dist/remote.js +271 -0
  58. package/dist/remote.js.map +1 -0
  59. package/dist/serve.d.ts +121 -0
  60. package/dist/serve.d.ts.map +1 -0
  61. package/dist/serve.js +249 -0
  62. package/dist/serve.js.map +1 -0
  63. package/dist/snapshot.d.ts +20 -0
  64. package/dist/snapshot.d.ts.map +1 -0
  65. package/dist/snapshot.js +41 -0
  66. package/dist/snapshot.js.map +1 -0
  67. package/dist/source-edit.d.ts +52 -0
  68. package/dist/source-edit.d.ts.map +1 -0
  69. package/dist/source-edit.js +455 -0
  70. package/dist/source-edit.js.map +1 -0
  71. package/dist/steps.d.ts +98 -0
  72. package/dist/steps.d.ts.map +1 -0
  73. package/dist/steps.js +189 -0
  74. package/dist/steps.js.map +1 -0
  75. package/dist/studio-door.d.ts +36 -0
  76. package/dist/studio-door.d.ts.map +1 -0
  77. package/dist/studio-door.js +102 -0
  78. package/dist/studio-door.js.map +1 -0
  79. package/dist/sync-seed.d.ts +61 -0
  80. package/dist/sync-seed.d.ts.map +1 -0
  81. package/dist/sync-seed.js +95 -0
  82. package/dist/sync-seed.js.map +1 -0
  83. package/dist/typecheck.d.ts +15 -0
  84. package/dist/typecheck.d.ts.map +1 -0
  85. package/dist/typecheck.js +59 -0
  86. package/dist/typecheck.js.map +1 -0
  87. package/package.json +75 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serve.js","sourceRoot":"","sources":["../src/serve.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAA0D,MAAM,WAAW,CAAC;AACjG,OAAO,EACL,YAA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,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IACpD,OAAO,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AACnD,CAAC;AAED,SAAS,MAAM,CAAC,MAAc,EAAE,IAAY;IAC1C,OAAO,IAAI,OAAO,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;QACjC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAC3B,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE;YACvB,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC;YACjC,KAAK,CAAC,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QAC/E,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,20 @@
1
+ import { type Primitive } from "@graview/core";
2
+ /**
3
+ * A stored graph mid-migration is BETWEEN schemas, so nothing here
4
+ * validates: the applier moves plain data structurally, and the new-schema
5
+ * store validates the final shape when it folds. Validation in the middle
6
+ * would refuse exactly the states migrations exist to pass through.
7
+ */
8
+ export interface GraphSnapshot {
9
+ readonly nodes: readonly ({
10
+ readonly id: string;
11
+ readonly kind: string;
12
+ } & Record<string, unknown>)[];
13
+ readonly edges: readonly {
14
+ readonly kind: string;
15
+ readonly from: string;
16
+ readonly to: string;
17
+ }[];
18
+ }
19
+ export declare function applyToSnapshot(snapshot: GraphSnapshot, primitives: readonly Primitive[]): GraphSnapshot;
20
+ //# sourceMappingURL=snapshot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snapshot.d.ts","sourceRoot":"","sources":["../src/snapshot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,SAAS,EAAE,MAAM,eAAe,CAAC;AAExD;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;QAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC;IACtG,QAAQ,CAAC,KAAK,EAAE,SAAS;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CAClG;AAED,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,aAAa,EACvB,UAAU,EAAE,SAAS,SAAS,EAAE,GAC/B,aAAa,CA2Cf"}
@@ -0,0 +1,41 @@
1
+ import { isUnset } from "@graview/core";
2
+ export function applyToSnapshot(snapshot, primitives) {
3
+ let nodes = [...snapshot.nodes];
4
+ let edges = [...snapshot.edges];
5
+ for (const primitive of primitives) {
6
+ switch (primitive.op) {
7
+ case "add-node":
8
+ nodes.push(primitive.node);
9
+ break;
10
+ case "remove-node":
11
+ nodes = nodes.filter((node) => node.id !== primitive.node.id);
12
+ edges = edges.filter((edge) => edge.from !== primitive.node.id && edge.to !== primitive.node.id);
13
+ break;
14
+ case "patch-node":
15
+ nodes = nodes.map((node) => {
16
+ if (node.id !== primitive.id)
17
+ return node;
18
+ const patched = { ...node, ...primitive.after };
19
+ // A key patched away is a removal, not a stored undefined — said
20
+ // as `undefined` in memory and as `UNSET` once the op has been
21
+ // written down, because JSON cannot carry the first one.
22
+ for (const [key, value] of Object.entries(primitive.after)) {
23
+ if (isUnset(value))
24
+ delete patched[key];
25
+ }
26
+ return patched;
27
+ });
28
+ break;
29
+ case "add-edge":
30
+ edges.push(primitive.edge);
31
+ break;
32
+ case "remove-edge":
33
+ edges = edges.filter((edge) => !(edge.kind === primitive.edge.kind &&
34
+ edge.from === primitive.edge.from &&
35
+ edge.to === primitive.edge.to));
36
+ break;
37
+ }
38
+ }
39
+ return { nodes, edges };
40
+ }
41
+ //# sourceMappingURL=snapshot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snapshot.js","sourceRoot":"","sources":["../src/snapshot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAkB,MAAM,eAAe,CAAC;AAaxD,MAAM,UAAU,eAAe,CAC7B,QAAuB,EACvB,UAAgC;IAEhC,IAAI,KAAK,GAAG,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAChC,IAAI,KAAK,GAAG,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAChC,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACnC,QAAQ,SAAS,CAAC,EAAE,EAAE,CAAC;YACrB,KAAK,UAAU;gBACb,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,IAAsC,CAAC,CAAC;gBAC7D,MAAM;YACR,KAAK,aAAa;gBAChB,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,KAAK,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;gBAC9D,KAAK,GAAG,KAAK,CAAC,MAAM,CAClB,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,IAAI,CAAC,EAAE,IAAI,IAAI,CAAC,EAAE,KAAK,SAAS,CAAC,IAAI,CAAC,EAAE,CAC3E,CAAC;gBACF,MAAM;YACR,KAAK,YAAY;gBACf,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;oBACzB,IAAI,IAAI,CAAC,EAAE,KAAK,SAAS,CAAC,EAAE;wBAAE,OAAO,IAAI,CAAC;oBAC1C,MAAM,OAAO,GAA4B,EAAE,GAAG,IAAI,EAAE,GAAG,SAAS,CAAC,KAAK,EAAE,CAAC;oBACzE,iEAAiE;oBACjE,+DAA+D;oBAC/D,yDAAyD;oBACzD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;wBAC3D,IAAI,OAAO,CAAC,KAAK,CAAC;4BAAE,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC;oBAC1C,CAAC;oBACD,OAAO,OAAyC,CAAC;gBACnD,CAAC,CAAC,CAAC;gBACH,MAAM;YACR,KAAK,UAAU;gBACb,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;gBAC3B,MAAM;YACR,KAAK,aAAa;gBAChB,KAAK,GAAG,KAAK,CAAC,MAAM,CAClB,CAAC,IAAI,EAAE,EAAE,CACP,CAAC,CACC,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,IAAI,CAAC,IAAI;oBACjC,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,IAAI,CAAC,IAAI;oBACjC,IAAI,CAAC,EAAE,KAAK,SAAS,CAAC,IAAI,CAAC,EAAE,CAC9B,CACJ,CAAC;gBACF,MAAM;QACV,CAAC;IACH,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,52 @@
1
+ import type { DeclarationChange } from "@graview/core";
2
+ import type * as TS from "typescript";
3
+ /**
4
+ * A DECLARATION CHANGE, MADE AS AN EDIT TO THE SOURCE.
5
+ *
6
+ * The studio can write a whole declaration from its graph, and for a new
7
+ * app that is right. For an app somebody has been writing for months it is
8
+ * a disaster with a green tick on it: the graph holds the shape, not the
9
+ * comments that say why, not the `describe` and `format` functions, not a
10
+ * single hand-written body — so a regenerated `schema.ts` is a smaller,
11
+ * poorer file that happens to type-check.
12
+ *
13
+ * So a change is carried as a change — "move `tended-by` from plot to
14
+ * planting" — and made here, inside the checkout's own `defineNode` calls,
15
+ * by the parser's positions: the property removed with the comment above
16
+ * it, carried to the other kind at that kind's indentation, and every other
17
+ * character left exactly where it was.
18
+ *
19
+ * All or nothing. A change the source cannot take — a kind it cannot find,
20
+ * fields written some way other than `z.object({ … })` — refuses the whole
21
+ * set, and says which and why, rather than writing half a declaration.
22
+ */
23
+ export interface SourceText {
24
+ readonly path: string;
25
+ readonly text: string;
26
+ }
27
+ export type SourceEdit = {
28
+ readonly ok: true;
29
+ readonly files: readonly SourceText[];
30
+ } | {
31
+ readonly ok: false;
32
+ readonly refused: readonly string[];
33
+ };
34
+ type Ts = typeof TS;
35
+ export declare function editDeclaration(ts: Ts, files: readonly SourceText[], changes: readonly DeclarationChange[]): SourceEdit;
36
+ /**
37
+ * The checkout's own acts and rules, each as the object it is declared
38
+ * with: what a person or a seat rewrites when a change leaves one of them
39
+ * saying something that is no longer true.
40
+ */
41
+ export declare function declaredCode(ts: Ts, files: readonly SourceText[]): {
42
+ readonly acts: Record<string, {
43
+ path: string;
44
+ text: string;
45
+ }>;
46
+ readonly rules: Record<string, {
47
+ path: string;
48
+ text: string;
49
+ }>;
50
+ };
51
+ export {};
52
+ //# sourceMappingURL=source-edit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"source-edit.d.ts","sourceRoot":"","sources":["../src/source-edit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAEtC;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,MAAM,UAAU,GAClB;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,SAAS,UAAU,EAAE,CAAA;CAAE,GAC5D;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,CAAC;AAEhE,KAAK,EAAE,GAAG,OAAO,EAAE,CAAC;AAEpB,wBAAgB,eAAe,CAAC,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,SAAS,UAAU,EAAE,EAAE,OAAO,EAAE,SAAS,iBAAiB,EAAE,GAAG,UAAU,CASvH;AA8FD;;;;GAIG;AACH,wBAAgB,YAAY,CAC1B,EAAE,EAAE,EAAE,EACN,KAAK,EAAE,SAAS,UAAU,EAAE,GAC3B;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE,CAenI"}
@@ -0,0 +1,455 @@
1
+ export function editDeclaration(ts, files, changes) {
2
+ const current = new Map(files.map((file) => [file.path, file.text]));
3
+ const refused = [];
4
+ for (const change of changes) {
5
+ const outcome = applyChange(ts, current, change);
6
+ if (typeof outcome === "string")
7
+ refused.push(outcome);
8
+ }
9
+ if (refused.length > 0)
10
+ return { ok: false, refused };
11
+ return { ok: true, files: files.map((file) => ({ path: file.path, text: current.get(file.path) })) };
12
+ }
13
+ const parse = (ts, path, text) => ts.createSourceFile(path, text, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
14
+ const calleeIs = (ts, call, name) => (ts.isIdentifier(call.expression) && call.expression.text === name) ||
15
+ (ts.isPropertyAccessExpression(call.expression) && call.expression.name.text === name);
16
+ function visit(ts, node, found) {
17
+ if (found(node))
18
+ return node;
19
+ return ts.forEachChild(node, (child) => visit(ts, child, found));
20
+ }
21
+ /** The declarations of each sort, by the function that declares them. */
22
+ const DECLARERS = {
23
+ kind: ["defineNode"],
24
+ act: ["defineMutation"],
25
+ rule: ["defineInvariant", "defineGraphInvariant"],
26
+ };
27
+ const declares = (ts, node, sort) => ts.isCallExpression(node) && DECLARERS[sort].some((name) => calleeIs(ts, node, name));
28
+ /** `defineNode("plot", { … })` and its kin: the name, when it is a string literal, and the object. */
29
+ function declared(ts, call) {
30
+ const [name, body] = call.arguments;
31
+ return name && ts.isStringLiteralLike(name) && body && ts.isObjectLiteralExpression(body) ? { name: name.text, object: body } : undefined;
32
+ }
33
+ function defineNodeOf(ts, files, kind) {
34
+ return declarationOf(ts, files, "kind", kind);
35
+ }
36
+ /**
37
+ * The declaration of this name. A name may be declared more than once — a
38
+ * tutorial's chapter keeps its own smaller `plot` beside the app's — and
39
+ * the one EXPORTED is the app's; the others are somebody's local copies.
40
+ */
41
+ function declarationOf(ts, files, sort, wanted) {
42
+ const found = [];
43
+ for (const [path, text] of files) {
44
+ const source = parse(ts, path, text);
45
+ const visitAll = (node) => {
46
+ if (declares(ts, node, sort) && declared(ts, node)?.name === wanted)
47
+ found.push(foundAt(ts, path, source, node));
48
+ ts.forEachChild(node, visitAll);
49
+ };
50
+ visitAll(source);
51
+ }
52
+ const exported = (one) => !!one.statement && ts.canHaveModifiers(one.statement) && (ts.getModifiers(one.statement) ?? []).some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword);
53
+ return found.find(exported) ?? found[0];
54
+ }
55
+ function foundAt(ts, path, source, call) {
56
+ let statement = call;
57
+ while (statement.parent && !ts.isSourceFile(statement.parent))
58
+ statement = statement.parent;
59
+ const variable = ts.isVariableStatement(statement) ? statement.declarationList.declarations[0] : undefined;
60
+ return {
61
+ path,
62
+ source,
63
+ object: declared(ts, call).object,
64
+ ...(ts.isVariableStatement(statement) ? { statement } : {}),
65
+ ...(variable && ts.isIdentifier(variable.name) ? { binding: variable.name.text } : {}),
66
+ };
67
+ }
68
+ const propertyName = (ts, property) => property.name && (ts.isIdentifier(property.name) || ts.isStringLiteralLike(property.name)) ? property.name.text : undefined;
69
+ function property(ts, object, name) {
70
+ return object.properties.find((one) => ts.isPropertyAssignment(one) && propertyName(ts, one) === name);
71
+ }
72
+ /** The object inside `fields: z.object({ … })`, or why there is none to edit. */
73
+ function fieldsOf(ts, found, kind) {
74
+ const fields = property(ts, found.object, "fields")?.initializer;
75
+ if (fields && ts.isCallExpression(fields) && calleeIs(ts, fields, "object")) {
76
+ const shape = fields.arguments[0];
77
+ if (shape && ts.isObjectLiteralExpression(shape))
78
+ return shape;
79
+ }
80
+ return `The fields of "${kind}" are not written as z.object({ … }) in ${found.path}, so the studio cannot edit them in place.`;
81
+ }
82
+ /**
83
+ * The checkout's own acts and rules, each as the object it is declared
84
+ * with: what a person or a seat rewrites when a change leaves one of them
85
+ * saying something that is no longer true.
86
+ */
87
+ export function declaredCode(ts, files) {
88
+ const acts = {};
89
+ const rules = {};
90
+ for (const file of files) {
91
+ const source = parse(ts, file.path, file.text);
92
+ const walk = (node) => {
93
+ for (const [sort, into] of [["act", acts], ["rule", rules]]) {
94
+ const found = declares(ts, node, sort) ? declared(ts, node) : undefined;
95
+ if (found)
96
+ into[found.name] = { path: file.path, text: file.text.slice(found.object.getStart(source), found.object.end) };
97
+ }
98
+ ts.forEachChild(node, walk);
99
+ };
100
+ walk(source);
101
+ }
102
+ return { acts, rules };
103
+ }
104
+ /* ------------------------------------------------------------ editing */
105
+ /** The whitespace a line starts with. */
106
+ const indentAt = (text, position) => {
107
+ const start = text.lastIndexOf("\n", position - 1) + 1;
108
+ return /^[ \t]*/.exec(text.slice(start))[0];
109
+ };
110
+ /** One level deeper than `indent`, in the file's own step. */
111
+ const deeper = (text, indent) => indent + (/\n\t/.test(text) && !/\n {2}/.test(text) ? "\t" : " ");
112
+ const key = (name) => (/^[A-Za-z_$][\w$]*$/.test(name) ? name : JSON.stringify(name));
113
+ /** Re-indent a block of source from one indentation to another. */
114
+ const reindent = (block, from, to) => block
115
+ .split("\n")
116
+ .map((line) => (line.startsWith(from) ? to + line.slice(from.length) : line))
117
+ .join("\n");
118
+ function insertProperty(text, object, source, entry) {
119
+ const last = object.properties[object.properties.length - 1];
120
+ // An object written on one line stays on one line, when what joins it fits on one.
121
+ if (!text.slice(object.getStart(source), object.end).includes("\n") && !entry.includes("\n")) {
122
+ return last
123
+ ? `${text.slice(0, last.end)}, ${entry}${text.slice(last.end)}`
124
+ : `${text.slice(0, object.getStart(source))}{ ${entry} }${text.slice(object.end)}`;
125
+ }
126
+ if (!last) {
127
+ const outer = indentAt(text, object.getStart(source));
128
+ const inner = deeper(text, outer);
129
+ return `${text.slice(0, object.getStart(source))}{\n${inner}${reindent(entry, "", inner).trimStart()},\n${outer}}${text.slice(object.end)}`;
130
+ }
131
+ const indent = indentAt(text, last.getStart(source));
132
+ const body = reindent(entry, "", indent).trimStart();
133
+ if (object.properties.hasTrailingComma) {
134
+ const comma = text.indexOf(",", last.end);
135
+ return `${text.slice(0, comma + 1)}\n${indent}${body},${text.slice(comma + 1)}`;
136
+ }
137
+ return `${text.slice(0, last.end)},\n${indent}${body}${text.slice(last.end)}`;
138
+ }
139
+ /**
140
+ * The property's span: from the end of whatever came before it — so the
141
+ * comment above it goes with it — to the comma after it.
142
+ */
143
+ function spanOf(text, element) {
144
+ const comma = /^[ \t]*,/.exec(text.slice(element.end));
145
+ return { start: element.getFullStart(), end: element.end + (comma ? comma[0].length : 0) };
146
+ }
147
+ const cut = (text, span) => text.slice(0, span.start) + text.slice(span.end);
148
+ function replaceNode(text, node, source, replacement) {
149
+ return text.slice(0, node.getStart(source)) + replacement + text.slice(node.end);
150
+ }
151
+ /* ------------------------------------------------------------ changes */
152
+ function applyChange(ts, files, change) {
153
+ if (change.what === "add-kind")
154
+ return addKind(ts, files, change);
155
+ if (change.what === "add-migration")
156
+ return addMigration(ts, files, change);
157
+ if (change.what === "replace-act" || change.what === "replace-rule") {
158
+ const sort = change.what === "replace-act" ? "act" : "rule";
159
+ const name = change.what === "replace-act" ? change.act : change.rule;
160
+ const found = declarationOf(ts, files, sort, name);
161
+ if (!found)
162
+ return `No ${sort} "${name}" declared in ${[...files.keys()].join(", ")}.`;
163
+ const text = files.get(found.path);
164
+ files.set(found.path, replaceNode(text, found.object, found.source, reindent(change.text.trim(), "", indentAt(text, found.object.getStart(found.source))).trimStart()));
165
+ return undefined;
166
+ }
167
+ if (change.what === "add-act" || change.what === "add-rule") {
168
+ const sort = change.what === "add-act" ? "act" : "rule";
169
+ const name = change.what === "add-act" ? change.act : change.rule;
170
+ return addDeclaration(ts, files, sort, name, change.binding, change.text);
171
+ }
172
+ if (change.what === "remove-act" || change.what === "remove-rule") {
173
+ const sort = change.what === "remove-act" ? "act" : "rule";
174
+ const name = change.what === "remove-act" ? change.act : change.rule;
175
+ const found = declarationOf(ts, files, sort, name);
176
+ if (!found?.statement)
177
+ return `No ${sort} "${name}" declared as a statement of its own.`;
178
+ let next = cut(files.get(found.path), spanOf(files.get(found.path), found.statement));
179
+ files.set(found.path, next);
180
+ // And out of whatever list gathers them, wherever that is.
181
+ if (found.binding) {
182
+ for (const [path, text] of files) {
183
+ next = removeFromList(ts, path, text, found.binding) ?? text;
184
+ files.set(path, next);
185
+ }
186
+ }
187
+ return undefined;
188
+ }
189
+ const kind = change.what === "move-edge" ? change.from : change.kind;
190
+ const found = defineNodeOf(ts, files, kind);
191
+ if (!found)
192
+ return `No defineNode("${kind}", { … }) in ${[...files.keys()].join(", ")}.`;
193
+ const text = files.get(found.path);
194
+ switch (change.what) {
195
+ case "remove-kind": {
196
+ if (!found.statement)
197
+ return `defineNode("${kind}") in ${found.path} is not a statement of its own, so the studio cannot remove it.`;
198
+ let next = cut(text, spanOf(text, found.statement));
199
+ if (found.binding)
200
+ next = removeFromSchema(ts, found.path, next, found.binding) ?? next;
201
+ files.set(found.path, next);
202
+ return undefined;
203
+ }
204
+ case "set-kind-property": {
205
+ const existing = property(ts, found.object, change.property);
206
+ if (change.text === null) {
207
+ if (existing)
208
+ files.set(found.path, cut(text, spanOf(text, existing)));
209
+ }
210
+ else if (existing) {
211
+ files.set(found.path, replaceNode(text, existing.initializer, found.source, change.text));
212
+ }
213
+ else {
214
+ files.set(found.path, insertProperty(text, found.object, found.source, `${key(change.property)}: ${change.text}`));
215
+ }
216
+ return undefined;
217
+ }
218
+ case "add-field":
219
+ case "change-field":
220
+ case "remove-field": {
221
+ const shape = fieldsOf(ts, found, kind);
222
+ if (typeof shape === "string")
223
+ return shape;
224
+ const existing = property(ts, shape, change.field);
225
+ if (change.what === "add-field") {
226
+ if (existing)
227
+ return `"${kind}" already has a field "${change.field}" in ${found.path}.`;
228
+ files.set(found.path, insertProperty(text, shape, found.source, `${key(change.field)}: ${change.zod}`));
229
+ }
230
+ else if (!existing) {
231
+ return `"${kind}" has no field "${change.field}" in ${found.path}.`;
232
+ }
233
+ else if (change.what === "change-field") {
234
+ files.set(found.path, replaceNode(text, existing.initializer, found.source, change.zod));
235
+ }
236
+ else {
237
+ files.set(found.path, cut(text, spanOf(text, existing)));
238
+ }
239
+ return undefined;
240
+ }
241
+ case "add-edge":
242
+ case "change-edge":
243
+ case "remove-edge": {
244
+ const edges = property(ts, found.object, "edges");
245
+ const object = edges && ts.isObjectLiteralExpression(edges.initializer) ? edges.initializer : undefined;
246
+ const existing = object ? property(ts, object, change.edge) : undefined;
247
+ if (change.what === "add-edge") {
248
+ if (existing)
249
+ return `"${kind}" already declares "${change.edge}" in ${found.path}.`;
250
+ const entry = `${key(change.edge)}: ${change.text}`;
251
+ files.set(found.path, object ? insertProperty(text, object, found.source, entry) : insertProperty(text, found.object, found.source, `edges: {\n ${entry.split("\n").join("\n ")},\n}`));
252
+ }
253
+ else if (!existing) {
254
+ return `"${kind}" declares no edge "${change.edge}" in ${found.path}.`;
255
+ }
256
+ else if (change.what === "change-edge") {
257
+ files.set(found.path, replaceNode(text, existing.initializer, found.source, reindent(change.text, "", indentAt(text, existing.getStart(found.source)))));
258
+ }
259
+ else {
260
+ files.set(found.path, cut(text, spanOf(text, existing)));
261
+ }
262
+ return undefined;
263
+ }
264
+ case "move-edge":
265
+ return moveEdge(ts, files, found, change);
266
+ }
267
+ }
268
+ /**
269
+ * THE SAME RELATION, ON ANOTHER KIND: carried as it was written. Its
270
+ * readings, its `appendOnly`, the comment that says why it exists all go
271
+ * with it; only where it points is rewritten.
272
+ */
273
+ function moveEdge(ts, files, found, change) {
274
+ const text = files.get(found.path);
275
+ const edges = property(ts, found.object, "edges");
276
+ const object = edges && ts.isObjectLiteralExpression(edges.initializer) ? edges.initializer : undefined;
277
+ const existing = object ? property(ts, object, change.edge) : undefined;
278
+ if (!existing || !ts.isObjectLiteralExpression(existing.initializer))
279
+ return `"${change.from}" declares no edge "${change.edge}" in ${found.path}.`;
280
+ if (!defineNodeOf(ts, files, change.to))
281
+ return `No defineNode("${change.to}", { … }) to move "${change.edge}" onto.`;
282
+ // The property's own text, with its targets rewritten, and its comments above it.
283
+ const span = spanOf(text, existing);
284
+ const target = property(ts, existing.initializer, "to");
285
+ let carried = text.slice(span.start, existing.end);
286
+ if (target) {
287
+ const at = target.initializer.getStart(found.source) - span.start;
288
+ carried = carried.slice(0, at) + change.targets + carried.slice(target.initializer.end - span.start);
289
+ }
290
+ const from = indentAt(text, existing.getStart(found.source));
291
+ const block = carried.replace(/^\n/, "");
292
+ const withoutIndent = reindent(block, from, "");
293
+ // Removed from where it was — and an `edges: {}` left empty goes too.
294
+ let next = cut(text, span);
295
+ const after = defineNodeOf(ts, new Map([[found.path, next]]), change.from);
296
+ const left = property(ts, after.object, "edges");
297
+ if (left && ts.isObjectLiteralExpression(left.initializer) && left.initializer.properties.length === 0) {
298
+ next = cut(next, spanOf(next, left));
299
+ }
300
+ files.set(found.path, next);
301
+ const destination = defineNodeOf(ts, files, change.to);
302
+ const there = files.get(destination.path);
303
+ const edgesThere = property(ts, destination.object, "edges");
304
+ files.set(destination.path, edgesThere && ts.isObjectLiteralExpression(edgesThere.initializer)
305
+ ? insertProperty(there, edgesThere.initializer, destination.source, withoutIndent)
306
+ : insertProperty(there, destination.object, destination.source, `edges: {\n ${withoutIndent.split("\n").join("\n ")},\n}`));
307
+ return undefined;
308
+ }
309
+ /** The `createSchema([...])` array, wherever the kinds are gathered. */
310
+ function schemaList(ts, path, text) {
311
+ const source = parse(ts, path, text);
312
+ const call = visit(ts, source, (node) => ts.isCallExpression(node) && calleeIs(ts, node, "createSchema"));
313
+ const list = call?.arguments[0];
314
+ return list && ts.isArrayLiteralExpression(list) ? { source, list } : undefined;
315
+ }
316
+ function removeFromSchema(ts, path, text, binding) {
317
+ const found = schemaList(ts, path, text);
318
+ return found ? removeElement(ts, text, found.source, found.list, binding) : undefined;
319
+ }
320
+ /** The binding taken out of every array literal in the file that lists it by name. */
321
+ function removeFromList(ts, path, text, binding) {
322
+ const source = parse(ts, path, text);
323
+ const list = visit(ts, source, (node) => ts.isArrayLiteralExpression(node) && node.elements.some((one) => ts.isIdentifier(one) && one.text === binding));
324
+ return list ? removeElement(ts, text, source, list, binding) : undefined;
325
+ }
326
+ function removeElement(ts, text, source, list, binding) {
327
+ const element = list.elements.find((one) => ts.isIdentifier(one) && one.text === binding);
328
+ if (!element)
329
+ return undefined;
330
+ const found = { source, list };
331
+ const elements = found.list.elements;
332
+ const at = elements.indexOf(element);
333
+ // With the comma on whichever side it sits.
334
+ const start = at > 0 ? elements[at - 1].end : element.getStart(found.source);
335
+ const end = at > 0 ? element.end : (elements[at + 1]?.getStart(found.source) ?? element.end);
336
+ return text.slice(0, start) + text.slice(end);
337
+ }
338
+ function addKind(ts, files, change) {
339
+ if (defineNodeOf(ts, files, change.kind))
340
+ return `"${change.kind}" is already declared.`;
341
+ for (const [path, text] of files) {
342
+ const found = schemaList(ts, path, text);
343
+ if (!found)
344
+ continue;
345
+ let statement = found.list;
346
+ while (statement.parent && !ts.isSourceFile(statement.parent))
347
+ statement = statement.parent;
348
+ // Into the list — ahead of any spread, so the app's own kinds stay together.
349
+ const spread = found.list.elements.find((one) => ts.isSpreadElement(one));
350
+ const last = found.list.elements[found.list.elements.length - 1];
351
+ let next = spread
352
+ ? `${text.slice(0, spread.getStart(found.source))}${change.binding}, ${text.slice(spread.getStart(found.source))}`
353
+ : last
354
+ ? `${text.slice(0, last.end)}, ${change.binding}${text.slice(last.end)}`
355
+ : `${text.slice(0, found.list.getStart(found.source) + 1)}${change.binding}${text.slice(found.list.getStart(found.source) + 1)}`;
356
+ // And declared just above where the schema gathers them.
357
+ const before = statement.getStart(found.source);
358
+ next = `${next.slice(0, before)}${change.text.trim()}\n\n${next.slice(before)}`;
359
+ files.set(path, next);
360
+ return undefined;
361
+ }
362
+ return `No createSchema([ … ]) to add "${change.kind}" to.`;
363
+ }
364
+ /**
365
+ * A new act or rule: declared after the last of its sort, and added to the
366
+ * list that gathers the others — the array literal that already names them.
367
+ */
368
+ function addDeclaration(ts, files, sort, name, binding, statement) {
369
+ if (declarationOf(ts, files, sort, name))
370
+ return `The ${sort} "${name}" is already declared.`;
371
+ for (const [path, text] of files) {
372
+ const source = parse(ts, path, text);
373
+ const bindings = new Set();
374
+ let last;
375
+ for (const top of source.statements) {
376
+ const call = visit(ts, top, (node) => declares(ts, node, sort));
377
+ if (!call)
378
+ continue;
379
+ last = top;
380
+ const bound = ts.isVariableStatement(top) ? top.declarationList.declarations[0]?.name : undefined;
381
+ if (bound && ts.isIdentifier(bound))
382
+ bindings.add(bound.text);
383
+ }
384
+ if (!last)
385
+ continue;
386
+ const list = visit(ts, source, (node) => ts.isArrayLiteralExpression(node) && node.elements.some((one) => ts.isIdentifier(one) && bindings.has(one.text)));
387
+ if (!list)
388
+ return `The ${sort}s in ${path} are not gathered in a list the studio can add "${binding}" to.`;
389
+ // The list first, since it comes after the declarations: an edit to it moves nothing above it.
390
+ const tail = list.elements[list.elements.length - 1];
391
+ const multiline = text.slice(list.getStart(source), list.end).includes("\n");
392
+ let next = multiline
393
+ ? `${text.slice(0, tail.end)},\n${indentAt(text, tail.getStart(source))}${binding}${text.slice(tail.end)}`
394
+ : `${text.slice(0, tail.end)}, ${binding}${text.slice(tail.end)}`;
395
+ next = `${next.slice(0, last.end)}\n\n${statement.trim()}${next.slice(last.end)}`;
396
+ files.set(path, next);
397
+ return undefined;
398
+ }
399
+ return `No file declares ${sort}s to add "${name}" beside.`;
400
+ }
401
+ /**
402
+ * THE APP CARRIES ITS STORED GRAPHS FORWARD: its `version` moves on and the
403
+ * migration to it joins `migrations`, in the `defineApp({ … })` the app is
404
+ * declared with — so the graph somebody already has opens on the new
405
+ * declaration by running it, logged and undoable like any other change.
406
+ */
407
+ function addMigration(ts, files, change) {
408
+ for (const [path, text] of files) {
409
+ const source = parse(ts, path, text);
410
+ const call = visit(ts, source, (node) => ts.isCallExpression(node) && calleeIs(ts, node, "defineApp"));
411
+ const app = call?.arguments[0];
412
+ if (!app || !ts.isObjectLiteralExpression(app))
413
+ continue;
414
+ // The list first, then the version, then the import: each edit is later in the file than the next one's position, or re-read.
415
+ let next = text;
416
+ const migrations = property(ts, app, "migrations");
417
+ if (migrations) {
418
+ if (!ts.isArrayLiteralExpression(migrations.initializer))
419
+ return `The migrations in ${path} are not written as a list the studio can add to.`;
420
+ const list = migrations.initializer;
421
+ const tail = list.elements[list.elements.length - 1];
422
+ next = tail
423
+ ? `${next.slice(0, tail.end)},\n${indentAt(next, tail.getStart(source))}${change.text}${next.slice(tail.end)}`
424
+ : `${next.slice(0, list.getStart(source))}[${change.text}]${next.slice(list.end)}`;
425
+ }
426
+ let reread = parse(ts, path, next);
427
+ let object = visit(ts, reread, (node) => ts.isCallExpression(node) && calleeIs(ts, node, "defineApp")).arguments[0];
428
+ if (!migrations)
429
+ next = insertProperty(next, object, reread, `migrations: [${change.text}]`);
430
+ reread = parse(ts, path, next);
431
+ object = visit(ts, reread, (node) => ts.isCallExpression(node) && calleeIs(ts, node, "defineApp")).arguments[0];
432
+ const version = property(ts, object, "version");
433
+ next = version ? replaceNode(next, version.initializer, reread, String(change.version)) : insertProperty(next, object, reread, `version: ${change.version}`);
434
+ files.set(path, withImport(ts, path, next, change.import.name, change.import.from));
435
+ return undefined;
436
+ }
437
+ return "No defineApp({ … }) in the declaration to add a migration to.";
438
+ }
439
+ /** `name` imported from `from`: added to an import of that module the file already has, or as a line of its own. */
440
+ function withImport(ts, path, text, name, from) {
441
+ const source = parse(ts, path, text);
442
+ const imports = source.statements.filter(ts.isImportDeclaration);
443
+ const existing = imports.find((one) => ts.isStringLiteral(one.moduleSpecifier) && one.moduleSpecifier.text === from && !one.importClause?.isTypeOnly);
444
+ const named = existing?.importClause?.namedBindings;
445
+ if (named && ts.isNamedImports(named)) {
446
+ if (named.elements.some((element) => element.name.text === name))
447
+ return text;
448
+ const last = named.elements[named.elements.length - 1];
449
+ return `${text.slice(0, last.end)}, ${name}${text.slice(last.end)}`;
450
+ }
451
+ const after = imports[imports.length - 1];
452
+ const line = `import { ${name} } from ${JSON.stringify(from)};`;
453
+ return after ? `${text.slice(0, after.end)}\n${line}${text.slice(after.end)}` : `${line}\n${text}`;
454
+ }
455
+ //# sourceMappingURL=source-edit.js.map