sdcmodeler 4.3.2__tar.gz → 4.4.1__tar.gz

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 (23) hide show
  1. {sdcmodeler-4.3.2 → sdcmodeler-4.4.1}/PKG-INFO +4 -2
  2. {sdcmodeler-4.3.2 → sdcmodeler-4.4.1}/README.md +3 -1
  3. {sdcmodeler-4.3.2 → sdcmodeler-4.4.1}/pyproject.toml +1 -1
  4. {sdcmodeler-4.3.2 → sdcmodeler-4.4.1}/src/sdcmodeler/__init__.py +1 -1
  5. {sdcmodeler-4.3.2 → sdcmodeler-4.4.1}/src/sdcmodeler/cli.py +9 -1
  6. {sdcmodeler-4.3.2 → sdcmodeler-4.4.1}/src/sdcmodeler/client.py +9 -0
  7. sdcmodeler-4.4.1/src/sdcmodeler/kits.py +86 -0
  8. {sdcmodeler-4.3.2 → sdcmodeler-4.4.1}/src/sdcmodeler/mcp_server.py +47 -2
  9. {sdcmodeler-4.3.2 → sdcmodeler-4.4.1}/src/sdcmodeler.egg-info/PKG-INFO +4 -2
  10. {sdcmodeler-4.3.2 → sdcmodeler-4.4.1}/src/sdcmodeler.egg-info/SOURCES.txt +2 -0
  11. sdcmodeler-4.4.1/tests/test_kits.py +69 -0
  12. {sdcmodeler-4.3.2 → sdcmodeler-4.4.1}/tests/test_mcp_server.py +19 -1
  13. {sdcmodeler-4.3.2 → sdcmodeler-4.4.1}/LICENSE +0 -0
  14. {sdcmodeler-4.3.2 → sdcmodeler-4.4.1}/setup.cfg +0 -0
  15. {sdcmodeler-4.3.2 → sdcmodeler-4.4.1}/src/sdcmodeler/pricing.py +0 -0
  16. {sdcmodeler-4.3.2 → sdcmodeler-4.4.1}/src/sdcmodeler.egg-info/dependency_links.txt +0 -0
  17. {sdcmodeler-4.3.2 → sdcmodeler-4.4.1}/src/sdcmodeler.egg-info/entry_points.txt +0 -0
  18. {sdcmodeler-4.3.2 → sdcmodeler-4.4.1}/src/sdcmodeler.egg-info/requires.txt +0 -0
  19. {sdcmodeler-4.3.2 → sdcmodeler-4.4.1}/src/sdcmodeler.egg-info/top_level.txt +0 -0
  20. {sdcmodeler-4.3.2 → sdcmodeler-4.4.1}/tests/test_cli.py +0 -0
  21. {sdcmodeler-4.3.2 → sdcmodeler-4.4.1}/tests/test_client.py +0 -0
  22. {sdcmodeler-4.3.2 → sdcmodeler-4.4.1}/tests/test_pricing.py +0 -0
  23. {sdcmodeler-4.3.2 → sdcmodeler-4.4.1}/tests/test_registry_launch.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sdcmodeler
3
- Version: 4.3.2
3
+ Version: 4.4.1
4
4
  Summary: The modeler's client for SDCStudio: search the catalog, estimate, assemble and publish SDC4 data models, generate applications; a CLI and an MCP server over one client
5
5
  Author: Axius SDC, Inc.
6
6
  License-Expression: Apache-2.0
@@ -88,6 +88,7 @@ sdcmodeler build tree.json --title "Vitals" --wait
88
88
  sdcmodeler job <job_ct_id>
89
89
  sdcmodeler package <ct_id> --dir ./packages
90
90
  sdcmodeler app <ct_id> --profile lightweight --dir ./apps
91
+ sdcmodeler kit <ct_id> --project ./my-app
91
92
  sdcmodeler wallet
92
93
  ```
93
94
 
@@ -112,13 +113,14 @@ A JSON-RPC 2.0 stdio server, no SDK, the way sdcvalidator and sdcgovernance are
112
113
  | `job_status` | one job by id: status, step, cost so far, the model's links | no |
113
114
  | `download_package` | a model's package ZIP with the key, including a model in a private project; builds a missing package first (free, once) unless `generate` is false | no |
114
115
  | `generate_app` | generate and download the application; needs `confirm_charge`; 1,500 credits the first time, free after | yes |
116
+ | `add_supabase_kit` | write a model's Supabase kit into a project (`project_dir`); needs `confirm_charge`; charged with the application, once per model | yes |
115
117
  | `wallet` | balance in credits and the key's policy | no |
116
118
 
117
119
  **The policy lives in the server.** No spend without an estimate shown: `build_model` takes the `estimate_id` that `estimate_model` returned for the same title and tree in this process. Stop at the key's limit: a build whose estimate exceeds what the key may still spend is refused before the server is asked. Never pay: a 402 is reported with the wallet page's address and the tool stops. No tool takes a URL, a key or a payment method as an argument; the key is the environment the server starts with.
118
120
 
119
121
  ## The package or the application
120
122
 
121
- `get_model` names the artifacts: the XSD 1.1 schema, the instance template, JSON, JSON-LD, SHACL, HTML, GraphQL. The package is a contract with no runtime attached; a feature inside an existing application implements on it, in any language, validating every record locally with [sdcvalidator](https://pypi.org/project/sdcvalidator/). The generated application (lightweight or enterprise profile) is a Django implementation on the same package, right when the feature is a new service. [CordovaOS](https://github.com/Axius-SDC/CordovaOS) is ten of them sharing data with zero integration code.
123
+ `get_model` names the artifacts: the XSD 1.1 schema, the instance template, JSON, JSON-LD, SHACL, HTML, GraphQL. The package is a contract with no runtime attached; a feature inside an existing application implements on it, in any language, validating every record locally with [sdcvalidator](https://pypi.org/project/sdcvalidator/). The generated application (lightweight or enterprise profile) is a Django implementation on the same package, right when the feature is a new service. The Supabase kit is the same for a TypeScript app on Supabase: typed code for the model's records, migrations, and a gate (an Edge Function) that validates every record against the published model before storing it. `sdcmodeler kit` and `add_supabase_kit` write it into the project: the first model brings the project base, each further one adds its kit and one migration, numbered after the project's latest, and a component already in the project is never rewritten. Apply with Supabase's CLI (`supabase db push`, `supabase functions deploy gate`). [CordovaOS](https://github.com/Axius-SDC/CordovaOS) is ten of them sharing data with zero integration code.
122
124
 
123
125
  ## What is not here
124
126
 
@@ -62,6 +62,7 @@ sdcmodeler build tree.json --title "Vitals" --wait
62
62
  sdcmodeler job <job_ct_id>
63
63
  sdcmodeler package <ct_id> --dir ./packages
64
64
  sdcmodeler app <ct_id> --profile lightweight --dir ./apps
65
+ sdcmodeler kit <ct_id> --project ./my-app
65
66
  sdcmodeler wallet
66
67
  ```
67
68
 
@@ -86,13 +87,14 @@ A JSON-RPC 2.0 stdio server, no SDK, the way sdcvalidator and sdcgovernance are
86
87
  | `job_status` | one job by id: status, step, cost so far, the model's links | no |
87
88
  | `download_package` | a model's package ZIP with the key, including a model in a private project; builds a missing package first (free, once) unless `generate` is false | no |
88
89
  | `generate_app` | generate and download the application; needs `confirm_charge`; 1,500 credits the first time, free after | yes |
90
+ | `add_supabase_kit` | write a model's Supabase kit into a project (`project_dir`); needs `confirm_charge`; charged with the application, once per model | yes |
89
91
  | `wallet` | balance in credits and the key's policy | no |
90
92
 
91
93
  **The policy lives in the server.** No spend without an estimate shown: `build_model` takes the `estimate_id` that `estimate_model` returned for the same title and tree in this process. Stop at the key's limit: a build whose estimate exceeds what the key may still spend is refused before the server is asked. Never pay: a 402 is reported with the wallet page's address and the tool stops. No tool takes a URL, a key or a payment method as an argument; the key is the environment the server starts with.
92
94
 
93
95
  ## The package or the application
94
96
 
95
- `get_model` names the artifacts: the XSD 1.1 schema, the instance template, JSON, JSON-LD, SHACL, HTML, GraphQL. The package is a contract with no runtime attached; a feature inside an existing application implements on it, in any language, validating every record locally with [sdcvalidator](https://pypi.org/project/sdcvalidator/). The generated application (lightweight or enterprise profile) is a Django implementation on the same package, right when the feature is a new service. [CordovaOS](https://github.com/Axius-SDC/CordovaOS) is ten of them sharing data with zero integration code.
97
+ `get_model` names the artifacts: the XSD 1.1 schema, the instance template, JSON, JSON-LD, SHACL, HTML, GraphQL. The package is a contract with no runtime attached; a feature inside an existing application implements on it, in any language, validating every record locally with [sdcvalidator](https://pypi.org/project/sdcvalidator/). The generated application (lightweight or enterprise profile) is a Django implementation on the same package, right when the feature is a new service. The Supabase kit is the same for a TypeScript app on Supabase: typed code for the model's records, migrations, and a gate (an Edge Function) that validates every record against the published model before storing it. `sdcmodeler kit` and `add_supabase_kit` write it into the project: the first model brings the project base, each further one adds its kit and one migration, numbered after the project's latest, and a component already in the project is never rewritten. Apply with Supabase's CLI (`supabase db push`, `supabase functions deploy gate`). [CordovaOS](https://github.com/Axius-SDC/CordovaOS) is ten of them sharing data with zero integration code.
96
98
 
97
99
  ## What is not here
98
100
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "sdcmodeler"
7
- version = "4.3.2"
7
+ version = "4.4.1"
8
8
  description = "The modeler's client for SDCStudio: search the catalog, estimate, assemble and publish SDC4 data models, generate applications; a CLI and an MCP server over one client"
9
9
  license = "Apache-2.0"
10
10
  requires-python = ">=3.10"
@@ -17,7 +17,7 @@ servers: sdcvalidator validates, sdcgovernance governs, sdcreader reads,
17
17
  sdcmodeler models. It also names the concept SDCStudio already has: every user
18
18
  is a Modeler, and the Modeler's projects scope every call.
19
19
  """
20
- __version__ = "4.3.2"
20
+ __version__ = "4.4.1"
21
21
 
22
22
  from sdcmodeler.client import ( # noqa: E402
23
23
  AssemblyRefused,
@@ -8,6 +8,7 @@ from pathlib import Path
8
8
 
9
9
  from sdcmodeler import __version__
10
10
  from sdcmodeler.client import SDCStudioClient, SDCStudioError
11
+ from sdcmodeler.kits import KitConflictError, write_kit
11
12
 
12
13
 
13
14
  def _print(data) -> None:
@@ -79,6 +80,13 @@ def build_parser() -> argparse.ArgumentParser:
79
80
  return {"generated": generated, "path": str(path), "charged": charged}
80
81
  s.set_defaults(func=_app)
81
82
 
83
+ s = sub.add_parser("kit", help="write a published model's Supabase kit into a project (1,500 credits the first time, shared with app)")
84
+ s.add_argument("ct_id"); s.add_argument("--project", default=".", help="the project holding supabase/ (default: here)")
85
+ def _kit(c, a):
86
+ kit = c.supabase_kit(a.ct_id)
87
+ return {"models": kit["models"], "written": write_kit(a.project, kit), "charged": kit.get("charged")}
88
+ s.set_defaults(func=_kit)
89
+
82
90
  s = sub.add_parser("wallet", help="the wallet balance in credits and this key's policy")
83
91
  s.set_defaults(func=lambda c, a: {"wallet": c.wallet(), "key": c.key_policy()})
84
92
 
@@ -102,7 +110,7 @@ def main(argv: list[str] | None = None) -> int:
102
110
  try:
103
111
  _print(args.func(client, args))
104
112
  return 0
105
- except SDCStudioError as exc:
113
+ except (SDCStudioError, KitConflictError) as exc:
106
114
  sys.stderr.write(f"{exc}\n")
107
115
  return 1
108
116
  finally:
@@ -330,6 +330,15 @@ class SDCStudioClient:
330
330
  payload["async"] = True
331
331
  return self._post(f"/api/v1/dmgen/dms/{ct_id}/generate_app/", payload)
332
332
 
333
+ def supabase_kit(self, ct_id: str) -> dict[str, Any]:
334
+ """
335
+ The published model's governed data kit for Supabase, as data (SDCStudio 4.26.0): its files by path,
336
+ the base migration and the model's, unversioned, and ``charged``. ``sdcmodeler.kits.write_kit`` writes
337
+ it into a project. Charged as the application is: the first download of a model by a user, kit or
338
+ application, costs 1,500 credits; later ones are free.
339
+ """
340
+ return self._get(f"/api/v1/dmgen/dms/{ct_id}/supabase_kit/")
341
+
333
342
  def download_app(self, ct_id: str, dest_dir: str | Path, profile: str = "lightweight") -> tuple[Path, bool | None]:
334
343
  """
335
344
  Save the generated application and return ``(path, charged)``.
@@ -0,0 +1,86 @@
1
+ """
2
+ Write a governed data kit, as SDCStudio answers it, into a Supabase project.
3
+
4
+ SDCStudio generates a published model's kit (GET /api/v1/dmgen/dms/<ct_id>/supabase_kit/): every file by its
5
+ path in the project, the project base's migration and the model's migration, each without a version. This
6
+ writes it, as SDCStudio's own project writer does:
7
+
8
+ supabase/functions/_shared/sdc/ the kit: runtime/, components/, models/ and models/index.ts
9
+ supabase/functions/gate/ the gate, the one way a record reaches gdr_records
10
+ supabase/migrations/ <version>_sdc_base.sql once, then <version>_sdc_dm_<ct_id>.sql per model
11
+
12
+ A published component never changes, so a component file that exists and differs is refused, never rewritten.
13
+ Each migration is written once, numbered after the project's latest. models/index.ts lists every model in the
14
+ kit. Apply with Supabase's own CLI (`supabase db push`, `supabase functions deploy gate`).
15
+ """
16
+ from __future__ import annotations
17
+
18
+ import re
19
+ from datetime import datetime, timedelta, timezone
20
+ from pathlib import Path
21
+ from typing import Any, Iterable
22
+
23
+ KIT = "supabase/functions/_shared/sdc"
24
+ MIGRATIONS = "supabase/migrations"
25
+ COMPONENTS = f"{KIT}/components/"
26
+ VERSIONED = re.compile(r"\d{14}_")
27
+
28
+
29
+ class KitConflictError(Exception):
30
+ """A file the kit would write already exists with other content."""
31
+
32
+
33
+ def models_index(model_files: Iterable[str], generator: str) -> str:
34
+ cts = sorted(m[len("dm-"):-len(".ts")] for m in model_files)
35
+ lines = [f"// Generated by the SDCStudio kit generator {generator}: every model in this kit, by its root element (dm-<ct_id>).",
36
+ "// Rewritten when a model kit is added.", ""]
37
+ lines += [f"import * as dm_{ct} from './dm-{ct}.ts';" for ct in cts]
38
+ lines += ["", "export const models = {", *[f' "dm-{ct}": dm_{ct},' for ct in cts], "} as const;", ""]
39
+ return "\n".join(lines)
40
+
41
+
42
+ def _write(root: Path, path: str, text: str, written: list[str], replace: bool) -> None:
43
+ target = root / path
44
+ if target.exists():
45
+ if target.read_text(encoding="utf-8") == text:
46
+ return
47
+ if not replace:
48
+ raise KitConflictError(f"{path} exists and differs; a published component never changes")
49
+ target.parent.mkdir(parents=True, exist_ok=True)
50
+ # newline="" keeps the generated text byte for byte on every platform.
51
+ with open(target, "w", encoding="utf-8", newline="") as f:
52
+ f.write(text)
53
+ written.append(path)
54
+
55
+
56
+ def write_kit(root: str | Path, kit: dict[str, Any], now: datetime | None = None) -> list[str]:
57
+ """Write a kit (SDCStudio's supabase_kit answer) into the project at ``root``. Returns the paths written."""
58
+ root = Path(root)
59
+ written: list[str] = []
60
+ # Refuse before writing anything: a differing component is found first, not halfway through.
61
+ for path, text in kit["files"].items():
62
+ target = root / path
63
+ if path.startswith(COMPONENTS) and target.exists() and target.read_text(encoding="utf-8") != text:
64
+ raise KitConflictError(f"{path} exists and differs; a published component never changes")
65
+ for path, text in kit["files"].items():
66
+ # The runtime, the gate and the model files may be regenerated; a component file never differs.
67
+ _write(root, path, text, written, replace=not path.startswith(COMPONENTS))
68
+ models = root / KIT / "models"
69
+ _write(root, f"{KIT}/models/index.ts", models_index((p.name for p in models.glob("dm-*.ts")), kit["generator"]),
70
+ written, replace=True)
71
+
72
+ migrations = root / MIGRATIONS
73
+ existing = [p.name for p in migrations.glob("*.sql")] if migrations.exists() else []
74
+ clock = (now or datetime.now(timezone.utc)).replace(microsecond=0)
75
+ latest = max((n[:14] for n in existing if VERSIONED.match(n)), default=None)
76
+ if latest:
77
+ after = datetime.strptime(latest, "%Y%m%d%H%M%S").replace(tzinfo=timezone.utc) + timedelta(seconds=1)
78
+ clock = max(clock, after)
79
+ for migration in [kit["base_migration"], *kit["migrations"]]:
80
+ # Each migration is written once, whatever version it was given.
81
+ if any(n[15:] == migration["name"] for n in existing if VERSIONED.match(n)):
82
+ continue
83
+ _write(root, f"{MIGRATIONS}/{clock.strftime('%Y%m%d%H%M%S')}_{migration['name']}", migration["sql"],
84
+ written, replace=False)
85
+ clock += timedelta(seconds=1)
86
+ return written
@@ -35,6 +35,7 @@ from sdcmodeler.client import (
35
35
  SDCStudioClient,
36
36
  SDCStudioError,
37
37
  )
38
+ from sdcmodeler.kits import KitConflictError, write_kit
38
39
  from sdcmodeler.pricing import DOWNLOAD_APP_CREDITS
39
40
 
40
41
  JSONRPC_VERSION = "2.0"
@@ -196,6 +197,31 @@ TOOLS: list[dict[str, Any]] = [
196
197
  "required": ["ct_id"],
197
198
  },
198
199
  },
200
+ {
201
+ "name": "add_supabase_kit",
202
+ "description": (
203
+ "Write a published model's governed data kit into a Supabase project: typed TypeScript for the "
204
+ "model's records, the gate (an Edge Function that validates every record against the published "
205
+ "model before storing it) and the migrations. The first call writes the project base too; call "
206
+ "again for each further model. Components already in the project are never rewritten, and each "
207
+ "migration is written once, numbered after the project's latest. Then apply them with Supabase's "
208
+ "own CLI or MCP server (supabase db push; supabase functions deploy gate). The first download of "
209
+ "a model by this user, kit or application, costs 1,500 credits; later downloads of the same model "
210
+ "are free. Needs confirm_charge true, after the person has agreed."
211
+ ),
212
+ "inputSchema": {
213
+ "type": "object",
214
+ "properties": {
215
+ "ct_id": {"type": "string"},
216
+ "project_dir": {
217
+ "type": "string",
218
+ "description": "The project holding supabase/, relative to the server's output directory. Default: the output directory.",
219
+ },
220
+ "confirm_charge": {"type": "boolean", "default": False},
221
+ },
222
+ "required": ["ct_id"],
223
+ },
224
+ },
199
225
  {
200
226
  "name": "wallet",
201
227
  "description": "The wallet balance in credits and this key's policy: scopes, spending limit, what it has spent, expiry. Free.",
@@ -350,6 +376,23 @@ def _handle_generate_app(args: dict) -> Any:
350
376
  return {"generated": generated, "path": str(path), "charged": charged, "profile": profile}
351
377
 
352
378
 
379
+ def _handle_add_supabase_kit(args: dict) -> Any:
380
+ ct_id = _string(args, "ct_id", required=True)
381
+ project = (_output_dir / (_string(args, "project_dir", default="") or ".")).resolve()
382
+ if not project.is_dir():
383
+ raise ValueError(f"{project} is not a directory: name the project that holds (or will hold) supabase/")
384
+ if not args.get("confirm_charge"):
385
+ raise ValueError(
386
+ f"add_supabase_kit downloads the model's kit, which costs {DOWNLOAD_APP_CREDITS} credits the first time "
387
+ "this user downloads this model, kit or application (free after that). Tell the person, and call again "
388
+ "with confirm_charge true."
389
+ )
390
+ kit = get_client().supabase_kit(ct_id)
391
+ written = write_kit(project, kit)
392
+ return {"project": str(project), "models": kit["models"], "written": written, "charged": kit.get("charged"),
393
+ "next": "supabase db push; supabase functions deploy gate"}
394
+
395
+
353
396
  def _handle_wallet(args: dict) -> Any:
354
397
  c = get_client()
355
398
  return {"wallet": c.wallet(), "key": c.key_policy()}
@@ -364,6 +407,7 @@ TOOL_HANDLERS = {
364
407
  "job_status": _handle_job_status,
365
408
  "download_package": _handle_download_package,
366
409
  "generate_app": _handle_generate_app,
410
+ "add_supabase_kit": _handle_add_supabase_kit,
367
411
  "wallet": _handle_wallet,
368
412
  }
369
413
 
@@ -412,7 +456,8 @@ def _handle_request(request: Any) -> dict | None:
412
456
  "components; estimate before you build and show the person the cost; build only with the "
413
457
  "estimate_id you showed; prefer the model package over the generated application when the "
414
458
  "feature lives inside an existing application; fetch a model's package, including one you just built "
415
- "in a private project, with download_package. A 402 means the person funds the wallet at "
459
+ "in a private project, with download_package; for a TypeScript app on Supabase, write the model's kit "
460
+ "into the project with add_supabase_kit. A 402 means the person funds the wallet at "
416
461
  f"{get_client().base_url}/app/settings?tab=wallet; never try to pay. "
417
462
  + ("A key is configured, so building and downloading are available within its policy."
418
463
  if has_key else "No key is configured: the catalog and estimates work; building needs SDCSTUDIO_API_KEY.")
@@ -440,7 +485,7 @@ def _handle_request(request: Any) -> dict | None:
440
485
  ))
441
486
  except KeyPolicyRefused as exc:
442
487
  return _tool_error(req_id, f"The API key refused this ({exc.error_type}): {exc}")
443
- except (AssemblyRefused, SDCStudioError, ValueError) as exc:
488
+ except (AssemblyRefused, SDCStudioError, KitConflictError, ValueError) as exc:
444
489
  return _tool_error(req_id, f"Tool execution error: {exc}")
445
490
  except Exception as exc: # a defect in this server, not in the caller's input
446
491
  return _tool_error(req_id, (
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sdcmodeler
3
- Version: 4.3.2
3
+ Version: 4.4.1
4
4
  Summary: The modeler's client for SDCStudio: search the catalog, estimate, assemble and publish SDC4 data models, generate applications; a CLI and an MCP server over one client
5
5
  Author: Axius SDC, Inc.
6
6
  License-Expression: Apache-2.0
@@ -88,6 +88,7 @@ sdcmodeler build tree.json --title "Vitals" --wait
88
88
  sdcmodeler job <job_ct_id>
89
89
  sdcmodeler package <ct_id> --dir ./packages
90
90
  sdcmodeler app <ct_id> --profile lightweight --dir ./apps
91
+ sdcmodeler kit <ct_id> --project ./my-app
91
92
  sdcmodeler wallet
92
93
  ```
93
94
 
@@ -112,13 +113,14 @@ A JSON-RPC 2.0 stdio server, no SDK, the way sdcvalidator and sdcgovernance are
112
113
  | `job_status` | one job by id: status, step, cost so far, the model's links | no |
113
114
  | `download_package` | a model's package ZIP with the key, including a model in a private project; builds a missing package first (free, once) unless `generate` is false | no |
114
115
  | `generate_app` | generate and download the application; needs `confirm_charge`; 1,500 credits the first time, free after | yes |
116
+ | `add_supabase_kit` | write a model's Supabase kit into a project (`project_dir`); needs `confirm_charge`; charged with the application, once per model | yes |
115
117
  | `wallet` | balance in credits and the key's policy | no |
116
118
 
117
119
  **The policy lives in the server.** No spend without an estimate shown: `build_model` takes the `estimate_id` that `estimate_model` returned for the same title and tree in this process. Stop at the key's limit: a build whose estimate exceeds what the key may still spend is refused before the server is asked. Never pay: a 402 is reported with the wallet page's address and the tool stops. No tool takes a URL, a key or a payment method as an argument; the key is the environment the server starts with.
118
120
 
119
121
  ## The package or the application
120
122
 
121
- `get_model` names the artifacts: the XSD 1.1 schema, the instance template, JSON, JSON-LD, SHACL, HTML, GraphQL. The package is a contract with no runtime attached; a feature inside an existing application implements on it, in any language, validating every record locally with [sdcvalidator](https://pypi.org/project/sdcvalidator/). The generated application (lightweight or enterprise profile) is a Django implementation on the same package, right when the feature is a new service. [CordovaOS](https://github.com/Axius-SDC/CordovaOS) is ten of them sharing data with zero integration code.
123
+ `get_model` names the artifacts: the XSD 1.1 schema, the instance template, JSON, JSON-LD, SHACL, HTML, GraphQL. The package is a contract with no runtime attached; a feature inside an existing application implements on it, in any language, validating every record locally with [sdcvalidator](https://pypi.org/project/sdcvalidator/). The generated application (lightweight or enterprise profile) is a Django implementation on the same package, right when the feature is a new service. The Supabase kit is the same for a TypeScript app on Supabase: typed code for the model's records, migrations, and a gate (an Edge Function) that validates every record against the published model before storing it. `sdcmodeler kit` and `add_supabase_kit` write it into the project: the first model brings the project base, each further one adds its kit and one migration, numbered after the project's latest, and a component already in the project is never rewritten. Apply with Supabase's CLI (`supabase db push`, `supabase functions deploy gate`). [CordovaOS](https://github.com/Axius-SDC/CordovaOS) is ten of them sharing data with zero integration code.
122
124
 
123
125
  ## What is not here
124
126
 
@@ -4,6 +4,7 @@ pyproject.toml
4
4
  src/sdcmodeler/__init__.py
5
5
  src/sdcmodeler/cli.py
6
6
  src/sdcmodeler/client.py
7
+ src/sdcmodeler/kits.py
7
8
  src/sdcmodeler/mcp_server.py
8
9
  src/sdcmodeler/pricing.py
9
10
  src/sdcmodeler.egg-info/PKG-INFO
@@ -14,6 +15,7 @@ src/sdcmodeler.egg-info/requires.txt
14
15
  src/sdcmodeler.egg-info/top_level.txt
15
16
  tests/test_cli.py
16
17
  tests/test_client.py
18
+ tests/test_kits.py
17
19
  tests/test_mcp_server.py
18
20
  tests/test_pricing.py
19
21
  tests/test_registry_launch.py
@@ -0,0 +1,69 @@
1
+ """Writing a governed data kit, as SDCStudio's supabase_kit route answers it, into a Supabase project."""
2
+ from datetime import datetime, timezone
3
+
4
+ import pytest
5
+
6
+ from sdcmodeler.kits import KitConflictError, write_kit
7
+
8
+ NOW = datetime(2026, 11, 2, 12, 0, 0, tzinfo=timezone.utc)
9
+ SDC = "supabase/functions/_shared/sdc"
10
+
11
+
12
+ def kit(ct: str, component: str = "mc-c1", text: str = "export const ctId = 'c1';\n") -> dict:
13
+ return {
14
+ "generator": "4.0.0",
15
+ "models": [{"ctId": ct, "title": ct.upper()}],
16
+ "files": {
17
+ f"{SDC}/runtime/record.ts": "// runtime\n",
18
+ f"{SDC}/components/{component}.ts": text,
19
+ f"{SDC}/models/dm-{ct}.ts": f"export const ctId = '{ct}';\n",
20
+ "supabase/functions/gate/index.ts": "// gate\n",
21
+ },
22
+ "base_migration": {"name": "sdc_base.sql", "sql": "-- base\n"},
23
+ "migrations": [{"ctId": ct, "name": f"sdc_dm_{ct}.sql", "sql": f"-- {ct}\n"}],
24
+ }
25
+
26
+
27
+ def migrations(root):
28
+ return sorted(p.name for p in (root / "supabase" / "migrations").glob("*.sql"))
29
+
30
+
31
+ def test_the_first_kit_writes_the_base_its_files_and_the_index(tmp_path):
32
+ written = write_kit(tmp_path, kit("m1"), now=NOW)
33
+ assert migrations(tmp_path) == ["20261102120000_sdc_base.sql", "20261102120001_sdc_dm_m1.sql"]
34
+ assert f"{SDC}/models/index.ts" in written
35
+ assert (tmp_path / SDC / "models" / "index.ts").read_text() == (
36
+ "// Generated by the SDCStudio kit generator 4.0.0: every model in this kit, by its root element (dm-<ct_id>).\n"
37
+ "// Rewritten when a model kit is added.\n\n"
38
+ "import * as dm_m1 from './dm-m1.ts';\n\n"
39
+ "export const models = {\n \"dm-m1\": dm_m1,\n} as const;\n"
40
+ )
41
+
42
+
43
+ def test_a_second_model_adds_its_kit_and_one_migration_after_the_others(tmp_path):
44
+ write_kit(tmp_path, kit("m1"), now=NOW)
45
+ written = write_kit(tmp_path, kit("m2"), now=NOW)
46
+ assert migrations(tmp_path)[-1] == "20261102120002_sdc_dm_m2.sql" and len(migrations(tmp_path)) == 3
47
+ assert not any(p.endswith("sdc_base.sql") for p in written), "the base is written once"
48
+ index = (tmp_path / SDC / "models" / "index.ts").read_text()
49
+ assert ' "dm-m1": dm_m1,' in index and ' "dm-m2": dm_m2,' in index
50
+
51
+
52
+ def test_writing_again_writes_nothing(tmp_path):
53
+ write_kit(tmp_path, kit("m1"), now=NOW)
54
+ assert write_kit(tmp_path, kit("m1"), now=NOW) == []
55
+
56
+
57
+ def test_a_component_that_differs_is_refused_before_anything_is_written(tmp_path):
58
+ write_kit(tmp_path, kit("m1"), now=NOW)
59
+ with pytest.raises(KitConflictError, match="a published component never changes"):
60
+ write_kit(tmp_path, kit("m2", text="export const ctId = 'changed';\n"), now=NOW)
61
+ assert not (tmp_path / SDC / "models" / "dm-m2.ts").exists()
62
+ assert len(migrations(tmp_path)) == 2
63
+
64
+
65
+ def test_a_cuid_is_never_a_key_on_its_own(tmp_path):
66
+ # A CUID may start with a digit; models are keyed by their root element, dm-<ct_id>, as the XSD names them.
67
+ write_kit(tmp_path, kit("5scaiw897xhuqa1k8sso932e"), now=NOW)
68
+ index = (tmp_path / SDC / "models" / "index.ts").read_text()
69
+ assert ' "dm-5scaiw897xhuqa1k8sso932e": dm_5scaiw897xhuqa1k8sso932e,' in index
@@ -42,7 +42,7 @@ def test_initialize_and_tools_list():
42
42
  assert r["result"]["protocolVersion"] == "2025-06-18"
43
43
  assert "wallet" in r["result"]["instructions"]
44
44
  tools = rpc("tools/list")["result"]["tools"]
45
- assert [t["name"] for t in tools] == ["search_components", "list_models", "get_model", "estimate_model", "build_model", "job_status", "download_package", "generate_app", "wallet"]
45
+ assert [t["name"] for t in tools] == ["search_components", "list_models", "get_model", "estimate_model", "build_model", "job_status", "download_package", "generate_app", "add_supabase_kit", "wallet"]
46
46
 
47
47
 
48
48
  def test_build_needs_the_estimate_the_person_saw(bound):
@@ -90,6 +90,24 @@ def test_generate_app_needs_confirmation_and_reports_the_charge(bound, tmp_path)
90
90
  assert out["charged"] is True and out["path"].endswith("app.zip") and (tmp_path / "app.zip").exists()
91
91
 
92
92
 
93
+ def test_add_supabase_kit_needs_confirmation_and_writes_into_the_project(bound, tmp_path):
94
+ _, err = call("add_supabase_kit", {"ct_id": "m1"})
95
+ assert "1500 credits" in err and "confirm_charge" in err
96
+ _, err = call("add_supabase_kit", {"ct_id": "m1", "project_dir": "missing", "confirm_charge": True})
97
+ assert "is not a directory" in err
98
+ (tmp_path / "app").mkdir()
99
+ bound.on("GET", "/api/v1/dmgen/dms/m1/supabase_kit/", body={
100
+ "generator": "4.0.0", "models": [{"ctId": "m1", "title": "M1"}], "charged": True,
101
+ "files": {"supabase/functions/_shared/sdc/models/dm-m1.ts": "x\n"},
102
+ "base_migration": {"name": "sdc_base.sql", "sql": "-- base\n"},
103
+ "migrations": [{"ctId": "m1", "name": "sdc_dm_m1.sql", "sql": "-- m1\n"}],
104
+ })
105
+ out, _ = call("add_supabase_kit", {"ct_id": "m1", "project_dir": "app", "confirm_charge": True})
106
+ assert out["charged"] is True and out["project"] == str(tmp_path / "app")
107
+ assert len(list((tmp_path / "app" / "supabase" / "migrations").glob("*_sdc_dm_m1.sql"))) == 1
108
+ assert (tmp_path / "app" / "supabase" / "functions" / "_shared" / "sdc" / "models" / "index.ts").exists()
109
+
110
+
93
111
  def test_malformed_input_is_answered_not_fatal():
94
112
  assert mcp_server._handle_request([])["error"]["code"] == -32600
95
113
  assert mcp_server._handle_request({"jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": "x"})["error"]["code"] == -32600
File without changes
File without changes
File without changes