schemaorg-kit 1.1.1 → 1.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/README.md CHANGED
@@ -87,33 +87,42 @@ console.log(article.toScript());
87
87
 
88
88
  ## `@graph` Support
89
89
 
90
- Use `createGraph` to output multiple schema nodes in a single `<script>` tag with `@id` cross-references:
90
+ Use `createGraph` to output multiple schema nodes in a single `<script>` tag. Use `SchemaIds` for consistent `@id` cross-references:
91
91
 
92
92
  ```typescript
93
93
  import {
94
+ SchemaIds,
94
95
  createGraph,
96
+ createOrganization,
97
+ createWebSite,
95
98
  createWebPage,
96
- createArticle,
97
- createPerson,
98
99
  } from "schemaorg-kit";
99
100
 
101
+ const ids = new SchemaIds("https://example.com");
102
+
100
103
  const graph = createGraph([
101
- createWebPage({
102
- "@id": "https://example.com/post#webpage",
103
- url: "https://example.com/post",
104
+ createOrganization({
105
+ "@id": ids.organization(),
106
+ name: "Acme Corp",
107
+ url: "https://example.com",
104
108
  }),
105
- createArticle({
106
- "@id": "https://example.com/post#article",
107
- headline: "Hello World",
108
- isPartOf: { "@id": "https://example.com/post#webpage" },
109
- author: { "@id": "https://example.com/about#person" },
109
+ createWebSite({
110
+ "@id": ids.website(),
111
+ name: "Acme",
112
+ url: "https://example.com",
113
+ publisher: ids.ref("organization"), // { "@id": "https://example.com/#organization" }
114
+ }),
115
+ createWebPage({
116
+ "@id": ids.webpage(),
117
+ url: "https://example.com",
110
118
  }),
111
- createPerson({ "@id": "https://example.com/about#person", name: "Jane Doe" }),
112
119
  ]);
113
120
 
114
121
  console.log(graph.toScript());
115
122
  ```
116
123
 
124
+ `SchemaIds` provides well-known methods (`organization()`, `website()`, `webpage()`, `person()`, etc.), `custom()` for arbitrary fragments, `forPath()` for page-scoped IDs, and `ref()` for cross-reference objects.
125
+
117
126
  ## Unified Factory
118
127
 
119
128
  As an alternative to named imports, use the `schema()` factory with any registered type name:
@@ -280,7 +289,8 @@ src/
280
289
  ├── core/
281
290
  │ ├── base.ts # SchemaNode<T> class + makeFactory()
282
291
  │ ├── registry.ts # Unified schema() factory + REGISTRY
283
- └── graph.ts # SchemaGraph + createGraph()
292
+ ├── graph.ts # SchemaGraph + createGraph()
293
+ │ └── ids.ts # SchemaIds + SchemaId (cross-reference helpers)
284
294
  ├── types/
285
295
  │ ├── shared/ # Reusable building blocks
286
296
  │ │ ├── Offer.ts # Offer, AggregateOffer, MerchantReturnPolicy, UnitPriceSpecification, ItemCondition