# shared/allowlists/factory.allowlist.ts

> 59 lines of code and 13 definitions.

Tree: Governance tree
Language: typescript
Layer: infrastructure
Canonical: https://banes-lab.com/anatomy/governance#file-governance-shared-allowlists-factory-allowlist-ts
Source text: https://banes-lab.com/source/governance/shared/allowlists/factory.allowlist.ts.txt

Listed in [shared/allowlists](https://banes-lab.com/api/source/governance/shared/allowlists.md), after [shared/allowlists/export.allowlist.ts](https://banes-lab.com/source/governance/shared/allowlists/export.allowlist.ts.md) and before [shared/allowlists/registrar.allowlist.ts](https://banes-lab.com/source/governance/shared/allowlists/registrar.allowlist.ts.md).

## Definitions

- `declaredModules` (lexical_declaration, line 55, exported)
- `isRecord` (lexical_declaration, line 34)
- `declaredNames` (lexical_declaration, line 38)
- `RAW_ELEMENT_FACTORIES` (lexical_declaration, line 3, exported)
- `ELEMENT_FACTORY_MODULES` (lexical_declaration, line 5, exported)
- `FACTORY_OPTIONS_SCHEMA` (lexical_declaration, line 7, exported)
- `MODULE_OPTIONS_SCHEMA` (lexical_declaration, line 15, exported)
- `WRITER_OPTIONS_SCHEMA` (lexical_declaration, line 23, exported)
- `options` (lexical_declaration, line 39)
- `value` (lexical_declaration, line 43)
- `declaredFactories` (lexical_declaration, line 47, exported)
- `declaredWriters` (lexical_declaration, line 63, exported)
- `declared` (lexical_declaration, line 67, exported)

## Used by

- [rules/eslint/no-inline-style-write.eslint.rule.ts](https://banes-lab.com/source/governance/rules/eslint/no-inline-style-write.eslint.rule.ts.md)
- [rules/eslint/no-raw-dom.eslint.rule.ts](https://banes-lab.com/source/governance/rules/eslint/no-raw-dom.eslint.rule.ts.md)

## Source

```typescript
import type { OptionsCarrier } from "../../types/manifest.types.ts";

export const RAW_ELEMENT_FACTORIES: ReadonlySet<string> = new Set<string>();

export const ELEMENT_FACTORY_MODULES: ReadonlySet<string> = new Set<string>();

export const FACTORY_OPTIONS_SCHEMA = [
    {
        additionalProperties: false,
        properties: { factories: { items: { type: "string" }, type: "array" } },
        type: "object",
    },
];

export const MODULE_OPTIONS_SCHEMA = [
    {
        additionalProperties: false,
        properties: { modules: { items: { type: "string" }, type: "array" } },
        type: "object",
    },
];

export const WRITER_OPTIONS_SCHEMA = [
    {
        additionalProperties: false,
        properties: {
            modules: { items: { type: "string" }, type: "array" },
            writers: { items: { type: "string" }, type: "array" },
        },
        type: "object",
    },
];

const isRecord = function isRecord(value: unknown): value is Record<string, unknown> {
    return typeof value === "object" && value !== null;
};

const declaredNames = function declaredNames(context: OptionsCarrier, key: string): string[] {
    const options: unknown = context.options.at(0);
    if (!isRecord(options)) {
        return [];
    }
    const value = options[key];
    return Array.isArray(value) ? value.filter((entry): entry is string => typeof entry === "string") : [];
};

export const declaredFactories = function declaredFactories(
    context: OptionsCarrier,
    fallback: ReadonlySet<string>,
): ReadonlySet<string> {
    const declared = declaredNames(context, "factories");
    return declared.length > 0 ? new Set(declared) : fallback;
};

export const declaredModules = function declaredModules(
    context: OptionsCarrier,
    fallback: ReadonlySet<string>,
): ReadonlySet<string> {
    const declared = declaredNames(context, "modules");
    return declared.length > 0 ? new Set(declared) : fallback;
};

export const declaredWriters = function declaredWriters(
    context: OptionsCarrier,
    fallback: ReadonlySet<string>,
): ReadonlySet<string> {
    const declared = declaredNames(context, "writers");
    return declared.length > 0 ? new Set(declared) : fallback;
};
```
