turborepo-remote-cache 1.6.7 → 1.7.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/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  ![Turborepo Remote Cache](https://user-images.githubusercontent.com/6388707/149501949-9a385f04-ec94-45f4-9ea9-d211be123071.png)
2
2
 
3
- ![GitHub package.json version](https://img.shields.io/github/package-json/v/ducktors/turborepo-remote-cache) [![CI](https://github.com/ducktors/turborepo-remote-cache/actions/workflows/build.yml/badge.svg)](https://github.com/ducktors/turborepo-remote-cache/actions/workflows/build.yml) [![Release](https://github.com/ducktors/turborepo-remote-cache/actions/workflows/release.yml/badge.svg)](https://github.com/ducktors/turborepo-remote-cache/actions/workflows/release.yml) [![Docker](https://github.com/ducktors/turborepo-remote-cache/actions/workflows/docker.yml/badge.svg)](https://github.com/ducktors/turborepo-remote-cache/actions/workflows/docker.yml) [![Coverage Status](https://coveralls.io/repos/github/ducktors/turborepo-remote-cache/badge.svg?branch=main)](https://coveralls.io/github/ducktors/turborepo-remote-cache?branch=main) [![Docker Pulls](https://img.shields.io/docker/pulls/fox1t/turborepo-remote-cache?logo=docker)](https://hub.docker.com/r/fox1t/turborepo-remote-cache) [![npm](https://img.shields.io/npm/dt/turborepo-remote-cache)]([https://img.shields.io/npm/dt/turborepo-remote-cache](https://www.npmjs.com/package/turborepo-remote-cache)) <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
4
- [![All Contributors](https://img.shields.io/badge/all_contributors-6-orange.svg?style=flat-square)](#contributors-)
3
+ ![GitHub package.json version](https://img.shields.io/github/package-json/v/ducktors/turborepo-remote-cache) [![CI](https://github.com/ducktors/turborepo-remote-cache/actions/workflows/build.yml/badge.svg)](https://github.com/ducktors/turborepo-remote-cache/actions/workflows/build.yml) [![Release](https://github.com/ducktors/turborepo-remote-cache/actions/workflows/release.yml/badge.svg)](https://github.com/ducktors/turborepo-remote-cache/actions/workflows/release.yml) [![Docker](https://github.com/ducktors/turborepo-remote-cache/actions/workflows/docker.yml/badge.svg)](https://github.com/ducktors/turborepo-remote-cache/actions/workflows/docker.yml) [![Coverage Status](https://coveralls.io/repos/github/ducktors/turborepo-remote-cache/badge.svg?branch=main)](https://coveralls.io/github/ducktors/turborepo-remote-cache?branch=main) [![Docker Pulls](https://img.shields.io/docker/pulls/fox1t/turborepo-remote-cache?logo=docker)](https://hub.docker.com/r/fox1t/turborepo-remote-cache) [![npm](https://img.shields.io/npm/dt/turborepo-remote-cache)]([https://img.shields.io/npm/dt/turborepo-remote-cache](https://www.npmjs.com/package/turborepo-remote-cache)) [![semantic-release: angular](https://img.shields.io/badge/semantic--release-angular-e10079?logo=semantic-release)](https://github.com/semantic-release/semantic-release) <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
4
+ [![All Contributors](https://img.shields.io/badge/all_contributors-9-orange.svg?style=flat-square)](#contributors-)
5
5
  <!-- ALL-CONTRIBUTORS-BADGE:END -->
6
6
 
7
7
 
@@ -45,6 +45,16 @@ It supports several storage providers and deploys environments. Moreover, the pr
45
45
 
46
46
  ```npm run dev```
47
47
 
48
+ ## How to commit
49
+
50
+ This repo uses [Semantic Release](https://github.com/semantic-release/semantic-release) with Conventional Commits.
51
+ Releases are automatically created based on the type of commit message: feat for minor and fix for patch.
52
+
53
+ ```
54
+ feat: new feature ---> 1.x.0
55
+ fix: fix a bug ---> 1.0.x
56
+ ```
57
+
48
58
  ## Contributors
49
59
 
50
60
  <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
@@ -59,6 +69,11 @@ It supports several storage providers and deploys environments. Moreover, the pr
59
69
  <td align="center"><a href="https://github.com/lodmfjord"><img src="https://avatars.githubusercontent.com/u/5091589?v=4?s=100" width="100px;" alt="lommi"/><br /><sub><b>lommi</b></sub></a><br /><a href="https://github.com/ducktors/turborepo-remote-cache/commits?author=lodmfjord" title="Code">💻</a></td>
60
70
  <td align="center"><a href="https://www.brianmuenzenmeyer.com"><img src="https://avatars.githubusercontent.com/u/298435?v=4?s=100" width="100px;" alt="Brian Muenzenmeyer"/><br /><sub><b>Brian Muenzenmeyer</b></sub></a><br /><a href="https://github.com/ducktors/turborepo-remote-cache/commits?author=bmuenzenmeyer" title="Documentation">📖</a></td>
61
71
  <td align="center"><a href="http://dobesv.com"><img src="https://avatars.githubusercontent.com/u/327833?v=4?s=100" width="100px;" alt="Dobes Vandermeer"/><br /><sub><b>Dobes Vandermeer</b></sub></a><br /><a href="https://github.com/ducktors/turborepo-remote-cache/commits?author=dobesv" title="Code">💻</a></td>
72
+ <td align="center"><a href="http://tanzigang.com"><img src="https://avatars.githubusercontent.com/u/11520821?v=4?s=100" width="100px;" alt="Tan Zi Gang"/><br /><sub><b>Tan Zi Gang</b></sub></a><br /><a href="https://github.com/ducktors/turborepo-remote-cache/commits?author=zigang93" title="Code">💻</a></td>
73
+ </tr>
74
+ <tr>
75
+ <td align="center"><a href="https://github.com/jgoz"><img src="https://avatars.githubusercontent.com/u/132233?v=4?s=100" width="100px;" alt="John Gozde"/><br /><sub><b>John Gozde</b></sub></a><br /><a href="https://github.com/ducktors/turborepo-remote-cache/commits?author=jgoz" title="Code">💻</a></td>
76
+ <td align="center"><a href="https://github.com/sppatel"><img src="https://avatars.githubusercontent.com/u/989367?v=4?s=100" width="100px;" alt="Sachin Patel"/><br /><sub><b>Sachin Patel</b></sub></a><br /><a href="https://github.com/ducktors/turborepo-remote-cache/commits?author=sppatel" title="Code">💻</a></td>
62
77
  </tr>
63
78
  </tbody>
64
79
  </table>
@@ -36,6 +36,7 @@ async function turboRemoteCache(instance, options) {
36
36
  }));
37
37
  await instance.register(async function (i) {
38
38
  i.route(routes_1.getArtifact);
39
+ i.route(routes_1.headArtifact);
39
40
  i.route(routes_1.putArtifact);
40
41
  i.route(routes_1.artifactsEvents);
41
42
  }, { prefix: `/${apiVersion}` });
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../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C,CAAA;SAClD;IACH,CAAC,CAAC,CAAA;IAEF,QAAQ,CAAC,QAAQ,CACf,UAAU,EACV,IAAA,wBAAc,EAAC,QAAQ,EAAE;QACvB,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,aAAa;QACxC,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,aAAa;QACxC,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,YAAY;QAClC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,SAAS;QACjC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,WAAW;QACrC,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,gBAAgB;QAC7C,UAAU,EAAE,QAAQ,CAAC,MAAM,CAAC,eAAe;QAC3C,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,cAAc;KAC1C,CAAC,CACH,CAAA;IAED,MAAM,QAAQ,CAAC,QAAQ,CACrB,KAAK,WAAW,CAAC;QACf,CAAC,CAAC,KAAK,CAAC,oBAAW,CAAC,CAAA;QACpB,CAAC,CAAC,KAAK,CAAC,oBAAW,CAAC,CAAA;QACpB,CAAC,CAAC,KAAK,CAAC,wBAAe,CAAC,CAAA;IAC1B,CAAC,EACD,EAAE,MAAM,EAAE,IAAI,UAAU,EAAE,EAAE,CAC7B,CAAA;AACH,CAAC;AAED,kBAAe,gBAAgB,CAAA","sourcesContent":["import { FastifyInstance } from 'fastify'\nimport { badRequest, unauthorized } from '@hapi/boom'\nimport { getArtifact, putArtifact, artifactsEvents } from './routes'\nimport { createLocation } from './storage'\nimport { STORAGE_PROVIDERS } from '../../env'\n\nasync function turboRemoteCache(\n instance: FastifyInstance,\n options: {\n allowedTokens: string[]\n bodyLimit?: number\n apiVersion?: `v${number}`\n provider?: STORAGE_PROVIDERS\n },\n) {\n const {\n allowedTokens,\n bodyLimit = 104857600,\n apiVersion = 'v8',\n provider = STORAGE_PROVIDERS.LOCAL,\n } = options\n if (!(Array.isArray(allowedTokens) && allowedTokens.length)) {\n throw new Error(\n `'allowedTokens' options must be a string[], ${typeof allowedTokens} provided instead`,\n )\n }\n\n instance.addContentTypeParser<Buffer>(\n 'application/octet-stream',\n { parseAs: 'buffer', bodyLimit },\n async function parser(request, payload) {\n return payload\n },\n )\n\n const tokens = new Set<string>(allowedTokens)\n instance.addHook('onRequest', async function (request) {\n let authHeader = request.headers['authorization']\n authHeader = Array.isArray(authHeader) ? authHeader.join() : authHeader\n\n if (!authHeader) {\n throw badRequest(`Missing Authorization header`)\n }\n const [, token] = authHeader.split('Bearer ')\n if (!tokens.has(token)) {\n throw unauthorized(`Invalid authorization token`)\n }\n })\n\n instance.decorate(\n 'location',\n createLocation(provider, {\n accessKey: instance.config.S3_ACCESS_KEY,\n secretKey: instance.config.S3_SECRET_KEY,\n path: instance.config.STORAGE_PATH,\n region: instance.config.S3_REGION,\n endpoint: instance.config.S3_ENDPOINT,\n clientEmail: instance.config.GCS_CLIENT_EMAIL,\n privateKey: instance.config.GCS_PRIVATE_KEY,\n projectId: instance.config.GCS_PROJECT_ID,\n }),\n )\n\n await instance.register(\n async function (i) {\n i.route(getArtifact)\n i.route(putArtifact)\n i.route(artifactsEvents)\n },\n { prefix: `/${apiVersion}` },\n )\n}\n\nexport default turboRemoteCache\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/remote-cache/index.ts"],"names":[],"mappings":";;AACA,qCAAqD;AACrD,qCAAkF;AAClF,uCAA0C;AAC1C,mCAA6C;AAE7C,KAAK,UAAU,gBAAgB,CAC7B,QAAyB,EACzB,OAKC;IAED,MAAM,EACJ,aAAa,EACb,SAAS,GAAG,SAAS,EACrB,UAAU,GAAG,IAAI,EACjB,QAAQ,GAAG,uBAAiB,CAAC,KAAK,GACnC,GAAG,OAAO,CAAA;IACX,IAAI,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,IAAI,aAAa,CAAC,MAAM,CAAC,EAAE;QAC3D,MAAM,IAAI,KAAK,CACb,+C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QAC7C,UAAU,EAAE,QAAQ,CAAC,MAAM,CAAC,eAAe;QAC3C,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,cAAc;KAC1C,CAAC,CACH,CAAA;IAED,MAAM,QAAQ,CAAC,QAAQ,CACrB,KAAK,WAAW,CAAC;QACf,CAAC,CAAC,KAAK,CAAC,oBAAW,CAAC,CAAA;QACpB,CAAC,CAAC,KAAK,CAAC,qBAAY,CAAC,CAAA;QACrB,CAAC,CAAC,KAAK,CAAC,oBAAW,CAAC,CAAA;QACpB,CAAC,CAAC,KAAK,CAAC,wBAAe,CAAC,CAAA;IAC1B,CAAC,EACD,EAAE,MAAM,EAAE,IAAI,UAAU,EAAE,EAAE,CAC7B,CAAA;AACH,CAAC;AAED,kBAAe,gBAAgB,CAAA","sourcesContent":["import { FastifyInstance } from 'fastify'\nimport { badRequest, unauthorized } from '@hapi/boom'\nimport { getArtifact, putArtifact, artifactsEvents, headArtifact } from './routes'\nimport { createLocation } from './storage'\nimport { STORAGE_PROVIDERS } from '../../env'\n\nasync function turboRemoteCache(\n instance: FastifyInstance,\n options: {\n allowedTokens: string[]\n bodyLimit?: number\n apiVersion?: `v${number}`\n provider?: STORAGE_PROVIDERS\n },\n) {\n const {\n allowedTokens,\n bodyLimit = 104857600,\n apiVersion = 'v8',\n provider = STORAGE_PROVIDERS.LOCAL,\n } = options\n if (!(Array.isArray(allowedTokens) && allowedTokens.length)) {\n throw new Error(\n `'allowedTokens' options must be a string[], ${typeof allowedTokens} provided instead`,\n )\n }\n\n instance.addContentTypeParser<Buffer>(\n 'application/octet-stream',\n { parseAs: 'buffer', bodyLimit },\n async function parser(request, payload) {\n return payload\n },\n )\n\n const tokens = new Set<string>(allowedTokens)\n instance.addHook('onRequest', async function (request) {\n let authHeader = request.headers['authorization']\n authHeader = Array.isArray(authHeader) ? authHeader.join() : authHeader\n\n if (!authHeader) {\n throw badRequest(`Missing Authorization header`)\n }\n const [, token] = authHeader.split('Bearer ')\n if (!tokens.has(token)) {\n throw unauthorized(`Invalid authorization token`)\n }\n })\n\n instance.decorate(\n 'location',\n createLocation(provider, {\n accessKey: instance.config.S3_ACCESS_KEY,\n secretKey: instance.config.S3_SECRET_KEY,\n path: instance.config.STORAGE_PATH,\n region: instance.config.S3_REGION,\n endpoint: instance.config.S3_ENDPOINT,\n clientEmail: instance.config.GCS_CLIENT_EMAIL,\n privateKey: instance.config.GCS_PRIVATE_KEY,\n projectId: instance.config.GCS_PROJECT_ID,\n }),\n )\n\n await instance.register(\n async function (i) {\n i.route(getArtifact)\n i.route(headArtifact)\n i.route(putArtifact)\n i.route(artifactsEvents)\n },\n { prefix: `/${apiVersion}` },\n )\n}\n\nexport default turboRemoteCache\n"]}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.headArtifact = void 0;
4
+ const boom_1 = require("@hapi/boom");
5
+ const schema_1 = require("./schema");
6
+ exports.headArtifact = {
7
+ method: 'HEAD',
8
+ url: '/artifacts/:id',
9
+ schema: schema_1.artifactsRouteSchema,
10
+ async handler(req, reply) {
11
+ const artifactId = req.params.id;
12
+ const teamId = req.query.teamId ?? req.query.slug;
13
+ if (!teamId) {
14
+ throw (0, boom_1.badRequest)(`querystring should have required property 'teamId'`);
15
+ }
16
+ try {
17
+ const artifact = await this.location.existsCachedArtifact(artifactId, teamId);
18
+ reply.send(artifact);
19
+ }
20
+ catch (err) {
21
+ throw (0, boom_1.notFound)(`Artifact not found`, err);
22
+ }
23
+ },
24
+ };
25
+ //# sourceMappingURL=head-artifact.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"head-artifact.js","sourceRoot":"","sources":["../../../../src/plugins/remote-cache/routes/head-artifact.ts"],"names":[],"mappings":";;;AAEA,qCAAiD;AACjD,qCAA8E;AAEjE,QAAA,YAAY,GAQrB;IACF,MAAM,EAAE,MAAM;IACd,GAAG,EAAE,gBAAgB;IACrB,MAAM,EAAE,6BAAoB;IAC5B,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK;QACtB,MAAM,UAAU,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAA;QAChC,MAAM,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,MAAM,IAAI,GAAG,CAAC,KAAK,CAAC,IAAI,CAAA;QACjD,IAAI,CAAC,MAAM,EAAE;YACX,MAAM,IAAA,iBAAU,EAAC,oDAAoD,CAAC,CAAA;SACvE;QAED,IAAI;YACF,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,oBAAoB,CAAC,UAAU,EAAE,MAAM,CAAC,CAAA;YAC7E,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;SACrB;QAAC,OAAO,GAAG,EAAE;YACZ,MAAM,IAAA,eAAQ,EAAC,oBAAoB,EAAE,GAAG,CAAC,CAAA;SAC1C;IACH,CAAC;CACF,CAAA","sourcesContent":["import type { Server } from 'http'\nimport type { RouteOptions, RawRequestDefaultExpression, RawReplyDefaultExpression } from 'fastify'\nimport { notFound, badRequest } from '@hapi/boom'\nimport { type Querystring, type Params, artifactsRouteSchema } from './schema'\n\nexport const headArtifact: RouteOptions<\n Server,\n RawRequestDefaultExpression,\n RawReplyDefaultExpression,\n {\n Querystring: Querystring\n Params: Params\n }\n> = {\n method: 'HEAD',\n url: '/artifacts/:id',\n schema: artifactsRouteSchema,\n async handler(req, reply) {\n const artifactId = req.params.id\n const teamId = req.query.teamId ?? req.query.slug // turborepo client passes teamId as slug when --team cli option is used\n if (!teamId) {\n throw badRequest(`querystring should have required property 'teamId'`)\n }\n\n try {\n const artifact = await this.location.existsCachedArtifact(artifactId, teamId)\n reply.send(artifact)\n } catch (err) {\n throw notFound(`Artifact not found`, err)\n }\n },\n}\n"]}
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.artifactsEvents = exports.putArtifact = exports.getArtifact = void 0;
3
+ exports.artifactsEvents = exports.putArtifact = exports.headArtifact = exports.getArtifact = void 0;
4
4
  var get_artifact_1 = require("./get-artifact");
5
5
  Object.defineProperty(exports, "getArtifact", { enumerable: true, get: function () { return get_artifact_1.getArtifact; } });
6
+ var head_artifact_1 = require("./head-artifact");
7
+ Object.defineProperty(exports, "headArtifact", { enumerable: true, get: function () { return head_artifact_1.headArtifact; } });
6
8
  var put_artifact_1 = require("./put-artifact");
7
9
  Object.defineProperty(exports, "putArtifact", { enumerable: true, get: function () { return put_artifact_1.putArtifact; } });
8
10
  var artifacts_events_1 = require("./artifacts-events");
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/plugins/remote-cache/routes/index.ts"],"names":[],"mappings":";;;AAAA,+CAA4C;AAAnC,2GAAA,WAAW,OAAA;AACpB,+CAA4C;AAAnC,2GAAA,WAAW,OAAA;AACpB,uDAAoD;AAA3C,mHAAA,eAAe,OAAA","sourcesContent":["export { getArtifact } from './get-artifact'\nexport { putArtifact } from './put-artifact'\nexport { artifactsEvents } from './artifacts-events'\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/plugins/remote-cache/routes/index.ts"],"names":[],"mappings":";;;AAAA,+CAA4C;AAAnC,2GAAA,WAAW,OAAA;AACpB,iDAA8C;AAArC,6GAAA,YAAY,OAAA;AACrB,+CAA4C;AAAnC,2GAAA,WAAW,OAAA;AACpB,uDAAoD;AAA3C,mHAAA,eAAe,OAAA","sourcesContent":["export { getArtifact } from './get-artifact'\nexport { headArtifact } from './head-artifact'\nexport { putArtifact } from './put-artifact'\nexport { artifactsEvents } from './artifacts-events'\n"]}
@@ -45,12 +45,27 @@ function createLocation(provider, providerOptions) {
45
45
  });
46
46
  });
47
47
  }
48
+ async function existsCachedArtifact(artifactId, teamId) {
49
+ return new Promise((resolve, reject) => {
50
+ const artifactPath = (0, path_1.join)(teamId, artifactId);
51
+ location.exists(artifactPath, (err, exists) => {
52
+ if (err) {
53
+ return reject(err);
54
+ }
55
+ if (!exists) {
56
+ return reject(new Error(`Artifact ${artifactPath} doesn't exist.`));
57
+ }
58
+ resolve();
59
+ });
60
+ });
61
+ }
48
62
  async function createCachedArtifact(artifactId, teamId, artifact) {
49
63
  return pipeline(artifact, location.createWriteStream((0, path_1.join)(teamId, artifactId)));
50
64
  }
51
65
  return {
52
66
  getCachedArtifact,
53
67
  createCachedArtifact,
68
+ existsCachedArtifact,
54
69
  };
55
70
  }
56
71
  exports.createLocation = createLocation;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/plugins/remote-cache/storage/index.ts"],"names":[],"mappings":";;;AAAA,+BAA2B;AAC3B,mCAA+D;AAC/D,+BAAgC;AAChC,sCAAgD;AAChD,6BAAyD;AACzD,mCAAqE;AACrE,iEAG+B;AAE/B,MAAM,QAAQ,GAAG,IAAA,gBAAS,EAAC,iBAAgB,CAAC,CAAA;AAC5C,MAAM,uBAAuB,GAAG,gBAAyB,CAAA;AAuBzD,SAAS,qBAAqB,CAC5B,QAAkB,EAClB,eAA0C;IAE1C,MAAM,EAAE,IAAI,GAAG,uBAAuB,EAAE,GAAG,eAAe,CAAA;IAE1D,QAAQ,QAAQ,EAAE;QAChB,KAAK,uBAAiB,CAAC,KAAK,CAAC,CAAC;YAC5B,OAAO,IAAA,mBAAW,EAAC,EAAE,IAAI,EAAE,CAAC,CAAA;SAC7B;QACD,KAAK,uBAAiB,CAAC,EAAE,CAAC;QAC1B,KAAK,uBAAiB,CAAC,EAAE,CAAC,CAAC;YACzB,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,eAA4B,CAAA;YAC/E,OAAO,IAAA,aAAQ,EAAC,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAA;SAC1E;QACD,KAAK,uBAAiB,CAAC,oBAAoB,CAAC,CAAC;YAC3C,MAAM,EAAE,WAAW,EAA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F,CAAC;IACD,OAAO;QACL,iBAAiB;QACjB,oBAAoB;KACrB,CAAA;AACH,CAAC;AA5BD,wCA4BC","sourcesContent":["import { join } from 'path'\nimport { Readable, pipeline as pipelineCallback } from 'stream'\nimport { promisify } from 'util'\nimport { STORAGE_PROVIDERS } from '../../../env'\nimport { createS3, type S3Options as S3Opts } from './s3'\nimport { createLocal, type LocalOptions as LocalOpts } from './local'\nimport {\n createGoogleCloudStorage,\n type GoogleCloudStorageOptions as GCSOpts,\n} from './google-cloud-storage'\n\nconst pipeline = promisify(pipelineCallback)\nconst TURBO_CACHE_FOLDER_NAME = 'turborepocache' as const\n\ntype LocalOptions = Partial<LocalOpts>\ntype S3Options = Omit<S3Opts, 'bucket'> & LocalOptions\ntype GoogleCloudStorageOptions = Omit<GCSOpts, 'bucket'> & LocalOptions\n\ntype ProviderOptions<Provider extends STORAGE_PROVIDERS> = Provider extends STORAGE_PROVIDERS.LOCAL\n ? LocalOptions\n : Provider extends STORAGE_PROVIDERS.S3\n ? S3Options\n : Provider extends STORAGE_PROVIDERS.s3\n ? S3Options\n : Provider extends STORAGE_PROVIDERS.GOOGLE_CLOUD_STORAGE\n ? GoogleCloudStorageOptions\n : never\n\n// https://github.com/maxogden/abstract-blob-store#api\nexport interface StorageProvider {\n exists: (artifactPath: string, cb: (err: Error | null, exists?: boolean) => void) => void\n createReadStream: (artifactPath: string) => NodeJS.ReadStream\n createWriteStream: (artifactPath: string) => NodeJS.WritableStream\n}\n\nfunction createStorageLocation<Provider extends STORAGE_PROVIDERS>(\n provider: Provider,\n providerOptions: ProviderOptions<Provider>,\n): StorageProvider {\n const { path = TURBO_CACHE_FOLDER_NAME } = providerOptions\n\n switch (provider) {\n case STORAGE_PROVIDERS.LOCAL: {\n return createLocal({ path })\n }\n case STORAGE_PROVIDERS.S3:\n case STORAGE_PROVIDERS.s3: {\n const { accessKey, secretKey, region, endpoint } = providerOptions as S3Options\n return createS3({ accessKey, secretKey, bucket: path, region, endpoint })\n }\n case STORAGE_PROVIDERS.GOOGLE_CLOUD_STORAGE: {\n const { clientEmail, privateKey, projectId } = providerOptions as GoogleCloudStorageOptions\n return createGoogleCloudStorage({ bucket: path, clientEmail, privateKey, projectId })\n }\n default:\n throw new Error(\n `Unsupported storage provider '${provider}'. Please select one of the following: ${Object.values(\n STORAGE_PROVIDERS,\n ).join(', ')}!`,\n )\n }\n}\n\nexport function createLocation<Provider extends STORAGE_PROVIDERS>(\n provider: Provider,\n providerOptions: ProviderOptions<Provider>,\n) {\n const location = createStorageLocation(provider, providerOptions)\n\n async function getCachedArtifact(artifactId: string, teamId: string) {\n return new Promise((resolve, reject) => {\n const artifactPath = join(teamId, artifactId)\n location.exists(artifactPath, (err, exists) => {\n if (err) {\n return reject(err)\n }\n if (!exists) {\n return reject(new Error(`Artifact ${artifactPath} doesn't exist.`))\n }\n resolve(location.createReadStream(artifactPath))\n })\n })\n }\n\n async function createCachedArtifact(artifactId: string, teamId: string, artifact: Readable) {\n return pipeline(artifact, location.createWriteStream(join(teamId, artifactId)))\n }\n return {\n getCachedArtifact,\n createCachedArtifact,\n }\n}\n\ndeclare module 'fastify' {\n interface FastifyInstance {\n location: {\n getCachedArtifact: ReturnType<typeof createLocation>['getCachedArtifact']\n createCachedArtifact: ReturnType<typeof createLocation>['createCachedArtifact']\n }\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/plugins/remote-cache/storage/index.ts"],"names":[],"mappings":";;;AAAA,+BAA2B;AAC3B,mCAA+D;AAC/D,+BAAgC;AAChC,sCAAgD;AAChD,6BAAyD;AACzD,mCAAqE;AACrE,iEAG+B;AAE/B,MAAM,QAAQ,GAAG,IAAA,gBAAS,EAAC,iBAAgB,CAAC,CAAA;AAC5C,MAAM,uBAAuB,GAAG,gBAAyB,CAAA;AAuBzD,SAAS,qBAAqB,CAC5B,QAAkB,EAClB,eAA0C;IAE1C,MAAM,EAAE,IAAI,GAAG,uBAAuB,EAAE,GAAG,eAAe,CAAA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;gBAC5C,IAAI,GAAG,EAAE;oBACP,OAAO,MAAM,CAAC,GAAG,CAAC,CAAA;iBACnB;gBACD,IAAI,CAAC,MAAM,EAAE;oBACX,OAAO,MAAM,CAAC,IAAI,KAAK,CAAC,YAAY,YAAY,iBAAiB,CAAC,CAAC,CAAA;iBACpE;gBACD,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAC,YAAY,CAAC,CAAC,CAAA;YAClD,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,KAAK,UAAU,oBAAoB,CAAC,UAAkB,EAAE,MAAc;QACpE,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC3C,MAAM,YAAY,GAAG,IAAA,WAAI,EAAC,MAAM,EAAE,UAAU,CAAC,CAAA;YAC7C,QAAQ,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE;gBAC5C,IAAI,GAAG,EAAE;oBACP,OAAO,MAAM,CAAC,GAAG,CAAC,CAAA;iBACnB;gBACD,IAAI,CAAC,MAAM,EAAE;oBACX,OAAO,MAAM,CAAC,IAAI,KAAK,CAAC,YAAY,YAAY,iBAAiB,CAAC,CAAC,CAAA;iBACpE;gBACD,OAAO,EAAE,CAAA;YACX,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,KAAK,UAAU,oBAAoB,CAAC,UAAkB,EAAE,MAAc,EAAE,QAAkB;QACxF,OAAO,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,iBAAiB,CAAC,IAAA,WAAI,EAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,CAAA;IACjF,CAAC;IAED,OAAO;QACL,iBAAiB;QACjB,oBAAoB;QACpB,oBAAoB;KACrB,CAAA;AACH,CAAC;AA7CD,wCA6CC","sourcesContent":["import { join } from 'path'\nimport { Readable, pipeline as pipelineCallback } from 'stream'\nimport { promisify } from 'util'\nimport { STORAGE_PROVIDERS } from '../../../env'\nimport { createS3, type S3Options as S3Opts } from './s3'\nimport { createLocal, type LocalOptions as LocalOpts } from './local'\nimport {\n createGoogleCloudStorage,\n type GoogleCloudStorageOptions as GCSOpts,\n} from './google-cloud-storage'\n\nconst pipeline = promisify(pipelineCallback)\nconst TURBO_CACHE_FOLDER_NAME = 'turborepocache' as const\n\ntype LocalOptions = Partial<LocalOpts>\ntype S3Options = Omit<S3Opts, 'bucket'> & LocalOptions\ntype GoogleCloudStorageOptions = Omit<GCSOpts, 'bucket'> & LocalOptions\n\ntype ProviderOptions<Provider extends STORAGE_PROVIDERS> = Provider extends STORAGE_PROVIDERS.LOCAL\n ? LocalOptions\n : Provider extends STORAGE_PROVIDERS.S3\n ? S3Options\n : Provider extends STORAGE_PROVIDERS.s3\n ? S3Options\n : Provider extends STORAGE_PROVIDERS.GOOGLE_CLOUD_STORAGE\n ? GoogleCloudStorageOptions\n : never\n\n// https://github.com/maxogden/abstract-blob-store#api\nexport interface StorageProvider {\n exists: (artifactPath: string, cb: (err: Error | null, exists?: boolean) => void) => void\n createReadStream: (artifactPath: string) => NodeJS.ReadStream\n createWriteStream: (artifactPath: string) => NodeJS.WritableStream\n}\n\nfunction createStorageLocation<Provider extends STORAGE_PROVIDERS>(\n provider: Provider,\n providerOptions: ProviderOptions<Provider>,\n): StorageProvider {\n const { path = TURBO_CACHE_FOLDER_NAME } = providerOptions\n\n switch (provider) {\n case STORAGE_PROVIDERS.LOCAL: {\n return createLocal({ path })\n }\n case STORAGE_PROVIDERS.S3:\n case STORAGE_PROVIDERS.s3: {\n const { accessKey, secretKey, region, endpoint } = providerOptions as S3Options\n return createS3({ accessKey, secretKey, bucket: path, region, endpoint })\n }\n case STORAGE_PROVIDERS.GOOGLE_CLOUD_STORAGE: {\n const { clientEmail, privateKey, projectId } = providerOptions as GoogleCloudStorageOptions\n return createGoogleCloudStorage({ bucket: path, clientEmail, privateKey, projectId })\n }\n default:\n throw new Error(\n `Unsupported storage provider '${provider}'. Please select one of the following: ${Object.values(\n STORAGE_PROVIDERS,\n ).join(', ')}!`,\n )\n }\n}\n\nexport function createLocation<Provider extends STORAGE_PROVIDERS>(\n provider: Provider,\n providerOptions: ProviderOptions<Provider>,\n) {\n const location = createStorageLocation(provider, providerOptions)\n\n async function getCachedArtifact(artifactId: string, teamId: string) {\n return new Promise((resolve, reject) => {\n const artifactPath = join(teamId, artifactId)\n location.exists(artifactPath, (err, exists) => {\n if (err) {\n return reject(err)\n }\n if (!exists) {\n return reject(new Error(`Artifact ${artifactPath} doesn't exist.`))\n }\n resolve(location.createReadStream(artifactPath))\n })\n })\n }\n\n async function existsCachedArtifact(artifactId: string, teamId: string) {\n return new Promise<void>((resolve, reject) => {\n const artifactPath = join(teamId, artifactId)\n location.exists(artifactPath, (err, exists) => {\n if (err) {\n return reject(err)\n }\n if (!exists) {\n return reject(new Error(`Artifact ${artifactPath} doesn't exist.`))\n }\n resolve()\n })\n })\n }\n\n async function createCachedArtifact(artifactId: string, teamId: string, artifact: Readable) {\n return pipeline(artifact, location.createWriteStream(join(teamId, artifactId)))\n }\n\n return {\n getCachedArtifact,\n createCachedArtifact,\n existsCachedArtifact,\n }\n}\n\ndeclare module 'fastify' {\n interface FastifyInstance {\n location: {\n existsCachedArtifact: ReturnType<typeof createLocation>['existsCachedArtifact']\n getCachedArtifact: ReturnType<typeof createLocation>['getCachedArtifact']\n createCachedArtifact: ReturnType<typeof createLocation>['createCachedArtifact']\n }\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "turborepo-remote-cache",
3
- "version": "1.6.7",
3
+ "version": "1.7.0",
4
4
  "description": "Turborepo remote cache server",
5
5
  "main": "build",
6
6
  "author": "Maksim Sinik <maksim@sinik.it>",