-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
157 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: publish to npm | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'v*' | ||
|
||
jobs: | ||
build-and-publish: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: '22' | ||
registry-url: 'https://registry.npmjs.org/' | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Build the package | ||
run: npm run build | ||
|
||
- name: Publish to npm | ||
run: npm publish --access public | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
|
||
- name: Done | ||
run: echo "Package published to npm successfully." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
src | ||
*config.* | ||
.github |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "vesuva", | ||
"version": "0.0.1-notest", | ||
"description": "dynamically reconstructs method chains as strings using proxies.", | ||
"main": "lib/index.js", | ||
"types": "lib/index.d.ts", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+github.com:kanamone/vesuva.git" | ||
}, | ||
"type": "module", | ||
"scripts": { | ||
"prepare": "npm run build", | ||
"build": "tsc -p ." | ||
}, | ||
"author": { | ||
"name": "uneco", | ||
"email": "[email protected]", | ||
"url": "https://u-ne.co" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"devDependencies": { | ||
"typescript": "^5.4.5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
function slate <T> (): T { | ||
return (() => {}) as T | ||
} | ||
|
||
export function encode (arg: unknown): string { | ||
if (typeof arg === 'object') { | ||
if (arg === null) { | ||
return 'null' | ||
} | ||
|
||
if (Array.isArray(arg)) { | ||
return `[${arg.map(encode).join(',')}]` | ||
} | ||
|
||
const keys = Object.keys(arg) | ||
const pairs = keys.map((key) => `${key}:${encode((arg as Record<string, unknown>)[key])}`) | ||
|
||
return `{${pairs.join(',')}}` | ||
} | ||
|
||
if (arg === undefined) { | ||
return 'undefined' | ||
} | ||
|
||
let isVesuva = false | ||
|
||
try { | ||
(arg as { __VESUVA__: () => void }).__VESUVA__() | ||
isVesuva = true | ||
} catch (e) {} | ||
|
||
if (isVesuva) { | ||
return arg.toString() | ||
} | ||
|
||
return JSON.stringify(arg) | ||
} | ||
|
||
export function proxy<T extends object>(receiver: string, initialPath: string[] = []): T { | ||
return new Proxy<T>(slate(), { | ||
get(_target, propKey) { | ||
const stringify = () => [receiver, ...initialPath].join('.') | ||
|
||
const specials: Record<string, () => unknown> = { | ||
toString: stringify, | ||
toJSON: stringify, | ||
__VESUVA__ () { | ||
return true | ||
} | ||
} | ||
|
||
if (typeof propKey === 'string' && propKey in specials) { | ||
return specials[propKey] | ||
} | ||
|
||
return new Proxy(slate(), { | ||
apply (_target, _thisArg, argumentsList) { | ||
const args = argumentsList.map(encode).join(', '); | ||
const newPath = [...initialPath, `${String(propKey)}(${args})`]; | ||
return proxy(receiver, newPath); | ||
} | ||
}); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"compilerOptions": { | ||
"lib": ["ES6", "ES2015.Proxy"], | ||
"allowJs": true, | ||
"skipLibCheck": true, | ||
"strict": true, | ||
"declaration": true, | ||
"sourceMap": true, | ||
"outDir": "./lib", | ||
"forceConsistentCasingInFileNames": true, | ||
"noEmit": false, | ||
"incremental": true, | ||
"esModuleInterop": true, | ||
"module": "esnext", | ||
"moduleResolution": "node", | ||
"isolatedModules": true | ||
}, | ||
"include": ["src/index.ts"], | ||
"exclude": ["node_modules"] | ||
} |