jsonpit 4.4.4__tar.gz → 4.4.5__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.
- {jsonpit-4.4.4 → jsonpit-4.4.5}/PKG-INFO +6 -6
- {jsonpit-4.4.4 → jsonpit-4.4.5}/README.md +4 -4
- {jsonpit-4.4.4 → jsonpit-4.4.5}/jsonpit/__init__.py +3 -5
- {jsonpit-4.4.4 → jsonpit-4.4.5}/jsonpit/cli.py +78 -12
- {jsonpit-4.4.4 → jsonpit-4.4.5}/jsonpit/exceptions.py +4 -0
- {jsonpit-4.4.4 → jsonpit-4.4.5}/jsonpit/item.py +58 -7
- {jsonpit-4.4.4 → jsonpit-4.4.5}/jsonpit/store.py +22 -1
- {jsonpit-4.4.4 → jsonpit-4.4.5}/pyproject.toml +2 -2
- {jsonpit-4.4.4 → jsonpit-4.4.5}/.gitignore +0 -0
- {jsonpit-4.4.4 → jsonpit-4.4.5}/jsonpit/canonical.py +0 -0
- {jsonpit-4.4.4 → jsonpit-4.4.5}/jsonpit/changes.py +0 -0
- {jsonpit-4.4.4 → jsonpit-4.4.5}/jsonpit/config.py +0 -0
- {jsonpit-4.4.4 → jsonpit-4.4.5}/jsonpit/flags.py +0 -0
- {jsonpit-4.4.4 → jsonpit-4.4.5}/jsonpit/fs.py +0 -0
- {jsonpit-4.4.4 → jsonpit-4.4.5}/jsonpit/history.py +0 -0
- {jsonpit-4.4.4 → jsonpit-4.4.5}/jsonpit/icons.py +0 -0
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: jsonpit
|
|
3
|
-
Version: 4.4.
|
|
3
|
+
Version: 4.4.5
|
|
4
4
|
Summary: Daemon-free distributed storage over Cloud Drives for developers and AI agents — multi-process, immutable history, zero dependencies.
|
|
5
5
|
Author: Dr. Rainer Burkhardt
|
|
6
6
|
License-Expression: Apache-2.0
|
|
7
|
-
Classifier: Development Status ::
|
|
7
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
8
8
|
Classifier: Intended Audience :: Developers
|
|
9
9
|
Classifier: Operating System :: OS Independent
|
|
10
10
|
Classifier: Programming Language :: Python :: 3
|
|
@@ -31,14 +31,14 @@ The canonical **reference (lead) implementation** is C# `JsonPit` and the `pits`
|
|
|
31
31
|
|
|
32
32
|
---
|
|
33
33
|
|
|
34
|
-
## Cross-Tool & Cross-Language Version Alignment (`v4.4.
|
|
34
|
+
## Cross-Tool & Cross-Language Version Alignment (`v4.4.5`)
|
|
35
35
|
|
|
36
|
-
`jsonpit` and the `jpit` CLI are version-synchronized to **`v4.4.
|
|
36
|
+
`jsonpit` and the `jpit` CLI are version-synchronized to **`v4.4.5`** in direct lockstep with C# `JsonPit` and `pits 4.4.5` in [RAIkeep](https://github.com/Burkhardt/RAIkeep).
|
|
37
37
|
|
|
38
38
|
### Why Harmonized Versioning is Essential:
|
|
39
39
|
- **Instant Compatibility Clarity:** Operators, DevOps pipelines, and autonomous AI agents immediately know whether `jpit` and `pits` share the exact same distributed protocol revision. If both tools report `4.4.x`, they guarantee identical master leasing rules, receipt mechanisms, 7-digit UTC timestamp parsing, and CR041 clean change file conventions.
|
|
40
40
|
- **Elimination of Multi-Language Matrix Confusion:** In heterogeneous environments (e.g. C# backend daemons paired with Python agent orchestrators and data science tooling), unified SemVer tags eliminate complex cross-compatibility lookup tables.
|
|
41
|
-
- **Joint Protocol Governance:** Architectural changes (such as CR040 anti-Read-Modify-Write rules, CR041 clean change file formatting,
|
|
41
|
+
- **Joint Protocol Governance:** Architectural changes (such as CR040 anti-Read-Modify-Write rules, CR041 clean change file formatting, CR044 missing configuration diagnostics, and CR047 strict patch validation) are certified across both languages under the exact same version milestone before release.
|
|
42
42
|
|
|
43
43
|
---
|
|
44
44
|
|
|
@@ -65,7 +65,7 @@ pipx install jsonpit
|
|
|
65
65
|
# (or via companion alias)
|
|
66
66
|
pipx install jpit
|
|
67
67
|
|
|
68
|
-
# Upgrade to the latest lockstep release (v4.4.
|
|
68
|
+
# Upgrade to the latest lockstep release (v4.4.5)
|
|
69
69
|
pipx upgrade jsonpit
|
|
70
70
|
# (or)
|
|
71
71
|
pipx upgrade jpit
|
|
@@ -9,14 +9,14 @@ The canonical **reference (lead) implementation** is C# `JsonPit` and the `pits`
|
|
|
9
9
|
|
|
10
10
|
---
|
|
11
11
|
|
|
12
|
-
## Cross-Tool & Cross-Language Version Alignment (`v4.4.
|
|
12
|
+
## Cross-Tool & Cross-Language Version Alignment (`v4.4.5`)
|
|
13
13
|
|
|
14
|
-
`jsonpit` and the `jpit` CLI are version-synchronized to **`v4.4.
|
|
14
|
+
`jsonpit` and the `jpit` CLI are version-synchronized to **`v4.4.5`** in direct lockstep with C# `JsonPit` and `pits 4.4.5` in [RAIkeep](https://github.com/Burkhardt/RAIkeep).
|
|
15
15
|
|
|
16
16
|
### Why Harmonized Versioning is Essential:
|
|
17
17
|
- **Instant Compatibility Clarity:** Operators, DevOps pipelines, and autonomous AI agents immediately know whether `jpit` and `pits` share the exact same distributed protocol revision. If both tools report `4.4.x`, they guarantee identical master leasing rules, receipt mechanisms, 7-digit UTC timestamp parsing, and CR041 clean change file conventions.
|
|
18
18
|
- **Elimination of Multi-Language Matrix Confusion:** In heterogeneous environments (e.g. C# backend daemons paired with Python agent orchestrators and data science tooling), unified SemVer tags eliminate complex cross-compatibility lookup tables.
|
|
19
|
-
- **Joint Protocol Governance:** Architectural changes (such as CR040 anti-Read-Modify-Write rules, CR041 clean change file formatting,
|
|
19
|
+
- **Joint Protocol Governance:** Architectural changes (such as CR040 anti-Read-Modify-Write rules, CR041 clean change file formatting, CR044 missing configuration diagnostics, and CR047 strict patch validation) are certified across both languages under the exact same version milestone before release.
|
|
20
20
|
|
|
21
21
|
---
|
|
22
22
|
|
|
@@ -43,7 +43,7 @@ pipx install jsonpit
|
|
|
43
43
|
# (or via companion alias)
|
|
44
44
|
pipx install jpit
|
|
45
45
|
|
|
46
|
-
# Upgrade to the latest lockstep release (v4.4.
|
|
46
|
+
# Upgrade to the latest lockstep release (v4.4.5)
|
|
47
47
|
pipx upgrade jsonpit
|
|
48
48
|
# (or)
|
|
49
49
|
pipx upgrade jpit
|
|
@@ -10,6 +10,7 @@ from .exceptions import (
|
|
|
10
10
|
PitInstanceConflictError,
|
|
11
11
|
PitNotFoundError,
|
|
12
12
|
ProtectedAttributeError,
|
|
13
|
+
StrictPatchValidationError,
|
|
13
14
|
TombstoneError,
|
|
14
15
|
)
|
|
15
16
|
from .config import DEFAULT_CONFIG_FILE_LOCATION, OsConfig, missing_configuration_diagnostic
|
|
@@ -18,11 +19,7 @@ from .icons import Icons
|
|
|
18
19
|
from .item import PitItem
|
|
19
20
|
from .store import Pit, PitStore, parse_and_validate_seed_payload
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
import importlib.metadata
|
|
23
|
-
__version__ = importlib.metadata.version("jsonpit")
|
|
24
|
-
except Exception:
|
|
25
|
-
__version__ = "4.4.4"
|
|
22
|
+
__version__ = "4.4.5"
|
|
26
23
|
|
|
27
24
|
__all__ = [
|
|
28
25
|
"Pit",
|
|
@@ -40,5 +37,6 @@ __all__ = [
|
|
|
40
37
|
"PitConcurrencyError",
|
|
41
38
|
"PitInstanceConflictError",
|
|
42
39
|
"ProtectedAttributeError",
|
|
40
|
+
"StrictPatchValidationError",
|
|
43
41
|
"TombstoneError",
|
|
44
42
|
]
|
|
@@ -20,7 +20,12 @@ from typing import Any
|
|
|
20
20
|
|
|
21
21
|
from .canonical import canonical_json, format_iso_timestamp, parse_iso_timestamp, utcnow
|
|
22
22
|
from .config import OsConfig, loads_json5, missing_configuration_diagnostic
|
|
23
|
-
from .exceptions import
|
|
23
|
+
from .exceptions import (
|
|
24
|
+
JsonPitError,
|
|
25
|
+
PitNotFoundError,
|
|
26
|
+
ProtectedAttributeError,
|
|
27
|
+
StrictPatchValidationError,
|
|
28
|
+
)
|
|
24
29
|
from .fs import resolve_pit_target
|
|
25
30
|
from .item import PitItem
|
|
26
31
|
from .icons import Icons
|
|
@@ -395,7 +400,9 @@ def cmd_put(args: argparse.Namespace) -> int:
|
|
|
395
400
|
Ingests entities from stdin, piped jq output, or a JSON5 file.
|
|
396
401
|
Adds entities cloud-safely with leasing.
|
|
397
402
|
CR043: Supports single root entity, keyed entity map, or entity array.
|
|
403
|
+
CR047: Strict patch mode via --require-existing or --patch.
|
|
398
404
|
"""
|
|
405
|
+
require_existing = bool(getattr(args, "require_existing", False) or getattr(args, "patch", False))
|
|
399
406
|
source_path_str = getattr(args, "source", None)
|
|
400
407
|
if not source_path_str and getattr(args, "source_opt", None):
|
|
401
408
|
source_path_str = args.source_opt
|
|
@@ -422,10 +429,42 @@ def cmd_put(args: argparse.Namespace) -> int:
|
|
|
422
429
|
sys.stderr.write(f"[jpit] Error: {ex}\n")
|
|
423
430
|
return 1
|
|
424
431
|
|
|
432
|
+
if require_existing and not items_to_add:
|
|
433
|
+
sys.stderr.write("error: Patch source contained 0 entities.\n")
|
|
434
|
+
return 1
|
|
435
|
+
|
|
425
436
|
if not items_to_add:
|
|
426
437
|
print(f"[jpit] Seed source '{source_name}' contained 0 entities.")
|
|
427
438
|
return 0
|
|
428
439
|
|
|
440
|
+
# CR047: Strict patch mode pre-validation before opening target Pit for writing or creating flags
|
|
441
|
+
if require_existing:
|
|
442
|
+
try:
|
|
443
|
+
with Pit.open(
|
|
444
|
+
args.pit,
|
|
445
|
+
cloud=args.cloud,
|
|
446
|
+
root=args.root,
|
|
447
|
+
read_only=True,
|
|
448
|
+
unflagged=True,
|
|
449
|
+
) as living_state:
|
|
450
|
+
for raw_obj in items_to_add:
|
|
451
|
+
item_id = raw_obj["Id"]
|
|
452
|
+
if not living_state.contains(item_id, with_deleted=False):
|
|
453
|
+
sys.stderr.write(
|
|
454
|
+
f"error: Entity '{item_id}' does not exist in Pit '{living_state.pit_name}'. "
|
|
455
|
+
"Use without --require-existing / --patch to allow creating new entities.\n"
|
|
456
|
+
)
|
|
457
|
+
return 1
|
|
458
|
+
except PitNotFoundError:
|
|
459
|
+
sys.stderr.write(
|
|
460
|
+
f"error: Entity '{items_to_add[0]['Id']}' does not exist in Pit '{args.pit}'. "
|
|
461
|
+
"Use without --require-existing / --patch to allow creating new entities.\n"
|
|
462
|
+
)
|
|
463
|
+
return 1
|
|
464
|
+
except Exception as ex:
|
|
465
|
+
sys.stderr.write(f"[jpit] Error: {ex}\n")
|
|
466
|
+
return 1
|
|
467
|
+
|
|
429
468
|
with Pit.open(
|
|
430
469
|
args.pit,
|
|
431
470
|
cloud=args.cloud,
|
|
@@ -464,13 +503,12 @@ def cmd_set(args: argparse.Namespace) -> int:
|
|
|
464
503
|
retain_window=getattr(args, "retain_window", False),
|
|
465
504
|
) as pit:
|
|
466
505
|
existing = pit.get(args.id)
|
|
467
|
-
if existing:
|
|
506
|
+
if existing is not None:
|
|
468
507
|
existing.set_property(payload)
|
|
469
|
-
pit.add(existing)
|
|
470
508
|
else:
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
pit.add(
|
|
509
|
+
delta = dict(payload)
|
|
510
|
+
delta["Id"] = args.id
|
|
511
|
+
pit.add(PitItem(delta))
|
|
474
512
|
|
|
475
513
|
print(f"[jpit] Updated entity '{args.id}' in Pit '{args.pit}'.")
|
|
476
514
|
return 0
|
|
@@ -513,7 +551,6 @@ def cmd_delete_prop(args: argparse.Namespace) -> int:
|
|
|
513
551
|
sys.stderr.write(f"[jpit] Entity '{args.id}' not found.\n")
|
|
514
552
|
return 1
|
|
515
553
|
item.delete_property_path(args.property_path)
|
|
516
|
-
pit.add(item)
|
|
517
554
|
|
|
518
555
|
print(f"[jpit] Tombstoned property '{args.property_path}' on entity '{args.id}'.")
|
|
519
556
|
return 0
|
|
@@ -844,7 +881,7 @@ def print_command_help(cmd: str, nologo: bool = False, use_color: bool = True) -
|
|
|
844
881
|
],
|
|
845
882
|
},
|
|
846
883
|
"put": {
|
|
847
|
-
"usage": "jpit put <PitName> [<source>] [-s <source>] [options]",
|
|
884
|
+
"usage": "jpit put <PitName> [<source>] [-s <source>] [--require-existing] [--patch] [options]",
|
|
848
885
|
"desc": "Ingest JSON5 entities from file or stdin pipe (alias: seed).",
|
|
849
886
|
"args": [
|
|
850
887
|
("PitName", "Pit name or file path"),
|
|
@@ -852,6 +889,8 @@ def print_command_help(cmd: str, nologo: bool = False, use_color: bool = True) -
|
|
|
852
889
|
],
|
|
853
890
|
"opts": [
|
|
854
891
|
("-s, --source <file>", "Source file for import (JSON or JSON5)"),
|
|
892
|
+
("--require-existing", "Reject batch if any entity does not already exist"),
|
|
893
|
+
("--patch", "Alias for --require-existing"),
|
|
855
894
|
],
|
|
856
895
|
"aliases": ["seed"],
|
|
857
896
|
},
|
|
@@ -1016,7 +1055,22 @@ class JsonPitArgumentParser(argparse.ArgumentParser):
|
|
|
1016
1055
|
sys.exit(2)
|
|
1017
1056
|
|
|
1018
1057
|
|
|
1019
|
-
def
|
|
1058
|
+
def get_cli_prog_name(argv0: str | None = None) -> str:
|
|
1059
|
+
"""Determines whether CLI is invoked as 'jsonpit' or 'jpit'."""
|
|
1060
|
+
if argv0 is None:
|
|
1061
|
+
argv0 = sys.argv[0] if sys.argv and sys.argv[0] else "jpit"
|
|
1062
|
+
base = Path(argv0).name.lower()
|
|
1063
|
+
if base == "jsonpit" or base.startswith("jsonpit"):
|
|
1064
|
+
return "jsonpit"
|
|
1065
|
+
if "jsonpit" in str(argv0).lower() and "jpit" not in base:
|
|
1066
|
+
return "jsonpit"
|
|
1067
|
+
return "jpit"
|
|
1068
|
+
|
|
1069
|
+
|
|
1070
|
+
def build_parser(prog: str | None = None) -> JsonPitArgumentParser:
|
|
1071
|
+
if prog is None:
|
|
1072
|
+
prog = get_cli_prog_name()
|
|
1073
|
+
|
|
1020
1074
|
common_parser = JsonPitArgumentParser(add_help=False)
|
|
1021
1075
|
common_parser.add_argument(
|
|
1022
1076
|
"-c", "--cloud",
|
|
@@ -1042,15 +1096,15 @@ def build_parser() -> JsonPitArgumentParser:
|
|
|
1042
1096
|
)
|
|
1043
1097
|
|
|
1044
1098
|
parser = JsonPitArgumentParser(
|
|
1045
|
-
prog=
|
|
1046
|
-
description="
|
|
1099
|
+
prog=prog,
|
|
1100
|
+
description=f"{prog} — Cloud-first distributed replicated storage CLI and Pit-Grep.",
|
|
1047
1101
|
parents=[common_parser],
|
|
1048
1102
|
)
|
|
1049
1103
|
parser.add_argument(
|
|
1050
1104
|
"-v",
|
|
1051
1105
|
"--version",
|
|
1052
1106
|
action="version",
|
|
1053
|
-
version=f"%(prog)s {__version__}",
|
|
1107
|
+
version=f"%(prog)s v{__version__}",
|
|
1054
1108
|
)
|
|
1055
1109
|
|
|
1056
1110
|
subparsers = parser.add_subparsers(dest="command", required=True, parser_class=JsonPitArgumentParser)
|
|
@@ -1101,6 +1155,18 @@ def build_parser() -> JsonPitArgumentParser:
|
|
|
1101
1155
|
p_put.add_argument("pit", help="Pit name")
|
|
1102
1156
|
p_put.add_argument("source", nargs="?", default=None, help="Source file or '-' for stdin")
|
|
1103
1157
|
p_put.add_argument("-s", "--source", dest="source_opt", help="Source file for import (JSON or JSON5)")
|
|
1158
|
+
p_put.add_argument(
|
|
1159
|
+
"--require-existing",
|
|
1160
|
+
action="store_true",
|
|
1161
|
+
default=False,
|
|
1162
|
+
help="CR047: Strictly require all incoming entity IDs to exist in the Pit",
|
|
1163
|
+
)
|
|
1164
|
+
p_put.add_argument(
|
|
1165
|
+
"--patch",
|
|
1166
|
+
action="store_true",
|
|
1167
|
+
default=False,
|
|
1168
|
+
help="CR047: Alias for --require-existing",
|
|
1169
|
+
)
|
|
1104
1170
|
|
|
1105
1171
|
# set
|
|
1106
1172
|
p_set = subparsers.add_parser("set", parents=[common_parser], help="Set or patch entity with JSON5 payload")
|
|
@@ -29,3 +29,7 @@ class TombstoneError(JsonPitError):
|
|
|
29
29
|
|
|
30
30
|
class ProtectedAttributeError(JsonPitError, ValueError):
|
|
31
31
|
"""Raised when attempting to manually mutate or inject protected lifecycle attributes (Modified, Deleted, Id)."""
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class StrictPatchValidationError(JsonPitError, ValueError):
|
|
35
|
+
"""CR047: Raised when --require-existing / --patch validation fails."""
|
|
@@ -11,6 +11,7 @@ import datetime
|
|
|
11
11
|
import json
|
|
12
12
|
from collections.abc import Iterator, MutableMapping
|
|
13
13
|
from typing import Any
|
|
14
|
+
import weakref
|
|
14
15
|
|
|
15
16
|
from .canonical import (
|
|
16
17
|
canonical_json,
|
|
@@ -84,13 +85,17 @@ class PitItem(MutableMapping[str, Any]):
|
|
|
84
85
|
deleted: bool = False,
|
|
85
86
|
modified: datetime.datetime | None = None,
|
|
86
87
|
invalidate: bool = True,
|
|
88
|
+
pit: Any | None = None,
|
|
87
89
|
) -> None:
|
|
88
90
|
self._data: dict[str, Any] = {}
|
|
89
91
|
self._dirty: bool = False
|
|
92
|
+
self._pit_ref: weakref.ref[Any] | None = weakref.ref(pit) if pit is not None else None
|
|
90
93
|
|
|
91
94
|
if isinstance(initial, PitItem):
|
|
92
95
|
self._data = copy.deepcopy(initial._data)
|
|
93
96
|
self._dirty = initial._dirty
|
|
97
|
+
if pit is not None:
|
|
98
|
+
self._pit_ref = weakref.ref(pit)
|
|
94
99
|
if id is not None:
|
|
95
100
|
self._data["Id"] = id
|
|
96
101
|
if note:
|
|
@@ -153,6 +158,16 @@ class PitItem(MutableMapping[str, Any]):
|
|
|
153
158
|
else:
|
|
154
159
|
self.validate()
|
|
155
160
|
|
|
161
|
+
def bind(self, pit: Any) -> PitItem:
|
|
162
|
+
"""Binds this living entity to its parent Pit container."""
|
|
163
|
+
self._pit_ref = weakref.ref(pit) if pit is not None else None
|
|
164
|
+
return self
|
|
165
|
+
|
|
166
|
+
@property
|
|
167
|
+
def pit(self) -> Any | None:
|
|
168
|
+
"""Returns the parent Pit if bound and alive, else None."""
|
|
169
|
+
return self._pit_ref() if self._pit_ref is not None else None
|
|
170
|
+
|
|
156
171
|
# --- Property Accessors ---
|
|
157
172
|
|
|
158
173
|
@property
|
|
@@ -264,15 +279,22 @@ class PitItem(MutableMapping[str, Any]):
|
|
|
264
279
|
"""
|
|
265
280
|
Appends a property tombstone by setting the top-level property to None (JSON null).
|
|
266
281
|
Resets Deleted to False and marks the entity dirty.
|
|
282
|
+
If bound to a Pit, automatically dispatches a sparse tombstone delta.
|
|
267
283
|
"""
|
|
268
284
|
self.deleted = False
|
|
269
285
|
self.invalidate()
|
|
270
286
|
self._data[property_name] = None
|
|
287
|
+
p = self.pit
|
|
288
|
+
if p is not None:
|
|
289
|
+
mutation = PitItem(id=self.id)
|
|
290
|
+
mutation.delete_property(property_name)
|
|
291
|
+
p.add(mutation)
|
|
271
292
|
|
|
272
293
|
def delete_property_path(self, property_path: str) -> None:
|
|
273
294
|
"""
|
|
274
295
|
Appends a property tombstone at a dot-delimited nested JSON path (e.g. 'Address.City').
|
|
275
296
|
Sets the leaf property to None (JSON null), resets Deleted to False, and marks dirty.
|
|
297
|
+
If bound to a Pit, automatically dispatches a sparse tombstone delta.
|
|
276
298
|
"""
|
|
277
299
|
if not property_path or not property_path.strip():
|
|
278
300
|
raise TombstoneError("A property path is required.")
|
|
@@ -304,11 +326,17 @@ class PitItem(MutableMapping[str, Any]):
|
|
|
304
326
|
container[segments[-1]] = None
|
|
305
327
|
self.deleted = False
|
|
306
328
|
self.invalidate()
|
|
329
|
+
p = self.pit
|
|
330
|
+
if p is not None:
|
|
331
|
+
mutation = PitItem(id=self.id)
|
|
332
|
+
mutation.delete_property_path(property_path)
|
|
333
|
+
p.add(mutation)
|
|
307
334
|
|
|
308
335
|
def delete(self, by: str | None = None, backdate_100: bool = True) -> bool:
|
|
309
336
|
"""
|
|
310
337
|
Tombstones this item. Appends an audit trail to Note.
|
|
311
338
|
If backdate_100 is True, preserves precedence by backdating Modified by 100 seconds.
|
|
339
|
+
If bound to a Pit, dispatches the tombstone to the Pit.
|
|
312
340
|
Returns True if newly deleted, False if already deleted.
|
|
313
341
|
"""
|
|
314
342
|
if self.deleted:
|
|
@@ -325,14 +353,13 @@ class PitItem(MutableMapping[str, Any]):
|
|
|
325
353
|
if by:
|
|
326
354
|
audit_entry += f" by {by}"
|
|
327
355
|
self.note = f"{audit_entry};\n{self.note}" if self.note else f"{audit_entry};"
|
|
356
|
+
p = self.pit
|
|
357
|
+
if p is not None:
|
|
358
|
+
p.delete_item(self.id, by=by, backdate_100=backdate_100)
|
|
328
359
|
return True
|
|
329
360
|
|
|
330
|
-
def
|
|
331
|
-
"""
|
|
332
|
-
Deep merges a dictionary into this entity.
|
|
333
|
-
Arrays are replaced; objects are recursively merged; nulls (tombstones) are preserved.
|
|
334
|
-
Returns True if any value was modified.
|
|
335
|
-
"""
|
|
361
|
+
def _apply_extend(self, obj: dict[str, Any]) -> bool:
|
|
362
|
+
"""In-memory deep merge without dispatching to parent Pit."""
|
|
336
363
|
original_canonical = canonical_json(self.to_dict())
|
|
337
364
|
|
|
338
365
|
def _deep_merge(target: dict[str, Any], source: dict[str, Any]) -> None:
|
|
@@ -349,6 +376,21 @@ class PitItem(MutableMapping[str, Any]):
|
|
|
349
376
|
self.invalidate()
|
|
350
377
|
return changed
|
|
351
378
|
|
|
379
|
+
def extend_with(self, obj: dict[str, Any]) -> bool:
|
|
380
|
+
"""
|
|
381
|
+
Deep merges a dictionary into this entity.
|
|
382
|
+
Arrays are replaced; objects are recursively merged; nulls (tombstones) are preserved.
|
|
383
|
+
If bound to a Pit, automatically dispatches a sparse delta fragment.
|
|
384
|
+
Returns True if any value was modified.
|
|
385
|
+
"""
|
|
386
|
+
changed = self._apply_extend(obj)
|
|
387
|
+
p = self.pit
|
|
388
|
+
if changed and p is not None:
|
|
389
|
+
delta = copy.deepcopy(obj)
|
|
390
|
+
delta["Id"] = self.id
|
|
391
|
+
p.add(PitItem(delta))
|
|
392
|
+
return changed
|
|
393
|
+
|
|
352
394
|
def extend(self, json_string: str) -> bool:
|
|
353
395
|
"""Parses JSON text and merges it into this entity."""
|
|
354
396
|
parsed = json.loads(json_string)
|
|
@@ -418,10 +460,19 @@ class PitItem(MutableMapping[str, Any]):
|
|
|
418
460
|
else:
|
|
419
461
|
self._data[key] = value
|
|
420
462
|
self.invalidate()
|
|
463
|
+
p = self.pit
|
|
464
|
+
if p is not None:
|
|
465
|
+
p.add(PitItem({"Id": self.id, key: value}))
|
|
421
466
|
|
|
422
467
|
def __delitem__(self, key: str) -> None:
|
|
423
|
-
|
|
468
|
+
if key in self._data:
|
|
469
|
+
del self._data[key]
|
|
424
470
|
self.invalidate()
|
|
471
|
+
p = self.pit
|
|
472
|
+
if p is not None:
|
|
473
|
+
mutation = PitItem(id=self.id)
|
|
474
|
+
mutation.delete_property(key)
|
|
475
|
+
p.add(mutation)
|
|
425
476
|
|
|
426
477
|
def __iter__(self) -> Iterator[str]:
|
|
427
478
|
# Ensure Id, Modified, Deleted are always visible in key enumeration
|
|
@@ -29,6 +29,7 @@ from .exceptions import (
|
|
|
29
29
|
PitInstanceConflictError,
|
|
30
30
|
PitNotFoundError,
|
|
31
31
|
ProtectedAttributeError,
|
|
32
|
+
StrictPatchValidationError,
|
|
32
33
|
)
|
|
33
34
|
from .flags import (
|
|
34
35
|
MasterFlagFile,
|
|
@@ -417,11 +418,12 @@ class Pit(JsonPitBase, MutableMapping[str, PitItem]):
|
|
|
417
418
|
raise
|
|
418
419
|
raise PitCorruptError(f"Failed to parse pit file {self.canonical_file}: {ex}") from ex
|
|
419
420
|
|
|
420
|
-
def seed_from_file(self, file_path: Path | str) -> int:
|
|
421
|
+
def seed_from_file(self, file_path: Path | str, require_existing: bool = False) -> int:
|
|
421
422
|
"""
|
|
422
423
|
Ingests a seed file (JSON or JSON5) and adds all entities to the pit.
|
|
423
424
|
Returns count of imported entities.
|
|
424
425
|
CR043: Validates payload shape and entities strictly before mutation.
|
|
426
|
+
CR047: If require_existing is True, validates that all IDs exist in living state.
|
|
425
427
|
"""
|
|
426
428
|
path = Path(file_path)
|
|
427
429
|
if not path.is_file():
|
|
@@ -430,6 +432,17 @@ class Pit(JsonPitBase, MutableMapping[str, PitItem]):
|
|
|
430
432
|
text = path.read_text(encoding="utf-8")
|
|
431
433
|
items_to_add = parse_and_validate_seed_payload(text, str(path))
|
|
432
434
|
|
|
435
|
+
if require_existing:
|
|
436
|
+
if not items_to_add:
|
|
437
|
+
raise StrictPatchValidationError("Patch source contained 0 entities.")
|
|
438
|
+
for raw_obj in items_to_add:
|
|
439
|
+
item_id = raw_obj["Id"]
|
|
440
|
+
if not self.contains(item_id, with_deleted=False):
|
|
441
|
+
raise StrictPatchValidationError(
|
|
442
|
+
f"Entity '{item_id}' does not exist in Pit '{self.pit_name}'. "
|
|
443
|
+
"Use without --require-existing / --patch to allow creating new entities."
|
|
444
|
+
)
|
|
445
|
+
|
|
433
446
|
count = 0
|
|
434
447
|
for raw_obj in items_to_add:
|
|
435
448
|
item = PitItem(raw_obj)
|
|
@@ -647,6 +660,8 @@ class Pit(JsonPitBase, MutableMapping[str, PitItem]):
|
|
|
647
660
|
if pit_items is None:
|
|
648
661
|
return default
|
|
649
662
|
projected = pit_items.project_state(at=at, with_deleted=with_deleted)
|
|
663
|
+
if projected is not None and at is None and not self.read_only:
|
|
664
|
+
projected.bind(self)
|
|
650
665
|
return projected if projected is not None else default
|
|
651
666
|
|
|
652
667
|
def get_at(
|
|
@@ -658,6 +673,12 @@ class Pit(JsonPitBase, MutableMapping[str, PitItem]):
|
|
|
658
673
|
"""Point-in-time historical projection of an entity."""
|
|
659
674
|
return self.get(item_id, at=at, with_deleted=with_deleted)
|
|
660
675
|
|
|
676
|
+
def contains(self, item_id: str, with_deleted: bool = False) -> bool:
|
|
677
|
+
"""100% C# parity: checks if an entity exists in living state."""
|
|
678
|
+
if not item_id:
|
|
679
|
+
return False
|
|
680
|
+
return self.get(item_id, with_deleted=with_deleted) is not None
|
|
681
|
+
|
|
661
682
|
def all_undeleted(self) -> list[PitItem]:
|
|
662
683
|
"""Returns all active, non-deleted entities in this pit."""
|
|
663
684
|
results: list[PitItem] = []
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "jsonpit"
|
|
7
|
-
version = "4.4.
|
|
7
|
+
version = "4.4.5"
|
|
8
8
|
description = "Daemon-free distributed storage over Cloud Drives for developers and AI agents — multi-process, immutable history, zero dependencies."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.12"
|
|
@@ -13,7 +13,7 @@ authors = [
|
|
|
13
13
|
{ name = "Dr. Rainer Burkhardt" },
|
|
14
14
|
]
|
|
15
15
|
classifiers = [
|
|
16
|
-
"Development Status ::
|
|
16
|
+
"Development Status :: 5 - Production/Stable",
|
|
17
17
|
"Intended Audience :: Developers",
|
|
18
18
|
"Operating System :: OS Independent",
|
|
19
19
|
"Programming Language :: Python :: 3",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|