@adhd/apigen-engine-naming 0.2.5 → 0.2.7
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 +14 -0
- package/index.d.ts +1 -1
- package/index.js +13 -2
- package/index.mjs +108 -56
- package/lib/emit.d.ts +15 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## 0.2.7 (2026-10-21)
|
|
2
|
+
|
|
3
|
+
### 🩹 Fixes
|
|
4
|
+
|
|
5
|
+
- **apigen-plugin-mcp:** route generateIndex literals through the shared engine-naming escapers ([933992e0](https://github.com/PseudoSky/adhd/commit/933992e0))
|
|
6
|
+
|
|
7
|
+
### ❤️ Thank You
|
|
8
|
+
|
|
9
|
+
- pseudosky
|
|
10
|
+
|
|
11
|
+
## 0.2.6 (2026-10-15)
|
|
12
|
+
|
|
13
|
+
This was a version bump only for apigen-engine-naming to align it with other projects, there were no code changes.
|
|
14
|
+
|
|
1
15
|
## 0.2.4 (2026-09-26)
|
|
2
16
|
|
|
3
17
|
### 🚀 Features
|
package/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { toKebab, toCamel, toPascal, toSnake, normalizeFileName, project, httpVerb, checkCollisions, CollisionDetectedError, envelopeKey, envelopeCliFlag, envelopeEnvVar, envelopeMetaKey, sanitizeIdentifier, uniqueSanitizedIdentifiers, } from './lib/naming';
|
|
2
|
-
export { escapeLineTerminators, escapeStringLiteral, toPosixPath, coercePort, } from './lib/emit';
|
|
2
|
+
export { escapeLineTerminators, escapeStringLiteral, escapeSingleQuotedLiteral, toPosixPath, coercePort, } from './lib/emit';
|
|
3
3
|
export type { TransportProjection, HttpVerb, ProjectionConfig, CollisionError, } from './lib/naming';
|
package/index.js
CHANGED
|
@@ -1,2 +1,13 @@
|
|
|
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
|
|
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=`$apigen`;`
|
|
2
|
+
function __apigenEnvelopeEncode(v) {
|
|
3
|
+
// Schema-less position: pass typed JSON through unchanged. A richer host
|
|
4
|
+
// prelude may wrap recognized runtime types as { ${JSON.stringify(t)}: id, v }.
|
|
5
|
+
return v;
|
|
6
|
+
}
|
|
7
|
+
function __apigenEnvelopeDecode(w) {
|
|
8
|
+
return w != null && typeof w === 'object' && ${JSON.stringify(t)} in w
|
|
9
|
+
? w.v
|
|
10
|
+
: w;
|
|
11
|
+
}
|
|
12
|
+
`.trim(),Object.freeze({"date-time":{encode:`$.toISOString()`,decode:`new Date($)`,mode:`native`},int64:{encode:`String($)`,decode:`BigInt($)`,mode:`native`},byte:{encode:`Buffer.from($).toString('base64')`,decode:`new Uint8Array(Buffer.from($, 'base64'))`,mode:`native`}});var n={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)}},r={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 i(e){return e}var a={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 i(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 i(e)}},o={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`))}},s=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/,c={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`&&!s.test(e))throw TypeError(`[uuid] wire value "${e}" at "${n.path}" is not a lowercase-hyphenated RFC 4122 UUID`);return e}},l=`NaN`,u=`Infinity`,d=`-Infinity`,f=new Set([l,u,d]);n.id,r.id,a.id,o.id,c.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)?l:e===1/0?u:e===-1/0?d:e},decode(e,t,n){if(typeof e==`number`)return e;if(typeof e==`string`){if(e===l)return NaN;if(e===u)return 1/0;if(e===d)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 ${[...f].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 p=new Set([`string`,`number`,`boolean`,`integer`]);function m(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`&&p.has(e)){t++;continue}return!1}}return t===1}function h(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 m(t.oneOf??t.anyOf);let{type:n}=t;return typeof n==`string`?p.has(n):Array.isArray(n)?n.every(e=>p.has(e)||e===`null`):Array.isArray(t.enum)&&t.enum.length>0?t.enum.every(e=>[`string`,`number`,`boolean`].includes(typeof e)):!1}function g(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(h)}var _={"decimal.js":`Decimal`};function v(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}Object.entries(_).map(([e,t])=>({pattern:RegExp(`import\\(["'][^"']*${v(e)}[^"']*["']\\)\\.\\w+`,`g`),key:t}));function y(e){return e.words.join(`-`)}function b(e){return e.words.map((e,t)=>t===0?e:P(e)).join(``)}function x(e){return e.words.map(P).join(``)}function S(e){return e.words.join(`_`)}function C(e){return e.replace(/\.[^.]+$/,``).replace(/[._]+/g,`-`)}function w(e,t={}){let n=[e.namespace,...e.path],r=e.safe||g(e.input)?`GET`:`POST`,i=t.http?.verb?.[e.id]??r,a=`/`+n.map(e=>y(e)).join(`/`),o=n.map(e=>S(e)).join(`_`),s=n.map(e=>S(e)).slice(0,-1).join(`.`),c=x(n[n.length-2]??n[0]),l=x(n[n.length-1]),u=n.map(e=>y(e));return{http:{verb:i,route:a},mcp:{name:o},grpc:{package:s,service:c,method:l},cli:{path:u}}}function T(e,t,n){let r=n.http?.verb?.[e];return r===`GET`||r===`POST`?r:t[`x-apigen-safe`]?`GET`:`POST`}var E=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(`
|
|
13
|
+
`)}`),this.name=`CollisionDetectedError`,this.collisions=e}};function D(e,t={}){let n=new Map,r=new Map,i=new Map,a=new Map,o=[];for(let s of e){let e=w(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 E(o)}function O(e,t){return`x-${e}-${t}`}function k(e,t){return`--${e}-${t}`}function A(e,t){let n=e=>e.toUpperCase().replace(/-/g,`_`);return e===`adhd`?`APIGEN_${n(t)}`:`APIGEN_${n(e)}_${n(t)}`}var j=O;function M(e){let t=e.replace(/[^a-zA-Z0-9_$]/g,`_`);return(t===``||/^[0-9]/.test(t))&&(t=`_${t}`),t}function N(e){let t=new Set,n=[];for(let r of e){let e=M(r),i=e,a=2;for(;t.has(i);)i=`${e}_${a}`,a+=1;t.add(i),n.push(i)}return n}function P(e){return e.length===0?e:e[0].toUpperCase()+e.slice(1)}function F(e){return e.replace(/\u2028/g,`\\u2028`).replace(/\u2029/g,`\\u2029`)}function I(e){return F(JSON.stringify(e))}function L(e){return`'${F(e.replace(/\\/g,`\\\\`).replace(/'/g,`\\'`).replace(/\n/g,`\\n`).replace(/\r/g,`\\r`))}'`}function R(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 z(e){return e.replace(/\\/g,`/`)}exports.CollisionDetectedError=E,exports.checkCollisions=D,exports.coercePort=R,exports.envelopeCliFlag=k,exports.envelopeEnvVar=A,exports.envelopeKey=O,exports.envelopeMetaKey=j,exports.escapeLineTerminators=F,exports.escapeSingleQuotedLiteral=L,exports.escapeStringLiteral=I,exports.httpVerb=T,exports.normalizeFileName=C,exports.project=w,exports.sanitizeIdentifier=M,exports.toCamel=b,exports.toKebab=y,exports.toPascal=x,exports.toPosixPath=z,exports.toSnake=S,exports.uniqueSanitizedIdentifiers=N;
|
package/index.mjs
CHANGED
|
@@ -3,8 +3,39 @@ import { createRequire as e } from "node:module";
|
|
|
3
3
|
import "node:path";
|
|
4
4
|
e(import.meta.url);
|
|
5
5
|
//#endregion
|
|
6
|
+
//#region ../apigen-base-logical/src/lib/contracts.ts
|
|
7
|
+
var t = "$apigen";
|
|
8
|
+
`
|
|
9
|
+
function __apigenEnvelopeEncode(v) {
|
|
10
|
+
// Schema-less position: pass typed JSON through unchanged. A richer host
|
|
11
|
+
// prelude may wrap recognized runtime types as { ${JSON.stringify(t)}: id, v }.
|
|
12
|
+
return v;
|
|
13
|
+
}
|
|
14
|
+
function __apigenEnvelopeDecode(w) {
|
|
15
|
+
return w != null && typeof w === 'object' && ${JSON.stringify(t)} in w
|
|
16
|
+
? w.v
|
|
17
|
+
: w;
|
|
18
|
+
}
|
|
19
|
+
`.trim(), Object.freeze({
|
|
20
|
+
"date-time": {
|
|
21
|
+
encode: "$.toISOString()",
|
|
22
|
+
decode: "new Date($)",
|
|
23
|
+
mode: "native"
|
|
24
|
+
},
|
|
25
|
+
int64: {
|
|
26
|
+
encode: "String($)",
|
|
27
|
+
decode: "BigInt($)",
|
|
28
|
+
mode: "native"
|
|
29
|
+
},
|
|
30
|
+
byte: {
|
|
31
|
+
encode: "Buffer.from($).toString('base64')",
|
|
32
|
+
decode: "new Uint8Array(Buffer.from($, 'base64'))",
|
|
33
|
+
mode: "native"
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
//#endregion
|
|
6
37
|
//#region ../apigen-base-logical/src/lib/codecs/date-time.ts
|
|
7
|
-
var
|
|
38
|
+
var n = {
|
|
8
39
|
id: "date-time",
|
|
9
40
|
kind: "scalar",
|
|
10
41
|
schema: {
|
|
@@ -28,7 +59,7 @@ var t = {
|
|
|
28
59
|
if (n.mode === "strict" && Number.isNaN(new Date(e).getTime())) throw TypeError(`[date-time] invalid date-time string at "${n.path}": ${JSON.stringify(e)}`);
|
|
29
60
|
return new Date(e);
|
|
30
61
|
}
|
|
31
|
-
},
|
|
62
|
+
}, r = {
|
|
32
63
|
id: "int64",
|
|
33
64
|
kind: "scalar",
|
|
34
65
|
schema: {
|
|
@@ -64,10 +95,10 @@ var t = {
|
|
|
64
95
|
};
|
|
65
96
|
//#endregion
|
|
66
97
|
//#region ../apigen-base-logical/src/lib/codecs/decimal.ts
|
|
67
|
-
function
|
|
98
|
+
function i(e) {
|
|
68
99
|
return e;
|
|
69
100
|
}
|
|
70
|
-
var
|
|
101
|
+
var a = {
|
|
71
102
|
id: "decimal",
|
|
72
103
|
kind: "scalar",
|
|
73
104
|
schema: {
|
|
@@ -83,12 +114,12 @@ var i = {
|
|
|
83
114
|
decode(e, t, n) {
|
|
84
115
|
if (typeof e != "string") {
|
|
85
116
|
if (n.mode === "strict") throw TypeError(`[decimal] expected a string on the wire at "${n.path}", got ${typeof e}`);
|
|
86
|
-
return
|
|
117
|
+
return i(String(e));
|
|
87
118
|
}
|
|
88
119
|
if (n.mode === "strict" && !/^-?\d+(\.\d+)?$/.test(e)) throw TypeError(`[decimal] wire value "${e}" at "${n.path}" is not a valid decimal string`);
|
|
89
|
-
return
|
|
120
|
+
return i(e);
|
|
90
121
|
}
|
|
91
|
-
},
|
|
122
|
+
}, o = {
|
|
92
123
|
id: "byte",
|
|
93
124
|
kind: "scalar",
|
|
94
125
|
schema: {
|
|
@@ -112,7 +143,7 @@ var i = {
|
|
|
112
143
|
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}"`);
|
|
113
144
|
return new Uint8Array(Buffer.from(e, "base64"));
|
|
114
145
|
}
|
|
115
|
-
},
|
|
146
|
+
}, s = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/, c = {
|
|
116
147
|
id: "uuid",
|
|
117
148
|
kind: "scalar",
|
|
118
149
|
schema: {
|
|
@@ -130,15 +161,15 @@ var i = {
|
|
|
130
161
|
if (n.mode === "strict") throw TypeError(`[uuid] expected a string on the wire at "${n.path}", got ${typeof e}`);
|
|
131
162
|
return String(e).toLowerCase();
|
|
132
163
|
}
|
|
133
|
-
if (n.mode === "strict" && !
|
|
164
|
+
if (n.mode === "strict" && !s.test(e)) throw TypeError(`[uuid] wire value "${e}" at "${n.path}" is not a lowercase-hyphenated RFC 4122 UUID`);
|
|
134
165
|
return e;
|
|
135
166
|
}
|
|
136
|
-
},
|
|
137
|
-
c,
|
|
167
|
+
}, l = "NaN", u = "Infinity", d = "-Infinity", f = /* @__PURE__ */ new Set([
|
|
138
168
|
l,
|
|
139
|
-
u
|
|
169
|
+
u,
|
|
170
|
+
d
|
|
140
171
|
]);
|
|
141
|
-
|
|
172
|
+
n.id, r.id, a.id, o.id, c.id, {
|
|
142
173
|
id: "number-special",
|
|
143
174
|
kind: "scalar",
|
|
144
175
|
schema: { type: "number" },
|
|
@@ -149,18 +180,18 @@ t.id, n.id, i.id, a.id, s.id, {
|
|
|
149
180
|
return typeof e == "number" && !Number.isFinite(e);
|
|
150
181
|
},
|
|
151
182
|
encode(e, t, n) {
|
|
152
|
-
return Number.isNaN(e) ?
|
|
183
|
+
return Number.isNaN(e) ? l : e === Infinity ? u : e === -Infinity ? d : e;
|
|
153
184
|
},
|
|
154
185
|
decode(e, t, n) {
|
|
155
186
|
if (typeof e == "number") return e;
|
|
156
187
|
if (typeof e == "string") {
|
|
157
|
-
if (e ===
|
|
158
|
-
if (e ===
|
|
159
|
-
if (e ===
|
|
188
|
+
if (e === l) return NaN;
|
|
189
|
+
if (e === u) return Infinity;
|
|
190
|
+
if (e === d) return -Infinity;
|
|
160
191
|
let t = Number(e);
|
|
161
192
|
if (!Number.isNaN(t)) return t;
|
|
162
193
|
}
|
|
163
|
-
if (n.mode === "strict") throw TypeError(`[number-special] unrecognized wire value at "${n.path}": ${JSON.stringify(e)}. Expected a number or one of ${[...
|
|
194
|
+
if (n.mode === "strict") throw TypeError(`[number-special] unrecognized wire value at "${n.path}": ${JSON.stringify(e)}. Expected a number or one of ${[...f].join(", ")}.`);
|
|
164
195
|
return NaN;
|
|
165
196
|
}
|
|
166
197
|
}.id, Object.freeze({
|
|
@@ -387,57 +418,75 @@ t.id, n.id, i.id, a.id, s.id, {
|
|
|
387
418
|
});
|
|
388
419
|
//#endregion
|
|
389
420
|
//#region ../apigen-core-client/src/lib/get-safety.ts
|
|
390
|
-
var
|
|
421
|
+
var p = /* @__PURE__ */ new Set([
|
|
391
422
|
"string",
|
|
392
423
|
"number",
|
|
393
424
|
"boolean",
|
|
394
425
|
"integer"
|
|
395
426
|
]);
|
|
396
|
-
function
|
|
427
|
+
function m(e) {
|
|
428
|
+
if (!Array.isArray(e) || e.length < 2) return !1;
|
|
429
|
+
let t = 0;
|
|
430
|
+
for (let n of e) {
|
|
431
|
+
if (typeof n != "object" || !n) return !1;
|
|
432
|
+
let { type: e, $ref: r, oneOf: i, anyOf: a, allOf: o } = n;
|
|
433
|
+
if (r !== void 0 || i || a || o) return !1;
|
|
434
|
+
if (e !== "null") {
|
|
435
|
+
if (typeof e == "string" && p.has(e)) {
|
|
436
|
+
t++;
|
|
437
|
+
continue;
|
|
438
|
+
}
|
|
439
|
+
return !1;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
return t === 1;
|
|
443
|
+
}
|
|
444
|
+
function h(e) {
|
|
397
445
|
if (typeof e != "object" || !e) return !1;
|
|
398
446
|
let t = e;
|
|
399
|
-
if (t.$ref !== void 0 || t.
|
|
447
|
+
if (t.$ref !== void 0 || t.allOf) return !1;
|
|
448
|
+
if (t.oneOf || t.anyOf) return m(t.oneOf ?? t.anyOf);
|
|
400
449
|
let { type: n } = t;
|
|
401
|
-
return typeof n == "string" ?
|
|
450
|
+
return typeof n == "string" ? p.has(n) : Array.isArray(n) ? n.every((e) => p.has(e) || e === "null") : Array.isArray(t.enum) && t.enum.length > 0 ? t.enum.every((e) => [
|
|
402
451
|
"string",
|
|
403
452
|
"number",
|
|
404
453
|
"boolean"
|
|
405
454
|
].includes(typeof e)) : !1;
|
|
406
455
|
}
|
|
407
|
-
function
|
|
456
|
+
function g(e) {
|
|
408
457
|
if (!e || typeof e != "object") return !1;
|
|
409
458
|
let t = e.properties;
|
|
410
|
-
return t === void 0 || typeof t != "object" || !t ? !1 : Object.values(t).every(
|
|
459
|
+
return t === void 0 || typeof t != "object" || !t ? !1 : Object.values(t).every(h);
|
|
411
460
|
}
|
|
412
461
|
//#endregion
|
|
413
462
|
//#region ../apigen-core-client/src/lib/schema-builders/ts-json-schema.ts
|
|
414
|
-
var
|
|
415
|
-
function
|
|
463
|
+
var _ = { "decimal.js": "Decimal" };
|
|
464
|
+
function v(e) {
|
|
416
465
|
return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
417
466
|
}
|
|
418
|
-
Object.entries(
|
|
419
|
-
pattern: RegExp(`import\\(["'][^"']*${
|
|
467
|
+
Object.entries(_).map(([e, t]) => ({
|
|
468
|
+
pattern: RegExp(`import\\(["'][^"']*${v(e)}[^"']*["']\\)\\.\\w+`, "g"),
|
|
420
469
|
key: t
|
|
421
470
|
}));
|
|
422
471
|
//#endregion
|
|
423
472
|
//#region src/lib/naming.ts
|
|
424
|
-
function
|
|
473
|
+
function y(e) {
|
|
425
474
|
return e.words.join("-");
|
|
426
475
|
}
|
|
427
|
-
function
|
|
428
|
-
return e.words.map((e, t) => t === 0 ? e :
|
|
476
|
+
function b(e) {
|
|
477
|
+
return e.words.map((e, t) => t === 0 ? e : P(e)).join("");
|
|
429
478
|
}
|
|
430
|
-
function
|
|
431
|
-
return e.words.map(
|
|
479
|
+
function x(e) {
|
|
480
|
+
return e.words.map(P).join("");
|
|
432
481
|
}
|
|
433
|
-
function
|
|
482
|
+
function S(e) {
|
|
434
483
|
return e.words.join("_");
|
|
435
484
|
}
|
|
436
|
-
function
|
|
485
|
+
function C(e) {
|
|
437
486
|
return e.replace(/\.[^.]+$/, "").replace(/[._]+/g, "-");
|
|
438
487
|
}
|
|
439
|
-
function
|
|
440
|
-
let n = [e.namespace, ...e.path], r = e.safe ||
|
|
488
|
+
function w(e, t = {}) {
|
|
489
|
+
let n = [e.namespace, ...e.path], r = e.safe || g(e.input) ? "GET" : "POST", i = t.http?.verb?.[e.id] ?? r, a = "/" + n.map((e) => y(e)).join("/"), o = n.map((e) => S(e)).join("_"), s = n.map((e) => S(e)).slice(0, -1).join("."), c = x(n[n.length - 2] ?? n[0]), l = x(n[n.length - 1]), u = n.map((e) => y(e));
|
|
441
490
|
return {
|
|
442
491
|
http: {
|
|
443
492
|
verb: i,
|
|
@@ -452,20 +501,20 @@ function S(e, t = {}) {
|
|
|
452
501
|
cli: { path: u }
|
|
453
502
|
};
|
|
454
503
|
}
|
|
455
|
-
function
|
|
504
|
+
function T(e, t, n) {
|
|
456
505
|
let r = n.http?.verb?.[e];
|
|
457
506
|
return r === "GET" || r === "POST" ? r : t["x-apigen-safe"] ? "GET" : "POST";
|
|
458
507
|
}
|
|
459
|
-
var
|
|
508
|
+
var E = class extends Error {
|
|
460
509
|
constructor(e) {
|
|
461
510
|
let t = e.map((e) => ` [${e.transport}] "${e.target}" ← ${e.ids[0]} vs ${e.ids[1]}`);
|
|
462
511
|
super(`apigen-naming: ${e.length} projection collision(s) detected:\n${t.join("\n")}`), this.name = "CollisionDetectedError", this.collisions = e;
|
|
463
512
|
}
|
|
464
513
|
};
|
|
465
|
-
function
|
|
514
|
+
function D(e, t = {}) {
|
|
466
515
|
let n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), o = [];
|
|
467
516
|
for (let s of e) {
|
|
468
|
-
let e =
|
|
517
|
+
let e = w(s, t), c = `${e.http.verb} ${e.http.route}`, l = n.get(c);
|
|
469
518
|
l !== void 0 && l !== s.id ? o.push({
|
|
470
519
|
transport: "http",
|
|
471
520
|
target: c,
|
|
@@ -490,52 +539,55 @@ function T(e, t = {}) {
|
|
|
490
539
|
ids: [m, s.id]
|
|
491
540
|
}) : a.set(p, s.id);
|
|
492
541
|
}
|
|
493
|
-
if (o.length > 0) throw new
|
|
542
|
+
if (o.length > 0) throw new E(o);
|
|
494
543
|
}
|
|
495
|
-
function
|
|
544
|
+
function O(e, t) {
|
|
496
545
|
return `x-${e}-${t}`;
|
|
497
546
|
}
|
|
498
|
-
function
|
|
547
|
+
function k(e, t) {
|
|
499
548
|
return `--${e}-${t}`;
|
|
500
549
|
}
|
|
501
|
-
function
|
|
550
|
+
function A(e, t) {
|
|
502
551
|
let n = (e) => e.toUpperCase().replace(/-/g, "_");
|
|
503
552
|
return e === "adhd" ? `APIGEN_${n(t)}` : `APIGEN_${n(e)}_${n(t)}`;
|
|
504
553
|
}
|
|
505
|
-
var
|
|
506
|
-
function
|
|
554
|
+
var j = O;
|
|
555
|
+
function M(e) {
|
|
507
556
|
let t = e.replace(/[^a-zA-Z0-9_$]/g, "_");
|
|
508
557
|
return (t === "" || /^[0-9]/.test(t)) && (t = `_${t}`), t;
|
|
509
558
|
}
|
|
510
|
-
function
|
|
559
|
+
function N(e) {
|
|
511
560
|
let t = /* @__PURE__ */ new Set(), n = [];
|
|
512
561
|
for (let r of e) {
|
|
513
|
-
let e =
|
|
562
|
+
let e = M(r), i = e, a = 2;
|
|
514
563
|
for (; t.has(i);) i = `${e}_${a}`, a += 1;
|
|
515
564
|
t.add(i), n.push(i);
|
|
516
565
|
}
|
|
517
566
|
return n;
|
|
518
567
|
}
|
|
519
|
-
function
|
|
568
|
+
function P(e) {
|
|
520
569
|
return e.length === 0 ? e : e[0].toUpperCase() + e.slice(1);
|
|
521
570
|
}
|
|
522
571
|
//#endregion
|
|
523
572
|
//#region src/lib/emit.ts
|
|
524
|
-
function
|
|
573
|
+
function F(e) {
|
|
525
574
|
return e.replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
|
|
526
575
|
}
|
|
527
|
-
function
|
|
528
|
-
return
|
|
576
|
+
function I(e) {
|
|
577
|
+
return F(JSON.stringify(e));
|
|
529
578
|
}
|
|
530
|
-
function
|
|
579
|
+
function L(e) {
|
|
580
|
+
return `'${F(e.replace(/\\/g, "\\\\").replace(/'/g, "\\'").replace(/\n/g, "\\n").replace(/\r/g, "\\r"))}'`;
|
|
581
|
+
}
|
|
582
|
+
function R(e, t = 3e3) {
|
|
531
583
|
if (e == null) return t;
|
|
532
584
|
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
585
|
let n = Number(e);
|
|
534
586
|
if (!Number.isInteger(n) || n < 0 || n > 65535) throw TypeError(`apigen: invalid port option ${JSON.stringify(e)} — expected an integer in [0, 65535]`);
|
|
535
587
|
return n;
|
|
536
588
|
}
|
|
537
|
-
function
|
|
589
|
+
function z(e) {
|
|
538
590
|
return e.replace(/\\/g, "/");
|
|
539
591
|
}
|
|
540
592
|
//#endregion
|
|
541
|
-
export {
|
|
593
|
+
export { E as CollisionDetectedError, D as checkCollisions, R as coercePort, k as envelopeCliFlag, A as envelopeEnvVar, O as envelopeKey, j as envelopeMetaKey, F as escapeLineTerminators, L as escapeSingleQuotedLiteral, I as escapeStringLiteral, T as httpVerb, C as normalizeFileName, w as project, M as sanitizeIdentifier, b as toCamel, y as toKebab, x as toPascal, z as toPosixPath, S as toSnake, N as uniqueSanitizedIdentifiers };
|
package/lib/emit.d.ts
CHANGED
|
@@ -38,6 +38,21 @@ export declare function escapeLineTerminators(text: string): string;
|
|
|
38
38
|
* @example escapeStringLiteral('\u2028') // → `"\\u2028"`
|
|
39
39
|
*/
|
|
40
40
|
export declare function escapeStringLiteral(value: string): string;
|
|
41
|
+
/**
|
|
42
|
+
* Renders a value as a **complete, single-quoted JavaScript/TypeScript string
|
|
43
|
+
* literal** (including the surrounding quotes), for generators whose emitted
|
|
44
|
+
* source style is single-quoted.
|
|
45
|
+
*
|
|
46
|
+
* Escapes the backslash first, then the single quote, `\n`, `\r`, and the two
|
|
47
|
+
* raw line terminators `U+2028` / `U+2029` (via {@link escapeLineTerminators}).
|
|
48
|
+
* Identity (apart from the surrounding quotes) for plain ids and import paths,
|
|
49
|
+
* so output for ordinary inputs is unchanged.
|
|
50
|
+
*
|
|
51
|
+
* @example escapeSingleQuotedLiteral("it's") // → `'it\'s'`
|
|
52
|
+
* @example escapeSingleQuotedLiteral('a\nb') // → `'a\nb'` (no raw newline)
|
|
53
|
+
* @example escapeSingleQuotedLiteral('\u2028') // → `'\u2028'`
|
|
54
|
+
*/
|
|
55
|
+
export declare function escapeSingleQuotedLiteral(value: string): string;
|
|
41
56
|
/**
|
|
42
57
|
* Coerces a caller-supplied `port` option to a validated integer, safe to
|
|
43
58
|
* splice into generated source as a numeric literal.
|
package/package.json
CHANGED