chadtmiller.com/pds.js
An atproto PDS in JavaScript, for Cloudflare Workers and Node
0
0
// @pdsjs/spaces/space-row - the one place a SpaceRow is constructed.
import { MEMBERSPACE, normalizePolicy } from './policy.js';
import { parseSpaceUri } from './uri.js';
/**
* Build a SpaceRow from a space URI.
*
* `SpaceRow` carries `spaceDid` and `spaceType` alongside `uri` so the storage
* adapters can filter on indexed columns without parsing AT-URIs themselves
* (parsing is domain logic and lives here). Those fields are therefore
* redundant with `uri`, and nothing downstream re-checks that they agree — so
* every construction site goes through this function rather than assembling the
* object by hand.
*
* @param {string} uri - space AT-URI
* @param {Partial<Omit<import('@pdsjs/core/ports').SpaceRow, 'uri'|'spaceDid'|'spaceType'>>} [fields]
* @returns {import('@pdsjs/core/ports').SpaceRow}
*/
export function makeSpaceRow(uri, fields = {}) {
const { spaceDid, spaceType } = parseSpaceUri(uri);
return {
uri,
spaceDid,
spaceType,
isOwner: fields.isOwner ?? false,
// The authority's own space has a policy, and a memberspace with its
// defaults when none is named. A writer's repo in another authority's
// space has none.
policy:
fields.policy ??
(fields.isOwner ? normalizePolicy({ $type: MEMBERSPACE }) : null),
createdAt: fields.createdAt ?? new Date().toISOString(),
deletedAt: fields.deletedAt ?? null,
};
}