@getaster/mock 0.2.0 → 0.3.0

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/NOTICE CHANGED
@@ -1,10 +1,9 @@
1
- Aster UI
1
+ @getaster/mock
2
2
  Copyright 2026 Aster UI contributors
3
3
 
4
- Aster UI source and the separately supplied OData mock WebAssembly binary are
5
- licensed under the Apache License, Version 2.0. Third-party components retain
6
- their respective licenses. The binary's attribution inventory and license texts
7
- are supplied in packages/mock/wasm/; packages include those notices when shipped.
4
+ Aster UI code in this package is licensed under the Apache License, Version 2.0.
5
+ See LICENSE. Separately installed dependencies retain their respective licenses.
8
6
 
9
- Geist and IBM Plex Mono fonts retain their SIL Open Font License notices.
10
- ECharts is an optional separately loaded third-party runtime.
7
+ The bundled OData mock WebAssembly binary includes third-party components.
8
+ Their attribution inventory is in wasm/NOTICE and their license texts are in
9
+ wasm/licenses/.
package/README.md CHANGED
@@ -1,7 +1,90 @@
1
1
  # @getaster/mock
2
2
 
3
- Aster UI mock.
3
+ A local OData service for Aster UI development, examples and integration tests.
4
+ The service runs in WebAssembly and exposes the same transport interface used
5
+ by `@getaster/data`, so a test can exercise metadata, queries and writes without
6
+ starting an HTTP server.
4
7
 
5
- Documentation: https://ui.getaster.now/docs/guide/library.html
8
+ This is a development tool, not a production database or authorization boundary.
9
+ Aster is pre-1.0; APIs may change.
6
10
 
7
- Licensed under Apache-2.0. See LICENSE and NOTICE.
11
+ ## Install
12
+
13
+ ```sh
14
+ npm install @getaster/data
15
+ npm install --save-dev @getaster/mock
16
+ ```
17
+
18
+ The package includes its WebAssembly binary and license notices. No Rust compiler
19
+ or install script is required. It provides ES modules and TypeScript declarations;
20
+ Node.js use requires Node 22 or later. Browser builds must serve the WASM asset
21
+ over HTTP or pass its bytes explicitly.
22
+
23
+ ## Run a local service in Node.js
24
+
25
+ TypeScript projects using this Node.js example also need `@types/node` as a
26
+ development dependency.
27
+
28
+ ```ts
29
+ import { readFileSync } from 'node:fs';
30
+ import { DataContext } from '@getaster/data';
31
+ import { createMockService } from '@getaster/mock';
32
+
33
+ const metadata = {
34
+ $Version: '4.01',
35
+ $EntityContainer: 'Demo.Container',
36
+ Demo: {
37
+ Project: {
38
+ $Kind: 'EntityType', $Key: ['id'],
39
+ id: { $Type: 'Edm.Int32' },
40
+ name: { $Type: 'Edm.String' },
41
+ },
42
+ Container: {
43
+ $Kind: 'EntityContainer',
44
+ Projects: { $Collection: true, $Type: 'Demo.Project' },
45
+ },
46
+ },
47
+ };
48
+ const wasm = readFileSync(new URL(
49
+ import.meta.resolve('@getaster/mock/wasm/odata_mock.wasm')
50
+ ));
51
+ const mock = await createMockService({
52
+ metadata, wasm,
53
+ data: { Projects: [{ id: 1, name: 'First project' }] },
54
+ });
55
+ const ctx = await DataContext.connect(mock.transport);
56
+ const projects = ctx.collection({ set: 'Projects' });
57
+ try {
58
+ await projects.view(0, 10);
59
+ if (projects.error.value) throw projects.error.value;
60
+ console.log(projects.items.value);
61
+ } finally {
62
+ ctx.release(projects);
63
+ }
64
+ ```
65
+
66
+ ## Exercise application behaviour
67
+
68
+ `mock.faults.latencyMs` and `writeLatencyMs` simulate slow requests;
69
+ `mock.faults.failNext(503)` fails the next transport request. Use `mock.external()`
70
+ to simulate another user's write and test stale edits. ETags are opaque values:
71
+ preserve and return them rather than constructing them in tests.
72
+
73
+ Counts are exact by default. The optional `countEstimate` setting simulates an
74
+ estimate-producing service for client tests; it is not Web Data's normal count
75
+ behaviour. Optional storage supports persistence; `dump()`, `flush()` and
76
+ `reset()` let tests control state. Worker helpers are available for browser use.
77
+
78
+ ## Documentation and support
79
+
80
+ - [Installation and distribution](https://ui.getaster.now/docs/guide/library.html)
81
+ - [Working browser example](https://ui.getaster.now/docs/guide/getting-started.html)
82
+ - [API reference](https://ui.getaster.now/docs/reference/)
83
+ - [Report a bug](https://github.com/GetAster/aster-ui/issues)
84
+
85
+ ## License
86
+
87
+ Aster UI code is Apache-2.0; see `LICENSE` and `NOTICE`. The bundled WebAssembly
88
+ binary includes third-party components: their attribution inventory is in
89
+ `wasm/NOTICE`, with license texts in `wasm/licenses/`. Preserve these files when
90
+ redistributing the binary.
package/dist/service.d.ts CHANGED
@@ -21,11 +21,11 @@ export interface MockServiceOptions {
21
21
  /** How long a save waits for more writes to share it; 200 ms by default. */
22
22
  saveDelayMs?: number;
23
23
  /**
24
- * Counts become estimates, as a database planner's would: the exact count
25
- * times this factor, rounded up, marked `@AsterData.CountEstimated`. A
26
- * set's `AsterData.CountThreshold` then makes its count exact below the
27
- * threshold and leaves it out at or above it, as aster-server does.
28
- * `Prefer: aster.count=exact` still gets the exact count.
24
+ * Test-only simulation for top-level entity-set reads: multiply the exact
25
+ * count by this positive factor, round up and mark CountEstimated.
26
+ * CountThreshold makes it exact below the threshold and absent at or above.
27
+ * Prefer: aster.count=exact bypasses simulation. Web Data itself returns
28
+ * exact counts; this option exercises clients of services with estimates.
29
29
  */
30
30
  countEstimate?: number;
31
31
  }
package/dist/service.js CHANGED
@@ -2,6 +2,9 @@ import { instantiate, loadWasmBytes } from "./engine.js";
2
2
  const DEFAULT_WASM = new URL("../wasm/odata_mock.wasm", import.meta.url);
3
3
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
4
4
  export async function createMockService(options) {
5
+ if (options.countEstimate !== undefined && (!Number.isFinite(options.countEstimate) || options.countEstimate <= 0)) {
6
+ throw new RangeError("countEstimate must be a positive finite factor");
7
+ }
5
8
  const now = options.now ?? (() => new Date().toISOString());
6
9
  const engine = await instantiate(await loadWasmBytes(options.wasm ?? DEFAULT_WASM), () => Date.parse(now()));
7
10
  const { storage } = options;
@@ -11,6 +14,7 @@ export async function createMockService(options) {
11
14
  maxPageSize: options.maxPageSize,
12
15
  countEstimate: options.countEstimate,
13
16
  data: from.data,
17
+ revisions: from.revisions,
14
18
  });
15
19
  init((await storage?.load()) ?? { data: options.data });
16
20
  // Storage holds the whole dataset, so writes close together share one
package/dist/storage.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  export interface Dump {
2
2
  data: Record<string, unknown[]>;
3
+ /** Internal concurrency counters, keyed by set and key predicate. Keep with data when persisting. */
4
+ revisions?: Record<string, Record<string, string>>;
3
5
  }
4
6
  export interface MockStorage {
5
7
  load(): Promise<Dump | undefined>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getaster/mock",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -11,7 +11,7 @@
11
11
  "./wasm/odata_mock.wasm": "./wasm/odata_mock.wasm"
12
12
  },
13
13
  "dependencies": {
14
- "@getaster/data": "0.2.0"
14
+ "@getaster/data": "0.3.0"
15
15
  },
16
16
  "license": "Apache-2.0",
17
17
  "repository": {
@@ -19,6 +19,18 @@
19
19
  "url": "git+https://github.com/GetAster/aster-ui.git",
20
20
  "directory": "packages/mock"
21
21
  },
22
+ "description": "Local OData mock service powered by WebAssembly for Aster UI tests and demos.",
23
+ "homepage": "https://ui.getaster.now/docs/guide/library.html",
24
+ "bugs": {
25
+ "url": "https://github.com/GetAster/aster-ui/issues"
26
+ },
27
+ "keywords": [
28
+ "odata",
29
+ "mock",
30
+ "webassembly",
31
+ "testing",
32
+ "typescript"
33
+ ],
22
34
  "types": "./dist/index.d.ts",
23
35
  "publishConfig": {
24
36
  "access": "public"
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "license": "Apache-2.0",
3
- "sha256": "cbdab46f22434ac0a8caf59d089eb6f6c53a4fc677914cb7005696a5e95d738d",
4
- "bytes": 4631621,
3
+ "sha256": "8aa8844f481eb34e4cdfe313bd62e3601333e61cb4e535100f9f52774e73ec6b",
4
+ "bytes": 5129972,
5
5
  "compiler": "rustc 1.96.0 (ac68faa20 2026-05-25)",
6
6
  "format": "wasm32-wasip1",
7
7
  "dependencies": [
@@ -742,6 +742,14 @@
742
742
  "licenses/cb5aedb296c5246d-LICENSE-MIT"
743
743
  ]
744
744
  },
745
+ {
746
+ "name": "xxhash-rust",
747
+ "version": "0.8.19",
748
+ "license": "BSL-1.0",
749
+ "notices": [
750
+ "licenses/c9bff75738922193-LICENSE"
751
+ ]
752
+ },
745
753
  {
746
754
  "name": "zerocopy",
747
755
  "version": "0.8.63",
@@ -0,0 +1,23 @@
1
+ Boost Software License - Version 1.0 - August 17th, 2003
2
+
3
+ Permission is hereby granted, free of charge, to any person or organization
4
+ obtaining a copy of the software and accompanying documentation covered by
5
+ this license (the "Software") to use, reproduce, display, distribute,
6
+ execute, and transmit the Software, and to prepare derivative works of the
7
+ Software, and to permit third-parties to whom the Software is furnished to
8
+ do so, all subject to the following:
9
+
10
+ The copyright notices in the Software and this entire statement, including
11
+ the above license grant, this restriction and the following disclaimer,
12
+ must be included in all copies of the Software, in whole or in part, and
13
+ all derivative works of the Software, unless such copies or derivative
14
+ works are solely in the form of machine-executable object code generated by
15
+ a source language processor.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
20
+ SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
21
+ FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
22
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23
+ DEALINGS IN THE SOFTWARE.
Binary file