@adhd/apigen-base-logical 0.0.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.
- package/index.d.ts +10 -0
- package/index.js +1 -0
- package/index.mjs +751 -0
- package/lib/codecs/byte.d.ts +13 -0
- package/lib/codecs/date-time.d.ts +11 -0
- package/lib/codecs/decimal.d.ts +29 -0
- package/lib/codecs/index.d.ts +24 -0
- package/lib/codecs/int64.d.ts +12 -0
- package/lib/codecs/number-special.d.ts +22 -0
- package/lib/codecs/uuid.d.ts +10 -0
- package/lib/contracts.d.ts +60 -0
- package/lib/descriptor-ext.d.ts +25 -0
- package/lib/emit.d.ts +113 -0
- package/lib/hints.d.ts +86 -0
- package/lib/registry.d.ts +37 -0
- package/lib/runmode.d.ts +97 -0
- package/package.json +7 -0
package/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type { LogicalTypeId, LogicalKind, Wire, SchemaNode, TranscodeCtx, LogicalTypeCodec, TemplateCell, ApigenEnvelope, Transcoder, } from './lib/contracts';
|
|
2
|
+
export { ENVELOPE_KEY } from './lib/contracts';
|
|
3
|
+
export type { LogicalTypeRegistry } from './lib/registry';
|
|
4
|
+
export { createRegistry, CodecRegistryError } from './lib/registry';
|
|
5
|
+
export { X_APIGEN_LOGICAL, X_APIGEN_CODEC, X_APIGEN_CTOR, X_APIGEN_TOJSON, LOGICAL_TYPE_VERSION, logicalKindOf, codecIdOf, } from './lib/descriptor-ext';
|
|
6
|
+
export { buildTranscoder, tryRegister, validateSchemaRefs } from './lib/runmode';
|
|
7
|
+
export { dateTimeCodec, int64Codec, decimalCodec, makeDecimal, byteCodec, uuidCodec, numberSpecialCodec, registerWellKnown, } from './lib/codecs/index';
|
|
8
|
+
export type { DecimalString } from './lib/codecs/index';
|
|
9
|
+
export { CANONICAL_LOGICAL_TYPE_IDS, TEMPLATE_CELLS, cellsFor, depsForLogicalTypes, tsDepMap, assertNoEmptyCells, } from './lib/hints';
|
|
10
|
+
export type { CanonicalLogicalTypeId, HostLanguage, LanguageTable, } from './lib/hints';
|
package/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l="$apigen";class C extends Error{constructor(o){super(o),this.code="E_DUP_CODEC",this.name="CodecRegistryError"}}function P(e){e==null||e.wellKnown;const o=new Map;return{register(n,r){if(o.has(n.id)&&!(r!=null&&r.override))throw new C(`E_DUP_CODEC: a codec is already registered for id "${n.id}"`);o.set(n.id,n)},resolve(n){for(const r of o.values())if(r.matches(n))return r},get(n){return o.get(n)},ids(){return[...o.keys()]},freeze(){const n=new Map(o),r={register(){throw new C("E_DUP_CODEC: registry is frozen and cannot accept new codecs")},resolve(d){for(const a of n.values())if(a.matches(d))return a},get(d){return n.get(d)},ids(){return[...n.keys()]},freeze(){return r}};return r}}}const $="x-apigen-logical",v="x-apigen-codec",j="x-apigen-ctor",M="x-apigen-tojson",R="0.1.0",G=["scalar","nominal","union","map","set"];function w(e){const o=e[$];return typeof o=="string"&&G.includes(o)?o:void 0}function B(e){const o=e[v];return typeof o=="string"?o:void 0}function T(e,o){return{registry:e,resolve:t=>{throw new Error(`[apigen-logical] $ref "${t}" cannot be resolved in run-mode without a descriptor root. Supply a resolve() in the ctx override to handle $ref.`)},seen:new WeakSet,path:"",mode:"strict",...o}}function p(e,o,t){const n=t.registry.resolve(o);if(n)return n.encode(e,o,t);const r=o.$ref;if(typeof r=="string"){const i=t.resolve(r);return p(e,i,t)}const d=o.oneOf;if(Array.isArray(d)){const i=U(e,d,o);return p(e,i,t)}const a=o.type;if(a==="array"){if(!Array.isArray(e))return D(e,o,t);const i=o.items;if(!i)return e.map(c=>u(c));const f=t.path;return Array.isArray(i)?e.map((c,_)=>{const s=i[_];return s===void 0?u(c):p(c,s,{...t,path:`${f}/${_}`})}):e.map((c,_)=>p(c,i,{...t,path:`${f}/${_}`}))}if(a==="object"){if(e===null||typeof e!="object"||Array.isArray(e))return D(e,o,t);const i=o.properties;if(!i)return u(e);const f=t.path,c={};for(const[_,s]of Object.entries(i)){const m=e[_];m!==void 0&&(c[_]=p(m,s,{...t,path:`${f}/${_}`}))}return c}return a==null?D(e,o,t):u(e)}function E(e,o,t){const n=t.registry.resolve(o);if(n)return n.decode(e,o,t);const r=o.$ref;if(typeof r=="string"){const i=t.resolve(r);return E(e,i,t)}const d=o.oneOf;if(Array.isArray(d)){const i=U(e,d,o);return E(e,i,t)}const a=o.type;if(a==="array"){if(!Array.isArray(e))return e;const i=o.items;if(!i)return e;const f=t.path;return Array.isArray(i)?e.map((c,_)=>{const s=i[_];return s===void 0?c:E(c,s,{...t,path:`${f}/${_}`})}):e.map((c,_)=>E(c,i,{...t,path:`${f}/${_}`}))}if(a==="object"){if(e===null||typeof e!="object"||Array.isArray(e))return e;const i=o.properties;if(!i)return e;const f=t.path,c={};for(const[_,s]of Object.entries(i)){const m=e[_];m!==void 0&&(c[_]=E(m,s,{...t,path:`${f}/${_}`}))}return c}return a==null?k(e,t):e}function U(e,o,t,n){const r=t.discriminator;if(r!=null&&r.propertyName){const d=e!==null&&typeof e=="object"?e[r.propertyName]:void 0;if(typeof d=="string"&&r.mapping){const a=r.mapping[d];if(a){const i=o.find(f=>f.$ref===a);if(i)return i}}}return o[0]??{}}function D(e,o,t){for(const n of t.registry.ids()){const r=t.registry.get(n);if(r)try{const d=r.encode(e,r.schema,t);return{[l]:n,v:d}}catch{}}return u(e)}function k(e,o){if(e!==null&&typeof e=="object"&&!Array.isArray(e)&&l in e){const t=e,n=t[l],r=o.registry.get(n);if(r)return r.decode(t.v,r.schema,o)}return e}function u(e){if(e===null||typeof e=="string"||typeof e=="number"||typeof e=="boolean")return e;if(Array.isArray(e))return e.map(u);if(typeof e=="object"){const o={};for(const[t,n]of Object.entries(e))n!==void 0&&(o[t]=u(n));return o}return null}function J(e,o){const t=new Set,n=[e];for(;n.length>0;){const r=n.pop();if(!r||t.has(r))continue;t.add(r);const d=r.$ref;if(typeof d=="string"){if(o){const s=o[d];if(!s){const m=Object.keys(o).join(", ")||"(none)";throw new Error(`[apigen-logical] $ref "${d}" cannot be resolved. Available $defs: ${m}`)}n.push(s)}continue}const a=r.oneOf;if(Array.isArray(a))for(const s of a)typeof s=="object"&&s!==null&&n.push(s);const i=r.properties;if(i)for(const s of Object.values(i))n.push(s);const f=r.items;if(Array.isArray(f))for(const s of f)typeof s=="object"&&s!==null&&n.push(s);else typeof f=="object"&&f!==null&&n.push(f);const c=r.additionalProperties;typeof c=="object"&&c!==null&&n.push(c);const _=r.propertyNames;typeof _=="object"&&_!==null&&n.push(_)}}function V(e){return{encode(o,t,n){const r=T(e,n);return p(o,t,r)},decode(o,t,n){const r=T(e,n);return E(o,t,r)}}}function Y(e,o,t){try{const n=t();e.register(n)}catch(n){if(K(n))return;throw n}}function K(e){return e===null||typeof e!="object"?!1:e.code==="MODULE_NOT_FOUND"}const h={id:"date-time",kind:"scalar",schema:{type:"string",format:"date-time"},matches(e){return e.type==="string"&&e.format==="date-time"},encode(e,o,t){return e.toISOString()},decode(e,o,t){if(typeof e!="string"){if(t.mode==="strict")throw new TypeError(`[date-time] expected a string on the wire at "${t.path}", got ${typeof e}`);return new Date(String(e))}if(t.mode==="strict"&&Number.isNaN(new Date(e).getTime()))throw new TypeError(`[date-time] invalid date-time string at "${t.path}": ${JSON.stringify(e)}`);return new Date(e)}},S={id:"int64",kind:"scalar",schema:{type:"string",format:"int64"},matches(e){return e.type==="string"&&e.format==="int64"},encode(e,o,t){return String(e)},decode(e,o,t){if(typeof e!="string"){if(t.mode==="strict")throw new TypeError(`[int64] expected a string on the wire at "${t.path}", got ${typeof e}`);try{return BigInt(Math.trunc(Number(e)))}catch{return BigInt(0)}}if(t.mode==="strict")return BigInt(e);if(/^-?\d+$/.test(e))try{return BigInt(e)}catch{return BigInt(0)}return BigInt(0)}};function W(e){return e}const N={id:"decimal",kind:"scalar",schema:{type:"string",format:"decimal"},matches(e){return e.type==="string"&&e.format==="decimal"},encode(e,o,t){return e},decode(e,o,t){if(typeof e!="string"){if(t.mode==="strict")throw new TypeError(`[decimal] expected a string on the wire at "${t.path}", got ${typeof e}`);return String(e)}if(t.mode==="strict"&&!/^-?\d+(\.\d+)?$/.test(e))throw new TypeError(`[decimal] wire value "${e}" at "${t.path}" is not a valid decimal string`);return e}},b={id:"byte",kind:"scalar",schema:{type:"string",format:"byte"},matches(e){return e.type==="string"&&e.format==="byte"},encode(e,o,t){return Buffer.from(e).toString("base64")},decode(e,o,t){if(typeof e!="string"){if(t.mode==="strict")throw new TypeError(`[byte] expected a base64 string on the wire at "${t.path}", got ${typeof e}`);return new Uint8Array(0)}if(t.mode==="strict"&&!/^[A-Za-z0-9+/]*={0,2}$/.test(e))throw new TypeError(`[byte] wire value at "${t.path}" is not standard base64 (format:byte): "${e}"`);return new Uint8Array(Buffer.from(e,"base64"))}},z=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/,L={id:"uuid",kind:"scalar",schema:{type:"string",format:"uuid"},matches(e){return e.type==="string"&&e.format==="uuid"},encode(e,o,t){return e.toLowerCase()},decode(e,o,t){if(typeof e!="string"){if(t.mode==="strict")throw new TypeError(`[uuid] expected a string on the wire at "${t.path}", got ${typeof e}`);return String(e).toLowerCase()}if(t.mode==="strict"&&!z.test(e))throw new TypeError(`[uuid] wire value "${e}" at "${t.path}" is not a lowercase-hyphenated RFC 4122 UUID`);return e}},O="NaN",A="Infinity",g="-Infinity",X=new Set([O,A,g]),F={id:"number-special",kind:"scalar",schema:{type:"number"},matches(e){return e.type==="number"&&e.format===void 0},encode(e,o,t){return Number.isNaN(e)?O:e===1/0?A:e===-1/0?g:e},decode(e,o,t){if(typeof e=="number")return e;if(typeof e=="string"){if(e===O)return NaN;if(e===A)return 1/0;if(e===g)return-1/0;const n=Number(e);if(!Number.isNaN(n))return n}if(t.mode==="strict")throw new TypeError(`[number-special] unrecognized wire value at "${t.path}": ${JSON.stringify(e)}. Expected a number or one of ${[...X].join(", ")}.`);return NaN}},H=[h,S,N,b,L,F];function Z(e,o={}){for(const t of H)e.register(t,{override:o.override??!1})}const I=[h.id,S.id,N.id,b.id,L.id,F.id],q={"date-time":{encode:"$.toISOString()",decode:"new Date($)",mode:"native"},int64:{encode:"String($)",decode:"BigInt($)",mode:"native"},decimal:{encode:"$.toString()",decode:"new Decimal($)",imports:[],dep:{name:"decimal.js",version:"^10"},mode:"branded"},byte:{encode:"Buffer.from($).toString('base64')",decode:"new Uint8Array(Buffer.from($, 'base64'))",mode:"native"},uuid:{encode:"$.toLowerCase()",decode:"$",mode:"native"},"number-special":{encode:"numToWire($)",decode:"wireToNum($)",mode:"native"}},Q={"date-time":{encode:"$.isoformat()",decode:"datetime.fromisoformat($)",imports:["from datetime import datetime"],mode:"native"},int64:{encode:"str($)",decode:"int($)",mode:"native"},decimal:{encode:"str($)",decode:"Decimal($)",imports:["from decimal import Decimal"],mode:"native"},byte:{encode:"b64encode($).decode()",decode:"b64decode($)",imports:["from base64 import b64encode, b64decode"],mode:"native"},uuid:{encode:"str($)",decode:"UUID($)",imports:["from uuid import UUID"],mode:"native"},"number-special":{encode:"num_to_wire($)",decode:"wire_to_num($)",mode:"native"}},x={"date-time":{encode:"__SCAFFOLD_RUST_DATETIME_ENCODE__",decode:"__SCAFFOLD_RUST_DATETIME_DECODE__",imports:["use chrono::{DateTime, Utc};"],dep:{name:"chrono",version:"^0.4"},mode:"lib"},int64:{encode:"__SCAFFOLD_RUST_INT64_ENCODE__",decode:"__SCAFFOLD_RUST_INT64_DECODE__",imports:["use serde_with::DisplayFromStr;"],dep:{name:"serde_with",version:"^3"},mode:"lib"},decimal:{encode:"__SCAFFOLD_RUST_DECIMAL_ENCODE__",decode:"__SCAFFOLD_RUST_DECIMAL_DECODE__",imports:["use rust_decimal::Decimal;"],dep:{name:"rust_decimal",version:"^1"},mode:"lib"},byte:{encode:"__SCAFFOLD_RUST_BYTE_ENCODE__",decode:"__SCAFFOLD_RUST_BYTE_DECODE__",imports:["use serde_with::base64::Base64;"],dep:{name:"serde_with",version:"^3"},mode:"lib"},uuid:{encode:"__SCAFFOLD_RUST_UUID_ENCODE__",decode:"__SCAFFOLD_RUST_UUID_DECODE__",imports:["use uuid::Uuid;"],dep:{name:"uuid",version:"^1"},mode:"lib"},"number-special":{encode:"__SCAFFOLD_RUST_NUMSPECIAL_ENCODE__",decode:"__SCAFFOLD_RUST_NUMSPECIAL_DECODE__",mode:"native"}},ee={"date-time":{encode:"__SCAFFOLD_GO_DATETIME_ENCODE__",decode:"__SCAFFOLD_GO_DATETIME_DECODE__",imports:['"time"'],mode:"native"},int64:{encode:"__SCAFFOLD_GO_INT64_ENCODE__",decode:"__SCAFFOLD_GO_INT64_DECODE__",imports:['"strconv"'],mode:"native"},decimal:{encode:"__SCAFFOLD_GO_DECIMAL_ENCODE__",decode:"__SCAFFOLD_GO_DECIMAL_DECODE__",imports:['"github.com/shopspring/decimal"'],dep:{name:"github.com/shopspring/decimal",version:"v1"},mode:"lib"},byte:{encode:"__SCAFFOLD_GO_BYTE_ENCODE__",decode:"__SCAFFOLD_GO_BYTE_DECODE__",imports:['"encoding/base64"'],mode:"native"},uuid:{encode:"__SCAFFOLD_GO_UUID_ENCODE__",decode:"__SCAFFOLD_GO_UUID_DECODE__",imports:['"github.com/google/uuid"'],dep:{name:"github.com/google/uuid",version:"v1"},mode:"lib"},"number-special":{encode:"__SCAFFOLD_GO_NUMSPECIAL_ENCODE__",decode:"__SCAFFOLD_GO_NUMSPECIAL_DECODE__",mode:"native"}},te={"date-time":{encode:"__SCAFFOLD_JAVA_DATETIME_ENCODE__",decode:"__SCAFFOLD_JAVA_DATETIME_DECODE__",imports:["import java.time.Instant;"],dep:{name:"jackson-datatype-jsr310",version:"2.x"},mode:"lib"},int64:{encode:"__SCAFFOLD_JAVA_INT64_ENCODE__",decode:"__SCAFFOLD_JAVA_INT64_DECODE__",imports:["import com.fasterxml.jackson.annotation.JsonFormat;"],mode:"native"},decimal:{encode:"__SCAFFOLD_JAVA_DECIMAL_ENCODE__",decode:"__SCAFFOLD_JAVA_DECIMAL_DECODE__",imports:["import java.math.BigDecimal;"],mode:"native"},byte:{encode:"__SCAFFOLD_JAVA_BYTE_ENCODE__",decode:"__SCAFFOLD_JAVA_BYTE_DECODE__",mode:"native"},uuid:{encode:"__SCAFFOLD_JAVA_UUID_ENCODE__",decode:"__SCAFFOLD_JAVA_UUID_DECODE__",imports:["import java.util.UUID;"],mode:"native"},"number-special":{encode:"__SCAFFOLD_JAVA_NUMSPECIAL_ENCODE__",decode:"__SCAFFOLD_JAVA_NUMSPECIAL_DECODE__",mode:"native"}},y=Object.freeze({typescript:q,python:Q,rust:x,go:ee,java:te});function oe(e){return y[e]}function ne(e,o){const t=y[o],n=[];for(const r of e){const d=t[r];d!=null&&d.dep&&n.push({id:r,dep:d.dep})}return n}function re(){const e=y.typescript,o={};for(const t of I){const n=e[t].dep;n&&(o[t]=n)}return Object.freeze(o)}function ie(e,o){const t=o??y[e],n=[];for(const r of I)t[r]||n.push(r);if(n.length>0)throw new Error(`[hints] assertNoEmptyCells: language "${e}" is missing cells for: ${n.join(", ")}`)}exports.CANONICAL_LOGICAL_TYPE_IDS=I;exports.CodecRegistryError=C;exports.ENVELOPE_KEY=l;exports.LOGICAL_TYPE_VERSION=R;exports.TEMPLATE_CELLS=y;exports.X_APIGEN_CODEC=v;exports.X_APIGEN_CTOR=j;exports.X_APIGEN_LOGICAL=$;exports.X_APIGEN_TOJSON=M;exports.assertNoEmptyCells=ie;exports.buildTranscoder=V;exports.byteCodec=b;exports.cellsFor=oe;exports.codecIdOf=B;exports.createRegistry=P;exports.dateTimeCodec=h;exports.decimalCodec=N;exports.depsForLogicalTypes=ne;exports.int64Codec=S;exports.logicalKindOf=w;exports.makeDecimal=W;exports.numberSpecialCodec=F;exports.registerWellKnown=Z;exports.tryRegister=Y;exports.tsDepMap=re;exports.uuidCodec=L;exports.validateSchemaRefs=J;
|