graphddb 0.3.1 → 0.4.1

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.
@@ -6,7 +6,6 @@ import {
6
6
  MetadataRegistry,
7
7
  NO_MIDDLEWARE,
8
8
  TableMapping,
9
- ViewRegistry,
10
9
  attachHiddenKey,
11
10
  attachModelClass,
12
11
  buildConditionExpression,
@@ -43,7 +42,7 @@ import {
43
42
  serializeFieldValue,
44
43
  serializeRawCondition,
45
44
  skTemplate
46
- } from "./chunk-YIXXTGZ6.js";
45
+ } from "./chunk-CPTV3H2U.js";
47
46
 
48
47
  // src/spec/types.ts
49
48
  var SPEC_VERSION = "1.0";
@@ -112,7 +111,12 @@ function buildFields(metadata) {
112
111
  const fields = {};
113
112
  for (const field of metadata.fields) {
114
113
  const format = field.options?.format;
115
- fields[field.propertyName] = format ? { type: DYNAMO_TYPE_TO_FIELD_TYPE[field.dynamoType], format } : { type: DYNAMO_TYPE_TO_FIELD_TYPE[field.dynamoType] };
114
+ const description = field.options?.description;
115
+ fields[field.propertyName] = {
116
+ type: DYNAMO_TYPE_TO_FIELD_TYPE[field.dynamoType],
117
+ ...format ? { format } : {},
118
+ ...description !== void 0 ? { description } : {}
119
+ };
116
120
  }
117
121
  return sortedRecord(fields);
118
122
  }
@@ -124,7 +128,8 @@ function buildEntity(metadata) {
124
128
  fields: buildFields(metadata),
125
129
  key: buildKey(metadata.primaryKey),
126
130
  gsis: buildGsis(metadata),
127
- relations: buildRelations(metadata)
131
+ relations: buildRelations(metadata),
132
+ ...metadata.description !== void 0 ? { description: metadata.description } : {}
128
133
  };
129
134
  }
130
135
  function buildManifest(registry = MetadataRegistry) {
@@ -3573,7 +3578,8 @@ function buildQueryContract(methods) {
3573
3578
  op,
3574
3579
  resolution,
3575
3580
  inputArity,
3576
- __methodName: name
3581
+ __methodName: name,
3582
+ ...op.description !== void 0 ? { description: op.description } : {}
3577
3583
  };
3578
3584
  }
3579
3585
  const contract = { __isContract: true, kind: "query", methods: resolved };
@@ -3587,8 +3593,8 @@ function buildCommandContract(methods) {
3587
3593
  const resolved = {};
3588
3594
  for (const [name, body] of Object.entries(methods)) {
3589
3595
  if (isPublicWriteDescriptor(body)) {
3590
- const { plan: plan2, select, condition, mode } = writeDescriptorToPlan(name, body);
3591
- resolved[name] = finalizeDescriptorCommand(name, plan2, select, condition, mode);
3596
+ const { plan: plan2, select, condition, mode, description } = writeDescriptorToPlan(name, body);
3597
+ resolved[name] = finalizeDescriptorCommand(name, plan2, select, condition, mode, description);
3592
3598
  continue;
3593
3599
  }
3594
3600
  if (isPublicComposeDescriptor(body)) {
@@ -3598,7 +3604,8 @@ function buildCommandContract(methods) {
3598
3604
  body.command,
3599
3605
  select,
3600
3606
  void 0,
3601
- body.mode ?? "transaction"
3607
+ body.mode ?? "transaction",
3608
+ body.description
3602
3609
  );
3603
3610
  continue;
3604
3611
  }
@@ -3663,7 +3670,7 @@ function buildPlannedCommandMethod(name, planned) {
3663
3670
  ...returnSelection !== void 0 ? { returnSelection } : {}
3664
3671
  };
3665
3672
  }
3666
- function finalizeDescriptorCommand(name, plan2, select, condition, mode) {
3673
+ function finalizeDescriptorCommand(name, plan2, select, condition, mode, description) {
3667
3674
  const planned = {
3668
3675
  [PLANNED_COMMAND_BRAND]: true,
3669
3676
  plan: plan2,
@@ -3675,7 +3682,8 @@ function finalizeDescriptorCommand(name, plan2, select, condition, mode) {
3675
3682
  return {
3676
3683
  ...built,
3677
3684
  op,
3678
- mode
3685
+ mode,
3686
+ ...description !== void 0 ? { description } : {}
3679
3687
  };
3680
3688
  }
3681
3689
  function normalizeReturnSelection(select) {
@@ -3761,7 +3769,8 @@ function readDescriptorToOp(name, d) {
3761
3769
  keys,
3762
3770
  ...isQuery ? { keyFields: keyFieldNames2 } : {},
3763
3771
  ...select !== void 0 ? { select } : {},
3764
- ...compose.length > 0 ? { compose } : {}
3772
+ ...compose.length > 0 ? { compose } : {},
3773
+ ...d.description !== void 0 ? { description: d.description } : {}
3765
3774
  };
3766
3775
  }
3767
3776
  function writeDescriptorToPlan(name, d) {
@@ -3795,7 +3804,7 @@ function writeDescriptorToPlan(name, d) {
3795
3804
  });
3796
3805
  const select = d.result !== void 0 && d.result.select !== void 0 ? d.result.select : void 0;
3797
3806
  const condition = d.condition !== void 0 ? descriptorConditionRecord(d.condition, name) : void 0;
3798
- return { plan: plan2, select, condition, mode: d.mode ?? "transaction" };
3807
+ return { plan: plan2, select, condition, mode: d.mode ?? "transaction", description: d.description };
3799
3808
  }
3800
3809
 
3801
3810
  // src/spec/mutation-command.ts
@@ -3952,9 +3961,8 @@ var MAINTAIN_ENTITY_PATH_RE = /^\$\.entity\.([A-Za-z_$][\w$]*)$/;
3952
3961
  var cachedMaintenanceGraph;
3953
3962
  function globalMaintenanceGraph() {
3954
3963
  const generation = MetadataRegistry.generation;
3955
- const viewGeneration = ViewRegistry.generation;
3956
- if (cachedMaintenanceGraph?.generation !== generation || cachedMaintenanceGraph?.viewGeneration !== viewGeneration) {
3957
- cachedMaintenanceGraph = { graph: buildMaintenanceGraph(), generation, viewGeneration };
3964
+ if (cachedMaintenanceGraph?.generation !== generation) {
3965
+ cachedMaintenanceGraph = { graph: buildMaintenanceGraph(), generation };
3958
3966
  }
3959
3967
  return cachedMaintenanceGraph.graph;
3960
3968
  }
@@ -5699,10 +5707,12 @@ function paramSpecs(params) {
5699
5707
  const out = {};
5700
5708
  for (const name of Object.keys(params).sort()) {
5701
5709
  const d = params[name];
5702
- out[name] = d.literals === void 0 ? { type: d.kind, required: d.required } : {
5710
+ out[name] = {
5703
5711
  type: d.kind,
5704
5712
  required: d.required,
5705
- literals: d.literals
5713
+ ...d.literals !== void 0 ? { literals: d.literals } : {},
5714
+ // Pure-documentation description (issue #154); absent → byte-identical spec.
5715
+ ...d.description !== void 0 ? { description: d.description } : {}
5706
5716
  };
5707
5717
  }
5708
5718
  return out;
@@ -5931,6 +5941,7 @@ function buildCommandSpec(def) {
5931
5941
  const params = paramSpecs(def.params);
5932
5942
  const entity = def.entity.name;
5933
5943
  const condition = extractCondition(def);
5944
+ const description = def.description !== void 0 ? { description: def.description } : {};
5934
5945
  if (def.operation === "put") {
5935
5946
  const item = templateRecord3(def.key);
5936
5947
  return {
@@ -5939,7 +5950,8 @@ function buildCommandSpec(def) {
5939
5950
  entity,
5940
5951
  params,
5941
5952
  item,
5942
- ...condition ? { condition } : {}
5953
+ ...condition ? { condition } : {},
5954
+ ...description
5943
5955
  };
5944
5956
  }
5945
5957
  if (def.operation === "delete") {
@@ -5949,7 +5961,8 @@ function buildCommandSpec(def) {
5949
5961
  entity,
5950
5962
  params,
5951
5963
  keyCondition: writeKeyCondition(metadata, def.key, entity),
5952
- ...condition ? { condition } : {}
5964
+ ...condition ? { condition } : {},
5965
+ ...description
5953
5966
  };
5954
5967
  }
5955
5968
  return {
@@ -5959,7 +5972,8 @@ function buildCommandSpec(def) {
5959
5972
  params,
5960
5973
  keyCondition: writeKeyCondition(metadata, def.key, entity),
5961
5974
  changes: templateRecord3(def.changes),
5962
- ...condition ? { condition } : {}
5975
+ ...condition ? { condition } : {},
5976
+ ...description
5963
5977
  };
5964
5978
  }
5965
5979
  function writeKeyCondition(metadata, key, entity) {
@@ -6026,7 +6040,9 @@ function buildQuerySpec(def) {
6026
6040
  operations,
6027
6041
  // `defineQuery` → a single entity object; `defineList` → a connection.
6028
6042
  cardinality: def.operation === "query" ? "one" : "many",
6029
- ...executionPlan !== void 0 ? { executionPlan } : {}
6043
+ ...executionPlan !== void 0 ? { executionPlan } : {},
6044
+ // Pure-documentation description (issue #154); absent → byte-identical spec.
6045
+ ...def.description !== void 0 ? { description: def.description } : {}
6030
6046
  };
6031
6047
  }
6032
6048
  function mergeSpecs(base, synthesized, kind) {
@@ -6790,7 +6806,9 @@ function serializeQueryContract(contractName, contract, querySpecs, contracts) {
6790
6806
  cardinality: method.resolution === "point" ? "one" : "many",
6791
6807
  operation: opName,
6792
6808
  ...compose.length > 0 ? { compose } : {},
6793
- ...compositionPlan !== void 0 ? { compositionPlan } : {}
6809
+ ...compositionPlan !== void 0 ? { compositionPlan } : {},
6810
+ // Pure-documentation description (issue #154); absent → byte-identical spec.
6811
+ ...method.description !== void 0 ? { description: method.description } : {}
6794
6812
  };
6795
6813
  }
6796
6814
  return {
@@ -6878,7 +6896,9 @@ function serializeCommandContract(contractName, contract, commandSpecs, transact
6878
6896
  result: method.result,
6879
6897
  single,
6880
6898
  ...batch !== void 0 ? { batch } : {},
6881
- ...returnSelection !== void 0 && Object.keys(returnSelection).length > 0 ? { returnSelection: sortedReturnSelection(returnSelection) } : {}
6899
+ ...returnSelection !== void 0 && Object.keys(returnSelection).length > 0 ? { returnSelection: sortedReturnSelection(returnSelection) } : {},
6900
+ // Pure-documentation description (issue #154); absent → byte-identical spec.
6901
+ ...method.description !== void 0 ? { description: method.description } : {}
6882
6902
  };
6883
6903
  }
6884
6904
  return {
package/dist/cli.js CHANGED
@@ -2,10 +2,10 @@
2
2
  import {
3
3
  buildBridgeBundle,
4
4
  normalizeSelectSpec
5
- } from "./chunk-VST3WOK3.js";
5
+ } from "./chunk-G5RWWBAL.js";
6
6
  import {
7
7
  MetadataRegistry
8
- } from "./chunk-YIXXTGZ6.js";
8
+ } from "./chunk-CPTV3H2U.js";
9
9
 
10
10
  // src/cli.ts
11
11
  import { createRequire } from "module";
@@ -467,9 +467,16 @@ function pyTransactionParamType(txName, paramName, spec) {
467
467
  }
468
468
  return pyParamType(spec);
469
469
  }
470
+ function pyDocLine(text) {
471
+ return text.replace(/\\/g, "\\\\").replace(/"""/g, '\\"\\"\\"').replace(/\r?\n/g, " ").trim();
472
+ }
473
+ function pyCommentLine(text) {
474
+ return text.replace(/\r?\n/g, " ").trim();
475
+ }
470
476
  function collectResultTypes(manifest, entity, select, typeName, out, seen) {
471
477
  const meta = manifest.entities[entity];
472
478
  const fields = [];
479
+ const fieldDescriptions = {};
473
480
  for (const field of Object.keys(select).sort()) {
474
481
  const value = select[field];
475
482
  const relation = meta?.relations[field];
@@ -504,13 +511,23 @@ function collectResultTypes(manifest, entity, select, typeName, out, seen) {
504
511
  continue;
505
512
  }
506
513
  if (value === true) {
507
- const fieldType = meta?.fields[field]?.type ?? "string";
514
+ const manifestField = meta?.fields[field];
515
+ const fieldType = manifestField?.type ?? "string";
508
516
  fields.push([field, pyScalarType(fieldType)]);
517
+ if (manifestField?.description !== void 0) {
518
+ fieldDescriptions[field] = manifestField.description;
519
+ }
509
520
  }
510
521
  }
511
522
  if (!seen.has(typeName)) {
512
523
  seen.add(typeName);
513
- out.push({ name: typeName, fields });
524
+ out.push({
525
+ name: typeName,
526
+ fields,
527
+ ...Object.keys(fieldDescriptions).length > 0 ? { fieldDescriptions } : {},
528
+ // The entity's own description (issue #154) becomes the result class docstring.
529
+ ...meta?.description !== void 0 ? { docstring: meta.description } : {}
530
+ });
514
531
  }
515
532
  }
516
533
  function selectOf(def) {
@@ -519,29 +536,44 @@ function selectOf(def) {
519
536
  function queryResultTypeName(queryName) {
520
537
  return `${toPascalCase(queryName)}Result`;
521
538
  }
539
+ function classDocstringLines(cls) {
540
+ return cls.docstring !== void 0 ? [` """${pyDocLine(cls.docstring)}"""`] : [];
541
+ }
542
+ function withFieldComment(cls, name, line) {
543
+ const desc = cls.fieldDescriptions?.[name];
544
+ return desc !== void 0 ? `${line} # ${pyCommentLine(desc)}` : line;
545
+ }
522
546
  function renderTypedDict(cls) {
547
+ const doc = classDocstringLines(cls);
523
548
  if (cls.fields.length === 0) {
524
- return `class ${cls.name}(TypedDict):
549
+ return doc.length > 0 ? `class ${cls.name}(TypedDict):
550
+ ${doc.join("\n")}` : `class ${cls.name}(TypedDict):
525
551
  pass`;
526
552
  }
527
- const lines = cls.fields.map(([name, type]) => ` ${name}: ${type}`);
553
+ const lines = cls.fields.map(
554
+ ([name, type]) => withFieldComment(cls, name, ` ${name}: ${type}`)
555
+ );
528
556
  return `class ${cls.name}(TypedDict):
529
- ${lines.join("\n")}`;
557
+ ${[...doc, ...lines].join("\n")}`;
530
558
  }
531
559
  function renderDataclass(cls) {
560
+ const doc = classDocstringLines(cls);
532
561
  if (cls.fields.length === 0) {
533
- return `@dataclass
562
+ return doc.length > 0 ? `@dataclass
563
+ class ${cls.name}:
564
+ ${doc.join("\n")}` : `@dataclass
534
565
  class ${cls.name}:
535
566
  pass`;
536
567
  }
537
568
  const lines = cls.fields.map(
538
- ([name, type]) => type.endsWith("| None") ? ` ${name}: ${type} = None` : ` ${name}: ${type}`
569
+ ([name, type]) => type.endsWith("| None") ? withFieldComment(cls, name, ` ${name}: ${type} = None`) : withFieldComment(cls, name, ` ${name}: ${type}`)
539
570
  );
540
- const required = lines.filter((l) => !l.endsWith("= None"));
541
- const optional = lines.filter((l) => l.endsWith("= None"));
571
+ const isOptional = (l) => /:\s.*\| None\s*=\sNone(\s+#.*)?$/.test(l);
572
+ const required = lines.filter((l) => !isOptional(l));
573
+ const optional = lines.filter(isOptional);
542
574
  return `@dataclass
543
575
  class ${cls.name}:
544
- ${[...required, ...optional].join("\n")}`;
576
+ ${[...doc, ...required, ...optional].join("\n")}`;
545
577
  }
546
578
  function collectTransactionElementTypes(transactions, out, seen) {
547
579
  for (const txName of Object.keys(transactions).sort()) {
@@ -625,7 +657,8 @@ function collectRepositories(queries, commands) {
625
657
  params: methodParams(def),
626
658
  returnType: `${queryResultTypeName(name)} | None`,
627
659
  kind: "query",
628
- operationId: name
660
+ operationId: name,
661
+ ...def.description !== void 0 ? { description: def.description } : {}
629
662
  });
630
663
  }
631
664
  for (const name of Object.keys(commands).sort()) {
@@ -635,7 +668,8 @@ function collectRepositories(queries, commands) {
635
668
  params: methodParams(def),
636
669
  returnType: "None",
637
670
  kind: "command",
638
- operationId: name
671
+ operationId: name,
672
+ ...def.description !== void 0 ? { description: def.description } : {}
639
673
  });
640
674
  }
641
675
  return [...byEntity.keys()].sort().map((className) => ({
@@ -646,11 +680,13 @@ function collectRepositories(queries, commands) {
646
680
  function renderMethod(m) {
647
681
  const sig = m.params.map((p) => `${p.argName}: ${p.pyType}`).join(", ");
648
682
  const head = ` def ${m.methodName}(self${sig ? ", " + sig : ""}) -> ${m.returnType}:`;
683
+ const doc = m.description !== void 0 ? [` """${pyDocLine(m.description)}"""`] : [];
649
684
  const paramsDict = m.params.map((p) => `"${p.originalName}": ${p.argName}`).join(", ");
650
685
  const paramsArg = paramsDict ? `{${paramsDict}}` : "{}";
651
686
  if (m.kind === "query") {
652
687
  return [
653
688
  head,
689
+ ...doc,
654
690
  ` return self._runtime.execute_query(`,
655
691
  ` query_id="${m.operationId}",`,
656
692
  ` params=${paramsArg},`,
@@ -659,6 +695,7 @@ function renderMethod(m) {
659
695
  }
660
696
  return [
661
697
  head,
698
+ ...doc,
662
699
  ` self._runtime.execute_command(`,
663
700
  ` command_id="${m.operationId}",`,
664
701
  ` params=${paramsArg},`,