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