@plitzi/sdk-shared 0.37.2 → 0.37.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (184) hide show
  1. package/CHANGELOG.md +1146 -0
  2. package/dist/actions/access.d.ts +12 -0
  3. package/dist/actions/access.mjs +13 -0
  4. package/dist/actions/functions.d.ts +27 -0
  5. package/dist/actions/functions.mjs +18 -0
  6. package/dist/actions/index.d.ts +4 -0
  7. package/dist/actions/index.mjs +9 -7
  8. package/dist/auth/index.d.ts +2 -0
  9. package/dist/auth/index.mjs +2 -1
  10. package/dist/auth/visitorRoles.d.ts +27 -0
  11. package/dist/auth/visitorRoles.mjs +48 -0
  12. package/dist/authoring/builder.mjs +1 -0
  13. package/dist/authoring/declare.d.ts +53 -0
  14. package/dist/authoring/declare.mjs +2 -2
  15. package/dist/authoring/index.mjs +5 -5
  16. package/dist/authoring/paramSpec.d.ts +1 -1
  17. package/dist/authoring/paramSpec.mjs +1 -0
  18. package/dist/authoring/spaceCallbacks.mjs +2 -2
  19. package/dist/dataSource/computed.d.ts +21 -0
  20. package/dist/dataSource/computed.mjs +45 -0
  21. package/dist/dataSource/getBindingsDetails.mjs +35 -34
  22. package/dist/dataSource/index.d.ts +1 -0
  23. package/dist/dataSource/index.mjs +7 -6
  24. package/dist/dataSource/utility/not.mjs +4 -7
  25. package/dist/dataSource/utility/stringToArray.mjs +1 -1
  26. package/dist/dataSource/utility/truthiness.d.ts +1 -0
  27. package/dist/dataSource/utility/truthiness.mjs +8 -0
  28. package/dist/dataSource/utility/twigTemplate.d.ts +2 -1
  29. package/dist/dataSource/utility/twigTemplate.mjs +29 -17
  30. package/dist/devTools/utils/PlitziConsole.mjs +22 -22
  31. package/dist/helpers/cookies.d.ts +10 -0
  32. package/dist/helpers/cookies.mjs +19 -0
  33. package/dist/helpers/fetchManifest.d.ts +9 -0
  34. package/dist/helpers/fetchManifest.mjs +3 -6
  35. package/dist/helpers/formatDate.d.ts +5 -3
  36. package/dist/helpers/formatDate.mjs +34 -36
  37. package/dist/helpers/index.d.ts +2 -0
  38. package/dist/helpers/index.mjs +18 -14
  39. package/dist/helpers/isDate.d.ts +7 -0
  40. package/dist/helpers/isDate.mjs +15 -0
  41. package/dist/helpers/keys.d.ts +42 -0
  42. package/dist/helpers/keys.mjs +91 -0
  43. package/dist/helpers/twigWrapper/AST.d.ts +2 -2
  44. package/dist/helpers/twigWrapper/Evaluator/Evaluator.d.ts +12 -2
  45. package/dist/helpers/twigWrapper/Evaluator/Evaluator.mjs +57 -34
  46. package/dist/helpers/twigWrapper/Evaluator/index.d.ts +1 -1
  47. package/dist/helpers/twigWrapper/Evaluator/index.mjs +2 -2
  48. package/dist/helpers/twigWrapper/Parser/ExpressionParser.d.ts +2 -2
  49. package/dist/helpers/twigWrapper/Parser/ExpressionParser.mjs +147 -34
  50. package/dist/helpers/twigWrapper/Parser/Parser.d.ts +2 -1
  51. package/dist/helpers/twigWrapper/Parser/Parser.mjs +21 -20
  52. package/dist/helpers/twigWrapper/filters/filters.mjs +130 -112
  53. package/dist/helpers/twigWrapper/index.d.ts +5 -2
  54. package/dist/helpers/twigWrapper/index.mjs +7 -5
  55. package/dist/helpers/twigWrapper/inspectTemplate.d.ts +23 -0
  56. package/dist/helpers/twigWrapper/inspectTemplate.mjs +110 -0
  57. package/dist/helpers/twigWrapper/processTwig/helpers.d.ts +7 -0
  58. package/dist/helpers/twigWrapper/processTwig/helpers.mjs +2 -1
  59. package/dist/helpers/twigWrapper/processTwig/index.d.ts +2 -1
  60. package/dist/helpers/twigWrapper/processTwig/index.mjs +3 -2
  61. package/dist/helpers/twigWrapper/processTwig/processTwig.d.ts +28 -0
  62. package/dist/helpers/twigWrapper/processTwig/processTwig.mjs +73 -16
  63. package/dist/helpers/twigWrapper/processTwig/resolveStepParam.d.ts +17 -0
  64. package/dist/helpers/twigWrapper/processTwig/resolveStepParam.mjs +14 -0
  65. package/dist/helpers/twigWrapper/templateRoots.d.ts +11 -0
  66. package/dist/helpers/twigWrapper/templateRoots.mjs +4 -4
  67. package/dist/helpers/twigWrapper/tokens/hasTemplateSyntax.d.ts +1 -1
  68. package/dist/history/describe.d.ts +29 -0
  69. package/dist/history/describe.mjs +93 -0
  70. package/dist/history/diff.d.ts +33 -0
  71. package/dist/history/diff.mjs +73 -0
  72. package/dist/history/index.d.ts +3 -0
  73. package/dist/history/index.mjs +3 -0
  74. package/dist/history/types.d.ts +48 -0
  75. package/dist/history/types.mjs +0 -0
  76. package/dist/index.d.ts +1 -0
  77. package/dist/index.mjs +77 -66
  78. package/dist/navigation/index.d.ts +1 -1
  79. package/dist/navigation/index.mjs +2 -2
  80. package/dist/navigation/routes.d.ts +11 -1
  81. package/dist/navigation/routes.mjs +15 -10
  82. package/dist/network/graphql/builder/Mutations/Space/SpaceFixIssuesMutation.d.ts +14 -0
  83. package/dist/network/graphql/builder/Mutations/Space/SpaceFixIssuesMutation.mjs +16 -0
  84. package/dist/network/graphql/builder/Mutations/Space/SpaceUpdatePluginMutation.d.ts +4 -0
  85. package/dist/network/graphql/builder/Mutations/Space/SpaceUpdatePluginMutation.mjs +2 -2
  86. package/dist/network/graphql/builder/Mutations/Space/actions/SpaceRunActionMutation.mjs +1 -0
  87. package/dist/network/graphql/builder/Mutations/Space/functions/SpaceRemoveFunctionsMutation.d.ts +3 -0
  88. package/dist/network/graphql/builder/Mutations/Space/functions/SpaceRemoveFunctionsMutation.mjs +9 -0
  89. package/dist/network/graphql/builder/Mutations/Space/functions/SpaceSaveFunctionsMutation.d.ts +11 -0
  90. package/dist/network/graphql/builder/Mutations/Space/functions/SpaceSaveFunctionsMutation.mjs +24 -0
  91. package/dist/network/graphql/builder/Mutations/Space/functions/SpaceTryFunctionMutation.d.ts +4 -0
  92. package/dist/network/graphql/builder/Mutations/Space/functions/SpaceTryFunctionMutation.mjs +15 -0
  93. package/dist/network/graphql/builder/Mutations/Space/runtime/SpaceRemoveRuntimeMutation.d.ts +2 -0
  94. package/dist/network/graphql/builder/Mutations/Space/runtime/SpaceRemoveRuntimeMutation.mjs +9 -0
  95. package/dist/network/graphql/builder/Mutations/Space/runtime/SpaceRemoveRuntimeVariableMutation.d.ts +2 -0
  96. package/dist/network/graphql/builder/Mutations/Space/runtime/SpaceRemoveRuntimeVariableMutation.mjs +9 -0
  97. package/dist/network/graphql/builder/Mutations/Space/runtime/SpaceSetRuntimeSizeMutation.d.ts +2 -0
  98. package/dist/network/graphql/builder/Mutations/Space/runtime/SpaceSetRuntimeSizeMutation.mjs +9 -0
  99. package/dist/network/graphql/builder/Mutations/Space/runtime/SpaceSetRuntimeVariableMutation.d.ts +2 -0
  100. package/dist/network/graphql/builder/Mutations/Space/runtime/SpaceSetRuntimeVariableMutation.mjs +9 -0
  101. package/dist/network/graphql/builder/Mutations/Space/runtime/SpaceStartRuntimeMutation.d.ts +2 -0
  102. package/dist/network/graphql/builder/Mutations/Space/runtime/SpaceStartRuntimeMutation.mjs +9 -0
  103. package/dist/network/graphql/builder/Mutations/Space/runtime/SpaceStopRuntimeMutation.d.ts +2 -0
  104. package/dist/network/graphql/builder/Mutations/Space/runtime/SpaceStopRuntimeMutation.mjs +9 -0
  105. package/dist/network/graphql/builder/Mutations/Space/visitors/SpaceAddVisitorMutation.d.ts +2 -0
  106. package/dist/network/graphql/builder/Mutations/Space/visitors/SpaceAddVisitorMutation.mjs +11 -0
  107. package/dist/network/graphql/builder/Mutations/Space/visitors/SpaceRemoveVisitorMutation.d.ts +2 -0
  108. package/dist/network/graphql/builder/Mutations/Space/visitors/SpaceRemoveVisitorMutation.mjs +11 -0
  109. package/dist/network/graphql/builder/Mutations/index.d.ts +28 -0
  110. package/dist/network/graphql/builder/Mutations/index.mjs +108 -84
  111. package/dist/network/graphql/builder/Queries/Space/SpaceChangesQuery.d.ts +23 -0
  112. package/dist/network/graphql/builder/Queries/Space/SpaceChangesQuery.mjs +49 -0
  113. package/dist/network/graphql/builder/Queries/Space/SpaceFunctionsQuery.d.ts +6 -0
  114. package/dist/network/graphql/builder/Queries/Space/SpaceFunctionsQuery.mjs +13 -0
  115. package/dist/network/graphql/builder/Queries/Space/SpaceIssuesQuery.d.ts +17 -0
  116. package/dist/network/graphql/builder/Queries/Space/SpaceIssuesQuery.mjs +22 -0
  117. package/dist/network/graphql/builder/Queries/Space/SpaceRuntimeQuery.d.ts +6 -0
  118. package/dist/network/graphql/builder/Queries/Space/SpaceRuntimeQuery.mjs +32 -0
  119. package/dist/network/graphql/builder/Queries/Space/SpaceVisitorsQuery.d.ts +6 -0
  120. package/dist/network/graphql/builder/Queries/Space/SpaceVisitorsQuery.mjs +16 -0
  121. package/dist/network/graphql/builder/Queries/index.d.ts +17 -3
  122. package/dist/network/graphql/builder/Queries/index.mjs +30 -22
  123. package/dist/network/graphql/sdk/Mutations/index.d.ts +1 -1
  124. package/dist/network/graphql/sdk/Queries/InitQuery.d.ts +1 -1
  125. package/dist/network/graphql/sdk/Queries/InitQuery.mjs +2 -91
  126. package/dist/network/graphql/sdk/Queries/Segment/SegmentQuery.d.ts +1 -1
  127. package/dist/network/graphql/sdk/Queries/Segment/SegmentQuery.mjs +2 -44
  128. package/dist/network/graphql/sdk/Queries/Segment/SegmentsQuery.d.ts +1 -1
  129. package/dist/network/graphql/sdk/Queries/Segment/SegmentsQuery.mjs +2 -55
  130. package/dist/network/graphql/sdk/Queries/index.d.ts +1 -5
  131. package/dist/network/index.mjs +7 -7
  132. package/dist/network/spaceEvents.d.ts +33 -3
  133. package/dist/network/spaceEvents.mjs +102 -89
  134. package/dist/realtime/client.d.ts +46 -0
  135. package/dist/realtime/client.mjs +192 -0
  136. package/dist/realtime/index.d.ts +6 -0
  137. package/dist/realtime/index.mjs +4 -0
  138. package/dist/realtime/presence.d.ts +38 -0
  139. package/dist/realtime/presence.mjs +70 -0
  140. package/dist/realtime/topics.d.ts +36 -0
  141. package/dist/realtime/topics.mjs +25 -0
  142. package/dist/server/actions/useRealtimeSync.d.ts +9 -0
  143. package/dist/server/actions/useRealtimeSync.mjs +7 -0
  144. package/dist/state/index.d.ts +1 -0
  145. package/dist/state/index.mjs +3 -2
  146. package/dist/state/paintedState.d.ts +52 -0
  147. package/dist/state/paintedState.mjs +37 -0
  148. package/dist/state/runtimeStatePersist.d.ts +8 -1
  149. package/dist/state/runtimeStatePersist.mjs +79 -29
  150. package/dist/store/index.d.ts +45 -45
  151. package/dist/store/renderSettings.d.ts +6 -3
  152. package/dist/store/tracing/index.d.ts +1 -0
  153. package/dist/store/tracing/tracingCollector.d.ts +17 -1
  154. package/dist/store/tracing/tracingCollector.mjs +5 -0
  155. package/dist/style/index.d.ts +1 -0
  156. package/dist/style/index.mjs +3 -2
  157. package/dist/style/runtimeStyle.d.ts +29 -0
  158. package/dist/style/runtimeStyle.mjs +7 -0
  159. package/dist/style/styleConstants.d.ts +3 -2
  160. package/dist/style/styleConstants.mjs +2 -0
  161. package/dist/style/styleStates.d.ts +14 -1
  162. package/dist/style/styleStates.mjs +10 -7
  163. package/dist/theme/ThemeProvider.mjs +35 -29
  164. package/dist/theme/themeCookie.mjs +11 -15
  165. package/dist/types/ActionTypes.d.ts +4 -0
  166. package/dist/types/AuthTypes.d.ts +11 -1
  167. package/dist/types/CommonTypes.d.ts +6 -0
  168. package/dist/types/FunctionTypes.d.ts +52 -0
  169. package/dist/types/FunctionTypes.mjs +0 -0
  170. package/dist/types/PluginTypes.d.ts +0 -1
  171. package/dist/types/RealtimeTypes.d.ts +94 -0
  172. package/dist/types/RealtimeTypes.mjs +0 -0
  173. package/dist/types/SchemaTypes.d.ts +54 -0
  174. package/dist/types/SchemaTypes.mjs +8 -0
  175. package/dist/types/ServerTypes.d.ts +259 -15
  176. package/dist/types/SpaceTypes.d.ts +53 -0
  177. package/dist/types/StateTypes.d.ts +6 -0
  178. package/dist/types/StoreTypes.d.ts +11 -0
  179. package/dist/types/index.d.ts +2 -0
  180. package/dist/types/index.mjs +3 -2
  181. package/package.json +172 -11
  182. package/vite.config.ts +0 -12
  183. package/dist/network/graphql/builder/Queries/PluginsQuery.d.ts +0 -9
  184. package/dist/network/graphql/builder/Queries/PluginsQuery.mjs +0 -54
@@ -2,37 +2,47 @@ import { StyleVariableCategory as e } from "../types/StyleTypes.mjs";
2
2
  import { STYLE_STATES as t } from "../style/styleStates.mjs";
3
3
  import { z as n } from "zod";
4
4
  //#region src/network/spaceEvents.ts
5
- var r = (e) => typeof e == "object" && !!e && !Array.isArray(e), i = n.custom((e) => r(e) && typeof e.id == "string", { message: "expected an element with an id" }), a = n.array(i), o = n.custom((e) => r(e) && Array.isArray(e.flat), { message: "expected a schema whose `flat` is a list of elements" }), s = n.custom((e) => r(e) && typeof e.id == "string", { message: "expected a page folder with an id" }), c = n.custom((e) => r(e) && typeof e.name == "string", { message: "expected a variable with a name" }), l = n.custom(r, { message: "expected a style attributes object" }), u = n.custom((e) => r(e) && typeof e.family == "string" && typeof e.source == "string", { message: "expected a font with a family and a source" }), d = n.custom((e) => typeof e == "string" || typeof e == "number" || r(e), { message: "expected a style variable value" }), f = n.enum([
5
+ var r = (e) => typeof e == "object" && !!e && !Array.isArray(e), i = n.custom((e) => r(e) && typeof e.id == "string", { message: "expected an element with an id" }), a = n.array(i), o = (e) => ({
6
+ ...e,
7
+ flat: Object.values(e.flat)
8
+ }), s = (e) => ({
9
+ ...e,
10
+ flat: Object.fromEntries(e.flat.map((e) => [e.id, e]))
11
+ }), c = n.custom((e) => r(e) && Array.isArray(e.flat), { message: "expected a schema whose `flat` is a list of elements" }), l = n.custom((e) => r(e) && typeof e.id == "string", { message: "expected a page folder with an id" }), u = n.custom((e) => r(e) && typeof e.name == "string", { message: "expected a variable with a name" }), d = n.custom(r, { message: "expected a style attributes object" }), f = n.custom((e) => r(e) && typeof e.family == "string" && typeof e.source == "string", { message: "expected a font with a family and a source" }), p = n.custom((e) => typeof e == "string" || typeof e == "number" || r(e), { message: "expected a style variable value" }), m = n.enum([
6
12
  "desktop",
7
13
  "tablet",
8
14
  "mobile"
9
- ]), p = n.custom((e) => typeof e == "string", { message: "expected a drop position" }), m = n.custom((e) => typeof e == "string", { message: "expected a style category" }), h = n.enum([
15
+ ]), h = n.custom((e) => typeof e == "string", { message: "expected a drop position" }), g = n.custom((e) => typeof e == "string", { message: "expected a style category" }), _ = n.enum([
10
16
  "class",
11
17
  "element",
12
18
  "id"
13
- ]), g = n.enum(t), _ = n.enum(e), v = n.object({
19
+ ]), v = n.enum(t), y = n.enum(e), b = n.object({
14
20
  componentType: n.string().optional(),
15
21
  styleSelector: n.string().optional(),
16
- styleState: g.optional(),
22
+ styleState: v.optional(),
17
23
  styleVariant: n.string().optional(),
18
24
  styleAncestor: n.string().optional()
19
- }), y = v.extend({ styleSelector: n.string() }), b = { contextId: n.string() }, x = n.object({ variable: c }), S = n.object({
20
- displayMode: f,
25
+ }), x = b.extend({ styleSelector: n.string() }), S = { contextId: n.string() }, C = n.object({ variable: u }), w = n.object({
26
+ displayMode: m,
21
27
  selector: n.string(),
22
- category: _,
28
+ category: y,
23
29
  name: n.string(),
24
- value: d
25
- }), C = n.object({
26
- displayMode: f,
30
+ value: p
31
+ }), T = n.object({
32
+ displayMode: m,
27
33
  selector: n.string(),
28
- category: _,
34
+ category: y,
29
35
  name: n.string()
30
- }), w = n.object({
31
- category: _,
36
+ }), E = n.object({
37
+ category: y,
32
38
  name: n.string(),
33
- value: d
34
- }), T = {
35
- SPACE_UPDATED: n.object({ schema: o }),
39
+ value: p
40
+ }), D = n.object({
41
+ type: n.string(),
42
+ resource: n.string(),
43
+ settings: n.custom(r, { message: "expected a plugin settings object" })
44
+ }), O = {
45
+ SPACE_UPDATED: n.object({ schema: c }),
36
46
  STYLE_UPDATED: n.object({
37
47
  platform: n.custom(r),
38
48
  variables: n.custom(r),
@@ -42,18 +52,18 @@ var r = (e) => typeof e == "object" && !!e && !Array.isArray(e), i = n.custom((e
42
52
  SPACE_UPDATE_PAGE: n.object({ page: i }),
43
53
  SPACE_SET_HOME_PAGE: n.object({ page: i }),
44
54
  SPACE_REMOVE_PAGE: n.object({ pageId: n.string() }),
45
- SPACE_ADD_PAGE_FOLDER: n.object({ pageFolder: s }),
46
- SPACE_UPDATE_PAGE_FOLDER: n.object({ pageFolder: s }),
55
+ SPACE_ADD_PAGE_FOLDER: n.object({ pageFolder: l }),
56
+ SPACE_UPDATE_PAGE_FOLDER: n.object({ pageFolder: l }),
47
57
  SPACE_REMOVE_PAGE_FOLDER: n.object({ pageFolderId: n.string() }),
48
- SPACE_ADD_VARIABLE: x,
49
- SPACE_UPDATE_VARIABLE: x,
58
+ SPACE_ADD_VARIABLE: C,
59
+ SPACE_UPDATE_VARIABLE: C,
50
60
  SPACE_REMOVE_VARIABLE: n.object({ name: n.string() }),
51
61
  SPACE_ADD_ELEMENT: n.object({
52
62
  element: i,
53
- dropPosition: p,
63
+ dropPosition: h,
54
64
  to: n.string(),
55
65
  initialItems: a.optional(),
56
- variables: n.array(c).optional()
66
+ variables: n.array(u).optional()
57
67
  }),
58
68
  SPACE_UPDATE_ELEMENT: n.object({ element: i }),
59
69
  SPACE_RENAME_ELEMENT: n.object({
@@ -66,22 +76,25 @@ var r = (e) => typeof e == "object" && !!e && !Array.isArray(e), i = n.custom((e
66
76
  from: n.string(),
67
77
  to: n.string(),
68
78
  elementId: n.string(),
69
- dropPosition: p
79
+ dropPosition: h
70
80
  }),
71
81
  SPACE_CLONE_ELEMENT: n.object({
72
82
  to: n.string(),
73
83
  element: i,
74
- dropPosition: p,
84
+ dropPosition: h,
75
85
  initialItems: a
76
86
  }),
77
87
  SPACE_ADD_TEMPLATE: n.object({
78
88
  element: i,
79
89
  style: n.custom(r),
80
90
  to: n.string(),
81
- dropPosition: p,
91
+ dropPosition: h,
82
92
  initialItems: a.optional(),
83
- variables: n.array(c).optional()
93
+ variables: n.array(u).optional()
84
94
  }),
95
+ SPACE_ADD_PLUGIN: n.object({ plugin: D }),
96
+ SPACE_UPDATE_PLUGIN: n.object({ plugin: D }),
97
+ SPACE_REMOVE_PLUGIN: n.object({ pluginType: n.string() }),
85
98
  SPACE_UPDATE_SETTINGS: n.object({
86
99
  path: n.string(),
87
100
  value: n.union([
@@ -91,146 +104,146 @@ var r = (e) => typeof e == "object" && !!e && !Array.isArray(e), i = n.custom((e
91
104
  ])
92
105
  }),
93
106
  STYLE_ADD_SELECTOR: n.object({
94
- displayMode: f,
107
+ displayMode: m,
95
108
  selector: n.string(),
96
- path: m.optional(),
97
- type: h,
98
- style: l.optional(),
99
- params: v
109
+ path: g.optional(),
110
+ type: _,
111
+ style: d.optional(),
112
+ params: b
100
113
  }),
101
114
  STYLE_UPDATE_SELECTOR: n.object({
102
- displayMode: f,
115
+ displayMode: m,
103
116
  selector: n.string(),
104
- path: m.optional(),
105
- style: l.optional(),
106
- params: y
117
+ path: g.optional(),
118
+ style: d.optional(),
119
+ params: x
107
120
  }),
108
121
  STYLE_REMOVE_SELECTOR: n.object({
109
- displayMode: f,
122
+ displayMode: m,
110
123
  selector: n.string()
111
124
  }),
112
125
  STYLE_REMOVE_SELECTORS: n.object({
113
- displayMode: f,
126
+ displayMode: m,
114
127
  selectors: n.array(n.string())
115
128
  }),
116
- STYLE_ADD_SELECTOR_VARIABLE: S,
117
- STYLE_UPDATE_SELECTOR_VARIABLE: S,
118
- STYLE_REMOVE_SELECTOR_VARIABLE: C,
119
- STYLE_ADD_VARIABLE: w,
120
- STYLE_UPDATE_VARIABLE: w,
129
+ STYLE_ADD_SELECTOR_VARIABLE: w,
130
+ STYLE_UPDATE_SELECTOR_VARIABLE: w,
131
+ STYLE_REMOVE_SELECTOR_VARIABLE: T,
132
+ STYLE_ADD_VARIABLE: E,
133
+ STYLE_UPDATE_VARIABLE: E,
121
134
  STYLE_REMOVE_VARIABLE: n.object({
122
- category: _,
135
+ category: y,
123
136
  name: n.string()
124
137
  }),
125
138
  STYLE_UPDATE_SETTINGS: n.object({
126
139
  path: n.string(),
127
140
  value: n.string()
128
141
  }),
129
- STYLE_ADD_FONT: n.object({ font: u }),
142
+ STYLE_ADD_FONT: n.object({ font: f }),
130
143
  STYLE_UPDATE_FONT: n.object({
131
144
  family: n.string(),
132
- font: u
145
+ font: f
133
146
  }),
134
147
  STYLE_REMOVE_FONT: n.object({ family: n.string() }),
135
148
  SEGMENT_ADD_ELEMENT: n.object({
136
- ...b,
149
+ ...S,
137
150
  element: i,
138
- dropPosition: p,
151
+ dropPosition: h,
139
152
  to: n.string(),
140
153
  initialItems: a.optional(),
141
- variables: n.array(c).optional()
154
+ variables: n.array(u).optional()
142
155
  }),
143
156
  SEGMENT_UPDATE_ELEMENT: n.object({
144
- ...b,
157
+ ...S,
145
158
  element: i
146
159
  }),
147
160
  SEGMENT_RENAME_ELEMENT: n.object({
148
- ...b,
161
+ ...S,
149
162
  elementId: n.string(),
150
163
  id: n.string()
151
164
  }),
152
165
  SEGMENT_UPDATE_ELEMENTS: n.object({
153
- ...b,
166
+ ...S,
154
167
  elements: a
155
168
  }),
156
169
  SEGMENT_REMOVE_ELEMENT: n.object({
157
- ...b,
170
+ ...S,
158
171
  elementId: n.string()
159
172
  }),
160
173
  SEGMENT_MOVE_ELEMENT: n.object({
161
- ...b,
174
+ ...S,
162
175
  elementId: n.string(),
163
176
  from: n.string(),
164
177
  to: n.string(),
165
- dropPosition: p
178
+ dropPosition: h
166
179
  }),
167
180
  SEGMENT_CLONE_ELEMENT: n.object({
168
- ...b,
181
+ ...S,
169
182
  element: i,
170
- dropPosition: p,
183
+ dropPosition: h,
171
184
  to: n.string(),
172
185
  initialItems: a.optional()
173
186
  }),
174
187
  SEGMENT_ADD_TEMPLATE: n.object({
175
- ...b,
188
+ ...S,
176
189
  element: i,
177
190
  style: n.custom(r),
178
191
  to: n.string(),
179
- dropPosition: p,
192
+ dropPosition: h,
180
193
  initialItems: a.optional(),
181
- variables: n.array(c).optional()
194
+ variables: n.array(u).optional()
182
195
  }),
183
196
  SEGMENT_SPACE_ADD_VARIABLE: n.object({
184
- ...b,
185
- variable: c
197
+ ...S,
198
+ variable: u
186
199
  }),
187
200
  SEGMENT_SPACE_UPDATE_VARIABLE: n.object({
188
- ...b,
189
- variable: c
201
+ ...S,
202
+ variable: u
190
203
  }),
191
204
  SEGMENT_SPACE_REMOVE_VARIABLE: n.object({
192
- ...b,
205
+ ...S,
193
206
  variable: n.object({ name: n.string() })
194
207
  }),
195
208
  SEGMENT_STYLE_ADD_SELECTOR: n.object({
196
- ...b,
197
- displayMode: f,
209
+ ...S,
210
+ displayMode: m,
198
211
  selector: n.string(),
199
- type: h,
200
- path: m.optional(),
201
- style: l.optional(),
202
- params: v
212
+ type: _,
213
+ path: g.optional(),
214
+ style: d.optional(),
215
+ params: b
203
216
  }),
204
217
  SEGMENT_STYLE_UPDATE_SELECTOR: n.object({
205
- ...b,
206
- displayMode: f,
218
+ ...S,
219
+ displayMode: m,
207
220
  selector: n.string(),
208
- path: m.optional(),
209
- style: l.optional(),
210
- params: y
221
+ path: g.optional(),
222
+ style: d.optional(),
223
+ params: x
211
224
  }),
212
225
  SEGMENT_STYLE_REMOVE_SELECTOR: n.object({
213
- ...b,
214
- displayMode: f,
226
+ ...S,
227
+ displayMode: m,
215
228
  selector: n.string()
216
229
  }),
217
230
  SEGMENT_STYLE_REMOVE_SELECTORS: n.object({
218
- ...b,
219
- displayMode: f,
231
+ ...S,
232
+ displayMode: m,
220
233
  selectors: n.array(n.string())
221
234
  }),
222
- SEGMENT_STYLE_ADD_SELECTOR_VARIABLE: S.extend(b),
223
- SEGMENT_STYLE_UPDATE_SELECTOR_VARIABLE: S.extend(b),
224
- SEGMENT_STYLE_REMOVE_SELECTOR_VARIABLE: C.extend(b),
225
- SEGMENT_STYLE_ADD_VARIABLE: w.extend(b),
226
- SEGMENT_STYLE_UPDATE_VARIABLE: w.extend(b),
235
+ SEGMENT_STYLE_ADD_SELECTOR_VARIABLE: w.extend(S),
236
+ SEGMENT_STYLE_UPDATE_SELECTOR_VARIABLE: w.extend(S),
237
+ SEGMENT_STYLE_REMOVE_SELECTOR_VARIABLE: T.extend(S),
238
+ SEGMENT_STYLE_ADD_VARIABLE: E.extend(S),
239
+ SEGMENT_STYLE_UPDATE_VARIABLE: E.extend(S),
227
240
  SEGMENT_STYLE_REMOVE_VARIABLE: n.object({
228
- ...b,
229
- category: _,
241
+ ...S,
242
+ category: y,
230
243
  name: n.string()
231
244
  })
232
- }, E = Object.fromEntries(Object.keys(T).map((e) => [e, e])), D = (e, t) => {
233
- let n = T[e];
245
+ }, k = Object.fromEntries(Object.keys(O).map((e) => [e, e])), A = (e, t) => {
246
+ let n = O[e];
234
247
  if (!n) return {
235
248
  ok: !1,
236
249
  issues: [{
@@ -251,4 +264,4 @@ var r = (e) => typeof e == "object" && !!e && !Array.isArray(e), i = n.custom((e
251
264
  };
252
265
  };
253
266
  //#endregion
254
- export { E as SpaceEvents, E as default, T as spaceEventSchemas, D as validateSpaceEvent };
267
+ export { k as SpaceEvents, k as default, s as schemaFromWire, o as schemaToWire, O as spaceEventSchemas, A as validateSpaceEvent };
@@ -0,0 +1,46 @@
1
+ import { RealtimeMessage, RealtimeTransport } from '../types/RealtimeTypes';
2
+ export type RealtimeStatus = 'idle' | 'connecting' | 'open' | 'closed';
3
+ type MessageListener = (message: RealtimeMessage) => void;
4
+ type StatusListener = (status: RealtimeStatus) => void;
5
+ export type RealtimeClient = {
6
+ /** Listens to a topic; the page's one connection is reopened to include it. Returns what stops listening. */
7
+ subscribe: (topic: string, listener: MessageListener) => () => void;
8
+ /**
9
+ * What opens a topic of a `grant: true` channel: the grant a flow's `realtime.grant` answered. Sent whenever the
10
+ * connection opens for as long as the topic is listened to — a grant is only asked for at the door, so a new one
11
+ * reopens nothing the server already let in. `undefined` forgets it.
12
+ */
13
+ grant: (topic: string, grant: string | undefined) => void;
14
+ /** Sends on a topic this page listens to. `false` when the server refused it or there is no connection. */
15
+ publish: (topic: string, type: string, data: unknown) => Promise<boolean>;
16
+ onStatus: (listener: StatusListener) => () => void;
17
+ readonly status: RealtimeStatus;
18
+ /** This page's name on its channels — the `from` of what it sends — once connected. */
19
+ readonly me: string | undefined;
20
+ /** How this page is connected right now: a socket, or a stream (also where a socket could not open). */
21
+ readonly transport: RealtimeTransport;
22
+ /** Why the server would not open a topic, when it would not. */
23
+ refusal: (topic: string) => string | undefined;
24
+ };
25
+ export type RealtimeClientOptions = {
26
+ /** What to connect with. `websocket` falls back to `sse` for good the first time a socket cannot open. */
27
+ transport?: RealtimeTransport;
28
+ fetchImpl?: typeof fetch;
29
+ WebSocketImpl?: typeof WebSocket;
30
+ };
31
+ /**
32
+ * A page's realtime connection: every topic it listens to over ONE connection — a Server-Sent Events stream it
33
+ * publishes to with requests, or a WebSocket that carries both.
34
+ *
35
+ * The stream is read with `fetch` rather than `EventSource`: an `EventSource` reconnects on its own, with the same
36
+ * topics, to a server that may have just refused them. Reconnecting is this client's decision: after a dropped
37
+ * connection, with a growing wait; never after a refusal.
38
+ *
39
+ * A socket that closes before it was ever ready is a socket that cannot open here — HTTP/2, a proxy that drops
40
+ * upgrades, or a refusal, which a browser does not let a page read — so the client moves to the stream for good. The
41
+ * stream says which it was.
42
+ */
43
+ export declare const createRealtimeClient: (endpoint: string, { transport: preferred, fetchImpl, WebSocketImpl }?: RealtimeClientOptions) => RealtimeClient;
44
+ /** The page's client for an endpoint: one connection, however many elements and plugins listen. */
45
+ export declare const realtimeClientFor: (endpoint: string, transport?: RealtimeTransport) => RealtimeClient;
46
+ export {};
@@ -0,0 +1,192 @@
1
+ import "./topics.mjs";
2
+ //#region src/realtime/client.ts
3
+ var e = 30, t = [
4
+ 500,
5
+ 1e3,
6
+ 2e3,
7
+ 5e3,
8
+ 1e4
9
+ ], n = 5e3, r = (e) => typeof e == "object" && !!e && "connection" in e && typeof e.connection == "string" && "refused" in e && Array.isArray(e.refused), i = (e) => typeof e == "object" && !!e && "topic" in e && typeof e.topic == "string" && "type" in e && typeof e.type == "string", a = (e) => typeof e == "object" && !!e && "id" in e && typeof e.id == "number" && "ok" in e && typeof e.ok == "boolean", o = (e) => {
10
+ let t = "message", n = [];
11
+ for (let r of e.split("\n")) r.startsWith("event: ") ? t = r.slice(7) : r.startsWith("data: ") && n.push(r.slice(6));
12
+ if (n.length) try {
13
+ return {
14
+ event: t,
15
+ data: JSON.parse(n.join("\n"))
16
+ };
17
+ } catch {
18
+ return;
19
+ }
20
+ }, s = (e) => {
21
+ try {
22
+ let t = JSON.parse(String(e));
23
+ return typeof t == "object" && t && "event" in t && typeof t.event == "string" ? {
24
+ event: t.event,
25
+ data: "data" in t ? t.data : void 0
26
+ } : void 0;
27
+ } catch {
28
+ return;
29
+ }
30
+ }, c = (e, t) => {
31
+ let n = new URL(`${e}?${t}`, globalThis.location.href);
32
+ return n.protocol = n.protocol === "https:" ? "wss:" : "ws:", n.href;
33
+ }, l = (l, { transport: u = "sse", fetchImpl: d = fetch, WebSocketImpl: f = globalThis.WebSocket } = {}) => {
34
+ let p = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Set(), g = "idle", _, v = /* @__PURE__ */ new Map(), y, b, x = 0, S = u === "websocket" && typeof f == "function", C = (e) => {
35
+ g = e, h.forEach((t) => t(e));
36
+ }, w = () => [...p.keys()].sort().join(","), T = (e) => {
37
+ let t = e.split(",").flatMap((e) => m.get(e) ?? []);
38
+ return `topics=${encodeURIComponent(e)}${t.length ? `&grants=${encodeURIComponent(t.join(","))}` : ""}`;
39
+ }, E = (e) => {
40
+ e.type === "$revoked" && e.from === "server" && v.set(e.topic, "revoked"), p.get(e.topic)?.forEach((t) => t(e));
41
+ }, D = (e, t) => {
42
+ e.me = t.connection, v = new Map(t.refused.map((e) => [e.topic, e.reason])), x = 0, C("open");
43
+ }, O = (e) => {
44
+ if (_ !== e) return;
45
+ C("connecting");
46
+ let n = t[Math.min(x, t.length - 1)];
47
+ x += 1, b = setTimeout(j, n);
48
+ }, k = (e, t) => {
49
+ let n = new AbortController(), a, s = {
50
+ topics: e,
51
+ transport: "sse",
52
+ close: () => n.abort(),
53
+ publish: async (e, t, n) => {
54
+ if (!a) return !1;
55
+ let r = await d(l, {
56
+ method: "POST",
57
+ headers: { "content-type": "application/json" },
58
+ credentials: "same-origin",
59
+ body: JSON.stringify({
60
+ token: a,
61
+ topic: e,
62
+ type: t,
63
+ data: n
64
+ })
65
+ }).catch(() => void 0);
66
+ return r?.status === 401 && _ === s && j(), r?.ok ?? !1;
67
+ }
68
+ }, c = async (e) => {
69
+ let t = e.body?.getReader();
70
+ if (!t) return;
71
+ let n = new TextDecoder(), c = "";
72
+ for (;;) {
73
+ let { done: e, value: l } = await t.read();
74
+ if (e) return;
75
+ c += n.decode(l, { stream: !0 });
76
+ let u = c.indexOf("\n\n");
77
+ for (; u !== -1;) {
78
+ let e = o(c.slice(0, u));
79
+ c = c.slice(u + 2), u = c.indexOf("\n\n"), e?.event === "ready" && r(e.data) ? (a = e.data.token, D(s, e.data)) : e?.event === "message" && i(e.data) && E(e.data);
80
+ }
81
+ }
82
+ };
83
+ return d(`${l}?${t}`, {
84
+ headers: { accept: "text/event-stream" },
85
+ credentials: "same-origin",
86
+ signal: n.signal
87
+ }).then(async (t) => {
88
+ if (!t.ok) {
89
+ v = new Map(e.split(",").map((e) => [e, `http_${t.status}`])), C("closed");
90
+ return;
91
+ }
92
+ throw await c(t), Error("The realtime stream ended");
93
+ }).catch(() => {
94
+ n.signal.aborted || O(s);
95
+ }), s;
96
+ }, A = (e, t) => {
97
+ let o = new f(c(l, t)), u = /* @__PURE__ */ new Map(), d = 0, p = !1, m = !1, h = () => {
98
+ u.forEach((e) => e(!1)), u.clear();
99
+ }, g = {
100
+ topics: e,
101
+ transport: "websocket",
102
+ close: () => {
103
+ m = !0, h(), o.close();
104
+ },
105
+ publish: (e, t, r) => new Promise((i) => {
106
+ if (o.readyState !== o.OPEN) {
107
+ i(!1);
108
+ return;
109
+ }
110
+ d += 1;
111
+ let a = d, s = setTimeout(() => {
112
+ u.delete(a), i(!1);
113
+ }, n);
114
+ u.set(a, (e) => {
115
+ clearTimeout(s), i(e);
116
+ }), o.send(JSON.stringify({
117
+ id: a,
118
+ topic: e,
119
+ type: t,
120
+ data: r
121
+ }));
122
+ })
123
+ };
124
+ return o.onmessage = (e) => {
125
+ let t = s(e.data);
126
+ t?.event === "ready" && r(t.data) ? (p = !0, D(g, t.data)) : t?.event === "message" && i(t.data) ? E(t.data) : t?.event === "ack" && a(t.data) && (u.get(t.data.id)?.(t.data.ok), u.delete(t.data.id));
127
+ }, o.onclose = () => {
128
+ if (h(), !(m || _ !== g)) {
129
+ if (!p) {
130
+ S = !1, j();
131
+ return;
132
+ }
133
+ O(g);
134
+ }
135
+ }, g;
136
+ };
137
+ function j() {
138
+ _?.close(), _ = void 0;
139
+ let e = w();
140
+ if (!e) {
141
+ C("idle");
142
+ return;
143
+ }
144
+ C("connecting");
145
+ let t = T(e);
146
+ _ = S ? A(e, t) : k(e, t);
147
+ }
148
+ let M = (t = !1) => {
149
+ clearTimeout(y), clearTimeout(b), y = setTimeout(() => {
150
+ (t || _?.topics !== w()) && j();
151
+ }, e);
152
+ }, N = (e) => g === "open" && _?.topics.split(",").includes(e) === !0, P = (e) => N(e) ? Promise.resolve(!0) : new Promise((t) => {
153
+ let r = setTimeout(() => {
154
+ i(), t(!1);
155
+ }, n), i = F.onStatus((n) => {
156
+ (n === "closed" || N(e)) && (clearTimeout(r), i(), t(n !== "closed"));
157
+ });
158
+ }), F = {
159
+ subscribe: (e, t) => {
160
+ let n = p.get(e) ?? /* @__PURE__ */ new Set();
161
+ return n.add(t), p.set(e, n), M(), () => {
162
+ n.delete(t), n.size || (p.delete(e), m.delete(e), M());
163
+ };
164
+ },
165
+ grant: (e, t) => {
166
+ if (m.get(e) === t) return;
167
+ t ? m.set(e, t) : m.delete(e);
168
+ let n = N(e) && !v.has(e);
169
+ t && p.has(e) && !n && M(!0);
170
+ },
171
+ publish: async (e, t, n) => !await P(e) || !_ ? !1 : _.publish(e, t, n),
172
+ onStatus: (e) => (h.add(e), () => h.delete(e)),
173
+ get status() {
174
+ return g;
175
+ },
176
+ get me() {
177
+ return _?.me;
178
+ },
179
+ get transport() {
180
+ return _?.transport ?? (S ? "websocket" : "sse");
181
+ },
182
+ refusal: (e) => v.get(e)
183
+ };
184
+ return F;
185
+ }, u = /* @__PURE__ */ new Map(), d = (e, t = "sse") => {
186
+ let n = `${t} ${e}`, r = u.get(n);
187
+ if (r) return r;
188
+ let i = l(e, { transport: t });
189
+ return u.set(n, i), i;
190
+ };
191
+ //#endregion
192
+ export { l as createRealtimeClient, d as realtimeClientFor };
@@ -0,0 +1,6 @@
1
+ export { createRealtimeClient, realtimeClientFor } from './client';
2
+ export { trackPresence } from './presence';
3
+ export { JOIN_TYPE, LEAVE_TYPE, PRESENCE_TYPE, REVOKED_TYPE, channelLimits, channelProblems, isValidTopic, matchChannel } from './topics';
4
+ export type { RealtimeClient, RealtimeClientOptions, RealtimeStatus } from './client';
5
+ export type { PresenceListeners, PresenceTracker, RealtimeMember } from './presence';
6
+ export type { ChannelMatch } from './topics';
@@ -0,0 +1,4 @@
1
+ import { JOIN_TYPE as e, LEAVE_TYPE as t, PRESENCE_TYPE as n, REVOKED_TYPE as r, channelLimits as i, channelProblems as a, isValidTopic as o, matchChannel as s } from "./topics.mjs";
2
+ import { createRealtimeClient as c, realtimeClientFor as l } from "./client.mjs";
3
+ import { trackPresence as u } from "./presence.mjs";
4
+ export { e as JOIN_TYPE, t as LEAVE_TYPE, n as PRESENCE_TYPE, r as REVOKED_TYPE, i as channelLimits, a as channelProblems, c as createRealtimeClient, o as isValidTopic, s as matchChannel, l as realtimeClientFor, u as trackPresence };
@@ -0,0 +1,38 @@
1
+ import { RealtimeClient } from './client';
2
+ import { RealtimeMessage, RealtimeSender } from '../types/RealtimeTypes';
3
+ /** One member of a channel: who they are to the server, and what they announced. */
4
+ export type RealtimeMember = RealtimeSender & {
5
+ /** What the member announced — a name, a colour, a cursor. */
6
+ state: unknown;
7
+ /** Whether this member is this page. */
8
+ me: boolean;
9
+ };
10
+ export type PresenceTracker = {
11
+ /** Announces this page's state — and keeps announcing it, so it is not taken for gone. */
12
+ set: (state: unknown) => void;
13
+ members: () => RealtimeMember[];
14
+ stop: () => void;
15
+ };
16
+ /** What a tracker is told: who is here, every message on the topic, and who came and went. */
17
+ export type PresenceListeners = {
18
+ onChange: (members: RealtimeMember[]) => void;
19
+ onMessage?: (message: RealtimeMessage) => void;
20
+ /**
21
+ * Somebody who joined after this page, once they have said who they are — their first `$presence`. Those already
22
+ * here when this page came are not arrivals: they answer its `$join` with theirs, and it is they who were here first.
23
+ */
24
+ onArrive?: (member: RealtimeMember) => void;
25
+ /** Somebody who was here went — the server said so, or they stopped being heard — as they last said they were. */
26
+ onDepart?: (member: RealtimeMember) => void;
27
+ };
28
+ /**
29
+ * Who is on a topic, kept from what the members say — nothing is stored anywhere.
30
+ *
31
+ * A member announces itself (`$presence`) when it sets its state, when somebody new arrives (`$join`) and every
32
+ * twenty seconds; the server says `$leave` when its connection closes. A member heard from in none of those ways for
33
+ * a minute is gone, which is what heals a leave that was lost.
34
+ *
35
+ * Every tracker of one topic on one client is a view of the same member: `set` from any of them is the page's state,
36
+ * and a tracker started late begins with everyone already known.
37
+ */
38
+ export declare const trackPresence: (client: RealtimeClient, topic: string, listener: PresenceListeners) => PresenceTracker;