René's URL Explorer Experiment


Title: automatically add dependencies for server side files. · Issue #361 · hyperstack-org/hyperstack · GitHub

Open Graph Title: automatically add dependencies for server side files. · Issue #361 · hyperstack-org/hyperstack

X Title: automatically add dependencies for server side files. · Issue #361 · hyperstack-org/hyperstack

Description: You can now easily split your class definitions so that you have an isomorphic (i.e. runs on the server and client) definition, and a server-only definition. This is especially useful for Server Operations and Active Record models. Here ...

Open Graph Description: You can now easily split your class definitions so that you have an isomorphic (i.e. runs on the server and client) definition, and a server-only definition. This is especially useful for Server Op...

X Description: You can now easily split your class definitions so that you have an isomorphic (i.e. runs on the server and client) definition, and a server-only definition. This is especially useful for Server Op...

Opengraph URL: https://github.com/hyperstack-org/hyperstack/issues/361

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"automatically add dependencies for server side files.","articleBody":"You can now easily split your class definitions so that you have an isomorphic (i.e. runs on the server and client) definition, and a server-only definition.\r\n\r\nThis is especially useful for Server Operations and Active Record models.\r\n\r\nHere is a sample directory structure, containing an application component, a model called Person, and an operation called PalindromeChecker.  We also have a model called Orderbut it is only visible on the server.  More on that later.\r\n\r\n```\r\napp -\r\n  hyperstack -\r\n    components -\r\n      app.rb\r\n    models -\r\n      application_record.rb\r\n      person.rb\r\n    operations\r\n      palindrome_checker.rb\r\n  models -\r\n    person.rb\r\n    order.rb\r\n  operations\r\n    palindrome_checker.rb\r\n```\r\n\r\nNote that the `person.rb` and `palindrome_checker.rb` files exist in two places:  one in the `hyperstack` directory, and the other in the outer app directory.\r\n\r\nFiles in the `hyperstack` `models`, `operations` and `shared` directories will be executed on both the client and the server.  This is how a method can be understood by both the client and the server.\r\n\r\nFiles in the outer app subdirectory are only recognized by the Rails server. So any information in those files, will not be seen on the client.\r\n\r\nAs a side note files in the `hyperstack` `/components`,  `/libs`, and in fact, any other directories except `/models`, `/operations`, and `/shared` directories are only seen on the client.  So there three kinds of files:  Server-only (those in the outer `app` directories), server and client (those in `hyperstack` `/models`, `/operations`, and `/shared`   directories, and client-only (any other `hyperstac`k subdirectories)\r\n\r\nHere is how we can use this difference to nicely structure our code that is sharing information between the server and client.   We can put class definitions that are only relevant to the server in the outer `app` directories, and put class definitions that are used by both the client and server in the `hyperstack` directories.\r\n\r\nSo for example here are the two PalindromeChecker files:\r\n\r\n```ruby\r\n# app/hyperstack/operations/palindrome_checker.rb\r\nclass PalindromeChecker \u003c Hyperstack::ServerOp\r\n  param :string \r\nend\r\n```\r\n\r\n```ruby\r\n# app/operations/palindrome_checker.rb\r\nclass PalindromeChecker \u003c Hyperstack::ServerOp\r\n  param :acting_user, nils: true\r\n  param :string \r\n\r\n  step { params.string = params.string.gsub(/\\s+/, '').downcase }\r\n  step { params.string.reverse == params.string }\r\nend\r\n```\r\n\r\nAll the client-side needs to know is that `PalindromeChecker` is a subclass of `Hyperstack::ServerOp`, and that it accepts a single param - a string to be checked.  This definition is also available to the server, and will ensure that the type signature matches between the isomorphic (client and server) definition and the server-only definition.\r\n\r\nThe server-side file has all the implementation details including the acting_user declaration which can be used to validate who can be calling this operation.  (In this case, we don't require an `acting_user` hence nils are allowed)\r\n\r\nLet's look at an Active Record example:\r\n\r\n```ruby\r\n# app/hyperstack/models/person.rb\r\nclass Person \u003c ApplicationRecord \r\n  def full_name\r\n    \"#{first_name} #{last_name}\"\r\n  end\r\n  \r\n  scope :children, -\u003e() { where(\"birthday \u003e ?\", Time.now - 21.years) }\r\n  scope :adults, -\u003e() { where(\"birthday \u003c= ?\", Time.now - 21.years) }\r\nend\r\n```\r\n\r\n```ruby\r\n# app/hyperstack/models/person.rb \r\nclass Person \u003c ApplicationRecord \r\n  has_many :orders\r\nend\r\n```\r\n\r\nHere we have a helper method and some scopes defined in the isomorphic definition:  These are available to both the client and the server.  \r\n\r\nHowever the server-side file also has relationships with another model, and because these are defined on the server-side they are not visible to the client.\r\n\r\nIn order for this to work, you do need to add a small snippet of code to your `initializers/hyperstack.rb` file which trains Rails to look in both directories for any constant definition.  This code will be released into Hyperstack soon, but in the meantime feel free to use this snippet and clean up your classes:\r\n\r\n```ruby\r\n# Add to your `initializers/hyperstack.rb file\r\nmodule ActiveSupport\r\n  module Dependencies\r\n    HYPERSTACK_DIR = 'hyperstack'  \r\n    class \u003c\u003c self\r\n      alias original_require_or_load require_or_load\r\n\r\n      # before requiring_or_loading a file, first check if\r\n      # we have the same file in the server side directory\r\n      # and add that as a dependency\r\n\r\n      def require_or_load(file_name, const_path = nil)\r\n        add_server_side_dependency(file_name)\r\n        original_require_or_load(file_name, const_path)\r\n      end\r\n\r\n      # search the filename path from the end towards the beginning\r\n      # for the HYPERSTACK_DIR directory.  If found, remove it from\r\n      # the filename, and if a ruby file exists at that location then\r\n      # add it as a dependency\r\n\r\n      def add_server_side_dependency(file_name)\r\n        path = File.expand_path(file_name.chomp('.rb'))\r\n                   .split(File::SEPARATOR).reverse\r\n        hs_index = path.find_index(HYPERSTACK_DIR)\r\n\r\n        return unless hs_index # no hyperstack directory here\r\n\r\n        new_path = (path[0..hs_index - 1] + path[hs_index + 1..-1]).reverse\r\n        load_path = new_path.join(File::SEPARATOR)\r\n\r\n        return unless File.exist? \"#{load_path}.rb\"\r\n\r\n        require_dependency load_path\r\n      end\r\n    end\r\n  end\r\nend\r\n```","author":{"url":"https://github.com/catmando","@type":"Person","name":"catmando"},"datePublished":"2021-02-25T01:51:45.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/361/hyperstack/issues/361"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:93e6949e-7cb2-5abd-f455-bcc849dd7749
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id8F50:73BCE:16B4270:1CEB8DE:6991838B
html-safe-nonce7ae6deb3bc78dbde9bbafd3eb0de9f7082607146ea18e4cc0a5a3ac724df4ed1
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RjUwOjczQkNFOjE2QjQyNzA6MUNFQjhERTo2OTkxODM4QiIsInZpc2l0b3JfaWQiOiIxNjk1ODg2NzM2NDUyODQ2NDc1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac62d8c7b697ad6a952df7e6bd1557cbbc101360aed39ac9be194dedaf47395ccb
hovercard-subject-tagissue:815993178
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/hyperstack-org/hyperstack/361/issue_layout
twitter:imagehttps://opengraph.githubassets.com/b8f4cb67295df620b3f57ee7e7f3c683dc5b05da9bfbac2406335504fbd99e28/hyperstack-org/hyperstack/issues/361
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/b8f4cb67295df620b3f57ee7e7f3c683dc5b05da9bfbac2406335504fbd99e28/hyperstack-org/hyperstack/issues/361
og:image:altYou can now easily split your class definitions so that you have an isomorphic (i.e. runs on the server and client) definition, and a server-only definition. This is especially useful for Server Op...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamecatmando
hostnamegithub.com
expected-hostnamegithub.com
None42c603b9d642c4a9065a51770f75e5e27132fef0e858607f5c9cb7e422831a7b
turbo-cache-controlno-preview
go-importgithub.com/hyperstack-org/hyperstack git https://github.com/hyperstack-org/hyperstack.git
octolytics-dimension-user_id34562730
octolytics-dimension-user_loginhyperstack-org
octolytics-dimension-repository_id145879576
octolytics-dimension-repository_nwohyperstack-org/hyperstack
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id145879576
octolytics-dimension-repository_network_root_nwohyperstack-org/hyperstack
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release848bc6032dcc93a9a7301dcc3f379a72ba13b96e
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/hyperstack-org/hyperstack/issues/361#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fhyperstack-org%2Fhyperstack%2Fissues%2F361
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fhyperstack-org%2Fhyperstack%2Fissues%2F361
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=hyperstack-org%2Fhyperstack
Reloadhttps://github.com/hyperstack-org/hyperstack/issues/361
Reloadhttps://github.com/hyperstack-org/hyperstack/issues/361
Reloadhttps://github.com/hyperstack-org/hyperstack/issues/361
hyperstack-org https://github.com/hyperstack-org
hyperstackhttps://github.com/hyperstack-org/hyperstack
Notifications https://github.com/login?return_to=%2Fhyperstack-org%2Fhyperstack
Fork 39 https://github.com/login?return_to=%2Fhyperstack-org%2Fhyperstack
Star 540 https://github.com/login?return_to=%2Fhyperstack-org%2Fhyperstack
Code https://github.com/hyperstack-org/hyperstack
Issues 164 https://github.com/hyperstack-org/hyperstack/issues
Pull requests 27 https://github.com/hyperstack-org/hyperstack/pulls
Actions https://github.com/hyperstack-org/hyperstack/actions
Wiki https://github.com/hyperstack-org/hyperstack/wiki
Security 0 https://github.com/hyperstack-org/hyperstack/security
Insights https://github.com/hyperstack-org/hyperstack/pulse
Code https://github.com/hyperstack-org/hyperstack
Issues https://github.com/hyperstack-org/hyperstack/issues
Pull requests https://github.com/hyperstack-org/hyperstack/pulls
Actions https://github.com/hyperstack-org/hyperstack/actions
Wiki https://github.com/hyperstack-org/hyperstack/wiki
Security https://github.com/hyperstack-org/hyperstack/security
Insights https://github.com/hyperstack-org/hyperstack/pulse
New issuehttps://github.com/login?return_to=https://github.com/hyperstack-org/hyperstack/issues/361
New issuehttps://github.com/login?return_to=https://github.com/hyperstack-org/hyperstack/issues/361
automatically add dependencies for server side files.https://github.com/hyperstack-org/hyperstack/issues/361#top
enhancementNew feature or requesthttps://github.com/hyperstack-org/hyperstack/issues?q=state%3Aopen%20label%3A%22enhancement%22
needs docEverything is working, but documentation is needed.https://github.com/hyperstack-org/hyperstack/issues?q=state%3Aopen%20label%3A%22needs%20doc%22
https://github.com/catmando
https://github.com/catmando
catmandohttps://github.com/catmando
on Feb 25, 2021https://github.com/hyperstack-org/hyperstack/issues/361#issue-815993178
enhancementNew feature or requesthttps://github.com/hyperstack-org/hyperstack/issues?q=state%3Aopen%20label%3A%22enhancement%22
needs docEverything is working, but documentation is needed.https://github.com/hyperstack-org/hyperstack/issues?q=state%3Aopen%20label%3A%22needs%20doc%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.