@toa.io/origin 1.3.0 → 1.3.2

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 CHANGED
@@ -1,3 +1,17 @@
1
+ ## [1.3.2](https://github.com/toa-io/origin/compare/v1.3.1...v1.3.2) (2025-10-06)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * add `tsup` ([313239a](https://github.com/toa-io/origin/commit/313239ac40799a450c304d4e2e72959baf7aaf05))
7
+
8
+ ## [1.3.1](https://github.com/toa-io/origin/compare/v1.3.0...v1.3.1) (2025-10-06)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * rebuild package-lock ([3b3b253](https://github.com/toa-io/origin/commit/3b3b2537ee92d51f4d9e2d9804882d3ac78ebe3a))
14
+
1
15
  # [1.3.0](https://github.com/toa-io/origin/compare/v1.2.2...v1.3.0) (2025-10-06)
2
16
 
3
17
 
package/dist/index.cjs ADDED
@@ -0,0 +1,189 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // source/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ connect: () => connect
34
+ });
35
+ module.exports = __toCommonJS(index_exports);
36
+
37
+ // source/Origin.ts
38
+ var import_mitt2 = __toESM(require("mitt"), 1);
39
+
40
+ // source/Agent.ts
41
+ var import_error_value = require("error-value");
42
+ var import_browser = require("meros/browser");
43
+ var import_mitt = __toESM(require("mitt"), 1);
44
+ var Agent = class {
45
+ origin;
46
+ events;
47
+ fetch = fetch;
48
+ challenge = null;
49
+ constructor(options) {
50
+ this.origin = options.origin;
51
+ this.events = options.events;
52
+ }
53
+ async json(path, init) {
54
+ const options = this.setup(init);
55
+ const response = await this.request(path, options);
56
+ const body = response.headers.get("content-type") === "application/json" ? await response.json() : await response.text();
57
+ if (response.ok)
58
+ return body;
59
+ else {
60
+ this.events.emit("error", { code: response.status, body });
61
+ return new import_error_value.Err(response.status, body);
62
+ }
63
+ }
64
+ async multipart(path, init) {
65
+ const options = this.setup(init);
66
+ const response = await this.request(path, options);
67
+ if (!response.ok)
68
+ return new import_error_value.Err(response.status, await response.json());
69
+ const generator = await (0, import_browser.meros)(response);
70
+ const ack = await generator.next();
71
+ if (JSON.parse(ack.value.body) !== "ACK") throw new Error("No ACK");
72
+ return (async function* () {
73
+ for await (const chunk of generator) {
74
+ const value = JSON.parse(chunk.body);
75
+ if (value === "FIN") return;
76
+ yield value;
77
+ }
78
+ })();
79
+ }
80
+ async octets(path, init) {
81
+ const generator = await this.multipart(path, init);
82
+ if (generator instanceof Error) return generator;
83
+ const chunk = await generator.next();
84
+ const entry = chunk.value;
85
+ const emitter = (0, import_mitt.default)();
86
+ void (async () => {
87
+ for await (const part of generator) {
88
+ const payload = part.status === "completed" ? part.output : new import_error_value.Err(part.error?.code ?? "UNKNOWN", part.error?.message);
89
+ emitter.emit(part.step, payload);
90
+ }
91
+ emitter.off("*");
92
+ })();
93
+ return [entry, emitter];
94
+ }
95
+ authenticate(challenge) {
96
+ this.challenge = challenge;
97
+ }
98
+ use(fetch2) {
99
+ this.fetch = fetch2;
100
+ }
101
+ setup(init) {
102
+ init ??= {};
103
+ init.headers ??= {};
104
+ init.headers["accept"] ??= "application/json";
105
+ if (init.credentials === "include" && init.headers["authorization"] === void 0) {
106
+ if (this.challenge === null)
107
+ throw new Error("Credentials must be set before sending authenticated request");
108
+ init.headers["authorization"] = this.challenge;
109
+ delete init.credentials;
110
+ }
111
+ if (init.body !== void 0)
112
+ if (init.body instanceof File || init.body instanceof ReadableStream) {
113
+ init.method ??= "POST";
114
+ init.duplex = "half";
115
+ init.headers["content-type"] ??= init.body.type ?? "application/octet-stream";
116
+ } else {
117
+ init.body = JSON.stringify(init.body);
118
+ init.headers["content-type"] ??= "application/json";
119
+ }
120
+ return init;
121
+ }
122
+ async request(path, init) {
123
+ const url = new URL(path, this.origin);
124
+ const response = await this.fetch(url.href, init);
125
+ const challenge = response.headers.get("authorization");
126
+ if (challenge !== null) {
127
+ this.challenge = challenge;
128
+ this.events.emit("challenge", challenge);
129
+ }
130
+ return response;
131
+ }
132
+ };
133
+
134
+ // source/Resource.ts
135
+ var Resource = class {
136
+ agent;
137
+ path;
138
+ constructor(options) {
139
+ this.agent = options.agent;
140
+ this.path = options.path;
141
+ }
142
+ async json(rel = "", init) {
143
+ const abs = this.abs(rel);
144
+ return await this.agent.json(abs, init);
145
+ }
146
+ async octets(rel = "", init) {
147
+ const abs = this.abs(rel);
148
+ return await this.agent.octets(abs, init);
149
+ }
150
+ abs(rel) {
151
+ const base = new URL(this.path, "uri://void");
152
+ const url = new URL(rel, base);
153
+ if (!url.pathname.endsWith("/"))
154
+ url.pathname += "/";
155
+ return url.pathname + url.search;
156
+ }
157
+ };
158
+
159
+ // source/Origin.ts
160
+ var Origin = class {
161
+ events;
162
+ agent;
163
+ constructor(options) {
164
+ this.events = (0, import_mitt2.default)();
165
+ this.agent = new Agent({
166
+ origin: options.origin,
167
+ events: this.events
168
+ });
169
+ }
170
+ resource(path) {
171
+ return new Resource({
172
+ agent: this.agent,
173
+ path
174
+ });
175
+ }
176
+ authenticate(challenge) {
177
+ this.agent.authenticate(challenge);
178
+ }
179
+ use(fetch2) {
180
+ this.agent.use(fetch2);
181
+ }
182
+ };
183
+ function connect(options) {
184
+ return new Origin(options);
185
+ }
186
+ // Annotate the CommonJS export names for ESM import in node:
187
+ 0 && (module.exports = {
188
+ connect
189
+ });
package/eslint.config.js CHANGED
@@ -4,7 +4,10 @@ import neostandard from 'neostandard'
4
4
  export default [
5
5
  ...neostandard({
6
6
  ts: true,
7
- ignores: neostandard.resolveIgnoresFromGitignore(),
7
+ ignores: [
8
+ ...neostandard.resolveIgnoresFromGitignore(),
9
+ 'dist',
10
+ ],
8
11
  }),
9
12
  {
10
13
  plugins: {
package/package.json CHANGED
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "name": "@toa.io/origin",
3
- "version": "1.3.0",
4
- "type": "module",
3
+ "version": "1.3.2",
5
4
  "publishConfig": {
6
5
  "access": "public"
7
6
  },
@@ -11,8 +10,17 @@
11
10
  "url": "git+ssh://git@github.com/toa-io/origin.git"
12
11
  },
13
12
  "homepage": "https://github.com/toa-io/origin#readme",
14
- "main": "transpiled/index.js",
15
- "types": "transpiled/index.d.ts",
13
+ "type": "module",
14
+ "main": "dist/index.cjs",
15
+ "module": "dist/index.mjs",
16
+ "types": "dist/index.d.ts",
17
+ "exports": {
18
+ ".": {
19
+ "import": "./dist/index.mjs",
20
+ "require": "./dist/index.cjs",
21
+ "default": "./dist/index.mjs"
22
+ }
23
+ },
16
24
  "peerDependencies": {
17
25
  "typescript": "^5.8.3"
18
26
  },
@@ -28,12 +36,13 @@
28
36
  "eslint-plugin-import": "^2.31.0",
29
37
  "husky": "^9.1.7",
30
38
  "neostandard": "^0.12.2",
31
- "semantic-release": "^24.2.9"
39
+ "semantic-release": "^24.2.9",
40
+ "tsup": "^8.5.0"
32
41
  },
33
42
  "scripts": {
34
43
  "prepare": "husky",
35
- "prepublishOnly": "npm run transpile",
36
- "transpile": "rm -rf transpiled tsconfig.tsbuildinfo && tsc",
44
+ "build": "tsup source/index.ts",
45
+ "prepublishOnly": "npm run build",
37
46
  "lint": "eslint .",
38
47
  "format": "eslint . --fix",
39
48
  "test": "npm run lint && node --test",
package/source/Agent.ts CHANGED
@@ -2,7 +2,7 @@ import { Err } from 'error-value'
2
2
  import { meros } from 'meros/browser'
3
3
  import mitt from 'mitt'
4
4
  import type { GenericError } from './Error'
5
- import type { Events } from './Evt'
5
+ import type { Events } from './Events'
6
6
  import type { Faulty, OctetsEntry, WorkflowStep } from './Octets'
7
7
  import type { Emitter } from 'mitt'
8
8
 
package/source/Origin.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import mitt from 'mitt'
2
2
  import { Agent } from './Agent'
3
3
  import { Resource } from './Resource'
4
- import type { Events } from './Evt'
4
+ import type { Events } from './Events'
5
5
  import type { Emitter } from 'mitt'
6
6
 
7
7
  /** Resoruce factory */
package/tsconfig.json CHANGED
@@ -1,19 +1,16 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/tsconfig",
3
3
  "compilerOptions": {
4
- "outDir": "./transpiled",
5
- "rootDir": "./source",
6
- "sourceMap": true,
7
- "declaration": true,
4
+ "strict": true,
8
5
  "esModuleInterop": true,
9
6
  "skipLibCheck": true,
10
- "incremental": true,
11
- "strict": true,
12
- "noImplicitOverride": true,
13
- "allowJs": true,
14
- "module": "ESNext",
7
+ "forceConsistentCasingInFileNames": true,
15
8
  "target": "ES2022",
16
- "moduleResolution": "node"
9
+ "module": "ESNext",
10
+ "moduleResolution": "Node",
11
+ "declaration": true,
12
+ "declarationDir": "./dist",
13
+ "outDir": "./dist"
17
14
  },
18
15
  "include": [
19
16
  "source/**/*"
@@ -1,30 +0,0 @@
1
- import type { GenericError } from './Error';
2
- import type { Events } from './Evt';
3
- import type { Faulty, OctetsEntry } from './Octets';
4
- import type { Emitter } from 'mitt';
5
- declare class Agent {
6
- private readonly origin;
7
- private readonly events;
8
- private fetch;
9
- private challenge;
10
- constructor(options: Options);
11
- json<T, E extends GenericError = GenericError>(path: string, init?: Init): Promise<T | E>;
12
- multipart<T = unknown>(path: string, init?: Init): Promise<AsyncGenerator<T, void, undefined> | GenericError>;
13
- octets<T extends Record<string, unknown> = Record<string, unknown>, E extends GenericError = GenericError>(path: string, init?: Init): Promise<[OctetsEntry, Emitter<Faulty<T>>] | E>;
14
- authenticate(challenge: string | null): void;
15
- use(fetch: Fetch): void;
16
- private setup;
17
- private request;
18
- }
19
- interface Options {
20
- origin: string;
21
- events: Emitter<Events>;
22
- }
23
- interface Init extends Omit<RequestInit, 'path' | 'headers'> {
24
- duplex?: 'half';
25
- body?: any;
26
- headers?: Record<string, string>;
27
- }
28
- type Fetch = typeof fetch;
29
- export { Agent };
30
- export type { Init };
@@ -1,102 +0,0 @@
1
- import { Err } from 'error-value';
2
- import { meros } from 'meros/browser';
3
- import mitt from 'mitt';
4
- class Agent {
5
- origin;
6
- events;
7
- fetch = fetch;
8
- challenge = null;
9
- constructor(options) {
10
- this.origin = options.origin;
11
- this.events = options.events;
12
- }
13
- async json(path, init) {
14
- const options = this.setup(init);
15
- const response = await this.request(path, options);
16
- const body = response.headers.get('content-type') === 'application/json'
17
- ? await response.json()
18
- : await response.text();
19
- if (response.ok)
20
- return body;
21
- else {
22
- this.events.emit('error', { code: response.status, body });
23
- return new Err(response.status, body);
24
- }
25
- }
26
- async multipart(path, init) {
27
- const options = this.setup(init);
28
- const response = await this.request(path, options);
29
- if (!response.ok)
30
- return new Err(response.status, await response.json());
31
- const generator = await meros(response);
32
- const ack = await generator.next();
33
- if (JSON.parse(ack.value.body) !== 'ACK')
34
- throw new Error('No ACK');
35
- return (async function* () {
36
- for await (const chunk of generator) {
37
- const value = JSON.parse(chunk.body);
38
- if (value === 'FIN')
39
- return;
40
- yield value;
41
- }
42
- })();
43
- }
44
- async octets(path, init) {
45
- const generator = await this.multipart(path, init);
46
- if (generator instanceof Error)
47
- return generator;
48
- const chunk = await generator.next();
49
- const entry = chunk.value;
50
- const emitter = mitt();
51
- void (async () => {
52
- for await (const part of generator) {
53
- const payload = part.status === 'completed'
54
- ? part.output
55
- : new Err(part.error?.code ?? 'UNKNOWN', part.error?.message);
56
- emitter.emit(part.step, payload);
57
- }
58
- emitter.off('*');
59
- })();
60
- return [entry, emitter];
61
- }
62
- authenticate(challenge) {
63
- this.challenge = challenge;
64
- }
65
- use(fetch) {
66
- this.fetch = fetch;
67
- }
68
- setup(init) {
69
- init ??= {};
70
- init.headers ??= {};
71
- init.headers['accept'] ??= 'application/json';
72
- if (init.credentials === 'include' && init.headers['authorization'] === undefined) {
73
- if (this.challenge === null)
74
- throw new Error('Credentials must be set before sending authenticated request');
75
- init.headers['authorization'] = this.challenge;
76
- delete init.credentials; // no cookies
77
- }
78
- if (init.body !== undefined)
79
- if (init.body instanceof File || init.body instanceof ReadableStream) {
80
- init.method ??= 'POST';
81
- init.duplex = 'half';
82
- init.headers['content-type'] ??= init.body.type ?? 'application/octet-stream';
83
- }
84
- else {
85
- init.body = JSON.stringify(init.body);
86
- init.headers['content-type'] ??= 'application/json';
87
- }
88
- return init;
89
- }
90
- async request(path, init) {
91
- const url = new URL(path, this.origin);
92
- const response = await this.fetch(url.href, init);
93
- const challenge = response.headers.get('authorization');
94
- if (challenge !== null) {
95
- this.challenge = challenge;
96
- this.events.emit('challenge', challenge);
97
- }
98
- return response;
99
- }
100
- }
101
- export { Agent };
102
- //# sourceMappingURL=Agent.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Agent.js","sourceRoot":"","sources":["../source/Agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MA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ACpB,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,KAAM,IAAI,CAAC,IAAa,CAAC,IAAI,IAAI,0BAA0B,CAAA;YACzF,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;gBACrC,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,KAAK,kBAAkB,CAAA;YACrD,CAAC;QAEH,OAAO,IAAuB,CAAA;IAChC,CAAC;IAEO,KAAK,CAAC,OAAO,CAAC,IAAY,EAAE,IAAU;QAC5C,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;QACtC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;QAEjD,MAAM,SAAS,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAA;QAEvD,IAAI,SAAS,KAAK,IAAI,EAAE,CAAC;YACvB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;YAC1B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,SAAS,CAAC,CAAA;QAC1C,CAAC;QAED,OAAO,QAAQ,CAAA;IACjB,CAAC;CACF;AAmBD,OAAO,EAAE,KAAK,EAAE,CAAA"}
@@ -1,2 +0,0 @@
1
- import type { Err } from 'error-value';
2
- export type GenericError<E = unknown> = Err<number, E>;
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=Error.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Error.js","sourceRoot":"","sources":["../source/Error.ts"],"names":[],"mappings":""}
@@ -1,8 +0,0 @@
1
- type Events = {
2
- challenge: string;
3
- error: {
4
- code: number;
5
- body: unknown;
6
- };
7
- };
8
- export { Events };
package/transpiled/Evt.js DELETED
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=Evt.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Evt.js","sourceRoot":"","sources":["../source/Evt.ts"],"names":[],"mappings":""}
@@ -1,11 +0,0 @@
1
- import type { Err } from 'error-value';
2
- export interface OctetsEntry {
3
- id: string;
4
- }
5
- export interface WorkflowStep<K extends string = string, T = unknown, E extends Err = Err> {
6
- step: K;
7
- status: 'completed' | 'exception';
8
- output?: T;
9
- error: E;
10
- }
11
- export type Faulty<T extends Record<string, unknown>> = Record<keyof T, T[keyof T] | Err>;
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=Octets.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Octets.js","sourceRoot":"","sources":["../source/Octets.ts"],"names":[],"mappings":""}
@@ -1,18 +0,0 @@
1
- import { Resource } from './Resource';
2
- import type { Events } from './Evt';
3
- import type { Emitter } from 'mitt';
4
- /** Resoruce factory */
5
- declare class Origin {
6
- readonly events: Emitter<Events>;
7
- private readonly agent;
8
- constructor(options: Options);
9
- resource<T = unknown>(path: string): Resource<T, import("./Error").GenericError>;
10
- authenticate(challenge: string | null): void;
11
- use(fetch: Fetch): void;
12
- }
13
- declare function connect(options: Options): Origin;
14
- interface Options {
15
- origin: string;
16
- }
17
- type Fetch = typeof fetch;
18
- export { connect };
@@ -1,32 +0,0 @@
1
- import mitt from 'mitt';
2
- import { Agent } from './Agent';
3
- import { Resource } from './Resource';
4
- /** Resoruce factory */
5
- class Origin {
6
- events;
7
- agent;
8
- constructor(options) {
9
- this.events = mitt();
10
- this.agent = new Agent({
11
- origin: options.origin,
12
- events: this.events,
13
- });
14
- }
15
- resource(path) {
16
- return new Resource({
17
- agent: this.agent,
18
- path,
19
- });
20
- }
21
- authenticate(challenge) {
22
- this.agent.authenticate(challenge);
23
- }
24
- use(fetch) {
25
- this.agent.use(fetch);
26
- }
27
- }
28
- function connect(options) {
29
- return new Origin(options);
30
- }
31
- export { connect };
32
- //# sourceMappingURL=Origin.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Origin.js","sourceRoot":"","sources":["../source/Origin.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAIrC,uBAAuB;AACvB,MAAM,MAAM;IACM,MAAM,CAAiB;IACtB,KAAK,CAAO;IAE7B,YAAY,OAAgB;QAC1B,IAAI,CAAC,MAAM,GAAG,IAAI,EAAU,CAAA;QAE5B,IAAI,CAAC,KAAK,GAAG,IAAI,KAAK,CAAC;YACrB,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,MAAM,EAAE,IAAI,CAAC,MAAM;SACpB,CAAC,CAAA;IACJ,CAAC;IAEM,QAAQ,CAAc,IAAY;QACvC,OAAO,IAAI,QAAQ,CAAI;YACrB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,IAAI;SACL,CAAC,CAAA;IACJ,CAAC;IAEM,YAAY,CAAC,SAAwB;QAC1C,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,SAAS,CAAC,CAAA;IACpC,CAAC;IAEM,GAAG,CAAC,KAAY;QACrB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;IACvB,CAAC;CACF;AAED,SAAS,OAAO,CAAC,OAAgB;IAC/B,OAAO,IAAI,MAAM,CAAC,OAAO,CAAC,CAAA;AAC5B,CAAC;AAQD,OAAO,EAAE,OAAO,EAAE,CAAA"}
@@ -1,17 +0,0 @@
1
- import type { Agent, Init } from './Agent';
2
- import type { GenericError } from './Error';
3
- import type { Faulty, OctetsEntry } from './Octets';
4
- import type { Emitter } from 'mitt';
5
- declare class Resource<T = unknown, E extends GenericError = GenericError> {
6
- private readonly agent;
7
- private readonly path;
8
- constructor(options: Options);
9
- json<R = T, F extends E = E>(rel?: string, init?: Init): Promise<R | F>;
10
- octets<T extends Record<string, unknown> = Record<string, unknown>, F extends E = E>(rel?: string, init?: Init): Promise<[OctetsEntry, Emitter<Faulty<T>>] | F>;
11
- private abs;
12
- }
13
- interface Options {
14
- agent: Agent;
15
- path: string;
16
- }
17
- export { Resource };
@@ -1,25 +0,0 @@
1
- class Resource {
2
- agent;
3
- path;
4
- constructor(options) {
5
- this.agent = options.agent;
6
- this.path = options.path;
7
- }
8
- async json(rel = '', init) {
9
- const abs = this.abs(rel);
10
- return await this.agent.json(abs, init);
11
- }
12
- async octets(rel = '', init) {
13
- const abs = this.abs(rel);
14
- return await this.agent.octets(abs, init);
15
- }
16
- abs(rel) {
17
- const base = new URL(this.path, 'uri://void');
18
- const url = new URL(rel, base);
19
- if (!url.pathname.endsWith('/'))
20
- url.pathname += '/';
21
- return url.pathname + url.search;
22
- }
23
- }
24
- export { Resource };
25
- //# sourceMappingURL=Resource.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Resource.js","sourceRoot":"","sources":["../source/Resource.ts"],"names":[],"mappings":"AAKA,MAAM,QAAQ;IACK,KAAK,CAAO;IACZ,IAAI,CAAQ;IAE7B,YAAmB,OAAgB;QACjC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAA;QAC1B,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAA;IAC1B,CAAC;IAEM,KAAK,CAAC,IAAI,CAAyB,MAAc,EAAE,EAAE,IAAW;QACrE,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAEzB,OAAO,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAO,GAAG,EAAE,IAAI,CAAC,CAAA;IAC/C,CAAC;IAEM,KAAK,CAAC,MAAM,CAA+E,MAAc,EAAE,EAAE,IAAW;QAC7H,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAEzB,OAAO,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAO,GAAG,EAAE,IAAI,CAAC,CAAA;IACjD,CAAC;IAEO,GAAG,CAAC,GAAW;QACrB,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,YAAY,CAAC,CAAA;QAC7C,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;QAE9B,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC;YAC7B,GAAG,CAAC,QAAQ,IAAI,GAAG,CAAA;QAErB,OAAO,GAAG,CAAC,QAAQ,GAAG,GAAG,CAAC,MAAM,CAAA;IAClC,CAAC;CACF;AAOD,OAAO,EAAE,QAAQ,EAAE,CAAA"}
@@ -1,3 +0,0 @@
1
- export { connect } from './Origin';
2
- export type { GenericError } from './Error';
3
- export type { OctetsEntry, WorkflowStep } from './Octets';
@@ -1,2 +0,0 @@
1
- export { connect } from './Origin';
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA"}
File without changes