Misc slots

Misc slots

These are slots that don’t belong to a specific category solving some problem related to your applications.

[magic.io.file.load-recursively]

This slot loads all files recursively within the specified folder, and returns their filenames and their content. The following example Hyperlambda illustrates its usage.

signal:magic.io.file.load-recursively
   .:/modules/

The above will result in something resembling the following. Notice, the result below has been significantly snippet.

signal
   :/modules/README.md
      :"\n# Your modules folder\n\nThis ... snip ...\n"
   :/modules/magic/crypto_invocations-count.get.hl
      :@"..."

As you can see above the result is an array of filenames, where each filename has one child node, being the actual content of the file. The slot is used when for instance a frontend application is being generated based upon a template - In addition when you download a folder or something similar.

[magic.modules.ensure-database]

This slot ensures that a module’s database exists by invoking its associated create database SQL file. The slot requires the following arguments.

  • [module] - Name of module
  • [database] - Name of database to check for
  • [database-type] - Optional type of database. If not specified defaults to the default database type

The slot basically checks to see if the specified [database] database exists, and if not, attempts to find its associated “xxx.yyy.sql” script within its folder, where “xxx” is the module name and “yyy” is the default database type. The slot will also automatically execute any migration scripts associated with the module. Notice, the “Ensure database” macro in “Hyper IDE” automatically takes care of wiring up invocations to this slot, creating the required structure in the process.

[magic.modules.install-module]

This slot installs a module that has been previously unzipped into your modules folder by making sure all startup files are executed. The slot takes the following argument.

  • [module] - Root folder of the module to install Typically you wouldn’t want to execute this directly yourself, but rely upon Magic’s middleware to invoke the slot. If you unzip a zip file inside of your “modules” folder, and/or download a bazar item, this slot will be automatically invoked.

[transformers.hash-password]

This slot is a “transformer” and typically used for input payloads originating from HTTP invocations, such as when creating a new user, etc. The following Hyperlambda illustrates its usage.

.arguments
   password:foo
eval:x:+
signal:transformers.hash-password
   reference:x:@.arguments/*/password

The idea of the slot is that it transforms in place the specified argument by reference. Implying executing the above Hyperlambda will result in something resembling the following.

.arguments
   password:$2b$10$ZjOhP3DecbgqYsTKknvLmODs1H1C6bfCheBug6iTk5TNmEckE9H3e

This makes it perfect for “transforming” input payloads containing passwords before persisting these into your database.