@latticecms/cli 0.0.0 → 0.1.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 (72) hide show
  1. package/README.md +138 -2
  2. package/dist/bin.d.ts +3 -0
  3. package/dist/bin.d.ts.map +1 -0
  4. package/dist/bin.js +12 -0
  5. package/dist/bin.js.map +1 -0
  6. package/dist/changes.d.ts +22 -0
  7. package/dist/changes.d.ts.map +1 -0
  8. package/dist/changes.js +118 -0
  9. package/dist/changes.js.map +1 -0
  10. package/dist/collection.d.ts +5 -0
  11. package/dist/collection.d.ts.map +1 -0
  12. package/dist/collection.js +166 -0
  13. package/dist/collection.js.map +1 -0
  14. package/dist/config.d.ts +37 -0
  15. package/dist/config.d.ts.map +1 -0
  16. package/dist/config.js +111 -0
  17. package/dist/config.js.map +1 -0
  18. package/dist/diff.d.ts +6 -0
  19. package/dist/diff.d.ts.map +1 -0
  20. package/dist/diff.js +83 -0
  21. package/dist/diff.js.map +1 -0
  22. package/dist/edit.d.ts +105 -0
  23. package/dist/edit.d.ts.map +1 -0
  24. package/dist/edit.js +571 -0
  25. package/dist/edit.js.map +1 -0
  26. package/dist/exit.d.ts +13 -0
  27. package/dist/exit.d.ts.map +1 -0
  28. package/dist/exit.js +19 -0
  29. package/dist/exit.js.map +1 -0
  30. package/dist/layout.d.ts +20 -0
  31. package/dist/layout.d.ts.map +1 -0
  32. package/dist/layout.js +59 -0
  33. package/dist/layout.js.map +1 -0
  34. package/dist/main.d.ts +7 -0
  35. package/dist/main.d.ts.map +1 -0
  36. package/dist/main.js +58 -0
  37. package/dist/main.js.map +1 -0
  38. package/dist/migrate.d.ts +9 -0
  39. package/dist/migrate.d.ts.map +1 -0
  40. package/dist/migrate.js +120 -0
  41. package/dist/migrate.js.map +1 -0
  42. package/dist/migration.d.ts +5 -0
  43. package/dist/migration.d.ts.map +1 -0
  44. package/dist/migration.js +170 -0
  45. package/dist/migration.js.map +1 -0
  46. package/dist/names.d.ts +15 -0
  47. package/dist/names.d.ts.map +1 -0
  48. package/dist/names.js +32 -0
  49. package/dist/names.js.map +1 -0
  50. package/dist/templates.d.ts +21 -0
  51. package/dist/templates.d.ts.map +1 -0
  52. package/dist/templates.js +73 -0
  53. package/dist/templates.js.map +1 -0
  54. package/dist/typescript.d.ts +9 -0
  55. package/dist/typescript.d.ts.map +1 -0
  56. package/dist/typescript.js +60 -0
  57. package/dist/typescript.js.map +1 -0
  58. package/package.json +61 -2
  59. package/src/bin.ts +12 -0
  60. package/src/changes.ts +170 -0
  61. package/src/collection.ts +228 -0
  62. package/src/config.ts +142 -0
  63. package/src/diff.ts +90 -0
  64. package/src/edit.ts +812 -0
  65. package/src/exit.ts +19 -0
  66. package/src/layout.ts +91 -0
  67. package/src/main.ts +71 -0
  68. package/src/migrate.ts +155 -0
  69. package/src/migration.ts +239 -0
  70. package/src/names.ts +48 -0
  71. package/src/templates.ts +104 -0
  72. package/src/typescript.ts +79 -0
package/dist/config.js ADDED
@@ -0,0 +1,111 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { readFile, stat } from 'node:fs/promises';
3
+ import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
4
+ import { Exit, isRecord } from './exit.js';
5
+ import { fieldProblem } from './names.js';
6
+ /** The `"lattice"` keys that name paths, each defaulting to the crm's layout. */
7
+ const defaults = {
8
+ collections: 'src/domain/collections',
9
+ composition: 'src/servers/rpc/contract.ts',
10
+ events: 'src/domain/events/domain-events.ts',
11
+ migrations: 'src/infra/migrations',
12
+ migrate: 'dist/servers/scripts/migrate.js',
13
+ };
14
+ /** Every key. `tenant` has no default. */
15
+ const keys = [...Object.keys(defaults), 'tenant'];
16
+ /** The nearest directory at or above `cwd` with a `package.json`. */
17
+ function rootOf(cwd) {
18
+ for (let dir = resolve(cwd);; dir = dirname(dir)) {
19
+ if (existsSync(join(dir, 'package.json')))
20
+ return dir;
21
+ if (dirname(dir) === dir) {
22
+ throw new Exit(`no package.json in ${cwd} or above it`, 1);
23
+ }
24
+ }
25
+ }
26
+ /**
27
+ * The app's config: the `"lattice"` key of the nearest `package.json`, over
28
+ * the defaults. Anything wrong with it is a usage error that names the file
29
+ * and the key: invalid JSON, an unknown key, a value that is not a
30
+ * non-empty string, a bad tenant field, or a path outside the app. Whether
31
+ * a path exists is checked by the command that needs it, with `existing`.
32
+ */
33
+ export async function loadConfig(cwd) {
34
+ const root = rootOf(cwd);
35
+ const manifestPath = join(root, 'package.json');
36
+ const manifest = relative(cwd, manifestPath) || 'package.json';
37
+ function fail(message) {
38
+ throw new Exit(message, 2);
39
+ }
40
+ let parsed;
41
+ try {
42
+ parsed = JSON.parse(await readFile(manifestPath, 'utf8'));
43
+ }
44
+ catch (error) {
45
+ fail(`${manifest} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`);
46
+ }
47
+ const given = isRecord(parsed) ? (parsed.lattice ?? {}) : {};
48
+ if (!isRecord(given))
49
+ fail(`"lattice" in ${manifest} must be an object`);
50
+ const values = { ...defaults };
51
+ for (const [key, value] of Object.entries(given)) {
52
+ if (!keys.includes(key)) {
53
+ fail(`unknown key "lattice.${key}" in ${manifest}`);
54
+ }
55
+ if (typeof value !== 'string' || value.trim() === '') {
56
+ fail(`"lattice.${key}" in ${manifest} must be a non-empty string`);
57
+ }
58
+ values[key] = value;
59
+ }
60
+ const written = {
61
+ collections: values.collections ?? defaults.collections,
62
+ composition: values.composition ?? defaults.composition,
63
+ events: values.events ?? defaults.events,
64
+ migrations: values.migrations ?? defaults.migrations,
65
+ migrate: values.migrate ?? defaults.migrate,
66
+ };
67
+ const inside = (key) => {
68
+ const value = written[key];
69
+ const absolute = resolve(root, value);
70
+ const path = relative(root, absolute);
71
+ if (isAbsolute(value) || path === '..' || path.startsWith(`..${sep}`)) {
72
+ fail(`"lattice.${key}" in ${manifest} must be a path inside the app, not ${value}`);
73
+ }
74
+ return absolute;
75
+ };
76
+ const tenant = values.tenant;
77
+ const problem = tenant === undefined ? undefined : fieldProblem(tenant);
78
+ if (problem !== undefined) {
79
+ fail(`"lattice.tenant" in ${manifest}: ${problem}`);
80
+ }
81
+ return {
82
+ root,
83
+ manifest,
84
+ paths: {
85
+ collections: inside('collections'),
86
+ composition: inside('composition'),
87
+ events: inside('events'),
88
+ migrations: inside('migrations'),
89
+ migrate: inside('migrate'),
90
+ },
91
+ written,
92
+ tenant,
93
+ };
94
+ }
95
+ /**
96
+ * The path of `key`, which must exist and be a file or a directory as
97
+ * `kind` says. Otherwise a usage error that names the key.
98
+ */
99
+ export async function existing(config, key, kind) {
100
+ const path = config.paths[key];
101
+ const value = config.written[key];
102
+ const found = await stat(path).catch(() => undefined);
103
+ if (found === undefined) {
104
+ throw new Exit(`${value} does not exist: set "lattice.${key}" in ${config.manifest} to the app's ${kind}`, 2);
105
+ }
106
+ if (found.isDirectory() !== (kind === 'directory')) {
107
+ throw new Exit(`"lattice.${key}" in ${config.manifest} must be a ${kind}: ${value}`, 2);
108
+ }
109
+ return path;
110
+ }
111
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAC9E,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1C,iFAAiF;AACjF,MAAM,QAAQ,GAAG;IACf,WAAW,EAAE,wBAAwB;IACrC,WAAW,EAAE,6BAA6B;IAC1C,MAAM,EAAE,oCAAoC;IAC5C,UAAU,EAAE,sBAAsB;IAClC,OAAO,EAAE,iCAAiC;CAC3C,C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G,MAAM,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IACtD,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,MAAM,IAAI,IAAI,CACZ,GAAG,KAAK,iCAAiC,GAAG,QAAQ,MAAM,CAAC,QAAQ,iBAAiB,IAAI,EAAE,EAC1F,CAAC,CACF,CAAC;IACJ,CAAC;IACD,IAAI,KAAK,CAAC,WAAW,EAAE,KAAK,CAAC,IAAI,KAAK,WAAW,CAAC,EAAE,CAAC;QACnD,MAAM,IAAI,IAAI,CACZ,YAAY,GAAG,QAAQ,MAAM,CAAC,QAAQ,cAAc,IAAI,KAAK,KAAK,EAAE,EACpE,CAAC,CACF,CAAC;IACJ,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
package/dist/diff.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ /**
2
+ * A unified diff of one file, `before` undefined for a new file. Each hunk
3
+ * has three lines of context, and hunks that touch merge.
4
+ */
5
+ export declare function diff(path: string, before: string | undefined, after: string): string;
6
+ //# sourceMappingURL=diff.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["../src/diff.ts"],"names":[],"mappings":"AAoDA;;;GAGG;AACH,wBAAgB,IAAI,CAClB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,KAAK,EAAE,MAAM,GACZ,MAAM,CA6BR"}
package/dist/diff.js ADDED
@@ -0,0 +1,83 @@
1
+ /** Lines of context around each change. */
2
+ const context = 3;
3
+ function linesOf(text) {
4
+ const lines = text.split('\n');
5
+ if (lines.at(-1) === '')
6
+ lines.pop();
7
+ return lines;
8
+ }
9
+ /** The longest common subsequence of lines, as keep, remove and add steps. */
10
+ function opsOf(before, after) {
11
+ const width = after.length + 1;
12
+ const table = new Uint32Array((before.length + 1) * width);
13
+ for (let i = before.length - 1; i >= 0; i--) {
14
+ for (let j = after.length - 1; j >= 0; j--) {
15
+ table[i * width + j] =
16
+ before[i] === after[j]
17
+ ? (table[(i + 1) * width + j + 1] ?? 0) + 1
18
+ : Math.max(table[(i + 1) * width + j] ?? 0, table[i * width + j + 1] ?? 0);
19
+ }
20
+ }
21
+ const ops = [];
22
+ let i = 0;
23
+ let j = 0;
24
+ while (i < before.length || j < after.length) {
25
+ const removed = before[i];
26
+ const added = after[j];
27
+ if (removed !== undefined && added !== undefined && removed === added) {
28
+ ops.push({ kind: ' ', line: removed });
29
+ i++;
30
+ j++;
31
+ }
32
+ else if (
33
+ // A changed line shows its removal first, as unified diffs do.
34
+ removed !== undefined &&
35
+ (added === undefined ||
36
+ (table[(i + 1) * width + j] ?? 0) >= (table[i * width + j + 1] ?? 0))) {
37
+ ops.push({ kind: '-', line: removed });
38
+ i++;
39
+ }
40
+ else if (added !== undefined) {
41
+ ops.push({ kind: '+', line: added });
42
+ j++;
43
+ }
44
+ }
45
+ return ops;
46
+ }
47
+ /**
48
+ * A unified diff of one file, `before` undefined for a new file. Each hunk
49
+ * has three lines of context, and hunks that touch merge.
50
+ */
51
+ export function diff(path, before, after) {
52
+ const ops = opsOf(linesOf(before ?? ''), linesOf(after));
53
+ const out = [before === undefined ? '--- /dev/null' : `--- a/${path}`];
54
+ out.push(`+++ b/${path}`);
55
+ let index = 0;
56
+ while (index < ops.length) {
57
+ const first = ops.findIndex((op, at) => at >= index && op.kind !== ' ');
58
+ if (first === -1)
59
+ break;
60
+ // Extend the hunk while the next change is within twice the context.
61
+ let last = first;
62
+ for (let at = first; at < ops.length; at++) {
63
+ if (ops[at]?.kind !== ' ')
64
+ last = at;
65
+ else if (at - last > 2 * context)
66
+ break;
67
+ }
68
+ const start = Math.max(first - context, index);
69
+ const end = Math.min(last + context + 1, ops.length);
70
+ const lead = ops.slice(0, start);
71
+ const hunk = ops.slice(start, end);
72
+ const oldStart = lead.filter((op) => op.kind !== '+').length;
73
+ const newStart = lead.filter((op) => op.kind !== '-').length;
74
+ const oldCount = hunk.filter((op) => op.kind !== '+').length;
75
+ const newCount = hunk.filter((op) => op.kind !== '-').length;
76
+ out.push(`@@ -${oldCount === 0 ? oldStart : oldStart + 1},${oldCount} +${newCount === 0 ? newStart : newStart + 1},${newCount} @@`);
77
+ for (const op of hunk)
78
+ out.push(`${op.kind}${op.line}`);
79
+ index = end;
80
+ }
81
+ return `${out.join('\n')}\n`;
82
+ }
83
+ //# sourceMappingURL=diff.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diff.js","sourceRoot":"","sources":["../src/diff.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,MAAM,OAAO,GAAG,CAAC,CAAC;AAElB,SAAS,OAAO,CAAC,IAAY;IAC3B,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC/B,IAAI,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE;QAAE,KAAK,CAAC,GAAG,EAAE,CAAC;IACrC,OAAO,KAAK,CAAC;AACf,CAAC;AAID,8EAA8E;AAC9E,SAAS,KAAK,CAAC,MAAyB,EAAE,KAAwB;IAChE,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;IAC/B,MAAM,KAAK,GAAG,IAAI,WAAW,CAAC,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC;IAC3D,KAAK,IAAI,CAAC,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC5C,KAAK,IAAI,CAAC,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;YAC3C,KAAK,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC;gBAClB,MAAM,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,C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KAAK,CAC1H,CAAC;QACF,KAAK,MAAM,EAAE,IAAI,IAAI;YAAE,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC;QACxD,KAAK,GAAG,GAAG,CAAC;IACd,CAAC;IACD,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;AAC/B,CAAC"}
package/dist/edit.d.ts ADDED
@@ -0,0 +1,105 @@
1
+ import type * as TS from 'typescript';
2
+ import type { Names } from './names.js';
3
+ import type { TypeScript } from './typescript.js';
4
+ /** Text to insert at an offset of a file, in place of `remove` characters there. */
5
+ export type Insert = {
6
+ readonly offset: number;
7
+ readonly text: string;
8
+ readonly remove?: number;
9
+ };
10
+ /**
11
+ * Lines a command adds to a file, where they go in words, and the inserts
12
+ * that put them there. A refused file has no inserts.
13
+ */
14
+ export type Addition = {
15
+ readonly where: string;
16
+ readonly lines: string;
17
+ readonly inserts: readonly Insert[];
18
+ };
19
+ /** The additions to one file, or why its shape gives them no place. */
20
+ export type FileEdit = {
21
+ readonly path: string;
22
+ readonly before: string;
23
+ readonly additions: readonly Addition[];
24
+ readonly refused: string | undefined;
25
+ };
26
+ /**
27
+ * `text` with each insert applied. Inserts never overlap; two at one offset
28
+ * land in the order given.
29
+ */
30
+ export declare function applyInserts(text: string, inserts: readonly Insert[]): string;
31
+ export declare function parse(ts: TypeScript, path: string, text: string): TS.SourceFile;
32
+ /** How a file writes line breaks and one level of indent. */
33
+ export type Style = {
34
+ readonly newline: string;
35
+ readonly unit: string;
36
+ };
37
+ /**
38
+ * The file's line break, and its indent unit: a tab, or the fewest leading
39
+ * spaces on a code line. JSDoc's ` * ` lines do not count.
40
+ */
41
+ export declare function styleOf(text: string): Style;
42
+ /** The additions with their inserted text in the file's line breaks. */
43
+ export declare function inStyle(additions: readonly Addition[], { newline }: Style): {
44
+ inserts: {
45
+ text: string;
46
+ offset: number;
47
+ remove?: number;
48
+ }[];
49
+ where: string;
50
+ lines: string;
51
+ }[];
52
+ /** The whitespace that starts the line holding `position`. */
53
+ export declare function indentAt(source: TS.SourceFile, position: number): string;
54
+ export declare const lineOf: (source: TS.SourceFile, position: number) => number;
55
+ /** `position`, moved past the comments that end its line, so they stay where they are. */
56
+ export declare function pastComments(ts: TypeScript, text: string, position: number): number;
57
+ /** The end of the comma token at `position`, skipping trivia, if there is one. */
58
+ export declare function commaAfter(ts: TypeScript, text: string, position: number): number | undefined;
59
+ /** The local name the file imports `name` from `module` as. */
60
+ export declare function importedAs(ts: TypeScript, source: TS.SourceFile, name: string, module: string): string | undefined;
61
+ /** A relative specifier's distance up, then its path, compared as numbers where digits run. */
62
+ export declare function compareSpecifiers(a: string, b: string): number;
63
+ /**
64
+ * An import of `name` from the relative `specifier`, among the file's
65
+ * imports in Biome's order: farther paths first, then by path. `clause` is
66
+ * what the import binds, such as `{ Notes }` or `m0002`. A file that
67
+ * already imports or declares `name` is refused.
68
+ */
69
+ export declare function importAddition(ts: TypeScript, source: TS.SourceFile, file: string, name: string, clause: string, specifier: string): Addition;
70
+ /**
71
+ * The composition's edit: an import, and a `.collection()` call at the end
72
+ * of the one `framework()` chain, open to any signed-in caller. Its shape
73
+ * must be `export const app = framework(...).collection(...)...`; `app` is
74
+ * the export a test reads the contract from.
75
+ */
76
+ export declare function compositionEdit(ts: TypeScript, path: string, file: string, before: string, names: Names, specifier: string): FileEdit & {
77
+ readonly app: string | undefined;
78
+ };
79
+ /**
80
+ * The events catalog's edit: an import, and the collection's three events
81
+ * after the last collection's, in the one `EventCatalog()` literal.
82
+ */
83
+ export declare function eventsEdit(ts: TypeScript, path: string, file: string, before: string, names: Names, specifier: string): FileEdit;
84
+ /** The list's elements: the local name each binds, and the specifier of its default import. */
85
+ export type ListElement = {
86
+ readonly local: string;
87
+ readonly specifier: string;
88
+ };
89
+ /** The one exported array literal in a migrations index, with its elements. */
90
+ export type MigrationList = {
91
+ readonly literal: TS.ArrayLiteralExpression;
92
+ readonly elements: readonly ListElement[];
93
+ };
94
+ /**
95
+ * The migrations list: the one top-level `export const x = [...]`, each of
96
+ * whose elements is a migration's default import. A file with no such
97
+ * list, or two, gives the reason instead.
98
+ */
99
+ export declare function migrationList(ts: TypeScript, source: TS.SourceFile, file: string): MigrationList | string;
100
+ /**
101
+ * The migrations index's edit: a default import of the new migration, and
102
+ * its local name at the end of the list.
103
+ */
104
+ export declare function migrationsEdit(ts: TypeScript, path: string, file: string, before: string, list: MigrationList, local: string, specifier: string): FileEdit;
105
+ //# sourceMappingURL=edit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"edit.d.ts","sourceRoot":"","sources":["../src/edit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAGtC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,oFAAoF;AACpF,MAAM,MAAM,MAAM,GAAG;IACnB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,QAAQ,GAAG;IACrB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;CACrC,CAAC;AAEF,uEAAuE;AACvE,MAAM,MAAM,QAAQ,GAAG;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,SAAS,EAAE,SAAS,QAAQ,EAAE,CAAC;IACxC,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,S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