@loadbare/app 0.18.0 → 0.18.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/lb-types.d.ts +6 -3
- package/dist/core/lb-types.d.ts.map +1 -1
- package/dist/core/lb-types.js.map +1 -1
- package/dist/hub/lb-apply.d.ts +12 -4
- package/dist/hub/lb-apply.d.ts.map +1 -1
- package/dist/hub/lb-apply.js +55 -8
- package/dist/hub/lb-apply.js.map +1 -1
- package/dist/hub/lb-hub.browser.js +3 -3
- package/dist/hub/lb-hub.browser.js.map +1 -1
- package/dist/server/lb-server.d.ts +5 -2
- package/dist/server/lb-server.d.ts.map +1 -1
- package/dist/server/lb-server.js +12 -3
- package/dist/server/lb-server.js.map +1 -1
- package/docs/TECHREF-1.0.md +49 -62
- package/docs/comparison.md +5 -5
- package/docs/reference/css.md +163 -0
- package/docs/reference/data-binding.md +31 -3
- package/docs/reference/page-files.md +2 -1
- package/docs/reference/widgets.md +24 -2
- package/docs/roadmap.md +17 -9
- package/package.json +1 -1
- package/skills/loadbare-app/SKILL.md +11 -5
- package/skills/loadbare-app/references/TECHREF-1.0.md +49 -62
- package/skills/loadbare-app/references/css.md +163 -0
- package/skills/loadbare-app/references/data-binding.md +31 -3
- package/skills/loadbare-app/references/page-files.md +2 -1
- package/skills/loadbare-app/references/widgets.md +24 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lb-server.js","sourceRoot":"","sources":["../../server/lb-server.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,EAAE;AACF,oEAAoE;AACpE,4EAA4E;AAC5E,4EAA4E;AAC5E,gDAAgD;AAgBhD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAC7E,OAAO,EACL,aAAa,EACb,YAAY,EACZ,QAAQ,EACR,SAAS,EACT,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EACl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AE,CAAC;QAChD,OAAO,iEAAiE,CAAC;IAC3E,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["// The server-side contract and the engine that runs it.\n//\n// This is the counterpart to core/lb-constants.ts: that file is the\n// vocabulary the browser writes, this one is the vocabulary the application\n// writes. The engine below is the whole of Loadbare on the server. It ships\n// no HTTP server, no router, and no data layer.\n\nimport type {\n ColumnTypes,\n HubData,\n HubRequest,\n HubResponse,\n HubResult,\n Kind,\n GatheredRow,\n HubRefusal,\n Patch,\n RequestFields,\n ResponseItem,\n Row,\n} from \"../core/lb-types.js\";\nimport { isRowRequest, nextLocation, parseOrder } from \"../core/lb-types.js\";\nimport {\n CHOICES_QUERY,\n COLUMN_TYPES,\n KIND_ROW,\n KIND_ROWS,\n LB_RESERVED_PREFIX,\n REQUEST_ROW_DELETE,\n REQUEST_ROW_INSERT,\n REQUEST_ROW_UPDATE,\n URL_COLUMN_PATH,\n URL_QUERY,\n} from \"../core/lb-constants.js\";\n\n/**\n * Whatever the application hands the engine for the duration of one request.\n *\n * Loadbare declares it empty and never reads it. An application fills it in\n * by declaration merging, once, anywhere in its own source:\n *\n * declare module \"@loadbare/app/server\" {\n * interface HubContext {\n * db: Db;\n * }\n * }\n *\n * That is why no type on this page takes a type parameter. The context is a\n * request-scoped handle — an authenticated database connection is the\n * expected case — so it is passed per call rather than held by the engine.\n * The page's query parms are the other expected member: a query that reads\n * one off the context takes no argument, and re-runs under `refresh` like\n * any other.\n */\nexport interface HubContext {}\n\n/**\n * A declared query: its kind, its key, and the run that answers it.\n *\n * Kind and key are properties of the name rather than of any one answer, so\n * they are declared here and never inferred from what comes back. The engine\n * sends both with every answer, so the markup repeats neither. Every query\n * has a key; an aggregate row answers with a constant one.\n *\n * Write one with `row()` or `rows()` below; nothing else builds one.\n */\nexport interface Query {\n readonly kind: Kind;\n readonly key: string;\n readonly run: (ctx: HubContext) => HubResult | Promise<HubResult>;\n /** A `rows` query's order, as `rows()` declared it. */\n readonly order?: string;\n /** A `rows` query's column types, as `rows()` declared them. */\n readonly types?: ColumnTypes;\n}\n\n/**\n * What a `rows` query declares about its order.\n *\n * `order` is the order the hub places its rows by: columns separated by\n * commas, each descending when it begins with `-`, as in\n * `category_order,-opened`. An order the user chose, held in `lb-choices`,\n * replaces it. With neither, rows show in the order the query answered them\n * in.\n *\n * `types` names a type for any of its columns, and the hub sorts, filters\n * and takes `lb-min` and `lb-max` of that column read as its type rather\n * than by the JSON type its values arrive as: `{ amount: \"number\" }` for a\n * Postgres `numeric` that arrives as a string. A column it does not name\n * compares by its JSON type. The order and the types go to the browser\n * once, with the answer that loads the page.\n */\nexport interface RowsOptions {\n order?: string;\n types?: ColumnTypes;\n}\n\n/** A query that answers with one row, identified by its `key` column. */\nexport function row(\n key: string,\n run: (ctx: HubContext) => Row | Promise<Row>,\n): Query {\n return { kind: KIND_ROW, key, run };\n}\n\n/**\n * A query that answers with all its rows. Rows land by their `key` column: a\n * row whose key is not in the answer is gone. The hub places them by the\n * order in `options`, or in the order they arrived when there is none.\n */\nexport function rows(\n key: string,\n run: (ctx: HubContext) => Row[] | Promise<Row[]>,\n options: RowsOptions = {},\n): Query {\n return {\n kind: KIND_ROWS,\n key,\n run,\n ...(options.order !== undefined && { order: options.order }),\n ...(options.types !== undefined && { types: options.types }),\n };\n}\n\n/**\n * Only what changed, returned from a handler for a `rows` query. Rows named\n * here are added or updated, keys in `drop` are removed, and everything\n * unnamed is left alone — its contents, and its place in whatever order the\n * page is keeping.\n *\n * `Array.isArray` is what tells a patch from all rows, so a patch needs no\n * marker of its own and no column name is reserved to carry one.\n */\nexport function patch(change: { rows?: Row[]; drop?: unknown[] }): Patch {\n const made = { ...change };\n patches.add(made);\n return made;\n}\n\n/**\n * Every object `patch()` made. A patch and a row are both plain objects, so\n * this is how the engine refuses a patch answering a `row` query.\n */\nconst patches = new WeakSet<object>();\n\n/**\n * A new row for `lb-url`, returned from a handler when only the handler can\n * know where the page belongs: the key of a row it inserted, or the absence\n * of one it deleted.\n *\n * A column other than `lb-path` is a query parm: set, or taken out when its\n * value is empty. With `lb-path` naming another page, the page is entered\n * with only the parms named here; otherwise every other parm is kept.\n *\n * The page then loads at the new URL in the same round trip, as a cold load\n * of it would, so the refresh set is not run and whatever else the handler\n * returned is dropped: both were answers for the URL the page is leaving.\n * This is Post/Redirect/Get without the redirect.\n */\nexport function url(columns: Record<string, string>): HubData {\n return { [URL_QUERY]: { ...columns } };\n}\n\n/**\n * The user's choices for the page, returned from `onPageEnter` to restore\n * what the user last chose: an order, a filter. Each column is a column of\n * `lb-choices`, and the hub places the page's rows by them as they land.\n * Return it beside `url()` with the spread both are written for:\n *\n * return { ...url({ acct: \"23\" }), ...choices({ sort: \"-amount\" }) };\n */\nexport function choices(columns: Record<string, string>): HubData {\n return { [CHOICES_QUERY]: { ...columns } };\n}\n\n/**\n * A handler's refusal: thrown, and answered to the browser with the words\n * it carries. Every other error a handler throws reaches the browser as a\n * failure with nothing in it.\n */\nexport class Refusal extends Error {\n readonly refusal: HubRefusal;\n\n constructor(refusal: HubRefusal) {\n super(refusal.message ?? \"refused\");\n this.name = \"Refusal\";\n this.refusal = refusal;\n }\n}\n\n/**\n * Refuse a request, in words written for the user. Throw what it returns:\n *\n * throw refusal(\"That series already has paychecks entered.\");\n * throw refusal({ amount: \"Must be more than zero\" });\n * throw refusal(\"Two fields need attention.\", { amount: \"…\" });\n *\n * A message alone is for the request as a whole; columns name the controls\n * the request gathered, and each message is shown on its control. Thrown\n * rather than returned, so a refusal can come from anywhere the handler\n * calls, and whatever the application has open rolls back as for any\n * throw.\n */\nexport function refusal(\n message: string | Record<string, string>,\n columns?: Record<string, string>,\n): Refusal {\n return typeof message === \"string\"\n ? new Refusal({ message, ...(columns && { columns }) })\n : new Refusal({ columns: message });\n}\n\n/** The shape of a `<stub>.queries.ts` module. */\nexport type Queries = Record<string, Query>;\n\n/**\n * What a handler does, and which queries re-run once it has.\n *\n * `run` may also return answers of its own, which are laid over the\n * refreshed ones. That is how a patch reaches the browser: a query answers\n * for all its rows and cannot know why it re-ran, but the handler knows\n * exactly what it changed and can say only that.\n */\nexport interface Handler<R = RequestFields> {\n run: (\n ctx: HubContext,\n request: R,\n ) => void | HubData | Promise<void | HubData>;\n refresh: string[];\n}\n\n/**\n * `rows` holds the rows of the queries nested in the form the request came\n * from, by query name, each with its own values: a master's details,\n * written with it.\n */\nexport type RowInsertHandler = Handler<{\n key?: string;\n values: Record<string, string>;\n rows?: Record<string, GatheredRow[]>;\n}>;\n/** `values` holds only the columns being set, as an SQL UPDATE sets them. */\nexport type RowUpdateHandler = Handler<{\n key: string;\n values: Record<string, string>;\n rows?: Record<string, GatheredRow[]>;\n}>;\nexport type RowDeleteHandler = Handler<{ key: string }>;\n\n/**\n * What the requests Loadbare provides do to one query, keyed by its name in\n * `Requests.crud`. A query with no entry here permits none of them: the wire\n * cannot reach anything the page has not published.\n *\n * Every key is the request name with the prefix stripped and the rest\n * camel-cased: `lb-row-insert` runs `rowInsert`.\n */\nexport interface Crud {\n rowInsert?: RowInsertHandler;\n rowUpdate?: RowUpdateHandler;\n rowDelete?: RowDeleteHandler;\n}\n\n/**\n * The shape of a `<stub>.requests.ts` module.\n *\n * `onPageEnter` runs when the page loads, before its queries. It declares no\n * refresh set: the page's queries all run afterward, so whatever it changed\n * is already in the response. It may return `url()` instead, to move the\n * page to other query parms or another page before anything shows, as an\n * application restoring what the user last had on screen does. The page\n * then loads there in the same round trip, and `onPageEnter` running for\n * that load is not followed again. It may return `choices()`, with `url()`\n * or alone, to restore the user's choices for the page.\n *\n * `onChoices` runs each time the user makes a choice, with every choice\n * made on the page, so an application can keep them for `onPageEnter` to\n * restore. It answers with nothing, by convention.\n *\n * `handlers` holds the page's declared requests, by name. A name the page\n * did not declare is refused, so the wire cannot reach anything the page has\n * not published.\n *\n * `crud` holds what the requests Loadbare provides run, by query name.\n */\nexport interface Requests {\n onPageEnter?: (ctx: HubContext) => void | HubData | Promise<void | HubData>;\n onChoices?: (\n ctx: HubContext,\n choices: Record<string, string>,\n ) => void | HubData | Promise<void | HubData>;\n handlers?: Record<string, Handler>;\n crud?: Record<string, Crud>;\n}\n\n/** A page is three files sharing a stub; two of them are these. */\nexport interface Page {\n queries: Queries;\n requests: Requests;\n}\n\n/**\n * The page registry. The builder writes it from every `.requests.ts` and\n * `.queries.ts` it discovers — see docs/reference/builder.md.\n */\nexport type Pages = Record<string, Page>;\n\n/**\n * How a page load treats a `url()` its `onPageEnter` returned.\n *\n * With `follow` false it is ignored and the queries run, as they must for a\n * load that is itself at a URL something else moved to. With `parms`, the\n * query parms the page is being loaded at, one that leads to the page and\n * parms already in hand is ignored the same way, so the page loads once.\n */\nexport interface PageLoadOptions {\n follow?: boolean;\n parms?: URLSearchParams;\n}\n\n/**\n * The engine. Both calls answer with response items. A request whose\n * handler returned `url()`, and a page load whose `onPageEnter` did, answer\n * with the `lb-url` item alone: the caller builds a context at the new URL,\n * calls `dataForPage` with it and `follow` false, and sends the load beside the\n * item. `hubRoutes` does exactly that.\n */\nexport interface Hub {\n /** A page load: its `onPageEnter`, then all of its queries. */\n dataForPage(\n page: string,\n ctx: HubContext,\n options?: PageLoadOptions,\n ): Promise<HubResponse>;\n\n /** A request: run the handler its name picks, then the refresh set. */\n runRequest(\n page: string,\n request: HubRequest,\n ctx: HubContext,\n ): Promise<HubResponse>;\n}\n\n/** The camel-cased `Crud` key of a request Loadbare provides. */\nconst CRUD_KEYS: Record<string, keyof Crud> = {\n [REQUEST_ROW_INSERT]: \"rowInsert\",\n [REQUEST_ROW_UPDATE]: \"rowUpdate\",\n [REQUEST_ROW_DELETE]: \"rowDelete\",\n};\n\n/**\n * Build the engine over a set of pages. The pages are fixed at startup; the\n * context is not, and arrives with each call.\n */\nexport function createHub(pages: Pages): Hub {\n // Names beginning with the reserved prefix are Loadbare's — its own query,\n // the requests it provides — so an application cannot declare one.\n // Refused at startup, because a name is a fact about the page and not\n // about any request.\n for (const [page, entry] of Object.entries(pages)) {\n const declared = [\n ...Object.keys(entry.queries),\n ...Object.keys(entry.requests.handlers ?? {}),\n ...Object.keys(entry.requests.crud ?? {}),\n ];\n for (const name of declared) {\n if (name.startsWith(LB_RESERVED_PREFIX)) {\n throw new Error(\n `loadbare: page '${page}' declares '${name}', but names ` +\n `beginning with '${LB_RESERVED_PREFIX}' are reserved`,\n );\n }\n }\n\n // A crud handler always knows which rows it changed: an update or a\n // delete names its row by key, and an insert has the new row's key once\n // it has written it. So each can answer with a patch, and the hub places\n // what the patch names by the query's order. Refreshing the whole set\n // instead sends every row to say one thing. There is no case where that\n // is the answer, so it is refused rather than warned about.\n // An order is a fact about the query, so a malformed one is refused at\n // startup, as a reserved name is.\n // So is a column type the hub does not know.\n for (const [name, query] of Object.entries(entry.queries)) {\n for (const [column, type] of Object.entries(query.types ?? {})) {\n if (!(COLUMN_TYPES as readonly string[]).includes(type)) {\n throw new Error(\n `loadbare: page '${page}' query '${name}' declares column ` +\n `'${column}' as '${type}'; a column type is one of ` +\n `${COLUMN_TYPES.join(\", \")}`,\n );\n }\n }\n if (query.order === undefined) continue;\n try {\n parseOrder(query.order);\n } catch (err) {\n throw new Error(\n `loadbare: page '${page}' query '${name}': ${(err as Error).message}`,\n );\n }\n }\n\n for (const [name, crud] of Object.entries(entry.requests.crud ?? {})) {\n if (entry.queries[name]?.kind !== KIND_ROWS) continue;\n for (const request of [\"rowInsert\", \"rowUpdate\", \"rowDelete\"] as const) {\n if (crud[request]?.refresh.includes(name)) {\n throw new Error(\n `loadbare: page '${page}' refreshes '${name}' after its own ` +\n `${request}; return the changed rows in a patch instead`,\n );\n }\n }\n }\n }\n\n /**\n * Answers into response items, adding the kind and key each query\n * declared. An answer that disagrees with its declaration is a mistake in\n * the application rather than a case to handle, and is left out: a page is\n * better off missing one query than showing the wrong shape for it.\n *\n * A page load also adds each `rows` query's order and column types, which\n * the hub keeps for the answers after it.\n */\n function items(page: string, data: HubData, load = false): HubResponse {\n const out: ResponseItem[] = [];\n for (const [name, result] of Object.entries(data)) {\n const query = pages[page]?.queries[name];\n if (!query) {\n console.warn(`loadbare: page '${page}' declares no query '${name}'`);\n continue;\n }\n const item: ResponseItem = {\n query: name,\n kind: query.kind,\n key: query.key,\n };\n if (query.kind === KIND_ROW) {\n if (Array.isArray(result) || patches.has(result)) {\n console.warn(\n `loadbare: query '${name}' is declared row but answered with ` +\n `${Array.isArray(result) ? \"rows\" : \"a patch\"}`,\n );\n continue;\n }\n item.row = result as Row;\n } else {\n if (Array.isArray(result)) item.rows = result;\n else item.patch = result as Patch;\n if (load && query.order !== undefined) item.order = query.order;\n if (load && query.types !== undefined) item.types = query.types;\n }\n out.push(item);\n }\n return out;\n }\n\n /** Run queries by name, each answering with all its rows or its row. */\n async function run(\n page: string,\n names: string[],\n ctx: HubContext,\n ): Promise<HubData> {\n const data: HubData = {};\n for (const name of names) {\n const query = pages[page]?.queries[name];\n if (!query) {\n console.warn(`loadbare: page '${page}' declares no query '${name}'`);\n continue;\n }\n const result = await query.run(ctx);\n if (Array.isArray(result) !== (query.kind === KIND_ROWS)) {\n console.warn(\n `loadbare: query '${name}' is declared ${query.kind} but answered ` +\n `with ${Array.isArray(result) ? \"rows\" : \"one row\"}`,\n );\n continue;\n }\n data[name] = result;\n }\n return data;\n }\n\n /**\n * Run a handler, then its refresh set against the same context, laying\n * what the handler itself returned over the refreshed queries — the\n * narrower answer wins because it knows what actually changed.\n *\n * A handler that returned `url()` answers with the `lb-url` item alone.\n * Loading the page there needs a context built at the new URL, and\n * building one is the caller's.\n */\n async function settle(\n page: string,\n handler: Handler<never> | undefined,\n request: RequestFields,\n ctx: HubContext,\n notFound: string,\n ): Promise<HubResponse> {\n if (!handler) {\n console.warn(notFound);\n return [];\n }\n const { [URL_QUERY]: moved, ...stated } =\n (await handler.run(ctx, request as never)) ?? {};\n const item = urlItem(page, moved);\n if (item) return [item];\n return items(page, {\n ...(await run(page, handler.refresh, ctx)),\n ...stated,\n });\n }\n\n /**\n * An update or a delete for several rows: the page's `crud` entry runs once\n * per key, as it would for each row alone, so an application writes\n * nothing more to allow it. What each run returns is laid together, a\n * patch onto a patch, and the refresh set runs once.\n *\n * A run that returns `url()` is reported and its row ignored: a URL names\n * one view, and several rows cannot each choose it.\n */\n async function eachKey(\n page: string,\n name: string,\n fields: RequestFields,\n ctx: HubContext,\n ): Promise<HubResponse> {\n const { keys, ...one } = fields;\n const query = fields.query ?? \"\";\n const handler = pages[page]?.requests.crud?.[query]?.[CRUD_KEYS[name]!] as\n | Handler<never>\n | undefined;\n if (!handler) {\n console.warn(\n `loadbare: page '${page}' declares no ${CRUD_KEYS[name]} for '${query}'`,\n );\n return [];\n }\n if (!Array.isArray(keys) || keys.some((key) => typeof key !== \"string\")) {\n console.warn(`loadbare: '${name}' carries keys that are not strings`);\n return [];\n }\n let stated: HubData = {};\n for (const key of keys) {\n const { [URL_QUERY]: moved, ...answer } =\n (await handler.run(ctx, { ...one, key } as never)) ?? {};\n if (moved !== undefined) {\n console.warn(\n `loadbare: ${CRUD_KEYS[name]} for '${query}' returned url() for ` +\n `one of several rows, ignoring it`,\n );\n }\n stated = layered(stated, answer);\n }\n return items(page, {\n ...(await run(page, handler.refresh, ctx)),\n ...stated,\n });\n }\n\n return {\n async dataForPage(page, ctx, { follow = true, parms } = {}) {\n const entry = pages[page];\n if (!entry) {\n console.warn(`loadbare: no page '${page}'`);\n return [];\n }\n const {\n [URL_QUERY]: moved,\n [CHOICES_QUERY]: chose,\n ...stated\n } = (await entry.requests.onPageEnter?.(ctx)) ?? {};\n if (Object.keys(stated).length > 0) {\n console.warn(\n `loadbare: page '${page}' onPageEnter returned answers; it returns ` +\n `url(), choices() or nothing, ignoring them`,\n );\n }\n const item = follow ? urlItem(page, moved) : undefined;\n if (item && !(parms && leadsHere(page, parms, item.row!))) return [item];\n // The choices go first, so the rows that read them land by them.\n return [\n ...choicesItem(page, chose),\n ...items(page, await run(page, Object.keys(entry.queries), ctx), true),\n ];\n },\n\n runRequest(page, request, ctx) {\n const { name, ...fields } = request;\n if (fields.rows !== undefined && !wellFormedRows(fields.rows)) {\n console.warn(\n `loadbare: '${name}' carries rows that are not keys and string ` +\n `values by query, ignoring it`,\n );\n return Promise.resolve([]);\n }\n // The user's choices, told to the page. One with no `onChoices` is\n // not keeping them, and is not told.\n if (fields.query === CHOICES_QUERY) {\n const onChoices = pages[page]?.requests.onChoices;\n if (name !== REQUEST_ROW_UPDATE || !onChoices) {\n return Promise.resolve([]);\n }\n return settle(\n page,\n {\n run: (c: HubContext, r: RequestFields) =>\n onChoices(c, r.values ?? {}),\n refresh: [],\n } as Handler<never>,\n fields,\n ctx,\n \"\",\n );\n }\n if (\n fields.keys !== undefined &&\n (name === REQUEST_ROW_UPDATE || name === REQUEST_ROW_DELETE)\n ) {\n return eachKey(page, name, fields, ctx);\n }\n if (isRowRequest(name)) {\n const query = fields.query ?? \"\";\n return settle(\n page,\n pages[page]?.requests.crud?.[query]?.[CRUD_KEYS[name]!] as\n Handler<never> | undefined,\n fields,\n ctx,\n `loadbare: page '${page}' declares no ${CRUD_KEYS[name]} for '${query}'`,\n );\n }\n return settle(\n page,\n pages[page]?.requests.handlers?.[name] as Handler<never> | undefined,\n fields,\n ctx,\n `loadbare: page '${page}' declares no request '${name}'`,\n );\n },\n };\n}\n\n/** Gathered rows as the hub sends them: string keys and string values. */\nfunction wellFormedRows(rows: unknown): boolean {\n if (typeof rows !== \"object\" || rows === null || Array.isArray(rows)) {\n return false;\n }\n return Object.values(rows).every(\n (set) =>\n Array.isArray(set) &&\n set.every(\n (row) =>\n typeof row === \"object\" &&\n row !== null &&\n typeof row.key === \"string\" &&\n typeof row.values === \"object\" &&\n row.values !== null &&\n Object.values(row.values).every((v) => typeof v === \"string\"),\n ),\n );\n}\n\n/**\n * Two answers as one: a patch laid onto a patch for the same query keeps\n * what both name, and any other answer replaces the one before it.\n */\nfunction layered(before: HubData, after: HubData): HubData {\n const out: HubData = { ...before };\n for (const [name, answer] of Object.entries(after)) {\n const was = out[name];\n if (was && patches.has(was) && patches.has(answer)) {\n const a = was as Patch;\n const b = answer as Patch;\n out[name] = patch({\n rows: [...(a.rows ?? []), ...(b.rows ?? [])],\n drop: [...(a.drop ?? []), ...(b.drop ?? [])],\n });\n } else {\n out[name] = answer;\n }\n }\n return out;\n}\n\n/**\n * The `lb-url` item for a row a handler or `onPageEnter` returned, or\n * nothing when it returned none or one that cannot be used. Whatever\n * returned it has already run, so a row that cannot be used is reported and\n * the call goes on as if none had been returned.\n */\nfunction urlItem(page: string, moved: unknown): ResponseItem | undefined {\n if (moved === undefined) return undefined;\n const refused = unusableUrl(moved);\n if (refused === undefined) {\n return {\n query: URL_QUERY,\n kind: KIND_ROW,\n key: URL_COLUMN_PATH,\n row: moved as Row,\n };\n }\n console.warn(\n `loadbare: page '${page}' returned ${URL_QUERY} ${refused}, ignoring it`,\n );\n return undefined;\n}\n\n/**\n * The `lb-choices` item for the choices `onPageEnter` returned, or nothing\n * when it returned none or ones that cannot be used, which are reported.\n */\nfunction choicesItem(page: string, chose: unknown): ResponseItem[] {\n if (chose === undefined) return [];\n const refused = unusableUrl(chose);\n if (refused !== undefined) {\n console.warn(\n `loadbare: page '${page}' returned ${CHOICES_QUERY} ${refused}, ` +\n `ignoring it`,\n );\n return [];\n }\n return [\n {\n query: CHOICES_QUERY,\n kind: KIND_ROW,\n key: URL_COLUMN_PATH,\n row: chose as Row,\n },\n ];\n}\n\n/** Whether a row for `lb-url` leads to the page and parms already in hand. */\nfunction leadsHere(page: string, parms: URLSearchParams, row: Row): boolean {\n const next = nextLocation(page, parms, row);\n return next.page === page && next.parms.toString() === parms.toString();\n}\n\n/**\n * Why a returned row for `lb-url` or `lb-choices` cannot be used, or nothing\n * when it can.\n *\n * A value is a string, as a control's is and a URL's is. At least one column\n * is named: a row naming none changes nothing.\n */\nfunction unusableUrl(columns: unknown): string | undefined {\n if (\n typeof columns !== \"object\" ||\n columns === null ||\n Array.isArray(columns)\n ) {\n return \"that is not a row\";\n }\n const values = Object.values(columns);\n if (values.length === 0) return \"naming no column\";\n if (!values.every((v) => typeof v === \"string\")) {\n return `holding a value that is not a string; write each value as \"...\"`;\n }\n return undefined;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"lb-server.js","sourceRoot":"","sources":["../../server/lb-server.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,EAAE;AACF,oEAAoE;AACpE,4EAA4E;AAC5E,4EAA4E;AAC5E,gDAAgD;AAgBhD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAC7E,OAAO,EACL,aAAa,EACb,YAAY,EACZ,QAAQ,EACR,SAAS,EACT,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,eAAe,EACf,SAAS,GACV,MAAM,yBAAyB,CAAC;AAgEjC;;;GAGG;AACH,MAAM,UAAU,GAAG,CACjB,GAAW,EACX,GAA0D;IAE1D,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;AACtC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,IAAI,CAClB,GAAW,EACX,GAAgD,EAChD,UAAuB,EAAE;IAEzB,OAAO;QACL,IAAI,EAAE,SAAS;QACf,GAAG;QACH,GAAG;QACH,GAAG,CAAC,OAAO,CAAC,KAAK,KAAK,SAAS,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC;QAC5D,GAAG,CAAC,OAAO,CAAC,KAAK,KAAK,SAAS,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC;KAC7D,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,KAAK,CAAC,MAA0C;IAC9D,MAAM,IAAI,GAAG,EAAE,GAAG,MAAM,EAAE,CAAC;IAC3B,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAClB,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;GAGG;AACH,MAAM,OAAO,GAA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8E;AAC9E,SAAS,SAAS,CAAC,IAAY,EAAE,KAAsB,EAAE,GAAQ;IAC/D,MAAM,IAAI,GAAG,YAAY,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;IAC5C,OAAO,IAAI,CAAC,IAAI,KAAK,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,KAAK,CAAC,QAAQ,EAAE,CAAC;AAC1E,CAAC;AAED;;;;;;GAMG;AACH,SAAS,WAAW,CAAC,OAAgB;IACnC,IACE,OAAO,OAAO,KAAK,QAAQ;QAC3B,OAAO,KAAK,IAAI;QAChB,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EACtB,CAAC;QACD,OAAO,mBAAmB,CAAC;IAC7B,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACtC,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,kBAAkB,CAAC;IACnD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,EAAE,CAAC;QAChD,OAAO,iEAAiE,CAAC;IAC3E,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["// The server-side contract and the engine that runs it.\n//\n// This is the counterpart to core/lb-constants.ts: that file is the\n// vocabulary the browser writes, this one is the vocabulary the application\n// writes. The engine below is the whole of Loadbare on the server. It ships\n// no HTTP server, no router, and no data layer.\n\nimport type {\n ColumnTypes,\n HubData,\n HubRequest,\n HubResponse,\n HubResult,\n Kind,\n GatheredRow,\n HubRefusal,\n Patch,\n RequestFields,\n ResponseItem,\n Row,\n} from \"../core/lb-types.js\";\nimport { isRowRequest, nextLocation, parseOrder } from \"../core/lb-types.js\";\nimport {\n CHOICES_QUERY,\n COLUMN_TYPES,\n KIND_ROW,\n KIND_ROWS,\n LB_RESERVED_PREFIX,\n REQUEST_ROW_DELETE,\n REQUEST_ROW_INSERT,\n REQUEST_ROW_UPDATE,\n URL_COLUMN_PATH,\n URL_QUERY,\n} from \"../core/lb-constants.js\";\n\n/**\n * Whatever the application hands the engine for the duration of one request.\n *\n * Loadbare declares it empty and never reads it. An application fills it in\n * by declaration merging, once, anywhere in its own source:\n *\n * declare module \"@loadbare/app/server\" {\n * interface HubContext {\n * db: Db;\n * }\n * }\n *\n * That is why no type on this page takes a type parameter. The context is a\n * request-scoped handle — an authenticated database connection is the\n * expected case — so it is passed per call rather than held by the engine.\n * The page's query parms are the other expected member: a query that reads\n * one off the context takes no argument, and re-runs under `refresh` like\n * any other.\n */\nexport interface HubContext {}\n\n/**\n * A declared query: its kind, its key, and the run that answers it.\n *\n * Kind and key are properties of the name rather than of any one answer, so\n * they are declared here and never inferred from what comes back. The engine\n * sends both with every answer, so the markup repeats neither. Every query\n * has a key; an aggregate row answers with a constant one.\n *\n * Write one with `row()` or `rows()` below; nothing else builds one.\n */\nexport interface Query {\n readonly kind: Kind;\n readonly key: string;\n readonly run: (ctx: HubContext) => HubResult | Promise<HubResult>;\n /** A `rows` query's order, as `rows()` declared it. */\n readonly order?: string;\n /** A `rows` query's column types, as `rows()` declared them. */\n readonly types?: ColumnTypes;\n}\n\n/**\n * What a `rows` query declares about its order.\n *\n * `order` is the order the hub places its rows by: columns separated by\n * commas, each descending when it begins with `-`, as in\n * `category_order,-opened`. An order the user chose, held in `lb-choices`,\n * replaces it. With neither, rows show in the order the query answered them\n * in.\n *\n * `types` names a type for any of its columns, and the hub sorts, filters\n * and takes `lb-min` and `lb-max` of that column read as its type rather\n * than by the JSON type its values arrive as: `{ amount: \"number\" }` for a\n * Postgres `numeric` that arrives as a string. A column it does not name\n * compares by its JSON type. The order and the types go to the browser\n * once, with the answer that loads the page.\n */\nexport interface RowsOptions {\n order?: string;\n types?: ColumnTypes;\n}\n\n/**\n * A query that answers with one row, identified by its `key` column, or with\n * `null` when there is none.\n */\nexport function row(\n key: string,\n run: (ctx: HubContext) => Row | null | Promise<Row | null>,\n): Query {\n return { kind: KIND_ROW, key, run };\n}\n\n/**\n * A query that answers with all its rows. Rows land by their `key` column: a\n * row whose key is not in the answer is gone. The hub places them by the\n * order in `options`, or in the order they arrived when there is none.\n */\nexport function rows(\n key: string,\n run: (ctx: HubContext) => Row[] | Promise<Row[]>,\n options: RowsOptions = {},\n): Query {\n return {\n kind: KIND_ROWS,\n key,\n run,\n ...(options.order !== undefined && { order: options.order }),\n ...(options.types !== undefined && { types: options.types }),\n };\n}\n\n/**\n * Only what changed, returned from a handler for a `rows` query. Rows named\n * here are added or updated, keys in `drop` are removed, and everything\n * unnamed is left alone — its contents, and its place in whatever order the\n * page is keeping.\n *\n * `Array.isArray` is what tells a patch from all rows, so a patch needs no\n * marker of its own and no column name is reserved to carry one.\n */\nexport function patch(change: { rows?: Row[]; drop?: unknown[] }): Patch {\n const made = { ...change };\n patches.add(made);\n return made;\n}\n\n/**\n * Every object `patch()` made. A patch and a row are both plain objects, so\n * this is how the engine refuses a patch answering a `row` query.\n */\nconst patches = new WeakSet<object>();\n\n/**\n * A new row for `lb-url`, returned from a handler when only the handler can\n * know where the page belongs: the key of a row it inserted, or the absence\n * of one it deleted.\n *\n * A column other than `lb-path` is a query parm: set, or taken out when its\n * value is empty. With `lb-path` naming another page, the page is entered\n * with only the parms named here; otherwise every other parm is kept.\n *\n * The page then loads at the new URL in the same round trip, as a cold load\n * of it would, so the refresh set is not run and whatever else the handler\n * returned is dropped: both were answers for the URL the page is leaving.\n * This is Post/Redirect/Get without the redirect.\n */\nexport function url(columns: Record<string, string>): HubData {\n return { [URL_QUERY]: { ...columns } };\n}\n\n/**\n * The user's choices for the page, returned from `onPageEnter` to restore\n * what the user last chose: an order, a filter. Each column is a column of\n * `lb-choices`, and the hub places the page's rows by them as they land.\n * Return it beside `url()` with the spread both are written for:\n *\n * return { ...url({ acct: \"23\" }), ...choices({ sort: \"-amount\" }) };\n */\nexport function choices(columns: Record<string, string>): HubData {\n return { [CHOICES_QUERY]: { ...columns } };\n}\n\n/**\n * A handler's refusal: thrown, and answered to the browser with the words\n * it carries. Every other error a handler throws reaches the browser as a\n * failure with nothing in it.\n */\nexport class Refusal extends Error {\n readonly refusal: HubRefusal;\n\n constructor(refusal: HubRefusal) {\n super(refusal.message ?? \"refused\");\n this.name = \"Refusal\";\n this.refusal = refusal;\n }\n}\n\n/**\n * Refuse a request, in words written for the user. Throw what it returns:\n *\n * throw refusal(\"That series already has paychecks entered.\");\n * throw refusal({ amount: \"Must be more than zero\" });\n * throw refusal(\"Two fields need attention.\", { amount: \"…\" });\n *\n * A message alone is for the request as a whole; columns name the controls\n * the request gathered, and each message is shown on its control. Thrown\n * rather than returned, so a refusal can come from anywhere the handler\n * calls, and whatever the application has open rolls back as for any\n * throw.\n */\nexport function refusal(\n message: string | Record<string, string>,\n columns?: Record<string, string>,\n): Refusal {\n return typeof message === \"string\"\n ? new Refusal({ message, ...(columns && { columns }) })\n : new Refusal({ columns: message });\n}\n\n/** The shape of a `<stub>.queries.ts` module. */\nexport type Queries = Record<string, Query>;\n\n/**\n * What a handler does, and which queries re-run once it has.\n *\n * `run` may also return answers of its own, which are laid over the\n * refreshed ones. That is how a patch reaches the browser: a query answers\n * for all its rows and cannot know why it re-ran, but the handler knows\n * exactly what it changed and can say only that.\n */\nexport interface Handler<R = RequestFields> {\n run: (\n ctx: HubContext,\n request: R,\n ) => void | HubData | Promise<void | HubData>;\n refresh: string[];\n}\n\n/**\n * `rows` holds the rows of the queries nested in the form the request came\n * from, by query name, each with its own values: a master's details,\n * written with it.\n */\nexport type RowInsertHandler = Handler<{\n key?: string;\n values: Record<string, string>;\n rows?: Record<string, GatheredRow[]>;\n}>;\n/** `values` holds only the columns being set, as an SQL UPDATE sets them. */\nexport type RowUpdateHandler = Handler<{\n key: string;\n values: Record<string, string>;\n rows?: Record<string, GatheredRow[]>;\n}>;\nexport type RowDeleteHandler = Handler<{ key: string }>;\n\n/**\n * What the requests Loadbare provides do to one query, keyed by its name in\n * `Requests.crud`. A query with no entry here permits none of them: the wire\n * cannot reach anything the page has not published.\n *\n * Every key is the request name with the prefix stripped and the rest\n * camel-cased: `lb-row-insert` runs `rowInsert`.\n */\nexport interface Crud {\n rowInsert?: RowInsertHandler;\n rowUpdate?: RowUpdateHandler;\n rowDelete?: RowDeleteHandler;\n}\n\n/**\n * The shape of a `<stub>.requests.ts` module.\n *\n * `onPageEnter` runs when the page loads, before its queries. It declares no\n * refresh set: the page's queries all run afterward, so whatever it changed\n * is already in the response. It may return `url()` instead, to move the\n * page to other query parms or another page before anything shows, as an\n * application restoring what the user last had on screen does. The page\n * then loads there in the same round trip, and `onPageEnter` running for\n * that load is not followed again. It may return `choices()`, with `url()`\n * or alone, to restore the user's choices for the page.\n *\n * `onChoices` runs each time the user makes a choice, with every choice\n * made on the page, so an application can keep them for `onPageEnter` to\n * restore. It answers with nothing, by convention.\n *\n * `handlers` holds the page's declared requests, by name. A name the page\n * did not declare is refused, so the wire cannot reach anything the page has\n * not published.\n *\n * `crud` holds what the requests Loadbare provides run, by query name.\n */\nexport interface Requests {\n onPageEnter?: (ctx: HubContext) => void | HubData | Promise<void | HubData>;\n onChoices?: (\n ctx: HubContext,\n choices: Record<string, string>,\n ) => void | HubData | Promise<void | HubData>;\n handlers?: Record<string, Handler>;\n crud?: Record<string, Crud>;\n}\n\n/** A page is three files sharing a stub; two of them are these. */\nexport interface Page {\n queries: Queries;\n requests: Requests;\n}\n\n/**\n * The page registry. The builder writes it from every `.requests.ts` and\n * `.queries.ts` it discovers — see docs/reference/builder.md.\n */\nexport type Pages = Record<string, Page>;\n\n/**\n * How a page load treats a `url()` its `onPageEnter` returned.\n *\n * With `follow` false it is ignored and the queries run, as they must for a\n * load that is itself at a URL something else moved to. With `parms`, the\n * query parms the page is being loaded at, one that leads to the page and\n * parms already in hand is ignored the same way, so the page loads once.\n */\nexport interface PageLoadOptions {\n follow?: boolean;\n parms?: URLSearchParams;\n}\n\n/**\n * The engine. Both calls answer with response items. A request whose\n * handler returned `url()`, and a page load whose `onPageEnter` did, answer\n * with the `lb-url` item alone: the caller builds a context at the new URL,\n * calls `dataForPage` with it and `follow` false, and sends the load beside the\n * item. `hubRoutes` does exactly that.\n */\nexport interface Hub {\n /** A page load: its `onPageEnter`, then all of its queries. */\n dataForPage(\n page: string,\n ctx: HubContext,\n options?: PageLoadOptions,\n ): Promise<HubResponse>;\n\n /** A request: run the handler its name picks, then the refresh set. */\n runRequest(\n page: string,\n request: HubRequest,\n ctx: HubContext,\n ): Promise<HubResponse>;\n}\n\n/** The camel-cased `Crud` key of a request Loadbare provides. */\nconst CRUD_KEYS: Record<string, keyof Crud> = {\n [REQUEST_ROW_INSERT]: \"rowInsert\",\n [REQUEST_ROW_UPDATE]: \"rowUpdate\",\n [REQUEST_ROW_DELETE]: \"rowDelete\",\n};\n\n/**\n * Build the engine over a set of pages. The pages are fixed at startup; the\n * context is not, and arrives with each call.\n */\nexport function createHub(pages: Pages): Hub {\n // Names beginning with the reserved prefix are Loadbare's — its own query,\n // the requests it provides — so an application cannot declare one.\n // Refused at startup, because a name is a fact about the page and not\n // about any request.\n for (const [page, entry] of Object.entries(pages)) {\n const declared = [\n ...Object.keys(entry.queries),\n ...Object.keys(entry.requests.handlers ?? {}),\n ...Object.keys(entry.requests.crud ?? {}),\n ];\n for (const name of declared) {\n if (name.startsWith(LB_RESERVED_PREFIX)) {\n throw new Error(\n `loadbare: page '${page}' declares '${name}', but names ` +\n `beginning with '${LB_RESERVED_PREFIX}' are reserved`,\n );\n }\n }\n\n // A crud handler always knows which rows it changed: an update or a\n // delete names its row by key, and an insert has the new row's key once\n // it has written it. So each can answer with a patch, and the hub places\n // what the patch names by the query's order. Refreshing the whole set\n // instead sends every row to say one thing. There is no case where that\n // is the answer, so it is refused rather than warned about.\n // An order is a fact about the query, so a malformed one is refused at\n // startup, as a reserved name is.\n // So is a column type the hub does not know.\n for (const [name, query] of Object.entries(entry.queries)) {\n for (const [column, type] of Object.entries(query.types ?? {})) {\n if (!(COLUMN_TYPES as readonly string[]).includes(type)) {\n throw new Error(\n `loadbare: page '${page}' query '${name}' declares column ` +\n `'${column}' as '${type}'; a column type is one of ` +\n `${COLUMN_TYPES.join(\", \")}`,\n );\n }\n }\n if (query.order === undefined) continue;\n try {\n parseOrder(query.order);\n } catch (err) {\n throw new Error(\n `loadbare: page '${page}' query '${name}': ${(err as Error).message}`,\n );\n }\n }\n\n for (const [name, crud] of Object.entries(entry.requests.crud ?? {})) {\n if (entry.queries[name]?.kind !== KIND_ROWS) continue;\n for (const request of [\"rowInsert\", \"rowUpdate\", \"rowDelete\"] as const) {\n if (crud[request]?.refresh.includes(name)) {\n throw new Error(\n `loadbare: page '${page}' refreshes '${name}' after its own ` +\n `${request}; return the changed rows in a patch instead`,\n );\n }\n }\n }\n }\n\n /**\n * Answers into response items, adding the kind and key each query\n * declared. An answer that disagrees with its declaration is a mistake in\n * the application rather than a case to handle, and is left out: a page is\n * better off missing one query than showing the wrong shape for it.\n *\n * A page load also adds each `rows` query's order and column types, which\n * the hub keeps for the answers after it.\n */\n function items(page: string, data: HubData, load = false): HubResponse {\n const out: ResponseItem[] = [];\n for (const [name, result] of Object.entries(data)) {\n const query = pages[page]?.queries[name];\n if (!query) {\n console.warn(`loadbare: page '${page}' declares no query '${name}'`);\n continue;\n }\n const item: ResponseItem = {\n query: name,\n kind: query.kind,\n key: query.key,\n };\n if (query.kind === KIND_ROW) {\n if (Array.isArray(result) || patches.has(result as object)) {\n console.warn(\n `loadbare: query '${name}' is declared row but answered with ` +\n `${Array.isArray(result) ? \"rows\" : \"a patch\"}`,\n );\n continue;\n }\n // No row reaches the browser as null, which JSON keeps and\n // undefined it would drop.\n item.row = (result ?? null) as Row | null;\n } else {\n if (result === null || result === undefined) {\n console.warn(\n `loadbare: query '${name}' is declared rows but answered with nothing`,\n );\n continue;\n }\n if (Array.isArray(result)) item.rows = result;\n else item.patch = result as Patch;\n if (load && query.order !== undefined) item.order = query.order;\n if (load && query.types !== undefined) item.types = query.types;\n }\n out.push(item);\n }\n return out;\n }\n\n /** Run queries by name, each answering with all its rows or its row. */\n async function run(\n page: string,\n names: string[],\n ctx: HubContext,\n ): Promise<HubData> {\n const data: HubData = {};\n for (const name of names) {\n const query = pages[page]?.queries[name];\n if (!query) {\n console.warn(`loadbare: page '${page}' declares no query '${name}'`);\n continue;\n }\n const result = await query.run(ctx);\n if (Array.isArray(result) !== (query.kind === KIND_ROWS)) {\n console.warn(\n `loadbare: query '${name}' is declared ${query.kind} but answered ` +\n `with ${Array.isArray(result) ? \"rows\" : result == null ? \"nothing\" : \"one row\"}`,\n );\n continue;\n }\n data[name] = result;\n }\n return data;\n }\n\n /**\n * Run a handler, then its refresh set against the same context, laying\n * what the handler itself returned over the refreshed queries — the\n * narrower answer wins because it knows what actually changed.\n *\n * A handler that returned `url()` answers with the `lb-url` item alone.\n * Loading the page there needs a context built at the new URL, and\n * building one is the caller's.\n */\n async function settle(\n page: string,\n handler: Handler<never> | undefined,\n request: RequestFields,\n ctx: HubContext,\n notFound: string,\n ): Promise<HubResponse> {\n if (!handler) {\n console.warn(notFound);\n return [];\n }\n const { [URL_QUERY]: moved, ...stated } =\n (await handler.run(ctx, request as never)) ?? {};\n const item = urlItem(page, moved);\n if (item) return [item];\n return items(page, {\n ...(await run(page, handler.refresh, ctx)),\n ...stated,\n });\n }\n\n /**\n * An update or a delete for several rows: the page's `crud` entry runs once\n * per key, as it would for each row alone, so an application writes\n * nothing more to allow it. What each run returns is laid together, a\n * patch onto a patch, and the refresh set runs once.\n *\n * A run that returns `url()` is reported and its row ignored: a URL names\n * one view, and several rows cannot each choose it.\n */\n async function eachKey(\n page: string,\n name: string,\n fields: RequestFields,\n ctx: HubContext,\n ): Promise<HubResponse> {\n const { keys, ...one } = fields;\n const query = fields.query ?? \"\";\n const handler = pages[page]?.requests.crud?.[query]?.[CRUD_KEYS[name]!] as\n | Handler<never>\n | undefined;\n if (!handler) {\n console.warn(\n `loadbare: page '${page}' declares no ${CRUD_KEYS[name]} for '${query}'`,\n );\n return [];\n }\n if (!Array.isArray(keys) || keys.some((key) => typeof key !== \"string\")) {\n console.warn(`loadbare: '${name}' carries keys that are not strings`);\n return [];\n }\n let stated: HubData = {};\n for (const key of keys) {\n const { [URL_QUERY]: moved, ...answer } =\n (await handler.run(ctx, { ...one, key } as never)) ?? {};\n if (moved !== undefined) {\n console.warn(\n `loadbare: ${CRUD_KEYS[name]} for '${query}' returned url() for ` +\n `one of several rows, ignoring it`,\n );\n }\n stated = layered(stated, answer);\n }\n return items(page, {\n ...(await run(page, handler.refresh, ctx)),\n ...stated,\n });\n }\n\n return {\n async dataForPage(page, ctx, { follow = true, parms } = {}) {\n const entry = pages[page];\n if (!entry) {\n console.warn(`loadbare: no page '${page}'`);\n return [];\n }\n const {\n [URL_QUERY]: moved,\n [CHOICES_QUERY]: chose,\n ...stated\n } = (await entry.requests.onPageEnter?.(ctx)) ?? {};\n if (Object.keys(stated).length > 0) {\n console.warn(\n `loadbare: page '${page}' onPageEnter returned answers; it returns ` +\n `url(), choices() or nothing, ignoring them`,\n );\n }\n const item = follow ? urlItem(page, moved) : undefined;\n if (item && !(parms && leadsHere(page, parms, item.row!))) return [item];\n // The choices go first, so the rows that read them land by them.\n return [\n ...choicesItem(page, chose),\n ...items(page, await run(page, Object.keys(entry.queries), ctx), true),\n ];\n },\n\n runRequest(page, request, ctx) {\n const { name, ...fields } = request;\n if (fields.rows !== undefined && !wellFormedRows(fields.rows)) {\n console.warn(\n `loadbare: '${name}' carries rows that are not keys and string ` +\n `values by query, ignoring it`,\n );\n return Promise.resolve([]);\n }\n // The user's choices, told to the page. One with no `onChoices` is\n // not keeping them, and is not told.\n if (fields.query === CHOICES_QUERY) {\n const onChoices = pages[page]?.requests.onChoices;\n if (name !== REQUEST_ROW_UPDATE || !onChoices) {\n return Promise.resolve([]);\n }\n return settle(\n page,\n {\n run: (c: HubContext, r: RequestFields) =>\n onChoices(c, r.values ?? {}),\n refresh: [],\n } as Handler<never>,\n fields,\n ctx,\n \"\",\n );\n }\n if (\n fields.keys !== undefined &&\n (name === REQUEST_ROW_UPDATE || name === REQUEST_ROW_DELETE)\n ) {\n return eachKey(page, name, fields, ctx);\n }\n if (isRowRequest(name)) {\n const query = fields.query ?? \"\";\n return settle(\n page,\n pages[page]?.requests.crud?.[query]?.[CRUD_KEYS[name]!] as\n Handler<never> | undefined,\n fields,\n ctx,\n `loadbare: page '${page}' declares no ${CRUD_KEYS[name]} for '${query}'`,\n );\n }\n return settle(\n page,\n pages[page]?.requests.handlers?.[name] as Handler<never> | undefined,\n fields,\n ctx,\n `loadbare: page '${page}' declares no request '${name}'`,\n );\n },\n };\n}\n\n/** Gathered rows as the hub sends them: string keys and string values. */\nfunction wellFormedRows(rows: unknown): boolean {\n if (typeof rows !== \"object\" || rows === null || Array.isArray(rows)) {\n return false;\n }\n return Object.values(rows).every(\n (set) =>\n Array.isArray(set) &&\n set.every(\n (row) =>\n typeof row === \"object\" &&\n row !== null &&\n typeof row.key === \"string\" &&\n typeof row.values === \"object\" &&\n row.values !== null &&\n Object.values(row.values).every((v) => typeof v === \"string\"),\n ),\n );\n}\n\n/**\n * Two answers as one: a patch laid onto a patch for the same query keeps\n * what both name, and any other answer replaces the one before it.\n */\nfunction layered(before: HubData, after: HubData): HubData {\n const out: HubData = { ...before };\n for (const [name, answer] of Object.entries(after)) {\n const was = out[name];\n if (was && patches.has(was) && patches.has(answer as object)) {\n const a = was as Patch;\n const b = answer as Patch;\n out[name] = patch({\n rows: [...(a.rows ?? []), ...(b.rows ?? [])],\n drop: [...(a.drop ?? []), ...(b.drop ?? [])],\n });\n } else {\n out[name] = answer;\n }\n }\n return out;\n}\n\n/**\n * The `lb-url` item for a row a handler or `onPageEnter` returned, or\n * nothing when it returned none or one that cannot be used. Whatever\n * returned it has already run, so a row that cannot be used is reported and\n * the call goes on as if none had been returned.\n */\nfunction urlItem(page: string, moved: unknown): ResponseItem | undefined {\n if (moved === undefined) return undefined;\n const refused = unusableUrl(moved);\n if (refused === undefined) {\n return {\n query: URL_QUERY,\n kind: KIND_ROW,\n key: URL_COLUMN_PATH,\n row: moved as Row,\n };\n }\n console.warn(\n `loadbare: page '${page}' returned ${URL_QUERY} ${refused}, ignoring it`,\n );\n return undefined;\n}\n\n/**\n * The `lb-choices` item for the choices `onPageEnter` returned, or nothing\n * when it returned none or ones that cannot be used, which are reported.\n */\nfunction choicesItem(page: string, chose: unknown): ResponseItem[] {\n if (chose === undefined) return [];\n const refused = unusableUrl(chose);\n if (refused !== undefined) {\n console.warn(\n `loadbare: page '${page}' returned ${CHOICES_QUERY} ${refused}, ` +\n `ignoring it`,\n );\n return [];\n }\n return [\n {\n query: CHOICES_QUERY,\n kind: KIND_ROW,\n key: URL_COLUMN_PATH,\n row: chose as Row,\n },\n ];\n}\n\n/** Whether a row for `lb-url` leads to the page and parms already in hand. */\nfunction leadsHere(page: string, parms: URLSearchParams, row: Row): boolean {\n const next = nextLocation(page, parms, row);\n return next.page === page && next.parms.toString() === parms.toString();\n}\n\n/**\n * Why a returned row for `lb-url` or `lb-choices` cannot be used, or nothing\n * when it can.\n *\n * A value is a string, as a control's is and a URL's is. At least one column\n * is named: a row naming none changes nothing.\n */\nfunction unusableUrl(columns: unknown): string | undefined {\n if (\n typeof columns !== \"object\" ||\n columns === null ||\n Array.isArray(columns)\n ) {\n return \"that is not a row\";\n }\n const values = Object.values(columns);\n if (values.length === 0) return \"naming no column\";\n if (!values.every((v) => typeof v === \"string\")) {\n return `holding a value that is not a string; write each value as \"...\"`;\n }\n return undefined;\n}\n"]}
|
package/docs/TECHREF-1.0.md
CHANGED
|
@@ -13,42 +13,6 @@ that they can be decided later w/o breaking changes, then we rename
|
|
|
13
13
|
them to "Out of Scope" or move them to the roadmap. Otherwise,
|
|
14
14
|
they must be resolved before we declare 1.0.
|
|
15
15
|
|
|
16
|
-
### Data types
|
|
17
|
-
|
|
18
|
-
Loadbare/app enforces no data types on values between the database and the
|
|
19
|
-
browser. A uniform and useful approach is difficult to discern, and we do
|
|
20
|
-
not want to pollute 1.0 with a potentially sub-optimal solution. Until then
|
|
21
|
-
a value is rendered by browser coercion when it lands on an HTML text
|
|
22
|
-
element or a control, and by whatever the custom element does with
|
|
23
|
-
`lb-column-value` when it lands on one that is not a control.
|
|
24
|
-
|
|
25
|
-
Three places read a value's type today. The [order](#order) compares
|
|
26
|
-
values by their JSON type, a [filter](#filters) reads its value as the
|
|
27
|
-
column's type, and an [aggregate](#aggregates) reads a sum or an average
|
|
28
|
-
from a JSON number or a string holding a plain decimal. A `rows` query may
|
|
29
|
-
declare a column's type, which the order, a filter, `lb-min` and `lb-max`
|
|
30
|
-
read the column as in place of its JSON type. No declared type changes how
|
|
31
|
-
a value renders.
|
|
32
|
-
|
|
33
|
-
We will then see if a useful solution emerges that Loadbare/app should
|
|
34
|
-
handle.
|
|
35
|
-
|
|
36
|
-
### Form controls
|
|
37
|
-
|
|
38
|
-
- **Radio buttons are not implemented.** A value does not land on one and
|
|
39
|
-
the hub does not gather one. A radio group is several elements answering
|
|
40
|
-
to one column.
|
|
41
|
-
|
|
42
|
-
### Custom element hooks
|
|
43
|
-
|
|
44
|
-
Loadbare/app owns every method name beginning with `lb` on a custom element.
|
|
45
|
-
That decision is firm; what the set contains is not.
|
|
46
|
-
|
|
47
|
-
- **Decide whether a custom element may receive a whole row.** A column
|
|
48
|
-
lands one element at a time and offers no escape hatch. An optional
|
|
49
|
-
`lbAcceptRow` would sit beside `lbRowsLanded`, and this is the most likely
|
|
50
|
-
first request from a custom element author.
|
|
51
|
-
|
|
52
16
|
### Nested queries
|
|
53
17
|
|
|
54
18
|
Imagine an HTML `<select>` that shows a fixed set of choices on every row of
|
|
@@ -83,18 +47,8 @@ But the allowed values may depend on other values in the row.
|
|
|
83
47
|
repository with several applications gets one per application. `--src`
|
|
84
48
|
stays a flag, since it is what locates the file. State the precedence
|
|
85
49
|
between a flag and a key once. Its key names join the permanent surface,
|
|
86
|
-
so this lands before 1.0 or not at all.
|
|
87
|
-
-
|
|
88
|
-
definition would let the builder ship only what survives expansion.
|
|
89
|
-
Recommend deferring the mechanism and reserving the configuration key, so
|
|
90
|
-
that it lands as an opt-in rather than as a silent drop.
|
|
91
|
-
- **Decide whether the build validates HTML.** A page can be well formed and
|
|
92
|
-
still break HTML's rules for what an element may hold, such as a `<div>`
|
|
93
|
-
inside a `<p>`. The parser rearranges it silently, the same way at build
|
|
94
|
-
time and in the browser, so nothing reports it. Checking those rules is a
|
|
95
|
-
validator's job, and html-validate is one the builder could run on the
|
|
96
|
-
source or on the expanded output. Deciding it after 1.0 is free if it
|
|
97
|
-
lands as an opt-in, and it may need a configuration key.
|
|
50
|
+
so this lands before 1.0 or not at all. It reserves a key for the
|
|
51
|
+
roadmap's tree-shaking CSS by tag name.
|
|
98
52
|
- **Confirm the three output names.** `app.html`, `client.js` and `app.css`
|
|
99
53
|
are about to be fixed in `staticRoutes` as well as in the builder.
|
|
100
54
|
|
|
@@ -103,16 +57,15 @@ But the allowed values may depend on other values in the row.
|
|
|
103
57
|
None of this is surface. It is listed here because trimming it is free
|
|
104
58
|
today and breaking after 1.0.
|
|
105
59
|
|
|
106
|
-
- **Audit what the hub does.**
|
|
107
|
-
|
|
60
|
+
- **Audit what the hub does.** Every routine it runs answers to an `lb-*`
|
|
61
|
+
attribute, a [reserved query](#reserved-queries), or a
|
|
62
|
+
[reserved event](#reserved-events) or [method](#reserved-methods). Trim
|
|
63
|
+
whatever does not, and leave what stays clean: no dead code, no routine
|
|
64
|
+
written twice, no comment the code contradicts.
|
|
108
65
|
- **Keep the rest as constants.** The endpoint, `index` and the timeout are
|
|
109
66
|
linkage between the builder and the hub rather than facts an application
|
|
110
67
|
varies. Adding a knob for any of them buys a second shape of application
|
|
111
68
|
to reason about.
|
|
112
|
-
- **Give the hub a configuration channel without using it.** `<lb-hub>` reads
|
|
113
|
-
no attributes at all, which is the free landing spot for the roadmap's
|
|
114
|
-
static-origin split and for a timeout an application eventually outgrows.
|
|
115
|
-
Reserve the idea, build nothing.
|
|
116
69
|
|
|
117
70
|
## The build
|
|
118
71
|
|
|
@@ -220,7 +173,8 @@ it is sent to the browser on initial page load, no HTML is ever sent
|
|
|
220
173
|
again.
|
|
221
174
|
|
|
222
175
|
The developer writes `lb-*` attributes in markup. Script never assigns
|
|
223
|
-
them. The hub and the builder write only their stamps
|
|
176
|
+
them. The hub and the builder write only their stamps, and the hub writes
|
|
177
|
+
the `name` of a radio button in a row template. See
|
|
224
178
|
[The markup checks](#the-markup-checks).
|
|
225
179
|
|
|
226
180
|
### Expansion
|
|
@@ -457,8 +411,8 @@ unless its name begins with `lb-`.
|
|
|
457
411
|
| Any other element | Its text content |
|
|
458
412
|
|
|
459
413
|
A control is an `<input>`, `<select>` or `<textarea>`, or a form-associated
|
|
460
|
-
custom element with a `value` property that fires `change`. A checkbox
|
|
461
|
-
|
|
414
|
+
custom element with a `value` property that fires `change`. A checkbox and
|
|
415
|
+
a radio button are controls too, by the rules below. A
|
|
462
416
|
form-associated custom element declares `static formAssociated = true`.
|
|
463
417
|
|
|
464
418
|
The hub stamps `lb-column-value` with the value on every element it sets.
|
|
@@ -481,9 +435,18 @@ attribute means nothing to the hub.
|
|
|
481
435
|
<input type="checkbox" lb-column="active" lb-request="lb-row-update" />
|
|
482
436
|
```
|
|
483
437
|
|
|
484
|
-
|
|
485
|
-
`
|
|
486
|
-
|
|
438
|
+
A radio button's state is `checked` as well. The hub checks it when its
|
|
439
|
+
`value` attribute equals the value as a string, and unchecks it otherwise,
|
|
440
|
+
`null` included. Of the radio buttons naming one column, the hub gathers
|
|
441
|
+
the `value` of the one checked, or `""` when none is.
|
|
442
|
+
|
|
443
|
+
```html
|
|
444
|
+
<input type="radio" lb-column="shift" value="day" lb-request="lb-row-update" />
|
|
445
|
+
<input type="radio" lb-column="shift" value="night" lb-request="lb-row-update" />
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
An `<input>` of type `file` receives nothing, not even `lb-column-value`,
|
|
449
|
+
and the hub reports it to the console. The hub does not gather one either.
|
|
487
450
|
|
|
488
451
|
A `<select>` with no option for the value shows no selection.
|
|
489
452
|
|
|
@@ -509,6 +472,10 @@ landed inside another query, such as a total in a table's foot, is not one
|
|
|
509
472
|
of that query's rows. A stylesheet or a custom element selects live rows
|
|
510
473
|
with `[lb-row-live]`, and never with `[lb-key-value]`.
|
|
511
474
|
|
|
475
|
+
A `row` query answering `null` lands every column its element names as
|
|
476
|
+
null, and the element loses `lb-key-value`. Under a row template, its live
|
|
477
|
+
row leaves.
|
|
478
|
+
|
|
512
479
|
A key is unique within a query. Two rows with one key in the same answer,
|
|
513
480
|
or two live rows showing one key, are reported on the console.
|
|
514
481
|
|
|
@@ -1583,6 +1550,26 @@ whose name begins with `lb` and a capital and is not in
|
|
|
1583
1550
|
Script never assigns an `lb-` attribute, so the markup states every one
|
|
1584
1551
|
that exists, and checking the markup is sound.
|
|
1585
1552
|
|
|
1553
|
+
### Uncommon layouts
|
|
1554
|
+
|
|
1555
|
+
The hub supports these layouts and adds no check to refuse them. They are
|
|
1556
|
+
uncommon, and Loadbare/app does not shape itself around them.
|
|
1557
|
+
|
|
1558
|
+
- **A radio button in a row template.** The browser groups radio buttons
|
|
1559
|
+
by `name`, and a row template repeats one `name` in every live row. The
|
|
1560
|
+
hub stamps each radio button's `name` with the `name` written, or its
|
|
1561
|
+
column when none is, followed by `-` and the live row's key, so each live
|
|
1562
|
+
row holds a group of its own.
|
|
1563
|
+
- **Several rows not yet entered, each holding radio buttons.** A
|
|
1564
|
+
[row not yet entered](#a-row-not-yet-entered) has an empty key, so the
|
|
1565
|
+
radio buttons of every such row share one `name` and form one group.
|
|
1566
|
+
- **Radio buttons populated from a query.** A radio button in a query's row
|
|
1567
|
+
template answers to that query's row, as any element there does, so which
|
|
1568
|
+
row and column it lands from and gathers to follows from where the layout
|
|
1569
|
+
puts it. The result is the same as in any framework that populates radio
|
|
1570
|
+
buttons from a query. A choice among a query's rows is better made with a
|
|
1571
|
+
form-associated control, such as `lb-options` in `@loadbare/widgets`.
|
|
1572
|
+
|
|
1586
1573
|
## Application files
|
|
1587
1574
|
|
|
1588
1575
|
### Chrome
|
|
@@ -1801,8 +1788,8 @@ export const queries: Queries = {
|
|
|
1801
1788
|
};
|
|
1802
1789
|
```
|
|
1803
1790
|
|
|
1804
|
-
A `row` query returns one object,
|
|
1805
|
-
objects, which the page shows in that order when the query declares none. An answer that disagrees with
|
|
1791
|
+
A `row` query returns one object, or `null` when it finds no row, and a
|
|
1792
|
+
`rows` query returns an array of objects, which the page shows in that order when the query declares none. An answer that disagrees with
|
|
1806
1793
|
its declared kind is left out of the response, with a warning naming the
|
|
1807
1794
|
query.
|
|
1808
1795
|
|
package/docs/comparison.md
CHANGED
|
@@ -407,8 +407,9 @@ requests and `crud` entries a page declares; any other name answers `[]` and
|
|
|
407
407
|
logs a server warning.
|
|
408
408
|
|
|
409
409
|
Values are not converted. The hub hands each value to the browser as the
|
|
410
|
-
query produced it. Formatting a date or an amount is done in the query
|
|
411
|
-
|
|
410
|
+
query produced it. Formatting a date or an amount is done in the query, or
|
|
411
|
+
by a custom element over `Intl`, such as `lb-number` and `lb-date` in
|
|
412
|
+
`@loadbare/widgets`.
|
|
412
413
|
|
|
413
414
|
### Elsewhere
|
|
414
415
|
|
|
@@ -825,7 +826,6 @@ cross-reference, so no count is given for them here.
|
|
|
825
826
|
- A widget's markup is in the document and in view-source.
|
|
826
827
|
- On navigation the hub sets `document.title` from the page's `<title>`. It
|
|
827
828
|
does not move focus or announce the new page.
|
|
828
|
-
- Radio buttons are not implemented for landing or gathering.
|
|
829
829
|
|
|
830
830
|
### Elsewhere
|
|
831
831
|
|
|
@@ -920,8 +920,8 @@ Roadmap.
|
|
|
920
920
|
| Nested data | A row never holds rows. Trees are sent as joined rows. |
|
|
921
921
|
| Record URLs and view parameters | A path names a page. A record or a filter is a query parm, `/accounts?acct=23`. |
|
|
922
922
|
| Query arguments from the browser | None. Query parms reach queries through `contextFor` and `ctx`. |
|
|
923
|
-
|
|
|
924
|
-
| Data types and formatting | No conversion. Queries format values.
|
|
923
|
+
| File inputs | Not landed and not gathered. |
|
|
924
|
+
| Data types and formatting | No conversion. Queries, or custom elements over `Intl`, format values. |
|
|
925
925
|
| Error messages | A handler's `refusal()` reaches the user; any other failure carries no message. |
|
|
926
926
|
| Field validation | No mechanism. Per-keystroke validation is a roadmap question. |
|
|
927
927
|
| Optimistic updates | None. |
|
package/docs/reference/css.md
CHANGED
|
@@ -42,3 +42,166 @@ See [`chrome.html`](./chrome.md) for the link, [The Express
|
|
|
42
42
|
server](./server.md) for the route, and
|
|
43
43
|
[`loadbare-app-build`](./builder.md#running-the-builder) for `--minify`.
|
|
44
44
|
</content>
|
|
45
|
+
|
|
46
|
+
## Selecting what the hub stamps
|
|
47
|
+
|
|
48
|
+
The hub tells a stylesheet everything it knows through attributes, so an
|
|
49
|
+
application styles state with selectors and writes no script for it. Each
|
|
50
|
+
stamp is an `lb-` attribute the hub writes; never write one in markup.
|
|
51
|
+
|
|
52
|
+
### A value
|
|
53
|
+
|
|
54
|
+
Every element a column lands on carries the value as `lb-column-value`,
|
|
55
|
+
exactly as the query sent it, and loses it when the value is null. Select
|
|
56
|
+
on the column and the value:
|
|
57
|
+
|
|
58
|
+
```css
|
|
59
|
+
[lb-column="status"][lb-column-value="locked"] { opacity: 0.5; }
|
|
60
|
+
[lb-column="balance"][lb-column-value^="-"] { color: var(--negative); }
|
|
61
|
+
[lb-column="note"]:not([lb-column-value]) { display: none; }
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
A widget that formats its value, such as `lb-number`, keeps the raw value
|
|
65
|
+
in the stamp, so the selector reads the number and not its text. See
|
|
66
|
+
[Where a column lands](./data-binding.md#where-a-column-lands).
|
|
67
|
+
|
|
68
|
+
### A row
|
|
69
|
+
|
|
70
|
+
| Select | For |
|
|
71
|
+
|----------------------|-------------------------------------------------|
|
|
72
|
+
| `[lb-row-live]` | Every live row of a list |
|
|
73
|
+
| `[lb-row-selected]` | A row its `lb-select` checkbox ticks |
|
|
74
|
+
| `[lb-row-editing]` | The row a pointed form is editing |
|
|
75
|
+
| `[lb-key-value="…"]` | One row, by its key |
|
|
76
|
+
| `[hidden]` | A row a filter hides; the browser hides it |
|
|
77
|
+
|
|
78
|
+
An element a `row` query lands on carries `lb-key-value` while the query has
|
|
79
|
+
a row, and loses it when the query answers `null`:
|
|
80
|
+
|
|
81
|
+
```css
|
|
82
|
+
[lb-query="member"]:not([lb-key-value]) .member-missing { display: revert; }
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Select live rows with `[lb-row-live]`, never with `[lb-key-value]`: a `row`
|
|
86
|
+
landed inside a list, such as a total in a table's foot, carries a key and
|
|
87
|
+
is not one of the list's rows.
|
|
88
|
+
|
|
89
|
+
```css
|
|
90
|
+
[lb-row-selected] { background: var(--selected); }
|
|
91
|
+
[lb-row-editing] { outline: 2px solid var(--accent); }
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
See [Rows](./data-binding.md#rows), [Selecting rows](./data-binding.md#selecting-rows)
|
|
95
|
+
and [Editing a row in one form](./data-binding.md#editing-a-row-in-one-form).
|
|
96
|
+
|
|
97
|
+
### A group
|
|
98
|
+
|
|
99
|
+
Each top-level element of a group carries `lb-group-live`, the column it
|
|
100
|
+
breaks on as `lb-group-column`, and its value there as `lb-group-value`:
|
|
101
|
+
|
|
102
|
+
```css
|
|
103
|
+
[lb-group-column="category"][lb-group-value="Income"] { color: var(--income); }
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
See [Groups](./data-binding.md#groups).
|
|
107
|
+
|
|
108
|
+
### What just happened to a row
|
|
109
|
+
|
|
110
|
+
The hub stamps what its last landing did, so a stylesheet animates with
|
|
111
|
+
nothing else:
|
|
112
|
+
|
|
113
|
+
| Select | For |
|
|
114
|
+
|--------------------------------|------------------------------------------------|
|
|
115
|
+
| `[lb-row-created]` | A row that arrived |
|
|
116
|
+
| `[lb-row-changed]` | A row whose values changed |
|
|
117
|
+
| `[lb-row-moved]` | A row whose values changed and now stands elsewhere; it carries `lb-row-changed` too |
|
|
118
|
+
| `[lb-row-requested]` | Any of the three, done by this page's request, as `created`, `changed` or `moved` |
|
|
119
|
+
| `[lb-row-leaving]`, `[lb-group-leaving]` | A row or group on its way out; the hub removes it when its animations end |
|
|
120
|
+
|
|
121
|
+
```css
|
|
122
|
+
[lb-row-created] { animation: arrive 200ms; }
|
|
123
|
+
[lb-row-requested="changed"] { animation: flash 600ms; }
|
|
124
|
+
[lb-row-leaving] { animation: depart 200ms forwards; }
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
A row stamped again plays its animation again. See
|
|
128
|
+
[What happened to a row](./data-binding.md#what-happened-to-a-row).
|
|
129
|
+
|
|
130
|
+
### How many rows show
|
|
131
|
+
|
|
132
|
+
An element carrying `lb-query` and a row template carries
|
|
133
|
+
`lb-query-row-count`, the number of live rows showing. A row a filter hides
|
|
134
|
+
is not counted.
|
|
135
|
+
|
|
136
|
+
```css
|
|
137
|
+
.roster-empty { display: none; }
|
|
138
|
+
[lb-query-row-count="0"] .roster-empty { display: revert; }
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
See [Counting rows](./data-binding.md#counting-rows).
|
|
142
|
+
|
|
143
|
+
### A request
|
|
144
|
+
|
|
145
|
+
| Select | For |
|
|
146
|
+
|------------------------|---------------------------------------------------------|
|
|
147
|
+
| `[lb-request-pending]` | The element that committed, while its round trip is out; `aria-busy="true"` rides with it |
|
|
148
|
+
| `[lb-request-error]` | The element whose round trip failed, until it commits again |
|
|
149
|
+
| `[lb-request-refused]` | The element whose request the handler refused, holding the message, empty when there is none |
|
|
150
|
+
| `:invalid` | A control a refusal named a column for |
|
|
151
|
+
|
|
152
|
+
The hub ignores a commit on a pending element, so the stylesheet only has to
|
|
153
|
+
show it:
|
|
154
|
+
|
|
155
|
+
```css
|
|
156
|
+
[lb-request-pending] { cursor: progress; opacity: 0.6; }
|
|
157
|
+
[lb-request-error] { outline: 2px solid var(--error); }
|
|
158
|
+
[lb-request-refused]:not([lb-request-refused=""])::after {
|
|
159
|
+
content: attr(lb-request-refused);
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
See [Request state](./data-binding.md#request-state) and
|
|
164
|
+
[Refusals](./data-binding.md#refusals).
|
|
165
|
+
|
|
166
|
+
### A form pointed at a row
|
|
167
|
+
|
|
168
|
+
A pointed form's `lb-key-value` says what it is doing:
|
|
169
|
+
|
|
170
|
+
| Select | The form is |
|
|
171
|
+
|------------------------------|--------------------|
|
|
172
|
+
| `form[lb-key-value]:not([lb-key-value=""])` | Editing a row |
|
|
173
|
+
| `form[lb-key-value=""]` | Entering a new row |
|
|
174
|
+
| `form:not([lb-key-value])` | Not in use |
|
|
175
|
+
|
|
176
|
+
```css
|
|
177
|
+
form[lb-key-value=""] .save-existing,
|
|
178
|
+
form:not([lb-key-value=""]) .save-new { display: none; }
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
See [Editing a row in one form](./data-binding.md#editing-a-row-in-one-form).
|
|
182
|
+
|
|
183
|
+
### The user's choices
|
|
184
|
+
|
|
185
|
+
An order or a filter the user chose is a column of `lb-choices`, so the
|
|
186
|
+
element showing it carries it as `lb-column-value`. Style anything else by
|
|
187
|
+
it with `:has()`:
|
|
188
|
+
|
|
189
|
+
```css
|
|
190
|
+
table:has([lb-column="accounts_order"][lb-column-value="-balance"])
|
|
191
|
+
th.balance::after { content: "▼"; }
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
See [Choices](./data-binding.md#choices).
|
|
195
|
+
|
|
196
|
+
### Content shown by condition
|
|
197
|
+
|
|
198
|
+
An element `lb-show` turns off is moved into a `<template>`, so no selector
|
|
199
|
+
reaches it and nothing about it needs styling. The `<template>` keeps its
|
|
200
|
+
place, so `:nth-child()` counts it; prefer `:nth-child(… of …)` or a class
|
|
201
|
+
over position. See [Where an absent element is](./data-binding.md#where-an-absent-element-is).
|
|
202
|
+
|
|
203
|
+
### The first load
|
|
204
|
+
|
|
205
|
+
Write `hidden` on the chrome's `<body>`, and the hub removes it once the
|
|
206
|
+
first page has landed. See
|
|
207
|
+
[Preventing the first-load blink](./chrome.md#preventing-the-first-load-blink).
|
|
@@ -95,6 +95,10 @@ not `lb-row-live`, so a `row` shown inside another query, such as a total in
|
|
|
95
95
|
a table's foot, is not one of that query's rows. Select live rows with
|
|
96
96
|
`[lb-row-live]`, never with `[lb-key-value]`.
|
|
97
97
|
|
|
98
|
+
A `row` query answering `null` found no row. The hub lands every column the
|
|
99
|
+
element names as null and removes its `lb-key-value`; under a row template,
|
|
100
|
+
the live row leaves.
|
|
101
|
+
|
|
98
102
|
Write `lb-column` on each element that shows a column. The element reads
|
|
99
103
|
from its nearest ancestor row: the live row it is in, or the element a
|
|
100
104
|
`row` landed on. A nested `lb-query` begins a new query, and what is inside
|
|
@@ -124,6 +128,7 @@ no row fills.
|
|
|
124
128
|
|------------------------------------------------------|-----------------------------------------|
|
|
125
129
|
| `<input>`, `<select>`, `<textarea>` | Its `value`, and `lb-column-value` |
|
|
126
130
|
| `<input type="checkbox">` | Its `checked`, and `lb-column-value` |
|
|
131
|
+
| `<input type="radio">` | Its `checked`, and `lb-column-value` |
|
|
127
132
|
| A form-associated custom element with `value` | Its `value`, and `lb-column-value` |
|
|
128
133
|
| Any other custom element | `lb-column-value` only |
|
|
129
134
|
| Any other element | Its text content, and `lb-column-value` |
|
|
@@ -135,11 +140,13 @@ element that is not a control keeps the content the builder placed in it
|
|
|
135
140
|
from its element file, and renders `lb-column-value` itself; see
|
|
136
141
|
[Custom Elements](./custom-elements.md#receiving-a-value).
|
|
137
142
|
|
|
138
|
-
A
|
|
139
|
-
the console.
|
|
143
|
+
A file input receives nothing, and the hub reports it to the console.
|
|
140
144
|
|
|
141
145
|
The hub hands every value to the browser as the server sent it. What a
|
|
142
|
-
number, a date or a null looks like is decided in the query
|
|
146
|
+
number, a date or a null looks like is decided in the query, or by a custom
|
|
147
|
+
element that formats it, such as
|
|
148
|
+
[`lb-number` and `lb-date`](./widgets.md#lb-number-and-lb-date). Send a
|
|
149
|
+
column the user sorts or filters raw, and format it in the element.
|
|
143
150
|
|
|
144
151
|
### Checkboxes
|
|
145
152
|
|
|
@@ -155,6 +162,27 @@ boolean, and the string `"false"` is checked. Unchecked sends `"false"`
|
|
|
155
162
|
rather than nothing, so a flag can be set back. The checkbox's `value`
|
|
156
163
|
attribute means nothing to the hub.
|
|
157
164
|
|
|
165
|
+
### Radio buttons
|
|
166
|
+
|
|
167
|
+
A radio button is a control. It is checked when its `value` is the
|
|
168
|
+
column's value as a string, and unchecked otherwise. Of the radio buttons
|
|
169
|
+
naming one column, the hub gathers the `value` of the one checked, or `""`
|
|
170
|
+
when none is:
|
|
171
|
+
|
|
172
|
+
```html
|
|
173
|
+
<input type="radio" lb-column="shift" value="day" lb-request="lb-row-update" />
|
|
174
|
+
<input type="radio" lb-column="shift" value="night" lb-request="lb-row-update" />
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
In a row template, the hub stamps each radio button's `name` with the
|
|
178
|
+
`name` written, or its column when none is, followed by `-` and the live
|
|
179
|
+
row's key, so each live row holds a group of its own. Rows not yet entered
|
|
180
|
+
share the empty key, and so share one group.
|
|
181
|
+
|
|
182
|
+
A radio button in a query's row template answers to that query's row, as
|
|
183
|
+
any element there does. A choice among a query's rows is better made with
|
|
184
|
+
a form-associated control, such as `lb-options` in `@loadbare/widgets`.
|
|
185
|
+
|
|
158
186
|
### Rows
|
|
159
187
|
|
|
160
188
|
Write a `<template>` inside the element carrying `lb-query`, holding one
|