@contract-kit/provider-storage-local 1.0.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/CHANGELOG.md +29 -0
- package/README.md +94 -0
- package/dist/index.d.ts +54 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +528 -0
- package/dist/index.js.map +1 -0
- package/package.json +65 -0
- package/src/index.ts +721 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# @contract-kit/provider-storage-local
|
|
2
|
+
|
|
3
|
+
## 1.0.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 72d66cb: Add a local filesystem storage provider with `createLocalStorage`,
|
|
8
|
+
`createLocalStorageProvider`, and `localStorageProvider`. Add
|
|
9
|
+
`createStorageRoute` for serving public storage objects from Next.js apps and
|
|
10
|
+
wire local storage into the framework starter.
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Updated dependencies [55f651c]
|
|
15
|
+
- Updated dependencies [e73a554]
|
|
16
|
+
- Updated dependencies [481e8ca]
|
|
17
|
+
- Updated dependencies [58d5528]
|
|
18
|
+
- Updated dependencies [c8b51ea]
|
|
19
|
+
- Updated dependencies [c5829fb]
|
|
20
|
+
- Updated dependencies [56ac09f]
|
|
21
|
+
- Updated dependencies [01eccbc]
|
|
22
|
+
- @contract-kit/devtools@1.0.0
|
|
23
|
+
- @contract-kit/ports@1.0.0
|
|
24
|
+
|
|
25
|
+
## 0.1.10
|
|
26
|
+
|
|
27
|
+
### Patch Changes
|
|
28
|
+
|
|
29
|
+
- Initial local filesystem storage provider package.
|
package/README.md
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# @contract-kit/provider-storage-local
|
|
2
|
+
|
|
3
|
+
Local filesystem storage provider for Contract Kit.
|
|
4
|
+
|
|
5
|
+
The provider installs the app-facing `ctx.ports.storage` port. Use it for
|
|
6
|
+
local development, tests that need durable files, and small deployments where a
|
|
7
|
+
filesystem-backed object store is enough.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
bun add @contract-kit/provider-storage-local
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Provider setup
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { localStorageProvider } from "@contract-kit/provider-storage-local";
|
|
19
|
+
import { createServer } from "@contract-kit/server";
|
|
20
|
+
|
|
21
|
+
const server = await createServer({
|
|
22
|
+
ports: basePorts,
|
|
23
|
+
providers: [localStorageProvider],
|
|
24
|
+
createContext: ({ ports }) => ({ ports }),
|
|
25
|
+
routes,
|
|
26
|
+
});
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Environment variables:
|
|
30
|
+
|
|
31
|
+
| Variable | Description |
|
|
32
|
+
| --- | --- |
|
|
33
|
+
| `STORAGE_ROOT` | Directory where objects are written. Defaults to `storage/app`. |
|
|
34
|
+
| `STORAGE_PUBLIC_BASE_URL` | Optional base URL returned by `publicUrl(...)` for public objects. |
|
|
35
|
+
|
|
36
|
+
`STORAGE_PUBLIC_BASE_URL` may be an absolute URL such as
|
|
37
|
+
`https://assets.example.com` or an app-relative path such as `/storage`.
|
|
38
|
+
The provider only returns URLs. If you use an app-relative path in a Next.js
|
|
39
|
+
app, serve public objects with `createStorageRoute`:
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
// app/storage/[...key]/route.ts
|
|
43
|
+
import { createStorageRoute } from "@contract-kit/next";
|
|
44
|
+
import { server } from "@/server";
|
|
45
|
+
|
|
46
|
+
export const { GET, HEAD } = createStorageRoute(server.ports.storage, {
|
|
47
|
+
basePath: "/storage",
|
|
48
|
+
});
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Direct port factory
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
import { createLocalStorage } from "@contract-kit/provider-storage-local";
|
|
55
|
+
|
|
56
|
+
const storage = createLocalStorage({
|
|
57
|
+
root: "storage/app",
|
|
58
|
+
publicBaseUrl: "/storage",
|
|
59
|
+
});
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
The same `StoragePort` works with local files, memory tests, and cloud object
|
|
63
|
+
stores:
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
await ctx.ports.storage.put("avatars/user_123.png", avatarBytes, {
|
|
67
|
+
contentType: "image/png",
|
|
68
|
+
visibility: "public",
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const object = await ctx.ports.storage.get("avatars/user_123.png");
|
|
72
|
+
const url = await ctx.ports.storage.publicUrl("avatars/user_123.png");
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Files on disk
|
|
76
|
+
|
|
77
|
+
Objects are written below `root` using their storage key. Object metadata is
|
|
78
|
+
stored in a `.ck-storage-meta` sidecar directory below the same root.
|
|
79
|
+
|
|
80
|
+
Storage keys must be relative object keys: no empty strings, empty path
|
|
81
|
+
segments, leading or trailing `/`, backslashes, or `.` / `..` path segments.
|
|
82
|
+
The `.ck-storage-meta` path segment is reserved for the provider's sidecar
|
|
83
|
+
metadata.
|
|
84
|
+
|
|
85
|
+
## Devtools
|
|
86
|
+
|
|
87
|
+
When `ctx.ports.devtools` is installed, the provider records storage
|
|
88
|
+
operations under the `storage` watcher. Events include operation name, key,
|
|
89
|
+
duration, object size, visibility, and whether a lookup hit. Object bodies are
|
|
90
|
+
never recorded.
|
|
91
|
+
|
|
92
|
+
## License
|
|
93
|
+
|
|
94
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { type StoragePort } from "@contract-kit/ports";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
export type { StorageBody, StorageMetadata, StorageObject, StorageObjectBody, StoragePort, StorageVisibility, } from "@contract-kit/ports";
|
|
4
|
+
declare const LocalStorageConfigSchema: z.ZodObject<{
|
|
5
|
+
ROOT: z.ZodDefault<z.ZodString>;
|
|
6
|
+
PUBLIC_BASE_URL: z.ZodOptional<z.ZodString>;
|
|
7
|
+
}, z.core.$strip>;
|
|
8
|
+
export type LocalStorageConfig = z.infer<typeof LocalStorageConfigSchema>;
|
|
9
|
+
export interface LocalStorageOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Directory where storage objects are written.
|
|
12
|
+
*/
|
|
13
|
+
root: string;
|
|
14
|
+
/**
|
|
15
|
+
* Base URL used by `publicUrl(...)` for public objects.
|
|
16
|
+
*/
|
|
17
|
+
publicBaseUrl?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Optional devtools target. The provider passes existing app ports here
|
|
20
|
+
* automatically; direct factory users can pass a devtools port explicitly.
|
|
21
|
+
*/
|
|
22
|
+
devtools?: unknown;
|
|
23
|
+
}
|
|
24
|
+
export interface LocalStorageProviderOptions {
|
|
25
|
+
/**
|
|
26
|
+
* Provider name. Defaults to "storage-local".
|
|
27
|
+
*/
|
|
28
|
+
name?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Default root used when STORAGE_ROOT is not set.
|
|
31
|
+
*/
|
|
32
|
+
root?: string;
|
|
33
|
+
/**
|
|
34
|
+
* Default public base URL used when STORAGE_PUBLIC_BASE_URL is not set.
|
|
35
|
+
*/
|
|
36
|
+
publicBaseUrl?: string;
|
|
37
|
+
}
|
|
38
|
+
export declare function createLocalStorage(options: LocalStorageOptions): StoragePort;
|
|
39
|
+
export interface LocalStorageProviderPorts {
|
|
40
|
+
storage: StoragePort;
|
|
41
|
+
}
|
|
42
|
+
export declare function createLocalStorageProvider(options?: LocalStorageProviderOptions): import("@contract-kit/ports").ServiceProvider<unknown, z.ZodObject<{
|
|
43
|
+
PUBLIC_BASE_URL: z.ZodOptional<z.ZodString>;
|
|
44
|
+
ROOT: z.ZodDefault<z.ZodString>;
|
|
45
|
+
}, z.core.$strip>, {
|
|
46
|
+
storage: StoragePort;
|
|
47
|
+
}>;
|
|
48
|
+
export declare const localStorageProvider: import("@contract-kit/ports").ServiceProvider<unknown, z.ZodObject<{
|
|
49
|
+
PUBLIC_BASE_URL: z.ZodOptional<z.ZodString>;
|
|
50
|
+
ROOT: z.ZodDefault<z.ZodString>;
|
|
51
|
+
}, z.core.$strip>, {
|
|
52
|
+
storage: StoragePort;
|
|
53
|
+
}>;
|
|
54
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAcA,OAAO,EAML,KAAK,WAAW,EAEjB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,YAAY,EACV,WAAW,EACX,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,WAAW,EACX,iBAAiB,GAClB,MAAM,qBAAqB,CAAC;AAI7B,QAAA,MAAM,wBAAwB;;;iBAG5B,CAAC;AAEH,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAE1E,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,2BAA2B;IAC1C;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AA8UD,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,mBAAmB,GAAG,WAAW,CAyQ5E;AAED,MAAM,WAAW,yBAAyB;IACxC,OAAO,EAAE,WAAW,CAAC;CACtB;AAED,wBAAgB,0BAA0B,CACxC,OAAO,GAAE,2BAAgC;;;;;GAoC1C;AAED,eAAO,MAAM,oBAAoB;;;;;EAA+B,CAAC"}
|