@lumeweb/pinner 0.0.1 → 0.1.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 +9 -0
- package/README.md +690 -28
- package/dist/cjs/_virtual/rolldown_runtime.cjs +29 -0
- package/dist/cjs/adapters/pinata/adapter.cjs +88 -0
- package/dist/cjs/adapters/pinata/adapter.cjs.map +1 -0
- package/dist/cjs/adapters/pinata/adapter.d.cts +35 -0
- package/dist/cjs/adapters/pinata/builder.cjs +194 -0
- package/dist/cjs/adapters/pinata/builder.cjs.map +1 -0
- package/dist/cjs/adapters/pinata/index.cjs +3 -0
- package/dist/cjs/adapters/pinata/list-builder.cjs +52 -0
- package/dist/cjs/adapters/pinata/list-builder.cjs.map +1 -0
- package/dist/cjs/blockstore/index.cjs +2 -0
- package/dist/cjs/blockstore/unstorage-base.cjs +240 -0
- package/dist/cjs/blockstore/unstorage-base.cjs.map +1 -0
- package/dist/cjs/blockstore/unstorage-base.d.cts +23 -0
- package/dist/cjs/blockstore/unstorage.cjs +39 -0
- package/dist/cjs/blockstore/unstorage.cjs.map +1 -0
- package/dist/cjs/blockstore/unstorage.d.cts +36 -0
- package/dist/cjs/config.d.cts +51 -0
- package/dist/cjs/encoder/base64.cjs +38 -0
- package/dist/cjs/encoder/base64.cjs.map +1 -0
- package/dist/cjs/encoder/csv/csv-formatter.cjs +81 -0
- package/dist/cjs/encoder/csv/csv-formatter.cjs.map +1 -0
- package/dist/cjs/encoder/csv/field-formatter.cjs +76 -0
- package/dist/cjs/encoder/csv/field-formatter.cjs.map +1 -0
- package/dist/cjs/encoder/csv/row-formatter.cjs +159 -0
- package/dist/cjs/encoder/csv/row-formatter.cjs.map +1 -0
- package/dist/cjs/encoder/csv.cjs +44 -0
- package/dist/cjs/encoder/csv.cjs.map +1 -0
- package/dist/cjs/encoder/error.cjs +19 -0
- package/dist/cjs/encoder/error.cjs.map +1 -0
- package/dist/cjs/encoder/index.cjs +6 -0
- package/dist/cjs/encoder/json.cjs +36 -0
- package/dist/cjs/encoder/json.cjs.map +1 -0
- package/dist/cjs/encoder/text.cjs +35 -0
- package/dist/cjs/encoder/text.cjs.map +1 -0
- package/dist/cjs/encoder/url.cjs +39 -0
- package/dist/cjs/encoder/url.cjs.map +1 -0
- package/dist/cjs/errors/index.cjs +104 -0
- package/dist/cjs/errors/index.cjs.map +1 -0
- package/dist/cjs/errors/index.d.cts +47 -0
- package/dist/cjs/index.cjs +42 -0
- package/dist/cjs/index.d.cts +14 -0
- package/dist/cjs/pin/client.cjs +96 -0
- package/dist/cjs/pin/client.cjs.map +1 -0
- package/dist/cjs/pin/index.cjs +1 -0
- package/dist/cjs/pinner.cjs +126 -0
- package/dist/cjs/pinner.cjs.map +1 -0
- package/dist/cjs/pinner.d.cts +77 -0
- package/dist/cjs/types/constants.cjs +34 -0
- package/dist/cjs/types/constants.cjs.map +1 -0
- package/dist/cjs/types/mime-types.cjs +11 -0
- package/dist/cjs/types/mime-types.cjs.map +1 -0
- package/dist/cjs/types/mime-types.d.cts +7 -0
- package/dist/cjs/types/pin.d.cts +74 -0
- package/dist/cjs/types/pinata.d.cts +99 -0
- package/dist/cjs/types/type-guards.cjs +20 -0
- package/dist/cjs/types/type-guards.cjs.map +1 -0
- package/dist/cjs/types/type-guards.d.cts +15 -0
- package/dist/cjs/types/upload.cjs +18 -0
- package/dist/cjs/types/upload.cjs.map +1 -0
- package/dist/cjs/types/upload.d.cts +189 -0
- package/dist/cjs/upload/base-upload.cjs +135 -0
- package/dist/cjs/upload/base-upload.cjs.map +1 -0
- package/dist/cjs/upload/builder.cjs +174 -0
- package/dist/cjs/upload/builder.cjs.map +1 -0
- package/dist/cjs/upload/builder.d.cts +60 -0
- package/dist/cjs/upload/car.cjs +129 -0
- package/dist/cjs/upload/car.cjs.map +1 -0
- package/dist/cjs/upload/car.d.cts +19 -0
- package/dist/cjs/upload/constants.cjs +9 -0
- package/dist/cjs/upload/constants.cjs.map +1 -0
- package/dist/cjs/upload/index.cjs +8 -0
- package/dist/cjs/upload/manager.cjs +249 -0
- package/dist/cjs/upload/manager.cjs.map +1 -0
- package/dist/cjs/upload/manager.d.cts +35 -0
- package/dist/cjs/upload/normalize.cjs +28 -0
- package/dist/cjs/upload/normalize.cjs.map +1 -0
- package/dist/cjs/upload/tus-upload.cjs +74 -0
- package/dist/cjs/upload/tus-upload.cjs.map +1 -0
- package/dist/cjs/upload/xhr-upload.cjs +41 -0
- package/dist/cjs/upload/xhr-upload.cjs.map +1 -0
- package/dist/cjs/utils/env.cjs +12 -0
- package/dist/cjs/utils/env.cjs.map +1 -0
- package/dist/cjs/utils/stream.cjs +141 -0
- package/dist/cjs/utils/stream.cjs.map +1 -0
- package/dist/cjs/utils/stream.d.cts +23 -0
- package/dist/cjs/utils/tus-patch.cjs +50 -0
- package/dist/cjs/utils/tus-patch.cjs.map +1 -0
- package/dist/cjs/utils/validation.cjs +62 -0
- package/dist/cjs/utils/validation.cjs.map +1 -0
- package/dist/esm/_virtual/rolldown_runtime.js +8 -0
- package/dist/esm/adapters/pinata/adapter.d.ts +35 -0
- package/dist/esm/adapters/pinata/adapter.js +87 -0
- package/dist/esm/adapters/pinata/adapter.js.map +1 -0
- package/dist/esm/adapters/pinata/builder.d.ts +1 -0
- package/dist/esm/adapters/pinata/builder.js +187 -0
- package/dist/esm/adapters/pinata/builder.js.map +1 -0
- package/dist/esm/adapters/pinata/index.d.ts +4 -0
- package/dist/esm/adapters/pinata/index.js +3 -0
- package/dist/esm/adapters/pinata/list-builder.d.ts +1 -0
- package/dist/esm/adapters/pinata/list-builder.js +51 -0
- package/dist/esm/adapters/pinata/list-builder.js.map +1 -0
- package/dist/esm/blockstore/index.d.ts +2 -0
- package/dist/esm/blockstore/index.js +2 -0
- package/dist/esm/blockstore/unstorage-base.d.ts +23 -0
- package/dist/esm/blockstore/unstorage-base.js +231 -0
- package/dist/esm/blockstore/unstorage-base.js.map +1 -0
- package/dist/esm/blockstore/unstorage.d.ts +36 -0
- package/dist/esm/blockstore/unstorage.js +38 -0
- package/dist/esm/blockstore/unstorage.js.map +1 -0
- package/dist/esm/config.d.ts +51 -0
- package/dist/esm/encoder/base64.js +37 -0
- package/dist/esm/encoder/base64.js.map +1 -0
- package/dist/esm/encoder/csv/csv-formatter.js +81 -0
- package/dist/esm/encoder/csv/csv-formatter.js.map +1 -0
- package/dist/esm/encoder/csv/field-formatter.js +75 -0
- package/dist/esm/encoder/csv/field-formatter.js.map +1 -0
- package/dist/esm/encoder/csv/row-formatter.js +159 -0
- package/dist/esm/encoder/csv/row-formatter.js.map +1 -0
- package/dist/esm/encoder/csv.js +43 -0
- package/dist/esm/encoder/csv.js.map +1 -0
- package/dist/esm/encoder/error.js +18 -0
- package/dist/esm/encoder/error.js.map +1 -0
- package/dist/esm/encoder/index.js +6 -0
- package/dist/esm/encoder/json.js +35 -0
- package/dist/esm/encoder/json.js.map +1 -0
- package/dist/esm/encoder/text.js +34 -0
- package/dist/esm/encoder/text.js.map +1 -0
- package/dist/esm/encoder/url.js +36 -0
- package/dist/esm/encoder/url.js.map +1 -0
- package/dist/esm/errors/index.d.ts +47 -0
- package/dist/esm/errors/index.js +93 -0
- package/dist/esm/errors/index.js.map +1 -0
- package/dist/esm/index.d.ts +16 -0
- package/dist/esm/index.js +14 -0
- package/dist/esm/pin/client.js +95 -0
- package/dist/esm/pin/client.js.map +1 -0
- package/dist/esm/pin/index.js +1 -0
- package/dist/esm/pinner.d.ts +77 -0
- package/dist/esm/pinner.js +125 -0
- package/dist/esm/pinner.js.map +1 -0
- package/dist/esm/types/constants.js +29 -0
- package/dist/esm/types/constants.js.map +1 -0
- package/dist/esm/types/mime-types.d.ts +7 -0
- package/dist/esm/types/mime-types.js +8 -0
- package/dist/esm/types/mime-types.js.map +1 -0
- package/dist/esm/types/pin.d.ts +74 -0
- package/dist/esm/types/pinata.d.ts +99 -0
- package/dist/esm/types/type-guards.d.ts +15 -0
- package/dist/esm/types/type-guards.js +19 -0
- package/dist/esm/types/type-guards.js.map +1 -0
- package/dist/esm/types/upload.d.ts +189 -0
- package/dist/esm/types/upload.js +16 -0
- package/dist/esm/types/upload.js.map +1 -0
- package/dist/esm/upload/base-upload.js +132 -0
- package/dist/esm/upload/base-upload.js.map +1 -0
- package/dist/esm/upload/builder.d.ts +60 -0
- package/dist/esm/upload/builder.js +173 -0
- package/dist/esm/upload/builder.js.map +1 -0
- package/dist/esm/upload/car.d.ts +19 -0
- package/dist/esm/upload/car.js +125 -0
- package/dist/esm/upload/car.js.map +1 -0
- package/dist/esm/upload/constants.js +7 -0
- package/dist/esm/upload/constants.js.map +1 -0
- package/dist/esm/upload/index.js +8 -0
- package/dist/esm/upload/manager.d.ts +35 -0
- package/dist/esm/upload/manager.js +248 -0
- package/dist/esm/upload/manager.js.map +1 -0
- package/dist/esm/upload/normalize.js +28 -0
- package/dist/esm/upload/normalize.js.map +1 -0
- package/dist/esm/upload/tus-upload.js +72 -0
- package/dist/esm/upload/tus-upload.js.map +1 -0
- package/dist/esm/upload/xhr-upload.js +39 -0
- package/dist/esm/upload/xhr-upload.js.map +1 -0
- package/dist/esm/utils/env.js +11 -0
- package/dist/esm/utils/env.js.map +1 -0
- package/dist/esm/utils/stream.d.ts +23 -0
- package/dist/esm/utils/stream.js +134 -0
- package/dist/esm/utils/stream.js.map +1 -0
- package/dist/esm/utils/tus-patch.js +51 -0
- package/dist/esm/utils/tus-patch.js.map +1 -0
- package/dist/esm/utils/validation.js +60 -0
- package/dist/esm/utils/validation.js.map +1 -0
- package/package.json +95 -8
- package/public/mockServiceWorker.js +349 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_index = require('../errors/index.cjs');
|
|
3
|
+
let multiformats_cid = require("multiformats/cid");
|
|
4
|
+
let _ipfs_shipyard_pinning_service_client = require("@ipfs-shipyard/pinning-service-client");
|
|
5
|
+
|
|
6
|
+
//#region src/pin/client.ts
|
|
7
|
+
var PinClient = class {
|
|
8
|
+
client = null;
|
|
9
|
+
config;
|
|
10
|
+
constructor(config) {
|
|
11
|
+
this.config = config;
|
|
12
|
+
}
|
|
13
|
+
getClient() {
|
|
14
|
+
if (this.client) return this.client;
|
|
15
|
+
if (!this.config.jwt) throw new require_index.ConfigurationError("JWT token is required");
|
|
16
|
+
this.client = new _ipfs_shipyard_pinning_service_client.RemotePinningServiceClient(new _ipfs_shipyard_pinning_service_client.Configuration({
|
|
17
|
+
endpointUrl: this.config.endpoint,
|
|
18
|
+
accessToken: this.config.jwt,
|
|
19
|
+
fetchApi: this.config.fetch ?? fetch
|
|
20
|
+
}));
|
|
21
|
+
return this.client;
|
|
22
|
+
}
|
|
23
|
+
async *add(cid, options) {
|
|
24
|
+
const client = this.getClient();
|
|
25
|
+
const pin = {
|
|
26
|
+
cid: cid.toString(),
|
|
27
|
+
name: options?.name,
|
|
28
|
+
meta: options?.metadata,
|
|
29
|
+
origins: options?.origins
|
|
30
|
+
};
|
|
31
|
+
await client.pinsPost({ pin }, { signal: options?.signal });
|
|
32
|
+
yield cid;
|
|
33
|
+
}
|
|
34
|
+
async *ls(options) {
|
|
35
|
+
const response = await this.getClient().pinsGet(this.normalizeListOptions(options), { signal: options?.signal });
|
|
36
|
+
for (const result of response.results) yield this.mapResponse(result);
|
|
37
|
+
}
|
|
38
|
+
async isPinned(cid, options) {
|
|
39
|
+
try {
|
|
40
|
+
await this.get(cid, options);
|
|
41
|
+
return true;
|
|
42
|
+
} catch {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
async get(cid, options) {
|
|
47
|
+
const response = await this.getClient().pinsGet({ cid: [cid.toString()] }, { signal: options?.signal });
|
|
48
|
+
if (response.results.length === 0) throw new require_index.NotFoundError(`Pin not found for CID: ${cid.toString()}`);
|
|
49
|
+
return this.mapResponse(response.results[0]);
|
|
50
|
+
}
|
|
51
|
+
async setMetadata(cid, metadata, options) {
|
|
52
|
+
const client = this.getClient();
|
|
53
|
+
const response = await client.pinsGet({ cid: [cid.toString()] }, { signal: options?.signal });
|
|
54
|
+
if (response.results.length === 0) throw new require_index.NotFoundError(`Pin not found for CID: ${cid.toString()}`);
|
|
55
|
+
const pin = response.results[0];
|
|
56
|
+
await client.pinsRequestidPost({
|
|
57
|
+
requestid: pin.requestid,
|
|
58
|
+
pin: {
|
|
59
|
+
cid: pin.pin.cid,
|
|
60
|
+
name: pin.pin.name,
|
|
61
|
+
meta: metadata,
|
|
62
|
+
origins: pin.pin.origins
|
|
63
|
+
}
|
|
64
|
+
}, { signal: options?.signal });
|
|
65
|
+
}
|
|
66
|
+
async *rm(cid, options) {
|
|
67
|
+
const client = this.getClient();
|
|
68
|
+
const response = await client.pinsGet({ cid: [cid.toString()] }, { signal: options?.signal });
|
|
69
|
+
await Promise.all([...response.results].map(async (result) => {
|
|
70
|
+
return client.pinsRequestidDelete({ requestid: result.requestid }, { signal: options?.signal });
|
|
71
|
+
}));
|
|
72
|
+
yield cid;
|
|
73
|
+
}
|
|
74
|
+
mapResponse(response) {
|
|
75
|
+
return {
|
|
76
|
+
cid: multiformats_cid.CID.parse(response.pin.cid),
|
|
77
|
+
name: response.pin.name,
|
|
78
|
+
status: response.status,
|
|
79
|
+
created: response.created,
|
|
80
|
+
size: response.pin.meta?.size ? parseInt(response.pin.meta.size, 10) : void 0,
|
|
81
|
+
metadata: response.pin.meta
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
normalizeListOptions(options) {
|
|
85
|
+
const request = {};
|
|
86
|
+
if (options?.limit !== void 0) request.limit = options.limit;
|
|
87
|
+
if (options?.cursor !== void 0) request.after = options.cursor;
|
|
88
|
+
if (options?.status !== void 0) request.status = options.status;
|
|
89
|
+
if (options?.name !== void 0) request.name = options.name;
|
|
90
|
+
return request;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
//#endregion
|
|
95
|
+
exports.PinClient = PinClient;
|
|
96
|
+
//# sourceMappingURL=client.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.cjs","names":["ConfigurationError","RemotePinningServiceClient","Configuration","NotFoundError","CID"],"sources":["../../../src/pin/client.ts"],"sourcesContent":["import {\n Configuration,\n type Pin,\n type PinStatus,\n RemotePinningServiceClient,\n} from \"@ipfs-shipyard/pinning-service-client\";\nimport type { PinnerConfig } from \"../config\";\nimport type {\n AbortOptions,\n RemoteAddOptions,\n RemoteLsOptions,\n RemotePin,\n RemotePins,\n} from \"@/types/pin\";\nimport { CID } from \"multiformats/cid\";\nimport { ConfigurationError, NotFoundError } from \"@/errors\";\n\nexport class PinClient implements RemotePins {\n private client: RemotePinningServiceClient | null = null;\n private config: PinnerConfig;\n\n constructor(config: PinnerConfig) {\n this.config = config;\n }\n\n protected getClient(): RemotePinningServiceClient {\n if (this.client) {\n return this.client;\n }\n\n if (!this.config.jwt) {\n throw new ConfigurationError(\"JWT token is required\");\n }\n\n const configuration = new Configuration({\n endpointUrl: this.config.endpoint,\n accessToken: this.config.jwt,\n fetchApi: this.config.fetch ?? fetch,\n });\n\n this.client = new RemotePinningServiceClient(configuration);\n return this.client;\n }\n\n async *add(\n cid: CID,\n options?: RemoteAddOptions,\n ): AsyncGenerator<CID, void, undefined> {\n const client = this.getClient();\n\n const pin: Pin = {\n cid: cid.toString(),\n name: options?.name,\n meta: options?.metadata,\n origins: options?.origins,\n };\n\n await client.pinsPost({ pin }, { signal: options?.signal });\n\n yield cid;\n }\n\n async *ls(\n options?: RemoteLsOptions,\n ): AsyncGenerator<RemotePin, void, undefined> {\n const client = this.getClient();\n const response = await client.pinsGet(this.normalizeListOptions(options), {\n signal: options?.signal,\n });\n\n for (const result of response.results) {\n yield this.mapResponse(result);\n }\n }\n\n async isPinned(cid: CID, options?: AbortOptions): Promise<boolean> {\n try {\n await this.get(cid, options);\n return true;\n } catch {\n return false;\n }\n }\n\n async get(cid: CID, options?: AbortOptions): Promise<RemotePin> {\n const client = this.getClient();\n const response = await client.pinsGet(\n { cid: [cid.toString()] },\n {\n signal: options?.signal,\n },\n );\n\n if (response.results.length === 0) {\n throw new NotFoundError(`Pin not found for CID: ${cid.toString()}`);\n }\n\n return this.mapResponse(response.results[0]);\n }\n\n async setMetadata(\n cid: CID,\n metadata: Record<string, string> | undefined,\n options?: AbortOptions,\n ): Promise<void> {\n const client = this.getClient();\n const response = await client.pinsGet(\n { cid: [cid.toString()] },\n {\n signal: options?.signal,\n },\n );\n\n if (response.results.length === 0) {\n throw new NotFoundError(`Pin not found for CID: ${cid.toString()}`);\n }\n\n const pin = response.results[0];\n await client.pinsRequestidPost(\n {\n requestid: pin.requestid,\n pin: {\n cid: pin.pin.cid,\n name: pin.pin.name,\n meta: metadata,\n origins: pin.pin.origins,\n },\n },\n { signal: options?.signal },\n );\n }\n\n async *rm(\n cid: CID,\n options?: AbortOptions,\n ): AsyncGenerator<CID, void, undefined> {\n const client = this.getClient();\n const response = await client.pinsGet(\n { cid: [cid.toString()] },\n { signal: options?.signal },\n );\n\n await Promise.all(\n [...response.results].map(async (result) => {\n return client.pinsRequestidDelete(\n { requestid: result.requestid },\n { signal: options?.signal },\n );\n }),\n );\n\n yield cid;\n }\n\n private mapResponse(response: PinStatus): RemotePin {\n return {\n cid: CID.parse(response.pin.cid),\n name: response.pin.name,\n status: response.status,\n created: response.created,\n size: response.pin.meta?.size\n ? parseInt(response.pin.meta.size, 10)\n : undefined,\n metadata: response.pin.meta,\n };\n }\n\n private normalizeListOptions(\n options?: RemoteLsOptions,\n ): Record<string, unknown> {\n const request: Record<string, unknown> = {};\n\n if (options?.limit !== undefined) {\n request.limit = options.limit;\n }\n if (options?.cursor !== undefined) {\n request.after = options.cursor;\n }\n if (options?.status !== undefined) {\n request.status = options.status;\n }\n if (options?.name !== undefined) {\n request.name = options.name;\n }\n\n return request;\n }\n}\n"],"mappings":";;;;;;AAiBA,IAAa,YAAb,MAA6C;CAC3C,AAAQ,SAA4C;CACpD,AAAQ;CAER,YAAY,QAAs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,SAAS,OACpB,SAAQ,OAAO,QAAQ;AAGzB,SAAO"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const require_client = require('./client.cjs');
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_manager = require('./upload/manager.cjs');
|
|
3
|
+
const require_builder = require('./upload/builder.cjs');
|
|
4
|
+
require('./upload/index.cjs');
|
|
5
|
+
const require_client = require('./pin/client.cjs');
|
|
6
|
+
require('./pin/index.cjs');
|
|
7
|
+
let multiformats_cid = require("multiformats/cid");
|
|
8
|
+
|
|
9
|
+
//#region src/pinner.ts
|
|
10
|
+
var Pinner = class {
|
|
11
|
+
uploadManager;
|
|
12
|
+
_pins;
|
|
13
|
+
_upload;
|
|
14
|
+
constructor(config) {
|
|
15
|
+
this.uploadManager = new require_manager.UploadManager(config);
|
|
16
|
+
this._pins = new require_client.PinClient(config);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Access the remote pins interface.
|
|
20
|
+
*/
|
|
21
|
+
get pins() {
|
|
22
|
+
return this._pins;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Upload interface that works as both a method and a builder namespace.
|
|
26
|
+
*
|
|
27
|
+
* As a method: upload(file, options) -> UploadOperation
|
|
28
|
+
* As a property: upload.file(), upload.json(), etc. -> Builder
|
|
29
|
+
*/
|
|
30
|
+
get upload() {
|
|
31
|
+
if (!this._upload) {
|
|
32
|
+
const builderNamespace = require_builder.createUploadBuilderNamespace(this);
|
|
33
|
+
const uploadMethod = async (file, options) => {
|
|
34
|
+
return this.uploadManager.upload(file, options);
|
|
35
|
+
};
|
|
36
|
+
this._upload = new Proxy(uploadMethod, { get(target, prop) {
|
|
37
|
+
if (prop in builderNamespace) return Reflect.get(builderNamespace, prop);
|
|
38
|
+
return Reflect.get(target, prop);
|
|
39
|
+
} });
|
|
40
|
+
}
|
|
41
|
+
return this._upload;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Upload a file and wait for completion.
|
|
45
|
+
* Convenience method for simple use cases where controls aren't needed.
|
|
46
|
+
*/
|
|
47
|
+
async uploadAndWait(file, options) {
|
|
48
|
+
return (await this.upload(file, options)).result;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Wait for an operation to complete or reach a settled state.
|
|
52
|
+
* @param input Either an operation ID (number) or an UploadResult
|
|
53
|
+
* @param options Polling options (interval, timeout, settledStates)
|
|
54
|
+
* @returns UploadResult with operation status merged in
|
|
55
|
+
*/
|
|
56
|
+
async waitForOperation(input, options) {
|
|
57
|
+
return this.uploadManager.waitForOperation(input, options);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Upload a directory to IPFS.
|
|
61
|
+
*/
|
|
62
|
+
async uploadDirectory(files, options) {
|
|
63
|
+
return this.uploadManager.uploadDirectory(files, options);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Upload a CAR file without preprocessing.
|
|
67
|
+
* This is useful for passthrough of pre-generated CAR files.
|
|
68
|
+
*/
|
|
69
|
+
async uploadCar(file, options) {
|
|
70
|
+
return this.uploadManager.uploadCar(file, options);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Pin existing content by CID.
|
|
74
|
+
*/
|
|
75
|
+
async pinByHash(cid, options) {
|
|
76
|
+
const cidObj = typeof cid === "string" ? multiformats_cid.CID.parse(cid) : cid;
|
|
77
|
+
return this.pins.add(cidObj, options);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* List pinned content.
|
|
81
|
+
*/
|
|
82
|
+
async listPins(options) {
|
|
83
|
+
const pins = [];
|
|
84
|
+
for await (const pin of this.pins.ls(options)) pins.push(pin);
|
|
85
|
+
return pins;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Get pin status.
|
|
89
|
+
*/
|
|
90
|
+
async getPinStatus(cid) {
|
|
91
|
+
const cidObj = typeof cid === "string" ? multiformats_cid.CID.parse(cid) : cid;
|
|
92
|
+
return this.pins.get(cidObj);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Check if content is pinned.
|
|
96
|
+
*/
|
|
97
|
+
async isPinned(cid) {
|
|
98
|
+
const cidObj = typeof cid === "string" ? multiformats_cid.CID.parse(cid) : cid;
|
|
99
|
+
return this.pins.isPinned(cidObj);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Update pin metadata.
|
|
103
|
+
*/
|
|
104
|
+
async setPinMetadata(cid, metadata) {
|
|
105
|
+
const cidObj = typeof cid === "string" ? multiformats_cid.CID.parse(cid) : cid;
|
|
106
|
+
return this.pins.setMetadata(cidObj, metadata);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Remove a pin. The block may be deleted when garbage collection is run.
|
|
110
|
+
*/
|
|
111
|
+
async unpin(cid, options) {
|
|
112
|
+
const cidObj = typeof cid === "string" ? multiformats_cid.CID.parse(cid) : cid;
|
|
113
|
+
const generator = this.pins.rm(cidObj, options);
|
|
114
|
+
for await (const _ of generator);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Destroy the client and cleanup resources.
|
|
118
|
+
*/
|
|
119
|
+
destroy() {
|
|
120
|
+
this.uploadManager.destroy();
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
//#endregion
|
|
125
|
+
exports.Pinner = Pinner;
|
|
126
|
+
//# sourceMappingURL=pinner.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pinner.cjs","names":["UploadManager","PinClient","createUploadBuilderNamespace","CID"],"sources":["../../src/pinner.ts"],"sourcesContent":["import type { PinnerConfig } from \"./config\";\nimport { UploadManager } from \"./upload\";\nimport { PinClient } from \"./pin\";\nimport type { UploadMethodAndBuilder } from \"@/upload/builder\";\nimport { createUploadBuilderNamespace } from \"@/upload/builder\";\nimport type {\n UploadOperation,\n UploadOptions,\n UploadResult,\n} from \"@/types/upload\";\nimport type { OperationPollingOptions } from \"@lumeweb/portal-sdk\";\nimport type {\n AbortOptions,\n RemoteAddOptions,\n RemoteLsOptions,\n RemotePin,\n RemotePins,\n} from \"@/types/pin\";\nimport { CID } from \"multiformats/cid\";\n\nexport class Pinner {\n private uploadManager: UploadManager;\n private _pins: RemotePins;\n private _upload?: UploadMethodAndBuilder;\n\n constructor(config: PinnerConfig) {\n this.uploadManager = new UploadManager(config);\n this._pins = new PinClient(config);\n }\n\n /**\n * Access the remote pins interface.\n */\n get pins(): RemotePins {\n return this._pins;\n }\n\n /**\n * Upload interface that works as both a method and a builder namespace.\n *\n * As a method: upload(file, options) -> UploadOperation\n * As a property: upload.file(), upload.json(), etc. -> Builder\n */\n get upload(): UploadMethodAndBuilder {\n if (!this._upload) {\n const builderNamespace = createUploadBuilderNamespace(this);\n const uploadMethod = async (\n file: File,\n options?: UploadOptions,\n ): Promise<UploadOperation> => {\n return this.uploadManager.upload(file, options);\n };\n\n this._upload = new Proxy(uploadMethod, {\n get(target, prop) {\n if (prop in builderNamespace) {\n return Reflect.get(builderNamespace, prop);\n }\n return Reflect.get(target, prop);\n },\n }) as UploadMethodAndBuilder;\n }\n return this._upload;\n }\n\n /**\n * Upload a file and wait for completion.\n * Convenience method for simple use cases where controls aren't needed.\n */\n async uploadAndWait(\n file: File,\n options?: UploadOptions,\n ): Promise<UploadResult> {\n const operation = await this.upload(file, options);\n return operation.result;\n }\n\n /**\n * Wait for an operation to complete or reach a settled state.\n * @param input Either an operation ID (number) or an UploadResult\n * @param options Polling options (interval, timeout, settledStates)\n * @returns UploadResult with operation status merged in\n */\n async waitForOperation(\n input: number | UploadResult,\n options?: OperationPollingOptions,\n ): Promise<UploadResult> {\n return this.uploadManager.waitForOperation(input, options);\n }\n\n /**\n * Upload a directory to IPFS.\n */\n async uploadDirectory(\n files: File[],\n options?: UploadOptions,\n ): Promise<UploadOperation> {\n return this.uploadManager.uploadDirectory(files, options);\n }\n\n /**\n * Upload a CAR file without preprocessing.\n * This is useful for passthrough of pre-generated CAR files.\n */\n async uploadCar(\n file: File | ReadableStream<Uint8Array>,\n options?: UploadOptions,\n ): Promise<UploadOperation> {\n return this.uploadManager.uploadCar(file, options);\n }\n\n /**\n * Pin existing content by CID.\n */\n async pinByHash(\n cid: string | CID,\n options?: RemoteAddOptions,\n ): Promise<AsyncGenerator<CID, void, undefined>> {\n const cidObj = typeof cid === \"string\" ? CID.parse(cid) : cid;\n return this.pins.add(cidObj, options);\n }\n\n /**\n * List pinned content.\n */\n async listPins(options?: RemoteLsOptions): Promise<RemotePin[]> {\n const pins: RemotePin[] = [];\n for await (const pin of this.pins.ls(options)) {\n pins.push(pin);\n }\n return pins;\n }\n\n /**\n * Get pin status.\n */\n async getPinStatus(cid: string | CID): Promise<RemotePin> {\n const cidObj = typeof cid === \"string\" ? CID.parse(cid) : cid;\n return this.pins.get(cidObj);\n }\n\n /**\n * Check if content is pinned.\n */\n async isPinned(cid: string | CID): Promise<boolean> {\n const cidObj = typeof cid === \"string\" ? CID.parse(cid) : cid;\n return this.pins.isPinned(cidObj);\n }\n\n /**\n * Update pin metadata.\n */\n async setPinMetadata(\n cid: string | CID,\n metadata: Record<string, string> | undefined,\n ): Promise<void> {\n const cidObj = typeof cid === \"string\" ? CID.parse(cid) : cid;\n return this.pins.setMetadata(cidObj, metadata);\n }\n\n /**\n * Remove a pin. The block may be deleted when garbage collection is run.\n */\n async unpin(cid: string | CID, options?: AbortOptions): Promise<void> {\n const cidObj = typeof cid === \"string\" ? CID.parse(cid) : cid;\n const generator = this.pins.rm(cidObj, options);\n for await (const _ of generator) {\n // Consume the generator to complete the unpin operation\n }\n }\n\n /**\n * Destroy the client and cleanup resources.\n */\n destroy(): void {\n this.uploadManager.destroy();\n }\n}\n"],"mappings":";;;;;;;;;AAoBA,IAAa,SAAb,MAAoB;CAClB,AAAQ;CACR,AAAQ;CACR,AAAQ;CAER,YAAY,QAAsB;AAChC,OAAK,gBAAg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OAAO;;;;;CAM9B,MAAM,SAAS,KAAqC;EAClD,MAAM,SAAS,OAAO,QAAQ,WAAWA,qBAAI,MAAM,IAAI,GAAG;AAC1D,SAAO,KAAK,KAAK,SAAS,OAAO;;;;;CAMnC,MAAM,eACJ,KACA,UACe;EACf,MAAM,SAAS,OAAO,QAAQ,WAAWA,qBAAI,MAAM,IAAI,GAAG;AAC1D,SAAO,KAAK,KAAK,YAAY,QAAQ,SAAS;;;;;CAMhD,MAAM,MAAM,KAAmB,SAAuC;EACpE,MAAM,SAAS,OAAO,QAAQ,WAAWA,qBAAI,MAAM,IAAI,GAAG;EAC1D,MAAM,YAAY,KAAK,KAAK,GAAG,QAAQ,QAAQ;AAC/C,aAAW,MAAM,KAAK;;;;;CAQxB,UAAgB;AACd,OAAK,cAAc,SAAS"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { PinnerConfig } from "./config.cjs";
|
|
2
|
+
import { UploadOperation, UploadOptions, UploadResult } from "./types/upload.cjs";
|
|
3
|
+
import { UploadMethodAndBuilder } from "./upload/builder.cjs";
|
|
4
|
+
import { AbortOptions, RemoteAddOptions, RemoteLsOptions, RemotePin, RemotePins } from "./types/pin.cjs";
|
|
5
|
+
import { OperationPollingOptions } from "@lumeweb/portal-sdk";
|
|
6
|
+
import { CID } from "multiformats/cid";
|
|
7
|
+
|
|
8
|
+
//#region src/pinner.d.ts
|
|
9
|
+
declare class Pinner {
|
|
10
|
+
private uploadManager;
|
|
11
|
+
private _pins;
|
|
12
|
+
private _upload?;
|
|
13
|
+
constructor(config: PinnerConfig);
|
|
14
|
+
/**
|
|
15
|
+
* Access the remote pins interface.
|
|
16
|
+
*/
|
|
17
|
+
get pins(): RemotePins;
|
|
18
|
+
/**
|
|
19
|
+
* Upload interface that works as both a method and a builder namespace.
|
|
20
|
+
*
|
|
21
|
+
* As a method: upload(file, options) -> UploadOperation
|
|
22
|
+
* As a property: upload.file(), upload.json(), etc. -> Builder
|
|
23
|
+
*/
|
|
24
|
+
get upload(): UploadMethodAndBuilder;
|
|
25
|
+
/**
|
|
26
|
+
* Upload a file and wait for completion.
|
|
27
|
+
* Convenience method for simple use cases where controls aren't needed.
|
|
28
|
+
*/
|
|
29
|
+
uploadAndWait(file: File, options?: UploadOptions): Promise<UploadResult>;
|
|
30
|
+
/**
|
|
31
|
+
* Wait for an operation to complete or reach a settled state.
|
|
32
|
+
* @param input Either an operation ID (number) or an UploadResult
|
|
33
|
+
* @param options Polling options (interval, timeout, settledStates)
|
|
34
|
+
* @returns UploadResult with operation status merged in
|
|
35
|
+
*/
|
|
36
|
+
waitForOperation(input: number | UploadResult, options?: OperationPollingOptions): Promise<UploadResult>;
|
|
37
|
+
/**
|
|
38
|
+
* Upload a directory to IPFS.
|
|
39
|
+
*/
|
|
40
|
+
uploadDirectory(files: File[], options?: UploadOptions): Promise<UploadOperation>;
|
|
41
|
+
/**
|
|
42
|
+
* Upload a CAR file without preprocessing.
|
|
43
|
+
* This is useful for passthrough of pre-generated CAR files.
|
|
44
|
+
*/
|
|
45
|
+
uploadCar(file: File | ReadableStream<Uint8Array>, options?: UploadOptions): Promise<UploadOperation>;
|
|
46
|
+
/**
|
|
47
|
+
* Pin existing content by CID.
|
|
48
|
+
*/
|
|
49
|
+
pinByHash(cid: string | CID, options?: RemoteAddOptions): Promise<AsyncGenerator<CID, void, undefined>>;
|
|
50
|
+
/**
|
|
51
|
+
* List pinned content.
|
|
52
|
+
*/
|
|
53
|
+
listPins(options?: RemoteLsOptions): Promise<RemotePin[]>;
|
|
54
|
+
/**
|
|
55
|
+
* Get pin status.
|
|
56
|
+
*/
|
|
57
|
+
getPinStatus(cid: string | CID): Promise<RemotePin>;
|
|
58
|
+
/**
|
|
59
|
+
* Check if content is pinned.
|
|
60
|
+
*/
|
|
61
|
+
isPinned(cid: string | CID): Promise<boolean>;
|
|
62
|
+
/**
|
|
63
|
+
* Update pin metadata.
|
|
64
|
+
*/
|
|
65
|
+
setPinMetadata(cid: string | CID, metadata: Record<string, string> | undefined): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Remove a pin. The block may be deleted when garbage collection is run.
|
|
68
|
+
*/
|
|
69
|
+
unpin(cid: string | CID, options?: AbortOptions): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Destroy the client and cleanup resources.
|
|
72
|
+
*/
|
|
73
|
+
destroy(): void;
|
|
74
|
+
}
|
|
75
|
+
//#endregion
|
|
76
|
+
export { Pinner };
|
|
77
|
+
//# sourceMappingURL=pinner.d.cts.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/types/constants.ts
|
|
3
|
+
/**
|
|
4
|
+
* Default API endpoint URL for the pinning service.
|
|
5
|
+
*/
|
|
6
|
+
const DEFAULT_ENDPOINT = "https://api.lumeweb.com";
|
|
7
|
+
/**
|
|
8
|
+
* Default TUS upload size threshold (100MB).
|
|
9
|
+
* Files larger than this will use TUS protocol for resumable uploads.
|
|
10
|
+
*/
|
|
11
|
+
const TUS_SIZE_THRESHOLD = 100 * 1024 * 1024;
|
|
12
|
+
/**
|
|
13
|
+
* Default key prefix for blockstore keys.
|
|
14
|
+
* This is prepended to CID strings in storage keys.
|
|
15
|
+
*/
|
|
16
|
+
const DEFAULT_BLOCKSTORE_PREFIX = "pinner-helia-blocks";
|
|
17
|
+
/**
|
|
18
|
+
* Default base path for blockstore storage driver.
|
|
19
|
+
* For IndexedDB: "pinner:" - the database name prefix
|
|
20
|
+
* For filesystem: "./.pinner-blocks" - the directory path
|
|
21
|
+
*/
|
|
22
|
+
const DEFAULT_BLOCKSTORE_BASE = "pinner:";
|
|
23
|
+
/**
|
|
24
|
+
* Default base path for blockstore filesystem storage driver (Node.js).
|
|
25
|
+
*/
|
|
26
|
+
const DEFAULT_BLOCKSTORE_FS_BASE = "./.pinner-blocks";
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
exports.DEFAULT_BLOCKSTORE_BASE = DEFAULT_BLOCKSTORE_BASE;
|
|
30
|
+
exports.DEFAULT_BLOCKSTORE_FS_BASE = DEFAULT_BLOCKSTORE_FS_BASE;
|
|
31
|
+
exports.DEFAULT_BLOCKSTORE_PREFIX = DEFAULT_BLOCKSTORE_PREFIX;
|
|
32
|
+
exports.DEFAULT_ENDPOINT = DEFAULT_ENDPOINT;
|
|
33
|
+
exports.TUS_SIZE_THRESHOLD = TUS_SIZE_THRESHOLD;
|
|
34
|
+
//# sourceMappingURL=constants.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.cjs","names":[],"sources":["../../../src/types/constants.ts"],"sourcesContent":["/**\n * Default API endpoint URL for the pinning service.\n */\nexport const DEFAULT_ENDPOINT = \"https://api.lumeweb.com\";\n\n/**\n * Default IPFS gateway URL for content retrieval.\n */\nexport const DEFAULT_GATEWAY = \"https://gateway.lumeweb.com\";\n\n/**\n * Default TUS upload size threshold (100MB).\n * Files larger than this will use TUS protocol for resumable uploads.\n */\nexport const TUS_SIZE_THRESHOLD = 100 * 1024 * 1024;\n\n/**\n * Default base path for Helia datastore storage.\n */\nexport const DEFAULT_DATASTORE_BASE = \"pinner-helia-data\";\n\n/**\n * Default key prefix for blockstore keys.\n * This is prepended to CID strings in storage keys.\n */\nexport const DEFAULT_BLOCKSTORE_PREFIX = \"pinner-helia-blocks\";\n\n/**\n * Default base path for blockstore storage driver.\n * For IndexedDB: \"pinner:\" - the database name prefix\n * For filesystem: \"./.pinner-blocks\" - the directory path\n */\nexport const DEFAULT_BLOCKSTORE_BASE = \"pinner:\";\n\n/**\n * Default base path for blockstore filesystem storage driver (Node.js).\n */\nexport const DEFAULT_BLOCKSTORE_FS_BASE = \"./.pinner-blocks\";\n\n/**\n * Default base path for datastore filesystem storage driver (Node.js).\n */\nexport const DEFAULT_DATASTORE_FS_BASE = \"./.pinner-data\";\n"],"mappings":";;;;;AAGA,MAAa,mBAAmB;;;;;AAWhC,MAAa,qBAAqB,MAAM,OAAO;;;;;AAW/C,MAAa,4BAA4B;;;;;;AAOzC,MAAa,0BAA0B;;;;AAKvC,MAAa,6BAA6B"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/types/mime-types.ts
|
|
3
|
+
const MIME_TYPE_CAR = "application/vnd.ipld.car";
|
|
4
|
+
const MIME_TYPE_OCTET_STREAM = "application/octet-stream";
|
|
5
|
+
const FILE_EXTENSION_CAR = ".car";
|
|
6
|
+
|
|
7
|
+
//#endregion
|
|
8
|
+
exports.FILE_EXTENSION_CAR = FILE_EXTENSION_CAR;
|
|
9
|
+
exports.MIME_TYPE_CAR = MIME_TYPE_CAR;
|
|
10
|
+
exports.MIME_TYPE_OCTET_STREAM = MIME_TYPE_OCTET_STREAM;
|
|
11
|
+
//# sourceMappingURL=mime-types.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mime-types.cjs","names":[],"sources":["../../../src/types/mime-types.ts"],"sourcesContent":["export const MIME_TYPE_CAR = \"application/vnd.ipld.car\";\nexport const MIME_TYPE_OCTET_STREAM = \"application/octet-stream\";\nexport const FILE_EXTENSION_CAR = \".car\";\n"],"mappings":";;AAAA,MAAa,gBAAgB;AAC7B,MAAa,yBAAyB;AACtC,MAAa,qBAAqB"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
//#region src/types/mime-types.d.ts
|
|
2
|
+
declare const MIME_TYPE_CAR = "application/vnd.ipld.car";
|
|
3
|
+
declare const MIME_TYPE_OCTET_STREAM = "application/octet-stream";
|
|
4
|
+
declare const FILE_EXTENSION_CAR = ".car";
|
|
5
|
+
//#endregion
|
|
6
|
+
export { FILE_EXTENSION_CAR, MIME_TYPE_CAR, MIME_TYPE_OCTET_STREAM };
|
|
7
|
+
//# sourceMappingURL=mime-types.d.cts.map
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { CID } from "multiformats/cid";
|
|
2
|
+
import { Status } from "@ipfs-shipyard/pinning-service-client";
|
|
3
|
+
|
|
4
|
+
//#region src/types/pin.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Options that can be passed to abort async operations
|
|
8
|
+
*/
|
|
9
|
+
interface AbortOptions {
|
|
10
|
+
signal?: AbortSignal;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Allows passing extra options accepted by the remote pinning service
|
|
14
|
+
*/
|
|
15
|
+
interface RemoteAddOptions extends AbortOptions {
|
|
16
|
+
name?: string;
|
|
17
|
+
metadata?: Record<string, string>;
|
|
18
|
+
origins?: string[];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Allows passing extra options accepted by the remote pinning service
|
|
22
|
+
*/
|
|
23
|
+
interface RemoteLsOptions extends AbortOptions {
|
|
24
|
+
name?: string;
|
|
25
|
+
status?: Status[];
|
|
26
|
+
limit?: number;
|
|
27
|
+
cursor?: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Includes extra metadata supported by the remote pinning service
|
|
31
|
+
*/
|
|
32
|
+
interface RemotePin {
|
|
33
|
+
cid: CID;
|
|
34
|
+
name?: string;
|
|
35
|
+
status: Status;
|
|
36
|
+
created: Date;
|
|
37
|
+
size?: number;
|
|
38
|
+
metadata?: Record<string, string>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Extends the Pins interface with remote pinning-specific arguments and return
|
|
42
|
+
* types (e.g. metadata as `Record<string, string>` and pins with an added
|
|
43
|
+
* `.status` property)
|
|
44
|
+
*/
|
|
45
|
+
interface RemotePins {
|
|
46
|
+
/**
|
|
47
|
+
* Pin a block in the blockstore. It will not be deleted
|
|
48
|
+
* when garbage collection is run.
|
|
49
|
+
*/
|
|
50
|
+
add(cid: CID, options?: RemoteAddOptions): AsyncGenerator<CID, void, undefined>;
|
|
51
|
+
/**
|
|
52
|
+
* List all blocks that have been pinned.
|
|
53
|
+
*/
|
|
54
|
+
ls(options?: RemoteLsOptions): AsyncGenerator<RemotePin, void, undefined>;
|
|
55
|
+
/**
|
|
56
|
+
* Return true if the passed CID is pinned
|
|
57
|
+
*/
|
|
58
|
+
isPinned(cid: CID, options?: AbortOptions): Promise<boolean>;
|
|
59
|
+
/**
|
|
60
|
+
* Return pin details
|
|
61
|
+
*/
|
|
62
|
+
get(cid: CID, options?: AbortOptions): Promise<RemotePin>;
|
|
63
|
+
/**
|
|
64
|
+
* Update pin metadata
|
|
65
|
+
*/
|
|
66
|
+
setMetadata(cid: CID, metadata: Record<string, string> | undefined, options?: AbortOptions): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Remove a pin. The block may be deleted when garbage collection is run.
|
|
69
|
+
*/
|
|
70
|
+
rm(cid: CID, options?: AbortOptions): AsyncGenerator<CID, void, undefined>;
|
|
71
|
+
}
|
|
72
|
+
//#endregion
|
|
73
|
+
export { AbortOptions, RemoteAddOptions, RemoteLsOptions, RemotePin, RemotePins };
|
|
74
|
+
//# sourceMappingURL=pin.d.cts.map
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
//#region src/types/pinata.d.ts
|
|
2
|
+
interface PinataUploadResult {
|
|
3
|
+
/**
|
|
4
|
+
* IPFS CID.
|
|
5
|
+
*/
|
|
6
|
+
IpfsHash: string;
|
|
7
|
+
/**
|
|
8
|
+
* Pin size in bytes.
|
|
9
|
+
*/
|
|
10
|
+
PinSize: number;
|
|
11
|
+
/**
|
|
12
|
+
* Timestamp of upload.
|
|
13
|
+
*/
|
|
14
|
+
Timestamp: string;
|
|
15
|
+
/**
|
|
16
|
+
* Whether content was pinned.
|
|
17
|
+
*/
|
|
18
|
+
isDuplicate: boolean;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Base metadata options - shared across upload and pin operations.
|
|
22
|
+
*/
|
|
23
|
+
interface PinataMetadataOptions {
|
|
24
|
+
name?: string;
|
|
25
|
+
keyvalues?: Record<string, string>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Generic upload builder interface.
|
|
29
|
+
* All upload methods return this builder with different result types.
|
|
30
|
+
*/
|
|
31
|
+
interface PinataUploadBuilder<T = PinataUploadResult> {
|
|
32
|
+
name(name: string): this;
|
|
33
|
+
keyvalues(kv: Record<string, string>): this;
|
|
34
|
+
execute(): Promise<T>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Options for pinning content by CID.
|
|
38
|
+
*/
|
|
39
|
+
interface PinByHashOptions extends PinataMetadataOptions {}
|
|
40
|
+
/**
|
|
41
|
+
* Pin information (Pinata SDK format).
|
|
42
|
+
* Note: This differs from RemotePin (@ipfs-shipyard/pinning-service-client format).
|
|
43
|
+
*/
|
|
44
|
+
interface PinataPin {
|
|
45
|
+
id: string;
|
|
46
|
+
ipfsPinHash: string;
|
|
47
|
+
size: number;
|
|
48
|
+
userId: string;
|
|
49
|
+
datePinned: string;
|
|
50
|
+
dateUnpinned?: string;
|
|
51
|
+
metadata?: PinataMetadata;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* File information (Pinata SDK format).
|
|
55
|
+
*/
|
|
56
|
+
interface PinataFile {
|
|
57
|
+
id: string;
|
|
58
|
+
ipfsPinHash: string;
|
|
59
|
+
size: number;
|
|
60
|
+
name: string;
|
|
61
|
+
cid: string;
|
|
62
|
+
createdAt: string;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* List builder interface for listing pins.
|
|
66
|
+
* Uses cursor-based pagination compatible with Pinata SDK.
|
|
67
|
+
*/
|
|
68
|
+
interface PinataListBuilder<T = PinataFile[]> {
|
|
69
|
+
limit(limit: number): this;
|
|
70
|
+
pageToken(pageToken: string): this;
|
|
71
|
+
execute(): Promise<T>;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Pin metadata.
|
|
75
|
+
*/
|
|
76
|
+
interface PinataMetadata extends PinataMetadataOptions {}
|
|
77
|
+
/**
|
|
78
|
+
* File information.
|
|
79
|
+
*/
|
|
80
|
+
interface PinataFile {
|
|
81
|
+
id: string;
|
|
82
|
+
ipfsPinHash: string;
|
|
83
|
+
size: number;
|
|
84
|
+
name: string;
|
|
85
|
+
mimeType?: string;
|
|
86
|
+
cid: string;
|
|
87
|
+
createdAt: string;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Generic list builder interface.
|
|
91
|
+
*/
|
|
92
|
+
interface PinataListBuilder<T> {
|
|
93
|
+
limit(limit: number): this;
|
|
94
|
+
offset(offset: number): this;
|
|
95
|
+
execute(): Promise<T>;
|
|
96
|
+
}
|
|
97
|
+
//#endregion
|
|
98
|
+
export { PinByHashOptions, PinataFile, PinataListBuilder, PinataPin, PinataUploadBuilder, PinataUploadResult };
|
|
99
|
+
//# sourceMappingURL=pinata.d.cts.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const require_index = require('../errors/index.cjs');
|
|
2
|
+
|
|
3
|
+
//#region src/types/type-guards.ts
|
|
4
|
+
/**
|
|
5
|
+
* Check if error is retryable.
|
|
6
|
+
*/
|
|
7
|
+
function isRetryable(error) {
|
|
8
|
+
return error.retryable;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Check if error is authentication-related.
|
|
12
|
+
*/
|
|
13
|
+
function isAuthenticationError(error) {
|
|
14
|
+
return error instanceof require_index.PinnerError && error.code === "AUTHENTICATION_ERROR";
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
exports.isAuthenticationError = isAuthenticationError;
|
|
19
|
+
exports.isRetryable = isRetryable;
|
|
20
|
+
//# sourceMappingURL=type-guards.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-guards.cjs","names":["PinnerError"],"sources":["../../../src/types/type-guards.ts"],"sourcesContent":["import { PinnerError } from \"../errors\";\n\n/**\n * Check if error is retryable.\n */\nexport function isRetryable(error: PinnerError): boolean {\n return error.retryable;\n}\n\n/**\n * Check if error is authentication-related.\n */\nexport function isAuthenticationError(error: PinnerError): boolean {\n return error instanceof PinnerError && error.code === \"AUTHENTICATION_ERROR\";\n}\n"],"mappings":";;;;;;AAKA,SAAgB,YAAY,OAA6B;AACvD,QAAO,MAAM;;;;;AAMf,SAAgB,sBAAsB,OAA6B;AACjE,QAAO,iBAAiBA,6BAAe,MAAM,SAAS"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { PinnerError } from "../errors/index.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/types/type-guards.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Check if error is retryable.
|
|
7
|
+
*/
|
|
8
|
+
declare function isRetryable(error: PinnerError): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Check if error is authentication-related.
|
|
11
|
+
*/
|
|
12
|
+
declare function isAuthenticationError(error: PinnerError): boolean;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { isAuthenticationError, isRetryable };
|
|
15
|
+
//# sourceMappingURL=type-guards.d.cts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/types/upload.ts
|
|
3
|
+
/**
|
|
4
|
+
* Symbol used to brand UploadResult for type checking
|
|
5
|
+
*/
|
|
6
|
+
const UploadResultSymbol = Symbol("UploadResult");
|
|
7
|
+
/**
|
|
8
|
+
* Type guard to check if a value is an UploadResult
|
|
9
|
+
* Uses the UploadResultSymbol for reliable type checking
|
|
10
|
+
*/
|
|
11
|
+
function isUploadResult(value) {
|
|
12
|
+
return typeof value === "object" && value !== null && UploadResultSymbol in value && value[UploadResultSymbol] === true;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
exports.UploadResultSymbol = UploadResultSymbol;
|
|
17
|
+
exports.isUploadResult = isUploadResult;
|
|
18
|
+
//# sourceMappingURL=upload.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upload.cjs","names":[],"sources":["../../../src/types/upload.ts"],"sourcesContent":["import type { OperationPollingOptions } from \"@lumeweb/portal-sdk\";\n\n/**\n * Symbol used to brand UploadResult for type checking\n */\nexport const UploadResultSymbol = Symbol(\"UploadResult\");\n\nexport interface UploadResult {\n /**\n * Unique identifier for this upload operation.\n */\n id: string;\n\n /**\n * IPFS Content Identifier for the uploaded content.\n */\n cid: string;\n\n /**\n * User-provided or auto-generated name for the content.\n */\n name: string;\n\n /**\n * Total size in bytes.\n */\n size: number;\n\n /**\n * MIME type of the content.\n */\n mimeType: string;\n\n /**\n * ISO timestamp when content was created.\n */\n createdAt: Date;\n\n /**\n * Number of files (1 for single file, N for directory).\n */\n numberOfFiles: number;\n\n /**\n * Custom key-value metadata.\n */\n keyvalues?: Record<string, string>;\n\n /**\n * Whether this upload is a directory.\n */\n isDirectory?: boolean;\n\n /**\n * Whether this upload is already a valid CAR file.\n * If true, the upload system will skip CAR preprocessing and upload the file as-is.\n * Useful for passthrough of pre-generated CAR files.\n */\n isCarFile?: boolean;\n\n /**\n * Portal operation ID for tracking the pinning operation.\n * Can be used with waitForOperation() to wait for the operation to complete.\n */\n operationId?: number;\n\n /**\n * Symbol brand for type checking - used to identify UploadResult objects\n */\n [UploadResultSymbol]?: true;\n}\n\nexport type UploadInput = File | ReadableStream<Uint8Array>;\n\n/**\n * Type guard to check if a value is an UploadResult\n * Uses the UploadResultSymbol for reliable type checking\n */\nexport function isUploadResult(value: unknown): value is UploadResult {\n return (\n typeof value === \"object\" &&\n value !== null &&\n UploadResultSymbol in value &&\n value[UploadResultSymbol] === true\n );\n}\n\nexport interface UploadOptions {\n /**\n * Name for the uploaded content.\n */\n name?: string;\n\n /**\n * Custom key-value metadata.\n */\n keyvalues?: Record<string, string>;\n\n /**\n * Progress callback invoked during upload.\n */\n onProgress?: (progress: UploadProgress) => void;\n\n /**\n * Callback invoked when upload completes successfully.\n */\n onComplete?: (result: UploadResult) => void;\n\n /**\n * Callback invoked when upload fails.\n */\n onError?: (error: Error) => void;\n\n /**\n * AbortSignal for cancellation.\n */\n signal?: AbortSignal;\n\n /**\n * Optional size override for the upload input.\n * Useful for ReadableStream inputs where size detection is difficult.\n */\n size?: number;\n\n /**\n * Whether this upload is a directory.\n */\n isDirectory?: boolean;\n\n /**\n * Whether this upload is already a valid CAR file.\n * If true, the upload system will skip CAR preprocessing and upload the file as-is.\n * Useful for passthrough of pre-generated CAR files.\n */\n isCarFile?: boolean;\n\n /**\n * Whether to wait for the pinning operation to complete/fail.\n * When true, the upload will block until the operation reaches a settled state\n * (completed, failed, or error). Default is false (upload only).\n */\n waitForOperation?: boolean;\n\n /**\n * Polling options for waiting on operation completion.\n * Only used when waitForOperation is true.\n */\n operationPollingOptions?: OperationPollingOptions;\n}\n\nexport interface UploadProgress {\n /**\n * Percentage complete (0-100).\n */\n percentage: number;\n\n /**\n * Number of bytes uploaded.\n */\n bytesUploaded: number;\n\n /**\n * Total bytes to upload.\n */\n bytesTotal: number;\n\n /**\n * Upload speed in bytes per second.\n */\n speed?: number;\n\n /**\n * Estimated time remaining in seconds.\n */\n eta?: number;\n}\n\nexport interface UploadOperation {\n /**\n * Cancel the ongoing upload.\n */\n cancel(): void;\n\n /**\n * Pause the upload (TUS only).\n */\n pause(): void;\n\n /**\n * Resume a paused upload (TUS only).\n */\n resume(): void;\n\n /**\n * Promise that resolves when upload completes.\n */\n result: Promise<UploadResult>;\n\n /**\n * Current progress.\n */\n progress: Readonly<UploadProgress>;\n}\n\n/**\n * Builder interface for Pinner upload API.\n * Supports chaining name/keyvalues and returns UploadOperation with controls.\n */\nexport interface PinnerUploadBuilder {\n /**\n * Set the name for the upload.\n */\n name(name: string): this;\n\n /**\n * Set custom key-value metadata.\n */\n keyvalues(kv: Record<string, string>): this;\n\n /**\n * Whether to wait for the pinning operation to complete/fail.\n * When true, the upload will block until the operation reaches a settled state.\n */\n waitForOperation(wait: boolean): this;\n\n /**\n * Set polling options for waiting on operation completion.\n * Only used when waitForOperation is true.\n */\n operationPollingOptions(options: OperationPollingOptions): this;\n\n /**\n * Start the upload and return UploadOperation with controls.\n */\n pin(): Promise<UploadOperation>;\n}\n"],"mappings":";;;;;AAKA,MAAa,qBAAqB,OAAO,eAAe;;;;;AAyExD,SAAgB,eAAe,OAAuC;AACpE,QACE,OAAO,UAAU,YACjB,UAAU,QACV,sBAAsB,SACtB,MAAM,wBAAwB"}
|