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.
- package/build/api/builder/ssg/generate.d.ts.map +1 -1
- package/build/api/builder/ssg/generate.js +5 -5
- package/build/api/builder/ssg/generate.js.map +1 -1
- package/build/api/builder/ssg/page-generator.worker.js +13 -3
- package/build/api/builder/ssg/page-generator.worker.js.map +1 -1
- package/build/api/config/input.d.ts +88 -3
- package/build/api/config/input.d.ts.map +1 -1
- package/build/api/config/normalized.d.ts +92 -7
- package/build/api/config/normalized.d.ts.map +1 -1
- package/build/api/config/normalized.js +11 -3
- package/build/api/config/normalized.js.map +1 -1
- package/build/api/config-template/template.js +2 -2
- package/build/api/config-template/template.js.map +1 -1
- package/build/api/content/sidebar.d.ts.map +1 -1
- package/build/api/content/sidebar.js +2 -1
- package/build/api/content/sidebar.js.map +1 -1
- package/build/api/examples/config.d.ts +366 -3
- package/build/api/examples/config.d.ts.map +1 -1
- package/build/api/examples/config.js +25 -3
- package/build/api/examples/config.js.map +1 -1
- package/build/api/examples/diagnostic/diagnostic.d.ts +5 -5
- package/build/api/examples/diagnostic/missing-versions.d.ts +5 -4
- package/build/api/examples/diagnostic/missing-versions.d.ts.map +1 -1
- package/build/api/examples/diagnostic/missing-versions.js +3 -2
- package/build/api/examples/diagnostic/missing-versions.js.map +1 -1
- package/build/api/examples/diagnostic/unknown-version.d.ts +5 -4
- package/build/api/examples/diagnostic/unknown-version.d.ts.map +1 -1
- package/build/api/examples/diagnostic/unknown-version.js +3 -2
- package/build/api/examples/diagnostic/unknown-version.js.map +1 -1
- package/build/api/examples/diagnostic/validation-error.d.ts +3 -2
- package/build/api/examples/diagnostic/validation-error.d.ts.map +1 -1
- package/build/api/examples/diagnostic/validation-error.js +9 -3
- package/build/api/examples/diagnostic/validation-error.js.map +1 -1
- package/build/api/examples/diagnostic/validator.d.ts.map +1 -1
- package/build/api/examples/diagnostic/validator.js +115 -69
- package/build/api/examples/diagnostic/validator.js.map +1 -1
- package/build/api/examples/filter.d.ts.map +1 -1
- package/build/api/examples/filter.js +9 -6
- package/build/api/examples/filter.js.map +1 -1
- package/build/api/examples/scanner.d.ts.map +1 -1
- package/build/api/examples/scanner.js +93 -103
- package/build/api/examples/scanner.js.map +1 -1
- package/build/api/examples/type-usage-indexer.d.ts.map +1 -1
- package/build/api/examples/type-usage-indexer.js +18 -32
- package/build/api/examples/type-usage-indexer.js.map +1 -1
- package/build/api/iso/schema/routing.d.ts.map +1 -1
- package/build/api/iso/schema/routing.js +8 -8
- package/build/api/iso/schema/routing.js.map +1 -1
- package/build/api/iso/schema/validation.d.ts.map +1 -1
- package/build/api/iso/schema/validation.js +3 -2
- package/build/api/iso/schema/validation.js.map +1 -1
- package/build/api/schema/input-sources/directory.js +2 -2
- package/build/api/schema/input-sources/directory.js.map +1 -1
- package/build/api/schema/input-sources/versioned-directory.d.ts +3 -3
- package/build/api/schema/input-sources/versioned-directory.d.ts.map +1 -1
- package/build/api/schema/input-sources/versioned-directory.js +6 -4
- package/build/api/schema/input-sources/versioned-directory.js.map +1 -1
- package/build/api/schema/load.d.ts.map +1 -1
- package/build/api/schema/load.js +2 -2
- package/build/api/schema/load.js.map +1 -1
- package/build/cli/commands/hero-image.js +1 -1
- package/build/cli/commands/hero-image.js.map +1 -1
- package/build/lib/catalog/catalog.d.ts +65 -24
- package/build/lib/catalog/catalog.d.ts.map +1 -1
- package/build/lib/catalog/catalog.js +72 -16
- package/build/lib/catalog/catalog.js.map +1 -1
- package/build/lib/catalog/versioned.d.ts +46 -26
- package/build/lib/catalog/versioned.d.ts.map +1 -1
- package/build/lib/catalog/versioned.js +44 -7
- package/build/lib/catalog/versioned.js.map +1 -1
- package/build/lib/catalog-statistics/analyze-catalog.js +3 -3
- package/build/lib/catalog-statistics/analyze-catalog.js.map +1 -1
- package/build/lib/document/document.d.ts +55 -5
- package/build/lib/document/document.d.ts.map +1 -1
- package/build/lib/document/document.js +96 -2
- package/build/lib/document/document.js.map +1 -1
- package/build/lib/document/versioned.d.ts +2 -2
- package/build/lib/document/versioned.d.ts.map +1 -1
- package/build/lib/document/versioned.js +7 -7
- package/build/lib/document/versioned.js.map +1 -1
- package/build/lib/lifecycles/lifecycles.d.ts +5 -4
- package/build/lib/lifecycles/lifecycles.d.ts.map +1 -1
- package/build/lib/lifecycles/lifecycles.js +15 -13
- package/build/lib/lifecycles/lifecycles.js.map +1 -1
- package/build/lib/version-coverage/$$.d.ts +2 -0
- package/build/lib/version-coverage/$$.d.ts.map +1 -0
- package/build/lib/version-coverage/$$.js +2 -0
- package/build/lib/version-coverage/$$.js.map +1 -0
- package/build/lib/version-coverage/$.d.ts.map +1 -0
- package/build/lib/version-coverage/$.js.map +1 -0
- package/build/lib/{version-selection/version-selection.d.ts → version-coverage/version-coverage.d.ts} +1 -1
- package/build/lib/version-coverage/version-coverage.d.ts.map +1 -0
- package/build/lib/{version-selection/version-selection.js → version-coverage/version-coverage.js} +2 -2
- package/build/lib/version-coverage/version-coverage.js.map +1 -0
- package/build/template/components/Changelog/Changelog.d.ts.map +1 -1
- package/build/template/components/Changelog/Changelog.js +7 -7
- package/build/template/components/Changelog/Changelog.js.map +1 -1
- package/build/template/components/GraphQLDocument.d.ts +1 -1
- package/build/template/components/GraphQLDocument.d.ts.map +1 -1
- package/build/template/components/GraphQLDocument.js +10 -38
- package/build/template/components/GraphQLDocument.js.map +1 -1
- package/build/template/components/GraphQLInteractive/lib/parser.d.ts +28 -0
- package/build/template/components/GraphQLInteractive/lib/parser.d.ts.map +1 -1
- package/build/template/components/GraphQLInteractive/lib/parser.js +60 -27
- package/build/template/components/GraphQLInteractive/lib/parser.js.map +1 -1
- package/build/template/components/VersionCoveragePicker.d.ts +1 -1
- package/build/template/components/VersionCoveragePicker.d.ts.map +1 -1
- package/build/template/components/VersionCoveragePicker.js +4 -6
- package/build/template/components/VersionCoveragePicker.js.map +1 -1
- package/build/template/components/VersionPicker.d.ts.map +1 -1
- package/build/template/components/VersionPicker.js +5 -2
- package/build/template/components/VersionPicker.js.map +1 -1
- package/build/template/components/home/FeaturesGrid.js +1 -1
- package/build/template/components/home/FeaturesGrid.js.map +1 -1
- package/build/template/components/home/HeroSection.js +1 -1
- package/build/template/components/home/HeroSection.js.map +1 -1
- package/build/template/components/home/QuickStart.d.ts.map +1 -1
- package/build/template/components/home/QuickStart.js +8 -4
- package/build/template/components/home/QuickStart.js.map +1 -1
- package/build/template/components/home/RecentChanges.d.ts.map +1 -1
- package/build/template/components/home/RecentChanges.js +2 -1
- package/build/template/components/home/RecentChanges.js.map +1 -1
- package/build/template/hooks/use-highlighted.d.ts.map +1 -1
- package/build/template/hooks/use-highlighted.js +19 -13
- package/build/template/hooks/use-highlighted.js.map +1 -1
- package/build/template/lib/fetch-text.d.ts +18 -0
- package/build/template/lib/fetch-text.d.ts.map +1 -1
- package/build/template/lib/fetch-text.js +32 -4
- package/build/template/lib/fetch-text.js.map +1 -1
- package/build/template/routes/changelog.d.ts +1 -1
- package/build/template/routes/changelog.d.ts.map +1 -1
- package/build/template/routes/changelog.js +7 -4
- package/build/template/routes/changelog.js.map +1 -1
- package/build/template/routes/examples/_index.js +1 -1
- package/build/template/routes/examples/_index.js.map +1 -1
- package/build/template/routes/examples/name.d.ts.map +1 -1
- package/build/template/routes/examples/name.js +4 -2
- package/build/template/routes/examples/name.js.map +1 -1
- package/build/template/routes/reference.js +6 -6
- package/build/template/routes/reference.js.map +1 -1
- package/build/template/stores/toast.d.ts.map +1 -1
- package/build/template/stores/toast.js +5 -3
- package/build/template/stores/toast.js.map +1 -1
- package/build/vite/plugins/navbar.js +1 -1
- package/build/vite/plugins/navbar.js.map +1 -1
- package/build/vite/plugins/routes-manifest.js +1 -1
- package/build/vite/plugins/routes-manifest.js.map +1 -1
- package/package.json +7 -7
- package/src/api/builder/ssg/generate.ts +10 -5
- package/src/api/builder/ssg/page-generator.worker.ts +18 -3
- package/src/api/config/normalized.ts +12 -3
- package/src/api/config-template/template.ts +2 -2
- package/src/api/content/sidebar.ts +3 -3
- package/src/api/examples/config.test.ts +10 -0
- package/src/api/examples/config.ts +33 -4
- package/src/api/examples/diagnostic/missing-versions.ts +3 -2
- package/src/api/examples/diagnostic/unknown-version.ts +3 -2
- package/src/api/examples/diagnostic/validation-error.ts +9 -3
- package/src/api/examples/diagnostic/validator.test.ts +100 -55
- package/src/api/examples/diagnostic/validator.ts +148 -105
- package/src/api/examples/filter.ts +9 -6
- package/src/api/examples/scanner.ts +144 -120
- package/src/api/examples/type-usage-indexer.test.ts +44 -33
- package/src/api/examples/type-usage-indexer.ts +25 -40
- package/src/api/iso/schema/routing.ts +10 -10
- package/src/api/iso/schema/validation.ts +3 -2
- package/src/api/schema/$.test.ts +2 -2
- package/src/api/schema/input-sources/directory.ts +2 -2
- package/src/api/schema/input-sources/versioned-directory.ts +11 -8
- package/src/api/schema/load.ts +2 -2
- package/src/cli/commands/hero-image.ts +1 -1
- package/src/lib/catalog/catalog.ts +93 -16
- package/src/lib/catalog/versioned.ts +57 -7
- package/src/lib/catalog-statistics/$.test.ts +22 -12
- package/src/lib/catalog-statistics/analyze-catalog.ts +3 -3
- package/src/lib/document/document.ts +135 -2
- package/src/lib/document/versioned.ts +8 -8
- package/src/lib/lifecycles/lifecycles.ts +33 -28
- package/src/lib/version-coverage/$$.ts +1 -0
- package/src/lib/{version-selection/version-selection.ts → version-coverage/version-coverage.ts} +1 -1
- package/src/template/components/Changelog/Changelog.tsx +10 -6
- package/src/template/components/GraphQLDocument.tsx +11 -68
- package/src/template/components/GraphQLInteractive/lib/parser.ts +81 -29
- package/src/template/components/VersionCoveragePicker.tsx +4 -5
- package/src/template/components/VersionPicker.tsx +9 -2
- package/src/template/components/home/FeaturesGrid.tsx +1 -1
- package/src/template/components/home/HeroSection.tsx +1 -1
- package/src/template/components/home/QuickStart.tsx +16 -7
- package/src/template/components/home/RecentChanges.tsx +3 -1
- package/src/template/hooks/use-highlighted.ts +31 -19
- package/src/template/lib/fetch-text.ts +45 -4
- package/src/template/routes/changelog.tsx +10 -4
- package/src/template/routes/examples/_index.tsx +1 -1
- package/src/template/routes/examples/name.tsx +4 -2
- package/src/template/routes/reference.tsx +6 -6
- package/src/template/stores/toast.ts +6 -3
- package/src/vite/plugins/navbar.ts +1 -1
- package/src/vite/plugins/routes-manifest.ts +1 -1
- package/build/lib/graph/$$.d.ts +0 -2
- package/build/lib/graph/$$.d.ts.map +0 -1
- package/build/lib/graph/$$.js +0 -2
- package/build/lib/graph/$$.js.map +0 -1
- package/build/lib/graph/$.d.ts +0 -2
- package/build/lib/graph/$.d.ts.map +0 -1
- package/build/lib/graph/$.js +0 -2
- package/build/lib/graph/$.js.map +0 -1
- package/build/lib/graph/graph.d.ts +0 -127
- package/build/lib/graph/graph.d.ts.map +0 -1
- package/build/lib/graph/graph.js +0 -152
- package/build/lib/graph/graph.js.map +0 -1
- package/build/lib/mask/$$.d.ts +0 -3
- package/build/lib/mask/$$.d.ts.map +0 -1
- package/build/lib/mask/$$.js +0 -3
- package/build/lib/mask/$$.js.map +0 -1
- package/build/lib/mask/$.d.ts +0 -2
- package/build/lib/mask/$.d.ts.map +0 -1
- package/build/lib/mask/$.js +0 -2
- package/build/lib/mask/$.js.map +0 -1
- package/build/lib/mask/apply.d.ts +0 -86
- package/build/lib/mask/apply.d.ts.map +0 -1
- package/build/lib/mask/apply.js +0 -86
- package/build/lib/mask/apply.js.map +0 -1
- package/build/lib/mask/mask.d.ts +0 -124
- package/build/lib/mask/mask.d.ts.map +0 -1
- package/build/lib/mask/mask.js +0 -137
- package/build/lib/mask/mask.js.map +0 -1
- package/build/lib/mask/mask.test-d.d.ts +0 -2
- package/build/lib/mask/mask.test-d.d.ts.map +0 -1
- package/build/lib/mask/mask.test-d.js +0 -102
- package/build/lib/mask/mask.test-d.js.map +0 -1
- package/build/lib/version-selection/$$.d.ts +0 -2
- package/build/lib/version-selection/$$.d.ts.map +0 -1
- package/build/lib/version-selection/$$.js +0 -2
- package/build/lib/version-selection/$$.js.map +0 -1
- package/build/lib/version-selection/$.d.ts.map +0 -1
- package/build/lib/version-selection/$.js.map +0 -1
- package/build/lib/version-selection/version-selection.d.ts.map +0 -1
- package/build/lib/version-selection/version-selection.js.map +0 -1
- package/src/lib/graph/$$.ts +0 -1
- package/src/lib/graph/$.ts +0 -1
- package/src/lib/graph/graph.ts +0 -197
- package/src/lib/mask/$$.ts +0 -2
- package/src/lib/mask/$.test.ts +0 -226
- package/src/lib/mask/$.ts +0 -1
- package/src/lib/mask/apply.ts +0 -134
- package/src/lib/mask/mask.test-d.ts +0 -156
- package/src/lib/mask/mask.ts +0 -244
- package/src/lib/version-selection/$$.ts +0 -1
- /package/build/lib/{version-selection → version-coverage}/$.d.ts +0 -0
- /package/build/lib/{version-selection → version-coverage}/$.js +0 -0
- /package/src/lib/{version-selection → version-coverage}/$.ts +0 -0
@@ -1,156 +0,0 @@
|
|
1
|
-
import { Ts } from '@wollybeard/kit'
|
2
|
-
import { Mask } from './$.js'
|
3
|
-
import type { InferOptions, Mask as MaskType, PropertiesMask } from './mask.js'
|
4
|
-
|
5
|
-
// Test 1: InferOptions with unknown should accept all option types
|
6
|
-
{
|
7
|
-
type Options = InferOptions<unknown>
|
8
|
-
|
9
|
-
// This is a type-level assertion - we need to use a different pattern
|
10
|
-
type _Test = Ts.AssertExact<Options, boolean | string[] | Record<string, boolean>>
|
11
|
-
|
12
|
-
// All of these should be valid options
|
13
|
-
const option1: Options = true
|
14
|
-
const option2: Options = false
|
15
|
-
const option3: Options = [`name`, `age`]
|
16
|
-
const option4: Options = []
|
17
|
-
const option5: Options = { name: true, age: false }
|
18
|
-
const option6: Options = {}
|
19
|
-
}
|
20
|
-
|
21
|
-
// Test 2: Mask.create with unknown data type should accept all option types
|
22
|
-
{
|
23
|
-
// Boolean options
|
24
|
-
const mask1 = Mask.create(true)
|
25
|
-
const mask2 = Mask.create(false)
|
26
|
-
// Without explicit type parameter, returns union type
|
27
|
-
Ts.assertEqual<MaskType<unknown>>()(mask1)
|
28
|
-
Ts.assertEqual<MaskType<unknown>>()(mask2)
|
29
|
-
|
30
|
-
// Array options (no type parameter needed)
|
31
|
-
const mask3 = Mask.create([`name`, `age`])
|
32
|
-
const mask4 = Mask.create([])
|
33
|
-
const mask5 = Mask.create([`a`, `b`, `c`])
|
34
|
-
// Returns union type with inferred properties
|
35
|
-
Ts.assertEqual<MaskType<{ name: any; age: any }>>()(mask3)
|
36
|
-
Ts.assertEqual<MaskType<unknown>>()(mask4)
|
37
|
-
Ts.assertEqual<MaskType<{ a: any; b: any; c: any }>>()(mask5)
|
38
|
-
|
39
|
-
// Object options
|
40
|
-
const mask6 = Mask.create({ name: true, age: false })
|
41
|
-
const mask7 = Mask.create({})
|
42
|
-
const mask8 = Mask.create({ foo: true, bar: true, baz: false })
|
43
|
-
// Returns union type with inferred properties
|
44
|
-
Ts.assertEqual<MaskType<unknown>>()(mask6)
|
45
|
-
Ts.assertEqual<MaskType<unknown>>()(mask7)
|
46
|
-
Ts.assertEqual<MaskType<unknown>>()(mask8)
|
47
|
-
}
|
48
|
-
|
49
|
-
// Test 3: With specific data type, options are constrained
|
50
|
-
{
|
51
|
-
interface User {
|
52
|
-
name: string
|
53
|
-
age: number
|
54
|
-
email: string
|
55
|
-
}
|
56
|
-
|
57
|
-
// Valid options
|
58
|
-
const mask1 = Mask.create<User>(true)
|
59
|
-
const mask2 = Mask.create<User>([`name`, `age`])
|
60
|
-
const mask3 = Mask.create<User>({ name: true, age: false, email: true })
|
61
|
-
|
62
|
-
// With explicit type parameter, still returns union type
|
63
|
-
Ts.assertEqual<MaskType<User>>()(mask1)
|
64
|
-
Ts.assertEqual<MaskType<User>>()(mask2)
|
65
|
-
Ts.assertEqual<MaskType<User>>()(mask3)
|
66
|
-
|
67
|
-
// Invalid cases would be compile errors
|
68
|
-
// const mask4 = Mask.create<User>(['invalid']) // Error: 'invalid' is not a key of User
|
69
|
-
// const mask5 = Mask.create<User>({ invalid: true }) // Error: 'invalid' is not a property of User
|
70
|
-
}
|
71
|
-
|
72
|
-
// Test 4: Non-object types only accept boolean
|
73
|
-
{
|
74
|
-
const mask1 = Mask.create<string>(true)
|
75
|
-
const mask2 = Mask.create<string>(false)
|
76
|
-
|
77
|
-
Ts.assertEqual<MaskType<string>>()(mask1)
|
78
|
-
Ts.assertEqual<MaskType<string>>()(mask2)
|
79
|
-
|
80
|
-
// Invalid cases would be compile errors
|
81
|
-
// const mask3 = Mask.create<string>(['prop']) // Error: string is not an object
|
82
|
-
// const mask4 = Mask.create<string>({ prop: true }) // Error: string is not an object
|
83
|
-
}
|
84
|
-
|
85
|
-
// Test 5: Test inference in practical scenarios
|
86
|
-
{
|
87
|
-
// Should infer PropertiesMask with object data type
|
88
|
-
const userMask = Mask.create([`name`, `email`, `password`])
|
89
|
-
Ts.assertEqual<MaskType<{ name: any; email: any; password: any }>>()(userMask)
|
90
|
-
|
91
|
-
// When mask is a union type, apply returns a union of possible results
|
92
|
-
const user1 = { name: `John`, email: `john@example.com`, password: `secret`, extra: `data` }
|
93
|
-
const maskedUser1 = Mask.apply(user1, userMask)
|
94
|
-
// Result is a union type that includes the properties mask result
|
95
|
-
type MaskedUser1 = typeof maskedUser1
|
96
|
-
// Can't use assertSub with union types
|
97
|
-
|
98
|
-
// For partial data, use applyPartial
|
99
|
-
const user2 = { name: `Jane`, email: `jane@example.com` }
|
100
|
-
const maskedUser2 = Mask.applyPartial(user2, userMask)
|
101
|
-
// Result is a union type
|
102
|
-
type MaskedUser2 = typeof maskedUser2
|
103
|
-
}
|
104
|
-
|
105
|
-
// Test 6: Pick and omit helpers
|
106
|
-
{
|
107
|
-
const pick1 = Mask.pick([`name`, `email`])
|
108
|
-
const omit1 = Mask.omit([`password`, `secret`])
|
109
|
-
|
110
|
-
// Infers specific property types
|
111
|
-
Ts.assertEqual<PropertiesMask<{ name: any; email: any }>>()(pick1)
|
112
|
-
Ts.assertEqual<PropertiesMask<{ password: any; secret: any }>>()(omit1)
|
113
|
-
|
114
|
-
interface User {
|
115
|
-
name: string
|
116
|
-
email: string
|
117
|
-
password: string
|
118
|
-
}
|
119
|
-
const pick2 = Mask.pick<User>([`name`, `email`])
|
120
|
-
const omit2 = Mask.omit<User>([`password`])
|
121
|
-
|
122
|
-
Ts.assertEqual<PropertiesMask<User>>()(pick2)
|
123
|
-
Ts.assertEqual<PropertiesMask<User>>()(omit2)
|
124
|
-
}
|
125
|
-
|
126
|
-
// Test 7: Apply type transformations
|
127
|
-
{
|
128
|
-
interface User {
|
129
|
-
name: string
|
130
|
-
email: string
|
131
|
-
password: string
|
132
|
-
}
|
133
|
-
const user: User = { name: `John`, email: `john@example.com`, password: `secret` }
|
134
|
-
|
135
|
-
// Binary mask
|
136
|
-
const showMask = Mask.create<User>(true)
|
137
|
-
const hideMask = Mask.create<User>(false)
|
138
|
-
const shown = Mask.apply(user, showMask)
|
139
|
-
const hidden = Mask.apply(user, hideMask)
|
140
|
-
|
141
|
-
// showMask and hideMask are MaskType<User> (union types), so results are unions
|
142
|
-
type ShownType = typeof shown // Omit<User, keyof User> | undefined
|
143
|
-
type HiddenType = typeof hidden // Omit<User, keyof User> | undefined
|
144
|
-
|
145
|
-
// Properties mask - allow mode
|
146
|
-
const allowMask = Mask.create<User>([`name`, `email`])
|
147
|
-
const allowed = Mask.apply(user, allowMask)
|
148
|
-
// Result is a union due to mask being a union type
|
149
|
-
type AllowedType = typeof allowed
|
150
|
-
|
151
|
-
// Properties mask - deny mode
|
152
|
-
const denyMask = Mask.create<User>({ password: false })
|
153
|
-
const denied = Mask.apply(user, denyMask)
|
154
|
-
// Result is a union due to mask being a union type
|
155
|
-
type DeniedType = typeof denied
|
156
|
-
}
|
package/src/lib/mask/mask.ts
DELETED
@@ -1,244 +0,0 @@
|
|
1
|
-
//
|
2
|
-
//
|
3
|
-
//
|
4
|
-
//
|
5
|
-
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ • Mask
|
6
|
-
//
|
7
|
-
//
|
8
|
-
|
9
|
-
/**
|
10
|
-
* A mask that can either hide/show data entirely (BinaryMask) or
|
11
|
-
* selectively hide/show object properties (PropertiesMask).
|
12
|
-
*
|
13
|
-
* @template $Data - The data type being masked
|
14
|
-
*/
|
15
|
-
export type Mask<$Data = any> = BinaryMask<$Data> | PropertiesMask<$Data extends object ? $Data : object>
|
16
|
-
|
17
|
-
/**
|
18
|
-
* Create a mask based on the provided options.
|
19
|
-
*
|
20
|
-
* @param options - Mask configuration:
|
21
|
-
* - `boolean`: Creates a binary mask (true = show, false = hide)
|
22
|
-
* - `string[]`: Creates a properties mask that allows only the specified keys
|
23
|
-
* - `object`: Creates a properties mask based on true/false values per key
|
24
|
-
*
|
25
|
-
* @returns A mask that can be applied to data
|
26
|
-
*
|
27
|
-
* @example
|
28
|
-
* ```ts
|
29
|
-
* // Binary mask
|
30
|
-
* const showAll = create(true)
|
31
|
-
* const hideAll = create(false)
|
32
|
-
*
|
33
|
-
* // Properties mask with array
|
34
|
-
* const allowMask = create<User>(['name', 'email'])
|
35
|
-
*
|
36
|
-
* // Properties mask with object
|
37
|
-
* const objectMask = create<User>({
|
38
|
-
* name: true,
|
39
|
-
* email: true,
|
40
|
-
* password: false
|
41
|
-
* })
|
42
|
-
* ```
|
43
|
-
*/
|
44
|
-
export const create = <$Data = unknown>(
|
45
|
-
options: InferOptions<$Data>,
|
46
|
-
): Mask<$Data> => {
|
47
|
-
if (typeof options === `boolean`) {
|
48
|
-
return createBinary(options) as any
|
49
|
-
}
|
50
|
-
|
51
|
-
// Array input -> PropertiesMask with 'allow' mode
|
52
|
-
if (Array.isArray(options)) {
|
53
|
-
return createProperties(`allow`, options as any) as any
|
54
|
-
}
|
55
|
-
|
56
|
-
// Object input -> PropertiesMask based on true/false values
|
57
|
-
const entries = Object.entries(options)
|
58
|
-
|
59
|
-
const allowedKeys = entries
|
60
|
-
.filter(([_, include]) => include === true)
|
61
|
-
.map(([key]) => key)
|
62
|
-
|
63
|
-
const deniedKeys = entries
|
64
|
-
.filter(([_, include]) => include === false)
|
65
|
-
.map(([key]) => key)
|
66
|
-
|
67
|
-
// If we have denied keys, use deny mode
|
68
|
-
if (deniedKeys.length > 0 && allowedKeys.length === 0) {
|
69
|
-
return createProperties(`deny`, deniedKeys) as any
|
70
|
-
}
|
71
|
-
|
72
|
-
// Default to allow mode with allowed keys
|
73
|
-
return createProperties(`allow`, allowedKeys) as any
|
74
|
-
}
|
75
|
-
|
76
|
-
/**
|
77
|
-
* Valid options for creating a mask for the given data type.
|
78
|
-
*
|
79
|
-
* @template $Data - The data type to be masked
|
80
|
-
*/
|
81
|
-
export type InferOptions<$Data> = unknown extends $Data ? boolean | string[] | Record<string, boolean>
|
82
|
-
: $Data extends object ? (
|
83
|
-
| boolean
|
84
|
-
| (keyof $Data)[]
|
85
|
-
| Partial<
|
86
|
-
{
|
87
|
-
[K in keyof $Data]: boolean
|
88
|
-
}
|
89
|
-
>
|
90
|
-
)
|
91
|
-
: boolean
|
92
|
-
|
93
|
-
//
|
94
|
-
//
|
95
|
-
//
|
96
|
-
//
|
97
|
-
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ • PropertiesMask
|
98
|
-
//
|
99
|
-
//
|
100
|
-
|
101
|
-
/**
|
102
|
-
* A mask that selectively shows or hides object properties.
|
103
|
-
*
|
104
|
-
* @template $Data - The object type being masked
|
105
|
-
*/
|
106
|
-
export interface PropertiesMask<$Data extends object = object> {
|
107
|
-
type: `properties`
|
108
|
-
/** Whether to allow only specified properties or deny them */
|
109
|
-
mode: `allow` | `deny`
|
110
|
-
/** The list of property keys to allow or deny */
|
111
|
-
properties: (keyof $Data)[]
|
112
|
-
}
|
113
|
-
|
114
|
-
/**
|
115
|
-
* Create a properties mask.
|
116
|
-
*
|
117
|
-
* @param mode - 'allow' to show only specified properties, 'deny' to hide them
|
118
|
-
* @param properties - Array of property keys to allow or deny
|
119
|
-
* @returns A PropertiesMask
|
120
|
-
*/
|
121
|
-
export const createProperties = <$Data extends object = object>(
|
122
|
-
mode: `allow` | `deny`,
|
123
|
-
properties: (keyof $Data)[],
|
124
|
-
): PropertiesMask<$Data> => ({
|
125
|
-
type: `properties`,
|
126
|
-
mode,
|
127
|
-
properties,
|
128
|
-
})
|
129
|
-
|
130
|
-
//
|
131
|
-
//
|
132
|
-
//
|
133
|
-
//
|
134
|
-
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ • BinaryMask
|
135
|
-
//
|
136
|
-
//
|
137
|
-
|
138
|
-
/**
|
139
|
-
* A mask that either shows or hides data entirely.
|
140
|
-
*
|
141
|
-
* @template _$Data - The data type being masked (used for type inference)
|
142
|
-
*/
|
143
|
-
export interface BinaryMask<_$Data = any> {
|
144
|
-
type: `binary`
|
145
|
-
/** Whether to show (true) or hide (false) the data */
|
146
|
-
show: boolean
|
147
|
-
}
|
148
|
-
|
149
|
-
/**
|
150
|
-
* Create a binary mask.
|
151
|
-
*
|
152
|
-
* @param show - Whether to show (true) or hide (false) the data
|
153
|
-
* @returns A BinaryMask
|
154
|
-
*/
|
155
|
-
export const createBinary = <$Data = any>(show: boolean): BinaryMask<$Data> => ({
|
156
|
-
type: `binary`,
|
157
|
-
show,
|
158
|
-
})
|
159
|
-
|
160
|
-
//
|
161
|
-
//
|
162
|
-
//
|
163
|
-
//
|
164
|
-
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ • Convenience Constructors with Semantic Names
|
165
|
-
//
|
166
|
-
//
|
167
|
-
|
168
|
-
/**
|
169
|
-
* Create a mask that shows all data.
|
170
|
-
* @returns A BinaryMask with show=true
|
171
|
-
*/
|
172
|
-
export const show = (): BinaryMask => ({
|
173
|
-
type: `binary`,
|
174
|
-
show: true,
|
175
|
-
})
|
176
|
-
|
177
|
-
/**
|
178
|
-
* Create a mask that hides all data.
|
179
|
-
* @returns A BinaryMask with show=false
|
180
|
-
*/
|
181
|
-
export const hide = (): BinaryMask => ({
|
182
|
-
type: `binary`,
|
183
|
-
show: false,
|
184
|
-
})
|
185
|
-
|
186
|
-
/**
|
187
|
-
* Create a mask that shows only the specified properties.
|
188
|
-
*
|
189
|
-
* @param properties - Array of property keys to show
|
190
|
-
* @returns A PropertiesMask in 'allow' mode
|
191
|
-
*
|
192
|
-
* @example
|
193
|
-
* ```ts
|
194
|
-
* const userMask = pick<User>(['name', 'email'])
|
195
|
-
* // Only 'name' and 'email' will be shown
|
196
|
-
* ```
|
197
|
-
*/
|
198
|
-
export const pick = <$Data extends object = object>(
|
199
|
-
properties: (keyof $Data)[],
|
200
|
-
): PropertiesMask<$Data> => ({
|
201
|
-
type: `properties`,
|
202
|
-
mode: `allow`,
|
203
|
-
properties,
|
204
|
-
})
|
205
|
-
|
206
|
-
/**
|
207
|
-
* Create a mask that hides the specified properties.
|
208
|
-
*
|
209
|
-
* @param properties - Array of property keys to hide
|
210
|
-
* @returns A PropertiesMask in 'deny' mode
|
211
|
-
*
|
212
|
-
* @example
|
213
|
-
* ```ts
|
214
|
-
* const userMask = omit<User>(['password', 'ssn'])
|
215
|
-
* // Everything except 'password' and 'ssn' will be shown
|
216
|
-
* ```
|
217
|
-
*/
|
218
|
-
export const omit = <$Data extends object = object>(
|
219
|
-
properties: (keyof $Data)[],
|
220
|
-
): PropertiesMask<$Data> => ({
|
221
|
-
type: `properties`,
|
222
|
-
mode: `deny`,
|
223
|
-
properties,
|
224
|
-
})
|
225
|
-
|
226
|
-
//
|
227
|
-
//
|
228
|
-
//
|
229
|
-
//
|
230
|
-
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ • Utilities
|
231
|
-
//
|
232
|
-
//
|
233
|
-
|
234
|
-
/**
|
235
|
-
* Extract the data type from a mask.
|
236
|
-
*
|
237
|
-
* @template $Mask - The mask type
|
238
|
-
* @returns The data type the mask is designed for
|
239
|
-
*/
|
240
|
-
// dprint-ignore
|
241
|
-
export type GetDataType<$Mask extends Mask> =
|
242
|
-
$Mask extends BinaryMask<infer $Data> ? $Data :
|
243
|
-
$Mask extends PropertiesMask<infer $Data> ? $Data
|
244
|
-
: never
|
@@ -1 +0,0 @@
|
|
1
|
-
export * from './version-selection.js'
|
File without changes
|
File without changes
|
File without changes
|