@loadbare/app 0.17.0 → 0.18.1
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/hub/lb-apply.d.ts +12 -4
- package/dist/hub/lb-apply.d.ts.map +1 -1
- package/dist/hub/lb-apply.js +45 -5
- 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.map +1 -1
- package/dist/server/lb-server.js +7 -8
- package/dist/server/lb-server.js.map +1 -1
- package/docs/TECHREF-1.0.md +55 -61
- package/docs/comparison.md +1 -2
- package/docs/reference/data-binding.md +23 -2
- package/docs/reference/page-files.md +5 -4
- package/docs/reference/widgets.md +11 -0
- package/docs/roadmap.md +17 -9
- package/package.json +1 -1
- package/skills/loadbare-app/SKILL.md +9 -7
- package/skills/loadbare-app/references/TECHREF-1.0.md +55 -61
- package/skills/loadbare-app/references/data-binding.md +23 -2
- package/skills/loadbare-app/references/page-files.md +5 -4
- package/skills/loadbare-app/references/widgets.md +11 -0
|
@@ -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,EAClB,eAAe,EACf,SAAS,GACV,MAAM,yBAAyB,CAAC;AAgEjC,yEAAyE;AACzE,MAAM,UAAU,GAAG,CACjB,GAAW,EACX,GAA4C;IAE5C,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EA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AW,CAAC,KAAK,CAAC,CAAC;IACnC,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,OAAO,CAAC,IAAI,CACV,mBAAmB,IAAI,cAAc,aAAa,IAAI,OAAO,IAAI;YAC/D,aAAa,CAChB,CAAC;QACF,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,OAAO;QACL;YACE,KAAK,EAAE,aAAa;YACpB,IAAI,EAAE,QAAQ;YACd,GAAG,EAAE,eAAe;YACpB,GAAG,EAAE,KAAY;SAClB;KACF,CAAC;AACJ,CAAC;AAED,8EAA8E;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/** 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 // An update or a delete names its row by key, so its handler always\n // knows which rows changed and can answer with a patch, and the hub\n // places what the patch names by the query's order. Refreshing the whole\n // set instead sends every row to say one thing. There is no case where\n // that is the answer to either, so it is refused rather than warned\n // about. An insert is not: its key exists only once the row does, and a\n // handler may leave the query to say so.\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 [\"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":[],"m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B,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/** 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"]}
|
package/docs/TECHREF-1.0.md
CHANGED
|
@@ -15,39 +15,14 @@ they must be resolved before we declare 1.0.
|
|
|
15
15
|
|
|
16
16
|
### Data types
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
`lb-column-value` when it lands on one that is not a control.
|
|
18
|
+
A value renders by browser coercion when it lands on an HTML text element or
|
|
19
|
+
a control, and by whatever the custom element does with `lb-column-value`
|
|
20
|
+
when it lands on one that is not a control. A `rows` query may declare a
|
|
21
|
+
column's type, which the [order](#order), a [filter](#filters), `lb-min` and
|
|
22
|
+
`lb-max` read.
|
|
24
23
|
|
|
25
|
-
|
|
26
|
-
|
|
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.
|
|
24
|
+
- **Decide who formats a value.** The hub could own formatting, or take it
|
|
25
|
+
from the application as configuration or as code.
|
|
51
26
|
|
|
52
27
|
### Nested queries
|
|
53
28
|
|
|
@@ -83,18 +58,8 @@ But the allowed values may depend on other values in the row.
|
|
|
83
58
|
repository with several applications gets one per application. `--src`
|
|
84
59
|
stays a flag, since it is what locates the file. State the precedence
|
|
85
60
|
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.
|
|
61
|
+
so this lands before 1.0 or not at all. It reserves a key for the
|
|
62
|
+
roadmap's tree-shaking CSS by tag name.
|
|
98
63
|
- **Confirm the three output names.** `app.html`, `client.js` and `app.css`
|
|
99
64
|
are about to be fixed in `staticRoutes` as well as in the builder.
|
|
100
65
|
|
|
@@ -103,16 +68,15 @@ But the allowed values may depend on other values in the row.
|
|
|
103
68
|
None of this is surface. It is listed here because trimming it is free
|
|
104
69
|
today and breaking after 1.0.
|
|
105
70
|
|
|
106
|
-
- **Audit what the hub does.**
|
|
107
|
-
|
|
71
|
+
- **Audit what the hub does.** Every routine it runs answers to an `lb-*`
|
|
72
|
+
attribute, a [reserved query](#reserved-queries), or a
|
|
73
|
+
[reserved event](#reserved-events) or [method](#reserved-methods). Trim
|
|
74
|
+
whatever does not, and leave what stays clean: no dead code, no routine
|
|
75
|
+
written twice, no comment the code contradicts.
|
|
108
76
|
- **Keep the rest as constants.** The endpoint, `index` and the timeout are
|
|
109
77
|
linkage between the builder and the hub rather than facts an application
|
|
110
78
|
varies. Adding a knob for any of them buys a second shape of application
|
|
111
79
|
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
80
|
|
|
117
81
|
## The build
|
|
118
82
|
|
|
@@ -220,7 +184,8 @@ it is sent to the browser on initial page load, no HTML is ever sent
|
|
|
220
184
|
again.
|
|
221
185
|
|
|
222
186
|
The developer writes `lb-*` attributes in markup. Script never assigns
|
|
223
|
-
them. The hub and the builder write only their stamps
|
|
187
|
+
them. The hub and the builder write only their stamps, and the hub writes
|
|
188
|
+
the `name` of a radio button in a row template. See
|
|
224
189
|
[The markup checks](#the-markup-checks).
|
|
225
190
|
|
|
226
191
|
### Expansion
|
|
@@ -457,8 +422,8 @@ unless its name begins with `lb-`.
|
|
|
457
422
|
| Any other element | Its text content |
|
|
458
423
|
|
|
459
424
|
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
|
-
|
|
425
|
+
custom element with a `value` property that fires `change`. A checkbox and
|
|
426
|
+
a radio button are controls too, by the rules below. A
|
|
462
427
|
form-associated custom element declares `static formAssociated = true`.
|
|
463
428
|
|
|
464
429
|
The hub stamps `lb-column-value` with the value on every element it sets.
|
|
@@ -481,9 +446,18 @@ attribute means nothing to the hub.
|
|
|
481
446
|
<input type="checkbox" lb-column="active" lb-request="lb-row-update" />
|
|
482
447
|
```
|
|
483
448
|
|
|
484
|
-
|
|
485
|
-
`
|
|
486
|
-
|
|
449
|
+
A radio button's state is `checked` as well. The hub checks it when its
|
|
450
|
+
`value` attribute equals the value as a string, and unchecks it otherwise,
|
|
451
|
+
`null` included. Of the radio buttons naming one column, the hub gathers
|
|
452
|
+
the `value` of the one checked, or `""` when none is.
|
|
453
|
+
|
|
454
|
+
```html
|
|
455
|
+
<input type="radio" lb-column="shift" value="day" lb-request="lb-row-update" />
|
|
456
|
+
<input type="radio" lb-column="shift" value="night" lb-request="lb-row-update" />
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
An `<input>` of type `file` receives nothing, not even `lb-column-value`,
|
|
460
|
+
and the hub reports it to the console. The hub does not gather one either.
|
|
487
461
|
|
|
488
462
|
A `<select>` with no option for the value shows no selection.
|
|
489
463
|
|
|
@@ -1583,6 +1557,26 @@ whose name begins with `lb` and a capital and is not in
|
|
|
1583
1557
|
Script never assigns an `lb-` attribute, so the markup states every one
|
|
1584
1558
|
that exists, and checking the markup is sound.
|
|
1585
1559
|
|
|
1560
|
+
### Uncommon layouts
|
|
1561
|
+
|
|
1562
|
+
The hub supports these layouts and adds no check to refuse them. They are
|
|
1563
|
+
uncommon, and Loadbare/app does not shape itself around them.
|
|
1564
|
+
|
|
1565
|
+
- **A radio button in a row template.** The browser groups radio buttons
|
|
1566
|
+
by `name`, and a row template repeats one `name` in every live row. The
|
|
1567
|
+
hub stamps each radio button's `name` with the `name` written, or its
|
|
1568
|
+
column when none is, followed by `-` and the live row's key, so each live
|
|
1569
|
+
row holds a group of its own.
|
|
1570
|
+
- **Several rows not yet entered, each holding radio buttons.** A
|
|
1571
|
+
[row not yet entered](#a-row-not-yet-entered) has an empty key, so the
|
|
1572
|
+
radio buttons of every such row share one `name` and form one group.
|
|
1573
|
+
- **Radio buttons populated from a query.** A radio button in a query's row
|
|
1574
|
+
template answers to that query's row, as any element there does, so which
|
|
1575
|
+
row and column it lands from and gathers to follows from where the layout
|
|
1576
|
+
puts it. The result is the same as in any framework that populates radio
|
|
1577
|
+
buttons from a query. A choice among a query's rows is better made with a
|
|
1578
|
+
form-associated control, such as `lb-options` in `@loadbare/widgets`.
|
|
1579
|
+
|
|
1586
1580
|
## Application files
|
|
1587
1581
|
|
|
1588
1582
|
### Chrome
|
|
@@ -1854,12 +1848,12 @@ the refreshed ones. That is how a delta reaches the browser: wrap it in
|
|
|
1854
1848
|
`patch()`, naming the rows that arrived or changed and the keys that went.
|
|
1855
1849
|
|
|
1856
1850
|
A refreshed `rows` query sends every row to say what changed. An update or
|
|
1857
|
-
a delete names its row by key,
|
|
1858
|
-
|
|
1859
|
-
|
|
1851
|
+
a delete names its row by key, and an insert has the new row's key once it
|
|
1852
|
+
has written it, so each handler knows what changed and answers with a
|
|
1853
|
+
patch, which the hub places by the query's [order](#order): `createHub`
|
|
1854
|
+
refuses at startup a `crud` `rowInsert`, `rowUpdate` or `rowDelete` on a
|
|
1860
1855
|
`rows` query whose `refresh` names that same query. A `row` query sends one
|
|
1861
|
-
row and may refresh itself.
|
|
1862
|
-
key exists only once the row does.
|
|
1856
|
+
row and may refresh itself.
|
|
1863
1857
|
|
|
1864
1858
|
`run` may instead return `url()`, a new row for `lb-url`, naming query parms
|
|
1865
1859
|
only the write can know, such as the key of a row it inserted. The page
|
package/docs/comparison.md
CHANGED
|
@@ -825,7 +825,6 @@ cross-reference, so no count is given for them here.
|
|
|
825
825
|
- A widget's markup is in the document and in view-source.
|
|
826
826
|
- On navigation the hub sets `document.title` from the page's `<title>`. It
|
|
827
827
|
does not move focus or announce the new page.
|
|
828
|
-
- Radio buttons are not implemented for landing or gathering.
|
|
829
828
|
|
|
830
829
|
### Elsewhere
|
|
831
830
|
|
|
@@ -920,7 +919,7 @@ Roadmap.
|
|
|
920
919
|
| Nested data | A row never holds rows. Trees are sent as joined rows. |
|
|
921
920
|
| Record URLs and view parameters | A path names a page. A record or a filter is a query parm, `/accounts?acct=23`. |
|
|
922
921
|
| Query arguments from the browser | None. Query parms reach queries through `contextFor` and `ctx`. |
|
|
923
|
-
|
|
|
922
|
+
| File inputs | Not landed and not gathered. |
|
|
924
923
|
| Data types and formatting | No conversion. Queries format values. Open blocker. |
|
|
925
924
|
| Error messages | A handler's `refusal()` reaches the user; any other failure carries no message. |
|
|
926
925
|
| Field validation | No mechanism. Per-keystroke validation is a roadmap question. |
|
|
@@ -124,6 +124,7 @@ no row fills.
|
|
|
124
124
|
|------------------------------------------------------|-----------------------------------------|
|
|
125
125
|
| `<input>`, `<select>`, `<textarea>` | Its `value`, and `lb-column-value` |
|
|
126
126
|
| `<input type="checkbox">` | Its `checked`, and `lb-column-value` |
|
|
127
|
+
| `<input type="radio">` | Its `checked`, and `lb-column-value` |
|
|
127
128
|
| A form-associated custom element with `value` | Its `value`, and `lb-column-value` |
|
|
128
129
|
| Any other custom element | `lb-column-value` only |
|
|
129
130
|
| Any other element | Its text content, and `lb-column-value` |
|
|
@@ -135,8 +136,7 @@ element that is not a control keeps the content the builder placed in it
|
|
|
135
136
|
from its element file, and renders `lb-column-value` itself; see
|
|
136
137
|
[Custom Elements](./custom-elements.md#receiving-a-value).
|
|
137
138
|
|
|
138
|
-
A
|
|
139
|
-
the console.
|
|
139
|
+
A file input receives nothing, and the hub reports it to the console.
|
|
140
140
|
|
|
141
141
|
The hub hands every value to the browser as the server sent it. What a
|
|
142
142
|
number, a date or a null looks like is decided in the query.
|
|
@@ -155,6 +155,27 @@ boolean, and the string `"false"` is checked. Unchecked sends `"false"`
|
|
|
155
155
|
rather than nothing, so a flag can be set back. The checkbox's `value`
|
|
156
156
|
attribute means nothing to the hub.
|
|
157
157
|
|
|
158
|
+
### Radio buttons
|
|
159
|
+
|
|
160
|
+
A radio button is a control. It is checked when its `value` is the
|
|
161
|
+
column's value as a string, and unchecked otherwise. Of the radio buttons
|
|
162
|
+
naming one column, the hub gathers the `value` of the one checked, or `""`
|
|
163
|
+
when none is:
|
|
164
|
+
|
|
165
|
+
```html
|
|
166
|
+
<input type="radio" lb-column="shift" value="day" lb-request="lb-row-update" />
|
|
167
|
+
<input type="radio" lb-column="shift" value="night" lb-request="lb-row-update" />
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
In a row template, the hub stamps each radio button's `name` with the
|
|
171
|
+
`name` written, or its column when none is, followed by `-` and the live
|
|
172
|
+
row's key, so each live row holds a group of its own. Rows not yet entered
|
|
173
|
+
share the empty key, and so share one group.
|
|
174
|
+
|
|
175
|
+
A radio button in a query's row template answers to that query's row, as
|
|
176
|
+
any element there does. A choice among a query's rows is better made with
|
|
177
|
+
a form-associated control, such as `lb-options` in `@loadbare/widgets`.
|
|
178
|
+
|
|
158
179
|
### Rows
|
|
159
180
|
|
|
160
181
|
Write a `<template>` inside the element carrying `lb-query`, holding one
|
|
@@ -337,10 +337,11 @@ A change that seems to need a refresh usually has a patch:
|
|
|
337
337
|
delete and drop them too.
|
|
338
338
|
|
|
339
339
|
An update or a delete always has a patch, since it names its row by key and
|
|
340
|
-
removing a row never reorders the rest.
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
340
|
+
removing a row never reorders the rest. So does an insert, which has the new
|
|
341
|
+
row's key once it has written it, and the hub places the new row by the
|
|
342
|
+
query's order. `createHub` refuses at startup a `crud` `rowInsert`,
|
|
343
|
+
`rowUpdate` or `rowDelete` on a `rows` query whose `refresh` names that same
|
|
344
|
+
query.
|
|
344
345
|
|
|
345
346
|
Each request's `refresh` is its own, and every query in it needs its own
|
|
346
347
|
reason. A list shared by several requests is a warning sign.
|
|
@@ -78,6 +78,7 @@ writes the row template inside the widget:
|
|
|
78
78
|
| Parameter | Fills |
|
|
79
79
|
|-------------|----------------------------|
|
|
80
80
|
| `exp-label` | The visible `<label>` text |
|
|
81
|
+
| `exp-size` | The `<select>`'s `size`, an open list rather than a drop-down |
|
|
81
82
|
|
|
82
83
|
- Each option's `value` is its row's key, the `lb-key-value` the hub stamps
|
|
83
84
|
on the live row, so the widget holds a key and shows a label.
|
|
@@ -90,6 +91,9 @@ writes the row template inside the widget:
|
|
|
90
91
|
<optgroup><template><option lb-column="label"></option></template></optgroup>
|
|
91
92
|
</template>
|
|
92
93
|
```
|
|
94
|
+
- A heading option marked `data-group-label` in the `<optgroup>`, `hidden`
|
|
95
|
+
and `disabled`, labels the group with its text instead, so the label can
|
|
96
|
+
be a column of the group's first row.
|
|
93
97
|
- Its `value` selects the option with that key, including an option that
|
|
94
98
|
arrives after the value did.
|
|
95
99
|
|
|
@@ -167,6 +171,9 @@ row, the row template, and optionally a footer, each as a `<template>`:
|
|
|
167
171
|
cursor back in it once an insert from it succeeds.
|
|
168
172
|
- After rows land, the widget scrolls the row the page's own request created
|
|
169
173
|
or moved into view.
|
|
174
|
+
- Text selected in a cell whose `lb-column` the table's `lb-filter` names
|
|
175
|
+
becomes that column's filter in `lb-choices`: `=` for the whole text,
|
|
176
|
+
`^=` from its start, `$=` up to its end, `*=` otherwise.
|
|
170
177
|
|
|
171
178
|
## `lb-confirm`
|
|
172
179
|
|
|
@@ -207,6 +214,10 @@ with `commandfor` and `command="show-modal"`. Save is the form's
|
|
|
207
214
|
`lb-options` around the button that opened it, and closes. The handler
|
|
208
215
|
answers with a patch holding the new row.
|
|
209
216
|
|
|
217
|
+
While open, the button that opened it carries `insert-dialog-opener` and the
|
|
218
|
+
widget carries `anchored`, for a stylesheet to place the dialog beside the
|
|
219
|
+
button with CSS anchor positioning.
|
|
220
|
+
|
|
210
221
|
| Parameter | Fills |
|
|
211
222
|
|-------------|---------------------------------------------------|
|
|
212
223
|
| `exp-id` | The dialog's `id` |
|
package/docs/roadmap.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Roadmap
|
|
2
2
|
|
|
3
|
-
Release 1.0 is optimized to prove that a Loadbare app
|
|
4
|
-
|
|
3
|
+
Release 1.0 is optimized to prove that a Loadbare app holds a median 300ms
|
|
4
|
+
round trip from click to paint. See [Theory](./theory.md).
|
|
5
5
|
|
|
6
6
|
What follows is everything not yet decided or not yet built: release
|
|
7
7
|
candidates, risks not worth solving speculatively, and open design
|
|
@@ -30,13 +30,6 @@ read from a query parm. Whether a response may say the server already
|
|
|
30
30
|
sorted it is open: the server may not sort as the browser does, and for a
|
|
31
31
|
thousand rows the hub's sort is a small cost.
|
|
32
32
|
|
|
33
|
-
### Nesting
|
|
34
|
-
|
|
35
|
-
Whether a live row may hold rows of its own detail (master-detail, an
|
|
36
|
-
expanding row). [Theory](./theory.md) already flags this as possibly load-bearing if
|
|
37
|
-
disallowed. Worth a decision-in-principle the first time a master-detail
|
|
38
|
-
page is built, even before the mechanism is needed elsewhere.
|
|
39
|
-
|
|
40
33
|
### Events while a request is in flight
|
|
41
34
|
|
|
42
35
|
The hub ignores a commit on an element carrying `lb-request-pending`.
|
|
@@ -90,6 +83,9 @@ If the hub were configured with a URL for the data channel, the entire app
|
|
|
90
83
|
could be delivered from a static origin, such as an S3 bucket or static web
|
|
91
84
|
server.
|
|
92
85
|
|
|
86
|
+
`<lb-hub>` reads no attributes, so the data channel's URL, and a timeout an
|
|
87
|
+
application outgrows, can arrive as attributes on it.
|
|
88
|
+
|
|
93
89
|
### Tree-shaking CSS by tag name
|
|
94
90
|
|
|
95
91
|
Release 1.0 concatenates every `.css` file under `src`, and every one inside
|
|
@@ -110,6 +106,18 @@ Most valuable against a large imported widget library, where an app uses a
|
|
|
110
106
|
small fraction of what ships. Revisit when a real app's `app.css` is big
|
|
111
107
|
enough to measure.
|
|
112
108
|
|
|
109
|
+
### HTML validation in the build
|
|
110
|
+
|
|
111
|
+
A page can be well formed and still break HTML's rules for what an element
|
|
112
|
+
may hold, such as a `<div>` inside a `<p>`. The parser rearranges it
|
|
113
|
+
silently, the same way at build time and in the browser. The builder could
|
|
114
|
+
run html-validate on the source or the expanded output, as an opt-in.
|
|
115
|
+
|
|
116
|
+
### A whole row for a custom element
|
|
117
|
+
|
|
118
|
+
A column lands one element at a time. An optional `lbAcceptRow` beside
|
|
119
|
+
`lbRowsLanded` would hand a custom element its whole row.
|
|
120
|
+
|
|
113
121
|
### Options on `createHub`
|
|
114
122
|
|
|
115
123
|
Global hooks, transaction wrapping, error handling and a CSRF token each
|
package/package.json
CHANGED
|
@@ -244,8 +244,11 @@ row. Anything else gathers its form owner's controls. A `<form>` cannot
|
|
|
244
244
|
wrap a `<tr>`, so an insert row in a table puts its controls in a form
|
|
245
245
|
elsewhere with the HTML `form` attribute. A checkbox is a control: checked
|
|
246
246
|
unless its column is `false` or null, and gathered as `"true"` or `"false"`.
|
|
247
|
-
|
|
248
|
-
and
|
|
247
|
+
A radio button is a control: checked when its `value` is the column's
|
|
248
|
+
value, and the group gathers the one checked, or `""`. In a row template
|
|
249
|
+
the hub stamps its `name` with the row's key, so each row is its own group.
|
|
250
|
+
File inputs are not controls here: they receive no value and are not
|
|
251
|
+
gathered.
|
|
249
252
|
|
|
250
253
|
**A form that adds to a set chosen elsewhere is written once, outside every
|
|
251
254
|
row.** A form cannot sit inside another form or in a table row, so a dialog
|
|
@@ -320,11 +323,10 @@ fills a new row from the last one.
|
|
|
320
323
|
- Rows the database removes with a deleted one: select their keys before
|
|
321
324
|
the delete and drop them too.
|
|
322
325
|
|
|
323
|
-
An update or a delete names its row by key,
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
lands in its place by the order.
|
|
326
|
+
An update or a delete names its row by key, removing a row never reorders
|
|
327
|
+
the rest, and an insert has the new row's key once it has written it, so
|
|
328
|
+
each always has a patch: `createHub` refuses at startup a `rowInsert`,
|
|
329
|
+
`rowUpdate` or `rowDelete` whose `refresh` names its own `rows` query.
|
|
328
330
|
Each handler's `refresh` is its own, and every query in it needs its own
|
|
329
331
|
reason. A list shared by several handlers is a warning sign.
|
|
330
332
|
|