All files / realm/blong-party/meta/db db.ts

100% Statements 112/112
100% Branches 1/1
100% Functions 0/0
100% Lines 112/112

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 1131x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
import {handler} from '@feasibleone/blong';
 
export default handler(() => ({
    config: {
        schema: {
            // No `dbTest` here: the adapter's `dev` and `ci` activations turn it on, and an
            // `upgrade` or `release` process must not dispatch the test seeds — their handler
            // groups are not loaded there, and the generic merge read an undefined object.
            tables: {
                // Party tables are resource-backed with a REAL display-name column
                // (`resource: {nameColumn}`), not the virtual `${object}Name`:
                // `core_resource.resourceName` mirrors that column — which is what
                // dropdown labels and ACL target names read — while the column
                // itself stays a normal, editable table column.
                //
                // The hierarchy lives in `core_triple` and is declared here as
                // `edges`, so the models can manage it as pivot arrays and the
                // generic CRUD keeps it in sync (`core.path` refresh included).
                // `core_resource.resourceName` mirrors the full name, so every
                // dropdown label and every ACL target reads as a person rather
                // than a surname. `personName` is filled by the form and the
                // seeds. `@@D-602`
                'party.person': {
                    order: 300,
                    resource: {nameColumn: 'personName'},
                    edges: [
                        {
                            // Membership: person → unit.
                            predicate: 'belongsTo',
                            table: 'party_unit',
                            object: 'unit',
                            objectKey: 'unitId',
                            nameField: 'unitName',
                        },
                    ],
                    // Record-level ACL: a person is acted on within the unit it
                    // belongs to.  `add` reads the unit from the submitted
                    // `belongsTo` edge (a person has no unit column).
                    acl: {
                        mode: 'scoped',
                        scopes: ['belongsTo'],
                        addScope: {predicate: 'belongsTo'},
                    },
                },
                'party.organization': {
                    order: 301,
                    resource: {nameColumn: 'legalName'},
                    // An organization is scoped at *itself*: the hierarchy points
                    // the other way (`unit --belongsTo--> organization`), so the
                    // record has no scope edge to follow and a grant naming the
                    // organization (or a parent organization) is what admits it.
                    acl: {mode: 'scoped', selfScope: true},
                },
                'party.unit': {
                    order: 302,
                    resource: {nameColumn: 'unitName'},
                    edges: [
                        {
                            // The unit's owning organization.
                            predicate: 'belongsTo',
                            table: 'party_organization',
                            object: 'organization',
                            objectKey: 'organizationId',
                            nameField: 'organizationName',
                        },
                        {
                            // Self-referencing tree: child unit → parent unit.  The
                            // materialized `access.effectiveScope` path turns this
                            // into "a grant on a parent covers its descendants".
                            predicate: 'isPartOf',
                            table: 'party_unit',
                            object: 'parentUnit',
                            objectKey: 'unitId',
                            nameField: 'unitName',
                            reverse: true,
                        },
                    ],
                    acl: {
                        mode: 'scoped',
                        scopes: ['belongsTo'],
                        addScope: {predicate: 'belongsTo'},
                    },
                },
                'party.contact': 303,
                'party.address': 304,
                'party.identifier': 305,
                // The explicit-mode table of the ACL matrix.  `mode: 'explicit'`
                // means a rule is the only way in: no `hasScope` grant is
                // consulted, so the fixture can show — side by side — a record
                // rule that admits exactly one row, a scope rule that admits
                // nothing at all and a wildcard rule that admits every row.  The
                // `belongsTo` edge is still declared: the models manage it as a
                // pivot, and the fixture asserts the ownership.
                'party.consent': {
                    order: 306,
                    resource: {nameColumn: 'consentName'},
                    edges: [
                        {
                            predicate: 'belongsTo',
                            table: 'party_person',
                            object: 'person',
                            objectKey: 'personId',
                            nameField: 'lastName',
                        },
                    ],
                    acl: {mode: 'explicit'},
                },
            },
        },
        // No mock entries — all models use real DB tables (like marineCoralModel).
    },
}));