Skip to main content

AccessPolicyContextUtils

The thing an AccessPolicy is handed when it runs. A named concept with a checked shape rather than an anonymous table, because a policy author reads this before they write anything, and "what do I get and what may I do with it" should be answerable in one place.

apply = function(context)
	return context.observeFact(AccessFactNames.PLAYER_IS_ADMIN):Subscribe(function(isAdmin)
		if isAdmin == false then
			kick(context.player)
		end
	end)
end

observeFact and observeFeature refuse anything the policy did not declare, so what a readout says a policy depends on is the whole truth about its inputs.

Properties

isAccessPolicyContext

AccessPolicyContextUtils.isAccessPolicyContext: (any) → (
boolean,
string?
)

Functions

create

AccessPolicyContextUtils.create(contextAccessPolicyContext) → AccessPolicyContext

Types

interface AccessPolicyContext {
playerPlayer
observeFact(factNamestring) → Observable<boolean?>
observeFeature(
featureAccessFeature,
subjectany?
) → Observable<AccessState>
}

Builds a context, asserting its shape. Strict rather than lenient: a context missing a member fails here, where the message names it, instead of inside somebody's policy as a nil call.

Show raw api
{
    "functions": [
        {
            "name": "create",
            "desc": "Builds a context, asserting its shape. Strict rather than lenient: a context missing a member fails\nhere, where the message names it, instead of inside somebody's policy as a nil call.",
            "params": [
                {
                    "name": "context",
                    "desc": "",
                    "lua_type": "AccessPolicyContext"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "AccessPolicyContext"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 74,
                "path": "src/access/src/Shared/AccessPolicyContextUtils.lua"
            }
        }
    ],
    "properties": [
        {
            "name": "isAccessPolicyContext",
            "desc": "",
            "lua_type": "(any) -> (boolean, string?)",
            "source": {
                "line": 61,
                "path": "src/access/src/Shared/AccessPolicyContextUtils.lua"
            }
        }
    ],
    "types": [
        {
            "name": "AccessPolicyContext",
            "desc": "",
            "fields": [
                {
                    "name": "player",
                    "lua_type": "Player",
                    "desc": ""
                },
                {
                    "name": "observeFact",
                    "lua_type": "(factName: string) -> Observable<boolean?>",
                    "desc": ""
                },
                {
                    "name": "observeFeature",
                    "lua_type": "(feature: AccessFeature, subject: any?) -> Observable<AccessState>",
                    "desc": ""
                }
            ],
            "source": {
                "line": 37,
                "path": "src/access/src/Shared/AccessPolicyContextUtils.lua"
            }
        }
    ],
    "name": "AccessPolicyContextUtils",
    "desc": "The thing an [AccessPolicy] is handed when it runs. A named concept with a checked shape rather than\nan anonymous table, because a policy author reads this before they write anything, and \"what do I get\nand what may I do with it\" should be answerable in one place.\n\n```lua\napply = function(context)\n\treturn context.observeFact(AccessFactNames.PLAYER_IS_ADMIN):Subscribe(function(isAdmin)\n\t\tif isAdmin == false then\n\t\t\tkick(context.player)\n\t\tend\n\tend)\nend\n```\n\n`observeFact` and `observeFeature` refuse anything the policy did not declare, so what a readout says\na policy depends on is the whole truth about its inputs.",
    "source": {
        "line": 22,
        "path": "src/access/src/Shared/AccessPolicyContextUtils.lua"
    }
}