@ez4/local-storage 0.22.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/LICENSE +21 -0
- package/README.md +15 -0
- package/dist/main.cjs +24 -0
- package/dist/main.d.ts +1 -0
- package/dist/main.mjs +20 -0
- package/dist/provider/emulator.d.ts +12 -0
- package/dist/provider/register.d.ts +1 -0
- package/dist/service/client.d.ts +3 -0
- package/package.json +47 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Silas B.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
package/dist/main.cjs
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";var g=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var C=Object.prototype.hasOwnProperty;var n=(e,t)=>g(e,"name",{value:t,configurable:!0});var b=(e,t)=>{for(var o in t)g(e,o,{get:t[o],enumerable:!0})},z=(e,t,o,i)=>{if(t&&
|
|
2
|
+
typeof t=="object"||typeof t=="function")for(let r of v(t))!C.call(e,r)&&r!==o&&
|
|
3
|
+
g(e,r,{get:()=>t[r],enumerable:!(i=E(t,r))||i.enumerable});return e};var P=e=>z(g({},"__esModule",{value:!0}),e);var x={};b(x,{registerTriggers:()=>B});module.exports=P(x);var w=require("@ez4/storage/library"),h=require("@ez4/project/library");var m=require("@ez4/project/library");var a=require("node:fs/promises"),c=require("node:path"),p=require("node:fs"),u=require("@ez4/utils"),
|
|
4
|
+
y=require("@ez4/project/library");var f=n((e,t)=>{let o=(0,y.getServiceName)(e,t),i=(0,c.join)(".ez4",(0,u.toKebabCase)(
|
|
5
|
+
e));return new class{async exists(r){let s=(0,c.join)(i,r);return(0,p.existsSync)(
|
|
6
|
+
s)}async write(r,s){let l=(0,c.join)(i,r);await(0,a.mkdir)((0,c.dirname)(l),{recursive:!0}),
|
|
7
|
+
await(0,a.writeFile)(l,s)}async read(r){let s=(0,c.join)(i,r);return(0,a.readFile)(
|
|
8
|
+
s)}async delete(r){let s=(0,c.join)(i,r);await(0,a.unlink)(s)}async getWriteUrl(r){
|
|
9
|
+
return`http://${t.host}/${o}/${r}`}async getReadUrl(r){return`http://${t.host}/${o}\
|
|
10
|
+
/${r}`}async getStats(r){let s=(0,c.join)(i,r);try{return{type:"application/octe\
|
|
11
|
+
t-stream",size:(await(0,a.stat)(s)).size}}catch(l){if(!(0,u.isAnyObject)(l)||l.code!==
|
|
12
|
+
"ENOENT")throw l;return}}}},"createStorageClient");var d=n((e,t)=>{let o=f(e.name,t);return{type:"Storage",name:e.name,identifier:(0,m.getServiceName)(
|
|
13
|
+
e.name,t),clientHandler:n(()=>f(e.name,t),"clientHandler"),requestHandler:n(i=>F(
|
|
14
|
+
o,i),"requestHandler")}},"registerBucketEmulator"),F=n(async(e,t)=>{if(!t.path||
|
|
15
|
+
t.path==="/")throw new Error("File path wasn't given.");switch(t.method){case"GE\
|
|
16
|
+
T":return $(e,t.path);case"PUT":{if(!t.body)throw new Error("File content wasn't\
|
|
17
|
+
given.");return k(e,t.path,t.body)}default:throw new Error("Unsupported storage\
|
|
18
|
+
request.")}},"handleRequest"),$=n(async(e,t)=>{let[o,i]=await Promise.all([e.read(
|
|
19
|
+
t),e.getStats(t)]);return m.Logger.log(`File downloaded from ${t}`),{status:200,
|
|
20
|
+
body:o,headers:{"content-type":i}}},"loadFile"),k=n(async(e,t,o)=>(await e.write(
|
|
21
|
+
t,o),m.Logger.log(`File uploaded to ${t}`),{status:204}),"storeFile");var S=!1,B=n(()=>{S||((0,h.createTrigger)("@ez4/local-storage",{"emulator:getSer\
|
|
22
|
+
vices":n(({service:e,options:t})=>(0,w.isBucketService)(e)?d(e,t):null,"emulator\
|
|
23
|
+
:getServices")}),S=!0)},"registerTriggers");0&&(module.exports={registerTriggers});
|
|
24
|
+
//# sourceMappingURL=main.cjs.map
|
package/dist/main.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './provider/register.js';
|
package/dist/main.mjs
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
var f=Object.defineProperty;var o=(e,t)=>f(e,"name",{value:t,configurable:!0});import{isBucketService as k}from"@ez4/storage/library";import{createTrigger as B}from"@ez4/project/library";import{getServiceName as z,Logger as m}from"@ez4/project/library";import{mkdir as p,readFile as y,stat as d,unlink as S,writeFile as w}from"node:fs/promises";
|
|
2
|
+
import{dirname as h,join as c}from"node:path";import{existsSync as E}from"node:fs";
|
|
3
|
+
import{isAnyObject as v,toKebabCase as C}from"@ez4/utils";import{getServiceName as b}from"@ez4/project/library";var l=o((e,t)=>{let a=b(e,t),i=c(".ez4",C(e));return new class{async exists(r){let n=c(
|
|
4
|
+
i,r);return E(n)}async write(r,n){let s=c(i,r);await p(h(s),{recursive:!0}),await w(
|
|
5
|
+
s,n)}async read(r){let n=c(i,r);return y(n)}async delete(r){let n=c(i,r);await S(
|
|
6
|
+
n)}async getWriteUrl(r){return`http://${t.host}/${a}/${r}`}async getReadUrl(r){return`\
|
|
7
|
+
http://${t.host}/${a}/${r}`}async getStats(r){let n=c(i,r);try{return{type:"appl\
|
|
8
|
+
ication/octet-stream",size:(await d(n)).size}}catch(s){if(!v(s)||s.code!=="ENOEN\
|
|
9
|
+
T")throw s;return}}}},"createStorageClient");var g=o((e,t)=>{let a=l(e.name,t);return{type:"Storage",name:e.name,identifier:z(
|
|
10
|
+
e.name,t),clientHandler:o(()=>l(e.name,t),"clientHandler"),requestHandler:o(i=>P(
|
|
11
|
+
a,i),"requestHandler")}},"registerBucketEmulator"),P=o(async(e,t)=>{if(!t.path||
|
|
12
|
+
t.path==="/")throw new Error("File path wasn't given.");switch(t.method){case"GE\
|
|
13
|
+
T":return F(e,t.path);case"PUT":{if(!t.body)throw new Error("File content wasn't\
|
|
14
|
+
given.");return $(e,t.path,t.body)}default:throw new Error("Unsupported storage\
|
|
15
|
+
request.")}},"handleRequest"),F=o(async(e,t)=>{let[a,i]=await Promise.all([e.read(
|
|
16
|
+
t),e.getStats(t)]);return m.log(`File downloaded from ${t}`),{status:200,body:a,
|
|
17
|
+
headers:{"content-type":i}}},"loadFile"),$=o(async(e,t,a)=>(await e.write(t,a),m.
|
|
18
|
+
log(`File uploaded to ${t}`),{status:204}),"storeFile");var u=!1,J=o(()=>{u||(B("@ez4/local-storage",{"emulator:getServices":o(({service:e,
|
|
19
|
+
options:t})=>k(e)?g(e,t):null,"emulator:getServices")}),u=!0)},"registerTriggers");export{J as registerTriggers};
|
|
20
|
+
//# sourceMappingURL=main.mjs.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { EmulatorServiceRequest, ServeOptions } from '@ez4/project/library';
|
|
2
|
+
import type { Client as StorageClient } from '@ez4/storage';
|
|
3
|
+
import type { BucketService } from '@ez4/storage/library';
|
|
4
|
+
export declare const registerBucketEmulator: (service: BucketService, options: ServeOptions) => {
|
|
5
|
+
type: string;
|
|
6
|
+
name: string;
|
|
7
|
+
identifier: string;
|
|
8
|
+
clientHandler: () => StorageClient;
|
|
9
|
+
requestHandler: (request: EmulatorServiceRequest) => Promise<{
|
|
10
|
+
status: number;
|
|
11
|
+
}>;
|
|
12
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const registerTriggers: () => void;
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ez4/local-storage",
|
|
3
|
+
"description": "EZ4: Local storage emulator",
|
|
4
|
+
"version": "0.22.0",
|
|
5
|
+
"author": "Silas B.",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"ez4",
|
|
10
|
+
"ez4-local"
|
|
11
|
+
],
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/sbalmt/ez4.git",
|
|
15
|
+
"directory": "providers/local/local-storage"
|
|
16
|
+
},
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=22.7"
|
|
19
|
+
},
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/main.d.ts",
|
|
23
|
+
"require": "./dist/main.cjs",
|
|
24
|
+
"import": "./dist/main.mjs"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"workspaces": [
|
|
28
|
+
"packages/*",
|
|
29
|
+
"providers/local/*"
|
|
30
|
+
],
|
|
31
|
+
"scripts": {
|
|
32
|
+
"clean": "rm -f *.tsbuildinfo && rm -rf dist/*",
|
|
33
|
+
"build": "tsc -p tsconfig.json && node tools/bundler.mjs",
|
|
34
|
+
"test": "npm run test:types && node --test --import ../../../tools/tsnode.mjs test/*.spec.ts",
|
|
35
|
+
"test:only": "npm run test:types && node --test-only --test --import ../../../tools/tsnode.mjs test/*.spec.ts",
|
|
36
|
+
"test:types": "npm run build && tsc -p tsconfig.test.json",
|
|
37
|
+
"local:publish": "npm run build && npm run clean:registry && npm publish --registry http://localhost:4873",
|
|
38
|
+
"clean:registry": "rm -rf ../../../.registry/@ez4/local-storage",
|
|
39
|
+
"live:publish": "npm run test && npm publish --access public"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@ez4/local-common": "^0.22.0",
|
|
43
|
+
"@ez4/project": "^0.22.0",
|
|
44
|
+
"@ez4/storage": "^0.22.0",
|
|
45
|
+
"@ez4/utils": "^0.22.0"
|
|
46
|
+
}
|
|
47
|
+
}
|