@krak-stack/assets 0.1.4 → 0.1.6
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 +67 -0
- package/README.md +174 -20
- package/dist/access.d.ts +44 -0
- package/dist/access.d.ts.map +1 -0
- package/dist/access.js +56 -0
- package/dist/access.js.map +1 -0
- package/dist/api.builder.d.ts +100 -0
- package/dist/api.builder.d.ts.map +1 -0
- package/dist/api.builder.js +233 -0
- package/dist/api.builder.js.map +1 -0
- package/dist/api.d.ts +2 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.group.d.ts +222 -0
- package/dist/api.group.d.ts.map +1 -0
- package/dist/api.group.js +83 -0
- package/dist/api.group.js.map +1 -0
- package/dist/api.js +2 -0
- package/dist/api.js.map +1 -0
- package/dist/catalog.d.ts +91 -0
- package/dist/catalog.d.ts.map +1 -0
- package/dist/catalog.js +52 -0
- package/dist/catalog.js.map +1 -0
- package/dist/client.d.ts +245 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +8 -0
- package/dist/client.js.map +1 -0
- package/dist/commands.d.ts +55 -0
- package/dist/commands.d.ts.map +1 -0
- package/dist/commands.js +127 -0
- package/dist/commands.js.map +1 -0
- package/dist/components/asset-input/html.d.ts +70 -0
- package/dist/components/asset-input/html.d.ts.map +1 -0
- package/dist/components/asset-input/html.js +1549 -0
- package/dist/components/asset-input/html.js.map +1 -0
- package/dist/components/asset-input/index.d.ts +280 -0
- package/dist/components/asset-input/react.d.ts +32 -0
- package/dist/components/asset-input/react.d.ts.map +1 -0
- package/dist/components/asset-input/react.js +2269 -0
- package/dist/components/asset-input/react.js.map +1 -0
- package/dist/components/asset-input/schema.d.ts +93 -0
- package/dist/components/asset-input/upload.d.ts +15 -0
- package/dist/components/asset-table/html.d.ts +110 -0
- package/dist/components/asset-table/html.d.ts.map +1 -0
- package/dist/components/asset-table/html.js +4934 -0
- package/dist/components/asset-table/html.js.map +1 -0
- package/dist/components/asset-table/index.d.ts +225 -0
- package/dist/components/asset-table/react.d.ts +21 -0
- package/dist/components/asset-table/react.d.ts.map +1 -0
- package/dist/components/asset-table/react.js +8241 -0
- package/dist/components/asset-table/react.js.map +1 -0
- package/dist/components/asset-table/schema.d.ts +73 -0
- package/dist/index.d.ts +215 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +49 -24
- package/dist/index.js.map +1 -1
- package/dist/migrations/0004_upload_intents.d.ts +5 -0
- package/dist/migrations/0004_upload_intents.d.ts.map +1 -0
- package/dist/migrations/0004_upload_intents.js +14 -0
- package/dist/migrations/0004_upload_intents.js.map +1 -0
- package/dist/migrations.d.ts.map +1 -1
- package/dist/migrations.js +2 -0
- package/dist/migrations.js.map +1 -1
- package/dist/queries.d.ts +6 -0
- package/dist/queries.d.ts.map +1 -0
- package/dist/queries.js +18 -0
- package/dist/queries.js.map +1 -0
- package/dist/retrieval.d.ts +6 -1
- package/dist/retrieval.d.ts.map +1 -1
- package/dist/retrieval.js +48 -17
- package/dist/retrieval.js.map +1 -1
- package/dist/schema.d.ts +116 -1
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +88 -1
- package/dist/schema.js.map +1 -1
- package/dist/services/assets/library.d.ts +221 -0
- package/dist/services/assets/library.d.ts.map +1 -0
- package/dist/services/assets/library.js +101 -0
- package/dist/services/assets/library.js.map +1 -0
- package/dist/services/assets/schema.d.ts +3 -0
- package/dist/services/assets/url.d.ts +12 -0
- package/dist/services/assets/use-library.d.ts +20 -0
- package/dist/workflows.d.ts +2 -0
- package/dist/workflows.d.ts.map +1 -1
- package/dist/workflows.js +2 -0
- package/dist/workflows.js.map +1 -1
- package/package.json +43 -7
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { type SqlClient } from "effect/sql";
|
|
3
|
+
export declare const makeAssetCatalog: (sql: SqlClient.SqlClient) => {
|
|
4
|
+
list: (request: {
|
|
5
|
+
readonly organizationId: string;
|
|
6
|
+
readonly search?: string | undefined;
|
|
7
|
+
readonly kind?: "caption" | "document" | "image" | "video" | undefined;
|
|
8
|
+
}) => Effect.Effect<{
|
|
9
|
+
readonly id: string;
|
|
10
|
+
readonly organizationId: string;
|
|
11
|
+
readonly name: string;
|
|
12
|
+
readonly mimeType: string;
|
|
13
|
+
readonly byteSize: number;
|
|
14
|
+
readonly checksum: string;
|
|
15
|
+
readonly metadata: {
|
|
16
|
+
readonly [x: string]: unknown;
|
|
17
|
+
};
|
|
18
|
+
readonly createdBy: string;
|
|
19
|
+
readonly createdAt: Date;
|
|
20
|
+
readonly updatedAt: Date;
|
|
21
|
+
readonly objectKey: string;
|
|
22
|
+
}[], import("effect/Schema").SchemaError | import("effect/sql/SqlError").SqlError, never>;
|
|
23
|
+
query: (request: {
|
|
24
|
+
readonly organizationId: string;
|
|
25
|
+
readonly search?: string | undefined;
|
|
26
|
+
readonly kind?: "caption" | "document" | "image" | "video" | undefined;
|
|
27
|
+
}) => Effect.Effect<{
|
|
28
|
+
items: {
|
|
29
|
+
readonly id: string;
|
|
30
|
+
readonly organizationId: string;
|
|
31
|
+
readonly name: string;
|
|
32
|
+
readonly mimeType: string;
|
|
33
|
+
readonly byteSize: number;
|
|
34
|
+
readonly checksum: string;
|
|
35
|
+
readonly metadata: {
|
|
36
|
+
readonly [x: string]: unknown;
|
|
37
|
+
};
|
|
38
|
+
readonly createdBy: string;
|
|
39
|
+
readonly createdAt: Date;
|
|
40
|
+
readonly updatedAt: Date;
|
|
41
|
+
readonly objectKey: string;
|
|
42
|
+
}[];
|
|
43
|
+
stats: {
|
|
44
|
+
readonly assetCount: number;
|
|
45
|
+
readonly storageUsedBytes: number;
|
|
46
|
+
};
|
|
47
|
+
}, import("effect/Cause").NoSuchElementError | import("effect/Schema").SchemaError | import("effect/sql/SqlError").SqlError, never>;
|
|
48
|
+
stats: (request: {
|
|
49
|
+
readonly organizationId: string;
|
|
50
|
+
}) => Effect.Effect<{
|
|
51
|
+
readonly assetCount: number;
|
|
52
|
+
readonly storageUsedBytes: number;
|
|
53
|
+
}, import("effect/Cause").NoSuchElementError | import("effect/Schema").SchemaError | import("effect/sql/SqlError").SqlError, never>;
|
|
54
|
+
readAsset: (request: {
|
|
55
|
+
readonly assetId: string;
|
|
56
|
+
readonly organizationId: string;
|
|
57
|
+
}) => Effect.Effect<import("effect/Option").Option<{
|
|
58
|
+
readonly id: string;
|
|
59
|
+
readonly organizationId: string;
|
|
60
|
+
readonly name: string;
|
|
61
|
+
readonly mimeType: string;
|
|
62
|
+
readonly byteSize: number;
|
|
63
|
+
readonly checksum: string;
|
|
64
|
+
readonly metadata: {
|
|
65
|
+
readonly [x: string]: unknown;
|
|
66
|
+
};
|
|
67
|
+
readonly createdBy: string;
|
|
68
|
+
readonly createdAt: Date;
|
|
69
|
+
readonly updatedAt: Date;
|
|
70
|
+
readonly objectKey: string;
|
|
71
|
+
}>, import("effect/Schema").SchemaError | import("effect/sql/SqlError").SqlError, never>;
|
|
72
|
+
lockAsset: (request: {
|
|
73
|
+
readonly assetId: string;
|
|
74
|
+
readonly organizationId: string;
|
|
75
|
+
}) => Effect.Effect<import("effect/Option").Option<{
|
|
76
|
+
readonly id: string;
|
|
77
|
+
readonly organizationId: string;
|
|
78
|
+
readonly name: string;
|
|
79
|
+
readonly mimeType: string;
|
|
80
|
+
readonly byteSize: number;
|
|
81
|
+
readonly checksum: string;
|
|
82
|
+
readonly metadata: {
|
|
83
|
+
readonly [x: string]: unknown;
|
|
84
|
+
};
|
|
85
|
+
readonly createdBy: string;
|
|
86
|
+
readonly createdAt: Date;
|
|
87
|
+
readonly updatedAt: Date;
|
|
88
|
+
readonly objectKey: string;
|
|
89
|
+
}>, import("effect/Schema").SchemaError | import("effect/sql/SqlError").SqlError, never>;
|
|
90
|
+
};
|
|
91
|
+
//# sourceMappingURL=catalog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../src/catalog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAa,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AASvD,eAAO,MAAM,gBAAgB,QAAS,SAAS,CAAC,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyDxD,CAAC"}
|
package/dist/catalog.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { SqlSchema } from "effect/sql";
|
|
3
|
+
import { AssetListRequestSchema, AssetOrganizationRequestSchema, AssetRequestSchema, AssetRowSchema, AssetStatsSchema, } from "./schema.js";
|
|
4
|
+
export const makeAssetCatalog = (sql) => {
|
|
5
|
+
const listFilter = ({ search, kind }) => {
|
|
6
|
+
const name = search?.trim().toLowerCase();
|
|
7
|
+
const category = kind
|
|
8
|
+
? sql `AND CASE
|
|
9
|
+
WHEN lower(mime_type) LIKE 'image/%' THEN 'image'
|
|
10
|
+
WHEN lower(mime_type) LIKE 'video/%' THEN 'video'
|
|
11
|
+
WHEN lower(trim(split_part(mime_type, ';', 1))) = 'text/vtt' THEN 'caption'
|
|
12
|
+
ELSE 'document'
|
|
13
|
+
END = ${kind}`
|
|
14
|
+
: sql ``;
|
|
15
|
+
return sql `TRUE
|
|
16
|
+
${name ? sql `AND strpos(lower(name), ${name}) > 0` : sql ``}
|
|
17
|
+
${category}`;
|
|
18
|
+
};
|
|
19
|
+
const aggregates = sql `count(*)::double precision AS asset_count,
|
|
20
|
+
coalesce(sum(byte_size), 0)::double precision AS storage_used_bytes`;
|
|
21
|
+
const list = SqlSchema.findAll({
|
|
22
|
+
Request: AssetListRequestSchema,
|
|
23
|
+
Result: AssetRowSchema,
|
|
24
|
+
execute: (request) => sql `SELECT * FROM assets
|
|
25
|
+
WHERE organization_id = ${request.organizationId} AND ${listFilter(request)}
|
|
26
|
+
ORDER BY updated_at DESC, id DESC`,
|
|
27
|
+
});
|
|
28
|
+
const findAsset = (lock) => SqlSchema.findOneOption({
|
|
29
|
+
Request: AssetRequestSchema,
|
|
30
|
+
Result: AssetRowSchema,
|
|
31
|
+
execute: ({ organizationId, assetId }) => sql `SELECT * FROM assets WHERE id = ${assetId} AND organization_id = ${organizationId} ${lock ? sql `FOR UPDATE` : sql ``}`,
|
|
32
|
+
});
|
|
33
|
+
const stats = SqlSchema.findOne({
|
|
34
|
+
Request: AssetOrganizationRequestSchema,
|
|
35
|
+
Result: AssetStatsSchema,
|
|
36
|
+
execute: ({ organizationId }) => sql `SELECT ${aggregates}
|
|
37
|
+
FROM assets WHERE organization_id = ${organizationId}`,
|
|
38
|
+
});
|
|
39
|
+
const query = Effect.fn("Assets.query")(function* (request) {
|
|
40
|
+
const items = yield* list(request);
|
|
41
|
+
const summary = yield* stats({ organizationId: request.organizationId });
|
|
42
|
+
return { items, stats: summary };
|
|
43
|
+
});
|
|
44
|
+
return {
|
|
45
|
+
list,
|
|
46
|
+
query,
|
|
47
|
+
stats,
|
|
48
|
+
readAsset: findAsset(false),
|
|
49
|
+
lockAsset: findAsset(true),
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=catalog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"catalog.js","sourceRoot":"","sources":["../src/catalog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,SAAS,EAAkB,MAAM,YAAY,CAAC;AACvD,OAAO,EACL,sBAAsB,EACtB,8BAA8B,EAC9B,kBAAkB,EAClB,cAAc,EACd,gBAAgB,GACjB,MAAM,aAAa,CAAC;AAErB,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,GAAwB,EAAE,EAAE;IAC3D,MAAM,UAAU,GAAG,CAAC,EAAE,MAAM,EAAE,IAAI,EAAsC,EAAE,EAAE;QAC1E,MAAM,IAAI,GAAG,MAAM,EAAE,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;QAC1C,MAAM,QAAQ,GAAG,IAAI;YACnB,CAAC,CAAC,GAAG,CAAA;;;;;gBAKK,IAAI,EAAE;YAChB,CAAC,CAAC,GAAG,CAAA,EAAE,CAAC;QACV,OAAO,GAAG,CAAA;QACN,IAAI,CAAC,CAAC,CAAC,GAAG,CAAA,2BAA2B,IAAI,OAAO,CAAC,CAAC,CAAC,GAAG,CAAA,EAAE;QACxD,QAAQ,EAAE,CAAC;IACjB,CAAC,CAAC;IACF,MAAM,UAAU,GAAG,GAAG,CAAA;wEACgD,CAAC;IACvE,MAAM,IAAI,GAAG,SAAS,CAAC,OAAO,CAAC;QAC7B,OAAO,EAAE,sBAAsB;QAC/B,MAAM,EAAE,cAAc;QACtB,OAAO,EAAE,CAAC,OAAO,EAAE,EAAE,CACnB,GAAG,CAAA;kCACyB,OAAO,CAAC,cAAc,QAAQ,UAAU,CAAC,OAAO,CAAC;4CACvC;KACzC,CAAC,CAAC;IAEH,MAAM,SAAS,GAAG,CAAC,IAAa,EAAE,EAAE,CAClC,SAAS,CAAC,aAAa,CAAC;QACtB,OAAO,EAAE,kBAAkB;QAC3B,MAAM,EAAE,cAAc;QACtB,OAAO,EAAE,CAAC,EAAE,cAAc,EAAE,OAAO,EAAE,EAAE,EAAE,CACvC,GAAG,CAAA,mCAAmC,OAAO,0BAA0B,cAAc,IAAI,IAAI,CAAC,CAAC,CAAC,GAAG,CAAA,YAAY,CAAC,CAAC,CAAC,GAAG,CAAA,EAAE,EAAE;KAC5H,CAAC,CAAC;IAEL,MAAM,KAAK,GAAG,SAAS,CAAC,OAAO,CAAC;QAC9B,OAAO,EAAE,8BAA8B;QACvC,MAAM,EAAE,gBAAgB;QACxB,OAAO,EAAE,CAAC,EAAE,cAAc,EAAE,EAAE,EAAE,CAC9B,GAAG,CAAA,UAAU,UAAU;gDACmB,cAAc,EAAE;KAC7D,CAAC,CAAC;IAEH,MAAM,KAAK,GAAG,MAAM,CAAC,EAAE,CAAC,cAAc,CAAC,CAAC,QAAQ,CAAC,EAC/C,OAA2C;QAE3C,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACnC,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,KAAK,CAAC,EAAE,cAAc,EAAE,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;QACzE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;IACnC,CAAC,CAAC,CAAC;IAEH,OAAO;QACL,IAAI;QACJ,KAAK;QACL,KAAK;QACL,SAAS,EAAE,SAAS,CAAC,KAAK,CAAC;QAC3B,SAAS,EAAE,SAAS,CAAC,IAAI,CAAC;KAC3B,CAAC;AACJ,CAAC,CAAC"}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { Context, Layer, type Effect } from "effect";
|
|
2
|
+
import { HttpApiClient } from "effect/http-api";
|
|
3
|
+
export declare const makeAssetsClient: (options?: Parameters<typeof HttpApiClient.make>[1]) => Effect.Effect<{
|
|
4
|
+
readonly assets: {
|
|
5
|
+
readonly completeAssetUpload: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"completeAssetUpload", "POST", "/api/assets/:assetId/complete", import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
|
|
6
|
+
readonly assetId: import("effect/Schema").String;
|
|
7
|
+
}>>, import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
|
|
8
|
+
readonly attemptId: import("effect/Schema").optionalKey<import("effect/Schema").String>;
|
|
9
|
+
}>>, never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
|
|
10
|
+
readonly attemptId: import("effect/Schema").optionalKey<import("effect/Schema").String>;
|
|
11
|
+
readonly assetId: import("effect/Schema").String;
|
|
12
|
+
readonly uploadStatus: import("effect/Schema").Literals<readonly ["pending", "published", "rejected", "unscannable", "invalid", "failed"]>;
|
|
13
|
+
}>>, import("effect/Schema").toCodecJson<typeof import("effect/http-api/HttpApiError").Unauthorized | typeof import("effect/http-api/HttpApiError").Forbidden | typeof import("effect/http-api/HttpApiError").InternalServerError | typeof import("./schema.js").AssetNotFound | typeof import("./schema.js").AssetUploadInvalid>, never, never>, never, never>;
|
|
14
|
+
readonly createAssetUpload: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"createAssetUpload", "POST", "/api/assets", never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
|
|
15
|
+
readonly name: import("effect/Schema").NonEmptyString;
|
|
16
|
+
readonly mimeType: import("effect/Schema").NonEmptyString;
|
|
17
|
+
readonly byteSize: import("effect/Schema").Int;
|
|
18
|
+
readonly checksum: import("effect/Schema").NonEmptyString;
|
|
19
|
+
readonly assetId: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
20
|
+
}>>, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
|
|
21
|
+
readonly attemptId: import("effect/Schema").optionalKey<import("effect/Schema").String>;
|
|
22
|
+
readonly assetId: import("effect/Schema").String;
|
|
23
|
+
readonly uploadUrl: import("effect/Schema").String;
|
|
24
|
+
readonly contentType: import("effect/Schema").NonEmptyString;
|
|
25
|
+
}>>, import("effect/Schema").toCodecJson<typeof import("effect/http-api/HttpApiError").Unauthorized | typeof import("effect/http-api/HttpApiError").Forbidden | typeof import("effect/http-api/HttpApiError").InternalServerError | typeof import("./schema.js").AssetNotFound | typeof import("./schema.js").AssetUploadInvalid>, never, never>, never, never>;
|
|
26
|
+
readonly deleteAssets: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"deleteAssets", "DELETE", "/api/assets", never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
|
|
27
|
+
readonly ids: import("effect/Schema").$Array<import("effect/Schema").String>;
|
|
28
|
+
}>>, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
|
|
29
|
+
readonly deletedIds: import("effect/Schema").$Array<import("effect/Schema").String>;
|
|
30
|
+
readonly failures: import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
31
|
+
readonly id: import("effect/Schema").String;
|
|
32
|
+
readonly reason: import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"not_found">, import("effect/Schema").Literal<"in_use">]>;
|
|
33
|
+
}>>;
|
|
34
|
+
}>>, import("effect/Schema").toCodecJson<typeof import("effect/http-api/HttpApiError").Unauthorized | typeof import("effect/http-api/HttpApiError").Forbidden | typeof import("effect/http-api/HttpApiError").InternalServerError>, never, never>, never, never>;
|
|
35
|
+
readonly file: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"file", "GET", "/api/assets/:assetId/file", import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
|
|
36
|
+
readonly assetId: import("effect/Schema").String;
|
|
37
|
+
}>>, import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
|
|
38
|
+
readonly download: import("effect/Schema").optionalKey<import("effect/Schema").Literal<"1">>;
|
|
39
|
+
readonly v: import("effect/Schema").optionalKey<import("effect/Schema").String>;
|
|
40
|
+
}>>, never, never, import("effect/http-api/HttpApiSchema").StreamUint8Array | import("effect/Schema").toCodecJson<import("effect/Schema").Void>, import("effect/Schema").toCodecJson<typeof import("effect/http-api/HttpApiError").Unauthorized | typeof import("effect/http-api/HttpApiError").Forbidden | typeof import("effect/http-api/HttpApiError").InternalServerError | typeof import("./schema.js").AssetNotFound>, never, never>, never, never>;
|
|
41
|
+
readonly getAsset: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"getAsset", "GET", "/api/assets/:assetId", import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
|
|
42
|
+
readonly assetId: import("effect/Schema").String;
|
|
43
|
+
}>>, import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
|
|
44
|
+
readonly attemptId: import("effect/Schema").optionalKey<import("effect/Schema").String>;
|
|
45
|
+
readonly outlineOffset: import("effect/Schema").optionalKey<import("effect/Schema").Int>;
|
|
46
|
+
}>>, never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Union<readonly [import("effect/Schema").Struct<{
|
|
47
|
+
readonly id: import("effect/Schema").String;
|
|
48
|
+
readonly name: import("effect/Schema").String;
|
|
49
|
+
readonly mimeType: import("effect/Schema").String;
|
|
50
|
+
readonly status: import("effect/Schema").Literals<readonly ["pending", "running", "completed", "failed", "unsupported"]>;
|
|
51
|
+
readonly totalBytes: import("effect/Schema").Int;
|
|
52
|
+
readonly totalChunks: import("effect/Schema").Int;
|
|
53
|
+
readonly failure: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
54
|
+
readonly outline: import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
55
|
+
readonly headingPath: import("effect/Schema").String;
|
|
56
|
+
readonly firstOrdinal: import("effect/Schema").Int;
|
|
57
|
+
readonly lastOrdinal: import("effect/Schema").Int;
|
|
58
|
+
}>>;
|
|
59
|
+
readonly nextOutlineOffset: import("effect/Schema").NullOr<import("effect/Schema").Int>;
|
|
60
|
+
readonly url: import("effect/Schema").String;
|
|
61
|
+
}>, import("effect/Schema").Struct<{
|
|
62
|
+
readonly attemptId: import("effect/Schema").optionalKey<import("effect/Schema").String>;
|
|
63
|
+
readonly assetId: import("effect/Schema").String;
|
|
64
|
+
readonly uploadStatus: import("effect/Schema").Literals<readonly ["pending", "published", "rejected", "unscannable", "invalid", "failed"]>;
|
|
65
|
+
}>]>>, import("effect/Schema").toCodecJson<typeof import("effect/http-api/HttpApiError").Unauthorized | typeof import("effect/http-api/HttpApiError").Forbidden | typeof import("effect/http-api/HttpApiError").InternalServerError | typeof import("./schema.js").AssetNotFound>, never, never>, never, never>;
|
|
66
|
+
readonly getAssetChunks: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"getAssetChunks", "GET", "/api/assets/:assetId/chunks", import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
|
|
67
|
+
readonly assetId: import("effect/Schema").String;
|
|
68
|
+
}>>, import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
|
|
69
|
+
readonly query: import("effect/Schema").optionalKey<import("effect/Schema").NonEmptyString>;
|
|
70
|
+
readonly language: import("effect/Schema").optionalKey<import("effect/Schema").Literals<readonly ["en", "fr"]>>;
|
|
71
|
+
readonly offset: import("effect/Schema").optionalKey<import("effect/Schema").Int>;
|
|
72
|
+
readonly headingPath: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
73
|
+
readonly ids: import("effect/Schema").optionalKey<import("effect/Schema").$Array<import("effect/Schema").String>>;
|
|
74
|
+
readonly includeNeighbors: import("effect/Schema").optional<import("effect/Schema").Boolean>;
|
|
75
|
+
}>>, never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Union<readonly [import("effect/Schema").Struct<{
|
|
76
|
+
readonly assetId: import("effect/Schema").String;
|
|
77
|
+
readonly nextOffset: import("effect/Schema").NullOr<import("effect/Schema").Int>;
|
|
78
|
+
readonly hits: import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
79
|
+
readonly id: import("effect/Schema").String;
|
|
80
|
+
readonly ordinal: import("effect/Schema").Int;
|
|
81
|
+
readonly headingPath: import("effect/Schema").String;
|
|
82
|
+
readonly byteStart: import("effect/Schema").Int;
|
|
83
|
+
readonly byteEnd: import("effect/Schema").Int;
|
|
84
|
+
readonly firstPage: import("effect/Schema").NullOr<import("effect/Schema").Int>;
|
|
85
|
+
readonly lastPage: import("effect/Schema").NullOr<import("effect/Schema").Int>;
|
|
86
|
+
readonly snippet: import("effect/Schema").String;
|
|
87
|
+
readonly score: import("effect/Schema").Finite;
|
|
88
|
+
}>>;
|
|
89
|
+
}>, import("effect/Schema").Struct<{
|
|
90
|
+
readonly assetId: import("effect/Schema").String;
|
|
91
|
+
readonly chunks: import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
92
|
+
readonly ordinal: import("effect/Schema").Int;
|
|
93
|
+
readonly content: import("effect/Schema").NonEmptyString;
|
|
94
|
+
readonly headingPath: import("effect/Schema").String;
|
|
95
|
+
readonly byteStart: import("effect/Schema").Int;
|
|
96
|
+
readonly byteEnd: import("effect/Schema").Int;
|
|
97
|
+
readonly firstPage: import("effect/Schema").NullOr<import("effect/Schema").Int>;
|
|
98
|
+
readonly lastPage: import("effect/Schema").NullOr<import("effect/Schema").Int>;
|
|
99
|
+
readonly id: import("effect/Schema").String;
|
|
100
|
+
}>>;
|
|
101
|
+
}>]>>, import("effect/Schema").toCodecJson<typeof import("effect/http-api/HttpApiError").Unauthorized | typeof import("effect/http-api/HttpApiError").Forbidden | typeof import("effect/http-api/HttpApiError").InternalServerError | typeof import("./schema.js").AssetTextChunkInvalid | typeof import("./schema.js").AssetTextVersionChanged | typeof import("./schema.js").AssetNotFound>, never, never>, never, never>;
|
|
102
|
+
readonly list: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"list", "GET", "/api/assets", never, import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
|
|
103
|
+
readonly search: import("effect/Schema").optionalKey<import("effect/Schema").String>;
|
|
104
|
+
readonly kind: import("effect/Schema").optionalKey<import("effect/Schema").Literals<readonly ["image", "video", "caption", "document"]>>;
|
|
105
|
+
}>>, never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
|
|
106
|
+
readonly items: import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
107
|
+
readonly id: import("effect/Schema").String;
|
|
108
|
+
readonly name: import("effect/Schema").NonEmptyString;
|
|
109
|
+
readonly mimeType: import("effect/Schema").NonEmptyString;
|
|
110
|
+
readonly byteSize: import("effect/Schema").Int;
|
|
111
|
+
readonly createdAt: import("effect/Schema").Date;
|
|
112
|
+
readonly updatedAt: import("effect/Schema").Date;
|
|
113
|
+
readonly url: import("effect/Schema").optionalKey<import("effect/Schema").String>;
|
|
114
|
+
}>>;
|
|
115
|
+
readonly stats: import("effect/Schema").Struct<{
|
|
116
|
+
readonly assetCount: import("effect/Schema").Int;
|
|
117
|
+
readonly storageUsedBytes: import("effect/Schema").Int;
|
|
118
|
+
}>;
|
|
119
|
+
}>>, import("effect/Schema").toCodecJson<typeof import("effect/http-api/HttpApiError").Unauthorized | typeof import("effect/http-api/HttpApiError").Forbidden | typeof import("effect/http-api/HttpApiError").InternalServerError>, never, never>, never, never>;
|
|
120
|
+
};
|
|
121
|
+
}, never, import("effect/http/HttpClient").HttpClient>;
|
|
122
|
+
declare const AssetsClient_base: Context.ServiceClass<AssetsClient, "@krak-stack/assets/AssetsClient", {
|
|
123
|
+
readonly assets: {
|
|
124
|
+
readonly completeAssetUpload: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"completeAssetUpload", "POST", "/api/assets/:assetId/complete", import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
|
|
125
|
+
readonly assetId: import("effect/Schema").String;
|
|
126
|
+
}>>, import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
|
|
127
|
+
readonly attemptId: import("effect/Schema").optionalKey<import("effect/Schema").String>;
|
|
128
|
+
}>>, never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
|
|
129
|
+
readonly attemptId: import("effect/Schema").optionalKey<import("effect/Schema").String>;
|
|
130
|
+
readonly assetId: import("effect/Schema").String;
|
|
131
|
+
readonly uploadStatus: import("effect/Schema").Literals<readonly ["pending", "published", "rejected", "unscannable", "invalid", "failed"]>;
|
|
132
|
+
}>>, import("effect/Schema").toCodecJson<typeof import("effect/http-api/HttpApiError").Unauthorized | typeof import("effect/http-api/HttpApiError").Forbidden | typeof import("effect/http-api/HttpApiError").InternalServerError | typeof import("./schema.js").AssetNotFound | typeof import("./schema.js").AssetUploadInvalid>, never, never>, never, never>;
|
|
133
|
+
readonly createAssetUpload: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"createAssetUpload", "POST", "/api/assets", never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
|
|
134
|
+
readonly name: import("effect/Schema").NonEmptyString;
|
|
135
|
+
readonly mimeType: import("effect/Schema").NonEmptyString;
|
|
136
|
+
readonly byteSize: import("effect/Schema").Int;
|
|
137
|
+
readonly checksum: import("effect/Schema").NonEmptyString;
|
|
138
|
+
readonly assetId: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
139
|
+
}>>, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
|
|
140
|
+
readonly attemptId: import("effect/Schema").optionalKey<import("effect/Schema").String>;
|
|
141
|
+
readonly assetId: import("effect/Schema").String;
|
|
142
|
+
readonly uploadUrl: import("effect/Schema").String;
|
|
143
|
+
readonly contentType: import("effect/Schema").NonEmptyString;
|
|
144
|
+
}>>, import("effect/Schema").toCodecJson<typeof import("effect/http-api/HttpApiError").Unauthorized | typeof import("effect/http-api/HttpApiError").Forbidden | typeof import("effect/http-api/HttpApiError").InternalServerError | typeof import("./schema.js").AssetNotFound | typeof import("./schema.js").AssetUploadInvalid>, never, never>, never, never>;
|
|
145
|
+
readonly deleteAssets: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"deleteAssets", "DELETE", "/api/assets", never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
|
|
146
|
+
readonly ids: import("effect/Schema").$Array<import("effect/Schema").String>;
|
|
147
|
+
}>>, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
|
|
148
|
+
readonly deletedIds: import("effect/Schema").$Array<import("effect/Schema").String>;
|
|
149
|
+
readonly failures: import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
150
|
+
readonly id: import("effect/Schema").String;
|
|
151
|
+
readonly reason: import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"not_found">, import("effect/Schema").Literal<"in_use">]>;
|
|
152
|
+
}>>;
|
|
153
|
+
}>>, import("effect/Schema").toCodecJson<typeof import("effect/http-api/HttpApiError").Unauthorized | typeof import("effect/http-api/HttpApiError").Forbidden | typeof import("effect/http-api/HttpApiError").InternalServerError>, never, never>, never, never>;
|
|
154
|
+
readonly file: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"file", "GET", "/api/assets/:assetId/file", import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
|
|
155
|
+
readonly assetId: import("effect/Schema").String;
|
|
156
|
+
}>>, import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
|
|
157
|
+
readonly download: import("effect/Schema").optionalKey<import("effect/Schema").Literal<"1">>;
|
|
158
|
+
readonly v: import("effect/Schema").optionalKey<import("effect/Schema").String>;
|
|
159
|
+
}>>, never, never, import("effect/http-api/HttpApiSchema").StreamUint8Array | import("effect/Schema").toCodecJson<import("effect/Schema").Void>, import("effect/Schema").toCodecJson<typeof import("effect/http-api/HttpApiError").Unauthorized | typeof import("effect/http-api/HttpApiError").Forbidden | typeof import("effect/http-api/HttpApiError").InternalServerError | typeof import("./schema.js").AssetNotFound>, never, never>, never, never>;
|
|
160
|
+
readonly getAsset: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"getAsset", "GET", "/api/assets/:assetId", import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
|
|
161
|
+
readonly assetId: import("effect/Schema").String;
|
|
162
|
+
}>>, import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
|
|
163
|
+
readonly attemptId: import("effect/Schema").optionalKey<import("effect/Schema").String>;
|
|
164
|
+
readonly outlineOffset: import("effect/Schema").optionalKey<import("effect/Schema").Int>;
|
|
165
|
+
}>>, never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Union<readonly [import("effect/Schema").Struct<{
|
|
166
|
+
readonly id: import("effect/Schema").String;
|
|
167
|
+
readonly name: import("effect/Schema").String;
|
|
168
|
+
readonly mimeType: import("effect/Schema").String;
|
|
169
|
+
readonly status: import("effect/Schema").Literals<readonly ["pending", "running", "completed", "failed", "unsupported"]>;
|
|
170
|
+
readonly totalBytes: import("effect/Schema").Int;
|
|
171
|
+
readonly totalChunks: import("effect/Schema").Int;
|
|
172
|
+
readonly failure: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
173
|
+
readonly outline: import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
174
|
+
readonly headingPath: import("effect/Schema").String;
|
|
175
|
+
readonly firstOrdinal: import("effect/Schema").Int;
|
|
176
|
+
readonly lastOrdinal: import("effect/Schema").Int;
|
|
177
|
+
}>>;
|
|
178
|
+
readonly nextOutlineOffset: import("effect/Schema").NullOr<import("effect/Schema").Int>;
|
|
179
|
+
readonly url: import("effect/Schema").String;
|
|
180
|
+
}>, import("effect/Schema").Struct<{
|
|
181
|
+
readonly attemptId: import("effect/Schema").optionalKey<import("effect/Schema").String>;
|
|
182
|
+
readonly assetId: import("effect/Schema").String;
|
|
183
|
+
readonly uploadStatus: import("effect/Schema").Literals<readonly ["pending", "published", "rejected", "unscannable", "invalid", "failed"]>;
|
|
184
|
+
}>]>>, import("effect/Schema").toCodecJson<typeof import("effect/http-api/HttpApiError").Unauthorized | typeof import("effect/http-api/HttpApiError").Forbidden | typeof import("effect/http-api/HttpApiError").InternalServerError | typeof import("./schema.js").AssetNotFound>, never, never>, never, never>;
|
|
185
|
+
readonly getAssetChunks: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"getAssetChunks", "GET", "/api/assets/:assetId/chunks", import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
|
|
186
|
+
readonly assetId: import("effect/Schema").String;
|
|
187
|
+
}>>, import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
|
|
188
|
+
readonly query: import("effect/Schema").optionalKey<import("effect/Schema").NonEmptyString>;
|
|
189
|
+
readonly language: import("effect/Schema").optionalKey<import("effect/Schema").Literals<readonly ["en", "fr"]>>;
|
|
190
|
+
readonly offset: import("effect/Schema").optionalKey<import("effect/Schema").Int>;
|
|
191
|
+
readonly headingPath: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
192
|
+
readonly ids: import("effect/Schema").optionalKey<import("effect/Schema").$Array<import("effect/Schema").String>>;
|
|
193
|
+
readonly includeNeighbors: import("effect/Schema").optional<import("effect/Schema").Boolean>;
|
|
194
|
+
}>>, never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Union<readonly [import("effect/Schema").Struct<{
|
|
195
|
+
readonly assetId: import("effect/Schema").String;
|
|
196
|
+
readonly nextOffset: import("effect/Schema").NullOr<import("effect/Schema").Int>;
|
|
197
|
+
readonly hits: import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
198
|
+
readonly id: import("effect/Schema").String;
|
|
199
|
+
readonly ordinal: import("effect/Schema").Int;
|
|
200
|
+
readonly headingPath: import("effect/Schema").String;
|
|
201
|
+
readonly byteStart: import("effect/Schema").Int;
|
|
202
|
+
readonly byteEnd: import("effect/Schema").Int;
|
|
203
|
+
readonly firstPage: import("effect/Schema").NullOr<import("effect/Schema").Int>;
|
|
204
|
+
readonly lastPage: import("effect/Schema").NullOr<import("effect/Schema").Int>;
|
|
205
|
+
readonly snippet: import("effect/Schema").String;
|
|
206
|
+
readonly score: import("effect/Schema").Finite;
|
|
207
|
+
}>>;
|
|
208
|
+
}>, import("effect/Schema").Struct<{
|
|
209
|
+
readonly assetId: import("effect/Schema").String;
|
|
210
|
+
readonly chunks: import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
211
|
+
readonly ordinal: import("effect/Schema").Int;
|
|
212
|
+
readonly content: import("effect/Schema").NonEmptyString;
|
|
213
|
+
readonly headingPath: import("effect/Schema").String;
|
|
214
|
+
readonly byteStart: import("effect/Schema").Int;
|
|
215
|
+
readonly byteEnd: import("effect/Schema").Int;
|
|
216
|
+
readonly firstPage: import("effect/Schema").NullOr<import("effect/Schema").Int>;
|
|
217
|
+
readonly lastPage: import("effect/Schema").NullOr<import("effect/Schema").Int>;
|
|
218
|
+
readonly id: import("effect/Schema").String;
|
|
219
|
+
}>>;
|
|
220
|
+
}>]>>, import("effect/Schema").toCodecJson<typeof import("effect/http-api/HttpApiError").Unauthorized | typeof import("effect/http-api/HttpApiError").Forbidden | typeof import("effect/http-api/HttpApiError").InternalServerError | typeof import("./schema.js").AssetTextChunkInvalid | typeof import("./schema.js").AssetTextVersionChanged | typeof import("./schema.js").AssetNotFound>, never, never>, never, never>;
|
|
221
|
+
readonly list: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"list", "GET", "/api/assets", never, import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
|
|
222
|
+
readonly search: import("effect/Schema").optionalKey<import("effect/Schema").String>;
|
|
223
|
+
readonly kind: import("effect/Schema").optionalKey<import("effect/Schema").Literals<readonly ["image", "video", "caption", "document"]>>;
|
|
224
|
+
}>>, never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
|
|
225
|
+
readonly items: import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
226
|
+
readonly id: import("effect/Schema").String;
|
|
227
|
+
readonly name: import("effect/Schema").NonEmptyString;
|
|
228
|
+
readonly mimeType: import("effect/Schema").NonEmptyString;
|
|
229
|
+
readonly byteSize: import("effect/Schema").Int;
|
|
230
|
+
readonly createdAt: import("effect/Schema").Date;
|
|
231
|
+
readonly updatedAt: import("effect/Schema").Date;
|
|
232
|
+
readonly url: import("effect/Schema").optionalKey<import("effect/Schema").String>;
|
|
233
|
+
}>>;
|
|
234
|
+
readonly stats: import("effect/Schema").Struct<{
|
|
235
|
+
readonly assetCount: import("effect/Schema").Int;
|
|
236
|
+
readonly storageUsedBytes: import("effect/Schema").Int;
|
|
237
|
+
}>;
|
|
238
|
+
}>>, import("effect/Schema").toCodecJson<typeof import("effect/http-api/HttpApiError").Unauthorized | typeof import("effect/http-api/HttpApiError").Forbidden | typeof import("effect/http-api/HttpApiError").InternalServerError>, never, never>, never, never>;
|
|
239
|
+
};
|
|
240
|
+
}>;
|
|
241
|
+
export declare class AssetsClient extends AssetsClient_base {
|
|
242
|
+
static readonly layer: (options?: Parameters<typeof makeAssetsClient>[0]) => Layer.Layer<AssetsClient, never, import("effect/http/HttpClient").HttpClient>;
|
|
243
|
+
}
|
|
244
|
+
export {};
|
|
245
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGhD,eAAO,MAAM,gBAAgB,aACjB,UAAU,CAAC,OAAO,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;sDACT,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE5C,qBAAa,YAAa,SAAQ,iBAGI;IACpC,MAAM,CAAC,QAAQ,CAAC,KAAK,aAAc,UAAU,CAAC,OAAO,gBAAgB,CAAC,CAAC,CAAC,CAAC,mFACzB;CACjD"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Context, Layer } from "effect";
|
|
2
|
+
import { HttpApiClient } from "effect/http-api";
|
|
3
|
+
import { AssetsApi } from "./api.group.js";
|
|
4
|
+
export const makeAssetsClient = (options) => HttpApiClient.make(AssetsApi, options);
|
|
5
|
+
export class AssetsClient extends Context.Service()("@krak-stack/assets/AssetsClient") {
|
|
6
|
+
static layer = (options) => Layer.effect(this, makeAssetsClient(options));
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAe,MAAM,QAAQ,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,OAAkD,EAClD,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;AAE5C,MAAM,OAAO,YAAa,SAAQ,OAAO,CAAC,OAAO,EAG9C,CAAC,iCAAiC,CAAC;IACpC,MAAM,CAAU,KAAK,GAAG,CAAC,OAAgD,EAAE,EAAE,CAC3E,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC;CACjD"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Effect, Layer, Schema } from "effect";
|
|
2
|
+
import { Command, Query } from "effect/ui";
|
|
3
|
+
import { AssetsClient } from "./client.js";
|
|
4
|
+
import { AssetLibraryActions, AssetList, type AssetLibraryRuntime } from "./services/assets/library.js";
|
|
5
|
+
import { AssetUploadTargetSchema } from "./schema.js";
|
|
6
|
+
export declare const fileMimeType: (file: Pick<File, "name" | "type">) => string;
|
|
7
|
+
declare const AssetTransferFailed_base: Schema.Class<AssetTransferFailed, Schema.TaggedStruct<"AssetTransferFailed", {}>, import("effect/Cause").YieldableError>;
|
|
8
|
+
declare class AssetTransferFailed extends AssetTransferFailed_base {
|
|
9
|
+
}
|
|
10
|
+
export declare const uploadAsset: (file: File, onProgress: (percent: number) => void, assetId?: string | undefined) => Effect.Effect<{
|
|
11
|
+
assetId: string;
|
|
12
|
+
attemptId?: string | undefined;
|
|
13
|
+
}, import("./schema.js").AssetNotFound | AssetTransferFailed | import("./schema.js").AssetUploadInvalid | import("effect/http-api/HttpApiError").Forbidden | import("effect/http/HttpClientError").HttpClientError | import("effect/http-api/HttpApiError").InternalServerError | Schema.SchemaError | import("effect/http-api/HttpApiError").Unauthorized | import("effect/Cause").UnknownError, AssetsClient>;
|
|
14
|
+
export type StagedAssetUpload = Effect.Success<ReturnType<typeof uploadAsset>>;
|
|
15
|
+
export declare const publishAsset: (payload: typeof AssetUploadTargetSchema.Type) => Effect.Effect<{
|
|
16
|
+
readonly attemptId?: string | undefined;
|
|
17
|
+
readonly assetId: string;
|
|
18
|
+
readonly uploadStatus: "failed" | "invalid" | "pending" | "published" | "rejected" | "unscannable";
|
|
19
|
+
}, import("./schema.js").AssetNotFound | import("./schema.js").AssetUploadInvalid | import("effect/http-api/HttpApiError").Forbidden | import("effect/http/HttpClientError").HttpClientError | import("effect/http-api/HttpApiError").InternalServerError | Schema.SchemaError | import("effect/Cause").TimeoutError | import("effect/http-api/HttpApiError").Unauthorized, AssetsClient | Query.Cache>;
|
|
20
|
+
export declare const deleteAssets: (ids: readonly string[]) => Effect.Effect<{
|
|
21
|
+
readonly deletedIds: readonly string[];
|
|
22
|
+
readonly failures: readonly {
|
|
23
|
+
readonly id: string;
|
|
24
|
+
readonly reason: "in_use" | "not_found";
|
|
25
|
+
}[];
|
|
26
|
+
}, import("effect/http-api/HttpApiError").Forbidden | import("effect/http/HttpClientError").HttpClientError | import("effect/http-api/HttpApiError").InternalServerError | Schema.SchemaError | import("effect/http-api/HttpApiError").Unauthorized, AssetsClient | Query.Cache>;
|
|
27
|
+
declare const PublishAsset_base: Command.Service<PublishAsset, "@krak-stack/assets/PublishAsset", {
|
|
28
|
+
readonly attemptId?: string | undefined;
|
|
29
|
+
readonly assetId: string;
|
|
30
|
+
}, Schema.Struct<{
|
|
31
|
+
readonly attemptId: Schema.optionalKey<Schema.String>;
|
|
32
|
+
readonly assetId: Schema.String;
|
|
33
|
+
readonly uploadStatus: Schema.Literals<readonly ["pending", "published", "rejected", "unscannable", "invalid", "failed"]>;
|
|
34
|
+
}>, false, Schema.Literal<"unavailable">, never>;
|
|
35
|
+
export declare class PublishAsset extends PublishAsset_base {
|
|
36
|
+
static readonly layer: Layer.Layer<PublishAsset, never, AssetsClient>;
|
|
37
|
+
}
|
|
38
|
+
declare const DeleteAssets_base: Command.Service<DeleteAssets, "@krak-stack/assets/DeleteAssets", {
|
|
39
|
+
readonly ids: readonly string[];
|
|
40
|
+
}, Schema.Struct<{
|
|
41
|
+
readonly deletedIds: Schema.$Array<Schema.String>;
|
|
42
|
+
readonly failures: Schema.$Array<Schema.Struct<{
|
|
43
|
+
readonly id: Schema.String;
|
|
44
|
+
readonly reason: Schema.Union<readonly [Schema.Literal<"not_found">, Schema.Literal<"in_use">]>;
|
|
45
|
+
}>>;
|
|
46
|
+
}>, false, Schema.Literal<"unavailable">, never>;
|
|
47
|
+
export declare class DeleteAssets extends DeleteAssets_base {
|
|
48
|
+
static readonly layer: Layer.Layer<DeleteAssets, never, AssetsClient>;
|
|
49
|
+
}
|
|
50
|
+
export declare const assetLibraryLayer: Layer.Layer<AssetLibraryActions | AssetList, never, AssetsClient>;
|
|
51
|
+
export declare const makeAssetLibraryRuntime: (clientLayer: Layer.Layer<AssetsClient>) => AssetLibraryRuntime & {
|
|
52
|
+
readonly dispose: () => Promise<void>;
|
|
53
|
+
};
|
|
54
|
+
export {};
|
|
55
|
+
//# sourceMappingURL=commands.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../src/commands.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAA4B,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEzE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EACL,mBAAmB,EACnB,SAAS,EACT,KAAK,mBAAmB,EACzB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAGL,uBAAuB,EAGxB,MAAM,aAAa,CAAC;AAoBrB,eAAO,MAAM,YAAY,SAAU,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,WAQ7D,CAAC;;AAEF,cAAM,mBAAoB,SAAQ,wBAGjC;CAAG;AAEJ,eAAO,MAAM,WAAW,qCAEA,MAAM,KAAK,IAAI;;;+YA6CrC,CAAC;AAEH,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC;AA0B/E,eAAO,MAAM,YAAY,YAAa,OAAO,uBAAuB,CAAC,IAAI;;;;uYAKtE,CAAC;AAEJ,eAAO,MAAM,YAAY,QAAS,SAAS,MAAM,EAAE;;;;;;gRAShD,CAAC;;;;;;;;;AAIJ,qBAAa,YAAa,SAAQ,iBAOjC;IACC,MAAM,CAAC,QAAQ,CAAC,KAAK,iDASnB;CACH;;;;;;;;;;AAED,qBAAa,YAAa,SAAQ,iBAOjC;IACC,MAAM,CAAC,QAAQ,CAAC,KAAK,iDASnB;CACH;AAED,eAAO,MAAM,iBAAiB,mEA4B7B,CAAC;AAEF,eAAO,MAAM,uBAAuB,gBACrB,KAAK,CAAC,KAAK,CAAC,YAAY,CAAC,KACrC,mBAAmB,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAY/D,CAAC"}
|
package/dist/commands.js
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { Effect, Layer, ManagedRuntime, Schedule, Schema } from "effect";
|
|
2
|
+
import { Digest } from "effect/crypto";
|
|
3
|
+
import { Command, Query } from "effect/ui";
|
|
4
|
+
import { AssetsClient } from "./client.js";
|
|
5
|
+
import { AssetLibraryActions, AssetList, } from "./services/assets/library.js";
|
|
6
|
+
import { assetListLayer } from "./queries.js";
|
|
7
|
+
import { AssetDeleteResultSchema, AssetIdsPayloadSchema, AssetUploadTargetSchema, AssetUploadStateSchema, AssetUploadSizeSchema, } from "./schema.js";
|
|
8
|
+
const mimeByExtension = new Map([
|
|
9
|
+
["csv", "text/csv"],
|
|
10
|
+
[
|
|
11
|
+
"docx",
|
|
12
|
+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
13
|
+
],
|
|
14
|
+
["json", "application/json"],
|
|
15
|
+
["md", "text/markdown"],
|
|
16
|
+
[
|
|
17
|
+
"pptx",
|
|
18
|
+
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
19
|
+
],
|
|
20
|
+
["rtf", "application/rtf"],
|
|
21
|
+
["txt", "text/plain"],
|
|
22
|
+
["vtt", "text/vtt"],
|
|
23
|
+
["xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],
|
|
24
|
+
]);
|
|
25
|
+
export const fileMimeType = (file) => {
|
|
26
|
+
const dot = file.name.lastIndexOf(".");
|
|
27
|
+
return (mimeByExtension.get(dot > 0 ? file.name.slice(dot + 1).toLowerCase() : "") ??
|
|
28
|
+
(file.type || "application/octet-stream"));
|
|
29
|
+
};
|
|
30
|
+
class AssetTransferFailed extends Schema.TaggedError()("AssetTransferFailed", {}) {
|
|
31
|
+
}
|
|
32
|
+
export const uploadAsset = Effect.fn("Assets.uploadAsset")(function* (file, onProgress, assetId) {
|
|
33
|
+
// Reject before allocating a buffer or asking the server for a signed URL.
|
|
34
|
+
const byteSize = yield* Schema.decodeEffect(AssetUploadSizeSchema)(file.size);
|
|
35
|
+
const client = yield* AssetsClient;
|
|
36
|
+
const checksum = yield* Effect.tryPromise(() => file.arrayBuffer()).pipe(Effect.flatMap((buffer) => Digest.Digest.use((digest) => digest.digestHex(Digest.sha256, new Uint8Array(buffer)))), Effect.provide(Digest.layerWebCrypto));
|
|
37
|
+
const payload = {
|
|
38
|
+
name: file.name,
|
|
39
|
+
mimeType: fileMimeType(file),
|
|
40
|
+
byteSize,
|
|
41
|
+
checksum,
|
|
42
|
+
...(assetId ? { assetId } : {}),
|
|
43
|
+
};
|
|
44
|
+
const upload = yield* client.assets.createAssetUpload({ payload });
|
|
45
|
+
yield* Effect.callback((resume) => {
|
|
46
|
+
const xhr = new XMLHttpRequest();
|
|
47
|
+
xhr.open("PUT", upload.uploadUrl);
|
|
48
|
+
xhr.setRequestHeader("Content-Type", upload.contentType);
|
|
49
|
+
xhr.upload.onprogress = (event) => {
|
|
50
|
+
if (event.lengthComputable && event.total > 0)
|
|
51
|
+
onProgress(Math.round((event.loaded / event.total) * 100));
|
|
52
|
+
};
|
|
53
|
+
xhr.onload = () => resume(xhr.status >= 200 && xhr.status < 300
|
|
54
|
+
? Effect.void
|
|
55
|
+
: Effect.fail(new AssetTransferFailed()));
|
|
56
|
+
xhr.onerror = xhr.onabort = () => resume(Effect.fail(new AssetTransferFailed()));
|
|
57
|
+
xhr.send(file);
|
|
58
|
+
return Effect.sync(() => xhr.abort());
|
|
59
|
+
});
|
|
60
|
+
return {
|
|
61
|
+
assetId: upload.assetId,
|
|
62
|
+
...(upload.attemptId ? { attemptId: upload.attemptId } : {}),
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
|
+
const publication = Effect.fn("Assets.publishAsset")(function* ({ assetId, attemptId, }) {
|
|
66
|
+
const client = yield* AssetsClient;
|
|
67
|
+
const request = {
|
|
68
|
+
params: { assetId },
|
|
69
|
+
query: attemptId ? { attemptId } : {},
|
|
70
|
+
};
|
|
71
|
+
const state = yield* client.assets.completeAssetUpload(request);
|
|
72
|
+
if (state.uploadStatus !== "pending")
|
|
73
|
+
return state;
|
|
74
|
+
return yield* client.assets.getAsset(request).pipe(Effect.map((result) => "uploadStatus" in result
|
|
75
|
+
? result
|
|
76
|
+
: { assetId: result.id, uploadStatus: "published" }), Effect.repeat({
|
|
77
|
+
schedule: Schedule.spaced("2 seconds"),
|
|
78
|
+
until: ({ uploadStatus }) => uploadStatus !== "pending",
|
|
79
|
+
}));
|
|
80
|
+
}, Effect.timeout("40 minutes"));
|
|
81
|
+
export const publishAsset = (payload) => publication(payload).pipe(Effect.tap(({ uploadStatus }) => uploadStatus === "published" ? AssetList.invalidate() : Effect.void));
|
|
82
|
+
export const deleteAssets = (ids) => AssetsClient.use((client) => client.assets.deleteAssets({ payload: { ids } })).pipe(Effect.tap(({ deletedIds }) => deletedIds.length > 0 ? AssetList.invalidate() : Effect.void),
|
|
83
|
+
// A failed response may follow one or more committed deletes.
|
|
84
|
+
Effect.tapError(() => AssetList.invalidate()));
|
|
85
|
+
const CommandError = Schema.Literal("unavailable");
|
|
86
|
+
export class PublishAsset extends Command.Service()("@krak-stack/assets/PublishAsset", {
|
|
87
|
+
args: AssetUploadTargetSchema,
|
|
88
|
+
success: AssetUploadStateSchema,
|
|
89
|
+
error: CommandError,
|
|
90
|
+
}) {
|
|
91
|
+
static layer = this.toLayer(Effect.gen(function* () {
|
|
92
|
+
const client = yield* AssetsClient;
|
|
93
|
+
return (payload) => publishAsset(payload).pipe(Effect.provideService(AssetsClient, client), Effect.mapError(() => "unavailable"));
|
|
94
|
+
}));
|
|
95
|
+
}
|
|
96
|
+
export class DeleteAssets extends Command.Service()("@krak-stack/assets/DeleteAssets", {
|
|
97
|
+
args: AssetIdsPayloadSchema,
|
|
98
|
+
success: AssetDeleteResultSchema,
|
|
99
|
+
error: CommandError,
|
|
100
|
+
}) {
|
|
101
|
+
static layer = this.toLayer(Effect.gen(function* () {
|
|
102
|
+
const client = yield* AssetsClient;
|
|
103
|
+
return ({ ids }) => deleteAssets(ids).pipe(Effect.provideService(AssetsClient, client), Effect.mapError(() => "unavailable"));
|
|
104
|
+
}));
|
|
105
|
+
}
|
|
106
|
+
export const assetLibraryLayer = Layer.merge(assetListLayer, Layer.effect(AssetLibraryActions, Effect.gen(function* () {
|
|
107
|
+
const client = yield* AssetsClient;
|
|
108
|
+
return AssetLibraryActions.of({
|
|
109
|
+
upload: (file, progress, replaceId) => uploadAsset(file, progress, replaceId).pipe(Effect.provideService(AssetsClient, client)),
|
|
110
|
+
publish: (upload) => publishAsset(upload).pipe(Effect.provideService(AssetsClient, client), Effect.map(({ assetId, uploadStatus }) => uploadStatus === "published"
|
|
111
|
+
? { status: "published", assetId }
|
|
112
|
+
: {
|
|
113
|
+
status: "rejected",
|
|
114
|
+
reason: uploadStatus === "rejected" ? "rejected" : "failed",
|
|
115
|
+
})),
|
|
116
|
+
remove: (ids) => deleteAssets(ids).pipe(Effect.provideService(AssetsClient, client)),
|
|
117
|
+
});
|
|
118
|
+
})));
|
|
119
|
+
export const makeAssetLibraryRuntime = (clientLayer) => {
|
|
120
|
+
const runtime = ManagedRuntime.make(assetLibraryLayer.pipe(Layer.provide(clientLayer), Layer.merge(Query.layer())));
|
|
121
|
+
return {
|
|
122
|
+
layer: Layer.effectContext(Effect.promise(() => runtime.context())),
|
|
123
|
+
runPromise: runtime.runPromise,
|
|
124
|
+
dispose: runtime.dispose,
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
//# sourceMappingURL=commands.js.map
|