@gasboost/fake-core 0.1.3 → 0.3.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.
@@ -0,0 +1,14 @@
1
+ export type HttpResponseHeaders = Record<string, string | string[]>;
2
+ export declare class InMemoryHttpResponse implements GoogleAppsScript.URL_Fetch.HTTPResponse {
3
+ private content;
4
+ private responseCode;
5
+ private headers;
6
+ constructor(data: string | ArrayLike<number>, responseCode?: number, headers?: HttpResponseHeaders, charset?: string);
7
+ getAllHeaders(): object;
8
+ getAs(contentType: string): GoogleAppsScript.Base.Blob;
9
+ getBlob(): GoogleAppsScript.Base.Blob;
10
+ getContent(): number[];
11
+ getContentText(charset?: string): string;
12
+ getHeaders(): object;
13
+ getResponseCode(): number;
14
+ }
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InMemoryHttpResponse = void 0;
4
+ const InMemoryBlob_1 = require("../blob/InMemoryBlob");
5
+ const BinaryData_1 = require("../utilities/BinaryData");
6
+ class InMemoryHttpResponse {
7
+ content;
8
+ responseCode;
9
+ headers;
10
+ constructor(data, responseCode = 200, headers = {}, charset) {
11
+ this.content = new BinaryData_1.BinaryData(data, charset ?? "UTF_8").bytes;
12
+ this.responseCode = responseCode;
13
+ this.headers = {};
14
+ for (const [name, value] of Object.entries(headers)) {
15
+ this.headers[name] = Array.isArray(value) ? [...value] : value;
16
+ }
17
+ }
18
+ getAllHeaders() {
19
+ const headers = {};
20
+ for (const [name, value] of Object.entries(this.headers)) {
21
+ headers[name] = Array.isArray(value) ? [...value] : value;
22
+ }
23
+ return headers;
24
+ }
25
+ getAs(contentType) {
26
+ return this.getBlob().getAs(contentType);
27
+ }
28
+ getBlob() {
29
+ let contentType = null;
30
+ for (const [name, value] of Object.entries(this.headers)) {
31
+ if (name.toLowerCase() === "content-type") {
32
+ contentType = Array.isArray(value) ? (value[0] ?? null) : value;
33
+ break;
34
+ }
35
+ }
36
+ return new InMemoryBlob_1.InMemoryBlob(this.content, contentType);
37
+ }
38
+ getContent() {
39
+ return new BinaryData_1.BinaryData(this.content).signedBytes();
40
+ }
41
+ getContentText(charset) {
42
+ return new BinaryData_1.BinaryData(this.content, charset ?? "UTF_8").decode();
43
+ }
44
+ getHeaders() {
45
+ const headers = {};
46
+ for (const [name, value] of Object.entries(this.headers)) {
47
+ headers[name] = Array.isArray(value) ? (value[0] ?? "") : value;
48
+ }
49
+ return headers;
50
+ }
51
+ getResponseCode() {
52
+ return this.responseCode;
53
+ }
54
+ }
55
+ exports.InMemoryHttpResponse = InMemoryHttpResponse;
56
+ //# sourceMappingURL=InMemoryHttpResponse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InMemoryHttpResponse.js","sourceRoot":"","sources":["../../src/fetch/InMemoryHttpResponse.ts"],"names":[],"mappings":";;;AAAA,uDAAoD;AACpD,wDAAqD;AAIrD,MAAa,oBAAoB;IAGvB,OAAO,CAAa;IACpB,YAAY,CAAS;IACrB,OAAO,CAAsB;IAErC,YACE,IAAgC,EAChC,YAAY,GAAG,GAAG,EAClB,UAA+B,EAAE,EACjC,OAAgB;QAEhB,IAAI,CAAC,OAAO,GAAG,IAAI,uBAAU,CAAC,IAAI,EAAE,OAAO,IAAI,OAAO,CAAC,CAAC,KAAK,CAAC;QAC9D,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;QAElB,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;YACpD,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;QACjE,CAAC;IACH,CAAC;IAED,aAAa;QACX,MAAM,OAAO,GAAwB,E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AC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;YACzD,OAAO,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;QAClE,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,eAAe;QACb,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;CACF;AAtED,oDAsEC"}
@@ -0,0 +1 @@
1
+ export * from "./InMemoryHttpResponse";
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./InMemoryHttpResponse"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/fetch/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yDAAuC"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from "./blob/InMemoryBlob";
2
2
  export * from "./cache";
3
+ export * from "./fetch";
3
4
  export * from "./properties-service";
4
5
  export * from "./session";
5
6
  export * from "./utilities";
package/dist/index.js CHANGED
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./blob/InMemoryBlob"), exports);
18
18
  __exportStar(require("./cache"), exports);
19
+ __exportStar(require("./fetch"), exports);
19
20
  __exportStar(require("./properties-service"), exports);
20
21
  __exportStar(require("./session"), exports);
21
22
  __exportStar(require("./utilities"), exports);
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sDAAoC;AACpC,0CAAwB;AACxB,uDAAqC;AACrC,4CAA0B;AAC1B,8CAA4B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sDAAoC;AACpC,0CAAwB;AACxB,0CAAwB;AACxB,uDAAqC;AACrC,4CAA0B;AAC1B,8CAA4B"}
@@ -1,4 +1,13 @@
1
+ export type InMemoryPropertiesServiceOptions = {
2
+ document?: Record<string, string>;
3
+ user?: Record<string, string>;
4
+ script?: Record<string, string>;
5
+ };
1
6
  export declare class InMemoryPropertiesService implements GoogleAppsScript.Properties.PropertiesService {
7
+ private readonly documentProperties;
8
+ private readonly userProperties;
9
+ private readonly scriptProperties;
10
+ constructor(options?: InMemoryPropertiesServiceOptions);
2
11
  getDocumentProperties(): GoogleAppsScript.Properties.Properties;
3
12
  getUserProperties(): GoogleAppsScript.Properties.Properties;
4
13
  getScriptProperties(): GoogleAppsScript.Properties.Properties;
@@ -3,14 +3,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.InMemoryPropertiesService = void 0;
4
4
  const InMemoryProperties_1 = require("./InMemoryProperties");
5
5
  class InMemoryPropertiesService {
6
+ documentProperties = new InMemoryProperties_1.InMemoryProperties();
7
+ userProperties = new InMemoryProperties_1.InMemoryProperties();
8
+ scriptProperties = new InMemoryProperties_1.InMemoryProperties();
9
+ constructor(options = {}) {
10
+ this.documentProperties.setProperties(options.document ?? {});
11
+ this.userProperties.setProperties(options.user ?? {});
12
+ this.scriptProperties.setProperties(options.script ?? {});
13
+ }
6
14
  getDocumentProperties() {
7
- return new InMemoryProperties_1.InMemoryProperties();
15
+ return this.documentProperties;
8
16
  }
9
17
  getUserProperties() {
10
- return new InMemoryProperties_1.InMemoryProperties();
18
+ return this.userProperties;
11
19
  }
12
20
  getScriptProperties() {
13
- return new InMemoryProperties_1.InMemoryProperties();
21
+ return this.scriptProperties;
14
22
  }
15
23
  }
16
24
  exports.InMemoryPropertiesService = InMemoryPropertiesService;
@@ -1 +1 @@
1
- {"version":3,"file":"InMemoryPropertiesService.js","sourceRoot":"","sources":["../../src/properties-service/InMemoryPropertiesService.ts"],"names":[],"mappings":";;;AAAA,6DAA0D;AAE1D,MAAa,yBAAyB;IAGpC,qBAAqB;QACnB,OAAO,IAAI,uCAAkB,EAAE,CAAC;IAClC,CAAC;IAED,iBAAiB;QACf,OAAO,IAAI,uCAAkB,EAAE,CAAC;IAClC,CAAC;IAED,mBAAmB;QACjB,OAAO,IAAI,uCAAkB,EAAE,CAAC;IAClC,CAAC;CACF;AAdD,8DAcC"}
1
+ {"version":3,"file":"InMemoryPropertiesService.js","sourceRoot":"","sources":["../../src/properties-service/InMemoryPropertiesService.ts"],"names":[],"mappings":";;;AAAA,6DAA0D;AAQ1D,MAAa,yBAAyB;IAGnB,kBAAkB,GAAG,IAAI,uCAAkB,EAAE,CAAC;IAC9C,cAAc,GAAG,IAAI,uCAAkB,EAAE,CAAC;IAC1C,gBAAgB,GAAG,IAAI,uCAAkB,EAAE,CAAC;IAE7D,YAAY,UAA4C,EAAE;QACxD,IAAI,CAAC,kBAAkB,CAAC,aAAa,CAAC,OAAO,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC;QAC9D,IAAI,CAAC,cAAc,CAAC,aAAa,CAAC,OAAO,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;QACtD,IAAI,CAAC,gBAAgB,CAAC,aAAa,CAAC,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC;IAC5D,CAAC;IAED,qBAAqB;QACnB,OAAO,IAAI,CAAC,kBAAkB,CAAC;IACjC,CAAC;IAED,iBAAiB;QACf,OAAO,IAAI,CAAC,cAAc,CAAC;IAC7B,CAAC;IAED,mBAAmB;QACjB,OAAO,IAAI,CAAC,gBAAgB,CAAC;IAC/B,CAAC;CACF;AAxBD,8DAwBC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gasboost/fake-core",
3
- "version": "0.1.3",
3
+ "version": "0.3.0",
4
4
  "description": "This package provides a fake implementation of Google Apps Script built-in services for testing purposes.",
5
5
  "license": "MIT",
6
6
  "author": "tiger-oshima",