polen 0.11.0-next.16 → 0.11.0-next.18

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 (251) hide show
  1. package/build/api/builder/ssg/generate.d.ts.map +1 -1
  2. package/build/api/builder/ssg/generate.js +5 -5
  3. package/build/api/builder/ssg/generate.js.map +1 -1
  4. package/build/api/builder/ssg/page-generator.worker.js +13 -3
  5. package/build/api/builder/ssg/page-generator.worker.js.map +1 -1
  6. package/build/api/config/input.d.ts +88 -3
  7. package/build/api/config/input.d.ts.map +1 -1
  8. package/build/api/config/normalized.d.ts +92 -7
  9. package/build/api/config/normalized.d.ts.map +1 -1
  10. package/build/api/config/normalized.js +11 -3
  11. package/build/api/config/normalized.js.map +1 -1
  12. package/build/api/config-template/template.js +2 -2
  13. package/build/api/config-template/template.js.map +1 -1
  14. package/build/api/content/sidebar.d.ts.map +1 -1
  15. package/build/api/content/sidebar.js +2 -1
  16. package/build/api/content/sidebar.js.map +1 -1
  17. package/build/api/examples/config.d.ts +366 -3
  18. package/build/api/examples/config.d.ts.map +1 -1
  19. package/build/api/examples/config.js +25 -3
  20. package/build/api/examples/config.js.map +1 -1
  21. package/build/api/examples/diagnostic/diagnostic.d.ts +5 -5
  22. package/build/api/examples/diagnostic/missing-versions.d.ts +5 -4
  23. package/build/api/examples/diagnostic/missing-versions.d.ts.map +1 -1
  24. package/build/api/examples/diagnostic/missing-versions.js +3 -2
  25. package/build/api/examples/diagnostic/missing-versions.js.map +1 -1
  26. package/build/api/examples/diagnostic/unknown-version.d.ts +5 -4
  27. package/build/api/examples/diagnostic/unknown-version.d.ts.map +1 -1
  28. package/build/api/examples/diagnostic/unknown-version.js +3 -2
  29. package/build/api/examples/diagnostic/unknown-version.js.map +1 -1
  30. package/build/api/examples/diagnostic/validation-error.d.ts +3 -2
  31. package/build/api/examples/diagnostic/validation-error.d.ts.map +1 -1
  32. package/build/api/examples/diagnostic/validation-error.js +9 -3
  33. package/build/api/examples/diagnostic/validation-error.js.map +1 -1
  34. package/build/api/examples/diagnostic/validator.d.ts.map +1 -1
  35. package/build/api/examples/diagnostic/validator.js +115 -69
  36. package/build/api/examples/diagnostic/validator.js.map +1 -1
  37. package/build/api/examples/filter.d.ts.map +1 -1
  38. package/build/api/examples/filter.js +9 -6
  39. package/build/api/examples/filter.js.map +1 -1
  40. package/build/api/examples/scanner.d.ts.map +1 -1
  41. package/build/api/examples/scanner.js +93 -103
  42. package/build/api/examples/scanner.js.map +1 -1
  43. package/build/api/examples/type-usage-indexer.d.ts.map +1 -1
  44. package/build/api/examples/type-usage-indexer.js +18 -32
  45. package/build/api/examples/type-usage-indexer.js.map +1 -1
  46. package/build/api/iso/schema/routing.d.ts.map +1 -1
  47. package/build/api/iso/schema/routing.js +8 -8
  48. package/build/api/iso/schema/routing.js.map +1 -1
  49. package/build/api/iso/schema/validation.d.ts.map +1 -1
  50. package/build/api/iso/schema/validation.js +3 -2
  51. package/build/api/iso/schema/validation.js.map +1 -1
  52. package/build/api/schema/input-sources/directory.js +2 -2
  53. package/build/api/schema/input-sources/directory.js.map +1 -1
  54. package/build/api/schema/input-sources/versioned-directory.d.ts +3 -3
  55. package/build/api/schema/input-sources/versioned-directory.d.ts.map +1 -1
  56. package/build/api/schema/input-sources/versioned-directory.js +6 -4
  57. package/build/api/schema/input-sources/versioned-directory.js.map +1 -1
  58. package/build/api/schema/load.d.ts.map +1 -1
  59. package/build/api/schema/load.js +2 -2
  60. package/build/api/schema/load.js.map +1 -1
  61. package/build/cli/commands/hero-image.js +1 -1
  62. package/build/cli/commands/hero-image.js.map +1 -1
  63. package/build/lib/catalog/catalog.d.ts +65 -24
  64. package/build/lib/catalog/catalog.d.ts.map +1 -1
  65. package/build/lib/catalog/catalog.js +72 -16
  66. package/build/lib/catalog/catalog.js.map +1 -1
  67. package/build/lib/catalog/versioned.d.ts +46 -26
  68. package/build/lib/catalog/versioned.d.ts.map +1 -1
  69. package/build/lib/catalog/versioned.js +44 -7
  70. package/build/lib/catalog/versioned.js.map +1 -1
  71. package/build/lib/catalog-statistics/analyze-catalog.js +3 -3
  72. package/build/lib/catalog-statistics/analyze-catalog.js.map +1 -1
  73. package/build/lib/document/document.d.ts +55 -5
  74. package/build/lib/document/document.d.ts.map +1 -1
  75. package/build/lib/document/document.js +96 -2
  76. package/build/lib/document/document.js.map +1 -1
  77. package/build/lib/document/versioned.d.ts +2 -2
  78. package/build/lib/document/versioned.d.ts.map +1 -1
  79. package/build/lib/document/versioned.js +7 -7
  80. package/build/lib/document/versioned.js.map +1 -1
  81. package/build/lib/lifecycles/lifecycles.d.ts +5 -4
  82. package/build/lib/lifecycles/lifecycles.d.ts.map +1 -1
  83. package/build/lib/lifecycles/lifecycles.js +15 -13
  84. package/build/lib/lifecycles/lifecycles.js.map +1 -1
  85. package/build/lib/version-coverage/$$.d.ts +2 -0
  86. package/build/lib/version-coverage/$$.d.ts.map +1 -0
  87. package/build/lib/version-coverage/$$.js +2 -0
  88. package/build/lib/version-coverage/$$.js.map +1 -0
  89. package/build/lib/version-coverage/$.d.ts.map +1 -0
  90. package/build/lib/version-coverage/$.js.map +1 -0
  91. package/build/lib/{version-selection/version-selection.d.ts → version-coverage/version-coverage.d.ts} +1 -1
  92. package/build/lib/version-coverage/version-coverage.d.ts.map +1 -0
  93. package/build/lib/{version-selection/version-selection.js → version-coverage/version-coverage.js} +2 -2
  94. package/build/lib/version-coverage/version-coverage.js.map +1 -0
  95. package/build/template/components/Changelog/Changelog.d.ts.map +1 -1
  96. package/build/template/components/Changelog/Changelog.js +7 -7
  97. package/build/template/components/Changelog/Changelog.js.map +1 -1
  98. package/build/template/components/GraphQLDocument.d.ts +1 -1
  99. package/build/template/components/GraphQLDocument.d.ts.map +1 -1
  100. package/build/template/components/GraphQLDocument.js +10 -38
  101. package/build/template/components/GraphQLDocument.js.map +1 -1
  102. package/build/template/components/GraphQLInteractive/lib/parser.d.ts +28 -0
  103. package/build/template/components/GraphQLInteractive/lib/parser.d.ts.map +1 -1
  104. package/build/template/components/GraphQLInteractive/lib/parser.js +60 -27
  105. package/build/template/components/GraphQLInteractive/lib/parser.js.map +1 -1
  106. package/build/template/components/VersionCoveragePicker.d.ts +1 -1
  107. package/build/template/components/VersionCoveragePicker.d.ts.map +1 -1
  108. package/build/template/components/VersionCoveragePicker.js +4 -6
  109. package/build/template/components/VersionCoveragePicker.js.map +1 -1
  110. package/build/template/components/VersionPicker.d.ts.map +1 -1
  111. package/build/template/components/VersionPicker.js +5 -2
  112. package/build/template/components/VersionPicker.js.map +1 -1
  113. package/build/template/components/home/FeaturesGrid.js +1 -1
  114. package/build/template/components/home/FeaturesGrid.js.map +1 -1
  115. package/build/template/components/home/HeroSection.js +1 -1
  116. package/build/template/components/home/HeroSection.js.map +1 -1
  117. package/build/template/components/home/QuickStart.d.ts.map +1 -1
  118. package/build/template/components/home/QuickStart.js +8 -4
  119. package/build/template/components/home/QuickStart.js.map +1 -1
  120. package/build/template/components/home/RecentChanges.d.ts.map +1 -1
  121. package/build/template/components/home/RecentChanges.js +2 -1
  122. package/build/template/components/home/RecentChanges.js.map +1 -1
  123. package/build/template/hooks/use-highlighted.d.ts.map +1 -1
  124. package/build/template/hooks/use-highlighted.js +19 -13
  125. package/build/template/hooks/use-highlighted.js.map +1 -1
  126. package/build/template/lib/fetch-text.d.ts +18 -0
  127. package/build/template/lib/fetch-text.d.ts.map +1 -1
  128. package/build/template/lib/fetch-text.js +32 -4
  129. package/build/template/lib/fetch-text.js.map +1 -1
  130. package/build/template/routes/changelog.d.ts +1 -1
  131. package/build/template/routes/changelog.d.ts.map +1 -1
  132. package/build/template/routes/changelog.js +7 -4
  133. package/build/template/routes/changelog.js.map +1 -1
  134. package/build/template/routes/examples/_index.js +1 -1
  135. package/build/template/routes/examples/_index.js.map +1 -1
  136. package/build/template/routes/examples/name.d.ts.map +1 -1
  137. package/build/template/routes/examples/name.js +4 -2
  138. package/build/template/routes/examples/name.js.map +1 -1
  139. package/build/template/routes/reference.js +6 -6
  140. package/build/template/routes/reference.js.map +1 -1
  141. package/build/template/stores/toast.d.ts.map +1 -1
  142. package/build/template/stores/toast.js +5 -3
  143. package/build/template/stores/toast.js.map +1 -1
  144. package/build/vite/plugins/navbar.js +1 -1
  145. package/build/vite/plugins/navbar.js.map +1 -1
  146. package/build/vite/plugins/routes-manifest.js +1 -1
  147. package/build/vite/plugins/routes-manifest.js.map +1 -1
  148. package/package.json +7 -7
  149. package/src/api/builder/ssg/generate.ts +10 -5
  150. package/src/api/builder/ssg/page-generator.worker.ts +18 -3
  151. package/src/api/config/normalized.ts +12 -3
  152. package/src/api/config-template/template.ts +2 -2
  153. package/src/api/content/sidebar.ts +3 -3
  154. package/src/api/examples/config.test.ts +10 -0
  155. package/src/api/examples/config.ts +33 -4
  156. package/src/api/examples/diagnostic/missing-versions.ts +3 -2
  157. package/src/api/examples/diagnostic/unknown-version.ts +3 -2
  158. package/src/api/examples/diagnostic/validation-error.ts +9 -3
  159. package/src/api/examples/diagnostic/validator.test.ts +100 -55
  160. package/src/api/examples/diagnostic/validator.ts +148 -105
  161. package/src/api/examples/filter.ts +9 -6
  162. package/src/api/examples/scanner.ts +144 -120
  163. package/src/api/examples/type-usage-indexer.test.ts +44 -33
  164. package/src/api/examples/type-usage-indexer.ts +25 -40
  165. package/src/api/iso/schema/routing.ts +10 -10
  166. package/src/api/iso/schema/validation.ts +3 -2
  167. package/src/api/schema/$.test.ts +2 -2
  168. package/src/api/schema/input-sources/directory.ts +2 -2
  169. package/src/api/schema/input-sources/versioned-directory.ts +11 -8
  170. package/src/api/schema/load.ts +2 -2
  171. package/src/cli/commands/hero-image.ts +1 -1
  172. package/src/lib/catalog/catalog.ts +93 -16
  173. package/src/lib/catalog/versioned.ts +57 -7
  174. package/src/lib/catalog-statistics/$.test.ts +22 -12
  175. package/src/lib/catalog-statistics/analyze-catalog.ts +3 -3
  176. package/src/lib/document/document.ts +135 -2
  177. package/src/lib/document/versioned.ts +8 -8
  178. package/src/lib/lifecycles/lifecycles.ts +33 -28
  179. package/src/lib/version-coverage/$$.ts +1 -0
  180. package/src/lib/{version-selection/version-selection.ts → version-coverage/version-coverage.ts} +1 -1
  181. package/src/template/components/Changelog/Changelog.tsx +10 -6
  182. package/src/template/components/GraphQLDocument.tsx +11 -68
  183. package/src/template/components/GraphQLInteractive/lib/parser.ts +81 -29
  184. package/src/template/components/VersionCoveragePicker.tsx +4 -5
  185. package/src/template/components/VersionPicker.tsx +9 -2
  186. package/src/template/components/home/FeaturesGrid.tsx +1 -1
  187. package/src/template/components/home/HeroSection.tsx +1 -1
  188. package/src/template/components/home/QuickStart.tsx +16 -7
  189. package/src/template/components/home/RecentChanges.tsx +3 -1
  190. package/src/template/hooks/use-highlighted.ts +31 -19
  191. package/src/template/lib/fetch-text.ts +45 -4
  192. package/src/template/routes/changelog.tsx +10 -4
  193. package/src/template/routes/examples/_index.tsx +1 -1
  194. package/src/template/routes/examples/name.tsx +4 -2
  195. package/src/template/routes/reference.tsx +6 -6
  196. package/src/template/stores/toast.ts +6 -3
  197. package/src/vite/plugins/navbar.ts +1 -1
  198. package/src/vite/plugins/routes-manifest.ts +1 -1
  199. package/build/lib/graph/$$.d.ts +0 -2
  200. package/build/lib/graph/$$.d.ts.map +0 -1
  201. package/build/lib/graph/$$.js +0 -2
  202. package/build/lib/graph/$$.js.map +0 -1
  203. package/build/lib/graph/$.d.ts +0 -2
  204. package/build/lib/graph/$.d.ts.map +0 -1
  205. package/build/lib/graph/$.js +0 -2
  206. package/build/lib/graph/$.js.map +0 -1
  207. package/build/lib/graph/graph.d.ts +0 -127
  208. package/build/lib/graph/graph.d.ts.map +0 -1
  209. package/build/lib/graph/graph.js +0 -152
  210. package/build/lib/graph/graph.js.map +0 -1
  211. package/build/lib/mask/$$.d.ts +0 -3
  212. package/build/lib/mask/$$.d.ts.map +0 -1
  213. package/build/lib/mask/$$.js +0 -3
  214. package/build/lib/mask/$$.js.map +0 -1
  215. package/build/lib/mask/$.d.ts +0 -2
  216. package/build/lib/mask/$.d.ts.map +0 -1
  217. package/build/lib/mask/$.js +0 -2
  218. package/build/lib/mask/$.js.map +0 -1
  219. package/build/lib/mask/apply.d.ts +0 -86
  220. package/build/lib/mask/apply.d.ts.map +0 -1
  221. package/build/lib/mask/apply.js +0 -86
  222. package/build/lib/mask/apply.js.map +0 -1
  223. package/build/lib/mask/mask.d.ts +0 -124
  224. package/build/lib/mask/mask.d.ts.map +0 -1
  225. package/build/lib/mask/mask.js +0 -137
  226. package/build/lib/mask/mask.js.map +0 -1
  227. package/build/lib/mask/mask.test-d.d.ts +0 -2
  228. package/build/lib/mask/mask.test-d.d.ts.map +0 -1
  229. package/build/lib/mask/mask.test-d.js +0 -102
  230. package/build/lib/mask/mask.test-d.js.map +0 -1
  231. package/build/lib/version-selection/$$.d.ts +0 -2
  232. package/build/lib/version-selection/$$.d.ts.map +0 -1
  233. package/build/lib/version-selection/$$.js +0 -2
  234. package/build/lib/version-selection/$$.js.map +0 -1
  235. package/build/lib/version-selection/$.d.ts.map +0 -1
  236. package/build/lib/version-selection/$.js.map +0 -1
  237. package/build/lib/version-selection/version-selection.d.ts.map +0 -1
  238. package/build/lib/version-selection/version-selection.js.map +0 -1
  239. package/src/lib/graph/$$.ts +0 -1
  240. package/src/lib/graph/$.ts +0 -1
  241. package/src/lib/graph/graph.ts +0 -197
  242. package/src/lib/mask/$$.ts +0 -2
  243. package/src/lib/mask/$.test.ts +0 -226
  244. package/src/lib/mask/$.ts +0 -1
  245. package/src/lib/mask/apply.ts +0 -134
  246. package/src/lib/mask/mask.test-d.ts +0 -156
  247. package/src/lib/mask/mask.ts +0 -244
  248. package/src/lib/version-selection/$$.ts +0 -1
  249. /package/build/lib/{version-selection → version-coverage}/$.d.ts +0 -0
  250. /package/build/lib/{version-selection → version-coverage}/$.js +0 -0
  251. /package/src/lib/{version-selection → version-coverage}/$.ts +0 -0
@@ -1,197 +0,0 @@
1
- import { S } from '#lib/kit-temp/effect'
2
-
3
- // ─── Schema ──────────────────────────────────────────────────────────────────
4
-
5
- /**
6
- * Dependency graph for tracking relationships between nodes
7
- * Used to efficiently handle dependencies in various contexts
8
- */
9
- export const DependencyGraph = S.Struct({
10
- /**
11
- * Map from parent ID to array of child IDs (parent depends on children)
12
- */
13
- dependencies: S.Record({ key: S.String, value: S.Array(S.String) }),
14
-
15
- /**
16
- * Map from child ID to array of parent IDs (child is depended on by parents)
17
- */
18
- dependents: S.Record({ key: S.String, value: S.Array(S.String) }),
19
- }).annotations({
20
- identifier: 'DependencyGraph',
21
- description: 'A directed graph tracking dependencies between nodes',
22
- })
23
-
24
- export type DependencyGraph = typeof DependencyGraph.Type
25
-
26
- // ─── Constructors ────────────────────────────────────────────────────────────
27
-
28
- export const make = DependencyGraph.make
29
-
30
- /**
31
- * Create an empty dependency graph
32
- */
33
- export const create = (): DependencyGraph =>
34
- make({
35
- dependencies: {},
36
- dependents: {},
37
- })
38
-
39
- // ─── Domain Logic ────────────────────────────────────────────────────────────
40
-
41
- /**
42
- * Add a dependency relationship (immutable)
43
- * @param graph - The dependency graph
44
- * @param parent - The parent node ID
45
- * @param child - The child node ID that the parent depends on
46
- * @returns A new graph with the dependency added
47
- */
48
- export const addDependency = (
49
- graph: DependencyGraph,
50
- parent: string,
51
- child: string,
52
- ): DependencyGraph => {
53
- // Get existing arrays or create empty ones
54
- const children = graph.dependencies[parent] || []
55
- const parents = graph.dependents[child] || []
56
-
57
- // Add child if not already present
58
- const newChildren = children.includes(child) ? children : [...children, child]
59
-
60
- // Add parent if not already present
61
- const newParents = parents.includes(parent) ? parents : [...parents, parent]
62
-
63
- return make({
64
- dependencies: {
65
- ...graph.dependencies,
66
- [parent]: newChildren,
67
- },
68
- dependents: {
69
- ...graph.dependents,
70
- [child]: newParents,
71
- },
72
- })
73
- }
74
-
75
- /**
76
- * Add a dependency relationship (mutable)
77
- * @param graph - The dependency graph to mutate
78
- * @param parent - The parent node ID
79
- * @param child - The child node ID that the parent depends on
80
- */
81
- export const addDependencyMutable = (
82
- graph: DependencyGraph,
83
- parent: string,
84
- child: string,
85
- ): void => {
86
- // Cast to mutable for mutation
87
- const mutableGraph = graph as {
88
- dependencies: Record<string, string[]>
89
- dependents: Record<string, string[]>
90
- }
91
-
92
- // Add to dependencies
93
- if (!mutableGraph.dependencies[parent]) {
94
- mutableGraph.dependencies[parent] = []
95
- }
96
- if (!mutableGraph.dependencies[parent].includes(child)) {
97
- mutableGraph.dependencies[parent].push(child)
98
- }
99
-
100
- // Add to dependents
101
- if (!mutableGraph.dependents[child]) {
102
- mutableGraph.dependents[child] = []
103
- }
104
- if (!mutableGraph.dependents[child].includes(parent)) {
105
- mutableGraph.dependents[child].push(parent)
106
- }
107
- }
108
-
109
- /**
110
- * Find all nodes that have no dependencies (leaf nodes)
111
- */
112
- export const findLeafNodes = (graph: DependencyGraph): Set<string> => {
113
- const leaves = new Set<string>()
114
-
115
- // Check all nodes that appear as children
116
- for (const child of Object.keys(graph.dependents)) {
117
- const deps = graph.dependencies[child]
118
- if (!deps || deps.length === 0) {
119
- leaves.add(child)
120
- }
121
- }
122
-
123
- return leaves
124
- }
125
-
126
- /**
127
- * Check if all dependencies of a node have been processed
128
- */
129
- export const areDependenciesReady = (
130
- node: string,
131
- graph: DependencyGraph,
132
- processed: Set<string>,
133
- ): boolean => {
134
- const deps = graph.dependencies[node]
135
- if (!deps) return true
136
-
137
- return deps.every(dep => processed.has(dep))
138
- }
139
-
140
- /**
141
- * Get topological ordering of nodes (children before parents)
142
- * This ensures we process dependencies before the nodes that depend on them
143
- *
144
- * @param graph - The dependency graph
145
- * @returns Array of node IDs in topological order
146
- */
147
- export const topologicalSort = (graph: DependencyGraph): string[] => {
148
- const result: string[] = []
149
- const visited = new Set<string>()
150
- const visiting = new Set<string>() // For cycle detection
151
-
152
- // Get all nodes
153
- const allNodes = new Set<string>()
154
- for (const parent of Object.keys(graph.dependencies)) {
155
- allNodes.add(parent)
156
- }
157
- for (const child of Object.keys(graph.dependents)) {
158
- allNodes.add(child)
159
- }
160
-
161
- const visit = (node: string): void => {
162
- if (visited.has(node)) return
163
-
164
- if (visiting.has(node)) {
165
- // Cycle detected - just skip this node
166
- return
167
- }
168
-
169
- visiting.add(node)
170
-
171
- // Visit all children first
172
- const children = graph.dependencies[node]
173
- if (children) {
174
- for (const child of children) {
175
- visit(child)
176
- }
177
- }
178
-
179
- visiting.delete(node)
180
- visited.add(node)
181
- result.push(node)
182
- }
183
-
184
- // Visit all nodes
185
- for (const node of allNodes) {
186
- visit(node)
187
- }
188
-
189
- return result
190
- }
191
-
192
- // ─── Codec ───────────────────────────────────────────────────────────────────
193
-
194
- export const decode = S.decode(DependencyGraph)
195
- export const decodeSync = S.decodeSync(DependencyGraph)
196
- export const encode = S.encode(DependencyGraph)
197
- export const encodeSync = S.encodeSync(DependencyGraph)
@@ -1,2 +0,0 @@
1
- export * from './apply.js'
2
- export * from './mask.js'
@@ -1,226 +0,0 @@
1
- import * as fc from 'fast-check'
2
- import { describe, expect, test } from 'vitest'
3
- import { Test } from '../../../tests/unit/helpers/test.js'
4
- import { Mask } from './$.js'
5
-
6
- // dprint-ignore
7
- Test.suite<{ options: any; expectedType: 'binary' | 'properties'; expectedMode?: 'allow' | 'deny'; expectedShow?: boolean; expectedProperties?: string[] }>('Mask.create', [
8
- { name: 'boolean true creates binary show mask', options: true, expectedType: 'binary', expectedShow: true },
9
- { name: 'boolean false creates binary hide mask', options: false, expectedType: 'binary', expectedShow: false },
10
- { name: 'array creates allow mode properties mask', options: ['name', 'age'], expectedType: 'properties', expectedMode: 'allow', expectedProperties: ['name', 'age'] },
11
- { name: 'object with true values creates allow mode', options: { name: true, age: true, password: false }, expectedType: 'properties', expectedMode: 'allow', expectedProperties: ['name', 'age'] },
12
- { name: 'object with false values creates deny mode', options: { password: false, secret: false }, expectedType: 'properties', expectedMode: 'deny', expectedProperties: ['password', 'secret'] },
13
- ], ({ options, expectedType, expectedMode, expectedShow, expectedProperties }) => {
14
- const mask = Mask.create(options)
15
- expect(mask.type).toBe(expectedType)
16
-
17
- if (expectedType === 'binary' && mask.type === 'binary') {
18
- expect(mask.show).toBe(expectedShow)
19
- }
20
-
21
- if (expectedType === 'properties' && mask.type === 'properties') {
22
- expect(mask.mode).toBe(expectedMode)
23
- expect(mask.properties).toEqual(expectedProperties)
24
- }
25
- })
26
-
27
- // dprint-ignore
28
- Test.suite<{ data: any; maskOptions: any; shouldThrow?: boolean; expected?: any }>('Mask.apply', [
29
- { name: 'binary show mask returns data', data: { a: 1 }, maskOptions: true, expected: { a: 1 } },
30
- { name: 'binary hide mask returns undefined', data: { a: 1 }, maskOptions: false, expected: undefined },
31
- { name: 'allow mode filters properties', data: { name: 'John', age: 30, password: 'secret' }, maskOptions: ['name', 'age'], expected: { name: 'John', age: 30 } },
32
- { name: 'deny mode removes properties', data: { name: 'John', age: 30, password: 'secret' }, maskOptions: { password: false }, expected: { name: 'John', age: 30 } },
33
- { name: 'properties mask throws for string', data: 'string', maskOptions: ['name'], shouldThrow: true },
34
- { name: 'properties mask throws for number', data: 123, maskOptions: ['name'], shouldThrow: true },
35
- { name: 'properties mask throws for null', data: null, maskOptions: ['name'], shouldThrow: true },
36
- ], ({ data, maskOptions, shouldThrow, expected }) => {
37
- const mask = Mask.create(maskOptions)
38
-
39
- if (shouldThrow) {
40
- expect(() => Mask.apply(data as any, mask)).toThrow()
41
- } else {
42
- const result = Mask.apply(data, mask)
43
- if (expected === undefined) {
44
- expect(result).toBe(undefined)
45
- } else {
46
- expect(result).toEqual(expected)
47
- }
48
- }
49
- })
50
-
51
- // dprint-ignore
52
- Test.suite<{ method: 'applyPartial' | 'applyExact'; data: any; maskOptions: any; expected: any }>('apply variants', [
53
- { name: 'applyPartial allows missing properties', method: 'applyPartial', data: { name: 'John' }, maskOptions: ['name', 'age'], expected: { name: 'John' } },
54
- { name: 'applyPartial with empty object', method: 'applyPartial', data: {}, maskOptions: ['name', 'age'], expected: {} },
55
- { name: 'applyExact with binary show mask', method: 'applyExact', data: 'hello', maskOptions: true, expected: 'hello' },
56
- { name: 'applyExact with binary hide mask', method: 'applyExact', data: 'hello', maskOptions: false, expected: undefined },
57
- ], ({ method, data, maskOptions, expected }) => {
58
- const mask = Mask.create(maskOptions)
59
-
60
- const result = method === 'applyPartial'
61
- ? Mask.applyPartial(data, mask)
62
- : Mask.applyExact(data as any, mask)
63
-
64
- if (expected === undefined) {
65
- expect(result).toBe(undefined)
66
- } else {
67
- expect(result).toEqual(expected)
68
- }
69
- })
70
-
71
- describe('property-based tests', () => {
72
- test('binary masks - invariants', () => {
73
- fc.assert(
74
- fc.property(fc.anything(), (data) => {
75
- expect(Mask.apply(data, Mask.create(true))).toBe(data)
76
- expect(Mask.apply(data, Mask.create(false))).toBe(undefined)
77
- }),
78
- )
79
- })
80
-
81
- test('properties mask - allow mode filters correctly', () => {
82
- fc.assert(
83
- fc.property(
84
- fc.dictionary(fc.string(), fc.anything()),
85
- fc.array(fc.string(), { minLength: 1 }),
86
- (obj, keys) => {
87
- const mask = Mask.create(keys)
88
- const result = Mask.apply(obj as any, mask)
89
- const resultKeys = Object.keys(result as any)
90
-
91
- // Result contains only keys that were in both mask and object
92
- expect(resultKeys.every(key => keys.includes(key))).toBe(true)
93
-
94
- // All requested keys that are own properties of obj are in result
95
- keys.forEach(key => {
96
- if (Object.prototype.hasOwnProperty.call(obj, key)) {
97
- expect(result).toHaveProperty(key, (obj as any)[key])
98
- }
99
- })
100
- },
101
- ),
102
- )
103
- })
104
-
105
- test('properties mask - deny mode filters correctly', () => {
106
- fc.assert(
107
- fc.property(
108
- fc.dictionary(fc.string(), fc.anything()),
109
- fc.uniqueArray(fc.string(), { minLength: 1 }),
110
- (data, keysToRemove) => {
111
- const maskSpec = Object.fromEntries(keysToRemove.map(k => [k, false]))
112
- const mask = Mask.create(maskSpec)
113
-
114
- expect(mask.type).toBe('properties')
115
- if (mask.type !== 'properties') return
116
- expect(mask.mode).toBe('deny')
117
-
118
- const result = Mask.apply(data as any, mask)
119
-
120
- // Result should not have any of the denied keys
121
- keysToRemove.forEach(key => {
122
- expect(Object.prototype.hasOwnProperty.call(result, key)).toBe(false)
123
- })
124
-
125
- // Result should have all other keys from data
126
- Object.keys(data).forEach(key => {
127
- if (!keysToRemove.includes(key)) {
128
- expect(Object.prototype.hasOwnProperty.call(result, key)).toBe(true)
129
- expect((result as any)[key]).toBe((data as any)[key])
130
- }
131
- })
132
- },
133
- ),
134
- )
135
- })
136
-
137
- test('undefined values are preserved', () => {
138
- fc.assert(
139
- fc.property(
140
- fc.record({
141
- a: fc.oneof(fc.anything(), fc.constant(undefined)),
142
- b: fc.oneof(fc.anything(), fc.constant(undefined)),
143
- c: fc.oneof(fc.anything(), fc.constant(undefined)),
144
- }),
145
- fc.shuffledSubarray(['a', 'b', 'c'], { minLength: 1 }),
146
- (obj, keys) => {
147
- const result = Mask.apply(obj as any, Mask.create(keys))
148
-
149
- keys.forEach(key => {
150
- if (Object.prototype.hasOwnProperty.call(obj, key)) {
151
- expect(result).toHaveProperty(key)
152
- expect((result as any)[key]).toBe((obj as any)[key])
153
- }
154
- })
155
- },
156
- ),
157
- )
158
- })
159
-
160
- test('apply and applyPartial are consistent for complete data', () => {
161
- fc.assert(
162
- fc.property(
163
- fc.dictionary(fc.string(), fc.anything()),
164
- fc.array(fc.string(), { minLength: 1 }),
165
- (data, keys) => {
166
- const mask = Mask.create(keys)
167
- expect(Mask.apply(data as any, mask)).toEqual(Mask.applyPartial(data as any, mask))
168
- },
169
- ),
170
- )
171
- })
172
-
173
- test('non-objects throw with properties masks', () => {
174
- fc.assert(
175
- fc.property(
176
- fc.oneof(
177
- fc.string(),
178
- fc.integer(),
179
- fc.boolean(),
180
- fc.constant(null),
181
- fc.constant(undefined),
182
- ),
183
- fc.array(fc.string(), { minLength: 1 }),
184
- (nonObject, keys) => {
185
- const mask = Mask.create(keys)
186
- expect(() => Mask.apply(nonObject as any, mask)).toThrow('Cannot apply properties mask to non-object data')
187
- },
188
- ),
189
- )
190
- })
191
-
192
- test('immutability invariants', () => {
193
- fc.assert(
194
- fc.property(
195
- fc.dictionary(
196
- fc.string(),
197
- fc.oneof(
198
- fc.string(),
199
- fc.integer(),
200
- fc.boolean(),
201
- fc.constant(null),
202
- ),
203
- ),
204
- fc.oneof(
205
- fc.boolean(),
206
- fc.array(fc.string()),
207
- fc.dictionary(fc.string(), fc.boolean()),
208
- ),
209
- (data, maskOptions) => {
210
- const mask = Mask.create(maskOptions as any)
211
- const originalData = { ...data }
212
- const originalMask = JSON.parse(JSON.stringify(mask))
213
-
214
- try {
215
- Mask.apply(data as any, mask)
216
- } catch {
217
- // Ignore errors for invalid combinations
218
- }
219
-
220
- expect(data).toEqual(originalData)
221
- expect(mask).toEqual(originalMask)
222
- },
223
- ),
224
- )
225
- })
226
- })
package/src/lib/mask/$.ts DELETED
@@ -1 +0,0 @@
1
- export * as Mask from './$$.js'
@@ -1,134 +0,0 @@
1
- import { type ExtendsExact, objPolicyFilter } from '#lib/kit-temp'
2
- import { Obj } from '@wollybeard/kit'
3
- import { never } from '@wollybeard/kit/language'
4
- import type { GetDataType, Mask } from './mask.js'
5
-
6
- /**
7
- * Type-level function that applies a mask to data.
8
- *
9
- * @template Data - The data type
10
- * @template M - The mask type
11
- *
12
- * Binary masks:
13
- * - show=true returns the data unchanged
14
- * - show=false returns undefined
15
- *
16
- * Properties masks:
17
- * - 'allow' mode returns Pick<Data, keys>
18
- * - 'deny' mode returns Omit<Data, keys>
19
- * - Non-objects throw an error at runtime
20
- */
21
- // dprint-ignore
22
- export type Apply<$Data, $M extends Mask> =
23
- $M extends { type: `binary`, show: boolean }
24
- ? $M[`show`] extends true
25
- ? $Data
26
- : undefined
27
- : $M extends { type: `properties`, mode: string, properties: any[] }
28
- ? $Data extends object
29
- ? $M[`mode`] extends `allow`
30
- ? Pick<$Data, Extract<$M[`properties`][number], keyof $Data>>
31
- : Omit<$Data, Extract<$M[`properties`][number], keyof $Data>>
32
- : never // Non-objects not allowed with property masks
33
- : never
34
-
35
- /**
36
- * Apply mask to data with standard covariance.
37
- *
38
- * Data must be assignable to the mask's expected type (may have excess properties).
39
- *
40
- * @param data - The data to mask
41
- * @param mask - The mask to apply
42
- * @returns The masked data
43
- *
44
- * @example
45
- * ```ts
46
- * const user = { name: 'John', email: 'john@example.com', password: 'secret' }
47
- * const mask = Mask.pick<User>(['name', 'email'])
48
- * const safeUser = apply(user, mask) // { name: 'John', email: 'john@example.com' }
49
- * ```
50
- */
51
- export const apply = <
52
- data extends GetDataType<mask>,
53
- mask extends Mask,
54
- >(data: data, mask: mask): Apply<data, mask> => {
55
- return applyInternal(data, mask) as Apply<data, mask>
56
- }
57
-
58
- /**
59
- * Apply mask to partial data.
60
- *
61
- * Data may have only a subset of the mask's expected properties.
62
- * Useful when working with incomplete data or optional fields.
63
- *
64
- * @param data - The partial data to mask
65
- * @param mask - The mask to apply
66
- * @returns The masked data
67
- *
68
- * @example
69
- * ```ts
70
- * const partialUser = { name: 'John' } // missing email
71
- * const mask = Mask.pick<User>(['name', 'email'])
72
- * const result = applyPartial(partialUser, mask) // { name: 'John' }
73
- * ```
74
- */
75
- export const applyPartial = <
76
- data extends Partial<GetDataType<mask>>,
77
- mask extends Mask,
78
- >(data: data, mask: mask): Apply<data, mask> => {
79
- return applyInternal(data, mask) as Apply<data, mask>
80
- }
81
-
82
- /**
83
- * Apply mask to data with exact type matching.
84
- *
85
- * Data must exactly match the mask's expected type - no missing or excess properties.
86
- * Provides the strictest type checking.
87
- *
88
- * @param data - The data to mask (must exactly match expected type)
89
- * @param mask - The mask to apply
90
- * @returns The masked data
91
- *
92
- * @example
93
- * ```ts
94
- * type User = { name: string; email: string }
95
- * const mask = Mask.pick<User>(['name'])
96
- *
97
- * // This works - exact match
98
- * const user: User = { name: 'John', email: 'john@example.com' }
99
- * const result = applyExact(user, mask)
100
- *
101
- * // This fails - has extra property
102
- * const userWithExtra = { name: 'John', email: 'john@example.com', age: 30 }
103
- * const result2 = applyExact(userWithExtra, mask) // Type error!
104
- * ```
105
- */
106
- export const applyExact = <
107
- data,
108
- mask extends Mask,
109
- >(
110
- data: ExtendsExact<data, GetDataType<mask>>,
111
- mask: mask,
112
- ): Apply<data, mask> => {
113
- return applyInternal(data, mask) as Apply<data, mask>
114
- }
115
-
116
- // Internal implementation
117
- const applyInternal = (data: any, mask: Mask): any => {
118
- // ━ Handle binary mask
119
- if (mask.type === `binary`) {
120
- return mask.show ? data : undefined
121
- }
122
-
123
- // ━ Handle properties mask
124
- if (mask.type === `properties`) {
125
- // Properties mask requires object data
126
- if (!Obj.is(data)) {
127
- throw new Error(`Cannot apply properties mask to non-object data`)
128
- }
129
-
130
- return objPolicyFilter(mask.mode, data, mask.properties)
131
- }
132
-
133
- never()
134
- }