file_path
stringlengths
3
280
file_language
stringclasses
66 values
content
stringlengths
1
1.04M
repo_name
stringlengths
5
92
repo_stars
int64
0
154k
repo_description
stringlengths
0
402
repo_primary_language
stringclasses
108 values
developer_username
stringlengths
1
25
developer_name
stringlengths
0
30
developer_company
stringlengths
0
82
Sources/SwiftComponent/Internal/AreOrderedSetsDuplicates.swift
Swift
// Copyright (c) 2024 Point-Free, Inc. // https://github.com/pointfreeco/swift-composable-architecture/blob/main/LICENSE import Foundation import OrderedCollections @inlinable func areOrderedSetsDuplicates<T>(_ lhs: OrderedSet<T>, _ rhs: OrderedSet<T>) -> Bool { guard lhs.count == rhs.count else { return false } ...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftComponent/Internal/CodeEditor.swift
Swift
import Foundation import SwiftParser import SwiftSyntax class CodeParser { let originalSource: String let syntax: SourceFileSyntax init(source: String) { originalSource = source syntax = Parser.parse(source: source) } var modelSource: Codeblock? { syntax.getStruct(type: "...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftComponent/Internal/ComponentDescription.swift
Swift
@_implementationOnly import Runtime struct ComponentDescription: Equatable, Codable { var model: ModelInfo var component: ComponentInfo } extension ComponentDescription { init<ComponentType: Component>(type: ComponentType.Type) throws { func getType(_ type: Any.Type) throws -> TypeDescription { ...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftComponent/Internal/Core.swift
Swift
import Foundation import CustomDump extension String { func indent(by indent: Int) -> String { let indentation = String(repeating: " ", count: indent) return indentation + self.replacingOccurrences(of: "\n", with: "\n\(indentation)") } var quoted: String { "\"\(self)\""} } public func dum...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftComponent/Internal/Enum.swift
Swift
import Foundation struct EnumCase { let name: String let values: [String: Any] } func getEnumCase<T>(_ enumValue: T) -> EnumCase { let reflection = Mirror(reflecting: enumValue) guard reflection.displayStyle == .enum, let associated = reflection.children.first else { return EnumCase(na...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftComponent/Internal/ExampleComponent.swift
Swift
import Foundation import SwiftUI @ComponentModel struct ExampleModel { struct Connections { let child = Connection<ExampleChildModel>(output: Input.child) let connectedChild = Connection<ExampleChildModel>(output: Input.child) .dependency(\.uuid, value: .incrementing) ...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftComponent/Internal/Export.swift
Swift
import Foundation import Dependencies import CasePaths @_exported import Dependencies @_exported import CasePaths @_exported import SwiftUINavigation @_exported import IdentifiedCollections #if canImport(Observation) @_exported import Observation #endif #if canImport(Perception) @_exported import Perception #endif
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftComponent/Internal/KeyPath.swift
Swift
import Foundation @_implementationOnly import Runtime extension KeyPath { // swift 5.8 has a debugDescription on KeyPath, and even works with getters, but it doesn't work with index lookups // We can use mirror as a fallback but it doesn't work with getters or indices // TODO: enable Item.array[0].string ...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftComponent/Internal/Source.swift
Swift
import Foundation public struct Source: Hashable { public static func == (lhs: Source, rhs: Source) -> Bool { lhs.file.description == rhs.file.description && lhs.line == rhs.line } public let file: StaticString public let line: UInt public func hash(into hasher: inout Hasher) { ha...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftComponent/Internal/ViewHelpers.swift
Swift
import Foundation import SwiftUI extension View { func interactiveBackground() -> some View { contentShape(Rectangle()) } func eraseToAnyView() -> AnyView { AnyView(self) } }
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftComponent/Macros.swift
Swift
import Observation @attached(extension, conformances: ComponentModel) @attached(memberAttribute) @attached(member, names: arbitrary) public macro ComponentModel() = #externalMacro(module: "SwiftComponentMacros", type: "ComponentModelMacro") @attached(extension, conformances: Observable, ObservableState) @attached(mem...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftComponent/ModelContext.swift
Swift
import Foundation import SwiftUI import CasePaths import Dependencies @dynamicMemberLookup public class ModelContext<Model: ComponentModel> { weak var store: ComponentStore<Model>! init(store: ComponentStore<Model>) { self.store = store } @MainActor public var state: Model.State { store.stat...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftComponent/Models.swift
Swift
import Foundation //typealias SimpleModel<State, Action, Environment> = ViewModel<SimpleComponentModel<State, Action, Environment>> //struct SimpleComponentModel<State, Output, Environment>: ComponentModel { // // typealias State = State // typealias Action = Output // typealias Output = Output // typealia...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftComponent/Observation/ObservableState.swift
Swift
// Copyright (c) 2024 Point-Free, Inc. // https://github.com/pointfreeco/swift-composable-architecture/blob/main/LICENSE #if canImport(Perception) import Foundation /// A type that emits notifications to observers when underlying data changes. /// /// Conforming to this protocol signals to other APIs that the value t...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftComponent/Observation/ObservationStateRegistrar.swift
Swift
// Copyright (c) 2024 Point-Free, Inc. // https://github.com/pointfreeco/swift-composable-architecture/blob/main/LICENSE #if canImport(Perception) /// Provides storage for tracking and access to data changes. public struct ObservationStateRegistrar: Sendable { public private(set) var id = ObservableStateID() ...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftComponent/Path.swift
Swift
import Foundation public struct ComponentPath: CustomStringConvertible, Equatable, Hashable { public static func == (lhs: ComponentPath, rhs: ComponentPath) -> Bool { lhs.string == rhs.string } public let path: [any ComponentModel.Type] var pathString: String { path.map { $0.baseName ...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftComponent/Presentation.swift
Swift
import Foundation import SwiftUI //TODO: turn into protocol that handles any sort of presentation based on view modifiers public enum Presentation { case sheet case push case fullScreenCover @available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0, *) // use NavigationView instead of NavigationStac...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftComponent/ResourceState.swift
Swift
import Foundation import SwiftUI import Perception @propertyWrapper public struct ResourceState<Value> { public var wrappedValue: Value? { get { content } set { content = newValue } } public var content: Value? public var error: Error? public var isLoading: Bool = false public ...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftComponent/Routing.swift
Swift
import Foundation extension ComponentModel { @MainActor @discardableResult public func route<Child: ComponentModel>(to route: (ComponentRoute<Child>) -> Route, state: Child.State, childRoute: Child.Route? = nil, file: StaticString = #filePath, line: UInt = #line) -> ComponentRoute<Child> { let com...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftComponent/Snapshotting.swift
Swift
import Foundation import SwiftUI public struct SnapshotModifier { var apply: (AnyView) -> AnyView public static func environment<V>(_ keyPath: WritableKeyPath<EnvironmentValues, V>, _ value: V) -> Self { SnapshotModifier { AnyView($0.environment(keyPath, value)) } } ...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftComponent/Testing/Snapshot.swift
Swift
import Foundation public struct ComponentSnapshot<Model: ComponentModel> { public var name: String public var state: Model.State public var environment: Model.Environment public var route: Model.Route? public var tags: Set<String> public var source: Source public var dependencies: Component...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftComponent/Testing/Test.swift
Swift
import Foundation public struct Test<ComponentType: Component>: Identifiable { public typealias Model = ComponentType.Model public init(_ name: String? = nil, assertions: [TestAssertion]? = nil, environment: Model.Environment? = nil, file: StaticString = #filePath, line: UInt = #line, @TestStepBuilder<Mo...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftComponent/Testing/TestAssertion.swift
Swift
import Foundation import Runtime extension [TestAssertion] { public static var none: Self { [] } public static var all: Self { [ OutputTestAssertion(), TaskTestAssertion(), RouteTestAssertion(), EmptyRouteTestAssertion(), StateTestAssertion(), DependencyTestAss...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftComponent/Testing/TestExpectation.swift
Swift
import Foundation public struct TestExpectation<Model: ComponentModel> { public let title: String public let details: String? public let source: Source @MainActor let run: (inout Context) -> Void public var description: String { var string = title if let details { stri...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftComponent/Testing/TestExpectations.swift
Swift
import Foundation extension TestStep { public func expectOutput(_ output: Model.Output, file: StaticString = #filePath, line: UInt = #line) -> Self { addExpectation(title: "Expect Output", details: getEnumCase(output).name, file: file, line: line) { context in let foundOutput: Model.Output? =...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftComponent/Testing/TestResult.swift
Swift
import Foundation public struct TestStepResult: Identifiable { public var id: UUID public var title: String public var details: String? public var expectations: [String] public var events: [Event] public var stepErrors: [TestError] public var expectationErrors: [TestError] public var a...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftComponent/Testing/TestRun.swift
Swift
// // File.swift // // // Created by Yonas Kolb on 20/3/2023. // import Foundation import SwiftUI @_implementationOnly import Runtime struct TestRun<ComponentType: Component> { typealias Model = ComponentType.Model var testState: [Test<ComponentType>.ID: TestState] = [:] var testResults: [Test<Compon...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftComponent/Testing/TestRunner.swift
Swift
import Foundation @_implementationOnly import Runtime @MainActor public struct TestContext<Model: ComponentModel> { public let model: ViewModel<Model> public var delay: TimeInterval public var assertions: [TestAssertion] public var runAssertions: Bool = true public var runExpectations: Bool = true ...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftComponent/Testing/TestStep.swift
Swift
import Foundation public typealias TestStepContext<Model: ComponentModel> = TestStep<Model> public typealias Step = TestStep public enum TestStepID { @TaskLocal public static var current = UUID() } public struct TestStep<Model: ComponentModel>: Identifiable { public var title: String public var details:...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftComponent/Testing/TestSteps.swift
Swift
import Foundation import SwiftUI extension TestStep { public static func run(_ title: String, file: StaticString = #filePath, line: UInt = #line, _ run: @escaping () async -> Void) -> Self { .init(title: title, file: file, line: line) { _ in await run() } } public static f...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftComponent/UI/ComponentDashboardView.swift
Swift
import Foundation import SwiftUI import SwiftPreview import SwiftGUI @MainActor struct ComponentDashboardView<ComponentType: Component>: View { var model: ViewModel<ComponentType.Model> @AppStorage("componentPreview.showView") var showView = true @AppStorage("componentPreview.showComponent") var showComp...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftComponent/UI/ComponentDebugView.swift
Swift
import SwiftUI import SwiftGUI struct ComponentDebugSheet<Model: ComponentModel>: View { let model: ViewModel<Model> @Environment(\.dismiss) var dismiss var body: some View { NavigationView { ComponentDebugView(model: model) .toolbar { #if os(iOS) T...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftComponent/UI/ComponentDescriptionView.swift
Swift
import Foundation import SwiftUI import SwiftPreview struct ComponentDescriptionView<ComponentType: Component>: View { var componentDescription: ComponentDescription = try! ComponentDescription(type: ComponentType.self) var maxPillWidth = 400.0 var body: some View { pills } var pills: s...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftComponent/UI/ComponentEditorView.swift
Swift
import SwiftUI import SwiftSyntax /** TODO: syntax highlighting TODO: proper editor with at least auto indent TODO: finer grained code blocks **/ struct ComponentEditorView<ComponentType: Component>: View { @State var initialFileContent: String = "" @State var fileContent: String = "" @State var model...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftComponent/UI/ComponentEventView.swift
Swift
import Foundation import SwiftUI import SwiftGUI struct ComponentEventList: View { let events: [Event] let allEvents: [Event] var depth: Int = 0 var indent = true @State var showEvent: UUID? @State var showMutation: UUID? func eventDepth(_ event: Event) -> Int { guard indent else ...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftComponent/UI/ComponentListView.swift
Swift
import SwiftUI import SwiftPreview public struct ComponentListView: View { @Environment(\.colorScheme) var colorScheme: ColorScheme var components: [any Component.Type] let scale = 0.5 let device = Device.mediumPhone var environments: [String] @State var testRuns: [String: ItemTestRun] = [:] ...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftComponent/UI/ComponentPreview.swift
Swift
import SwiftUI import SwiftPreview struct ComponentPreview<ComponentType: Component>: View { @StateObject var model = ComponentType.previewModel().logEvents() @AppStorage("componentPreview.viewState") var viewState: ViewState = .dashboard enum ViewState: String, CaseIterable { case dashboard = "C...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftComponent/UI/ComponentSnapshotView.swift
Swift
// // SwiftUIView.swift // // // Created by Yonas Kolb on 26/6/2023. // import SwiftUI @MainActor struct ComponentSnapshotView<ComponentType: Component>: View { let snapshotName: String @State var snapshot: ComponentSnapshot<ComponentType.Model>? func generateSnapshot() async { if let snapsho...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftComponent/UI/ComponentTestsView.swift
Swift
import Foundation import SwiftUI struct ComponentTestsView<ComponentType: Component>: View { typealias Model = ComponentType.Model @State var testRun = TestRun<ComponentType>() @AppStorage("testPreview.showStepTitles") var showStepTitles = true @AppStorage("testPreview.showEvents") var showEvents = fa...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftComponent/UI/ComponentViewPreview.swift
Swift
import Foundation import SwiftUI import SwiftPreview struct ComponentViewPreview<Content: View>: View { var sizeCategories: [ContentSizeCategory] = [ .extraSmall, .large, .extraExtraExtraLarge, .accessibilityExtraExtraExtraLarge, ] var devices: [Device] = Device.all @S...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftComponent/UI/PreviewColorScheme.swift
Swift
import Foundation import SwiftUI extension View { func previewColorScheme() -> some View { modifier(PreviewColorSchemeModifier()) } } struct PreviewColorSchemeModifier: ViewModifier { @AppStorage(PreviewColorScheme.key) var previewColorScheme: PreviewColorScheme = .system @Environment(\.c...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftComponent/UI/PreviewDevice.swift
Swift
import Foundation import SwiftUI extension View { public func largePreview() -> some View { self.previewDevice(.iPad) } }
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftComponent/UI/PreviewReference.swift
Swift
import SwiftUI struct PreviewReferenceKey: EnvironmentKey { static var defaultValue: Bool = false } extension EnvironmentValues { public var isPreviewReference: Bool { get { self[PreviewReferenceKey.self] } set { self[PreviewReferenceKey.self] = newValue ...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftComponent/ViewModel.swift
Swift
import Foundation import SwiftUI import Combine @dynamicMemberLookup @MainActor public class ViewModel<Model: ComponentModel>: ObservableObject { let store: ComponentStore<Model> public var path: ComponentPath { store.path } public var componentName: String { Model.baseName } private var cancellables...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftComponentCLI/CLI.swift
Swift
import Foundation import ArgumentParser @main struct Components: ParsableCommand { static var configuration = CommandConfiguration( abstract: "A tool for SwiftComponent", subcommands: [ GenerateComponents.self, ]) }
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftComponentCLI/GenerateComponents.swift
Swift
import Foundation import SwiftParser import SwiftSyntax import ArgumentParser struct GenerateComponents: ParsableCommand { static var configuration = CommandConfiguration( commandName: "generate-components", abstract: "Generates a file containing all the Components in the directory" ) @Ar...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftComponentMacros/Availability.swift
Swift
//===----------------------------------------------------------------------===// // // This source file is part of the Swift.org open source project // // Copyright (c) 2023 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE....
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftComponentMacros/Extensions.swift
Swift
//===----------------------------------------------------------------------===// // // This source file is part of the Swift.org open source project // // Copyright (c) 2023 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE....
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftComponentMacros/Macros.swift
Swift
import Foundation import SwiftCompilerPlugin import SwiftSyntaxMacros @main struct MyMacroPlugin: CompilerPlugin { let providingMacros: [Macro.Type] = [ ComponentModelMacro.self, ObservableStateMacro.self, ObservationStateTrackedMacro.self, ObservationStateIgnoredMacro.self, ...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftComponentMacros/ModelMacro.swift
Swift
import Foundation import SwiftSyntaxMacros import SwiftSyntax public struct ComponentModelMacro {} extension ComponentModelMacro: MemberMacro { public static func expansion( of node: AttributeSyntax, providingMembersOf declaration: some DeclGroupSyntax, in context: some MacroExpansionConte...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftComponentMacros/ObservableStateMacro.swift
Swift
//===----------------------------------------------------------------------===// // // This source file is part of the Swift.org open source project // // Copyright (c) 2023 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE....
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftComponentMacros/ResourceMacro.swift
Swift
import SwiftDiagnostics import SwiftOperators import SwiftSyntax import SwiftSyntaxBuilder import SwiftSyntaxMacroExpansion import SwiftSyntaxMacros public enum ResourceMacro { } extension ResourceMacro: AccessorMacro { public static func expansion<D: DeclSyntaxProtocol, C: MacroExpansionContext>( of node: Attr...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftPreview/Accessibility/AccessibilityHeirarchy.swift
Swift
#if os(iOS) import Foundation import SwiftUI import UIKit import AccessibilitySnapshotCore public typealias AccessibilityHierarchy = [AccessibilityMarker] extension View { public func accessibilityHierarchy(frame: CGRect = CGRect(origin: .zero, size: CGSize(width: 500, height: 2000))) -> AccessibilityHierarchy {...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftPreview/Accessibility/AccessibilityMarkdown.swift
Swift
#if os(iOS) import Foundation import SwiftUI import UIKit import AccessibilitySnapshotCore import RegexBuilder extension AccessibilityHierarchy { public func markdown() -> String { self.filter { !$0.description.trimmingCharacters(in: .whitespaces).isEmpty } .enumerated() .map { $1....
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftPreview/Accessibility/AccessibillityView.swift
Swift
#if os(iOS) import Foundation import SwiftUI import AccessibilitySnapshotCore import UIKit extension View { public func accessibilityPreview() -> some View { let hierarchy = self.accessibilityHierarchy() return AccessibilityHierarchyView(hierarchy: hierarchy) } } struct AccessibilityHierarchy...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftPreview/Device.swift
Swift
import Foundation import SwiftUI public struct Device: Equatable { public var name: String public var type: DeviceType public var width: Double public var height: Double var iconType: Icon { switch (homeIndicator, type) { case (true, .iPad): return .iPad case (false, .iPad):...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftPreview/DeviceView.swift
Swift
import Foundation import SwiftUI extension View { public func embedIn(device: Device) -> some View { self.modifier(DeviceWrapper(device: device)) } } struct DeviceWrapper: ViewModifier { var device: Device var frameColor = Color(white: 0.05) var borderColor = Color(white: 0.15) var no...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftPreview/Rendering.swift
Swift
#if os(iOS) import SwiftUI import UIKit extension View { public func renderView<T>(in frame: CGRect = UIScreen.main.bounds, render: (UIView) -> T) -> T { let viewController = UIHostingController(rootView: self) var value: T? UIWindow.prepare(viewController: viewController, frame: frame) { ...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Sources/SwiftPreview/ScalingView.swift
Swift
import Foundation import SwiftUI public enum Scaling: String { case exact case fit } public struct ScalingView<Content: View>: View { let size: CGSize let scaling: Scaling var content: Content public init(size: CGSize, scaling: Scaling = .fit, @ViewBuilder content: () -> Content) { se...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Tests/SwiftComponentMacroTests/ModelMacroTests.swift
Swift
#if canImport(SwiftComponentMacros) import MacroTesting import Foundation import XCTest import SwiftComponentMacros final class ModelMacroTests: XCTestCase { override func invokeTest() { withMacroTesting(isRecording: false, macros: [ComponentModelMacro.self]) { super.invokeTest() } ...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Tests/SwiftComponentMacroTests/ObservableStateMacroTests.swift
Swift
#if canImport(SwiftComponentMacros) import MacroTesting import Foundation import XCTest import SwiftComponentMacros final class ObservableStateMacroTests: XCTestCase { override func invokeTest() { withMacroTesting(isRecording: false, macros: [ObservableStateMacro.self]) { super.invokeTest() ...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Tests/SwiftComponentMacroTests/ResourceMacroTests.swift
Swift
#if canImport(SwiftComponentMacros) import MacroTesting import Foundation import XCTest import SwiftComponentMacros final class ResourceMacroTests: XCTestCase { override func invokeTest() { withMacroTesting(isRecording: false, macros: [ResourceMacro.self]) { super.invokeTest() } } ...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Tests/SwiftComponentTests/ComponentDescriptionTests.swift
Swift
import Foundation import XCTest import InlineSnapshotTesting @testable import SwiftComponent @available(iOS 16, macOS 13, tvOS 16, watchOS 9, *) final class ComponentDescriptionTests: XCTestCase { func testDescriptionParsing() throws { let description = try ComponentDescription(type: ExampleComponent....
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Tests/SwiftComponentTests/ConnectionTests.swift
Swift
import Foundation import XCTest @testable import SwiftComponent @available(iOS 16, macOS 13, tvOS 16, watchOS 9, *) final class ConnectionTests: XCTestCase { @MainActor func testInlineOutput() async { let parent = ViewModel<TestModel>(state: .init()) let child = parent.connectedModel(\.child, ...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Tests/SwiftComponentTests/KeyPathTests.swift
Swift
import Foundation import XCTest @testable import SwiftComponent class KeyPathTests: XCTestCase { func testPropertyName() { XCTAssertEqual((\Item.string as KeyPath).propertyName, "string") XCTAssertEqual((\Item.stringOptional as KeyPath).propertyName, "stringOptional") XCTAssertEqual((\...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Tests/SwiftComponentTests/MemoryTests.swift
Swift
import Foundation import XCTest @testable import SwiftComponent @available(iOS 16, macOS 13, tvOS 16, watchOS 9, *) final class MemoryTests: XCTestCase { @MainActor func testMemoryLeak() async { let viewModel = ViewModel<TestModel>(state: .init(child: .init(count: 2))) .dependency(\.contin...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Tests/SwiftComponentTests/NumberDependency.swift
Swift
import Dependencies struct NumberDependency { let value: Int func callAsFunction() -> Int { value } } extension NumberDependency: ExpressibleByIntegerLiteral { init(integerLiteral value: IntegerLiteralType) { self.value = value } } extension NumberDependency: DependencyK...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Tests/SwiftComponentTests/ObservabilityTests.swift
Swift
import Foundation import XCTest @testable import SwiftComponent import Perception @available(iOS 16, macOS 13, tvOS 16, watchOS 9, *) @MainActor final class ObservabilityTests: XCTestCase { var viewModel: ViewModel<Model> = .init(state: .init()) override func setUp() { viewModel = .init(state: .init(...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
Tests/SwiftComponentTests/TaskCancellationTests.swift
Swift
import XCTest @testable import SwiftComponent @available(iOS 16, macOS 13, tvOS 16, watchOS 9, *) @MainActor final class TaskCancellationTests: XCTestCase { func test_task_cancels_old_task() async throws { let clock = TestClock() let viewModel = ViewModel<TestModel>(state: .init()) .de...
yonaskolb/SwiftComponent
16
Where architecture meets tooling
Swift
yonaskolb
Yonas Kolb
cmd/main.go
Go
package main import ( "net/http" "github.com/go-chi/chi/v5" chiMiddleware "github.com/go-chi/chi/v5/middleware" httpSwagger "github.com/swaggo/http-swagger" "go.uber.org/zap" "github.com/yorukot/starker/internal/config" "github.com/yorukot/starker/internal/database" "github.com/yorukot/starker/internal/handl...
yorukot/Houng
1
Go
yorukot
Yorukot
docs/docs.go
Go
// Package docs Code generated by swaggo/swag. DO NOT EDIT package docs import "github.com/swaggo/swag" const docTemplate = `{ "schemes": {{ marshal .Schemes }}, "swagger": "2.0", "info": { "description": "{{escape .Description}}", "title": "{{.Title}}", "termsOfService": "http://s...
yorukot/Houng
1
Go
yorukot
Yorukot
internal/config/env.go
Go
package config import ( "sync" "github.com/caarlos0/env/v10" "go.uber.org/zap" ) type AppEnv string const ( AppEnvDev AppEnv = "dev" AppEnvProd AppEnv = "prod" ) // EnvConfig holds all environment variables for the application type EnvConfig struct { AdminPassword string `env:"ADMIN_PASSWORD,required"` Adm...
yorukot/Houng
1
Go
yorukot
Yorukot
internal/database/postgresql.go
Go
package database import ( "context" "errors" "fmt" "os" "github.com/golang-migrate/migrate/v4" "github.com/jackc/pgx/v5/pgxpool" "go.uber.org/zap" "github.com/yorukot/starker/internal/config" ) // InitDatabase initialize the database connection pool and return the pool and also migrate the database func Ini...
yorukot/Houng
1
Go
yorukot
Yorukot
internal/handler/auth/auth.go
Go
// Package auth provides the auth handler. package auth import ( "encoding/json" "net/http" "go.uber.org/zap" "github.com/yorukot/starker/internal/config" "github.com/yorukot/starker/internal/service/authsvc" "github.com/yorukot/starker/pkg/response" ) // +----------------------------------------------+ // | ...
yorukot/Houng
1
Go
yorukot
Yorukot
internal/handler/auth/handler.go
Go
package auth import ( "github.com/jackc/pgx/v5/pgxpool" ) // AuthHandler is the handler for the auth routes type AuthHandler struct { DB *pgxpool.Pool }
yorukot/Houng
1
Go
yorukot
Yorukot
internal/handler/collection/create.go
Go
package collection import ( "encoding/json" "net/http" "go.uber.org/zap" "github.com/yorukot/starker/internal/repository" "github.com/yorukot/starker/internal/service/collectionsvc" "github.com/yorukot/starker/pkg/response" ) // +----------------------------------------------+ // | Create Collection ...
yorukot/Houng
1
Go
yorukot
Yorukot
internal/handler/collection/delete.go
Go
package collection import ( "net/http" "github.com/go-chi/chi/v5" "go.uber.org/zap" "github.com/yorukot/starker/internal/repository" "github.com/yorukot/starker/pkg/response" ) // +----------------------------------------------+ // | Delete Collection | // +-------------------------...
yorukot/Houng
1
Go
yorukot
Yorukot
internal/handler/collection/get.go
Go
package collection import ( "net/http" "go.uber.org/zap" "github.com/yorukot/starker/internal/repository" "github.com/yorukot/starker/internal/service/collectionsvc" "github.com/yorukot/starker/pkg/response" ) // GetCollections godoc // @Summary Get all collections // @Description Gets all collections with the...
yorukot/Houng
1
Go
yorukot
Yorukot
internal/handler/collection/handler.go
Go
package collection import "github.com/jackc/pgx/v5/pgxpool" type CollectionHandler struct { DB *pgxpool.Pool }
yorukot/Houng
1
Go
yorukot
Yorukot
internal/handler/collection/update.go
Go
package collection import ( "encoding/json" "net/http" "time" "github.com/go-chi/chi/v5" "go.uber.org/zap" "github.com/yorukot/starker/internal/repository" "github.com/yorukot/starker/internal/service/collectionsvc" "github.com/yorukot/starker/pkg/response" ) // UpdateCollection godoc // @Summary Update a c...
yorukot/Houng
1
Go
yorukot
Yorukot
internal/handler/monitor/create.go
Go
package monitor import ( "encoding/json" "net/http" "strings" "github.com/go-chi/chi/v5" "go.uber.org/zap" "github.com/yorukot/starker/internal/repository" "github.com/yorukot/starker/internal/service/monitorsvc" "github.com/yorukot/starker/pkg/response" ) // +----------------------------------------------+...
yorukot/Houng
1
Go
yorukot
Yorukot
internal/handler/monitor/delete.go
Go
package monitor import "net/http" func (h *MonitorHandler) DeleteMonitor(w http.ResponseWriter, r *http.Request) { // Get the monitor ID from the request // Start the transaction // Check if the monitor is exists // Delete the monitor // Commit the transaction // Return the monitor }
yorukot/Houng
1
Go
yorukot
Yorukot
internal/handler/monitor/get.go
Go
package monitor import ( "net/http" "github.com/go-chi/chi/v5" "go.uber.org/zap" "github.com/yorukot/starker/internal/repository" "github.com/yorukot/starker/pkg/response" ) // +----------------------------------------------+ // | GetMonitor | // +-----------------------------...
yorukot/Houng
1
Go
yorukot
Yorukot
internal/handler/monitor/handler.go
Go
package monitor import ( "github.com/jackc/pgx/v5/pgxpool" ) type MonitorHandler struct { DB *pgxpool.Pool }
yorukot/Houng
1
Go
yorukot
Yorukot
internal/handler/monitor/update.go
Go
package monitor import ( "encoding/json" "net/http" "github.com/go-chi/chi/v5" "go.uber.org/zap" "github.com/yorukot/starker/internal/repository" "github.com/yorukot/starker/internal/service/monitorsvc" "github.com/yorukot/starker/pkg/response" ) // +----------------------------------------------+ // | Upda...
yorukot/Houng
1
Go
yorukot
Yorukot
internal/handler/node/create.go
Go
package node import ( "encoding/json" "net/http" "go.uber.org/zap" "github.com/yorukot/starker/internal/repository" "github.com/yorukot/starker/internal/service/nodesvc" "github.com/yorukot/starker/pkg/response" ) // CreateNode godoc // @Summary Create a new node // @Description Creates a new infrastructure n...
yorukot/Houng
1
Go
yorukot
Yorukot
internal/handler/node/delete.go
Go
package node import ( "net/http" "github.com/go-chi/chi/v5" "go.uber.org/zap" "github.com/yorukot/starker/internal/repository" "github.com/yorukot/starker/pkg/response" ) // DeleteNode godoc // @Summary Delete a node // @Description Deletes a node by ID. Node cannot be deleted if it has associated monitors // ...
yorukot/Houng
1
Go
yorukot
Yorukot
internal/handler/node/get.go
Go
package node import ( "net/http" "github.com/yorukot/starker/internal/repository" "github.com/yorukot/starker/pkg/response" ) // GetNodes godoc // @Summary Get all nodes // @Description Get all nodes // @Tags nodes // @Accept json // @Produce json // @Success 200 {array} models.Node "Nodes fetched successfully" /...
yorukot/Houng
1
Go
yorukot
Yorukot
internal/handler/node/handler.go
Go
package node import "github.com/jackc/pgx/v5/pgxpool" type NodeHandler struct { DB *pgxpool.Pool }
yorukot/Houng
1
Go
yorukot
Yorukot
internal/handler/node/update.go
Go
package node import ( "encoding/json" "net/http" "time" "github.com/go-chi/chi/v5" "go.uber.org/zap" "github.com/yorukot/starker/internal/repository" "github.com/yorukot/starker/internal/service/nodesvc" "github.com/yorukot/starker/pkg/response" ) // UpdateNode godoc // @Summary Update a node // @Descriptio...
yorukot/Houng
1
Go
yorukot
Yorukot
internal/handler/type.go
Go
package handler import "github.com/jackc/pgx/v5/pgxpool" // App is the application context type App struct { DB *pgxpool.Pool }
yorukot/Houng
1
Go
yorukot
Yorukot
internal/middleware/auth.go
Go
package middleware import ( "context" "net/http" "github.com/yorukot/starker/internal/config" "github.com/yorukot/starker/internal/models" "github.com/yorukot/starker/pkg/encrypt" "github.com/yorukot/starker/pkg/response" ) // authMiddlewareLogic is the logic for the auth middleware func authMiddlewareLogic(w ...
yorukot/Houng
1
Go
yorukot
Yorukot
internal/middleware/logger.go
Go
package middleware import ( "net/http" "time" "github.com/fatih/color" "github.com/google/uuid" "go.uber.org/zap" "github.com/yorukot/starker/internal/config" ) // ZapLoggerMiddleware is a middleware that logs the incoming request and the response time func ZapLoggerMiddleware(logger *zap.Logger) func(http.Ha...
yorukot/Houng
1
Go
yorukot
Yorukot
internal/middleware/type.go
Go
package middleware // ContextKey is a type for the context key type ContextKey string // ContextKey constants const ( UserIDKey ContextKey = "userID" )
yorukot/Houng
1
Go
yorukot
Yorukot
internal/models/auth.go
Go
package models // CookieName constants const ( CookieNameAccessToken = "access_token" )
yorukot/Houng
1
Go
yorukot
Yorukot
internal/models/collection.go
Go
package models import "time" // Collection represents a hierarchical collection in the system type Collection struct { ID string `json:"id" example:"01ARZ3NDEKTSV4RRFFQ69G5FAV"` // Unique identifier for the collection Name string `json:"name" example:"Production Se...
yorukot/Houng
1
Go
yorukot
Yorukot
internal/models/monitor.go
Go
package models import "time" // Monitor represents a monitoring configuration in the system type Monitor struct { ID string `json:"id" example:"01ARZ3NDEKTSV4RRFFQ69G5FAV"` // Unique identifier for the monitor CollectionID string `json:"collection_id" example:"01ARZ3NDEKTSV4RRFFQ"` // ID of the...
yorukot/Houng
1
Go
yorukot
Yorukot
internal/models/node.go
Go
package models import "time" // Node represents an infrastructure node in the system type Node struct { ID string `json:"id" example:"01ARZ3NDEKTSV4RRFFQ69G5FAV"` // Unique identifier for the node IP string `json:"ip" example:"192.168.1.100"` // IP address of the no...
yorukot/Houng
1
Go
yorukot
Yorukot
internal/models/ping.go
Go
package models import "time" // Ping represents a ping result in the system type Ping struct { PingID string `json:"ping_id" example:"01ARZ3NDEKTSV4RRFFQ69G5FAV"` // Unique identifier for the ping NodeID string `json:"node_id" example:"01ARZ3NDEKTSV4RRFFQ69G5FAV"` // ID of the node that performed the ...
yorukot/Houng
1
Go
yorukot
Yorukot
internal/repository/collection.go
Go
package repository import ( "context" "github.com/jackc/pgx/v5" "github.com/yorukot/starker/internal/models" ) // GetCollectionByID gets a collection by ID func GetCollectionByID(ctx context.Context, tx pgx.Tx, id string) (*models.Collection, error) { query := ` SELECT id, name, parent_collection_id, created_...
yorukot/Houng
1
Go
yorukot
Yorukot