@foundrykit/history-plugin 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/activePlugins.d.ts +10 -0
- package/dist/activePlugins.js +27 -0
- package/dist/activePlugins.js.map +1 -0
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Config } from 'payload';
|
|
2
|
+
/**
|
|
3
|
+
* Records this plugin as active in `config.custom.foundrykit.activePlugins`, the list
|
|
4
|
+
* `@foundrykit/guides-plugin` sends to the guides hub so the site gets this plugin's guides.
|
|
5
|
+
* Only call it on the enabled path: installed-but-disabled doesn't count.
|
|
6
|
+
*
|
|
7
|
+
* Every FoundryKit Payload plugin carries its own copy of this file (it's too small for a package);
|
|
8
|
+
* keep them identical.
|
|
9
|
+
*/
|
|
10
|
+
export declare const recordActivePlugin: (config: Config, name: string) => Config;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Records this plugin as active in `config.custom.foundrykit.activePlugins`, the list
|
|
3
|
+
* `@foundrykit/guides-plugin` sends to the guides hub so the site gets this plugin's guides.
|
|
4
|
+
* Only call it on the enabled path: installed-but-disabled doesn't count.
|
|
5
|
+
*
|
|
6
|
+
* Every FoundryKit Payload plugin carries its own copy of this file (it's too small for a package);
|
|
7
|
+
* keep them identical.
|
|
8
|
+
*/ export const recordActivePlugin = (config, name)=>{
|
|
9
|
+
const foundrykit = config.custom?.foundrykit ?? {};
|
|
10
|
+
return {
|
|
11
|
+
...config,
|
|
12
|
+
custom: {
|
|
13
|
+
...config.custom,
|
|
14
|
+
foundrykit: {
|
|
15
|
+
...foundrykit,
|
|
16
|
+
activePlugins: [
|
|
17
|
+
...new Set([
|
|
18
|
+
...foundrykit.activePlugins ?? [],
|
|
19
|
+
name
|
|
20
|
+
])
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=activePlugins.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/activePlugins.ts"],"sourcesContent":["import type { Config } from 'payload';\n\n/**\n * Records this plugin as active in `config.custom.foundrykit.activePlugins`, the list\n * `@foundrykit/guides-plugin` sends to the guides hub so the site gets this plugin's guides.\n * Only call it on the enabled path: installed-but-disabled doesn't count.\n *\n * Every FoundryKit Payload plugin carries its own copy of this file (it's too small for a package);\n * keep them identical.\n */\nexport const recordActivePlugin = (config: Config, name: string): Config => {\n const foundrykit = (config.custom?.foundrykit ?? {}) as {\n activePlugins?: string[];\n };\n return {\n ...config,\n custom: {\n ...config.custom,\n foundrykit: {\n ...foundrykit,\n activePlugins: [\n ...new Set([...(foundrykit.activePlugins ?? []), name]),\n ],\n },\n },\n };\n};\n"],"names":["recordActivePlugin","config","name","foundrykit","custom","activePlugins","Set"],"mappings":"AAEA;;;;;;;CAOC,GACD,OAAO,MAAMA,qBAAqB,CAACC,QAAgBC;IACjD,MAAMC,aAAcF,OAAOG,MAAM,EAAED,cAAc,CAAC;IAGlD,OAAO;QACL,GAAGF,MAAM;QACTG,QAAQ;YACN,GAAGH,OAAOG,MAAM;YAChBD,YAAY;gBACV,GAAGA,UAAU;gBACbE,eAAe;uBACV,IAAIC,IAAI;2BAAKH,WAAWE,aAAa,IAAI,EAAE;wBAAGH;qBAAK;iBACvD;YACH;QACF;IACF;AACF,EAAE"}
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { recordActivePlugin } from './activePlugins.js';
|
|
1
2
|
import { AUTHOR_FIELD } from './timeline.js';
|
|
2
3
|
export { AUTHOR_FIELD } from './timeline.js';
|
|
3
4
|
const TIMELINE = '@foundrykit/history-plugin/rsc#TimelineView';
|
|
@@ -128,11 +129,11 @@ export const historyPlugin = (options = {})=>(config)=>{
|
|
|
128
129
|
const globals = config.globals ?? [];
|
|
129
130
|
const trackedCollections = checkTracked('collection', options.collections, collections.filter((c)=>c.versions).map((c)=>c.slug));
|
|
130
131
|
const trackedGlobals = checkTracked('global', options.globals, globals.filter((g)=>g.versions).map((g)=>g.slug));
|
|
131
|
-
return {
|
|
132
|
+
return recordActivePlugin({
|
|
132
133
|
...config,
|
|
133
134
|
collections: collections.map((c)=>trackedCollections.has(c.slug) ? trackCollection(c, usersSlug) : c),
|
|
134
135
|
globals: globals.map((g)=>trackedGlobals.has(g.slug) ? trackGlobal(g, usersSlug) : g)
|
|
135
|
-
};
|
|
136
|
+
}, '@foundrykit/history-plugin');
|
|
136
137
|
};
|
|
137
138
|
|
|
138
139
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type {\n Access,\n AccessArgs,\n CollectionConfig,\n CollectionSlug,\n Config,\n Field,\n GlobalConfig,\n Payload,\n Where,\n} from 'payload';\n\nimport { AUTHOR_FIELD } from './timeline.js';\n\nexport { AUTHOR_FIELD } from './timeline.js';\n\nexport type HistoryPluginConfig = {\n /** Collections to track. Defaults to every collection with versions. */\n collections?: string[];\n /** Globals to track. Defaults to every global with versions. */\n globals?: string[];\n};\n\nconst TIMELINE = '@foundrykit/history-plugin/rsc#TimelineView';\nconst VERSION_AUTHOR = '@foundrykit/history-plugin/rsc#VersionAuthor';\n\ntype Views = NonNullable<\n NonNullable<CollectionConfig['admin']>['components']\n>['views'];\n\n/**\n * Uses the timeline as the versions tab, unless the site already replaced it, and names the\n * author on a single version. Actions alone don't replace Payload's version view.\n */\nconst withTimeline = (views: Views): Views => ({\n ...views,\n edit: {\n ...views?.edit,\n version: {\n ...views?.edit?.version,\n actions: [...(views?.edit?.version?.actions ?? []), VERSION_AUTHOR],\n },\n versions: views?.edit?.versions ?? { Component: TIMELINE },\n } as NonNullable<Views>['edit'],\n});\n\nconst authorField = (usersSlug: string): Field => ({\n name: AUTHOR_FIELD,\n type: 'relationship',\n // Staff only. A site's own server-side reads (Local API, overrideAccess) skip field access, so\n // maxDepth keeps it an id there: populated, it would put a staff user's email into any page\n // data that reaches the browser.\n access: { read: ({ req }) => Boolean(req.user) },\n admin: { position: 'sidebar', readOnly: true },\n hooks: {\n // Always the person saving, whatever was sent. Saves with no admin user (scripts, the\n // public site) record no author.\n beforeChange: [\n ({ req }) => (req.user?.collection === usersSlug ? req.user.id : null),\n ],\n },\n label: 'Last edited by',\n maxDepth: 0,\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion -- a union once a site generates types\n relationTo: usersSlug as CollectionSlug,\n});\n\n/**\n * Version history needs a login and the entity's own read access. Payload's default only needs\n * a login, so a site gating reads (for example with the permissions plugin) would leak history.\n * The entity's read access is looked up at request time, so plugin order doesn't matter.\n */\n/** Rewrites a read query on documents into the same query on their versions. */\nconst toVersionsWhere = (where: Where): Where =>\n Object.fromEntries(\n Object.entries(where).map(([key, value]) =>\n key === 'and' || key === 'or'\n ? [key, (value as Where[]).map(toVersionsWhere)]\n : [key === 'id' ? 'parent' : `version.${key}`, value]\n )\n );\n\nconst readVersions =\n (getRead: (payload: Payload) => Access | undefined): Access =>\n async (args: AccessArgs) => {\n if (!args.req.user) {\n return false;\n }\n const read = getRead(args.req.payload);\n const result = read ? await read(args) : true;\n // A query limits which documents can be read, so it limits which versions can be read too.\n return typeof result === 'boolean' ? result : toVersionsWhere(result);\n };\n\nconst checkTracked = (\n kind: string,\n wanted: string[] | undefined,\n versioned: string[]\n) => {\n for (const slug of wanted ?? []) {\n if (!versioned.includes(slug)) {\n throw new Error(\n `history: ${kind} \"${slug}\" doesn't exist or has versions turned off`\n );\n }\n }\n return new Set(wanted ?? versioned);\n};\n\nconst checkNoAuthorField = (slug: string, fields: Field[]) => {\n if (fields.some(field => 'name' in field && field.name === AUTHOR_FIELD)) {\n throw new Error(`history: \"${slug}\" already has a \"${AUTHOR_FIELD}\" field`);\n }\n};\n\nconst trackCollection = (\n collection: CollectionConfig,\n usersSlug: string\n): CollectionConfig => {\n checkNoAuthorField(collection.slug, collection.fields);\n return {\n ...collection,\n access: {\n ...collection.access,\n readVersions:\n collection.access?.readVersions ??\n readVersions(\n payload =>\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion -- a union once a site generates types\n payload.collections[collection.slug as CollectionSlug]?.config\n .access.read\n ),\n },\n admin: {\n ...collection.admin,\n components: {\n ...collection.admin?.components,\n views: withTimeline(collection.admin?.components?.views),\n },\n },\n fields: [...collection.fields, authorField(usersSlug)],\n };\n};\n\nconst trackGlobal = (global: GlobalConfig, usersSlug: string): GlobalConfig => {\n checkNoAuthorField(global.slug, global.fields);\n return {\n ...global,\n access: {\n ...global.access,\n readVersions:\n global.access?.readVersions ??\n readVersions(\n payload =>\n payload.config.globals.find(g => g.slug === global.slug)?.access\n .read\n ),\n },\n admin: {\n ...global.admin,\n components: {\n ...global.admin?.components,\n views: withTimeline(global.admin?.components?.views),\n },\n },\n fields: [...global.fields, authorField(usersSlug)],\n };\n};\n\nexport const historyPlugin =\n (options: HistoryPluginConfig = {}) =>\n (config: Config): Config => {\n const usersSlug = config.admin?.user ?? 'users';\n const collections = config.collections ?? [];\n const globals = config.globals ?? [];\n\n const trackedCollections = checkTracked(\n 'collection',\n options.collections,\n collections.filter(c => c.versions).map(c => c.slug)\n );\n const trackedGlobals = checkTracked(\n 'global',\n options.globals,\n globals.filter(g => g.versions).map(g => g.slug)\n );\n\n return {\n ...config,\n collections: collections.map(c =>\n trackedCollections.has(c.slug) ? trackCollection(c, usersSlug) : c\n ),\n globals: globals.map(g =>\n trackedGlobals.has(g.slug) ? trackGlobal(g, usersSlug) : g\n ),\n };\n };\n"],"names":["AUTHOR_FIELD","TIMELINE","VERSION_AUTHOR","withTimeline","views","edit","version","actions","versions","Component","authorField","usersSlug","name","type","access","read","req","Boolean","user","admin","position","readOnly","hooks","beforeChange","collection","id","label","maxDepth","relationTo","toVersionsWhere","where","Object","fromEntries","entries","map","key","value","readVersions","getRead","args","payload","result","checkTracked","kind","wanted","versioned","slug","includes","Error","Set","checkNoAuthorField","fields","some","field","trackCollection","collections","config","components","trackGlobal","global","globals","find","g","historyPlugin","options","trackedCollections","filter","c","trackedGlobals","has"],"mappings":"AAYA,SAASA,YAAY,QAAQ,gBAAgB;AAE7C,SAASA,YAAY,QAAQ,gBAAgB;AAS7C,MAAMC,WAAW;AACjB,MAAMC,iBAAiB;AAMvB;;;CAGC,GACD,MAAMC,eAAe,CAACC,QAAyB,CAAA;QAC7C,GAAGA,KAAK;QACRC,MAAM;YACJ,GAAGD,OAAOC,IAAI;YACdC,SAAS;gBACP,GAAGF,OAAOC,MAAMC,OAAO;gBACvBC,SAAS;uBAAKH,OAAOC,MAAMC,SAASC,WAAW,EAAE;oBAAGL;iBAAe;YACrE;YACAM,UAAUJ,OAAOC,MAAMG,YAAY;gBAAEC,WAAWR;YAAS;QAC3D;IACF,CAAA;AAEA,MAAMS,cAAc,CAACC,YAA8B,CAAA;QACjDC,MAAMZ;QACNa,MAAM;QACN,+FAA+F;QAC/F,4FAA4F;QAC5F,iCAAiC;QACjCC,QAAQ;YAAEC,MAAM,CAAC,EAAEC,GAAG,EAAE,GAAKC,QAAQD,IAAIE,IAAI;QAAE;QAC/CC,OAAO;YAAEC,UAAU;YAAWC,UAAU;QAAK;QAC7CC,OAAO;YACL,sFAAsF;YACtF,iCAAiC;YACjCC,cAAc;gBACZ,CAAC,EAAEP,GAAG,EAAE,GAAMA,IAAIE,IAAI,EAAEM,eAAeb,YAAYK,IAAIE,IAAI,CAACO,EAAE,GAAG;aAClE;QACH;QACAC,OAAO;QACPC,UAAU;QACV,mHAAmH;QACnHC,YAAYjB;IACd,CAAA;AAEA;;;;CAIC,GACD,8EAA8E,GAC9E,MAAMkB,kBAAkB,CAACC,QACvBC,OAAOC,WAAW,CAChBD,OAAOE,OAAO,CAACH,OAAOI,GAAG,CAAC,CAAC,CAACC,KAAKC,M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,QAAQM,MAAM,CAACJ,CAAAA,IAAKA,EAAEtD,QAAQ,EAAE0B,GAAG,CAAC4B,CAAAA,IAAKA,EAAEhB,IAAI;QAGjD,OAAO;YACL,GAAGU,MAAM;YACTD,aAAaA,YAAYrB,GAAG,CAACiC,CAAAA,IAC3BF,mBAAmBI,GAAG,CAACF,EAAErB,IAAI,IAAIQ,gBAAgBa,GAAGxD,aAAawD;YAEnEP,SAASA,QAAQ1B,GAAG,CAAC4B,CAAAA,IACnBM,eAAeC,GAAG,CAACP,EAAEhB,IAAI,IAAIY,YAAYI,GAAGnD,aAAamD;QAE7D;IACF,EAAE"}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type {\n Access,\n AccessArgs,\n CollectionConfig,\n CollectionSlug,\n Config,\n Field,\n GlobalConfig,\n Payload,\n Where,\n} from 'payload';\nimport { recordActivePlugin } from './activePlugins.js';\nimport { AUTHOR_FIELD } from './timeline.js';\n\nexport { AUTHOR_FIELD } from './timeline.js';\n\nexport type HistoryPluginConfig = {\n /** Collections to track. Defaults to every collection with versions. */\n collections?: string[];\n /** Globals to track. Defaults to every global with versions. */\n globals?: string[];\n};\n\nconst TIMELINE = '@foundrykit/history-plugin/rsc#TimelineView';\nconst VERSION_AUTHOR = '@foundrykit/history-plugin/rsc#VersionAuthor';\n\ntype Views = NonNullable<\n NonNullable<CollectionConfig['admin']>['components']\n>['views'];\n\n/**\n * Uses the timeline as the versions tab, unless the site already replaced it, and names the\n * author on a single version. Actions alone don't replace Payload's version view.\n */\nconst withTimeline = (views: Views): Views => ({\n ...views,\n edit: {\n ...views?.edit,\n version: {\n ...views?.edit?.version,\n actions: [...(views?.edit?.version?.actions ?? []), VERSION_AUTHOR],\n },\n versions: views?.edit?.versions ?? { Component: TIMELINE },\n } as NonNullable<Views>['edit'],\n});\n\nconst authorField = (usersSlug: string): Field => ({\n name: AUTHOR_FIELD,\n type: 'relationship',\n // Staff only. A site's own server-side reads (Local API, overrideAccess) skip field access, so\n // maxDepth keeps it an id there: populated, it would put a staff user's email into any page\n // data that reaches the browser.\n access: { read: ({ req }) => Boolean(req.user) },\n admin: { position: 'sidebar', readOnly: true },\n hooks: {\n // Always the person saving, whatever was sent. Saves with no admin user (scripts, the\n // public site) record no author.\n beforeChange: [\n ({ req }) => (req.user?.collection === usersSlug ? req.user.id : null),\n ],\n },\n label: 'Last edited by',\n maxDepth: 0,\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion -- a union once a site generates types\n relationTo: usersSlug as CollectionSlug,\n});\n\n/**\n * Version history needs a login and the entity's own read access. Payload's default only needs\n * a login, so a site gating reads (for example with the permissions plugin) would leak history.\n * The entity's read access is looked up at request time, so plugin order doesn't matter.\n */\n/** Rewrites a read query on documents into the same query on their versions. */\nconst toVersionsWhere = (where: Where): Where =>\n Object.fromEntries(\n Object.entries(where).map(([key, value]) =>\n key === 'and' || key === 'or'\n ? [key, (value as Where[]).map(toVersionsWhere)]\n : [key === 'id' ? 'parent' : `version.${key}`, value]\n )\n );\n\nconst readVersions =\n (getRead: (payload: Payload) => Access | undefined): Access =>\n async (args: AccessArgs) => {\n if (!args.req.user) {\n return false;\n }\n const read = getRead(args.req.payload);\n const result = read ? await read(args) : true;\n // A query limits which documents can be read, so it limits which versions can be read too.\n return typeof result === 'boolean' ? result : toVersionsWhere(result);\n };\n\nconst checkTracked = (\n kind: string,\n wanted: string[] | undefined,\n versioned: string[]\n) => {\n for (const slug of wanted ?? []) {\n if (!versioned.includes(slug)) {\n throw new Error(\n `history: ${kind} \"${slug}\" doesn't exist or has versions turned off`\n );\n }\n }\n return new Set(wanted ?? versioned);\n};\n\nconst checkNoAuthorField = (slug: string, fields: Field[]) => {\n if (fields.some(field => 'name' in field && field.name === AUTHOR_FIELD)) {\n throw new Error(`history: \"${slug}\" already has a \"${AUTHOR_FIELD}\" field`);\n }\n};\n\nconst trackCollection = (\n collection: CollectionConfig,\n usersSlug: string\n): CollectionConfig => {\n checkNoAuthorField(collection.slug, collection.fields);\n return {\n ...collection,\n access: {\n ...collection.access,\n readVersions:\n collection.access?.readVersions ??\n readVersions(\n payload =>\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion -- a union once a site generates types\n payload.collections[collection.slug as CollectionSlug]?.config\n .access.read\n ),\n },\n admin: {\n ...collection.admin,\n components: {\n ...collection.admin?.components,\n views: withTimeline(collection.admin?.components?.views),\n },\n },\n fields: [...collection.fields, authorField(usersSlug)],\n };\n};\n\nconst trackGlobal = (global: GlobalConfig, usersSlug: string): GlobalConfig => {\n checkNoAuthorField(global.slug, global.fields);\n return {\n ...global,\n access: {\n ...global.access,\n readVersions:\n global.access?.readVersions ??\n readVersions(\n payload =>\n payload.config.globals.find(g => g.slug === global.slug)?.access\n .read\n ),\n },\n admin: {\n ...global.admin,\n components: {\n ...global.admin?.components,\n views: withTimeline(global.admin?.components?.views),\n },\n },\n fields: [...global.fields, authorField(usersSlug)],\n };\n};\n\nexport const historyPlugin =\n (options: HistoryPluginConfig = {}) =>\n (config: Config): Config => {\n const usersSlug = config.admin?.user ?? 'users';\n const collections = config.collections ?? [];\n const globals = config.globals ?? [];\n\n const trackedCollections = checkTracked(\n 'collection',\n options.collections,\n collections.filter(c => c.versions).map(c => c.slug)\n );\n const trackedGlobals = checkTracked(\n 'global',\n options.globals,\n globals.filter(g => g.versions).map(g => g.slug)\n );\n\n return recordActivePlugin(\n {\n ...config,\n collections: collections.map(c =>\n trackedCollections.has(c.slug) ? trackCollection(c, usersSlug) : c\n ),\n globals: globals.map(g =>\n trackedGlobals.has(g.slug) ? trackGlobal(g, usersSlug) : g\n ),\n },\n '@foundrykit/history-plugin'\n );\n };\n"],"names":["recordActivePlugin","AUTHOR_FIELD","TIMELINE","VERSION_AUTHOR","withTimeline","views","edit","version","actions","versions","Component","authorField","usersSlug","name","type","access","read","req","Boolean","user","admin","position","readOnly","hooks","beforeChange","collection","id","label","maxDepth","relationTo","toVersionsWhere","where","Object","fromEntries","entries","map","key","value","readVersions","getRead","args","payload","result","checkTracked","kind","wanted","versioned","slug","includes","Error","Set","checkNoAuthorField","fields","some","field","trackCollection","collections","config","components","trackGlobal","global","globals","find","g","historyPlugin","options","trackedCollections","filter","c","trackedGlobals","has"],"mappings":"AAWA,SAASA,kBAAkB,QAAQ,qBAAqB;AACxD,SAASC,YAAY,QAAQ,gBAAgB;AAE7C,SAASA,YAAY,QAAQ,gBAAgB;AAS7C,MAAMC,WAAW;AACjB,MAAMC,iBAAiB;AAMvB;;;CAGC,GACD,MAAMC,eAAe,CAACC,QAAyB,CAAA;QAC7C,GAAGA,KAAK;QACRC,MAAM;YACJ,GAAGD,OAAOC,IAAI;YACdC,SAAS;gBACP,GAAGF,OAAOC,MAAMC,OAAO;gBACvBC,SAAS;uBAAKH,OAAOC,MAAMC,SAASC,WAAW,EAAE;oBAAGL;iBAAe;YACrE;YACAM,UAAUJ,OAAOC,MAAMG,YAAY;gBAAEC,WAAWR;YAAS;QAC3D;IACF,CAAA;AAEA,MAAMS,cAAc,CAACC,YAA8B,CAAA;QACjDC,MAAMZ;QACNa,MAAM;QACN,+FAA+F;QAC/F,4FAA4F;QAC5F,iCAAiC;QACjCC,QAAQ;YAAEC,MAAM,CAAC,EAAEC,GAAG,EAAE,GAAKC,QAAQD,IAAIE,IAAI;QAAE;QAC/CC,OAAO;YAAEC,UAAU;YAAWC,UAAU;QAAK;QAC7CC,OAAO;YACL,sFAAsF;YACtF,iCAAiC;YACjCC,cAAc;gBACZ,CAAC,EAAEP,GAAG,EAAE,GAAMA,IAAIE,IAAI,EAAEM,eAAeb,YAAYK,IAAIE,IAAI,CAACO,EAAE,GAAG;aAClE;QACH;QACAC,OAAO;QACPC,UAAU;QACV,mHAAmH;QACnHC,YAAYjB;IACd,CAAA;AAEA;;;;CAIC,GACD,8EAA8E,GAC9E,MAAMkB,kBAAkB,CAACC,QACvBC,OAAOC,WAAW,CAChBD,OAAOE,OAAO,CAACH,OAAOI,GAAG,CAAC,CAAC,CAACC,KAAKC,MAAM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