@adhd/apigen-engine-naming 0.2.4 → 0.2.6
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/CHANGELOG.md +4 -0
- package/index.js +2 -2
- package/index.mjs +52 -34
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
package/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require("node:fs");let e=require("node:module");require("node:path"),(0,e.createRequire)(require("node:url").pathToFileURL(__filename).href);var t={id:`date-time`,kind:`scalar`,schema:{type:`string`,format:`date-time`},matches(e){return e.type===`string`&&e.format===`date-time`},ownsValue(e){return e instanceof Date},encode(e,t,n){return e.toISOString()},decode(e,t,n){if(typeof e!=`string`){if(n.mode===`strict`)throw TypeError(`[date-time] expected a string on the wire at "${n.path}", got ${typeof e}`);return new Date(String(e))}if(n.mode===`strict`&&Number.isNaN(new Date(e).getTime()))throw TypeError(`[date-time] invalid date-time string at "${n.path}": ${JSON.stringify(e)}`);return new Date(e)}},n={id:`int64`,kind:`scalar`,schema:{type:`string`,format:`int64`},matches(e){return e.type===`string`&&e.format===`int64`},ownsValue(e){return typeof e==`bigint`},encode(e,t,n){return String(e)},decode(e,t,n){if(typeof e!=`string`){if(n.mode===`strict`)throw TypeError(`[int64] expected a string on the wire at "${n.path}", got ${typeof e}`);try{return BigInt(Math.trunc(Number(e)))}catch{return BigInt(0)}}if(n.mode===`strict`)return BigInt(e);if(/^-?\d+$/.test(e))try{return BigInt(e)}catch{return BigInt(0)}return BigInt(0)}};function r(e){return e}var i={id:`decimal`,kind:`scalar`,schema:{type:`string`,format:`decimal`},matches(e){return e.type===`string`&&e.format===`decimal`},encode(e,t,n){return e},decode(e,t,n){if(typeof e!=`string`){if(n.mode===`strict`)throw TypeError(`[decimal] expected a string on the wire at "${n.path}", got ${typeof e}`);return r(String(e))}if(n.mode===`strict`&&!/^-?\d+(\.\d+)?$/.test(e))throw TypeError(`[decimal] wire value "${e}" at "${n.path}" is not a valid decimal string`);return r(e)}},a={id:`byte`,kind:`scalar`,schema:{type:`string`,format:`byte`},matches(e){return e.type===`string`&&e.format===`byte`},ownsValue(e){return e instanceof Uint8Array},encode(e,t,n){return Buffer.from(e).toString(`base64`)},decode(e,t,n){if(typeof e!=`string`){if(n.mode===`strict`)throw TypeError(`[byte] expected a base64 string on the wire at "${n.path}", got ${typeof e}`);return new Uint8Array}if(n.mode===`strict`&&!/^[A-Za-z0-9+/]*={0,2}$/.test(e))throw TypeError(`[byte] wire value at "${n.path}" is not standard base64 (format:byte): "${e}"`);return new Uint8Array(Buffer.from(e,`base64`))}},o=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/,s={id:`uuid`,kind:`scalar`,schema:{type:`string`,format:`uuid`},matches(e){return e.type===`string`&&e.format===`uuid`},encode(e,t,n){return e.toLowerCase()},decode(e,t,n){if(typeof e!=`string`){if(n.mode===`strict`)throw TypeError(`[uuid] expected a string on the wire at "${n.path}", got ${typeof e}`);return String(e).toLowerCase()}if(n.mode===`strict`&&!o.test(e))throw TypeError(`[uuid] wire value "${e}" at "${n.path}" is not a lowercase-hyphenated RFC 4122 UUID`);return e}},c=`NaN`,l=`Infinity`,u=`-Infinity`,d=new Set([c,l,u]);t.id,n.id,i.id,a.id,s.id,{id:`number-special`,kind:`scalar`,schema:{type:`number`},matches(e){return e.type===`number`&&e.format===void 0},ownsValue(e){return typeof e==`number`&&!Number.isFinite(e)},encode(e,t,n){return Number.isNaN(e)?c:e===1/0?l:e===-1/0?u:e},decode(e,t,n){if(typeof e==`number`)return e;if(typeof e==`string`){if(e===c)return NaN;if(e===l)return 1/0;if(e===u)return-1/0;let t=Number(e);if(!Number.isNaN(t))return t}if(n.mode===`strict`)throw TypeError(`[number-special] unrecognized wire value at "${n.path}": ${JSON.stringify(e)}. Expected a number or one of ${[...d].join(`, `)}.`);return NaN}}.id,Object.freeze({typescript:{"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`}},python:{"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`}},rust:{"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`}},go:{"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`}},java:{"date-time":{encode:`$.toString()`,decode:`Instant.parse($)`,imports:[`import java.time.Instant;`],dep:{name:`jackson-datatype-jsr310`,version:`2.x`},mode:`lib`},int64:{encode:`@JsonFormat(shape = JsonFormat.Shape.STRING)`,decode:`@JsonFormat(shape = JsonFormat.Shape.STRING)`,imports:[`import com.fasterxml.jackson.annotation.JsonFormat;`],mode:`native`},decimal:{encode:`@JsonSerialize(using = ToStringSerializer.class)`,decode:`new BigDecimal($)`,imports:[`import java.math.BigDecimal;`,`import com.fasterxml.jackson.databind.annotation.JsonSerialize;`,`import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;`],mode:`native`},byte:{encode:`$`,decode:`$`,mode:`native`},uuid:{encode:`$.toString()`,decode:`UUID.fromString($)`,imports:[`import java.util.UUID;`],mode:`native`},"number-special":{encode:`@JsonSerialize(using = NumberSpecialSerializer.class)`,decode:`@JsonDeserialize(using = NumberSpecialDeserializer.class)`,imports:[`import com.fasterxml.jackson.databind.annotation.JsonSerialize;`,`import com.fasterxml.jackson.databind.annotation.JsonDeserialize;`],mode:`native`}}});var f=new Set([`string`,`number`,`boolean`,`integer`]);function p(e){if(typeof e!=`object`||!e)return!1;let t=e;if(t.$ref!==void 0||t.oneOf||t.anyOf
|
|
2
|
-
`)}`),this.name=`CollisionDetectedError`,this.collisions=e}};function
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require("node:fs");let e=require("node:module");require("node:path"),(0,e.createRequire)(require("node:url").pathToFileURL(__filename).href);var t={id:`date-time`,kind:`scalar`,schema:{type:`string`,format:`date-time`},matches(e){return e.type===`string`&&e.format===`date-time`},ownsValue(e){return e instanceof Date},encode(e,t,n){return e.toISOString()},decode(e,t,n){if(typeof e!=`string`){if(n.mode===`strict`)throw TypeError(`[date-time] expected a string on the wire at "${n.path}", got ${typeof e}`);return new Date(String(e))}if(n.mode===`strict`&&Number.isNaN(new Date(e).getTime()))throw TypeError(`[date-time] invalid date-time string at "${n.path}": ${JSON.stringify(e)}`);return new Date(e)}},n={id:`int64`,kind:`scalar`,schema:{type:`string`,format:`int64`},matches(e){return e.type===`string`&&e.format===`int64`},ownsValue(e){return typeof e==`bigint`},encode(e,t,n){return String(e)},decode(e,t,n){if(typeof e!=`string`){if(n.mode===`strict`)throw TypeError(`[int64] expected a string on the wire at "${n.path}", got ${typeof e}`);try{return BigInt(Math.trunc(Number(e)))}catch{return BigInt(0)}}if(n.mode===`strict`)return BigInt(e);if(/^-?\d+$/.test(e))try{return BigInt(e)}catch{return BigInt(0)}return BigInt(0)}};function r(e){return e}var i={id:`decimal`,kind:`scalar`,schema:{type:`string`,format:`decimal`},matches(e){return e.type===`string`&&e.format===`decimal`},encode(e,t,n){return e},decode(e,t,n){if(typeof e!=`string`){if(n.mode===`strict`)throw TypeError(`[decimal] expected a string on the wire at "${n.path}", got ${typeof e}`);return r(String(e))}if(n.mode===`strict`&&!/^-?\d+(\.\d+)?$/.test(e))throw TypeError(`[decimal] wire value "${e}" at "${n.path}" is not a valid decimal string`);return r(e)}},a={id:`byte`,kind:`scalar`,schema:{type:`string`,format:`byte`},matches(e){return e.type===`string`&&e.format===`byte`},ownsValue(e){return e instanceof Uint8Array},encode(e,t,n){return Buffer.from(e).toString(`base64`)},decode(e,t,n){if(typeof e!=`string`){if(n.mode===`strict`)throw TypeError(`[byte] expected a base64 string on the wire at "${n.path}", got ${typeof e}`);return new Uint8Array}if(n.mode===`strict`&&!/^[A-Za-z0-9+/]*={0,2}$/.test(e))throw TypeError(`[byte] wire value at "${n.path}" is not standard base64 (format:byte): "${e}"`);return new Uint8Array(Buffer.from(e,`base64`))}},o=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/,s={id:`uuid`,kind:`scalar`,schema:{type:`string`,format:`uuid`},matches(e){return e.type===`string`&&e.format===`uuid`},encode(e,t,n){return e.toLowerCase()},decode(e,t,n){if(typeof e!=`string`){if(n.mode===`strict`)throw TypeError(`[uuid] expected a string on the wire at "${n.path}", got ${typeof e}`);return String(e).toLowerCase()}if(n.mode===`strict`&&!o.test(e))throw TypeError(`[uuid] wire value "${e}" at "${n.path}" is not a lowercase-hyphenated RFC 4122 UUID`);return e}},c=`NaN`,l=`Infinity`,u=`-Infinity`,d=new Set([c,l,u]);t.id,n.id,i.id,a.id,s.id,{id:`number-special`,kind:`scalar`,schema:{type:`number`},matches(e){return e.type===`number`&&e.format===void 0},ownsValue(e){return typeof e==`number`&&!Number.isFinite(e)},encode(e,t,n){return Number.isNaN(e)?c:e===1/0?l:e===-1/0?u:e},decode(e,t,n){if(typeof e==`number`)return e;if(typeof e==`string`){if(e===c)return NaN;if(e===l)return 1/0;if(e===u)return-1/0;let t=Number(e);if(!Number.isNaN(t))return t}if(n.mode===`strict`)throw TypeError(`[number-special] unrecognized wire value at "${n.path}": ${JSON.stringify(e)}. Expected a number or one of ${[...d].join(`, `)}.`);return NaN}}.id,Object.freeze({typescript:{"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`}},python:{"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`}},rust:{"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`}},go:{"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`}},java:{"date-time":{encode:`$.toString()`,decode:`Instant.parse($)`,imports:[`import java.time.Instant;`],dep:{name:`jackson-datatype-jsr310`,version:`2.x`},mode:`lib`},int64:{encode:`@JsonFormat(shape = JsonFormat.Shape.STRING)`,decode:`@JsonFormat(shape = JsonFormat.Shape.STRING)`,imports:[`import com.fasterxml.jackson.annotation.JsonFormat;`],mode:`native`},decimal:{encode:`@JsonSerialize(using = ToStringSerializer.class)`,decode:`new BigDecimal($)`,imports:[`import java.math.BigDecimal;`,`import com.fasterxml.jackson.databind.annotation.JsonSerialize;`,`import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;`],mode:`native`},byte:{encode:`$`,decode:`$`,mode:`native`},uuid:{encode:`$.toString()`,decode:`UUID.fromString($)`,imports:[`import java.util.UUID;`],mode:`native`},"number-special":{encode:`@JsonSerialize(using = NumberSpecialSerializer.class)`,decode:`@JsonDeserialize(using = NumberSpecialDeserializer.class)`,imports:[`import com.fasterxml.jackson.databind.annotation.JsonSerialize;`,`import com.fasterxml.jackson.databind.annotation.JsonDeserialize;`],mode:`native`}}});var f=new Set([`string`,`number`,`boolean`,`integer`]);function p(e){if(!Array.isArray(e)||e.length<2)return!1;let t=0;for(let n of e){if(typeof n!=`object`||!n)return!1;let{type:e,$ref:r,oneOf:i,anyOf:a,allOf:o}=n;if(r!==void 0||i||a||o)return!1;if(e!==`null`){if(typeof e==`string`&&f.has(e)){t++;continue}return!1}}return t===1}function m(e){if(typeof e!=`object`||!e)return!1;let t=e;if(t.$ref!==void 0||t.allOf)return!1;if(t.oneOf||t.anyOf)return p(t.oneOf??t.anyOf);let{type:n}=t;return typeof n==`string`?f.has(n):Array.isArray(n)?n.every(e=>f.has(e)||e===`null`):Array.isArray(t.enum)&&t.enum.length>0?t.enum.every(e=>[`string`,`number`,`boolean`].includes(typeof e)):!1}function h(e){if(!e||typeof e!=`object`)return!1;let t=e.properties;return t===void 0||typeof t!=`object`||!t?!1:Object.values(t).every(m)}var g={"decimal.js":`Decimal`};function _(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}Object.entries(g).map(([e,t])=>({pattern:RegExp(`import\\(["'][^"']*${_(e)}[^"']*["']\\)\\.\\w+`,`g`),key:t}));function v(e){return e.words.join(`-`)}function y(e){return e.words.map((e,t)=>t===0?e:N(e)).join(``)}function b(e){return e.words.map(N).join(``)}function x(e){return e.words.join(`_`)}function S(e){return e.replace(/\.[^.]+$/,``).replace(/[._]+/g,`-`)}function C(e,t={}){let n=[e.namespace,...e.path],r=e.safe||h(e.input)?`GET`:`POST`,i=t.http?.verb?.[e.id]??r,a=`/`+n.map(e=>v(e)).join(`/`),o=n.map(e=>x(e)).join(`_`),s=n.map(e=>x(e)).slice(0,-1).join(`.`),c=b(n[n.length-2]??n[0]),l=b(n[n.length-1]),u=n.map(e=>v(e));return{http:{verb:i,route:a},mcp:{name:o},grpc:{package:s,service:c,method:l},cli:{path:u}}}function w(e,t,n){let r=n.http?.verb?.[e];return r===`GET`||r===`POST`?r:t[`x-apigen-safe`]?`GET`:`POST`}var T=class extends Error{constructor(e){let t=e.map(e=>` [${e.transport}] "${e.target}" ← ${e.ids[0]} vs ${e.ids[1]}`);super(`apigen-naming: ${e.length} projection collision(s) detected:\n${t.join(`
|
|
2
|
+
`)}`),this.name=`CollisionDetectedError`,this.collisions=e}};function E(e,t={}){let n=new Map,r=new Map,i=new Map,a=new Map,o=[];for(let s of e){let e=C(s,t),c=`${e.http.verb} ${e.http.route}`,l=n.get(c);l!==void 0&&l!==s.id?o.push({transport:`http`,target:c,ids:[l,s.id]}):n.set(c,s.id);let u=r.get(e.mcp.name);u!==void 0&&u!==s.id?o.push({transport:`mcp`,target:e.mcp.name,ids:[u,s.id]}):r.set(e.mcp.name,s.id);let d=`${e.grpc.package}.${e.grpc.service}/${e.grpc.method}`,f=i.get(d);f!==void 0&&f!==s.id?o.push({transport:`grpc`,target:d,ids:[f,s.id]}):i.set(d,s.id);let p=e.cli.path.join(` `),m=a.get(p);m!==void 0&&m!==s.id?o.push({transport:`cli`,target:p,ids:[m,s.id]}):a.set(p,s.id)}if(o.length>0)throw new T(o)}function D(e,t){return`x-${e}-${t}`}function O(e,t){return`--${e}-${t}`}function k(e,t){let n=e=>e.toUpperCase().replace(/-/g,`_`);return e===`adhd`?`APIGEN_${n(t)}`:`APIGEN_${n(e)}_${n(t)}`}var A=D;function j(e){let t=e.replace(/[^a-zA-Z0-9_$]/g,`_`);return(t===``||/^[0-9]/.test(t))&&(t=`_${t}`),t}function M(e){let t=new Set,n=[];for(let r of e){let e=j(r),i=e,a=2;for(;t.has(i);)i=`${e}_${a}`,a+=1;t.add(i),n.push(i)}return n}function N(e){return e.length===0?e:e[0].toUpperCase()+e.slice(1)}function P(e){return e.replace(/\u2028/g,`\\u2028`).replace(/\u2029/g,`\\u2029`)}function F(e){return P(JSON.stringify(e))}function I(e,t=3e3){if(e==null)return t;if(typeof e!=`string`&&typeof e!=`number`||typeof e==`string`&&e.trim()===``)throw TypeError(`apigen: invalid port option ${JSON.stringify(e)} — expected an integer in [0, 65535]`);let n=Number(e);if(!Number.isInteger(n)||n<0||n>65535)throw TypeError(`apigen: invalid port option ${JSON.stringify(e)} — expected an integer in [0, 65535]`);return n}function L(e){return e.replace(/\\/g,`/`)}exports.CollisionDetectedError=T,exports.checkCollisions=E,exports.coercePort=I,exports.envelopeCliFlag=O,exports.envelopeEnvVar=k,exports.envelopeKey=D,exports.envelopeMetaKey=A,exports.escapeLineTerminators=P,exports.escapeStringLiteral=F,exports.httpVerb=w,exports.normalizeFileName=S,exports.project=C,exports.sanitizeIdentifier=j,exports.toCamel=y,exports.toKebab=v,exports.toPascal=b,exports.toPosixPath=L,exports.toSnake=x,exports.uniqueSanitizedIdentifiers=M;
|
package/index.mjs
CHANGED
|
@@ -394,9 +394,27 @@ var f = /* @__PURE__ */ new Set([
|
|
|
394
394
|
"integer"
|
|
395
395
|
]);
|
|
396
396
|
function p(e) {
|
|
397
|
+
if (!Array.isArray(e) || e.length < 2) return !1;
|
|
398
|
+
let t = 0;
|
|
399
|
+
for (let n of e) {
|
|
400
|
+
if (typeof n != "object" || !n) return !1;
|
|
401
|
+
let { type: e, $ref: r, oneOf: i, anyOf: a, allOf: o } = n;
|
|
402
|
+
if (r !== void 0 || i || a || o) return !1;
|
|
403
|
+
if (e !== "null") {
|
|
404
|
+
if (typeof e == "string" && f.has(e)) {
|
|
405
|
+
t++;
|
|
406
|
+
continue;
|
|
407
|
+
}
|
|
408
|
+
return !1;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
return t === 1;
|
|
412
|
+
}
|
|
413
|
+
function m(e) {
|
|
397
414
|
if (typeof e != "object" || !e) return !1;
|
|
398
415
|
let t = e;
|
|
399
|
-
if (t.$ref !== void 0 || t.
|
|
416
|
+
if (t.$ref !== void 0 || t.allOf) return !1;
|
|
417
|
+
if (t.oneOf || t.anyOf) return p(t.oneOf ?? t.anyOf);
|
|
400
418
|
let { type: n } = t;
|
|
401
419
|
return typeof n == "string" ? f.has(n) : Array.isArray(n) ? n.every((e) => f.has(e) || e === "null") : Array.isArray(t.enum) && t.enum.length > 0 ? t.enum.every((e) => [
|
|
402
420
|
"string",
|
|
@@ -404,40 +422,40 @@ function p(e) {
|
|
|
404
422
|
"boolean"
|
|
405
423
|
].includes(typeof e)) : !1;
|
|
406
424
|
}
|
|
407
|
-
function
|
|
425
|
+
function h(e) {
|
|
408
426
|
if (!e || typeof e != "object") return !1;
|
|
409
427
|
let t = e.properties;
|
|
410
|
-
return t === void 0 || typeof t != "object" || !t ? !1 : Object.values(t).every(
|
|
428
|
+
return t === void 0 || typeof t != "object" || !t ? !1 : Object.values(t).every(m);
|
|
411
429
|
}
|
|
412
430
|
//#endregion
|
|
413
431
|
//#region ../apigen-core-client/src/lib/schema-builders/ts-json-schema.ts
|
|
414
|
-
var
|
|
415
|
-
function
|
|
432
|
+
var g = { "decimal.js": "Decimal" };
|
|
433
|
+
function _(e) {
|
|
416
434
|
return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
417
435
|
}
|
|
418
|
-
Object.entries(
|
|
419
|
-
pattern: RegExp(`import\\(["'][^"']*${
|
|
436
|
+
Object.entries(g).map(([e, t]) => ({
|
|
437
|
+
pattern: RegExp(`import\\(["'][^"']*${_(e)}[^"']*["']\\)\\.\\w+`, "g"),
|
|
420
438
|
key: t
|
|
421
439
|
}));
|
|
422
440
|
//#endregion
|
|
423
441
|
//#region src/lib/naming.ts
|
|
424
|
-
function _(e) {
|
|
425
|
-
return e.words.join("-");
|
|
426
|
-
}
|
|
427
442
|
function v(e) {
|
|
428
|
-
return e.words.
|
|
443
|
+
return e.words.join("-");
|
|
429
444
|
}
|
|
430
445
|
function y(e) {
|
|
431
|
-
return e.words.map(
|
|
446
|
+
return e.words.map((e, t) => t === 0 ? e : N(e)).join("");
|
|
432
447
|
}
|
|
433
448
|
function b(e) {
|
|
434
|
-
return e.words.join("
|
|
449
|
+
return e.words.map(N).join("");
|
|
435
450
|
}
|
|
436
451
|
function x(e) {
|
|
452
|
+
return e.words.join("_");
|
|
453
|
+
}
|
|
454
|
+
function S(e) {
|
|
437
455
|
return e.replace(/\.[^.]+$/, "").replace(/[._]+/g, "-");
|
|
438
456
|
}
|
|
439
|
-
function
|
|
440
|
-
let n = [e.namespace, ...e.path], r = e.safe ||
|
|
457
|
+
function C(e, t = {}) {
|
|
458
|
+
let n = [e.namespace, ...e.path], r = e.safe || h(e.input) ? "GET" : "POST", i = t.http?.verb?.[e.id] ?? r, a = "/" + n.map((e) => v(e)).join("/"), o = n.map((e) => x(e)).join("_"), s = n.map((e) => x(e)).slice(0, -1).join("."), c = b(n[n.length - 2] ?? n[0]), l = b(n[n.length - 1]), u = n.map((e) => v(e));
|
|
441
459
|
return {
|
|
442
460
|
http: {
|
|
443
461
|
verb: i,
|
|
@@ -452,20 +470,20 @@ function S(e, t = {}) {
|
|
|
452
470
|
cli: { path: u }
|
|
453
471
|
};
|
|
454
472
|
}
|
|
455
|
-
function
|
|
473
|
+
function w(e, t, n) {
|
|
456
474
|
let r = n.http?.verb?.[e];
|
|
457
475
|
return r === "GET" || r === "POST" ? r : t["x-apigen-safe"] ? "GET" : "POST";
|
|
458
476
|
}
|
|
459
|
-
var
|
|
477
|
+
var T = class extends Error {
|
|
460
478
|
constructor(e) {
|
|
461
479
|
let t = e.map((e) => ` [${e.transport}] "${e.target}" ← ${e.ids[0]} vs ${e.ids[1]}`);
|
|
462
480
|
super(`apigen-naming: ${e.length} projection collision(s) detected:\n${t.join("\n")}`), this.name = "CollisionDetectedError", this.collisions = e;
|
|
463
481
|
}
|
|
464
482
|
};
|
|
465
|
-
function
|
|
483
|
+
function E(e, t = {}) {
|
|
466
484
|
let n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), o = [];
|
|
467
485
|
for (let s of e) {
|
|
468
|
-
let e =
|
|
486
|
+
let e = C(s, t), c = `${e.http.verb} ${e.http.route}`, l = n.get(c);
|
|
469
487
|
l !== void 0 && l !== s.id ? o.push({
|
|
470
488
|
transport: "http",
|
|
471
489
|
target: c,
|
|
@@ -490,52 +508,52 @@ function T(e, t = {}) {
|
|
|
490
508
|
ids: [m, s.id]
|
|
491
509
|
}) : a.set(p, s.id);
|
|
492
510
|
}
|
|
493
|
-
if (o.length > 0) throw new
|
|
511
|
+
if (o.length > 0) throw new T(o);
|
|
494
512
|
}
|
|
495
|
-
function
|
|
513
|
+
function D(e, t) {
|
|
496
514
|
return `x-${e}-${t}`;
|
|
497
515
|
}
|
|
498
|
-
function
|
|
516
|
+
function O(e, t) {
|
|
499
517
|
return `--${e}-${t}`;
|
|
500
518
|
}
|
|
501
|
-
function
|
|
519
|
+
function k(e, t) {
|
|
502
520
|
let n = (e) => e.toUpperCase().replace(/-/g, "_");
|
|
503
521
|
return e === "adhd" ? `APIGEN_${n(t)}` : `APIGEN_${n(e)}_${n(t)}`;
|
|
504
522
|
}
|
|
505
|
-
var
|
|
506
|
-
function
|
|
523
|
+
var A = D;
|
|
524
|
+
function j(e) {
|
|
507
525
|
let t = e.replace(/[^a-zA-Z0-9_$]/g, "_");
|
|
508
526
|
return (t === "" || /^[0-9]/.test(t)) && (t = `_${t}`), t;
|
|
509
527
|
}
|
|
510
|
-
function
|
|
528
|
+
function M(e) {
|
|
511
529
|
let t = /* @__PURE__ */ new Set(), n = [];
|
|
512
530
|
for (let r of e) {
|
|
513
|
-
let e =
|
|
531
|
+
let e = j(r), i = e, a = 2;
|
|
514
532
|
for (; t.has(i);) i = `${e}_${a}`, a += 1;
|
|
515
533
|
t.add(i), n.push(i);
|
|
516
534
|
}
|
|
517
535
|
return n;
|
|
518
536
|
}
|
|
519
|
-
function
|
|
537
|
+
function N(e) {
|
|
520
538
|
return e.length === 0 ? e : e[0].toUpperCase() + e.slice(1);
|
|
521
539
|
}
|
|
522
540
|
//#endregion
|
|
523
541
|
//#region src/lib/emit.ts
|
|
524
|
-
function
|
|
542
|
+
function P(e) {
|
|
525
543
|
return e.replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
|
|
526
544
|
}
|
|
527
|
-
function
|
|
528
|
-
return
|
|
545
|
+
function F(e) {
|
|
546
|
+
return P(JSON.stringify(e));
|
|
529
547
|
}
|
|
530
|
-
function
|
|
548
|
+
function I(e, t = 3e3) {
|
|
531
549
|
if (e == null) return t;
|
|
532
550
|
if (typeof e != "string" && typeof e != "number" || typeof e == "string" && e.trim() === "") throw TypeError(`apigen: invalid port option ${JSON.stringify(e)} — expected an integer in [0, 65535]`);
|
|
533
551
|
let n = Number(e);
|
|
534
552
|
if (!Number.isInteger(n) || n < 0 || n > 65535) throw TypeError(`apigen: invalid port option ${JSON.stringify(e)} — expected an integer in [0, 65535]`);
|
|
535
553
|
return n;
|
|
536
554
|
}
|
|
537
|
-
function
|
|
555
|
+
function L(e) {
|
|
538
556
|
return e.replace(/\\/g, "/");
|
|
539
557
|
}
|
|
540
558
|
//#endregion
|
|
541
|
-
export {
|
|
559
|
+
export { T as CollisionDetectedError, E as checkCollisions, I as coercePort, O as envelopeCliFlag, k as envelopeEnvVar, D as envelopeKey, A as envelopeMetaKey, P as escapeLineTerminators, F as escapeStringLiteral, w as httpVerb, S as normalizeFileName, C as project, j as sanitizeIdentifier, y as toCamel, v as toKebab, b as toPascal, L as toPosixPath, x as toSnake, M as uniqueSanitizedIdentifiers };
|
package/package.json
CHANGED