@aglyn/aglyn 1.18.0 → 1.20.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 (47) hide show
  1. package/package.json +11 -11
  2. package/src/lib/app-utils/analytics-events.d.ts +44 -0
  3. package/src/lib/app-utils/analytics-events.js +226 -21
  4. package/src/lib/app-utils/analytics-events.js.map +1 -1
  5. package/src/lib/app-utils/analytics-link-clicks.js +3 -4
  6. package/src/lib/app-utils/analytics-link-clicks.js.map +1 -1
  7. package/src/lib/app-utils/compose-reusable-components.js +7 -3
  8. package/src/lib/app-utils/compose-reusable-components.js.map +1 -1
  9. package/src/lib/app-utils/crm.d.ts +80 -1
  10. package/src/lib/app-utils/crm.js +136 -5
  11. package/src/lib/app-utils/crm.js.map +1 -1
  12. package/src/lib/app-utils/docs-help-sections.generated.js +1 -1
  13. package/src/lib/app-utils/docs-help-sections.generated.js.map +1 -1
  14. package/src/lib/app-utils/docs-help.generated.d.ts +2 -2
  15. package/src/lib/app-utils/docs-help.generated.js +6 -1
  16. package/src/lib/app-utils/docs-help.generated.js.map +1 -1
  17. package/src/lib/app-utils/docs-index.generated.js +44 -16
  18. package/src/lib/app-utils/docs-index.generated.js.map +1 -1
  19. package/src/lib/app-utils/element-motion.js +6 -5
  20. package/src/lib/app-utils/element-motion.js.map +1 -1
  21. package/src/lib/app-utils/expand-repeatables.d.ts +23 -3
  22. package/src/lib/app-utils/expand-repeatables.js +61 -7
  23. package/src/lib/app-utils/expand-repeatables.js.map +1 -1
  24. package/src/lib/app-utils/plugin-connection-editor.d.ts +22 -0
  25. package/src/lib/app-utils/plugin-connection-editor.js.map +1 -1
  26. package/src/lib/app-utils/plugin-connection-repeat.d.ts +82 -0
  27. package/src/lib/app-utils/plugin-connection-repeat.js +162 -0
  28. package/src/lib/app-utils/plugin-connection-repeat.js.map +1 -0
  29. package/src/lib/app-utils/repeat-sources.d.ts +33 -1
  30. package/src/lib/app-utils/repeat-sources.js +27 -3
  31. package/src/lib/app-utils/repeat-sources.js.map +1 -1
  32. package/src/lib/app-utils/seo-page-facts.js +3 -6
  33. package/src/lib/app-utils/seo-page-facts.js.map +1 -1
  34. package/src/lib/plugin-manager/feature-plugins.d.ts +8 -0
  35. package/src/lib/plugin-manager/feature-plugins.js.map +1 -1
  36. package/src/lib/plugin-manager/first-party-plugins.generated.d.ts +6 -0
  37. package/src/lib/plugin-manager/first-party-plugins.generated.js +8 -0
  38. package/src/lib/plugin-manager/first-party-plugins.generated.js.map +1 -1
  39. package/src/lib/plugin-manager/plugin-scope-sharing.d.ts +22 -0
  40. package/src/lib/plugin-manager/plugin-scope-sharing.js +21 -1
  41. package/src/lib/plugin-manager/plugin-scope-sharing.js.map +1 -1
  42. package/src/lib/plugin-manager/plugin-site-exclusions.d.ts +107 -0
  43. package/src/lib/plugin-manager/plugin-site-exclusions.js +169 -0
  44. package/src/lib/plugin-manager/plugin-site-exclusions.js.map +1 -0
  45. package/src/lib/plugin-manager/repeat-rows.d.ts +20 -2
  46. package/src/lib/plugin-manager/repeat-rows.js +42 -16
  47. package/src/lib/plugin-manager/repeat-rows.js.map +1 -1
@@ -50,3 +50,25 @@ export declare function registerPluginScopeSharingPatch(collections: readonly st
50
50
  export declare function scopeSharingPatchFor(collection: string): ScopeSharingPatch | null;
51
51
  /** Test seam: forget every patch. */
52
52
  export declare function resetScopeSharingPatchesForTests(): void;
53
+ /**
54
+ * What a plugin keeps level itself after a workspace's sites change, for
55
+ * sharing it stores somewhere other than a document's own marker: the CRM's
56
+ * grants shared with all sites except some, which sit inside a record's
57
+ * `sharing` map. Called after the sweep, with the time it may spend inline;
58
+ * work left past it is the plugin's to finish. It must never throw.
59
+ */
60
+ export type ScopeSharingSiteChangeHook = (input: {
61
+ orgId: string;
62
+ reason: 'site-added' | 'site-removed' | 'drift-repair';
63
+ hostId?: string;
64
+ budgetMs: number;
65
+ }) => Promise<void>;
66
+ /** Registers a plugin's {@link ScopeSharingSiteChangeHook}. One per plugin; again replaces it. */
67
+ export declare function registerPluginScopeSharingSiteChange(hook: ScopeSharingSiteChangeHook, options?: {
68
+ pluginId?: string;
69
+ }): void;
70
+ /** Every registered site-change hook, by plugin. */
71
+ export declare function listScopeSharingSiteChangeHooks(): Array<{
72
+ pluginId: string;
73
+ hook: ScopeSharingSiteChangeHook;
74
+ }>;
@@ -1,5 +1,5 @@
1
1
  import { _ as _extends } from "@swc/helpers/_/_extends";
2
- var _globalScope_PATCHES_KEY;
2
+ var _globalScope_PATCHES_KEY, _globalHooks_SITE_CHANGE_KEY;
3
3
  /**
4
4
  * @license
5
5
  * Copyright 2026 Aglyn LLC
@@ -80,6 +80,26 @@ const patches = (_globalScope_PATCHES_KEY = globalScope[PATCHES_KEY]) != null ?
80
80
  }
81
81
  /** Test seam: forget every patch. */ export function resetScopeSharingPatchesForTests() {
82
82
  patches.clear();
83
+ siteChangeHooks.clear();
84
+ }
85
+ const SITE_CHANGE_KEY = Symbol.for('@aglyn/aglyn:plugin-scope-sharing-site-change');
86
+ const globalHooks = globalThis;
87
+ const siteChangeHooks = (_globalHooks_SITE_CHANGE_KEY = globalHooks[SITE_CHANGE_KEY]) != null ? _globalHooks_SITE_CHANGE_KEY : globalHooks[SITE_CHANGE_KEY] = new Map();
88
+ /** Registers a plugin's {@link ScopeSharingSiteChangeHook}. One per plugin; again replaces it. */ export function registerPluginScopeSharingSiteChange(hook, options) {
89
+ var _ref, _getRegisteringPluginId;
90
+ const pluginId = ((_ref = (_getRegisteringPluginId = getRegisteringPluginId()) != null ? _getRegisteringPluginId : options == null ? void 0 : options.pluginId) != null ? _ref : '').trim();
91
+ if (!pluginId) {
92
+ throw new Error('a scope-sharing site-change hook was registered with no owner: pass { pluginId } ' + 'when registering outside a plugin register fn');
93
+ }
94
+ siteChangeHooks.set(pluginId, hook);
95
+ }
96
+ /** Every registered site-change hook, by plugin. */ export function listScopeSharingSiteChangeHooks() {
97
+ return [
98
+ ...siteChangeHooks.entries()
99
+ ].map(([pluginId, hook])=>({
100
+ pluginId,
101
+ hook
102
+ }));
83
103
  }
84
104
 
85
105
  //# sourceMappingURL=plugin-scope-sharing.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../libs/aglyn/src/lib/plugin-manager/plugin-scope-sharing.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * WHICH COLLECTIONS HOLD DOCUMENTS SHARED WITH \"ALL SITES EXCEPT…\" (AGL-4047).\n *\n * Such a document names its included sites in `visibleTo`, so that list has\n * to change when a site joins or leaves the workspace. One sweep does that for\n * every collection (`scope-sharing-sweep.ts`), and it can only walk what it\n * has been told about, so a plugin declares its collections in the\n * `scopeSharingCollections` block of `plugins.config.json`, compiled like its\n * other storage. Media belongs to the platform and is listed here.\n *\n * A collection whose documents store fields derived from `visibleTo` declares\n * `patch: true` and registers the function that recomputes them. The sweep\n * refuses to write such a collection while the function is missing, because a\n * `visibleTo` written without them leaves a document its list cannot find.\n */\n\nimport { getRegisteringPluginId } from '../app-utils/registering-plugin'\nimport { PLUGIN_SCOPE_SHARING_COLLECTIONS_DECLARED } from './plugin-scope-sharing.generated'\n\n/** One collection under `orgs/{orgId}` whose documents can be all-except. */\nexport interface ScopeSharingCollection {\n /** The subcollection, spelled as Firestore holds it. */\n name: string\n /** Stored fields follow `visibleTo`: a patch function is registered. */\n patch?: boolean\n /** The most sites one document may reach; past it the list stops widening. */\n maxIncluded?: number\n /** Fields naming sites that stay included though they are excluded. */\n keepSiteFields?: string[]\n}\n\n/** A declaration with its owner; `core` for what the platform holds itself. */\nexport type ResolvedScopeSharingCollection = ScopeSharingCollection & {\n pluginId: string\n}\n\n/** The platform's own: media belongs to no plugin. */\nconst CORE_SCOPE_SHARING_COLLECTIONS: readonly ResolvedScopeSharingCollection[] = [\n { pluginId: 'core', name: 'media' },\n { pluginId: 'core', name: 'mediaFolders' },\n]\n\n/**\n * Every collection the sweep walks, in a stable order: a sweep's cursor names\n * a position in this list, and resuming relies on the ones before it being done.\n */\nexport function listScopeSharingCollections(): ResolvedScopeSharingCollection[] {\n return [\n ...CORE_SCOPE_SHARING_COLLECTIONS,\n ...PLUGIN_SCOPE_SHARING_COLLECTIONS_DECLARED,\n ].map((row) => ({ ...row }))\n}\n\n/**\n * Recomputes the fields a document derives from its scope: `next` is the whole\n * document as it will be stored, and the answer is merged into the write.\n */\nexport type ScopeSharingPatch = (\n collection: string,\n next: Record<string, unknown>,\n) => Promise<Record<string, unknown>> | Record<string, unknown>\n\n/**\n * One map per process, on `globalThis`, for the reason `plugin-site-resources`\n * gives: the declarations register from `instrumentation.ts`, which Next\n * compiles apart from the route that runs the sweep.\n */\nconst PATCHES_KEY = Symbol.for('@aglyn/aglyn:plugin-scope-sharing-patches')\n\nconst globalScope = globalThis as typeof globalThis & {\n [PATCHES_KEY]?: Map<string, ScopeSharingPatch>\n}\n\nconst patches: Map<string, ScopeSharingPatch> =\n globalScope[PATCHES_KEY] ?? (globalScope[PATCHES_KEY] = new Map())\n\n/**\n * Registers the patch for collections a plugin declared with `patch: true`.\n * Refuses a collection another plugin declared, or one declared without it.\n */\nexport function registerPluginScopeSharingPatch(\n collections: readonly string[],\n patch: ScopeSharingPatch,\n options?: { pluginId?: string },\n): void {\n const pluginId = (getRegisteringPluginId() ?? options?.pluginId ?? '').trim()\n if (!pluginId) {\n throw new Error(\n 'a scope-sharing patch was registered with no owner: pass { pluginId } ' +\n 'when registering outside a plugin register fn',\n )\n }\n for (const name of collections) {\n const declared = PLUGIN_SCOPE_SHARING_COLLECTIONS_DECLARED.find((row) => row.name === name)\n if (declared?.pluginId !== pluginId || !declared.patch) {\n throw new Error(`${pluginId} did not declare ${name} with patch: true in scopeSharingCollections`)\n }\n }\n for (const name of collections) patches.set(name, patch)\n}\n\n/** The patch registered for a collection, or `null`. */\nexport function scopeSharingPatchFor(collection: string): ScopeSharingPatch | null {\n return patches.get(collection) ?? null\n}\n\n/** Test seam: forget every patch. */\nexport function resetScopeSharingPatchesForTests(): void {\n patches.clear()\n}\n"],"names":["globalScope","getRegisteringPluginId","PLUGIN_SCOPE_SHARING_COLLECTIONS_DECLARED","CORE_SCOPE_SHARING_COLLECTIONS","pluginId","name","listScopeSharingCollections","map","row","PATCHES_KEY","Symbol","for","globalThis","patches","Map","registerPluginScopeSharingPatch","collections","patch","options","trim","Error","declared","find","set","scopeSharingPatchFor","collection","get","resetScopeSharingPatchesForTests","clear"],"mappings":";IA2FEA;AA3FF;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;CAcC,GAED,SAASC,sBAAsB,QAAQ,qCAAiC;AACxE,SAASC,yCAAyC,QAAQ,sCAAkC;AAmB5F,oDAAoD,GACpD,MAAMC,iCAA4E;IAChF;QAAEC,UAAU;QAAQC,MAAM;IAAQ;IAClC;QAAED,UAAU;QAAQC,MAAM;IAAe;CAC1C;AAED;;;CAGC,GACD,OAAO,SAASC;IACd,OAAO;WACFH;WACAD;KACJ,CAACK,GAAG,CAAC,CAACC,MAAS,aAAKA;AACvB;AAWA;;;;CAIC,GACD,MAAMC,cAAcC,OAAOC,GAAG,CAAC;AAE/B,MAAMX,cAAcY;AAIpB,MAAMC,WACJb,2BAAAA,WAAW,CAACS,YAAY,YAAxBT,2BAA6BA,WAAW,CAACS,YAAY,GAAG,IAAIK;AAE9D;;;CAGC,GACD,OAAO,SAASC,gCACdC,WAA8B,EAC9BC,KAAwB,EACxBC,OAA+B;QAEbjB,MAAAA;IAAlB,MAAMG,WAAW,EAACH,QAAAA,0BAAAA,oCAAAA,0BAA4BiB,2BAAAA,QAASd,QAAQ,YAA7CH,OAAiD,IAAIkB,IAAI;IAC3E,IAAI,CAACf,UAAU;QACb,MAAM,IAAIgB,MACR,2EACE;IAEN;IACA,KAAK,MAAMf,QAAQW,YAAa;QAC9B,MAAMK,WAAWnB,0CAA0CoB,IAAI,CAAC,CAACd,MAAQA,IAAIH,IAAI,KAAKA;QACtF,IAAIgB,CAAAA,4BAAAA,SAAUjB,QAAQ,MAAKA,YAAY,CAACiB,SAASJ,KAAK,EAAE;YACtD,MAAM,IAAIG,MAAM,GAAGhB,SAAS,iBAAiB,EAAEC,KAAK,4CAA4C,CAAC;QACnG;IACF;IACA,KAAK,MAAMA,QAAQW,YAAaH,QAAQU,GAAG,CAAClB,MAAMY;AACpD;AAEA,sDAAsD,GACtD,OAAO,SAASO,qBAAqBC,UAAkB;QAC9CZ;IAAP,QAAOA,eAAAA,QAAQa,GAAG,CAACD,uBAAZZ,eAA2B;AACpC;AAEA,mCAAmC,GACnC,OAAO,SAASc;IACdd,QAAQe,KAAK;AACf"}
1
+ {"version":3,"sources":["../../../../../../libs/aglyn/src/lib/plugin-manager/plugin-scope-sharing.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * WHICH COLLECTIONS HOLD DOCUMENTS SHARED WITH \"ALL SITES EXCEPT…\" (AGL-4047).\n *\n * Such a document names its included sites in `visibleTo`, so that list has\n * to change when a site joins or leaves the workspace. One sweep does that for\n * every collection (`scope-sharing-sweep.ts`), and it can only walk what it\n * has been told about, so a plugin declares its collections in the\n * `scopeSharingCollections` block of `plugins.config.json`, compiled like its\n * other storage. Media belongs to the platform and is listed here.\n *\n * A collection whose documents store fields derived from `visibleTo` declares\n * `patch: true` and registers the function that recomputes them. The sweep\n * refuses to write such a collection while the function is missing, because a\n * `visibleTo` written without them leaves a document its list cannot find.\n */\n\nimport { getRegisteringPluginId } from '../app-utils/registering-plugin'\nimport { PLUGIN_SCOPE_SHARING_COLLECTIONS_DECLARED } from './plugin-scope-sharing.generated'\n\n/** One collection under `orgs/{orgId}` whose documents can be all-except. */\nexport interface ScopeSharingCollection {\n /** The subcollection, spelled as Firestore holds it. */\n name: string\n /** Stored fields follow `visibleTo`: a patch function is registered. */\n patch?: boolean\n /** The most sites one document may reach; past it the list stops widening. */\n maxIncluded?: number\n /** Fields naming sites that stay included though they are excluded. */\n keepSiteFields?: string[]\n}\n\n/** A declaration with its owner; `core` for what the platform holds itself. */\nexport type ResolvedScopeSharingCollection = ScopeSharingCollection & {\n pluginId: string\n}\n\n/** The platform's own: media belongs to no plugin. */\nconst CORE_SCOPE_SHARING_COLLECTIONS: readonly ResolvedScopeSharingCollection[] = [\n { pluginId: 'core', name: 'media' },\n { pluginId: 'core', name: 'mediaFolders' },\n]\n\n/**\n * Every collection the sweep walks, in a stable order: a sweep's cursor names\n * a position in this list, and resuming relies on the ones before it being done.\n */\nexport function listScopeSharingCollections(): ResolvedScopeSharingCollection[] {\n return [\n ...CORE_SCOPE_SHARING_COLLECTIONS,\n ...PLUGIN_SCOPE_SHARING_COLLECTIONS_DECLARED,\n ].map((row) => ({ ...row }))\n}\n\n/**\n * Recomputes the fields a document derives from its scope: `next` is the whole\n * document as it will be stored, and the answer is merged into the write.\n */\nexport type ScopeSharingPatch = (\n collection: string,\n next: Record<string, unknown>,\n) => Promise<Record<string, unknown>> | Record<string, unknown>\n\n/**\n * One map per process, on `globalThis`, for the reason `plugin-site-resources`\n * gives: the declarations register from `instrumentation.ts`, which Next\n * compiles apart from the route that runs the sweep.\n */\nconst PATCHES_KEY = Symbol.for('@aglyn/aglyn:plugin-scope-sharing-patches')\n\nconst globalScope = globalThis as typeof globalThis & {\n [PATCHES_KEY]?: Map<string, ScopeSharingPatch>\n}\n\nconst patches: Map<string, ScopeSharingPatch> =\n globalScope[PATCHES_KEY] ?? (globalScope[PATCHES_KEY] = new Map())\n\n/**\n * Registers the patch for collections a plugin declared with `patch: true`.\n * Refuses a collection another plugin declared, or one declared without it.\n */\nexport function registerPluginScopeSharingPatch(\n collections: readonly string[],\n patch: ScopeSharingPatch,\n options?: { pluginId?: string },\n): void {\n const pluginId = (getRegisteringPluginId() ?? options?.pluginId ?? '').trim()\n if (!pluginId) {\n throw new Error(\n 'a scope-sharing patch was registered with no owner: pass { pluginId } ' +\n 'when registering outside a plugin register fn',\n )\n }\n for (const name of collections) {\n const declared = PLUGIN_SCOPE_SHARING_COLLECTIONS_DECLARED.find((row) => row.name === name)\n if (declared?.pluginId !== pluginId || !declared.patch) {\n throw new Error(`${pluginId} did not declare ${name} with patch: true in scopeSharingCollections`)\n }\n }\n for (const name of collections) patches.set(name, patch)\n}\n\n/** The patch registered for a collection, or `null`. */\nexport function scopeSharingPatchFor(collection: string): ScopeSharingPatch | null {\n return patches.get(collection) ?? null\n}\n\n/** Test seam: forget every patch. */\nexport function resetScopeSharingPatchesForTests(): void {\n patches.clear()\n siteChangeHooks.clear()\n}\n\n/**\n * What a plugin keeps level itself after a workspace's sites change, for\n * sharing it stores somewhere other than a document's own marker: the CRM's\n * grants shared with all sites except some, which sit inside a record's\n * `sharing` map. Called after the sweep, with the time it may spend inline;\n * work left past it is the plugin's to finish. It must never throw.\n */\nexport type ScopeSharingSiteChangeHook = (input: {\n orgId: string\n reason: 'site-added' | 'site-removed' | 'drift-repair'\n hostId?: string\n budgetMs: number\n}) => Promise<void>\n\nconst SITE_CHANGE_KEY = Symbol.for('@aglyn/aglyn:plugin-scope-sharing-site-change')\n\nconst globalHooks = globalThis as typeof globalThis & {\n [SITE_CHANGE_KEY]?: Map<string, ScopeSharingSiteChangeHook>\n}\n\nconst siteChangeHooks: Map<string, ScopeSharingSiteChangeHook> =\n globalHooks[SITE_CHANGE_KEY] ?? (globalHooks[SITE_CHANGE_KEY] = new Map())\n\n/** Registers a plugin's {@link ScopeSharingSiteChangeHook}. One per plugin; again replaces it. */\nexport function registerPluginScopeSharingSiteChange(\n hook: ScopeSharingSiteChangeHook,\n options?: { pluginId?: string },\n): void {\n const pluginId = (getRegisteringPluginId() ?? options?.pluginId ?? '').trim()\n if (!pluginId) {\n throw new Error(\n 'a scope-sharing site-change hook was registered with no owner: pass { pluginId } ' +\n 'when registering outside a plugin register fn',\n )\n }\n siteChangeHooks.set(pluginId, hook)\n}\n\n/** Every registered site-change hook, by plugin. */\nexport function listScopeSharingSiteChangeHooks(): Array<{\n pluginId: string\n hook: ScopeSharingSiteChangeHook\n}> {\n return [...siteChangeHooks.entries()].map(([pluginId, hook]) => ({ pluginId, hook }))\n}\n"],"names":["globalScope","globalHooks","getRegisteringPluginId","PLUGIN_SCOPE_SHARING_COLLECTIONS_DECLARED","CORE_SCOPE_SHARING_COLLECTIONS","pluginId","name","listScopeSharingCollections","map","row","PATCHES_KEY","Symbol","for","globalThis","patches","Map","registerPluginScopeSharingPatch","collections","patch","options","trim","Error","declared","find","set","scopeSharingPatchFor","collection","get","resetScopeSharingPatchesForTests","clear","siteChangeHooks","SITE_CHANGE_KEY","registerPluginScopeSharingSiteChange","hook","listScopeSharingSiteChangeHooks","entries"],"mappings":";IA2FEA,0BA2DAC;AAtJF;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;CAcC,GAED,SAASC,sBAAsB,QAAQ,qCAAiC;AACxE,SAASC,yCAAyC,QAAQ,sCAAkC;AAmB5F,oDAAoD,GACpD,MAAMC,iCAA4E;IAChF;QAAEC,UAAU;QAAQC,MAAM;IAAQ;IAClC;QAAED,UAAU;QAAQC,MAAM;IAAe;CAC1C;AAED;;;CAGC,GACD,OAAO,SAASC;IACd,OAAO;WACFH;WACAD;KACJ,CAACK,GAAG,CAAC,CAACC,MAAS,aA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d,OAA+B;QAEbjB,MAAAA;IAAlB,MAAMG,WAAW,EAACH,QAAAA,0BAAAA,oCAAAA,0BAA4BiB,2BAAAA,QAASd,QAAQ,YAA7CH,OAAiD,IAAIkB,IAAI;IAC3E,IAAI,CAACf,UAAU;QACb,MAAM,IAAIgB,MACR,sFACE;IAEN;IACAS,gBAAgBN,GAAG,CAACnB,UAAU4B;AAChC;AAEA,kDAAkD,GAClD,OAAO,SAASC;IAId,OAAO;WAAIJ,gBAAgBK,OAAO;KAAG,CAAC3B,GAAG,CAAC,CAAC,CAACH,UAAU4B,KAAK,GAAM,CAAA;YAAE5B;YAAU4B;QAAK,CAAA;AACpF"}
@@ -0,0 +1,107 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ /** One site, as far as where a plugin runs is concerned. */
18
+ export interface PluginSiteEntry {
19
+ /** The host document id. */
20
+ id: string;
21
+ disabledPlugins?: readonly string[] | null;
22
+ enabledPlugins?: readonly string[] | null;
23
+ }
24
+ /** Where a plugin runs, as a person would choose it. */
25
+ export type PluginRunsOn = {
26
+ mode: 'all';
27
+ } | {
28
+ mode: 'allExcept';
29
+ exceptHostIds: readonly string[];
30
+ };
31
+ /** Whether a site's deny-list names this plugin. */
32
+ export declare function siteLeavesOutPlugin(site: Pick<PluginSiteEntry, 'disabledPlugins'> | null | undefined, pluginId: string): boolean;
33
+ /**
34
+ * Where a plugin runs today, read across the workspace's sites: All sites
35
+ * when no site's deny-list names it, else all sites except the ones that do.
36
+ *
37
+ * Every site may be named, which is a state a site's own switches can reach
38
+ * and a choice this module refuses to WRITE (see {@link planPluginRunsOn}).
39
+ * It is read as what it is, so the field can say so rather than pretend.
40
+ */
41
+ export declare function pluginRunsOnOf(pluginId: string, sites: readonly Pick<PluginSiteEntry, 'id' | 'disabledPlugins'>[]): PluginRunsOn;
42
+ /** One site whose deny-list a choice changes. */
43
+ export interface PluginSiteWrite {
44
+ hostId: string;
45
+ /** The whole deny-list as it should be stored. */
46
+ disabledPlugins: string[];
47
+ /** True when the plugin is taken off this site, false when it comes back. */
48
+ leftOut: boolean;
49
+ }
50
+ /** A plugin that would be left running on a site without one it needs. */
51
+ export interface PluginSiteStranding {
52
+ hostId: string;
53
+ pluginId: string;
54
+ missing: string[];
55
+ }
56
+ export type PluginRunsOnPlan = {
57
+ writes: PluginSiteWrite[];
58
+ problem: null;
59
+ stranded: [];
60
+ } | {
61
+ writes: null;
62
+ problem: string;
63
+ stranded: PluginSiteStranding[];
64
+ };
65
+ /**
66
+ * What a "Runs on" choice writes to each site, or why it can't be written.
67
+ *
68
+ * - The base library runs on every site and can't be left out anywhere.
69
+ * - A plugin the workspace has switched off runs on no site, so there is no
70
+ * choice to make until it is switched back on.
71
+ * - "All sites except…" must leave out at least one site and keep at least
72
+ * one in: leaving every site out is switching it off for the workspace,
73
+ * which is a different switch with a different reach.
74
+ * - A site the choice names that the workspace doesn't hold is dropped, not
75
+ * refused: it is out either way.
76
+ * - Leaving a site out is refused, naming the site and the plugin, when a
77
+ * plugin running there needs this one. Only what THIS choice would strand
78
+ * is counted, so a site already in that state doesn't block the others.
79
+ * - Only sites whose deny-list changes are written. A site's opt-in list
80
+ * (`enabledPlugins`, for User Accounts) is never touched: a deny beats it.
81
+ */
82
+ export declare function planPluginRunsOn(input: {
83
+ pluginId: string;
84
+ choice: PluginRunsOn;
85
+ org: {
86
+ enabledPlugins?: string[];
87
+ } | null | undefined;
88
+ sites: readonly PluginSiteEntry[];
89
+ /** The workspace's pinned marketplace listings, as `resolveEnabledPlugins` reads them. */
90
+ installedListings?: readonly string[] | null;
91
+ /** How a site reads in a refusal. Its id when absent. */
92
+ siteName?: (hostId: string) => string;
93
+ /**
94
+ * The plugin's name in a refusal, for one the catalog can't name: a
95
+ * marketplace plugin, whose id is its listing's (AGL-4047). The catalog's
96
+ * label, else the id, when absent.
97
+ */
98
+ label?: string;
99
+ }): PluginRunsOnPlan;
100
+ /**
101
+ * The sentence the console shows for a plugin that is still off on a site it
102
+ * runs on by this choice, because that site never turned it on: User
103
+ * Accounts, which a site opts into (`defaultOffPerSite`). Null for every other
104
+ * plugin. The choice only ever takes a site out; it never turns a plugin on
105
+ * for a site that hasn't asked for it.
106
+ */
107
+ export declare function pluginRunsOnOptInNote(pluginId: string): string | null;
@@ -0,0 +1,169 @@
1
+ import { _ as _extends } from "@swc/helpers/_/_extends";
2
+ /**
3
+ * @license
4
+ * Copyright 2026 Aglyn LLC
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */ /**
18
+ * Where a plugin runs across a workspace's sites: All sites, or all sites
19
+ * except some (AGL-4047).
20
+ *
21
+ * NO NEW STORAGE AND NO MARKER. A site that is left out is a site whose own
22
+ * `disabledPlugins` deny-list names the plugin, which is exactly what that
23
+ * site's Admin › Plugins switch writes. So the workspace's "Runs on" choice
24
+ * is READ across the sites' deny-lists and WRITTEN into them, and nothing
25
+ * else needs to know it exists:
26
+ *
27
+ * - A site added later has no entry, so it runs the plugin. That is what
28
+ * "all sites except…" promises, with no sweep to keep it true.
29
+ * - A deleted site takes its entry with it.
30
+ * - Anyone who may change a site's plugins can still turn it back on there,
31
+ * as today, and the workspace's choice then reads that site as included.
32
+ *
33
+ * "Selected sites" is not offered for an ordinary plugin: a site's deny-list
34
+ * can't say "on only here", so it would have to deny every other site, and a
35
+ * site added later would then get the plugin, which is the opposite of what
36
+ * "selected" means.
37
+ *
38
+ * Pure: the console reads it to draw the field, and the route that writes it
39
+ * (`/api/orgs/plugin-sites`) asks it again against what it read in its own
40
+ * transaction.
41
+ */ import { canonicalPluginId, FIRST_PARTY_PLUGINS, isDefaultOffPerSite, isLockedOnForSite, resolveEnabledPlugins, resolveHostEnabledPlugins, strandedDependents } from "./enabled-plugins.js";
42
+ /** Whether a site's deny-list names this plugin. */ export function siteLeavesOutPlugin(site, pluginId) {
43
+ const id = canonicalPluginId(pluginId);
44
+ return Array.isArray(site == null ? void 0 : site.disabledPlugins) ? site.disabledPlugins.some((one)=>canonicalPluginId(String(one)) === id) : false;
45
+ }
46
+ /**
47
+ * Where a plugin runs today, read across the workspace's sites: All sites
48
+ * when no site's deny-list names it, else all sites except the ones that do.
49
+ *
50
+ * Every site may be named, which is a state a site's own switches can reach
51
+ * and a choice this module refuses to WRITE (see {@link planPluginRunsOn}).
52
+ * It is read as what it is, so the field can say so rather than pretend.
53
+ */ export function pluginRunsOnOf(pluginId, sites) {
54
+ const exceptHostIds = sites.filter((site)=>siteLeavesOutPlugin(site, pluginId)).map((site)=>site.id);
55
+ return exceptHostIds.length ? {
56
+ mode: 'allExcept',
57
+ exceptHostIds
58
+ } : {
59
+ mode: 'all'
60
+ };
61
+ }
62
+ /** A site's deny-list with this plugin added or taken out, or null when unchanged. */ function nextDisabled(site, pluginId, leaveOut) {
63
+ const current = Array.isArray(site.disabledPlugins) ? site.disabledPlugins.map(String) : [];
64
+ const listed = siteLeavesOutPlugin(site, pluginId);
65
+ if (leaveOut === listed) return null;
66
+ if (leaveOut) return [
67
+ ...current,
68
+ pluginId
69
+ ];
70
+ const id = canonicalPluginId(pluginId);
71
+ return current.filter((one)=>canonicalPluginId(one) !== id);
72
+ }
73
+ const labelOf = (pluginId)=>{
74
+ var _ref;
75
+ var _FIRST_PARTY_PLUGINS_find;
76
+ return (_ref = (_FIRST_PARTY_PLUGINS_find = FIRST_PARTY_PLUGINS.find((plugin)=>plugin.id === pluginId)) == null ? void 0 : _FIRST_PARTY_PLUGINS_find.label) != null ? _ref : pluginId;
77
+ };
78
+ /**
79
+ * What a "Runs on" choice writes to each site, or why it can't be written.
80
+ *
81
+ * - The base library runs on every site and can't be left out anywhere.
82
+ * - A plugin the workspace has switched off runs on no site, so there is no
83
+ * choice to make until it is switched back on.
84
+ * - "All sites except…" must leave out at least one site and keep at least
85
+ * one in: leaving every site out is switching it off for the workspace,
86
+ * which is a different switch with a different reach.
87
+ * - A site the choice names that the workspace doesn't hold is dropped, not
88
+ * refused: it is out either way.
89
+ * - Leaving a site out is refused, naming the site and the plugin, when a
90
+ * plugin running there needs this one. Only what THIS choice would strand
91
+ * is counted, so a site already in that state doesn't block the others.
92
+ * - Only sites whose deny-list changes are written. A site's opt-in list
93
+ * (`enabledPlugins`, for User Accounts) is never touched: a deny beats it.
94
+ */ export function planPluginRunsOn(input) {
95
+ var _input_siteName;
96
+ var _input_label;
97
+ const { pluginId, choice, org, sites } = input;
98
+ const refuse = (problem, stranded = [])=>({
99
+ writes: null,
100
+ problem,
101
+ stranded
102
+ });
103
+ const label = ((_input_label = input.label) == null ? void 0 : _input_label.trim()) || labelOf(pluginId);
104
+ if (isLockedOnForSite(pluginId)) {
105
+ return refuse(`${label} runs on every site, because sites are built out of it, so it can’t be left out.`);
106
+ }
107
+ if (!resolveEnabledPlugins(org, input.installedListings).includes(pluginId)) {
108
+ return refuse(`${label} is switched off for this workspace, so it runs on no site. Switch it on first.`);
109
+ }
110
+ const siteIds = sites.map((site)=>site.id);
111
+ const except = choice.mode === 'allExcept' ? [
112
+ ...new Set(choice.exceptHostIds.map(String))
113
+ ].filter((id)=>siteIds.includes(id)) : [];
114
+ if (choice.mode === 'allExcept') {
115
+ if (!except.length) {
116
+ return refuse('Choose at least one site to leave out, or choose All sites.');
117
+ }
118
+ if (except.length === siteIds.length) {
119
+ return refuse(`Keep at least one site in. To stop ${label} on every site, switch it off for the workspace.`);
120
+ }
121
+ }
122
+ const name = (_input_siteName = input.siteName) != null ? _input_siteName : (hostId)=>hostId;
123
+ const writes = [];
124
+ const stranded = [];
125
+ for (const site of sites){
126
+ const leaveOut = except.includes(site.id);
127
+ const disabledPlugins = nextDisabled(site, pluginId, leaveOut);
128
+ if (!disabledPlugins) continue;
129
+ if (leaveOut) {
130
+ const optedIn = Array.isArray(site.enabledPlugins) ? site.enabledPlugins.map(String) : undefined;
131
+ const runs = (denied)=>resolveHostEnabledPlugins(org, {
132
+ disabledPlugins: Array.isArray(denied) ? denied.map(String) : undefined,
133
+ enabledPlugins: optedIn
134
+ }, input.installedListings);
135
+ const before = new Set(strandedDependents(runs(site.disabledPlugins)).map((entry)=>entry.pluginId));
136
+ const after = strandedDependents(runs(disabledPlugins));
137
+ for (const entry of after){
138
+ if (!before.has(entry.pluginId)) stranded.push(_extends({
139
+ hostId: site.id
140
+ }, entry));
141
+ }
142
+ }
143
+ writes.push({
144
+ hostId: site.id,
145
+ disabledPlugins,
146
+ leftOut: leaveOut
147
+ });
148
+ }
149
+ if (stranded.length) {
150
+ const sentences = stranded.map((entry)=>`${labelOf(entry.pluginId)} on ${name(entry.hostId)} needs ${entry.missing.map(labelOf).join(' and ')}`);
151
+ return refuse(`${sentences.join('; ')}. Switch ${stranded.length === 1 ? 'it' : 'them'} off on ` + `${stranded.length === 1 ? 'that site' : 'those sites'} first, or keep ` + `${stranded.length === 1 ? 'the site' : 'those sites'} in.`, stranded);
152
+ }
153
+ return {
154
+ writes,
155
+ problem: null,
156
+ stranded: []
157
+ };
158
+ }
159
+ /**
160
+ * The sentence the console shows for a plugin that is still off on a site it
161
+ * runs on by this choice, because that site never turned it on: User
162
+ * Accounts, which a site opts into (`defaultOffPerSite`). Null for every other
163
+ * plugin. The choice only ever takes a site out; it never turns a plugin on
164
+ * for a site that hasn't asked for it.
165
+ */ export function pluginRunsOnOptInNote(pluginId) {
166
+ return isDefaultOffPerSite(pluginId) ? `${labelOf(pluginId)} still runs only on the sites that turned it on. Leaving a site out ` + 'here keeps it off there even if that site turned it on.' : null;
167
+ }
168
+
169
+ //# sourceMappingURL=plugin-site-exclusions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../libs/aglyn/src/lib/plugin-manager/plugin-site-exclusions.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * Where a plugin runs across a workspace's sites: All sites, or all sites\n * except some (AGL-4047).\n *\n * NO NEW STORAGE AND NO MARKER. A site that is left out is a site whose own\n * `disabledPlugins` deny-list names the plugin, which is exactly what that\n * site's Admin › Plugins switch writes. So the workspace's \"Runs on\" choice\n * is READ across the sites' deny-lists and WRITTEN into them, and nothing\n * else needs to know it exists:\n *\n * - A site added later has no entry, so it runs the plugin. That is what\n * \"all sites except…\" promises, with no sweep to keep it true.\n * - A deleted site takes its entry with it.\n * - Anyone who may change a site's plugins can still turn it back on there,\n * as today, and the workspace's choice then reads that site as included.\n *\n * \"Selected sites\" is not offered for an ordinary plugin: a site's deny-list\n * can't say \"on only here\", so it would have to deny every other site, and a\n * site added later would then get the plugin, which is the opposite of what\n * \"selected\" means.\n *\n * Pure: the console reads it to draw the field, and the route that writes it\n * (`/api/orgs/plugin-sites`) asks it again against what it read in its own\n * transaction.\n */\n\nimport {\n canonicalPluginId,\n FIRST_PARTY_PLUGINS,\n isDefaultOffPerSite,\n isLockedOnForSite,\n resolveEnabledPlugins,\n resolveHostEnabledPlugins,\n strandedDependents,\n} from './enabled-plugins'\n\n/** One site, as far as where a plugin runs is concerned. */\nexport interface PluginSiteEntry {\n /** The host document id. */\n id: string\n disabledPlugins?: readonly string[] | null\n enabledPlugins?: readonly string[] | null\n}\n\n/** Where a plugin runs, as a person would choose it. */\nexport type PluginRunsOn =\n | { mode: 'all' }\n | { mode: 'allExcept'; exceptHostIds: readonly string[] }\n\n/** Whether a site's deny-list names this plugin. */\nexport function siteLeavesOutPlugin(\n site: Pick<PluginSiteEntry, 'disabledPlugins'> | null | undefined,\n pluginId: string,\n): boolean {\n const id = canonicalPluginId(pluginId)\n return Array.isArray(site?.disabledPlugins)\n ? site.disabledPlugins.some((one) => canonicalPluginId(String(one)) === id)\n : false\n}\n\n/**\n * Where a plugin runs today, read across the workspace's sites: All sites\n * when no site's deny-list names it, else all sites except the ones that do.\n *\n * Every site may be named, which is a state a site's own switches can reach\n * and a choice this module refuses to WRITE (see {@link planPluginRunsOn}).\n * It is read as what it is, so the field can say so rather than pretend.\n */\nexport function pluginRunsOnOf(\n pluginId: string,\n sites: readonly Pick<PluginSiteEntry, 'id' | 'disabledPlugins'>[],\n): PluginRunsOn {\n const exceptHostIds = sites\n .filter((site) => siteLeavesOutPlugin(site, pluginId))\n .map((site) => site.id)\n return exceptHostIds.length ? { mode: 'allExcept', exceptHostIds } : { mode: 'all' }\n}\n\n/** A site's deny-list with this plugin added or taken out, or null when unchanged. */\nfunction nextDisabled(\n site: PluginSiteEntry,\n pluginId: string,\n leaveOut: boolean,\n): string[] | null {\n const current = Array.isArray(site.disabledPlugins)\n ? site.disabledPlugins.map(String)\n : []\n const listed = siteLeavesOutPlugin(site, pluginId)\n if (leaveOut === listed) return null\n if (leaveOut) return [...current, pluginId]\n const id = canonicalPluginId(pluginId)\n return current.filter((one) => canonicalPluginId(one) !== id)\n}\n\n/** One site whose deny-list a choice changes. */\nexport interface PluginSiteWrite {\n hostId: string\n /** The whole deny-list as it should be stored. */\n disabledPlugins: string[]\n /** True when the plugin is taken off this site, false when it comes back. */\n leftOut: boolean\n}\n\n/** A plugin that would be left running on a site without one it needs. */\nexport interface PluginSiteStranding {\n hostId: string\n pluginId: string\n missing: string[]\n}\n\nexport type PluginRunsOnPlan =\n | { writes: PluginSiteWrite[]; problem: null; stranded: [] }\n | { writes: null; problem: string; stranded: PluginSiteStranding[] }\n\nconst labelOf = (pluginId: string): string =>\n FIRST_PARTY_PLUGINS.find((plugin) => plugin.id === pluginId)?.label ?? pluginId\n\n/**\n * What a \"Runs on\" choice writes to each site, or why it can't be written.\n *\n * - The base library runs on every site and can't be left out anywhere.\n * - A plugin the workspace has switched off runs on no site, so there is no\n * choice to make until it is switched back on.\n * - \"All sites except…\" must leave out at least one site and keep at least\n * one in: leaving every site out is switching it off for the workspace,\n * which is a different switch with a different reach.\n * - A site the choice names that the workspace doesn't hold is dropped, not\n * refused: it is out either way.\n * - Leaving a site out is refused, naming the site and the plugin, when a\n * plugin running there needs this one. Only what THIS choice would strand\n * is counted, so a site already in that state doesn't block the others.\n * - Only sites whose deny-list changes are written. A site's opt-in list\n * (`enabledPlugins`, for User Accounts) is never touched: a deny beats it.\n */\nexport function planPluginRunsOn(input: {\n pluginId: string\n choice: PluginRunsOn\n org: { enabledPlugins?: string[] } | null | undefined\n sites: readonly PluginSiteEntry[]\n /** The workspace's pinned marketplace listings, as `resolveEnabledPlugins` reads them. */\n installedListings?: readonly string[] | null\n /** How a site reads in a refusal. Its id when absent. */\n siteName?: (hostId: string) => string\n /**\n * The plugin's name in a refusal, for one the catalog can't name: a\n * marketplace plugin, whose id is its listing's (AGL-4047). The catalog's\n * label, else the id, when absent.\n */\n label?: string\n}): PluginRunsOnPlan {\n const { pluginId, choice, org, sites } = input\n const refuse = (problem: string, stranded: PluginSiteStranding[] = []): PluginRunsOnPlan => ({\n writes: null,\n problem,\n stranded,\n })\n const label = input.label?.trim() || labelOf(pluginId)\n if (isLockedOnForSite(pluginId)) {\n return refuse(`${label} runs on every site, because sites are built out of it, so it can’t be left out.`)\n }\n if (!resolveEnabledPlugins(org, input.installedListings).includes(pluginId)) {\n return refuse(`${label} is switched off for this workspace, so it runs on no site. Switch it on first.`)\n }\n const siteIds = sites.map((site) => site.id)\n const except =\n choice.mode === 'allExcept'\n ? [...new Set(choice.exceptHostIds.map(String))].filter((id) => siteIds.includes(id))\n : []\n if (choice.mode === 'allExcept') {\n if (!except.length) {\n return refuse('Choose at least one site to leave out, or choose All sites.')\n }\n if (except.length === siteIds.length) {\n return refuse(\n `Keep at least one site in. To stop ${label} on every site, switch it off for the workspace.`,\n )\n }\n }\n const name = input.siteName ?? ((hostId: string) => hostId)\n const writes: PluginSiteWrite[] = []\n const stranded: PluginSiteStranding[] = []\n for (const site of sites) {\n const leaveOut = except.includes(site.id)\n const disabledPlugins = nextDisabled(site, pluginId, leaveOut)\n if (!disabledPlugins) continue\n if (leaveOut) {\n const optedIn = Array.isArray(site.enabledPlugins) ? site.enabledPlugins.map(String) : undefined\n const runs = (denied: readonly string[] | null | undefined) =>\n resolveHostEnabledPlugins(\n org,\n { disabledPlugins: Array.isArray(denied) ? denied.map(String) : undefined, enabledPlugins: optedIn },\n input.installedListings,\n )\n const before = new Set(strandedDependents(runs(site.disabledPlugins)).map((entry) => entry.pluginId))\n const after = strandedDependents(runs(disabledPlugins))\n for (const entry of after) {\n if (!before.has(entry.pluginId)) stranded.push({ hostId: site.id, ...entry })\n }\n }\n writes.push({ hostId: site.id, disabledPlugins, leftOut: leaveOut })\n }\n if (stranded.length) {\n const sentences = stranded.map(\n (entry) =>\n `${labelOf(entry.pluginId)} on ${name(entry.hostId)} needs ${entry.missing.map(labelOf).join(' and ')}`,\n )\n return refuse(\n `${sentences.join('; ')}. Switch ${stranded.length === 1 ? 'it' : 'them'} off on ` +\n `${stranded.length === 1 ? 'that site' : 'those sites'} first, or keep ` +\n `${stranded.length === 1 ? 'the site' : 'those sites'} in.`,\n stranded,\n )\n }\n return { writes, problem: null, stranded: [] }\n}\n\n/**\n * The sentence the console shows for a plugin that is still off on a site it\n * runs on by this choice, because that site never turned it on: User\n * Accounts, which a site opts into (`defaultOffPerSite`). Null for every other\n * plugin. The choice only ever takes a site out; it never turns a plugin on\n * for a site that hasn't asked for it.\n */\nexport function pluginRunsOnOptInNote(pluginId: string): string | null {\n return isDefaultOffPerSite(pluginId)\n ? `${labelOf(pluginId)} still runs only on the sites that turned it on. Leaving a site out ` +\n 'here keeps it off there even if that site turned it on.'\n : null\n}\n"],"names":["canonicalPluginId","FIRST_PARTY_PLUGINS","isDefaultOffPerSite","isLockedOnForSite","resolveEnabledPlugins","resolveHostEnabledPlugins","strandedDependents","siteLeavesOutPlugin","site","pluginId","id","Array","isArray","disabledPlugins","some","one","String","pluginRunsOnOf","sites","exceptHostIds","filter","map","length","mode","nextDisabled","leaveOut","current","listed","labelOf","find","plugin","label","planPluginRunsOn","input","choice","org","refuse","problem","stranded","writes","trim","installedListings","includes","siteIds","except","Set","name","siteName","hostId","optedIn","enabledPlugins","undefined","runs","denied","before","entry","after","has","push","leftOut","sentences","missing","join","pluginRunsOnOptInNote"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;;;;;;CAwBC,GAED,SACEA,iBAAiB,EACjBC,mBAAmB,EACnBC,mBAAmB,EACnBC,iBAAiB,EACjBC,qBAAqB,EACrBC,yBAAyB,EACzBC,kBAAkB,QACb,uBAAmB;AAe1B,kDAAkD,GAClD,OAAO,SAASC,oBACdC,IAAiE,EACjEC,QAAgB;IAEhB,MAAMC,KAAKV,kBAAkBS;IAC7B,OAAOE,MAAMC,OAAO,CAACJ,wBAAAA,KAAMK,eAAe,IACtCL,KAAKK,eAAe,CAACC,IAAI,CAAC,CAACC,MAAQf,kBAAkBgB,OAAOD,UAAUL,MACtE;AACN;AAEA;;;;;;;CAOC,GACD,OAAO,SAASO,eACdR,QAAgB,EAChBS,KAAiE;IAEj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AAG,CAAC,CAACkC,QAAUA,MAAM9C,QAAQ;YACnG,MAAM+C,QAAQlD,mBAAmB8C,KAAKvC;YACtC,KAAK,MAAM0C,SAASC,MAAO;gBACzB,IAAI,CAACF,OAAOG,GAAG,CAACF,MAAM9C,QAAQ,GAAG6B,SAASoB,IAAI,CAAC;oBAAEV,QAAQxC,KAAKE,EAAE;mBAAK6C;YACvE;QACF;QACAhB,OAAOmB,IAAI,CAAC;YAAEV,QAAQxC,KAAKE,EAAE;YAAEG;YAAiB8C,SAASlC;QAAS;IACpE;IACA,IAAIa,SAAShB,MAAM,EAAE;QACnB,MAAMsC,YAAYtB,SAASjB,GAAG,CAC5B,CAACkC,QACC,GAAG3B,QAAQ2B,MAAM9C,QAAQ,EAAE,IAAI,EAAEqC,KAAKS,MAAMP,MAAM,EAAE,OAAO,EAAEO,MAAMM,OAAO,CAACxC,GAAG,CAACO,SAASkC,IAAI,CAAC,UAAU;QAE3G,OAAO1B,OACL,GAAGwB,UAAUE,IAAI,CAAC,MAAM,SAAS,EAAExB,SAAShB,MAAM,KAAK,IAAI,OAAO,OAAO,QAAQ,CAAC,GAChF,GAAGgB,SAAShB,MAAM,KAAK,IAAI,cAAc,cAAc,gBAAgB,CAAC,GACxE,GAAGgB,SAAShB,MAAM,KAAK,IAAI,aAAa,cAAc,IAAI,CAAC,EAC7DgB;IAEJ;IACA,OAAO;QAAEC;QAAQF,SAAS;QAAMC,UAAU,EAAE;IAAC;AAC/C;AAEA;;;;;;CAMC,GACD,OAAO,SAASyB,sBAAsBtD,QAAgB;IACpD,OAAOP,oBAAoBO,YACvB,GAAGmB,QAAQnB,UAAU,oEAAoE,CAAC,GACxF,4DACF;AACN"}
@@ -14,7 +14,7 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- import type { RepeatableDataset } from '../app-utils/expand-repeatables';
17
+ import { type RepeatableDataset } from '../app-utils/expand-repeatables';
18
18
  /**
19
19
  * WHERE A PUBLISHED PAGE'S REPEATED ROWS COME FROM (AGL-3080).
20
20
  *
@@ -57,6 +57,16 @@ import type { RepeatableDataset } from '../app-utils/expand-repeatables';
57
57
  * or unreadable entry renders no copies of its element (AGL-3496) — never its
58
58
  * raw `{{item.*}}` template — and costs the page nothing else.
59
59
  *
60
+ * ## Two sources, routed by key (AGL-4212)
61
+ *
62
+ * A key `repeatKey` made from a node's `repeatConnection` starts
63
+ * `connection:`; it names a plugin connection's synced record, and goes to
64
+ * the connection source (`connectionRepeatSource` in `plugins.config.json`).
65
+ * Every other key goes to the `repeatSource`, exactly as before. Each source
66
+ * has the three cases above on its own: a page whose site has no plugin that
67
+ * keeps connection records gets no copies of a connection repeat, and still
68
+ * gets its datasets' rows.
69
+ *
60
70
  * Reached by path, never through a barrel: only the server composition asks.
61
71
  */
62
72
  /** One composition's question: the keys a page's tree repeats over. */
@@ -85,6 +95,13 @@ export interface RepeatSourceDeclaration {
85
95
  }
86
96
  /** The plugin declared to answer repeats, or `null` when none is. */
87
97
  export declare function declaredRepeatSource(): RepeatSourceDeclaration | null;
98
+ /**
99
+ * The plugin declared to answer repeats over a plugin connection's record
100
+ * (the `connection:` keys, AGL-4212), or `null` when none is.
101
+ */
102
+ export declare function declaredConnectionRepeatSource(): RepeatSourceDeclaration | null;
103
+ /** Whether a key names a plugin connection's record rather than a dataset. */
104
+ export declare const isConnectionRepeatKey: (key: string) => boolean;
88
105
  interface RegisteredReader {
89
106
  pluginId: string;
90
107
  reader: RepeatRowReader;
@@ -117,7 +134,8 @@ export declare class RepeatRowsUnavailableError extends Error {
117
134
  }
118
135
  /**
119
136
  * The rows a composition's repeats render. See the module note for what each
120
- * of the three cases answers; with no keys it answers `{}` and asks nobody.
137
+ * of the three cases answers, per source; with no keys it answers `{}` and
138
+ * asks nobody.
121
139
  */
122
140
  export declare function readRepeatRows(request: RepeatRowsRequest): Promise<RepeatRowsAnswer>;
123
141
  export {};
@@ -1,3 +1,4 @@
1
+ var _globalScope_READERS_KEY;
1
2
  /**
2
3
  * @license
3
4
  * Copyright 2026 Aglyn LLC
@@ -13,13 +14,20 @@
13
14
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
15
  * See the License for the specific language governing permissions and
15
16
  * limitations under the License.
16
- */ var _globalScope_READERS_KEY;
17
+ */ import { REPEAT_CONNECTION_KEY_PREFIX } from "../app-utils/expand-repeatables.js";
17
18
  import { getRegisteringPluginId } from "../app-utils/registering-plugin.js";
18
- import { PLUGIN_REPEAT_SOURCE_DECLARED } from "./first-party-plugins.generated.js";
19
+ import { PLUGIN_CONNECTION_REPEAT_SOURCE_DECLARED, PLUGIN_REPEAT_SOURCE_DECLARED } from "./first-party-plugins.generated.js";
19
20
  import { runPluginDeclarationsRepair } from "./plugin-declarations-repair.js";
20
21
  /** The plugin declared to answer repeats, or `null` when none is. */ export function declaredRepeatSource() {
21
22
  return PLUGIN_REPEAT_SOURCE_DECLARED;
22
23
  }
24
+ /**
25
+ * The plugin declared to answer repeats over a plugin connection's record
26
+ * (the `connection:` keys, AGL-4212), or `null` when none is.
27
+ */ export function declaredConnectionRepeatSource() {
28
+ return PLUGIN_CONNECTION_REPEAT_SOURCE_DECLARED;
29
+ }
30
+ /** Whether a key names a plugin connection's record rather than a dataset. */ export const isConnectionRepeatKey = (key)=>key.startsWith(REPEAT_CONNECTION_KEY_PREFIX);
23
31
  /**
24
32
  * One table per process, on `globalThis` (AGL-3412): the app registers from
25
33
  * `instrumentation.ts`, which Next compiles apart from the routes that read,
@@ -46,9 +54,13 @@ const readers = (_globalScope_READERS_KEY = globalScope[READERS_KEY]) != null ?
46
54
  if (!pluginId) {
47
55
  throw new Error(`repeat row reader "${id}" registered with no owner: pass { pluginId } ` + 'when registering outside a plugin register fn');
48
56
  }
49
- const declared = declaredRepeatSource();
50
- if ((declared == null ? void 0 : declared.id) === id && declared.pluginId !== pluginId) {
51
- throw new Error(`repeat source "${id}" is declared by "${declared.pluginId}"; ` + `refused a reader from "${pluginId}"`);
57
+ for (const declared of [
58
+ declaredRepeatSource(),
59
+ declaredConnectionRepeatSource()
60
+ ]){
61
+ if ((declared == null ? void 0 : declared.id) === id && declared.pluginId !== pluginId) {
62
+ throw new Error(`repeat source "${id}" is declared by "${declared.pluginId}"; ` + `refused a reader from "${pluginId}"`);
63
+ }
52
64
  }
53
65
  const held = readers.get(id);
54
66
  if (held && held.pluginId !== pluginId) {
@@ -81,28 +93,42 @@ const readers = (_globalScope_READERS_KEY = globalScope[READERS_KEY]) != null ?
81
93
  }
82
94
  /**
83
95
  * The rows a composition's repeats render. See the module note for what each
84
- * of the three cases answers; with no keys it answers `{}` and asks nobody.
96
+ * of the three cases answers, per source; with no keys it answers `{}` and
97
+ * asks nobody.
85
98
  */ export async function readRepeatRows(request) {
86
99
  const keys = [
87
100
  ...new Set(request.keys.map((key)=>key.trim()).filter(Boolean))
88
101
  ].sort();
89
102
  if (!keys.length) return {};
90
- const declared = declaredRepeatSource();
91
- if (!declared) return {};
92
- let registered = readers.get(declared.id);
93
- if (!registered) {
103
+ const connectionKeys = keys.filter(isConnectionRepeatKey);
104
+ const plainKeys = keys.filter((key)=>!isConnectionRepeatKey(key));
105
+ const asks = [
106
+ {
107
+ declared: declaredRepeatSource(),
108
+ keys: plainKeys
109
+ },
110
+ {
111
+ declared: declaredConnectionRepeatSource(),
112
+ keys: connectionKeys
113
+ }
114
+ ].filter((ask)=>ask.declared !== null && ask.keys.length > 0);
115
+ if (!asks.length) return {};
116
+ if (asks.some((ask)=>!readers.has(ask.declared.id))) {
94
117
  try {
95
118
  await runPluginDeclarationsRepair();
96
119
  } catch (error) {
97
120
  console.error('[repeat-rows] the declarations repair failed', error);
98
121
  }
99
- registered = readers.get(declared.id);
100
122
  }
101
- if (!registered) throw new RepeatRowsUnavailableError(declared);
102
- return registered.reader({
103
- hostId: request.hostId,
104
- keys
105
- });
123
+ const answers = await Promise.all(asks.map((ask)=>{
124
+ const registered = readers.get(ask.declared.id);
125
+ if (!registered) throw new RepeatRowsUnavailableError(ask.declared);
126
+ return registered.reader({
127
+ hostId: request.hostId,
128
+ keys: ask.keys
129
+ });
130
+ }));
131
+ return Object.assign({}, ...answers);
106
132
  }
107
133
 
108
134
  //# sourceMappingURL=repeat-rows.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../libs/aglyn/src/lib/plugin-manager/repeat-rows.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { RepeatableDataset } from '../app-utils/expand-repeatables'\nimport { getRegisteringPluginId } from '../app-utils/registering-plugin'\nimport { PLUGIN_REPEAT_SOURCE_DECLARED } from './first-party-plugins.generated'\nimport { runPluginDeclarationsRepair } from './plugin-declarations-repair'\n\n/**\n * WHERE A PUBLISHED PAGE'S REPEATED ROWS COME FROM (AGL-3080).\n *\n * Any element can repeat, and the platform decides what a repeat MEANS — the\n * scope, the copies, the filter, the bound (`expand-repeatables.ts`). What it\n * does not decide is where the rows live. That is the plugin's that keeps\n * them, and the composition that renders a published page asks it here, with\n * the keys the page's tree repeats over, and never reads a collection itself.\n *\n * `repeat-sources.ts` is the editor's side of the same line: a hook the\n * besigner's canvas mounts to preview the rows. This is the server's side,\n * read once per compose, and it is a different registry because its readers\n * are different processes with different failure costs.\n *\n * ## Declared, then registered — and an absent reader is refused\n *\n * The reader is registered from the owning plugin's `serverDeclarations`\n * entry, which every app runs at boot, so every process that composes a page\n * has it before the first request. But a registry is only safe where an empty\n * one cannot be mistaken for an answer, and here it can: a page whose repeat\n * found no reader would render no copies where the author put a list, and\n * nothing anywhere would be red. That is the AGL-3025 shape on the most\n * public surface the product has.\n *\n * So the plugin that answers also DECLARES that it does, in\n * `plugins.config.json` (`repeatSource`), and the generator compiles that into\n * core. The two together tell the one case that is a real answer from the one\n * that is a broken boot:\n *\n * - nothing declared — this deployment ships no plugin that keeps rows, and a\n * repeat renders no copies, exactly as a key naming nothing does (AGL-3496);\n * - declared and registered — the reader answers;\n * - declared and NOT registered — the boot failed. The app's declarations\n * step is run again ({@link runPluginDeclarationsRepair}); if the reader is\n * still missing, {@link readRepeatRows} THROWS. A render that throws keeps\n * the page it last rendered in the cache and is loud in the logs, which is\n * the right way round for a page that would otherwise go out wrong.\n *\n * Per-key failures are the reader's to absorb, as they always were: a deleted\n * or unreadable entry renders no copies of its element (AGL-3496) — never its\n * raw `{{item.*}}` template — and costs the page nothing else.\n *\n * Reached by path, never through a barrel: only the server composition asks.\n */\n\n/** One composition's question: the keys a page's tree repeats over. */\nexport interface RepeatRowsRequest {\n /** The site being rendered. A reader answers only what that site may see. */\n hostId: string\n /**\n * The keys exactly as the nodes store them (`repeatKeys`), trimmed,\n * sorted and without repeats.\n */\n keys: readonly string[]\n}\n\n/**\n * The rows for a request, under every key the expansion looks them up by: the\n * key as the node stores it, the entry's own id, and each entry a one-hop\n * reference in the rows reads. A key with nothing to render is absent.\n */\nexport type RepeatRowsAnswer = Record<string, RepeatableDataset>\n\n/** Answers one composition's request. Never rejects for a single bad key. */\nexport type RepeatRowReader = (\n request: RepeatRowsRequest,\n) => Promise<RepeatRowsAnswer>\n\n/** The compiled declaration: which plugin answers, under which source id. */\nexport interface RepeatSourceDeclaration {\n pluginId: string\n /** The same id the plugin's editor source (`repeat-sources.ts`) uses. */\n id: string\n}\n\n/** The plugin declared to answer repeats, or `null` when none is. */\nexport function declaredRepeatSource(): RepeatSourceDeclaration | null {\n return PLUGIN_REPEAT_SOURCE_DECLARED\n}\n\ninterface RegisteredReader {\n pluginId: string\n reader: RepeatRowReader\n}\n\n/**\n * One table per process, on `globalThis` (AGL-3412): the app registers from\n * `instrumentation.ts`, which Next compiles apart from the routes that read,\n * and a module-scoped map would be filled in one copy and read empty in the\n * other — the exact failure this module exists to refuse.\n */\nconst READERS_KEY = Symbol.for('@aglyn/aglyn:repeat-row-readers')\n\nconst globalScope = globalThis as typeof globalThis & {\n [READERS_KEY]?: Map<string, RegisteredReader>\n}\n\nconst readers: Map<string, RegisteredReader> =\n globalScope[READERS_KEY] ?? (globalScope[READERS_KEY] = new Map())\n\n/**\n * Registers the reader for a source. Returns the unregister, which removes it\n * only while it is still the one registered.\n *\n * The owner is the plugin whose register fn is running, or the `pluginId`\n * passed for a boot declaration, where the loader's marker is not set. A\n * registration with neither is refused, and so is one from a plugin other\n * than the one the declaration names — two readers for one source would each\n * answer for the other's rows. The same plugin registering again replaces its\n * reader (a second surface, a repeated boot).\n */\nexport function registerRepeatRowReader(\n sourceId: string,\n reader: RepeatRowReader,\n options?: { pluginId?: string },\n): () => void {\n const id = sourceId.trim()\n const pluginId = (getRegisteringPluginId() ?? options?.pluginId ?? '').trim()\n if (!id) throw new Error('a repeat row reader needs a source id')\n if (!pluginId) {\n throw new Error(\n `repeat row reader \"${id}\" registered with no owner: pass { pluginId } ` +\n 'when registering outside a plugin register fn',\n )\n }\n const declared = declaredRepeatSource()\n if (declared?.id === id && declared.pluginId !== pluginId) {\n throw new Error(\n `repeat source \"${id}\" is declared by \"${declared.pluginId}\"; ` +\n `refused a reader from \"${pluginId}\"`,\n )\n }\n const held = readers.get(id)\n if (held && held.pluginId !== pluginId) {\n throw new Error(\n `repeat source \"${id}\" already has a reader from \"${held.pluginId}\"; ` +\n `refused \"${pluginId}\"`,\n )\n }\n const entry: RegisteredReader = { pluginId, reader }\n readers.set(id, entry)\n return () => {\n if (readers.get(id) === entry) readers.delete(id)\n }\n}\n\n/** The reader registered for a source, with its owner, or `null`. */\nexport function repeatRowReader(sourceId: string): RegisteredReader | null {\n return readers.get(sourceId) ?? null\n}\n\n/** Only for specs: forgets every registered reader. */\nexport function resetRepeatRowReadersForTests(): void {\n readers.clear()\n}\n\n/**\n * The declared source's reader was not registered, even after the app's\n * declarations step ran again. Thrown, never answered: see the module note.\n */\nexport class RepeatRowsUnavailableError extends Error {\n constructor(readonly source: RepeatSourceDeclaration) {\n super(\n `repeat source \"${source.id}\" is declared by \"${source.pluginId}\" but ` +\n 'no reader is registered in this process — its server declarations ' +\n 'did not run. Refusing to render repeats as if they had no rows.',\n )\n this.name = 'RepeatRowsUnavailableError'\n }\n}\n\n/**\n * The rows a composition's repeats render. See the module note for what each\n * of the three cases answers; with no keys it answers `{}` and asks nobody.\n */\nexport async function readRepeatRows(\n request: RepeatRowsRequest,\n): Promise<RepeatRowsAnswer> {\n const keys = [\n ...new Set(request.keys.map((key) => key.trim()).filter(Boolean)),\n ].sort()\n if (!keys.length) return {}\n const declared = declaredRepeatSource()\n if (!declared) return {}\n let registered = readers.get(declared.id)\n if (!registered) {\n try {\n await runPluginDeclarationsRepair()\n } catch (error) {\n console.error('[repeat-rows] the declarations repair failed', error)\n }\n registered = readers.get(declared.id)\n }\n if (!registered) throw new RepeatRowsUnavailableError(declared)\n return registered.reader({ hostId: request.hostId, keys })\n}\n"],"names":["globalScope","getRegisteringPluginId","PLUGIN_REPEAT_SOURCE_DECLARED","runPluginDeclarationsRepair","declaredRepeatSource","READERS_KEY","Symbol","for","globalThis","readers","Map","registerRepeatRowReader","sourceId","reader","options","id","trim","pluginId","Error","declared","held","get","entry","set","delete","repeatRowReader","resetRepeatRowReadersForTests","clear","RepeatRowsUnavailableError","source","name","readRepeatRows","request","keys","Set","map","key","filter","Boolean","sort","length","registered","error","console","hostId"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,OAyGCA;AAtGF,SAASC,sBAAsB,QAAQ,qCAAiC;AACxE,SAASC,6BAA6B,QAAQ,qCAAiC;AAC/E,SAASC,2BAA2B,QAAQ,kCAA8B;AA6E1E,mEAAmE,GACnE,OAAO,SAASC;IACd,OAAOF;AACT;AAOA;;;;;CAKC,GACD,MAAMG,cAAcC,OAAO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IAAP,QAAOA,eAAAA,QAAQY,GAAG,CAACT,qBAAZH,eAAyB;AAClC;AAEA,qDAAqD,GACrD,OAAO,SAASiB;IACdjB,QAAQkB,KAAK;AACf;AAEA;;;CAGC,GACD,OAAO,MAAMC,mCAAmCV;IAC9C,YAAY,AAASW,MAA+B,CAAE;QACpD,KAAK,CACH,CAAC,eAAe,EAAEA,OAAOd,EAAE,CAAC,kBAAkB,EAAEc,OAAOZ,QAAQ,CAAC,MAAM,CAAC,GACrE,uEACA,yEAJeY,SAAAA;QAMnB,IAAI,CAACC,IAAI,GAAG;IACd;AACF;AAEA;;;CAGC,GACD,OAAO,eAAeC,eACpBC,OAA0B;IAE1B,MAAMC,OAAO;WACR,IAAIC,IAAIF,QAAQC,IAAI,CAACE,GAAG,CAAC,CAACC,MAAQA,IAAIpB,IAAI,IAAIqB,MAAM,CAACC;KACzD,CAACC,IAAI;IACN,IAAI,CAACN,KAAKO,MAAM,EAAE,OAAO,CAAC;IAC1B,MAAMrB,WAAWf;IACjB,IAAI,CAACe,UAAU,OAAO,CAAC;IACvB,IAAIsB,aAAahC,QAAQY,GAAG,CAACF,SAASJ,EAAE;IACxC,IAAI,CAAC0B,YAAY;QACf,IAAI;YACF,MAAMtC;QACR,EAAE,OAAOuC,OAAO;YACdC,QAAQD,KAAK,CAAC,gDAAgDA;QAChE;QACAD,aAAahC,QAAQY,GAAG,CAACF,SAASJ,EAAE;IACtC;IACA,IAAI,CAAC0B,YAAY,MAAM,IAAIb,2BAA2BT;IACtD,OAAOsB,WAAW5B,MAAM,CAAC;QAAE+B,QAAQZ,QAAQY,MAAM;QAAEX;IAAK;AAC1D"}
1
+ {"version":3,"sources":["../../../../../../libs/aglyn/src/lib/plugin-manager/repeat-rows.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n REPEAT_CONNECTION_KEY_PREFIX,\n type RepeatableDataset,\n} from '../app-utils/expand-repeatables'\nimport { getRegisteringPluginId } from '../app-utils/registering-plugin'\nimport {\n PLUGIN_CONNECTION_REPEAT_SOURCE_DECLARED,\n PLUGIN_REPEAT_SOURCE_DECLARED,\n} from './first-party-plugins.generated'\nimport { runPluginDeclarationsRepair } from './plugin-declarations-repair'\n\n/**\n * WHERE A PUBLISHED PAGE'S REPEATED ROWS COME FROM (AGL-3080).\n *\n * Any element can repeat, and the platform decides what a repeat MEANS — the\n * scope, the copies, the filter, the bound (`expand-repeatables.ts`). What it\n * does not decide is where the rows live. That is the plugin's that keeps\n * them, and the composition that renders a published page asks it here, with\n * the keys the page's tree repeats over, and never reads a collection itself.\n *\n * `repeat-sources.ts` is the editor's side of the same line: a hook the\n * besigner's canvas mounts to preview the rows. This is the server's side,\n * read once per compose, and it is a different registry because its readers\n * are different processes with different failure costs.\n *\n * ## Declared, then registered — and an absent reader is refused\n *\n * The reader is registered from the owning plugin's `serverDeclarations`\n * entry, which every app runs at boot, so every process that composes a page\n * has it before the first request. But a registry is only safe where an empty\n * one cannot be mistaken for an answer, and here it can: a page whose repeat\n * found no reader would render no copies where the author put a list, and\n * nothing anywhere would be red. That is the AGL-3025 shape on the most\n * public surface the product has.\n *\n * So the plugin that answers also DECLARES that it does, in\n * `plugins.config.json` (`repeatSource`), and the generator compiles that into\n * core. The two together tell the one case that is a real answer from the one\n * that is a broken boot:\n *\n * - nothing declared — this deployment ships no plugin that keeps rows, and a\n * repeat renders no copies, exactly as a key naming nothing does (AGL-3496);\n * - declared and registered — the reader answers;\n * - declared and NOT registered — the boot failed. The app's declarations\n * step is run again ({@link runPluginDeclarationsRepair}); if the reader is\n * still missing, {@link readRepeatRows} THROWS. A render that throws keeps\n * the page it last rendered in the cache and is loud in the logs, which is\n * the right way round for a page that would otherwise go out wrong.\n *\n * Per-key failures are the reader's to absorb, as they always were: a deleted\n * or unreadable entry renders no copies of its element (AGL-3496) — never its\n * raw `{{item.*}}` template — and costs the page nothing else.\n *\n * ## Two sources, routed by key (AGL-4212)\n *\n * A key `repeatKey` made from a node's `repeatConnection` starts\n * `connection:`; it names a plugin connection's synced record, and goes to\n * the connection source (`connectionRepeatSource` in `plugins.config.json`).\n * Every other key goes to the `repeatSource`, exactly as before. Each source\n * has the three cases above on its own: a page whose site has no plugin that\n * keeps connection records gets no copies of a connection repeat, and still\n * gets its datasets' rows.\n *\n * Reached by path, never through a barrel: only the server composition asks.\n */\n\n/** One composition's question: the keys a page's tree repeats over. */\nexport interface RepeatRowsRequest {\n /** The site being rendered. A reader answers only what that site may see. */\n hostId: string\n /**\n * The keys exactly as the nodes store them (`repeatKeys`), trimmed,\n * sorted and without repeats.\n */\n keys: readonly string[]\n}\n\n/**\n * The rows for a request, under every key the expansion looks them up by: the\n * key as the node stores it, the entry's own id, and each entry a one-hop\n * reference in the rows reads. A key with nothing to render is absent.\n */\nexport type RepeatRowsAnswer = Record<string, RepeatableDataset>\n\n/** Answers one composition's request. Never rejects for a single bad key. */\nexport type RepeatRowReader = (\n request: RepeatRowsRequest,\n) => Promise<RepeatRowsAnswer>\n\n/** The compiled declaration: which plugin answers, under which source id. */\nexport interface RepeatSourceDeclaration {\n pluginId: string\n /** The same id the plugin's editor source (`repeat-sources.ts`) uses. */\n id: string\n}\n\n/** The plugin declared to answer repeats, or `null` when none is. */\nexport function declaredRepeatSource(): RepeatSourceDeclaration | null {\n return PLUGIN_REPEAT_SOURCE_DECLARED\n}\n\n/**\n * The plugin declared to answer repeats over a plugin connection's record\n * (the `connection:` keys, AGL-4212), or `null` when none is.\n */\nexport function declaredConnectionRepeatSource(): RepeatSourceDeclaration | null {\n return PLUGIN_CONNECTION_REPEAT_SOURCE_DECLARED\n}\n\n/** Whether a key names a plugin connection's record rather than a dataset. */\nexport const isConnectionRepeatKey = (key: string): boolean =>\n key.startsWith(REPEAT_CONNECTION_KEY_PREFIX)\n\ninterface RegisteredReader {\n pluginId: string\n reader: RepeatRowReader\n}\n\n/**\n * One table per process, on `globalThis` (AGL-3412): the app registers from\n * `instrumentation.ts`, which Next compiles apart from the routes that read,\n * and a module-scoped map would be filled in one copy and read empty in the\n * other — the exact failure this module exists to refuse.\n */\nconst READERS_KEY = Symbol.for('@aglyn/aglyn:repeat-row-readers')\n\nconst globalScope = globalThis as typeof globalThis & {\n [READERS_KEY]?: Map<string, RegisteredReader>\n}\n\nconst readers: Map<string, RegisteredReader> =\n globalScope[READERS_KEY] ?? (globalScope[READERS_KEY] = new Map())\n\n/**\n * Registers the reader for a source. Returns the unregister, which removes it\n * only while it is still the one registered.\n *\n * The owner is the plugin whose register fn is running, or the `pluginId`\n * passed for a boot declaration, where the loader's marker is not set. A\n * registration with neither is refused, and so is one from a plugin other\n * than the one the declaration names — two readers for one source would each\n * answer for the other's rows. The same plugin registering again replaces its\n * reader (a second surface, a repeated boot).\n */\nexport function registerRepeatRowReader(\n sourceId: string,\n reader: RepeatRowReader,\n options?: { pluginId?: string },\n): () => void {\n const id = sourceId.trim()\n const pluginId = (getRegisteringPluginId() ?? options?.pluginId ?? '').trim()\n if (!id) throw new Error('a repeat row reader needs a source id')\n if (!pluginId) {\n throw new Error(\n `repeat row reader \"${id}\" registered with no owner: pass { pluginId } ` +\n 'when registering outside a plugin register fn',\n )\n }\n for (const declared of [\n declaredRepeatSource(),\n declaredConnectionRepeatSource(),\n ]) {\n if (declared?.id === id && declared.pluginId !== pluginId) {\n throw new Error(\n `repeat source \"${id}\" is declared by \"${declared.pluginId}\"; ` +\n `refused a reader from \"${pluginId}\"`,\n )\n }\n }\n const held = readers.get(id)\n if (held && held.pluginId !== pluginId) {\n throw new Error(\n `repeat source \"${id}\" already has a reader from \"${held.pluginId}\"; ` +\n `refused \"${pluginId}\"`,\n )\n }\n const entry: RegisteredReader = { pluginId, reader }\n readers.set(id, entry)\n return () => {\n if (readers.get(id) === entry) readers.delete(id)\n }\n}\n\n/** The reader registered for a source, with its owner, or `null`. */\nexport function repeatRowReader(sourceId: string): RegisteredReader | null {\n return readers.get(sourceId) ?? null\n}\n\n/** Only for specs: forgets every registered reader. */\nexport function resetRepeatRowReadersForTests(): void {\n readers.clear()\n}\n\n/**\n * The declared source's reader was not registered, even after the app's\n * declarations step ran again. Thrown, never answered: see the module note.\n */\nexport class RepeatRowsUnavailableError extends Error {\n constructor(readonly source: RepeatSourceDeclaration) {\n super(\n `repeat source \"${source.id}\" is declared by \"${source.pluginId}\" but ` +\n 'no reader is registered in this process — its server declarations ' +\n 'did not run. Refusing to render repeats as if they had no rows.',\n )\n this.name = 'RepeatRowsUnavailableError'\n }\n}\n\n/**\n * The rows a composition's repeats render. See the module note for what each\n * of the three cases answers, per source; with no keys it answers `{}` and\n * asks nobody.\n */\nexport async function readRepeatRows(\n request: RepeatRowsRequest,\n): Promise<RepeatRowsAnswer> {\n const keys = [\n ...new Set(request.keys.map((key) => key.trim()).filter(Boolean)),\n ].sort()\n if (!keys.length) return {}\n const connectionKeys = keys.filter(isConnectionRepeatKey)\n const plainKeys = keys.filter((key) => !isConnectionRepeatKey(key))\n const asks = [\n { declared: declaredRepeatSource(), keys: plainKeys },\n { declared: declaredConnectionRepeatSource(), keys: connectionKeys },\n ].filter(\n (ask): ask is { declared: RepeatSourceDeclaration; keys: string[] } =>\n ask.declared !== null && ask.keys.length > 0,\n )\n if (!asks.length) return {}\n if (asks.some((ask) => !readers.has(ask.declared.id))) {\n try {\n await runPluginDeclarationsRepair()\n } catch (error) {\n console.error('[repeat-rows] the declarations repair failed', error)\n }\n }\n const answers = await Promise.all(\n asks.map((ask) => {\n const registered = readers.get(ask.declared.id)\n if (!registered) throw new RepeatRowsUnavailableError(ask.declared)\n return registered.reader({ hostId: request.hostId, keys: ask.keys })\n }),\n )\n return Object.assign({}, ...answers) as RepeatRowsAnswer\n}\n"],"names":["globalScope","REPEAT_CONNECTION_KEY_PREFIX","getRegisteringPluginId","PLUGIN_CONNECTION_REPEAT_SOURCE_DECLARED","PLUGIN_REPEAT_SOURCE_DECLARED","runPluginDeclarationsRepair","declaredRepeatSource","declaredConnectionRepeatSource","isConnectionRepeatKey","key","startsWith","READERS_KEY","Symbol","for","globalThis","readers","Map","registerRepeatRowReader","sourceId","reader","options","id","trim","pluginId","Error","declared","held","get","entry","set","delete","repeatRowReader","resetRepeatRowReadersForTests","clear","RepeatRowsUnavailableError","source","name","readRepeatRows","request","keys","Set","map","filter","Boolean","sort","length","connectionKeys","plainKeys","asks","ask","some","has","error","console","answers","Promise","all","registered","hostId","Object","assign"],"mappings":"IAoJEA;AApJF;;;;;;;;;;;;;;;CAeC,GAED,SACEC,4BAA4B,QAEvB,qCAAiC;AACxC,SAASC,sBAAsB,QAAQ,qCAAiC;AACxE,SACEC,wCAAwC,EACxCC,6BAA6B,QACxB,qCAAiC;AACxC,SAASC,2BAA2B,QAAQ,kCAA8B;AAuF1E,mEAAmE,GACnE,OAAO,SAASC;IACd,OAAOF;AACT;AAEA;;;CAGC,GACD,OAAO,SAASG;IACd,OAAOJ;AACT;AAEA,4EAA4E,GAC5E,OAAO,MAAMK,wBAAwB,CAACC,MACpCA,IAAIC,UAAU,CAACT,8BAA6B;AAO9C;;;;;CAKC,GACD,MAAMU,cAAcC,OAAOC,GAAG,CAAC;AAE/B,MAAMb,cAAcc;AAIpB,MAAMC,WACJf,2BAAAA,WAAW,CAACW,YAAY,YAAxBX,2BAA6BA,WAAW,CAACW,YAAY,GAAG,IAAIK;AAE9D;;;;;;;;;;CAUC,GACD,OAAO,SAASC,wBACdC,QAAgB,EAChBC,MAAuB,EACvBC,OAA+B;QAGblB,MAAAA;IADlB,MAAMmB,KAAKH,SAASI,IAAI;IACxB,MAAMC,WAAW,EAACrB,QAAAA,0BAAAA,oCAAAA,0BAA4BkB,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