rastack 0.0.44 → 0.0.45

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/test/dev.spec.ts CHANGED
@@ -1,18 +1,24 @@
1
1
  import {
2
+ ADMIN_DEFAULTS,
2
3
  DEV_DEFAULTS,
3
4
  WASM_ENTRY,
4
5
  contentType,
6
+ parseAdminArgs,
5
7
  parseDevArgs,
6
8
  renderShell,
7
9
  wasmBundleCandidates,
8
10
  } from "../src/dev/harness";
9
11
  import {
12
+ boolFilterOptions,
10
13
  buildWriteBody,
11
14
  changelistHeaders,
12
15
  coerceFormValue,
16
+ distinctValueOptions,
13
17
  errorDetail,
14
18
  fieldControlType,
19
+ filterableFields,
15
20
  findResource,
21
+ fkFilterOptions,
16
22
  formFields,
17
23
  initialFormValues,
18
24
  listPath,
@@ -22,6 +28,7 @@ import {
22
28
  pageCount,
23
29
  parseManifest,
24
30
  readListEnvelope,
31
+ withFilters,
25
32
  PAGE_SIZE,
26
33
  type AdminResource,
27
34
  } from "../admin/adapters";
@@ -60,6 +67,26 @@ describe("rastack dev — arg parsing", () => {
60
67
  });
61
68
  });
62
69
 
70
+ describe("rastack admin — arg parsing", () => {
71
+ it("defaults to the server's port 8000 and the same dirs as dev", () => {
72
+ expect(parseAdminArgs([])).toEqual(ADMIN_DEFAULTS);
73
+ expect(ADMIN_DEFAULTS.port).toBe(8000);
74
+ expect(ADMIN_DEFAULTS.warehouseDir).toBe("data/warehouse");
75
+ });
76
+
77
+ it("reads --port, --warehouse, --out, --no-open and a positional dir", () => {
78
+ expect(
79
+ parseAdminArgs(["res", "--port", "9100", "--warehouse", "wh", "--no-open"]),
80
+ ).toEqual({
81
+ resourcesDir: "res",
82
+ outDir: ".rastack",
83
+ warehouseDir: "wh",
84
+ port: 9100,
85
+ open: false,
86
+ });
87
+ });
88
+ });
89
+
63
90
  describe("rastack dev — content types", () => {
64
91
  it("maps wasm to application/wasm (required for streaming instantiation)", () => {
65
92
  expect(contentType("/wasm/rastack_wasm_bg.wasm")).toBe("application/wasm");
@@ -275,3 +302,72 @@ describe("admin adapters — forms", () => {
275
302
  expect(errorDetail({})).toBe("Request failed");
276
303
  });
277
304
  });
305
+
306
+ describe("admin adapters — Linear-style filters", () => {
307
+ const resources = parseManifest(MANIFEST);
308
+ const airport = findResource(resources, "airports", "airport")!;
309
+ const terminal = findResource(resources, "airports", "terminal")!;
310
+
311
+ it("offers FK, boolean and non-unique string fields as facets", () => {
312
+ // `airport`: `code` is unique (an identifier, not a facet), `name` is a
313
+ // plain string → a single `choice` facet.
314
+ expect(filterableFields(airport)).toEqual([
315
+ { name: "name", label: "Name", kind: "choice" },
316
+ ]);
317
+ // `terminal`: FK + string + bool all filterable.
318
+ expect(filterableFields(terminal)).toEqual([
319
+ {
320
+ name: "airport",
321
+ label: "Airport",
322
+ kind: "fk",
323
+ relation: { app: "airports", model: "airport" },
324
+ },
325
+ { name: "label", label: "Label", kind: "choice" },
326
+ { name: "active", label: "Active", kind: "bool" },
327
+ ]);
328
+ });
329
+
330
+ it("booleans are True/False", () => {
331
+ expect(boolFilterOptions()).toEqual([
332
+ { value: "true", label: "True" },
333
+ { value: "false", label: "False" },
334
+ ]);
335
+ });
336
+
337
+ it("distinct values become sorted options, dropping empties", () => {
338
+ const rows = [
339
+ { label: "B" },
340
+ { label: "A" },
341
+ { label: "B" },
342
+ { label: "" },
343
+ { label: null },
344
+ ];
345
+ expect(distinctValueOptions(rows, "label")).toEqual([
346
+ { value: "A", label: "A" },
347
+ { value: "B", label: "B" },
348
+ ]);
349
+ });
350
+
351
+ it("drops a high-cardinality field (no useful facet)", () => {
352
+ const rows = Array.from({ length: 5 }, (_, i) => ({ v: `x${i}` }));
353
+ expect(distinctValueOptions(rows, "v", 3)).toEqual([]);
354
+ });
355
+
356
+ it("FK options reuse the option-label heuristic against the target rows", () => {
357
+ expect(
358
+ fkFilterOptions([
359
+ { id: 1, code: "JFK" },
360
+ { id: 2, code: "LHR" },
361
+ ]),
362
+ ).toEqual([
363
+ { value: "1", label: "JFK (#1)" },
364
+ { value: "2", label: "LHR (#2)" },
365
+ ]);
366
+ });
367
+
368
+ it("merges filters under the reserved keys (page/search always win)", () => {
369
+ expect(
370
+ withFilters({ page: "2", search: "x" }, { status: "active", page: "9" }),
371
+ ).toEqual({ status: "active", page: "2", search: "x" });
372
+ });
373
+ });
@@ -375,7 +375,7 @@ function __wbg_get_imports() {
375
375
  return ret;
376
376
  },
377
377
  __wbindgen_cast_0000000000000001: function(arg0, arg1) {
378
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 84, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
378
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 80, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
379
379
  const ret = makeMutClosure(arg0, arg1, wasm_bindgen_1a7aa9db5392c486___convert__closures_____invoke___wasm_bindgen_1a7aa9db5392c486___JsValue__core_7d5f0a2ba6a62c33___result__Result_____wasm_bindgen_1a7aa9db5392c486___JsError___true_);
380
380
  return ret;
381
381
  },
Binary file