apixa 0.0.0-stage → 0.1.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.
Files changed (64) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +257 -2
  3. package/dist/chunk-6ZX7GAWG.js +10 -0
  4. package/dist/chunk-A3QU5MFP.js +907 -0
  5. package/dist/chunk-DGSIZXRI.js +247 -0
  6. package/dist/chunk-GWZTJ7LM.js +2410 -0
  7. package/dist/chunk-IAQ5YOVE.js +10 -0
  8. package/dist/chunk-KE7UM4VW.js +707 -0
  9. package/dist/chunk-LARJYKRJ.js +117 -0
  10. package/dist/chunk-MLPW6EET.js +10 -0
  11. package/dist/chunk-QVKMZELC.js +10 -0
  12. package/dist/chunk-QY5YMHHN.js +607 -0
  13. package/dist/chunk-QZIU7J3G.js +10 -0
  14. package/dist/chunk-R4FXTZWU.js +10 -0
  15. package/dist/chunk-SIFGLE22.js +794 -0
  16. package/dist/chunk-WNJUPR6P.js +707 -0
  17. package/dist/chunk-ZSLMMDUX.js +727 -0
  18. package/dist/data-3HVQ54F3.js +2550 -0
  19. package/dist/data-ADLKYCN6.js +2211 -0
  20. package/dist/data-B47EIZXW.js +6 -0
  21. package/dist/data-DL4IKJCX.js +6 -0
  22. package/dist/data-GNCSLYM4.js +6 -0
  23. package/dist/data-GTTIEVFI.js +6 -0
  24. package/dist/data-HWX62BTJ.js +4772 -0
  25. package/dist/data-JR6F6HSR.js +6 -0
  26. package/dist/data-OKVHGTXW.js +3544 -0
  27. package/dist/data-PQPSE56A.js +1308 -0
  28. package/dist/data-QF32LRM4.js +3506 -0
  29. package/dist/data-UIVRJ77R.js +2456 -0
  30. package/dist/data-UZVNJUNM.js +2256 -0
  31. package/dist/data-WRWVXGYD.js +6 -0
  32. package/dist/data-Y6374BIT.js +3350 -0
  33. package/dist/index.d.ts +305 -0
  34. package/dist/index.js +80 -0
  35. package/dist/inference-BGj3DlzE.d.ts +1220 -0
  36. package/dist/loader-hhMdppVZ.d.ts +32 -0
  37. package/dist/mock-datasets-Xa9NXK9n.d.ts +178 -0
  38. package/dist/mocking/datasets/comments.d.ts +6 -0
  39. package/dist/mocking/datasets/comments.js +7 -0
  40. package/dist/mocking/datasets/companies.d.ts +6 -0
  41. package/dist/mocking/datasets/companies.js +7 -0
  42. package/dist/mocking/datasets/index.d.ts +18 -0
  43. package/dist/mocking/datasets/index.js +265 -0
  44. package/dist/mocking/datasets/orders.d.ts +6 -0
  45. package/dist/mocking/datasets/orders.js +7 -0
  46. package/dist/mocking/datasets/posts.d.ts +6 -0
  47. package/dist/mocking/datasets/posts.js +7 -0
  48. package/dist/mocking/datasets/products.d.ts +6 -0
  49. package/dist/mocking/datasets/products.js +7 -0
  50. package/dist/mocking/datasets/users.d.ts +6 -0
  51. package/dist/mocking/datasets/users.js +7 -0
  52. package/dist/mocking/index.d.ts +317 -0
  53. package/dist/mocking/index.js +366 -0
  54. package/dist/mocking/node.d.ts +33 -0
  55. package/dist/mocking/node.js +189 -0
  56. package/dist/mocking/register.d.ts +2 -0
  57. package/dist/mocking/register.js +9 -0
  58. package/dist/mutation-controller-BjCOn42y.d.ts +476 -0
  59. package/dist/react/advanced.d.ts +111 -0
  60. package/dist/react/advanced.js +119 -0
  61. package/dist/react/index.d.ts +283 -0
  62. package/dist/react/index.js +303 -0
  63. package/dist/types-mSoi1qGP.d.ts +46 -0
  64. package/package.json +128 -4
@@ -0,0 +1,33 @@
1
+ import { D as Dataset, a as DatasetListItem } from '../types-mSoi1qGP.js';
2
+ export { b as DatasetFieldSchema, c as DatasetMeta, d as DatasetResourceHint, e as DatasetSchema } from '../types-mSoi1qGP.js';
3
+
4
+ interface LoadDatasetOptions {
5
+ /** Absolute or relative path to the datasets root (folders named by dataset id). */
6
+ basePath?: string;
7
+ }
8
+ /**
9
+ * Load a dataset from disk by id (`<root>/<domain>/<id>/meta.json` + `data.json`). `id` may be the
10
+ * meta.id or a relative path under the root. Node only.
11
+ *
12
+ * The root is `options.basePath`, else `APIXA_DATASETS_DIR`, else `./datasets` in the working
13
+ * directory, else the repository's `datasets/` folder when running from a checkout. The published
14
+ * package contains no dataset files, so an installed app must supply a root. Records bundled for
15
+ * browsers and mocks come from `@apixa/mocking/datasets` instead.
16
+ */
17
+ declare function loadDataset(id: string, options?: LoadDatasetOptions): Promise<Dataset>;
18
+
19
+ type ListDatasetsOptions = LoadDatasetOptions;
20
+ /**
21
+ * List the datasets under the datasets root (no network). Walks domain folders; each leaf with
22
+ * `meta.json` is a dataset. The root is resolved as in `loadDataset`: an installed app passes
23
+ * `{ basePath }` (or sets `APIXA_DATASETS_DIR`); a missing root lists nothing.
24
+ */
25
+ declare function listDatasets(options?: ListDatasetsOptions): Promise<DatasetListItem[]>;
26
+ /** Load one dataset by id (registry entry → full dataset). */
27
+ declare function getDataset(id: string, options?: LoadDatasetOptions): Promise<Dataset>;
28
+
29
+ /** Recursively find directories that contain `meta.json`. */
30
+ declare function findDatasetDirs(root: string): Promise<string[]>;
31
+ declare function resolveDatasetDir(root: string, id: string): Promise<string | null>;
32
+
33
+ export { Dataset, DatasetListItem, type ListDatasetsOptions, type LoadDatasetOptions, findDatasetDirs, getDataset, listDatasets, loadDataset, resolveDatasetDir };
@@ -0,0 +1,189 @@
1
+ // packages/mocking/src/load.ts
2
+ import { readFile as readFile2 } from "fs/promises";
3
+ import { join as join2 } from "path";
4
+
5
+ // packages/mocking/src/discover.ts
6
+ import { readdir, readFile, stat } from "fs/promises";
7
+ import { join, relative } from "path";
8
+ async function findDatasetDirs(root) {
9
+ const found = [];
10
+ async function walk(dir) {
11
+ let entries;
12
+ try {
13
+ entries = await readdir(dir);
14
+ } catch {
15
+ return;
16
+ }
17
+ const hasMeta = entries.includes("meta.json");
18
+ if (hasMeta) {
19
+ found.push(dir);
20
+ return;
21
+ }
22
+ for (const name of entries) {
23
+ if (name.startsWith(".")) continue;
24
+ const child = join(dir, name);
25
+ const info = await stat(child).catch(() => null);
26
+ if (info?.isDirectory()) {
27
+ await walk(child);
28
+ }
29
+ }
30
+ }
31
+ await walk(root);
32
+ return found;
33
+ }
34
+ async function resolveDatasetDir(root, id) {
35
+ const direct = join(root, id);
36
+ try {
37
+ const info = await stat(direct);
38
+ if (info.isDirectory()) {
39
+ await readFile(join(direct, "meta.json"), "utf8");
40
+ return direct;
41
+ }
42
+ } catch {
43
+ }
44
+ const dirs = await findDatasetDirs(root);
45
+ for (const dir of dirs) {
46
+ const rel = relative(root, dir).replace(/\\/g, "/");
47
+ if (rel === id) return dir;
48
+ try {
49
+ const meta = JSON.parse(await readFile(join(dir, "meta.json"), "utf8"));
50
+ if (meta.id === id) return dir;
51
+ } catch {
52
+ }
53
+ }
54
+ return null;
55
+ }
56
+
57
+ // packages/mocking/src/paths.ts
58
+ import { existsSync } from "fs";
59
+ import { dirname, resolve } from "path";
60
+ import { fileURLToPath } from "url";
61
+ function resolveDatasetsRoot(basePath) {
62
+ if (basePath) {
63
+ return resolve(basePath);
64
+ }
65
+ if (process.env.APIXA_DATASETS_DIR) {
66
+ return resolve(process.env.APIXA_DATASETS_DIR);
67
+ }
68
+ const fromCwd = resolve(process.cwd(), "datasets");
69
+ if (existsSync(fromCwd)) {
70
+ return fromCwd;
71
+ }
72
+ const fromPackage = resolve(dirname(fileURLToPath(import.meta.url)), "../../../datasets");
73
+ if (existsSync(fromPackage)) {
74
+ return fromPackage;
75
+ }
76
+ return fromCwd;
77
+ }
78
+
79
+ // packages/mocking/src/load.ts
80
+ function assertMeta(value, id) {
81
+ if (!value || typeof value !== "object") {
82
+ throw new Error(`Dataset "${id}" meta.json is not an object`);
83
+ }
84
+ const meta = value;
85
+ if (typeof meta.id !== "string" || !meta.id) {
86
+ throw new Error(`Dataset "${id}" meta.json is missing id`);
87
+ }
88
+ if (typeof meta.title !== "string" || !meta.title) {
89
+ throw new Error(`Dataset "${id}" meta.json is missing title`);
90
+ }
91
+ if (typeof meta.license !== "string" || !meta.license) {
92
+ throw new Error(`Dataset "${id}" meta.json is missing license`);
93
+ }
94
+ if (typeof meta.version !== "string" || !meta.version) {
95
+ throw new Error(`Dataset "${id}" meta.json is missing version`);
96
+ }
97
+ if (!meta.resource || typeof meta.resource.path !== "string" || !meta.resource.path) {
98
+ throw new Error(`Dataset "${id}" meta.json is missing resource.path`);
99
+ }
100
+ if (!meta.schema || !Array.isArray(meta.schema.fields)) {
101
+ throw new Error(`Dataset "${id}" meta.json is missing schema.fields`);
102
+ }
103
+ return {
104
+ id: meta.id,
105
+ title: meta.title,
106
+ description: meta.description,
107
+ license: meta.license,
108
+ version: meta.version,
109
+ resource: {
110
+ path: meta.resource.path,
111
+ idField: meta.resource.idField
112
+ },
113
+ schema: { fields: meta.schema.fields },
114
+ records: typeof meta.records === "number" ? meta.records : 0
115
+ };
116
+ }
117
+ async function loadDataset(id, options = {}) {
118
+ const root = resolveDatasetsRoot(options.basePath);
119
+ const dir = await resolveDatasetDir(root, id);
120
+ if (!dir) {
121
+ throw new Error(
122
+ `Failed to load dataset "${id}": not found under ${root}. The npm package ships no files for "@apixa/mocking/node": pass { basePath } or set APIXA_DATASETS_DIR to a folder of <dataset>/meta.json + data.json.`
123
+ );
124
+ }
125
+ let metaRaw;
126
+ let dataRaw;
127
+ try {
128
+ metaRaw = await readFile2(join2(dir, "meta.json"), "utf8");
129
+ dataRaw = await readFile2(join2(dir, "data.json"), "utf8");
130
+ } catch (error) {
131
+ const reason = error instanceof Error ? error.message : String(error);
132
+ throw new Error(`Failed to load dataset "${id}" from ${dir}: ${reason}`);
133
+ }
134
+ const meta = assertMeta(JSON.parse(metaRaw), id);
135
+ const parsed = JSON.parse(dataRaw);
136
+ if (!Array.isArray(parsed)) {
137
+ throw new Error(`Dataset "${id}" data.json must be a JSON array`);
138
+ }
139
+ const records = parsed;
140
+ return {
141
+ meta: { ...meta, records: records.length },
142
+ records
143
+ };
144
+ }
145
+
146
+ // packages/mocking/src/registry.ts
147
+ import { readFile as readFile3 } from "fs/promises";
148
+ import { join as join3, relative as relative2 } from "path";
149
+ async function listDatasets(options = {}) {
150
+ const root = resolveDatasetsRoot(options.basePath);
151
+ let dirs;
152
+ try {
153
+ dirs = await findDatasetDirs(root);
154
+ } catch (error) {
155
+ const reason = error instanceof Error ? error.message : String(error);
156
+ throw new Error(`Failed to list datasets in ${root}: ${reason}`);
157
+ }
158
+ const items = [];
159
+ for (const dir of dirs) {
160
+ try {
161
+ const raw = await readFile3(join3(dir, "meta.json"), "utf8");
162
+ const meta = JSON.parse(raw);
163
+ if (typeof meta.id !== "string" || typeof meta.title !== "string") continue;
164
+ const rel = relative2(root, dir).replace(/\\/g, "/");
165
+ items.push({
166
+ id: meta.id,
167
+ title: meta.title,
168
+ description: meta.description,
169
+ license: typeof meta.license === "string" ? meta.license : "unknown",
170
+ version: typeof meta.version === "string" ? meta.version : "0.0.0",
171
+ records: typeof meta.records === "number" ? meta.records : 0,
172
+ resourcePath: meta.resource && typeof meta.resource.path === "string" ? meta.resource.path : "",
173
+ path: rel
174
+ });
175
+ } catch {
176
+ }
177
+ }
178
+ return items.sort((a, b) => a.id.localeCompare(b.id));
179
+ }
180
+ async function getDataset(id, options = {}) {
181
+ return loadDataset(id, options);
182
+ }
183
+ export {
184
+ findDatasetDirs,
185
+ getDataset,
186
+ listDatasets,
187
+ loadDataset,
188
+ resolveDatasetDir
189
+ };
@@ -0,0 +1,2 @@
1
+
2
+ export { }
@@ -0,0 +1,9 @@
1
+ import {
2
+ registerMockDatasetLoader
3
+ } from "../chunk-GWZTJ7LM.js";
4
+ import {
5
+ loadDatasetRecords
6
+ } from "../chunk-LARJYKRJ.js";
7
+
8
+ // packages/mocking/src/register.ts
9
+ registerMockDatasetLoader(loadDatasetRecords);