@panproto/core 0.10.0 → 0.11.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/dist/index.cjs CHANGED
@@ -45,6 +45,8 @@ async function loadWasm(input) {
45
45
  const exports$1 = {
46
46
  define_protocol: glue.define_protocol,
47
47
  build_schema: glue.build_schema,
48
+ parse_atproto_lexicon: glue.parse_atproto_lexicon,
49
+ schema_metadata: glue.schema_metadata,
48
50
  check_existence: glue.check_existence,
49
51
  compile_migration: glue.compile_migration,
50
52
  lift_record: glue.lift_record,
@@ -2119,6 +2121,61 @@ class Panproto {
2119
2121
  this.#protocols.set(spec.name, proto);
2120
2122
  return proto;
2121
2123
  }
2124
+ /**
2125
+ * Parse an ATProto lexicon JSON document into a schema.
2126
+ *
2127
+ * This is the universal entry point for any ATProto-compatible lexicon —
2128
+ * works for Bluesky, RelationalText, Layers, and any custom lexicon.
2129
+ * The resulting schema can be used with `lens()`, `convert()`, `diff()`,
2130
+ * and all other schema operations.
2131
+ *
2132
+ * @param lexiconJson - The lexicon JSON (object or string)
2133
+ * @returns A built schema that can be used for migration, lens generation, etc.
2134
+ * @throws {@link PanprotoError} if the lexicon is not valid ATProto Lexicon JSON
2135
+ *
2136
+ * @example
2137
+ * ```typescript
2138
+ * const rtSchema = panproto.parseLexicon(rtDocumentLexicon);
2139
+ * const layersSchema = panproto.parseLexicon(layersAnnotationLexicon);
2140
+ * const lens = panproto.lens(rtSchema, layersSchema);
2141
+ * ```
2142
+ */
2143
+ parseLexicon(lexiconJson) {
2144
+ const jsonStr = typeof lexiconJson === "string" ? lexiconJson : JSON.stringify(lexiconJson);
2145
+ const jsonBytes = new TextEncoder().encode(jsonStr);
2146
+ let rawHandle;
2147
+ try {
2148
+ rawHandle = this.#wasm.exports.parse_atproto_lexicon(jsonBytes);
2149
+ } catch (error) {
2150
+ throw new PanprotoError(
2151
+ `Failed to parse lexicon: ${error instanceof Error ? error.message : String(error)}`
2152
+ );
2153
+ }
2154
+ const metaBytes = this.#wasm.exports.schema_metadata(rawHandle);
2155
+ const meta = unpackFromWasm(metaBytes);
2156
+ const data = {
2157
+ protocol: meta.protocol,
2158
+ vertices: Object.fromEntries(
2159
+ meta.vertices.map((v) => [v.id, { id: v.id, kind: v.kind, nsid: v.nsid }])
2160
+ ),
2161
+ edges: meta.edges.map((e) => ({
2162
+ src: e.src,
2163
+ tgt: e.tgt,
2164
+ kind: e.kind,
2165
+ name: e.name
2166
+ })),
2167
+ hyperEdges: {},
2168
+ constraints: {},
2169
+ required: {},
2170
+ variants: {},
2171
+ orderings: {},
2172
+ recursionPoints: {},
2173
+ usageModes: {},
2174
+ spans: {},
2175
+ nominal: {}
2176
+ };
2177
+ return BuiltSchema._fromHandle(rawHandle, data, meta.protocol, this.#wasm);
2178
+ }
2122
2179
  /**
2123
2180
  * Start building a migration between two schemas.
2124
2181
  *