@gadicc/loom 0.0.0-oidc-bootstrap.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 +201 -0
- package/NOTICE +6 -0
- package/README.md +448 -0
- package/THIRD_PARTY_NOTICES.md +25 -0
- package/db/drizzle-config.d.ts +20 -0
- package/db/drizzle-config.js +34 -0
- package/db/fixtures.d.ts +31 -0
- package/db/fixtures.js +52 -0
- package/db/neon.d.ts +3 -0
- package/db/neon.js +20 -0
- package/db/neonFull.d.ts +12 -0
- package/db/neonFull.js +33 -0
- package/db/package.json +3 -0
- package/db/testing.d.ts +26 -0
- package/db/testing.js +76 -0
- package/db/testing.test.ts +28 -0
- package/db/valibot.d.ts +23 -0
- package/db/valibot.js +8 -0
- package/esm/_dnt.polyfills.d.ts +149 -0
- package/esm/_dnt.polyfills.d.ts.map +1 -0
- package/esm/_dnt.polyfills.js +163 -0
- package/esm/_dnt.shims.d.ts +2 -0
- package/esm/_dnt.shims.d.ts.map +1 -0
- package/esm/_dnt.shims.js +57 -0
- package/esm/bin/loom.d.ts +2 -0
- package/esm/bin/loom.d.ts.map +1 -0
- package/esm/bin/loom.js +11 -0
- package/esm/mod.d.ts +9 -0
- package/esm/mod.d.ts.map +1 -0
- package/esm/mod.js +8 -0
- package/esm/package.json +3 -0
- package/esm/src/apiKeys/authorize.d.ts +4 -0
- package/esm/src/apiKeys/authorize.d.ts.map +1 -0
- package/esm/src/apiKeys/authorize.js +184 -0
- package/esm/src/apiKeys/country.d.ts +3 -0
- package/esm/src/apiKeys/country.d.ts.map +1 -0
- package/esm/src/apiKeys/country.js +7 -0
- package/esm/src/apiKeys/credentials.d.ts +4 -0
- package/esm/src/apiKeys/credentials.d.ts.map +1 -0
- package/esm/src/apiKeys/credentials.js +55 -0
- package/esm/src/apiKeys/fingerprint.d.ts +3 -0
- package/esm/src/apiKeys/fingerprint.d.ts.map +1 -0
- package/esm/src/apiKeys/fingerprint.js +5 -0
- package/esm/src/apiKeys/mod.d.ts +9 -0
- package/esm/src/apiKeys/mod.d.ts.map +1 -0
- package/esm/src/apiKeys/mod.js +8 -0
- package/esm/src/apiKeys/policy.d.ts +59 -0
- package/esm/src/apiKeys/policy.d.ts.map +1 -0
- package/esm/src/apiKeys/policy.js +88 -0
- package/esm/src/apiKeys/retention.d.ts +55 -0
- package/esm/src/apiKeys/retention.d.ts.map +1 -0
- package/esm/src/apiKeys/retention.js +65 -0
- package/esm/src/apiKeys/types.d.ts +175 -0
- package/esm/src/apiKeys/types.d.ts.map +1 -0
- package/esm/src/apiKeys/types.js +1 -0
- package/esm/src/cli/externalSkills.d.ts +39 -0
- package/esm/src/cli/externalSkills.d.ts.map +1 -0
- package/esm/src/cli/externalSkills.js +177 -0
- package/esm/src/cli/mod.d.ts +337 -0
- package/esm/src/cli/mod.d.ts.map +1 -0
- package/esm/src/cli/mod.js +9268 -0
- package/esm/src/cli/projectSkills.d.ts +102 -0
- package/esm/src/cli/projectSkills.d.ts.map +1 -0
- package/esm/src/cli/projectSkills.js +592 -0
- package/esm/src/files/client.d.ts +29 -0
- package/esm/src/files/client.d.ts.map +1 -0
- package/esm/src/files/client.js +41 -0
- package/esm/src/files/errors.d.ts +37 -0
- package/esm/src/files/errors.d.ts.map +1 -0
- package/esm/src/files/errors.js +66 -0
- package/esm/src/files/hash.d.ts +15 -0
- package/esm/src/files/hash.d.ts.map +1 -0
- package/esm/src/files/hash.js +82 -0
- package/esm/src/files/memory.d.ts +29 -0
- package/esm/src/files/memory.d.ts.map +1 -0
- package/esm/src/files/memory.js +109 -0
- package/esm/src/files/metadata.d.ts +10 -0
- package/esm/src/files/metadata.d.ts.map +1 -0
- package/esm/src/files/metadata.js +186 -0
- package/esm/src/files/mod.d.ts +10 -0
- package/esm/src/files/mod.d.ts.map +1 -0
- package/esm/src/files/mod.js +9 -0
- package/esm/src/files/s3.d.ts +29 -0
- package/esm/src/files/s3.d.ts.map +1 -0
- package/esm/src/files/s3.js +107 -0
- package/esm/src/files/service.d.ts +27 -0
- package/esm/src/files/service.d.ts.map +1 -0
- package/esm/src/files/service.js +136 -0
- package/esm/src/files/types.d.ts +134 -0
- package/esm/src/files/types.d.ts.map +1 -0
- package/esm/src/files/types.js +1 -0
- package/esm/src/jobs/catalog.d.ts +32 -0
- package/esm/src/jobs/catalog.d.ts.map +1 -0
- package/esm/src/jobs/catalog.js +208 -0
- package/esm/src/jobs/controller.d.ts +28 -0
- package/esm/src/jobs/controller.d.ts.map +1 -0
- package/esm/src/jobs/controller.js +95 -0
- package/esm/src/jobs/direct.d.ts +36 -0
- package/esm/src/jobs/direct.d.ts.map +1 -0
- package/esm/src/jobs/direct.js +122 -0
- package/esm/src/jobs/events.d.ts +15 -0
- package/esm/src/jobs/events.d.ts.map +1 -0
- package/esm/src/jobs/events.js +30 -0
- package/esm/src/jobs/format.d.ts +16 -0
- package/esm/src/jobs/format.d.ts.map +1 -0
- package/esm/src/jobs/format.js +183 -0
- package/esm/src/jobs/http.d.ts +22 -0
- package/esm/src/jobs/http.d.ts.map +1 -0
- package/esm/src/jobs/http.js +44 -0
- package/esm/src/jobs/log.d.ts +2 -0
- package/esm/src/jobs/log.d.ts.map +1 -0
- package/esm/src/jobs/log.js +10 -0
- package/esm/src/jobs/mod.d.ts +10 -0
- package/esm/src/jobs/mod.d.ts.map +1 -0
- package/esm/src/jobs/mod.js +9 -0
- package/esm/src/jobs/run.d.ts +20 -0
- package/esm/src/jobs/run.d.ts.map +1 -0
- package/esm/src/jobs/run.js +57 -0
- package/esm/src/jobs/types.d.ts +31 -0
- package/esm/src/jobs/types.d.ts.map +1 -0
- package/esm/src/jobs/types.js +1 -0
- package/esm/src/mui/apiKeys.d.ts +65 -0
- package/esm/src/mui/apiKeys.d.ts.map +1 -0
- package/esm/src/mui/apiKeys.js +301 -0
- package/esm/src/mui/apiKeysView.d.ts +48 -0
- package/esm/src/mui/apiKeysView.d.ts.map +1 -0
- package/esm/src/mui/apiKeysView.js +34 -0
- package/esm/src/mui/confirm.d.ts +12 -0
- package/esm/src/mui/confirm.d.ts.map +1 -0
- package/esm/src/mui/confirm.js +78 -0
- package/esm/src/mui/mod.d.ts +4 -0
- package/esm/src/mui/mod.d.ts.map +1 -0
- package/esm/src/mui/mod.js +2 -0
- package/esm/src/next/apiKeys/mod.d.ts +64 -0
- package/esm/src/next/apiKeys/mod.d.ts.map +1 -0
- package/esm/src/next/apiKeys/mod.js +217 -0
- package/esm/src/next/auth/config.d.ts +34 -0
- package/esm/src/next/auth/config.d.ts.map +1 -0
- package/esm/src/next/auth/config.js +103 -0
- package/esm/src/next/auth/mod.d.ts +3 -0
- package/esm/src/next/auth/mod.d.ts.map +1 -0
- package/esm/src/next/auth/mod.js +2 -0
- package/esm/src/next/auth/server.d.ts +28 -0
- package/esm/src/next/auth/server.d.ts.map +1 -0
- package/esm/src/next/auth/server.js +24 -0
- package/esm/src/next/files/mod.d.ts +3 -0
- package/esm/src/next/files/mod.d.ts.map +1 -0
- package/esm/src/next/files/mod.js +2 -0
- package/esm/src/next/files/route.d.ts +99 -0
- package/esm/src/next/files/route.d.ts.map +1 -0
- package/esm/src/next/files/route.js +349 -0
- package/esm/src/next/jobs/list.d.ts +25 -0
- package/esm/src/next/jobs/list.d.ts.map +1 -0
- package/esm/src/next/jobs/list.js +39 -0
- package/esm/src/next/jobs/mod.d.ts +6 -0
- package/esm/src/next/jobs/mod.d.ts.map +1 -0
- package/esm/src/next/jobs/mod.js +5 -0
- package/esm/src/next/jobs/paths.d.ts +14 -0
- package/esm/src/next/jobs/paths.d.ts.map +1 -0
- package/esm/src/next/jobs/paths.js +40 -0
- package/esm/src/next/jobs/route.d.ts +48 -0
- package/esm/src/next/jobs/route.d.ts.map +1 -0
- package/esm/src/next/jobs/route.js +101 -0
- package/esm/src/next/jobs/run.d.ts +51 -0
- package/esm/src/next/jobs/run.d.ts.map +1 -0
- package/esm/src/next/jobs/run.js +563 -0
- package/esm/src/next/jobs/stream.d.ts +3 -0
- package/esm/src/next/jobs/stream.d.ts.map +1 -0
- package/esm/src/next/jobs/stream.js +25 -0
- package/esm/src/next/pwa/mod.d.ts +104 -0
- package/esm/src/next/pwa/mod.d.ts.map +1 -0
- package/esm/src/next/pwa/mod.js +169 -0
- package/esm/src/next/pwa/worker.d.ts +27 -0
- package/esm/src/next/pwa/worker.d.ts.map +1 -0
- package/esm/src/next/pwa/worker.js +27 -0
- package/package.json +293 -0
- package/script/_dnt.polyfills.d.ts +149 -0
- package/script/_dnt.polyfills.d.ts.map +1 -0
- package/script/_dnt.polyfills.js +166 -0
- package/script/_dnt.shims.d.ts +2 -0
- package/script/_dnt.shims.d.ts.map +1 -0
- package/script/_dnt.shims.js +60 -0
- package/script/bin/loom.d.ts +2 -0
- package/script/bin/loom.d.ts.map +1 -0
- package/script/bin/loom.js +17 -0
- package/script/mod.d.ts +9 -0
- package/script/mod.d.ts.map +1 -0
- package/script/mod.js +24 -0
- package/script/package.json +3 -0
- package/script/src/apiKeys/authorize.d.ts +4 -0
- package/script/src/apiKeys/authorize.d.ts.map +1 -0
- package/script/src/apiKeys/authorize.js +187 -0
- package/script/src/apiKeys/country.d.ts +3 -0
- package/script/src/apiKeys/country.d.ts.map +1 -0
- package/script/src/apiKeys/country.js +10 -0
- package/script/src/apiKeys/credentials.d.ts +4 -0
- package/script/src/apiKeys/credentials.d.ts.map +1 -0
- package/script/src/apiKeys/credentials.js +58 -0
- package/script/src/apiKeys/fingerprint.d.ts +3 -0
- package/script/src/apiKeys/fingerprint.d.ts.map +1 -0
- package/script/src/apiKeys/fingerprint.js +8 -0
- package/script/src/apiKeys/mod.d.ts +9 -0
- package/script/src/apiKeys/mod.d.ts.map +1 -0
- package/script/src/apiKeys/mod.js +24 -0
- package/script/src/apiKeys/policy.d.ts +59 -0
- package/script/src/apiKeys/policy.d.ts.map +1 -0
- package/script/src/apiKeys/policy.js +92 -0
- package/script/src/apiKeys/retention.d.ts +55 -0
- package/script/src/apiKeys/retention.d.ts.map +1 -0
- package/script/src/apiKeys/retention.js +70 -0
- package/script/src/apiKeys/types.d.ts +175 -0
- package/script/src/apiKeys/types.d.ts.map +1 -0
- package/script/src/apiKeys/types.js +2 -0
- package/script/src/cli/externalSkills.d.ts +39 -0
- package/script/src/cli/externalSkills.d.ts.map +1 -0
- package/script/src/cli/externalSkills.js +181 -0
- package/script/src/cli/mod.d.ts +337 -0
- package/script/src/cli/mod.d.ts.map +1 -0
- package/script/src/cli/mod.js +9337 -0
- package/script/src/cli/projectSkills.d.ts +102 -0
- package/script/src/cli/projectSkills.d.ts.map +1 -0
- package/script/src/cli/projectSkills.js +606 -0
- package/script/src/files/client.d.ts +29 -0
- package/script/src/files/client.d.ts.map +1 -0
- package/script/src/files/client.js +45 -0
- package/script/src/files/errors.d.ts +37 -0
- package/script/src/files/errors.d.ts.map +1 -0
- package/script/src/files/errors.js +76 -0
- package/script/src/files/hash.d.ts +15 -0
- package/script/src/files/hash.d.ts.map +1 -0
- package/script/src/files/hash.js +89 -0
- package/script/src/files/memory.d.ts +29 -0
- package/script/src/files/memory.d.ts.map +1 -0
- package/script/src/files/memory.js +113 -0
- package/script/src/files/metadata.d.ts +10 -0
- package/script/src/files/metadata.d.ts.map +1 -0
- package/script/src/files/metadata.js +189 -0
- package/script/src/files/mod.d.ts +10 -0
- package/script/src/files/mod.d.ts.map +1 -0
- package/script/src/files/mod.js +25 -0
- package/script/src/files/s3.d.ts +29 -0
- package/script/src/files/s3.d.ts.map +1 -0
- package/script/src/files/s3.js +110 -0
- package/script/src/files/service.d.ts +27 -0
- package/script/src/files/service.d.ts.map +1 -0
- package/script/src/files/service.js +139 -0
- package/script/src/files/types.d.ts +134 -0
- package/script/src/files/types.d.ts.map +1 -0
- package/script/src/files/types.js +2 -0
- package/script/src/jobs/catalog.d.ts +32 -0
- package/script/src/jobs/catalog.d.ts.map +1 -0
- package/script/src/jobs/catalog.js +223 -0
- package/script/src/jobs/controller.d.ts +28 -0
- package/script/src/jobs/controller.d.ts.map +1 -0
- package/script/src/jobs/controller.js +100 -0
- package/script/src/jobs/direct.d.ts +36 -0
- package/script/src/jobs/direct.d.ts.map +1 -0
- package/script/src/jobs/direct.js +128 -0
- package/script/src/jobs/events.d.ts +15 -0
- package/script/src/jobs/events.d.ts.map +1 -0
- package/script/src/jobs/events.js +37 -0
- package/script/src/jobs/format.d.ts +16 -0
- package/script/src/jobs/format.d.ts.map +1 -0
- package/script/src/jobs/format.js +193 -0
- package/script/src/jobs/http.d.ts +22 -0
- package/script/src/jobs/http.d.ts.map +1 -0
- package/script/src/jobs/http.js +50 -0
- package/script/src/jobs/log.d.ts +2 -0
- package/script/src/jobs/log.d.ts.map +1 -0
- package/script/src/jobs/log.js +13 -0
- package/script/src/jobs/mod.d.ts +10 -0
- package/script/src/jobs/mod.d.ts.map +1 -0
- package/script/src/jobs/mod.js +25 -0
- package/script/src/jobs/run.d.ts +20 -0
- package/script/src/jobs/run.d.ts.map +1 -0
- package/script/src/jobs/run.js +61 -0
- package/script/src/jobs/types.d.ts +31 -0
- package/script/src/jobs/types.d.ts.map +1 -0
- package/script/src/jobs/types.js +2 -0
- package/script/src/mui/apiKeys.d.ts +65 -0
- package/script/src/mui/apiKeys.d.ts.map +1 -0
- package/script/src/mui/apiKeys.js +327 -0
- package/script/src/mui/apiKeysView.d.ts +48 -0
- package/script/src/mui/apiKeysView.d.ts.map +1 -0
- package/script/src/mui/apiKeysView.js +40 -0
- package/script/src/mui/confirm.d.ts +12 -0
- package/script/src/mui/confirm.d.ts.map +1 -0
- package/script/src/mui/confirm.js +85 -0
- package/script/src/mui/mod.d.ts +4 -0
- package/script/src/mui/mod.d.ts.map +1 -0
- package/script/src/mui/mod.js +19 -0
- package/script/src/next/apiKeys/mod.d.ts +64 -0
- package/script/src/next/apiKeys/mod.d.ts.map +1 -0
- package/script/src/next/apiKeys/mod.js +224 -0
- package/script/src/next/auth/config.d.ts +34 -0
- package/script/src/next/auth/config.d.ts.map +1 -0
- package/script/src/next/auth/config.js +142 -0
- package/script/src/next/auth/mod.d.ts +3 -0
- package/script/src/next/auth/mod.d.ts.map +1 -0
- package/script/src/next/auth/mod.js +18 -0
- package/script/src/next/auth/server.d.ts +28 -0
- package/script/src/next/auth/server.d.ts.map +1 -0
- package/script/src/next/auth/server.js +27 -0
- package/script/src/next/files/mod.d.ts +3 -0
- package/script/src/next/files/mod.d.ts.map +1 -0
- package/script/src/next/files/mod.js +18 -0
- package/script/src/next/files/route.d.ts +99 -0
- package/script/src/next/files/route.d.ts.map +1 -0
- package/script/src/next/files/route.js +353 -0
- package/script/src/next/jobs/list.d.ts +25 -0
- package/script/src/next/jobs/list.d.ts.map +1 -0
- package/script/src/next/jobs/list.js +48 -0
- package/script/src/next/jobs/mod.d.ts +6 -0
- package/script/src/next/jobs/mod.d.ts.map +1 -0
- package/script/src/next/jobs/mod.js +21 -0
- package/script/src/next/jobs/paths.d.ts +14 -0
- package/script/src/next/jobs/paths.d.ts.map +1 -0
- package/script/src/next/jobs/paths.js +47 -0
- package/script/src/next/jobs/route.d.ts +48 -0
- package/script/src/next/jobs/route.d.ts.map +1 -0
- package/script/src/next/jobs/route.js +105 -0
- package/script/src/next/jobs/run.d.ts +51 -0
- package/script/src/next/jobs/run.d.ts.map +1 -0
- package/script/src/next/jobs/run.js +570 -0
- package/script/src/next/jobs/stream.d.ts +3 -0
- package/script/src/next/jobs/stream.d.ts.map +1 -0
- package/script/src/next/jobs/stream.js +28 -0
- package/script/src/next/pwa/mod.d.ts +104 -0
- package/script/src/next/pwa/mod.d.ts.map +1 -0
- package/script/src/next/pwa/mod.js +192 -0
- package/script/src/next/pwa/worker.d.ts +27 -0
- package/script/src/next/pwa/worker.d.ts.map +1 -0
- package/script/src/next/pwa/worker.js +33 -0
- package/skills/loom/SKILL.md +200 -0
- package/skills/loom-api-keys/SKILL.md +123 -0
- package/skills/loom-auth/SKILL.md +70 -0
- package/skills/loom-db/SKILL.md +94 -0
- package/skills/loom-db/references/db-stack.md +39 -0
- package/skills/loom-files/SKILL.md +97 -0
- package/skills/loom-jobs/SKILL.md +148 -0
- package/skills/upgrade-deps/SKILL.md +165 -0
- package/skills/upgrade-deps/agents/openai.yaml +4 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base error for file runtime failures that can be translated into HTTP
|
|
3
|
+
* responses by route adapters.
|
|
4
|
+
*/
|
|
5
|
+
export declare class LoomFileError extends Error {
|
|
6
|
+
readonly code: string;
|
|
7
|
+
readonly status: number;
|
|
8
|
+
constructor(message: string, options: {
|
|
9
|
+
code: string;
|
|
10
|
+
status: number;
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
export declare class LoomFileDigestMismatchError extends LoomFileError {
|
|
14
|
+
constructor(options: {
|
|
15
|
+
actual: string;
|
|
16
|
+
expected: string;
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
export declare class LoomFileDuplicateError extends LoomFileError {
|
|
20
|
+
constructor(message?: string);
|
|
21
|
+
}
|
|
22
|
+
export declare class LoomFileInvalidDigestError extends LoomFileError {
|
|
23
|
+
constructor(value: string);
|
|
24
|
+
}
|
|
25
|
+
export declare class LoomFileNotFoundError extends LoomFileError {
|
|
26
|
+
constructor(message?: string);
|
|
27
|
+
}
|
|
28
|
+
export declare class LoomFileSizeLimitError extends LoomFileError {
|
|
29
|
+
constructor(options: {
|
|
30
|
+
actual: number;
|
|
31
|
+
maxBytes: number;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
export declare class LoomFileStorageReadUnsupportedError extends LoomFileError {
|
|
35
|
+
constructor();
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/src/files/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,qBAAa,aAAc,SAAQ,KAAK;IACtC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBAEZ,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE;CAMvE;AAED,qBAAa,2BAA4B,SAAQ,aAAa;gBAChD,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE;CAO1D;AAED,qBAAa,sBAAuB,SAAQ,aAAa;gBAErD,OAAO,SAAwD;CAKlE;AAED,qBAAa,0BAA2B,SAAQ,aAAa;gBAC/C,KAAK,EAAE,MAAM;CAO1B;AAED,qBAAa,qBAAsB,SAAQ,aAAa;gBAC1C,OAAO,SAAoB;CAIxC;AAED,qBAAa,sBAAuB,SAAQ,aAAa;gBAC3C,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE;CAO1D;AAED,qBAAa,mCAAoC,SAAQ,aAAa;;CAQrE"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LoomFileStorageReadUnsupportedError = exports.LoomFileSizeLimitError = exports.LoomFileNotFoundError = exports.LoomFileInvalidDigestError = exports.LoomFileDuplicateError = exports.LoomFileDigestMismatchError = exports.LoomFileError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Base error for file runtime failures that can be translated into HTTP
|
|
6
|
+
* responses by route adapters.
|
|
7
|
+
*/
|
|
8
|
+
class LoomFileError extends Error {
|
|
9
|
+
constructor(message, options) {
|
|
10
|
+
super(message);
|
|
11
|
+
Object.defineProperty(this, "code", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
configurable: true,
|
|
14
|
+
writable: true,
|
|
15
|
+
value: void 0
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(this, "status", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
configurable: true,
|
|
20
|
+
writable: true,
|
|
21
|
+
value: void 0
|
|
22
|
+
});
|
|
23
|
+
this.name = "LoomFileError";
|
|
24
|
+
this.code = options.code;
|
|
25
|
+
this.status = options.status;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.LoomFileError = LoomFileError;
|
|
29
|
+
class LoomFileDigestMismatchError extends LoomFileError {
|
|
30
|
+
constructor(options) {
|
|
31
|
+
super(`SHA-256 digest mismatch: expected ${options.expected}, received ${options.actual}.`, { code: "digest_mismatch", status: 400 });
|
|
32
|
+
this.name = "LoomFileDigestMismatchError";
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.LoomFileDigestMismatchError = LoomFileDigestMismatchError;
|
|
36
|
+
class LoomFileDuplicateError extends LoomFileError {
|
|
37
|
+
constructor(message = "A file with the same SHA-256 digest already exists.") {
|
|
38
|
+
super(message, { code: "duplicate_file", status: 409 });
|
|
39
|
+
this.name = "LoomFileDuplicateError";
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.LoomFileDuplicateError = LoomFileDuplicateError;
|
|
43
|
+
class LoomFileInvalidDigestError extends LoomFileError {
|
|
44
|
+
constructor(value) {
|
|
45
|
+
super(`Invalid SHA-256 digest: ${value}.`, {
|
|
46
|
+
code: "invalid_digest",
|
|
47
|
+
status: 400,
|
|
48
|
+
});
|
|
49
|
+
this.name = "LoomFileInvalidDigestError";
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.LoomFileInvalidDigestError = LoomFileInvalidDigestError;
|
|
53
|
+
class LoomFileNotFoundError extends LoomFileError {
|
|
54
|
+
constructor(message = "File not found.") {
|
|
55
|
+
super(message, { code: "not_found", status: 404 });
|
|
56
|
+
this.name = "LoomFileNotFoundError";
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.LoomFileNotFoundError = LoomFileNotFoundError;
|
|
60
|
+
class LoomFileSizeLimitError extends LoomFileError {
|
|
61
|
+
constructor(options) {
|
|
62
|
+
super(`File is too large: ${options.actual} bytes exceeds ${options.maxBytes} bytes.`, { code: "size_limit_exceeded", status: 413 });
|
|
63
|
+
this.name = "LoomFileSizeLimitError";
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.LoomFileSizeLimitError = LoomFileSizeLimitError;
|
|
67
|
+
class LoomFileStorageReadUnsupportedError extends LoomFileError {
|
|
68
|
+
constructor() {
|
|
69
|
+
super("The configured file storage adapter does not support reads.", {
|
|
70
|
+
code: "storage_read_unsupported",
|
|
71
|
+
status: 501,
|
|
72
|
+
});
|
|
73
|
+
this.name = "LoomFileStorageReadUnsupportedError";
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.LoomFileStorageReadUnsupportedError = LoomFileStorageReadUnsupportedError;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { LoomFileBody } from "./types.js";
|
|
2
|
+
export interface ReadLoomFileBodyOptions {
|
|
3
|
+
maxBytes?: number;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Reads a supported file body into bytes and enforces an optional size limit.
|
|
7
|
+
* Route adapters use this before hashing so server-side limits are applied
|
|
8
|
+
* consistently for raw and multipart uploads.
|
|
9
|
+
*/
|
|
10
|
+
export declare function readLoomFileBodyBytes(body: LoomFileBody, options?: ReadLoomFileBodyOptions): Promise<Uint8Array<any>>;
|
|
11
|
+
export declare function sha256Hex(body: Uint8Array | ArrayBuffer): Promise<string>;
|
|
12
|
+
export declare function isSha256Hex(value: string): boolean;
|
|
13
|
+
export declare function normalizeSha256Hex(value: string): string;
|
|
14
|
+
export declare function assertExpectedSha256(actual: string, expected: string | null): void;
|
|
15
|
+
//# sourceMappingURL=hash.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../../src/src/files/hash.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAoBD;;;;GAIG;AACH,wBAAsB,qBAAqB,CACzC,IAAI,EAAE,YAAY,EAClB,OAAO,GAAE,uBAA4B,4BAwCtC;AAED,wBAAsB,SAAS,CAAC,IAAI,EAAE,UAAU,GAAG,WAAW,mBAI7D;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,WAExC;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,UAM/C;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,QAY3E"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readLoomFileBodyBytes = readLoomFileBodyBytes;
|
|
4
|
+
exports.sha256Hex = sha256Hex;
|
|
5
|
+
exports.isSha256Hex = isSha256Hex;
|
|
6
|
+
exports.normalizeSha256Hex = normalizeSha256Hex;
|
|
7
|
+
exports.assertExpectedSha256 = assertExpectedSha256;
|
|
8
|
+
const errors_js_1 = require("./errors.js");
|
|
9
|
+
function toHex(bytes) {
|
|
10
|
+
return [...bytes].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
11
|
+
}
|
|
12
|
+
function isReadableStream(value) {
|
|
13
|
+
return value instanceof ReadableStream;
|
|
14
|
+
}
|
|
15
|
+
function isArrayBufferView(value) {
|
|
16
|
+
return ArrayBuffer.isView(value);
|
|
17
|
+
}
|
|
18
|
+
function assertWithinLimit(byteSize, maxBytes) {
|
|
19
|
+
if (maxBytes !== undefined && byteSize > maxBytes) {
|
|
20
|
+
throw new errors_js_1.LoomFileSizeLimitError({ actual: byteSize, maxBytes });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Reads a supported file body into bytes and enforces an optional size limit.
|
|
25
|
+
* Route adapters use this before hashing so server-side limits are applied
|
|
26
|
+
* consistently for raw and multipart uploads.
|
|
27
|
+
*/
|
|
28
|
+
async function readLoomFileBodyBytes(body, options = {}) {
|
|
29
|
+
if (body instanceof Blob) {
|
|
30
|
+
assertWithinLimit(body.size, options.maxBytes);
|
|
31
|
+
return new Uint8Array(await body.arrayBuffer());
|
|
32
|
+
}
|
|
33
|
+
if (body instanceof ArrayBuffer) {
|
|
34
|
+
assertWithinLimit(body.byteLength, options.maxBytes);
|
|
35
|
+
return new Uint8Array(body);
|
|
36
|
+
}
|
|
37
|
+
if (isArrayBufferView(body)) {
|
|
38
|
+
assertWithinLimit(body.byteLength, options.maxBytes);
|
|
39
|
+
return new Uint8Array(body.buffer, body.byteOffset, body.byteLength);
|
|
40
|
+
}
|
|
41
|
+
if (isReadableStream(body)) {
|
|
42
|
+
const reader = body.getReader();
|
|
43
|
+
const chunks = [];
|
|
44
|
+
let size = 0;
|
|
45
|
+
while (true) {
|
|
46
|
+
const { done, value } = await reader.read();
|
|
47
|
+
if (done)
|
|
48
|
+
break;
|
|
49
|
+
size += value.byteLength;
|
|
50
|
+
assertWithinLimit(size, options.maxBytes);
|
|
51
|
+
chunks.push(value);
|
|
52
|
+
}
|
|
53
|
+
const bytes = new Uint8Array(size);
|
|
54
|
+
let offset = 0;
|
|
55
|
+
for (const chunk of chunks) {
|
|
56
|
+
bytes.set(chunk, offset);
|
|
57
|
+
offset += chunk.byteLength;
|
|
58
|
+
}
|
|
59
|
+
return bytes;
|
|
60
|
+
}
|
|
61
|
+
throw new TypeError("Unsupported Loom file body.");
|
|
62
|
+
}
|
|
63
|
+
async function sha256Hex(body) {
|
|
64
|
+
const bytes = body instanceof ArrayBuffer ? new Uint8Array(body) : body;
|
|
65
|
+
const digest = await crypto.subtle.digest("SHA-256", bytes.slice().buffer);
|
|
66
|
+
return toHex(new Uint8Array(digest));
|
|
67
|
+
}
|
|
68
|
+
function isSha256Hex(value) {
|
|
69
|
+
return /^[a-f0-9]{64}$/i.test(value);
|
|
70
|
+
}
|
|
71
|
+
function normalizeSha256Hex(value) {
|
|
72
|
+
const normalized = value.trim().toLowerCase();
|
|
73
|
+
if (!isSha256Hex(normalized)) {
|
|
74
|
+
throw new errors_js_1.LoomFileInvalidDigestError(value);
|
|
75
|
+
}
|
|
76
|
+
return normalized;
|
|
77
|
+
}
|
|
78
|
+
function assertExpectedSha256(actual, expected) {
|
|
79
|
+
if (!expected) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const normalizedExpected = normalizeSha256Hex(expected);
|
|
83
|
+
if (actual !== normalizedExpected) {
|
|
84
|
+
throw new errors_js_1.LoomFileDigestMismatchError({
|
|
85
|
+
actual,
|
|
86
|
+
expected: normalizedExpected,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { LoomFileRepository, LoomFileStorageAdapter } from "./types.js";
|
|
2
|
+
export interface CreateMemoryFileRepositoryOptions {
|
|
3
|
+
createId?: () => string;
|
|
4
|
+
now?: () => Date;
|
|
5
|
+
}
|
|
6
|
+
export interface MemoryFileStorageObject {
|
|
7
|
+
body: Uint8Array;
|
|
8
|
+
byteSize: number;
|
|
9
|
+
contentType: string | null;
|
|
10
|
+
detectedContentType: string | null;
|
|
11
|
+
metadata: Record<string, string>;
|
|
12
|
+
sha256: string;
|
|
13
|
+
}
|
|
14
|
+
export interface MemoryFileStorageAdapter extends LoomFileStorageAdapter {
|
|
15
|
+
objects: ReadonlyMap<string, MemoryFileStorageObject>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* In-memory repository for tests, examples, and non-persistent local tools.
|
|
19
|
+
*/
|
|
20
|
+
export declare function createMemoryFileRepository(options?: CreateMemoryFileRepositoryOptions): LoomFileRepository;
|
|
21
|
+
/**
|
|
22
|
+
* In-memory object storage adapter with the same contract as external storage
|
|
23
|
+
* providers. It is intentionally small and deterministic for route tests.
|
|
24
|
+
*/
|
|
25
|
+
export declare function createMemoryFileStorage(options?: {
|
|
26
|
+
bucket?: string | null;
|
|
27
|
+
provider?: string;
|
|
28
|
+
}): MemoryFileStorageAdapter;
|
|
29
|
+
//# sourceMappingURL=memory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../../src/src/files/memory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,kBAAkB,EAClB,sBAAsB,EAKvB,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,iCAAiC;IAChD,QAAQ,CAAC,EAAE,MAAM,MAAM,CAAC;IACxB,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC;CAClB;AAED,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,UAAU,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,mBAAmB,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,wBAAyB,SAAQ,sBAAsB;IACtE,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,uBAAuB,CAAC,CAAC;CACvD;AAiCD;;GAEG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,GAAE,iCAAsC,GAC9C,kBAAkB,CAuCpB;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,GAAE;IAC/C,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACd,GAAG,wBAAwB,CA0ChC"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createMemoryFileRepository = createMemoryFileRepository;
|
|
4
|
+
exports.createMemoryFileStorage = createMemoryFileStorage;
|
|
5
|
+
function defaultCreateId() {
|
|
6
|
+
return crypto.randomUUID?.() ?? `file_${Date.now().toString(36)}`;
|
|
7
|
+
}
|
|
8
|
+
function normalizeRecord(input, options) {
|
|
9
|
+
return {
|
|
10
|
+
audioMeta: input.audioMeta ?? null,
|
|
11
|
+
bucket: input.bucket ?? null,
|
|
12
|
+
byteSize: input.byteSize,
|
|
13
|
+
contentType: input.contentType ?? null,
|
|
14
|
+
createdAt: options.now,
|
|
15
|
+
deletedAt: null,
|
|
16
|
+
detectedContentType: input.detectedContentType ?? null,
|
|
17
|
+
id: options.id,
|
|
18
|
+
imageMeta: input.imageMeta ?? null,
|
|
19
|
+
kind: input.kind,
|
|
20
|
+
meta: input.meta ?? {},
|
|
21
|
+
objectKey: input.objectKey,
|
|
22
|
+
originalFilename: input.originalFilename ?? null,
|
|
23
|
+
ownerId: input.ownerId ?? null,
|
|
24
|
+
ownerType: input.ownerType ?? null,
|
|
25
|
+
sha256: input.sha256,
|
|
26
|
+
storageProvider: input.storageProvider,
|
|
27
|
+
updatedAt: options.now,
|
|
28
|
+
visibility: input.visibility ?? "private",
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* In-memory repository for tests, examples, and non-persistent local tools.
|
|
33
|
+
*/
|
|
34
|
+
function createMemoryFileRepository(options = {}) {
|
|
35
|
+
const records = new Map();
|
|
36
|
+
const sha256Index = new Map();
|
|
37
|
+
const now = options.now ?? (() => new Date());
|
|
38
|
+
const createId = options.createId ?? defaultCreateId;
|
|
39
|
+
return {
|
|
40
|
+
findById(id) {
|
|
41
|
+
return Promise.resolve(records.get(id) ?? null);
|
|
42
|
+
},
|
|
43
|
+
findBySha256(sha256) {
|
|
44
|
+
const id = sha256Index.get(sha256);
|
|
45
|
+
return Promise.resolve(id ? records.get(id) ?? null : null);
|
|
46
|
+
},
|
|
47
|
+
insert(input) {
|
|
48
|
+
if (sha256Index.has(input.sha256)) {
|
|
49
|
+
throw new Error(`Duplicate Loom file sha256: ${input.sha256}`);
|
|
50
|
+
}
|
|
51
|
+
const record = normalizeRecord(input, { id: createId(), now: now() });
|
|
52
|
+
records.set(record.id, record);
|
|
53
|
+
sha256Index.set(record.sha256, record.id);
|
|
54
|
+
return Promise.resolve(record);
|
|
55
|
+
},
|
|
56
|
+
updateVisibility(id, visibility) {
|
|
57
|
+
const record = records.get(id);
|
|
58
|
+
if (!record) {
|
|
59
|
+
throw new Error(`Unknown Loom file id: ${id}`);
|
|
60
|
+
}
|
|
61
|
+
const updated = {
|
|
62
|
+
...record,
|
|
63
|
+
updatedAt: now(),
|
|
64
|
+
visibility,
|
|
65
|
+
};
|
|
66
|
+
records.set(id, updated);
|
|
67
|
+
return Promise.resolve(updated);
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* In-memory object storage adapter with the same contract as external storage
|
|
73
|
+
* providers. It is intentionally small and deterministic for route tests.
|
|
74
|
+
*/
|
|
75
|
+
function createMemoryFileStorage(options = {}) {
|
|
76
|
+
const objects = new Map();
|
|
77
|
+
const provider = options.provider ?? "memory";
|
|
78
|
+
const bucket = options.bucket ?? null;
|
|
79
|
+
return {
|
|
80
|
+
bucket,
|
|
81
|
+
objects,
|
|
82
|
+
provider,
|
|
83
|
+
deleteObject(input) {
|
|
84
|
+
objects.delete(input.objectKey);
|
|
85
|
+
return Promise.resolve();
|
|
86
|
+
},
|
|
87
|
+
getObject(input) {
|
|
88
|
+
const object = objects.get(input.objectKey);
|
|
89
|
+
if (!object)
|
|
90
|
+
return Promise.resolve(null);
|
|
91
|
+
return Promise.resolve({
|
|
92
|
+
body: object.body.slice(),
|
|
93
|
+
byteSize: object.byteSize,
|
|
94
|
+
contentType: object.detectedContentType ?? object.contentType,
|
|
95
|
+
});
|
|
96
|
+
},
|
|
97
|
+
putObject(input) {
|
|
98
|
+
objects.set(input.objectKey, {
|
|
99
|
+
body: input.body.slice(),
|
|
100
|
+
byteSize: input.byteSize,
|
|
101
|
+
contentType: input.contentType ?? null,
|
|
102
|
+
detectedContentType: input.detectedContentType ?? null,
|
|
103
|
+
metadata: input.metadata ?? {},
|
|
104
|
+
sha256: input.sha256,
|
|
105
|
+
});
|
|
106
|
+
return Promise.resolve({
|
|
107
|
+
bucket,
|
|
108
|
+
objectKey: input.objectKey,
|
|
109
|
+
storageProvider: provider,
|
|
110
|
+
});
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { LoomFileDetectedMetadata } from "./types.js";
|
|
2
|
+
export interface DetectLoomFileMetadataOptions {
|
|
3
|
+
contentType?: string | null;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Detects a stable metadata subset without a native image-processing
|
|
7
|
+
* dependency. Apps can enrich the resulting `meta` fields in local code.
|
|
8
|
+
*/
|
|
9
|
+
export declare function detectLoomFileMetadata(bytes: Uint8Array, options?: DetectLoomFileMetadataOptions): LoomFileDetectedMetadata;
|
|
10
|
+
//# sourceMappingURL=metadata.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metadata.d.ts","sourceRoot":"","sources":["../../../src/src/files/metadata.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EAGzB,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,6BAA6B;IAC5C,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAmLD;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,UAAU,EACjB,OAAO,GAAE,6BAAkC,GAC1C,wBAAwB,CA8D1B"}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.detectLoomFileMetadata = detectLoomFileMetadata;
|
|
4
|
+
function startsWith(bytes, prefix) {
|
|
5
|
+
if (bytes.byteLength < prefix.length)
|
|
6
|
+
return false;
|
|
7
|
+
return prefix.every((byte, index) => bytes[index] === byte);
|
|
8
|
+
}
|
|
9
|
+
function ascii(bytes, start, length) {
|
|
10
|
+
if (bytes.byteLength < start + length)
|
|
11
|
+
return "";
|
|
12
|
+
return String.fromCharCode(...bytes.slice(start, start + length));
|
|
13
|
+
}
|
|
14
|
+
function readUint16Big(bytes, offset) {
|
|
15
|
+
return (bytes[offset] << 8) + bytes[offset + 1];
|
|
16
|
+
}
|
|
17
|
+
function readUint16Little(bytes, offset) {
|
|
18
|
+
return bytes[offset] + (bytes[offset + 1] << 8);
|
|
19
|
+
}
|
|
20
|
+
function readUint32Big(bytes, offset) {
|
|
21
|
+
return ((bytes[offset] * 0x1000000) +
|
|
22
|
+
((bytes[offset + 1] << 16) | (bytes[offset + 2] << 8) | bytes[offset + 3]));
|
|
23
|
+
}
|
|
24
|
+
function readUint24Little(bytes, offset) {
|
|
25
|
+
return bytes[offset] + (bytes[offset + 1] << 8) + (bytes[offset + 2] << 16);
|
|
26
|
+
}
|
|
27
|
+
function image(format, width, height) {
|
|
28
|
+
return { format, height, width };
|
|
29
|
+
}
|
|
30
|
+
function detectPng(bytes) {
|
|
31
|
+
if (!startsWith(bytes, [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]) ||
|
|
32
|
+
ascii(bytes, 12, 4) !== "IHDR" ||
|
|
33
|
+
bytes.byteLength < 24) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
return image("png", readUint32Big(bytes, 16), readUint32Big(bytes, 20));
|
|
37
|
+
}
|
|
38
|
+
function detectGif(bytes) {
|
|
39
|
+
const signature = ascii(bytes, 0, 6);
|
|
40
|
+
if ((signature !== "GIF87a" && signature !== "GIF89a") || bytes.length < 10) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
return image("gif", readUint16Little(bytes, 6), readUint16Little(bytes, 8));
|
|
44
|
+
}
|
|
45
|
+
function detectJpeg(bytes) {
|
|
46
|
+
if (!startsWith(bytes, [0xff, 0xd8])) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
let offset = 2;
|
|
50
|
+
while (offset + 8 < bytes.byteLength) {
|
|
51
|
+
if (bytes[offset] !== 0xff) {
|
|
52
|
+
offset += 1;
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
while (bytes[offset] === 0xff) {
|
|
56
|
+
offset += 1;
|
|
57
|
+
}
|
|
58
|
+
const marker = bytes[offset];
|
|
59
|
+
offset += 1;
|
|
60
|
+
if (marker === 0xd9 || marker === 0xda) {
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
if (offset + 2 > bytes.byteLength) {
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
const segmentLength = readUint16Big(bytes, offset);
|
|
67
|
+
if (segmentLength < 2 || offset + segmentLength > bytes.byteLength) {
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
const isStartOfFrame = [
|
|
71
|
+
0xc0,
|
|
72
|
+
0xc1,
|
|
73
|
+
0xc2,
|
|
74
|
+
0xc3,
|
|
75
|
+
0xc5,
|
|
76
|
+
0xc6,
|
|
77
|
+
0xc7,
|
|
78
|
+
0xc9,
|
|
79
|
+
0xca,
|
|
80
|
+
0xcb,
|
|
81
|
+
0xcd,
|
|
82
|
+
0xce,
|
|
83
|
+
0xcf,
|
|
84
|
+
].includes(marker);
|
|
85
|
+
if (isStartOfFrame && segmentLength >= 7) {
|
|
86
|
+
return image("jpeg", readUint16Big(bytes, offset + 5), readUint16Big(bytes, offset + 3));
|
|
87
|
+
}
|
|
88
|
+
offset += segmentLength;
|
|
89
|
+
}
|
|
90
|
+
return image("jpeg", 0, 0);
|
|
91
|
+
}
|
|
92
|
+
function detectWebp(bytes) {
|
|
93
|
+
if (ascii(bytes, 0, 4) !== "RIFF" || ascii(bytes, 8, 4) !== "WEBP") {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
const chunk = ascii(bytes, 12, 4);
|
|
97
|
+
if (chunk === "VP8X" && bytes.byteLength >= 30) {
|
|
98
|
+
return image("webp", readUint24Little(bytes, 24) + 1, readUint24Little(bytes, 27) + 1);
|
|
99
|
+
}
|
|
100
|
+
if (chunk === "VP8L" && bytes.byteLength >= 25 && bytes[20] === 0x2f) {
|
|
101
|
+
const b1 = bytes[21];
|
|
102
|
+
const b2 = bytes[22];
|
|
103
|
+
const b3 = bytes[23];
|
|
104
|
+
const b4 = bytes[24];
|
|
105
|
+
return image("webp", 1 + (((b2 & 0x3f) << 8) | b1), 1 + (((b4 & 0x0f) << 10) | (b3 << 2) | ((b2 & 0xc0) >> 6)));
|
|
106
|
+
}
|
|
107
|
+
if (chunk === "VP8 " && bytes.byteLength >= 30 &&
|
|
108
|
+
startsWith(bytes.slice(23), [0x9d, 0x01, 0x2a])) {
|
|
109
|
+
return image("webp", readUint16Little(bytes, 26) & 0x3fff, readUint16Little(bytes, 28) & 0x3fff);
|
|
110
|
+
}
|
|
111
|
+
return image("webp", 0, 0);
|
|
112
|
+
}
|
|
113
|
+
function kindFromContentType(contentType) {
|
|
114
|
+
if (!contentType)
|
|
115
|
+
return "other";
|
|
116
|
+
const lower = contentType.toLowerCase();
|
|
117
|
+
if (lower.startsWith("image/"))
|
|
118
|
+
return "image";
|
|
119
|
+
if (lower.startsWith("audio/"))
|
|
120
|
+
return "audio";
|
|
121
|
+
if (lower.startsWith("video/"))
|
|
122
|
+
return "video";
|
|
123
|
+
if (lower.startsWith("text/"))
|
|
124
|
+
return "text";
|
|
125
|
+
if (lower === "application/pdf")
|
|
126
|
+
return "pdf";
|
|
127
|
+
if (lower === "application/zip" ||
|
|
128
|
+
lower === "application/gzip" ||
|
|
129
|
+
lower === "application/x-tar") {
|
|
130
|
+
return "archive";
|
|
131
|
+
}
|
|
132
|
+
return "other";
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Detects a stable metadata subset without a native image-processing
|
|
136
|
+
* dependency. Apps can enrich the resulting `meta` fields in local code.
|
|
137
|
+
*/
|
|
138
|
+
function detectLoomFileMetadata(bytes, options = {}) {
|
|
139
|
+
const imageMeta = detectPng(bytes) ?? detectJpeg(bytes) ?? detectGif(bytes) ??
|
|
140
|
+
detectWebp(bytes);
|
|
141
|
+
if (imageMeta) {
|
|
142
|
+
return {
|
|
143
|
+
detectedContentType: `image/${imageMeta.format === "jpeg" ? "jpeg" : imageMeta.format}`,
|
|
144
|
+
imageMeta,
|
|
145
|
+
kind: "image",
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
if (startsWith(bytes, [0x25, 0x50, 0x44, 0x46, 0x2d])) {
|
|
149
|
+
return {
|
|
150
|
+
detectedContentType: "application/pdf",
|
|
151
|
+
imageMeta: null,
|
|
152
|
+
kind: "pdf",
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
if (startsWith(bytes, [0x49, 0x44, 0x33]) || startsWith(bytes, [0xff, 0xfb])) {
|
|
156
|
+
return {
|
|
157
|
+
detectedContentType: "audio/mpeg",
|
|
158
|
+
imageMeta: null,
|
|
159
|
+
kind: "audio",
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
if (ascii(bytes, 0, 4) === "RIFF" && ascii(bytes, 8, 4) === "WAVE") {
|
|
163
|
+
return { detectedContentType: "audio/wav", imageMeta: null, kind: "audio" };
|
|
164
|
+
}
|
|
165
|
+
if (ascii(bytes, 0, 4) === "OggS") {
|
|
166
|
+
return {
|
|
167
|
+
detectedContentType: "application/ogg",
|
|
168
|
+
imageMeta: null,
|
|
169
|
+
kind: "audio",
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
if (ascii(bytes, 4, 4) === "ftyp") {
|
|
173
|
+
return { detectedContentType: "video/mp4", imageMeta: null, kind: "video" };
|
|
174
|
+
}
|
|
175
|
+
if (startsWith(bytes, [0x50, 0x4b, 0x03, 0x04])) {
|
|
176
|
+
return {
|
|
177
|
+
detectedContentType: "application/zip",
|
|
178
|
+
imageMeta: null,
|
|
179
|
+
kind: "archive",
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
const suppliedContentType = options.contentType?.split(";")[0]?.trim()
|
|
183
|
+
.toLowerCase() || null;
|
|
184
|
+
return {
|
|
185
|
+
detectedContentType: null,
|
|
186
|
+
imageMeta: null,
|
|
187
|
+
kind: kindFromContentType(suppliedContentType),
|
|
188
|
+
};
|
|
189
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import "../../_dnt.polyfills.js";
|
|
2
|
+
export * from "./client.js";
|
|
3
|
+
export * from "./errors.js";
|
|
4
|
+
export * from "./hash.js";
|
|
5
|
+
export * from "./memory.js";
|
|
6
|
+
export * from "./metadata.js";
|
|
7
|
+
export * from "./s3.js";
|
|
8
|
+
export * from "./service.js";
|
|
9
|
+
export * from "./types.js";
|
|
10
|
+
//# sourceMappingURL=mod.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/src/files/mod.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
require("../../_dnt.polyfills.js");
|
|
18
|
+
__exportStar(require("./client.js"), exports);
|
|
19
|
+
__exportStar(require("./errors.js"), exports);
|
|
20
|
+
__exportStar(require("./hash.js"), exports);
|
|
21
|
+
__exportStar(require("./memory.js"), exports);
|
|
22
|
+
__exportStar(require("./metadata.js"), exports);
|
|
23
|
+
__exportStar(require("./s3.js"), exports);
|
|
24
|
+
__exportStar(require("./service.js"), exports);
|
|
25
|
+
__exportStar(require("./types.js"), exports);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { LoomFileStorageAdapter } from "./types.js";
|
|
2
|
+
export interface S3LikeClient {
|
|
3
|
+
send(command: unknown): Promise<Record<string, unknown>>;
|
|
4
|
+
}
|
|
5
|
+
export type S3CommandConstructor = new (input: any) => unknown;
|
|
6
|
+
export interface S3StorageCommands {
|
|
7
|
+
DeleteObjectCommand?: S3CommandConstructor;
|
|
8
|
+
GetObjectCommand: S3CommandConstructor;
|
|
9
|
+
PutObjectCommand: S3CommandConstructor;
|
|
10
|
+
}
|
|
11
|
+
export interface CreateS3FileStorageOptions {
|
|
12
|
+
bucket: string;
|
|
13
|
+
client: S3LikeClient;
|
|
14
|
+
commands: S3StorageCommands;
|
|
15
|
+
keyPrefix?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Sends conditional writes with `IfNoneMatch: "*"`. Use this with
|
|
18
|
+
* content-addressed keys when overwriting an existing object would hide a
|
|
19
|
+
* duplicate-upload bug.
|
|
20
|
+
*/
|
|
21
|
+
preventOverwrite?: boolean;
|
|
22
|
+
provider?: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Creates an S3-compatible storage adapter without making AWS SDK v3 a Loom
|
|
26
|
+
* dependency. Consumers pass their own client and command constructors.
|
|
27
|
+
*/
|
|
28
|
+
export declare function createS3FileStorage(options: CreateS3FileStorageOptions): LoomFileStorageAdapter;
|
|
29
|
+
//# sourceMappingURL=s3.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"s3.d.ts","sourceRoot":"","sources":["../../../src/src/files/s3.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,sBAAsB,EAKvB,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CAC1D;AAED,MAAM,MAAM,oBAAoB,GAAG,KACjC,KAAK,EAAE,GAAG,KACP,OAAO,CAAC;AAEb,MAAM,WAAW,iBAAiB;IAChC,mBAAmB,CAAC,EAAE,oBAAoB,CAAC;IAC3C,gBAAgB,EAAE,oBAAoB,CAAC;IACvC,gBAAgB,EAAE,oBAAoB,CAAC;CACxC;AAED,MAAM,WAAW,0BAA0B;IACzC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,YAAY,CAAC;IACrB,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAkED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,0BAA0B,GAClC,sBAAsB,CAuExB"}
|