Options
All
  • Public
  • Public/Protected
  • All
Menu
     

Interface Route

Config properties for the DBRequest object.

Hierarchy

Index

Describer Properties

Handler Properties

Other Properties

Post-Format Properties

Restrictive Properties

Post-Format Methods

Describer Properties

Optional Sub

Sub: String[]

A list of the heirarchy Endpoints contained within it's Base that it belongs under.

By default, any Endpoint defined within a BasePoint -- except, of course, for "/" -- is a direct descendant of "/", as "/" is just the definition of the BasePoint without any other paths following it. But obviously there are needs to push the heirarchy further.

Instead of forcing developers to use a Parant > Child structure that would get very annoying, very fast, heirarchies are defined using this property. As was said earlier, "/", is inherited by all other Endpoints contained with a BaseEndpoint, so it doesn't need to be add here. If the Endpoint in question is to remain a direct descendant of "/", then this need not be defined.

Depending on whether or not Merge is configured, the path will be resolved differently.

Example:

({
  User: {
    Actions: {
      Email: new RouteDB({
        Scheme: '/',
        Merge: true,
        Subs: ['settings'], // defined, child of "Settings", Merge
        // Resolves to "/user/settings/:sttg_id/email"
      }),
      Privacy: new RouteDB({
        Scheme: '/:uid/',
        Subs: ['settings'], // defined, child of "Settings", no Merge
        // Resolves to "/user/settings/privacy/:uid"
      }),
      Settings: new RouteDB({
        Scheme: '/:sttg_id/', ...
        // Sub not defined, is child of "/", no Merge
      }),
      "/": new RouteDB({
        Scheme: '/:uid/', ...
        // Resolves to "/user/:uid"
      }),
    }
  }
});

Optional Scheme

Scheme: String

A RegexP, string-representation of the Route Path.

Optional Merge

Merge: boolean | HMETHOD

A flag the specifies whether or not, and if so, how to prepend the path-parameters of the last parent-Endpoint referenced in Sub (along with the merge of its own parent; if applicable) to the path-name/parameters of this Endpoint:

  • If true, the Scheme from the parent-Endpoint will be prepended to this Scheme of this Endpoint.
  • If set as an HMETHOD, then the system will use the Scheme defined in the parent-Endpoint's CBRouteAU/CBRouteDB definition of the same HMETHOD. Otherwise, it choose the first Scheme found within each parent.
  • Defined in a method (see: Uses below), and set to true, then the system will look for that method deinition within the parent and choose that Scheme. Otherwise, the first Scheme found is chosen.

Example:

({
  User: {
    Actions: {
      Password: new RouteDB({
        Merge: true,
        Subs: ['settings','privacy'], // Child of "Settings"
        GET: () => ({ ... }), // Merge to "Privacy.GET"
        // ^ Resolves to "/user/:uid/settings/privacy/:prv_id/password"
      }),
      Email: new RouteDB({
        Merge: 'POST', // Merge to "Privacy.POST"
        Subs: ['settings','privacy'], // Child of "Settings"
        GET: () => ({ ... }),
        // ^ Resolves to "/user/:uid/settings/privacy/email"
      }),
      Privacy: new RouteDB({
        Scheme: '/:prv_id/', // Defult for any Method defined within
        Subs: ['settings'], // Child of "Settings".
        Merge: true,
        GET: () => ({ ... }),
        // ^ Merge to "Settings.GET",
        // ^ Resolves to "/user/:uid/settings/privacy/:prv_id"
        POST: () => ({ Scheme: '/' })
        // ^ Merge to "Settings.GET", Scheme redefined to "/"
        // ^ Resolves to "/user/:uid/settings/privacy"
      }),
      Settings: new RouteDB({
        Merge: true,
        GET: () => ({ ... }),
        // ^ Sub not defined, is child of "/"
        // ^ Resolves to "/user/:uid/settings"
      }),
      "/": new RouteDB({
        Scheme: '/:uid/',
        GET: () => ({ ... }),
        // ^ Resolves to "/user/:uid"
      }),
    }
  }
});

Uses:

Optional Limits

Limits: String[]

A list of Limits to subscribe to.

Optional Doc

Doc: Doc

The documentation for Methods in this Route.

Handler Properties

Optional GET

A callback that returns configs for a GET method within a Route.

Optional POST

POST: CBRouteDB

A callback that returns configs for a POST method within a Route.

Optional PUT

A callback that returns configs for a PUT method within a Route.

Optional DELETE

DELETE: CBRouteDB

A callback that returns configs for a DELETE method within a Route.

Optional Params

Params: CLParams

A collection of GNParams, which represent the global or method-specific path/query/body parameters of an Endpoint:

These can be defined inline:

{
    async Query() { ... },
    Params: {
         UserID: new GNParam({
             Name: 'User ID',
             Default: null,
             Format (cls) { return cls.user_id; },
             // ...
         }),
    },
    Parse(res) { ... },
}

Or defined in a CFG.PNTS.Defaults object within config/authpoints.cfg.js or config/endpoints.cfg.js:

{
    __DEFAULTS: {
        Header: { ... },
        Params: {
            // Define as a Default...
            UserID: new GNParam({ ... }),
        }
    },
    User: {
        Actions: {
            Settings: new RouteDB({
                Params: {
                    // ... Reference the default.
                    UserID: true,
                }
            }),
        },
    },
}

When defined using the latter technique, references to those predefined GNParams are made in the following ways:

Reference Example Description
Direct { Email: true } References the param defined in __DEFAULTS.
Version { Email: ['REQUIRED'] } References a required version of the Email Param.

Other Properties

Methods

Methods: Array<"GET" | "POST" | "PUT" | "DELETE">
inheritdoc

Post-Format Properties

Optional Key

Key: String

A string that refers to a property-key of an Object-interface property within any Data.Method result returned as an Array<{ key: value, ...rest }>. When this is set, the internal-parser will transform the Array<{ key: value, ...rest }> into Object<key,{ key: value, ...rest }>, removing the property from each item in the Object that now serves as the key of each item-value.

Example:

({
    Query: (cls) => ([
        { user_id: 1, name: 'Hello', age: 102 },
        { user_id: 2, name: 'World', age: 20  },
        { user_id: 3, name: 'Foo',   age: 31  },
        { user_id: 4, name: 'Bar',   age: 46  },
    ]),
    Key: 'user_id',
});
// payload.result = {
//     1: { name: 'Hello', age: 102 },
//     2: { name: 'World', age: 20  },
//     3: { name: 'Foo',   age: 31  },
//     4: { name: 'Bar',   age: 46  },
// }

Optional Links

Links: String[]

A list of Request Paths used for linking RouteDB requests.

Restrictive Properties

Optional Private

Private: boolean

true, if this Endpoint is restricted to Admins.

Post-Format Methods

Optional Parse

  • An optional callback that handles any post-formatting needed before the result of a method is attached to the payload for consumption.

    This may seem redundant when using Data.Method.Query (as a CBQYHandle, not a SQL string[]), but when a particular Enpdpoint responds to multiple HMETHODs, the result-structure is usually the same. This property can be exploited by defining it globally inside of the Data.Method config. For every CBRouteDB contained within the CFGRouteQry*, this callback will be applied. That way, you need only define it once.

    Of course, if a certain format is required across multiple Endpoints, one can always define the callback outside of the {@link CFGAuthPointsDB} config and assign it to Parse.

    If this is not defined, the internal-parser will do what it does. This is generally just dumping whatever was returned; unless the result returned is of Array<Object<key,value>>, and Key maps to one of the item's keys.

    Uses:

    Parameters

    Returns any