@plitzi/sdk-shared 0.38.24 → 0.39.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (197) hide show
  1. package/CHANGELOG.md +153 -1
  2. package/dist/actions/functions.d.ts +22 -1
  3. package/dist/actions/functions.mjs +3 -3
  4. package/dist/actions/index.d.ts +1 -1
  5. package/dist/actions/index.mjs +7 -7
  6. package/dist/auth/failureChannel.mjs +1 -0
  7. package/dist/auth/index.d.ts +1 -1
  8. package/dist/auth/index.mjs +2 -2
  9. package/dist/auth/visitorRoles.d.ts +8 -0
  10. package/dist/auth/visitorRoles.mjs +5 -2
  11. package/dist/authoring/declare.d.ts +34 -1
  12. package/dist/authoring/elementCallbacks.d.ts +13 -0
  13. package/dist/authoring/elementCallbacks.mjs +11 -5
  14. package/dist/authoring/index.mjs +3 -3
  15. package/dist/authoring/paramSpec.d.ts +1 -0
  16. package/dist/dataSource/getBindingsDetails.d.ts +1 -1
  17. package/dist/dataSource/getBindingsDetails.mjs +1 -1
  18. package/dist/dataSource/globalSources.d.ts +1 -1
  19. package/dist/dataSource/index.d.ts +1 -2
  20. package/dist/dataSource/index.mjs +1 -1
  21. package/dist/dataSource/utility/arrayMap.mjs +1 -1
  22. package/dist/dataSource/utility/capitalize.mjs +1 -1
  23. package/dist/dataSource/utility/styleSelector.mjs +5 -3
  24. package/dist/dataSource/utility/styleVariant.mjs +17 -13
  25. package/dist/dataSource/variables/index.d.ts +2 -0
  26. package/dist/dataSource/variables/index.mjs +1 -0
  27. package/dist/dataSource/{resolveVariables.d.ts → variables/resolveVariables.d.ts} +1 -1
  28. package/dist/dataSource/{resolveVariables.mjs → variables/resolveVariables.mjs} +1 -1
  29. package/dist/devTools/chrome.d.ts +6 -0
  30. package/dist/devTools/chrome.mjs +2 -2
  31. package/dist/devTools/index.mjs +5 -5
  32. package/dist/devTools/sight/index.d.ts +1 -0
  33. package/dist/devTools/sight/index.mjs +1 -0
  34. package/dist/devTools/sight/sight.d.ts +28 -0
  35. package/dist/devTools/sight/sight.mjs +127 -0
  36. package/dist/devTools/utils/PlitziConsole.d.ts +14 -0
  37. package/dist/devTools/utils/PlitziConsole.mjs +20 -3
  38. package/dist/flags/flagsCookie.mjs +4 -4
  39. package/dist/flags/resolveFlags.d.ts +1 -1
  40. package/dist/helpers/index.mjs +19 -19
  41. package/dist/helpers/ruleEvaluator.d.ts +2 -0
  42. package/dist/helpers/ruleEvaluator.mjs +2 -2
  43. package/dist/helpers/scroll.d.ts +10 -0
  44. package/dist/helpers/scroll.mjs +2 -2
  45. package/dist/helpers/twigWrapper/Evaluator/Evaluator.mjs +90 -88
  46. package/dist/helpers/twigWrapper/Evaluator/helpers.d.ts +6 -0
  47. package/dist/helpers/twigWrapper/Evaluator/helpers.mjs +11 -2
  48. package/dist/helpers/twigWrapper/filters/arrays.d.ts +2 -0
  49. package/dist/helpers/twigWrapper/filters/arrays.mjs +66 -0
  50. package/dist/helpers/twigWrapper/filters/catalog/index.d.ts +17 -0
  51. package/dist/helpers/twigWrapper/filters/catalog/index.mjs +351 -0
  52. package/dist/helpers/twigWrapper/filters/dateParts.d.ts +25 -0
  53. package/dist/helpers/twigWrapper/filters/dateParts.mjs +56 -0
  54. package/dist/helpers/twigWrapper/filters/dates.d.ts +2 -0
  55. package/dist/helpers/twigWrapper/filters/dates.mjs +97 -0
  56. package/dist/helpers/twigWrapper/filters/filters.d.ts +3 -13
  57. package/dist/helpers/twigWrapper/filters/filters.mjs +25 -483
  58. package/dist/helpers/twigWrapper/filters/hashing.d.ts +3 -0
  59. package/dist/helpers/twigWrapper/filters/hashing.mjs +101 -0
  60. package/dist/helpers/twigWrapper/filters/index.mjs +4 -1
  61. package/dist/helpers/twigWrapper/filters/misc.d.ts +5 -0
  62. package/dist/helpers/twigWrapper/filters/misc.mjs +52 -0
  63. package/dist/helpers/twigWrapper/filters/numbers.d.ts +2 -0
  64. package/dist/helpers/twigWrapper/filters/numbers.mjs +36 -0
  65. package/dist/helpers/twigWrapper/filters/objects.d.ts +3 -0
  66. package/dist/helpers/twigWrapper/filters/objects.mjs +61 -0
  67. package/dist/helpers/twigWrapper/filters/raw.d.ts +8 -0
  68. package/dist/helpers/twigWrapper/filters/raw.mjs +7 -0
  69. package/dist/helpers/twigWrapper/filters/strings.d.ts +7 -0
  70. package/dist/helpers/twigWrapper/filters/strings.mjs +79 -0
  71. package/dist/helpers/twigWrapper/filters/types.d.ts +5 -0
  72. package/dist/helpers/twigWrapper/filters/types.mjs +4 -0
  73. package/dist/helpers/twigWrapper/filters/values.d.ts +12 -0
  74. package/dist/helpers/twigWrapper/filters/values.mjs +17 -0
  75. package/dist/helpers/twigWrapper/inspectTemplate.d.ts +5 -0
  76. package/dist/helpers/twigWrapper/inspectTemplate.mjs +39 -20
  77. package/dist/helpers/utils.d.ts +4 -0
  78. package/dist/helpers/utils.mjs +3 -5
  79. package/dist/navigation/index.d.ts +2 -0
  80. package/dist/navigation/index.mjs +2 -1
  81. package/dist/navigation/sitemap.d.ts +16 -0
  82. package/dist/navigation/sitemap.mjs +25 -0
  83. package/dist/network/entitlements.d.ts +101 -0
  84. package/dist/network/entitlements.mjs +4 -0
  85. package/dist/network/graphql/builder/Mutations/Space/SpaceRunE2eTestsMutation.d.ts +31 -0
  86. package/dist/network/graphql/builder/Mutations/Space/SpaceRunE2eTestsMutation.mjs +13 -0
  87. package/dist/network/graphql/builder/Mutations/Space/SpaceSetTestsMutation.d.ts +5 -0
  88. package/dist/network/graphql/builder/Mutations/Space/SpaceSetTestsMutation.mjs +11 -0
  89. package/dist/network/graphql/builder/Mutations/Space/SpaceUpdateSettingsMutation.d.ts +1 -1
  90. package/dist/network/graphql/builder/Mutations/Space/SpaceUpdateSettingsMutation.mjs +1 -1
  91. package/dist/network/graphql/builder/Mutations/index.d.ts +5 -0
  92. package/dist/network/graphql/builder/Mutations/index.mjs +150 -146
  93. package/dist/network/graphql/builder/Queries/Space/SpaceTestsQuery.d.ts +40 -0
  94. package/dist/network/graphql/builder/Queries/Space/SpaceTestsQuery.mjs +24 -0
  95. package/dist/network/graphql/builder/Queries/index.d.ts +3 -0
  96. package/dist/network/graphql/builder/Queries/index.mjs +44 -42
  97. package/dist/network/graphql/sdk/Queries/InitQuery.d.ts +3 -1
  98. package/dist/network/graphql/sdk/Queries/InitQuery.mjs +1 -1
  99. package/dist/network/index.d.ts +1 -0
  100. package/dist/network/index.mjs +9 -8
  101. package/dist/network/spaceEvents.d.ts +20 -1
  102. package/dist/network/spaceEvents.mjs +12 -0
  103. package/dist/project/index.mjs +8 -5
  104. package/dist/project/layout/check.d.ts +22 -0
  105. package/dist/project/layout/check.mjs +60 -0
  106. package/dist/project/{layout.d.ts → layout/codes.d.ts} +3 -66
  107. package/dist/project/layout/codes.mjs +108 -0
  108. package/dist/project/layout/contents.d.ts +10 -0
  109. package/dist/project/layout/contents.mjs +31 -0
  110. package/dist/project/layout/files.d.ts +31 -0
  111. package/dist/project/layout/files.mjs +49 -0
  112. package/dist/project/layout/folders.d.ts +4 -0
  113. package/dist/project/layout/folders.mjs +69 -0
  114. package/dist/project/layout/index.d.ts +16 -0
  115. package/dist/project/layout/index.mjs +5 -0
  116. package/dist/project/layout/plugins.d.ts +46 -0
  117. package/dist/project/layout/plugins.mjs +99 -0
  118. package/dist/project/layout/vendor.d.ts +15 -0
  119. package/dist/project/layout/vendor.mjs +34 -0
  120. package/dist/project/pages/index.d.ts +8 -0
  121. package/dist/project/pages/index.mjs +14 -0
  122. package/dist/project/paths/index.d.ts +52 -4
  123. package/dist/project/paths/index.mjs +2 -2
  124. package/dist/project/root.d.ts +6 -0
  125. package/dist/project/root.mjs +11 -10
  126. package/dist/realtime/client.mjs +104 -91
  127. package/dist/realtime/presence.d.ts +2 -2
  128. package/dist/realtime/presence.mjs +27 -21
  129. package/dist/runs/index.d.ts +73 -0
  130. package/dist/runs/index.mjs +6 -0
  131. package/dist/runs/report.d.ts +56 -0
  132. package/dist/runs/report.mjs +17 -0
  133. package/dist/schema/index.d.ts +6 -0
  134. package/dist/schema/index.mjs +18 -12
  135. package/dist/schema/motion.d.ts +25 -0
  136. package/dist/schema/motion.mjs +47 -19
  137. package/dist/schema/pageAccess.d.ts +6 -0
  138. package/dist/schema/pageAccess.mjs +8 -3
  139. package/dist/schema/pageHead.d.ts +64 -0
  140. package/dist/schema/pageHead.mjs +68 -0
  141. package/dist/schema/providerAnswer.d.ts +17 -0
  142. package/dist/schema/providerAnswer.mjs +4 -0
  143. package/dist/schema/providerWhen.d.ts +36 -0
  144. package/dist/schema/providerWhen.mjs +58 -0
  145. package/dist/schema/schemaSettings.d.ts +14 -0
  146. package/dist/schema/schemaSettings.mjs +4 -0
  147. package/dist/schema/serverElements.d.ts +20 -1
  148. package/dist/schema/serverElements.mjs +41 -28
  149. package/dist/schema/serverInput.d.ts +34 -0
  150. package/dist/schema/serverInput.mjs +60 -0
  151. package/dist/schema/serverQuery.d.ts +47 -0
  152. package/dist/schema/serverQuery.mjs +70 -0
  153. package/dist/server/index.mjs +5 -5
  154. package/dist/server/rsc/refreshRsc.d.ts +6 -2
  155. package/dist/server/rsc/refreshRsc.mjs +75 -59
  156. package/dist/server/rsc/useRscSync.mjs +22 -18
  157. package/dist/source/export.d.ts +1 -1
  158. package/dist/state/index.mjs +3 -3
  159. package/dist/state/paintedState.d.ts +20 -4
  160. package/dist/state/paintedState.mjs +13 -12
  161. package/dist/state/runtimeStatePersist.mjs +109 -48
  162. package/dist/store/renderSettings.d.ts +2 -0
  163. package/dist/store/renderSettings.mjs +13 -5
  164. package/dist/store/storeHooks.d.ts +45 -45
  165. package/dist/style/index.mjs +16 -16
  166. package/dist/style/styleConstants.d.ts +12 -2
  167. package/dist/style/styleConstants.mjs +20 -0
  168. package/dist/style/styleStates.d.ts +5 -0
  169. package/dist/style/styleStates.mjs +21 -5
  170. package/dist/types/ActionTypes.d.ts +26 -3
  171. package/dist/types/AuthTypes.d.ts +19 -1
  172. package/dist/types/CommonTypes.d.ts +3 -2
  173. package/dist/types/ElementTypes.d.ts +1 -1
  174. package/dist/types/InteractionTypes.d.ts +10 -1
  175. package/dist/types/JobTypes.d.ts +2 -1
  176. package/dist/types/OAuthTypes.d.ts +246 -0
  177. package/dist/types/OAuthTypes.mjs +0 -0
  178. package/dist/types/PluginTypes.d.ts +2 -0
  179. package/dist/types/PreviewTypes.d.ts +71 -0
  180. package/dist/types/PreviewTypes.mjs +0 -0
  181. package/dist/types/RealtimeTypes.d.ts +11 -0
  182. package/dist/types/SchemaTypes.d.ts +63 -0
  183. package/dist/types/ServerAdapterTypes.d.ts +345 -0
  184. package/dist/types/ServerAdapterTypes.mjs +0 -0
  185. package/dist/types/ServerConfigTypes.d.ts +527 -0
  186. package/dist/types/ServerConfigTypes.mjs +0 -0
  187. package/dist/types/ServerLogTypes.d.ts +119 -0
  188. package/dist/types/ServerLogTypes.mjs +0 -0
  189. package/dist/types/ServerTypes.d.ts +30 -1215
  190. package/dist/types/StoreTypes.d.ts +39 -1
  191. package/dist/types/TestTypes.d.ts +249 -0
  192. package/dist/types/TestTypes.mjs +0 -0
  193. package/dist/types/index.d.ts +6 -0
  194. package/eslint.config.mjs +3 -1
  195. package/package.json +2 -2
  196. package/setupTests.ts +4 -3
  197. package/dist/project/layout.mjs +0 -394
@@ -0,0 +1,99 @@
1
+ import { isFunctionsDefinitionFile as e } from "../../actions/functions.mjs";
2
+ import { finding as t } from "./codes.mjs";
3
+ import { CASE_NOTE as n, JAVASCRIPT_ENTRY as r, NOT_SOURCE as i, TYPE_NAME as a, capitalized as o, entriesOf as s, exists as c, gitMove as l, holdsSource as u, nearName as d, sameIgnoringCase as f } from "./files.mjs";
4
+ import { PLUGINS_DIR as p, PLUGIN_DECLARATION_FILE as m, PLUGIN_ENTRIES as h, PLUGIN_FUNCTIONS_DIR as g, VENDOR_PLUGINS_DIR as _ } from "../paths/index.mjs";
5
+ import { readVendorPlugin as v } from "./vendor.mjs";
6
+ import y from "node:path";
7
+ //#region src/project/layout/plugins.ts
8
+ var b = (e) => `${e.charAt(0).toLowerCase()}${e.slice(1)}`, x = (e) => {
9
+ let t = e.split(/[^A-Za-z0-9]+/).filter(Boolean).map(o).join(""), n = /^\d+/.exec(t)?.[0] ?? "", r = `${o(t.slice(n.length))}${n}`;
10
+ return a.test(r) ? r : void 0;
11
+ }, S = (e) => {
12
+ let { files: t } = s(e), n = h.filter((e) => t.includes(e));
13
+ return n.length === 1 ? y.join(e, n[0]) : void 0;
14
+ }, C = (e, t) => a.test(t) ? S(y.join(e, p, t)) : void 0, w = (e) => e.length > 1 ? `${e[0]} (or ${e.slice(1).join(", ")})` : e[0], T = (e, i) => {
15
+ let { folder: a, accepted: o, code: u, lost: p } = i, m = s(y.join(e, a)), h = o.filter((e) => m.files.includes(e));
16
+ if (h.length === 1) return [];
17
+ if (h.length > 1) return [t("plugin-entry-ambiguous", `${a}/`, `${a}/ has both ${h.join(" and ")}, and a plugin is built from one of them.`, `Keep one — ${h[h.length - 1]} when it writes JSX — and delete the other.`)];
18
+ let g = m.files.find((e) => r.test(e));
19
+ if (g) {
20
+ let e = g.endsWith(".jsx") && o.includes("index.tsx") ? "index.tsx" : "index.ts";
21
+ return [t("entry-not-typescript", `${a}/${g}`, `${a}/${g} is JavaScript, and ${a}/ is built from ${w(o)}: the project's code is TypeScript, so ${p}.`, `Rename it ${e} — JavaScript is TypeScript already, types left out: ${l(`${a}/${g}`, `${a}/${e}`)}`, {
22
+ action: "move",
23
+ from: `${a}/${g}`,
24
+ to: `${a}/${e}`
25
+ })];
26
+ }
27
+ let _ = m.files.find((e) => o.some((t) => d(e, t)));
28
+ if (_) {
29
+ let e = o.find((e) => d(_, e)) ?? o[0];
30
+ return [t(u, `${a}/${_}`, `${a}/ has no ${e} — did you mean ${_}? Named otherwise, ${p}.${f(_, e) ? ` ${n}` : ""}`, `Rename it ${e}: ${l(`${a}/${_}`, `${a}/${e}`)}`, {
31
+ action: "move",
32
+ from: `${a}/${_}`,
33
+ to: `${a}/${e}`
34
+ })];
35
+ }
36
+ let v = m.folders.find((t) => o.some((n) => c(e, `${a}/${t}/${n}`, "file")));
37
+ return v ? [t(u, `${a}/${v}/`, `${a}/ has no ${w(o)}, and ${a}/${v}/ has: one folder too deep, so ${p}.`, `Move what ${a}/${v}/ holds up into ${a}/.`, {
38
+ action: "move",
39
+ from: `${a}/${v}/`,
40
+ to: `${a}/`
41
+ })] : [t(u, `${a}/`, `${a}/ has no ${w(o)}, so ${p}.`, i.write)];
42
+ }, E = (n, r) => {
43
+ let i = s(y.join(n, r.folder));
44
+ if (!u(i) || i.files.some(e)) return [];
45
+ let a = i.folders.find((t) => s(y.join(n, r.folder, t)).files.some(e));
46
+ return [t(r.code, `${r.folder}/${a === void 0 ? "" : `${a}/`}`, `${r.folder}/ has no file at its top${a === void 0 ? "" : `, and ${r.folder}/${a}/ has: a folder there is helpers`}, so ${r.lost}.`, r.write)];
47
+ }, D = (e, t) => u(s(y.join(e, t.folder))) ? T(e, t) : [], O = (e) => {
48
+ let n = x(e), r = `${p}/${e}`;
49
+ return t("plugin-name-invalid", `${r}/`, `${r}/ cannot be a plugin: a folder of ${p}/ is registered as the element type its name makes, and a type is a letter followed by letters and digits.${n ? ` Did you mean ${n}?` : ""}`, n ? `Rename it ${n} — the type ${b(n)}: ${l(r, `${p}/${n}`)}; then type: '${b(n)}' in its ${m}, and renderType: '${b(n)}' where the space renders it.` : "Rename it with letters and digits, starting with a letter: StatCard is the type statCard.");
50
+ }, k = (e, t) => e.find((e) => e === `${t}.tsx`) ?? e.find((e) => e === `${t}.ts`), A = (e, r) => {
51
+ let i = `${p}/${r}`, { files: a } = s(y.join(e, i));
52
+ if (a.includes("declaration.ts")) return [];
53
+ let o = b(r), c = `authoring holds none of the space's ${o} elements to its attributes, and the builder does not offer it`, u = a.find((e) => d(e, m));
54
+ return u ? [t("plugin-declaration-missing", `${i}/${u}`, `${i}/ has no ${m} — did you mean ${u}? Named otherwise, ${c}.${f(u, "declaration.ts") ? ` ${n}` : ""}`, `Rename it ${m}: ${l(`${i}/${u}`, `${i}/${m}`)}`, {
55
+ action: "move",
56
+ from: `${i}/${u}`,
57
+ to: `${i}/${m}`
58
+ })] : [t("plugin-declaration-missing", `${i}/`, `${i}/ has no ${m}: ${c}.`, `Write ${i}/${m} — export default { type: '${o}', … } — as npx plitzi plugin add writes one beside the component it makes.`)];
59
+ }, j = (e, t) => {
60
+ if (!a.test(t)) return [O(t)];
61
+ let n = `${p}/${t}`, r = b(t), i = k(s(y.join(e, n)).files, t);
62
+ return [
63
+ ...T(e, {
64
+ folder: n,
65
+ accepted: h,
66
+ code: "plugin-entry-missing",
67
+ lost: `the server cannot build the plugin ${r}`,
68
+ write: `Write ${n}/index.ts exporting the component by default${i ? ` — export { default } from './${i}';` : ""} — as npx plitzi plugin add writes it. Every folder of ${p}/ is a plugin: code several plugins share goes outside it (src/shared/).`
69
+ }),
70
+ ...E(e, {
71
+ folder: `${n}/${g}`,
72
+ code: "plugin-functions-entry-missing",
73
+ lost: `none of the plugin's server half runs (its routes under /fn/plugins/${r}/)`,
74
+ write: `Write ${n}/${g}/index.ts exporting defineFunctions({ … }) by default — as npx plitzi plugin add --server writes it.`
75
+ }),
76
+ ...A(e, t)
77
+ ];
78
+ }, M = (e) => {
79
+ let n = /* @__PURE__ */ new Map();
80
+ for (let t of e.filter((e) => a.test(e))) n.set(b(t), [...n.get(b(t)) ?? [], t]);
81
+ return [...n].flatMap(([e, n]) => n.slice(1).map((r) => t("plugin-type-taken", `${p}/${r}/`, `${p}/${n[0]}/ and ${p}/${r}/ are both the plugin ${e}: the server registers a folder by its name with a small first letter, and keeps one.`, `Put them in one folder, or rename one: git mv ${p}/${r} ${p}/<AnotherName>`)));
82
+ }, N = (e) => {
83
+ let { files: n, folders: r } = s(y.join(e, p)), o = n.filter((e) => !i.has(e) && e !== "declarations.ts").map((e) => {
84
+ let { name: n } = y.parse(e), r = n !== "index" && x(n) || "<Name>";
85
+ return t("plugin-file-loose", `${p}/${e}`, `${p}/${e} is a file, and every plugin is a folder of ${p}/: the server reads nothing of it.`, `Give it a folder with an index.ts that exports it by default — ${p}/${r}/${e} and ${p}/${r}/index.ts, as npx plitzi plugin add writes them — or move it out of ${p}/.`);
86
+ }), c = s(y.join(e, _)).folders, l = new Set(r.filter((e) => a.test(e)).map(b)), u = c.filter((e) => l.has(e)).map((e) => t("plugin-shadowed", `${_}/${e}/`, `${e} is both ${_}/${e}/, as it was built, and a folder of ${p}/: the server runs the built one, and a change to the source shows nowhere.`, `Delete ${_}/${e}/: the source is the plugin now.`)), d = c.flatMap((t) => {
87
+ let n = v(e, t);
88
+ return "problem" in n ? [n.problem] : [];
89
+ });
90
+ return [
91
+ ...r.flatMap((t) => j(e, t)),
92
+ ...M(r),
93
+ ...o,
94
+ ...u,
95
+ ...d
96
+ ];
97
+ };
98
+ //#endregion
99
+ export { j as checkPluginFolder, S as elementEntry, T as entryFindings, E as functionsFindings, C as pluginEntry, N as pluginFindings, b as pluginTypeOf, D as sourceEntryFindings };
@@ -0,0 +1,15 @@
1
+ import { LayoutFinding } from './codes';
2
+ /** What a built plugin runs, by absolute path: its script, its style and its server half, as its manifest names them. */
3
+ export interface VendorPlugin {
4
+ script: string;
5
+ style?: string;
6
+ version: string;
7
+ functions?: string;
8
+ }
9
+ /**
10
+ * A plugin of `vendor/plugins/` — one a project made from a space runs as it was built, beside the manifest `plitzi
11
+ * pack plugin` wrote when it was published — or what keeps it from running.
12
+ */
13
+ export declare const readVendorPlugin: (root: string, type: string) => VendorPlugin | {
14
+ problem: LayoutFinding;
15
+ };
@@ -0,0 +1,34 @@
1
+ import { isRecord as e } from "../../helpers/isRecord.mjs";
2
+ import { finding as t } from "./codes.mjs";
3
+ import { exists as n } from "./files.mjs";
4
+ import { PLUGIN_MANIFEST_FILE as r, VENDOR_PLUGINS_DIR as i } from "../paths/index.mjs";
5
+ import a from "node:path";
6
+ import { readFileSync as o } from "node:fs";
7
+ //#region src/project/layout/vendor.ts
8
+ var s = (t) => e(t.assets) ? Object.values(t.assets).flatMap((t) => e(t) && typeof t.src == "string" && typeof t.type == "string" ? [{
9
+ src: t.src,
10
+ type: t.type,
11
+ isMain: t.isMain === !0
12
+ }] : []) : [], c = (c, l) => {
13
+ let u = `${i}/${l}`, d = `${u}/${r}`, f = `npx plitzi space pull brings it again — or delete ${u}/, and the space renders no ${l}.`;
14
+ if (!n(c, d, "file")) return { problem: t("vendor-manifest-missing", `${u}/`, `${u}/ has no ${r}: the server runs a built plugin by what its manifest names, so ${l} does not run.`, f) };
15
+ let p;
16
+ try {
17
+ p = JSON.parse(o(a.join(c, d), "utf-8"));
18
+ } catch (e) {
19
+ return { problem: t("vendor-manifest-invalid", d, `${d} is not JSON (${e instanceof Error ? e.message : String(e)}), so ${l} does not run.`, f) };
20
+ }
21
+ if (!e(p)) return { problem: t("vendor-manifest-invalid", d, `${d} is not a manifest, so ${l} does not run.`, f) };
22
+ let m = s(p), h = m.find((e) => e.type === "script" && e.isMain) ?? m.find((e) => e.type === "script");
23
+ if (!h) return { problem: t("vendor-script-missing", d, `${d} names no script to run, so ${l} does not run.`, f) };
24
+ if (!n(c, a.posix.join(u, h.src), "file")) return { problem: t("vendor-script-missing", d, `${d} names ${h.src} as the script to run, and ${u}/${h.src} is not there, so ${l} does not run.`, f) };
25
+ let g = m.find((e) => e.type === "style");
26
+ return {
27
+ script: a.join(c, u, h.src),
28
+ ...g ? { style: a.join(c, u, g.src) } : {},
29
+ version: typeof p.version == "string" ? p.version : "1.0.0",
30
+ ...typeof p.functions == "string" ? { functions: a.join(c, u, p.functions) } : {}
31
+ };
32
+ };
33
+ //#endregion
34
+ export { c as readVendorPlugin };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The modules a folder of pages holds, by convention (`@plitzi/sdk-authoring/node`'s `pagesIn`): each module directly in
3
+ * it — `pets.ts` — and each folder's `index` — `home/index.ts`, whose other modules are its own. Absolute, in path order:
4
+ * one rule for the authoring that imports them and for the CLI that follows a project's imports through them, so a page
5
+ * is part of the space by being there, for both. None when the folder is not there. An entry of its own: the server,
6
+ * which loads `@plitzi/sdk-shared/project`, never reads it.
7
+ */
8
+ export declare const pageModulesIn: (folder: string) => string[];
@@ -0,0 +1,14 @@
1
+ import e from "node:path";
2
+ import { existsSync as t, readdirSync as n } from "node:fs";
3
+ //#region src/project/pages/index.ts
4
+ var r = /\.(?:[cm]?[jt]sx?)$/, i = /\.(?:test|spec)\.[cm]?[jt]sx?$|\.d\.[cm]?ts$/, a = [
5
+ "index.ts",
6
+ "index.tsx",
7
+ "index.js"
8
+ ], o = (o) => t(o) ? n(o, { withFileTypes: !0 }).flatMap((n) => {
9
+ if (n.isFile()) return r.test(n.name) && !i.test(n.name) ? [e.join(o, n.name)] : [];
10
+ let s = n.isDirectory() ? a.find((r) => t(e.join(o, n.name, r))) : void 0;
11
+ return s ? [e.join(o, n.name, s)] : [];
12
+ }).sort() : [];
13
+ //#endregion
14
+ export { o as pageModulesIn };
@@ -10,19 +10,31 @@
10
10
  * glance what is the project and what is a by-product of running it.
11
11
  */
12
12
  export declare const PROJECT_TMP = "tmp";
13
+ /**
14
+ * Where `plitzi run` keeps a run of agents: each task's copy of the project lives below it. A copy holds no
15
+ * `.env` on purpose — an agent never reads credentials — so a check run inside one says nothing of a missing one.
16
+ */
17
+ export declare const RUNS_DIR = "tmp/plitzi-runs";
18
+ /**
19
+ * The project's one open run, named (`{ runId, since, by }`): created when a run opens, gone with it. What the project's
20
+ * own server reads to say, while developing, that it serves the project as it is and not the agents' work.
21
+ */
22
+ export declare const ACTIVE_RUN_FILE = "tmp/plitzi-runs/active.json";
13
23
  /** The project's own code — its space, plugins, data, functions and server — which the server watches while developing. */
14
24
  export declare const SOURCE_DIR = "src";
15
25
  /**
16
26
  * The CLI's own part of a project — the script that authors the space, the types its plugins import besides code, the
17
- * page's base styles — apart from `src/`, which is the project's: `plitzi upgrade` keeps this folder current, and a
18
- * person reads `src/` without wading through it.
27
+ * page's base styles — beside what it records (`scaffold.json`, `space.json`, `team.json`), in one folder: apart from
28
+ * `src/`, which is the project's. `plitzi upgrade` keeps it current, and a person reads `src/` without wading through it.
19
29
  */
20
- export declare const CLI_DIR = "plitzi";
30
+ export declare const CLI_DIR = ".plitzi";
31
+ /** Where an older CLI kept its part of the project: `plitzi doctor --fix` moves it into `CLI_DIR`. */
32
+ export declare const LEGACY_CLI_DIR = "plitzi";
21
33
  /**
22
34
  * What authors the space and says what it found: `npm run author`, and the server's re-authoring on a save, which runs
23
35
  * it in a process of its own and is handed the documents over IPC (`--ipc`).
24
36
  */
25
- export declare const AUTHOR_FILE = "plitzi/author.ts";
37
+ export declare const AUTHOR_FILE = ".plitzi/author.ts";
26
38
  /**
27
39
  * The space, in a folder of its own — it grows a page, a layout, a component at a time — whose `index.ts` exports it as
28
40
  * `space`: what the server's entry point, the author script, the visual test and the CLI's checks import.
@@ -87,5 +99,41 @@ export declare const BUILD_DIR = "dist";
87
99
  export declare const PROJECT_STATE = "state";
88
100
  /** The `kv` a project's server keeps, as one JSON file (`createFileKv`). */
89
101
  export declare const KV_FILE = "state/kv.json";
102
+ /**
103
+ * The job queue a project's server keeps beside its `kv` — what `ctx.later`, the schedules and the functions' jobs wait
104
+ * in — as one JSON file (`createFileJobQueue`): a job due while the server was down runs once it is back.
105
+ */
106
+ export declare const JOBS_FILE = "state/jobs.json";
107
+ /**
108
+ * What `plitzi functions later` asks the project's running server, and where it answers: the server holds its queue's
109
+ * file, so a run set for later is read and started now through it — a spec of a show waited five real minutes a pass.
110
+ */
111
+ export declare const LATER_ASK_FILE = "tmp/later-ask.json";
112
+ export declare const LATER_ANSWER_FILE = "tmp/later-answer.json";
90
113
  /** The port the server took and the name its `/health` answers with: what `check`, `shot` and `visual` find it by. */
91
114
  export declare const DEV_SERVER_FILE = "tmp/dev-server.json";
115
+ /**
116
+ * Where a project's server writes its record instead of \`DEV_SERVER_FILE\`, when this variable says: the visual suite's
117
+ * own server keeps its record apart, so the one a person runs is still what \`check\` and \`shot\` find.
118
+ */
119
+ export declare const SERVER_RECORD_ENV = "PLITZI_SERVER_RECORD";
120
+ /**
121
+ * Where a project's server keeps what it holds instead of \`PROJECT_STATE\` — its \`kv\` and its job queue, when the
122
+ * project names no store of its own — and where a store the project opens itself should go too: the visual suite's own
123
+ * server keeps its own state, as it keeps its own record. One file is held by one process: its server beside a
124
+ * person's open one was refused ("createFileKv … is in use"), and a run read \`PLITZI_KV_FILE\` — the jobs' file
125
+ * followed it unsaid — as dead beside a sqlite \`kv\`, and its suite ran the person's queued jobs.
126
+ */
127
+ export declare const STATE_DIR_ENV = "PLITZI_STATE_DIR";
128
+ /**
129
+ * A JSON file naming one element to draw alone — `{ "element": "planCard", "copies": [{ … }, { … }] }`, a component of
130
+ * the space or an element type, each copy with its props or attributes — for which the project's authored space gets a
131
+ * page of its own at `PREVIEW_SLUG`, with no layout. Set only for a server started for that (`plitzi task look
132
+ * --alone`): a plugin or a component no page places yet, looked at like any page — a run's reviewers wrote probe pages
133
+ * in their scratch to see one.
134
+ */
135
+ export declare const PREVIEW_FILE_ENV = "PLITZI_PREVIEW_FILE";
136
+ /** Where the page of `PREVIEW_FILE_ENV` answers. */
137
+ export declare const PREVIEW_SLUG = "plitzi-preview";
138
+ /** The id each copy on that page is drawn with — `plitzi-preview-1`, `-2`… — what a look or a measure names it by. */
139
+ export declare const previewCopyId: (index: number) => string;
@@ -1,4 +1,4 @@
1
1
  //#region src/project/paths/index.ts
2
- var e = "tmp", t = "src", n = "plitzi", r = `${n}/author.ts`, i = "src/space", a = `${i}/index.ts`, o = "src/plugins", s = ["index.ts", "index.tsx"], c = "declaration.ts", l = "functions", u = "vendor/plugins", d = "plugin-manifest.json", f = "vendor/runtime.bundle", p = "public", m = "src/data", h = "/data/", g = "src/functions", _ = "src/runtime", v = `${_}/index.ts`, y = "dist", b = "state", x = `${b}/kv.json`, S = "tmp/dev-server.json";
2
+ var e = "tmp", t = "tmp/plitzi-runs", n = `${t}/active.json`, r = "src", i = ".plitzi", a = "plitzi", o = `${i}/author.ts`, s = "src/space", c = `${s}/index.ts`, l = "src/plugins", u = ["index.ts", "index.tsx"], d = "declaration.ts", f = "functions", p = "vendor/plugins", m = "plugin-manifest.json", h = "vendor/runtime.bundle", g = "public", _ = "src/data", v = "/data/", y = "src/functions", b = "src/runtime", x = `${b}/index.ts`, S = "dist", C = "state", w = `${C}/kv.json`, T = `${C}/jobs.json`, E = "tmp/later-ask.json", D = "tmp/later-answer.json", O = "tmp/dev-server.json", k = "PLITZI_SERVER_RECORD", A = "PLITZI_STATE_DIR", j = "PLITZI_PREVIEW_FILE", M = "plitzi-preview", N = (e) => `${M}-${String(e + 1)}`;
3
3
  //#endregion
4
- export { r as AUTHOR_FILE, y as BUILD_DIR, n as CLI_DIR, m as DATA_DIR, S as DEV_SERVER_FILE, g as FUNCTIONS_DIR, x as KV_FILE, o as PLUGINS_DIR, c as PLUGIN_DECLARATION_FILE, s as PLUGIN_ENTRIES, l as PLUGIN_FUNCTIONS_DIR, d as PLUGIN_MANIFEST_FILE, h as PROJECT_DATA_PREFIX, b as PROJECT_STATE, e as PROJECT_TMP, p as PUBLIC_DIR, f as RUNTIME_BUNDLE, _ as RUNTIME_DIR, v as RUNTIME_ENTRY, t as SOURCE_DIR, i as SPACE_DIR, a as SPACE_ENTRY, u as VENDOR_PLUGINS_DIR };
4
+ export { n as ACTIVE_RUN_FILE, o as AUTHOR_FILE, S as BUILD_DIR, i as CLI_DIR, _ as DATA_DIR, O as DEV_SERVER_FILE, y as FUNCTIONS_DIR, T as JOBS_FILE, w as KV_FILE, D as LATER_ANSWER_FILE, E as LATER_ASK_FILE, a as LEGACY_CLI_DIR, l as PLUGINS_DIR, d as PLUGIN_DECLARATION_FILE, u as PLUGIN_ENTRIES, f as PLUGIN_FUNCTIONS_DIR, m as PLUGIN_MANIFEST_FILE, j as PREVIEW_FILE_ENV, M as PREVIEW_SLUG, v as PROJECT_DATA_PREFIX, C as PROJECT_STATE, e as PROJECT_TMP, g as PUBLIC_DIR, t as RUNS_DIR, h as RUNTIME_BUNDLE, b as RUNTIME_DIR, x as RUNTIME_ENTRY, k as SERVER_RECORD_ENV, r as SOURCE_DIR, s as SPACE_DIR, c as SPACE_ENTRY, A as STATE_DIR_ENV, p as VENDOR_PLUGINS_DIR, N as previewCopyId };
@@ -22,3 +22,9 @@ export declare const projectRoot: () => string;
22
22
  * still finds the source, and one run compiled never imports a `.ts` file.
23
23
  */
24
24
  export declare const projectModule: (root: string, entry: string, script: string | undefined) => string;
25
+ /**
26
+ * Which copy of a project a folder is, in a few letters: the same for every process run there, another for its copy in
27
+ * another folder — two copies of one project answer `/health` with the same name, and a tool reaching a port tells its
28
+ * own copy from another's by this. The folder is hashed, so a server open to its network does not say where it is.
29
+ */
30
+ export declare const projectMark: (root: string) => string;
@@ -1,26 +1,27 @@
1
1
  import { BUILD_DIR as e } from "./paths/index.mjs";
2
2
  import t from "node:path";
3
3
  import { existsSync as n, realpathSync as r } from "node:fs";
4
+ import { createHash as i } from "node:crypto";
4
5
  //#region src/project/root.ts
5
- var i = ["package.json", "src/"], a = class extends Error {
6
+ var a = ["package.json", "src/"], o = class extends Error {
6
7
  constructor(e, t) {
7
8
  super(`${e} is not the root of a Plitzi project: it has no ${t.join(" and no ")}. Run it from the project's root, the folder its package.json is in — where its scripts run it (npm start, npm run author).`), this.name = "ProjectRootError";
8
9
  }
9
10
  };
10
- Object.defineProperty(a, "name", { value: "ProjectRootError" });
11
- var o = (e) => {
12
- let r = i.filter((r) => !n(t.join(e, r)));
13
- if (r.length > 0) throw new a(e, r);
11
+ Object.defineProperty(o, "name", { value: "ProjectRootError" });
12
+ var s = (e) => {
13
+ let r = a.filter((r) => !n(t.join(e, r)));
14
+ if (r.length > 0) throw new o(e, r);
14
15
  return e;
15
- }, s = () => o(process.cwd()), c = (e) => {
16
+ }, c = () => s(process.cwd()), l = (e) => {
16
17
  try {
17
18
  return r(e);
18
19
  } catch {
19
20
  return t.resolve(e);
20
21
  }
21
- }, l = (n, r, i) => {
22
- let a = c(t.join(n, e)), o = i !== void 0 && c(i).startsWith(`${a}${t.sep}`);
22
+ }, u = (n, r, i) => {
23
+ let a = l(t.join(n, e)), o = i !== void 0 && l(i).startsWith(`${a}${t.sep}`);
23
24
  return t.join(n, o ? t.join(e, t.relative("src", r)).replace(/\.tsx?$/, ".js") : r);
24
- };
25
+ }, d = (e) => i("sha256").update(l(e)).digest("hex").slice(0, 12);
25
26
  //#endregion
26
- export { a as ProjectRootError, o as checkProjectRoot, l as projectModule, s as projectRoot };
27
+ export { o as ProjectRootError, s as checkProjectRoot, d as projectMark, u as projectModule, c as projectRoot };
@@ -7,7 +7,7 @@ var t = 30, n = [
7
7
  2e3,
8
8
  5e3,
9
9
  1e4
10
- ], r = 5e3, i = (e) => typeof e == "object" && !!e && "connection" in e && typeof e.connection == "string" && "refused" in e && Array.isArray(e.refused), a = (e) => typeof e == "object" && !!e && "topic" in e && typeof e.topic == "string" && "type" in e && typeof e.type == "string", o = (e) => typeof e == "object" && !!e && "id" in e && typeof e.id == "number" && "ok" in e && typeof e.ok == "boolean", s = (e) => {
10
+ ], r = 5e3, i = 2e3, a = (e) => typeof e == "object" && !!e && "connection" in e && typeof e.connection == "string" && "refused" in e && Array.isArray(e.refused), o = (e) => typeof e == "object" && !!e && "topic" in e && typeof e.topic == "string" && "type" in e && typeof e.type == "string", s = (e) => typeof e == "object" && !!e && "id" in e && typeof e.id == "number" && "ok" in e && typeof e.ok == "boolean", c = (e) => {
11
11
  let t = "message", n = [];
12
12
  for (let r of e.split("\n")) r.startsWith("event: ") ? t = r.slice(7) : r.startsWith("data: ") && n.push(r.slice(6));
13
13
  if (n.length) try {
@@ -18,7 +18,7 @@ var t = 30, n = [
18
18
  } catch {
19
19
  return;
20
20
  }
21
- }, c = (e) => {
21
+ }, l = (e) => {
22
22
  try {
23
23
  let t = JSON.parse(String(e));
24
24
  return typeof t == "object" && t && "event" in t && typeof t.event == "string" ? {
@@ -28,60 +28,73 @@ var t = 30, n = [
28
28
  } catch {
29
29
  return;
30
30
  }
31
- }, l = (e, t) => {
31
+ }, u = (e, t) => {
32
32
  let n = new URL(`${e}?${t}`, globalThis.location.href);
33
33
  return n.protocol = n.protocol === "https:" ? "wss:" : "ws:", n.href;
34
- }, u = (e, { transport: u = "sse", fetchImpl: f = fetch, WebSocketImpl: p = globalThis.WebSocket } = {}) => {
35
- let m = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map(), g = /* @__PURE__ */ new Set(), _ = "idle", v, y = /* @__PURE__ */ new Map(), b, x, S = 0, C = u === "websocket" && typeof p == "function", w = () => [...m.keys()].sort().join(","), T = (e) => {
36
- _ = e;
37
- let t = w().split(",").filter(Boolean), n = v?.transport ?? (C ? "websocket" : "sse");
38
- d(e === "open" ? "success" : e === "closed" ? "warning" : "info", `${e} · ${t.join(", ") || "no topics"}`, {
34
+ }, d = (e, { transport: d = "sse", fetchImpl: p = fetch, WebSocketImpl: m = globalThis.WebSocket } = {}) => {
35
+ let h = /* @__PURE__ */ new Map(), g = /* @__PURE__ */ new Map(), _ = /* @__PURE__ */ new Set(), v = "idle", y, b, x = /* @__PURE__ */ new Set(), S = 0, C = /* @__PURE__ */ new Map(), w, T, E = 0, D = d === "websocket" && typeof m == "function", O = () => [...h.keys()].sort().join(","), k = (e) => {
36
+ v = e;
37
+ let t = O().split(",").filter(Boolean), n = y?.transport ?? (D ? "websocket" : "sse");
38
+ f(e === "open" ? "success" : e === "closed" ? "warning" : "info", `${e} · ${t.join(", ") || "no topics"}`, {
39
39
  event: "status",
40
40
  status: e,
41
41
  topics: t,
42
42
  transport: n
43
- }), g.forEach((t) => t(e));
44
- }, E = (e) => {
45
- for (let [t, n] of e) y.set(t, n), d("danger", `${t} refused: ${n}`, {
43
+ }), _.forEach((t) => t(e));
44
+ }, A = (e) => {
45
+ for (let [t, n] of e) C.set(t, n), f("danger", `${t} refused: ${n}`, {
46
46
  event: "refused",
47
47
  topic: t,
48
48
  reason: n
49
49
  });
50
- }, D = (e) => {
51
- let t = e.split(",").flatMap((e) => h.get(e) ?? []);
50
+ }, j = (e) => {
51
+ let t = e.split(",").flatMap((e) => g.get(e) ?? []);
52
52
  return `topics=${encodeURIComponent(e)}${t.length ? `&grants=${encodeURIComponent(t.join(","))}` : ""}`;
53
- }, O = (e) => {
54
- e.type === "$revoked" && e.from === "server" && E([[e.topic, "revoked"]]), d("info", `${e.topic} ← ${e.type}`, {
53
+ }, M = () => {
54
+ b && (b.close(), b = void 0, S = Date.now() + i);
55
+ }, N = (e) => {
56
+ if (!b && Date.now() > S) return x.clear(), !1;
57
+ let t = JSON.stringify([
58
+ e.topic,
59
+ e.type,
60
+ e.at,
61
+ e.from,
62
+ e.replayed,
63
+ e.data
64
+ ]);
65
+ return x.has(t) ? !0 : (x.add(t), !1);
66
+ }, P = (e) => {
67
+ N(e) || (e.type === "$revoked" && e.from === "server" && A([[e.topic, "revoked"]]), f("info", `${e.topic} ← ${e.type}`, {
55
68
  event: "received",
56
69
  message: e
57
- }), m.get(e.topic)?.forEach((t) => t(e));
58
- }, k = (e, t) => {
59
- e.me = t.connection, y = /* @__PURE__ */ new Map(), E(t.refused.map((e) => [e.topic, e.reason])), S = 0, T("open");
60
- }, A = (e) => {
61
- if (v !== e) return;
62
- T("connecting");
63
- let t = n[Math.min(S, n.length - 1)];
64
- S += 1, x = setTimeout(N, t);
65
- }, j = (t, n) => {
66
- let r = new AbortController(), o, c = {
70
+ }), h.get(e.topic)?.forEach((t) => t(e)));
71
+ }, F = (e, t) => {
72
+ e.ready = !0, M(), e.me = t.connection, C = /* @__PURE__ */ new Map(), A(t.refused.map((e) => [e.topic, e.reason])), E = 0, k("open");
73
+ }, I = (e) => {
74
+ if (y !== e) return;
75
+ M(), k("connecting");
76
+ let t = n[Math.min(E, n.length - 1)];
77
+ E += 1, T = setTimeout(z, t);
78
+ }, L = (t, n) => {
79
+ let r = new AbortController(), i, s = {
67
80
  topics: t,
68
81
  transport: "sse",
69
82
  close: () => r.abort(),
70
- publish: async (t, n, r, { echo: i }) => {
71
- if (!o) return !1;
72
- let a = await f(e, {
83
+ publish: async (t, n, r, { echo: a }) => {
84
+ if (!i) return !1;
85
+ let o = await p(e, {
73
86
  method: "POST",
74
87
  headers: { "content-type": "application/json" },
75
88
  credentials: "same-origin",
76
89
  body: JSON.stringify({
77
- token: o,
90
+ token: i,
78
91
  topic: t,
79
92
  type: n,
80
93
  data: r,
81
- ...i ? { echo: i } : {}
94
+ ...a ? { echo: a } : {}
82
95
  })
83
96
  }).catch(() => void 0);
84
- return a?.status === 401 && v === c && N(), a?.ok ?? !1;
97
+ return o?.status === 401 && y === s && z(), o?.ok ?? !1;
85
98
  }
86
99
  }, l = async (e) => {
87
100
  let t = e.body?.getReader();
@@ -93,94 +106,94 @@ var t = 30, n = [
93
106
  r += n.decode(l, { stream: !0 });
94
107
  let u = r.indexOf("\n\n");
95
108
  for (; u !== -1;) {
96
- let e = s(r.slice(0, u));
97
- r = r.slice(u + 2), u = r.indexOf("\n\n"), e?.event === "ready" && i(e.data) ? (o = e.data.token, k(c, e.data)) : e?.event === "message" && a(e.data) && O(e.data);
109
+ let e = c(r.slice(0, u));
110
+ r = r.slice(u + 2), u = r.indexOf("\n\n"), e?.event === "ready" && a(e.data) ? (i = e.data.token, F(s, e.data)) : e?.event === "message" && o(e.data) && P(e.data);
98
111
  }
99
112
  }
100
113
  };
101
- return f(`${e}?${n}`, {
114
+ return p(`${e}?${n}`, {
102
115
  headers: { accept: "text/event-stream" },
103
116
  credentials: "same-origin",
104
117
  signal: r.signal
105
118
  }).then(async (e) => {
106
- if (!e.ok) y = /* @__PURE__ */ new Map(), E(t.split(",").map((t) => [t, `http_${String(e.status)}`])), T("closed");
119
+ if (!e.ok) C = /* @__PURE__ */ new Map(), A(t.split(",").map((t) => [t, `http_${String(e.status)}`])), M(), k("closed");
107
120
  else throw await l(e), Error("The realtime stream ended");
108
121
  }).catch(() => {
109
- r.signal.aborted || A(c);
110
- }), c;
111
- }, M = (t, n) => {
112
- let s = new p(l(e, n)), u = /* @__PURE__ */ new Map(), d = 0, f = !1, m = !1, h = () => {
113
- u.forEach((e) => e(!1)), u.clear();
122
+ r.signal.aborted || I(s);
123
+ }), s;
124
+ }, R = (t, n) => {
125
+ let i = new m(u(e, n)), c = /* @__PURE__ */ new Map(), d = 0, f = !1, p = !1, h = () => {
126
+ c.forEach((e) => e(!1)), c.clear();
114
127
  }, g = {
115
128
  topics: t,
116
129
  transport: "websocket",
117
130
  close: () => {
118
- m = !0, h(), s.close();
131
+ p = !0, h(), i.close();
119
132
  },
120
- publish: (e, t, n, { echo: i }) => new Promise((a) => {
121
- if (s.readyState !== s.OPEN) {
122
- a(!1);
133
+ publish: (e, t, n, { echo: a }) => new Promise((o) => {
134
+ if (i.readyState !== i.OPEN) {
135
+ o(!1);
123
136
  return;
124
137
  }
125
138
  d += 1;
126
- let o = d, c = setTimeout(() => {
127
- u.delete(o), a(!1);
139
+ let s = d, l = setTimeout(() => {
140
+ c.delete(s), o(!1);
128
141
  }, r);
129
- u.set(o, (e) => {
130
- clearTimeout(c), a(e);
131
- }), s.send(JSON.stringify({
132
- id: o,
142
+ c.set(s, (e) => {
143
+ clearTimeout(l), o(e);
144
+ }), i.send(JSON.stringify({
145
+ id: s,
133
146
  topic: e,
134
147
  type: t,
135
148
  data: n,
136
- ...i ? { echo: i } : {}
149
+ ...a ? { echo: a } : {}
137
150
  }));
138
151
  })
139
152
  };
140
- return s.onmessage = (e) => {
141
- let t = c(e.data);
142
- t?.event === "ready" && i(t.data) ? (f = !0, k(g, t.data)) : t?.event === "message" && a(t.data) ? O(t.data) : t?.event === "ack" && o(t.data) && (u.get(t.data.id)?.(t.data.ok), u.delete(t.data.id));
143
- }, s.onclose = () => {
144
- h(), !(m || v !== g) && (f ? A(g) : (C = !1, N()));
153
+ return i.onmessage = (e) => {
154
+ let t = l(e.data);
155
+ t?.event === "ready" && a(t.data) ? (f = !0, F(g, t.data)) : t?.event === "message" && o(t.data) ? P(t.data) : t?.event === "ack" && s(t.data) && (c.get(t.data.id)?.(t.data.ok), c.delete(t.data.id));
156
+ }, i.onclose = () => {
157
+ h(), !(p || y !== g) && (f ? I(g) : (D = !1, z()));
145
158
  }, g;
146
159
  };
147
- function N() {
148
- v?.close(), v = void 0;
149
- let e = w();
160
+ function z() {
161
+ y?.ready ? (b?.close(), b = y) : y?.close(), y = void 0;
162
+ let e = O();
150
163
  if (!e) {
151
- T("idle");
164
+ M(), k("idle");
152
165
  return;
153
166
  }
154
- T("connecting");
155
- let t = D(e);
156
- v = C ? M(e, t) : j(e, t);
167
+ k("connecting");
168
+ let t = j(e);
169
+ y = D ? R(e, t) : L(e, t);
157
170
  }
158
- let P = (e = !1) => {
159
- clearTimeout(b), clearTimeout(x), b = setTimeout(() => {
160
- (e || v?.topics !== w()) && N();
171
+ let B = (e = !1) => {
172
+ clearTimeout(w), clearTimeout(T), w = setTimeout(() => {
173
+ (e || y?.topics !== O()) && z();
161
174
  }, t);
162
- }, F = (e) => _ === "open" && v?.topics.split(",").includes(e) === !0, I = (e) => F(e) ? Promise.resolve(!0) : new Promise((t) => {
175
+ }, V = (e) => v === "open" && y?.topics.split(",").includes(e) === !0, H = (e) => V(e) ? Promise.resolve(!0) : new Promise((t) => {
163
176
  let n = setTimeout(() => {
164
177
  i(), t(!1);
165
- }, r), i = L.onStatus((r) => {
166
- (r === "closed" || F(e)) && (clearTimeout(n), i(), t(r !== "closed"));
178
+ }, r), i = U.onStatus((r) => {
179
+ (r === "closed" || V(e)) && (clearTimeout(n), i(), t(r !== "closed"));
167
180
  });
168
- }), L = {
181
+ }), U = {
169
182
  subscribe: (e, t) => {
170
- let n = m.get(e) ?? /* @__PURE__ */ new Set();
171
- return n.add(t), m.set(e, n), P(), () => {
172
- n.delete(t), n.size || (m.delete(e), h.delete(e), P());
183
+ let n = h.get(e) ?? /* @__PURE__ */ new Set();
184
+ return n.add(t), h.set(e, n), B(), () => {
185
+ n.delete(t), n.size || (h.delete(e), g.delete(e), B());
173
186
  };
174
187
  },
175
188
  grant: (e, t) => {
176
- if (h.get(e) === t) return;
177
- t ? h.set(e, t) : h.delete(e);
178
- let n = F(e) && !y.has(e);
179
- t && m.has(e) && !n && P(!0);
189
+ if (g.get(e) === t) return;
190
+ t ? g.set(e, t) : g.delete(e);
191
+ let n = V(e) && !C.has(e);
192
+ t && h.has(e) && !n && B(!0);
180
193
  },
181
194
  publish: async (e, t, n, r = {}) => {
182
- let i = await I(e) && v ? await v.publish(e, t, n, r) : !1;
183
- return d(i ? "info" : "danger", `${e} → ${t}${i ? "" : " (not delivered)"}`, {
195
+ let i = await H(e) && y ? await y.publish(e, t, n, r) : !1;
196
+ return f(i ? "info" : "danger", `${e} → ${t}${i ? "" : " (not delivered)"}`, {
184
197
  event: "published",
185
198
  topic: e,
186
199
  type: t,
@@ -188,26 +201,26 @@ var t = 30, n = [
188
201
  delivered: i
189
202
  }), i;
190
203
  },
191
- onStatus: (e) => (g.add(e), () => g.delete(e)),
204
+ onStatus: (e) => (_.add(e), () => _.delete(e)),
192
205
  get status() {
193
- return _;
206
+ return v;
194
207
  },
195
208
  get me() {
196
- return v?.me;
209
+ return y?.me;
197
210
  },
198
211
  get transport() {
199
- return v?.transport ?? (C ? "websocket" : "sse");
212
+ return y?.transport ?? (D ? "websocket" : "sse");
200
213
  },
201
- refusal: (e) => y.get(e)
214
+ refusal: (e) => C.get(e)
202
215
  };
203
- return L;
204
- }, d = (t, n, r) => {
216
+ return U;
217
+ }, f = (t, n, r) => {
205
218
  t === "success" ? e.success("realtime", n, r) : t === "warning" ? e.warning("realtime", n, r) : t === "danger" ? e.danger("realtime", n, r) : e.info("realtime", n, r);
206
- }, f = /* @__PURE__ */ new Map(), p = (e, t = "sse") => {
207
- let n = `${t} ${e}`, r = f.get(n);
219
+ }, p = /* @__PURE__ */ new Map(), m = (e, t = "sse") => {
220
+ let n = `${t} ${e}`, r = p.get(n);
208
221
  if (r) return r;
209
- let i = u(e, { transport: t });
210
- return f.set(n, i), i;
222
+ let i = d(e, { transport: t });
223
+ return p.set(n, i), i;
211
224
  };
212
225
  //#endregion
213
- export { u as createRealtimeClient, p as realtimeClientFor };
226
+ export { d as createRealtimeClient, m as realtimeClientFor };