Aller au contenu
Krizaka TS
Krizaka TS

@krizaka/organize

Un nom, un avatar, des étiquettes et des collections pour toute entité, avec un kit de conformité.

Installer

bashTerminal
npm install @krizaka/organize

Le README ci-dessous est celui du paquet sur npm, en anglais.

A name, an avatar, a description, tags, collections and an undeletable default collection for any entity of a Krizaka product (ADR-006). No ORM, no framework, no image library: you pass a query function and, for uploaded avatars, an AvatarProcessor and an ObjectStore.

import { createOrganize, organizeMigration } from "@krizaka/organize";

const schema = { defaultName: { fr: "Mes boutiques", en: "My shops" }, kinds: { shop: { table: "shops" } } };
await db.query(organizeMigration(schema)); // once, in your migrations
const organize = createOrganize({ query: (sql, params) => pool.query(sql, params).then((r) => r.rows), schema, images });

await organize.collections.create(owner, { name: "Quartier Est" });
await organize.profile("shop").rename(owner, shopId, "Salon Cèdre");
await organize.tags.assign(owner, "shop", shopId, [tagId]);
  • The invariants are the database's: one default collection per owner (exclusion constraint + deferred trigger), never deleted while its owner exists, created with the owner in its language, and every entity given no collection falls into it.
  • Refusals are OrganizeError with a stable code and status (DEFAULT_COLLECTION, NAME_TAKEN, AVATAR_NOT_ALLOWED…): a product maps them to its own answers.
  • Pure rules for the URL: parseTagsParam, toggleTag, tagsHref.

Exports

Les 33 noms que le paquet exporte, lus dans ses types.

NomNatureCe que c’est
AvatartypeAn avatar: one of a set (a seed the UI draws) or an uploaded image (served at an address that carries its version).
AVATAR_KINDconstante
AvatarImageErrorclasseThe processor refuses an image with a stable reason; the service turns it into AVATAR_UNREADABLE or a pass-through error.
AvatarProcessortypeMakes an uploaded image an avatar: checked, square, upright, without metadata.
AvatarRulestype
cleanDescriptionfonctionA description: trimmed, at most DESCRIPTION_MAX characters; empty means none (null).
cleanNamefonctionWhat an entity or a collection may be called: spaces collapsed, trimmed, 1 to NAME_MAX characters; null when it is not.
Collectiontype
createOrganizefonction« organize »: for every kind a product declares, a name, a description, an avatar, tags and a place in a collection; collections with an undeletable default…
DEFAULTSconstante
DESCRIPTION_MAXconstante
identfonctionA SQL identifier from the product's declaration: lower-case letters, digits, underscore.
isIdfonction
isTagColorfonction
KindDecltype
NAME_MAXconstanteThe pure rules of « organize »: names, tag colours, ids, and the tags parameter of a view (the URL is the state).
ObjectStoretypeWhat an uploaded avatar is kept in: the same shape as a document store (put, get, delete), so a product passes the one it has.
Organizetype
ORGANIZE_CODEconstanteStable refusal codes: a product turns them into its own HTTP answers and messages.
OrganizeCodetype
OrganizeDepstype
OrganizeErrorclasse
organizeMigrationfonction
OrganizeSchematype
parseTagsParamfonction?tags=a,b (or the repeated form) → the ids, in order, without duplicates and without anything that is not an id.
Profiletype
QuerytypeRuns one SQL statement with its parameters and returns the rows.
storedAvatarKeyfonctionWhere an uploaded avatar lives in the product's object store (a signed link to it is the product's to make).
Tagtype
TAG_COLORSconstanteTag colours are NAMES that the UI maps to its tokens — never a hex in the database.
TagColortype
tagsHreffonctionThe same path with another set of tags: the URL is the state.
toggleTagfonction

Paquet

Version sur npm0.3.0 (npm)
LicenceApache-2.0
Node.js>=22
Dépendancesaucune
Code sourceorganize

Journal des versions

0.3.0

Minor changes

  • legacyAvatarKey: a product's older image keys are read and deleted as a fallback, never written.

0.2.0

Minor changes

  • storedAvatarKey (where an uploaded avatar lives in the object store, so a product can sign a link to it) and collectionTags (the collections' tag join table, for a product that already has one under another name).

0.1.0

Minor changes

  • First release: the pure rules of « organize » — names, descriptions, tag colours, ids and the tags URL parameter.
  • A kind may say how an entity is its owner's (owns) when its table has no owner column, a collection takes a product's extra columns on creation, and tagging needs no name or avatar column.
  • The service: collections with an undeletable default one (invariants in the database), tags, and the name, description, avatar (a set or an uploaded image behind two ports) and collection of any declared kind; the migration generator; tests against PostgreSQL.

Sur cette page