@space-df/sdk 0.0.1-dev.3.3 → 0.0.1-dev.4
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/.editorconfig +24 -0
- package/.github/pull_request_template.md +25 -0
- package/.github/workflows/bump-version.yml +67 -0
- package/.github/workflows/publish-package.yml +28 -0
- package/.gitignore +11 -0
- package/CODE_OF_CONDUCT.md +128 -0
- package/CONTRIBUTING.md +89 -0
- package/api.doc.md +1321 -0
- package/dist/LICENSE +7 -0
- package/dist/README.md +382 -0
- package/{index.d.mts → dist/index.d.mts} +1 -0
- package/{index.d.ts → dist/index.d.ts} +1 -0
- package/{index.d.ts.map → dist/index.d.ts.map} +1 -1
- package/{index.js → dist/index.js} +1 -0
- package/dist/index.js.map +1 -0
- package/{index.mjs → dist/index.mjs} +1 -0
- package/dist/index.mjs.map +1 -0
- package/dist/package.json +101 -0
- package/{resources → dist/resources}/auth/index.d.ts +1 -0
- package/{resources → dist/resources}/auth/index.d.ts.map +1 -1
- package/{resources → dist/resources}/auth/index.js +1 -0
- package/{resources → dist/resources}/auth/index.js.map +1 -1
- package/{resources → dist/resources}/auth/index.mjs +1 -0
- package/dist/resources/auth/users.d.ts +19 -0
- package/dist/resources/auth/users.d.ts.map +1 -0
- package/dist/resources/auth/users.js +17 -0
- package/dist/resources/auth/users.js.map +1 -0
- package/dist/resources/auth/users.mjs +13 -0
- package/dist/resources/auth/users.mjs.map +1 -0
- package/dist/src/_shims/MultipartBody.ts +9 -0
- package/dist/src/_shims/README.md +46 -0
- package/dist/src/_shims/auto/runtime-bun.ts +4 -0
- package/dist/src/_shims/auto/runtime-node.ts +4 -0
- package/dist/src/_shims/auto/runtime.ts +4 -0
- package/dist/src/_shims/auto/types-node.ts +4 -0
- package/dist/src/_shims/auto/types.d.ts +101 -0
- package/dist/src/_shims/auto/types.js +3 -0
- package/dist/src/_shims/auto/types.mjs +3 -0
- package/dist/src/_shims/bun-runtime.ts +14 -0
- package/dist/src/_shims/index.d.ts +72 -0
- package/dist/src/_shims/index.js +13 -0
- package/dist/src/_shims/index.mjs +7 -0
- package/dist/src/_shims/manual-types.d.ts +12 -0
- package/dist/src/_shims/manual-types.js +3 -0
- package/dist/src/_shims/manual-types.mjs +3 -0
- package/dist/src/_shims/node-runtime.ts +78 -0
- package/dist/src/_shims/node-types.d.ts +42 -0
- package/dist/src/_shims/node-types.js +3 -0
- package/dist/src/_shims/node-types.mjs +3 -0
- package/dist/src/_shims/registry.ts +60 -0
- package/dist/src/_shims/web-runtime.ts +91 -0
- package/dist/src/_shims/web-types.d.ts +83 -0
- package/dist/src/_shims/web-types.js +3 -0
- package/dist/src/_shims/web-types.mjs +3 -0
- package/dist/src/core.ts +1061 -0
- package/dist/src/error.ts +134 -0
- package/dist/src/index.ts +207 -0
- package/dist/src/libs/utils.ts +66 -0
- package/dist/src/resource.ts +9 -0
- package/dist/src/resources/auth/auth.ts +92 -0
- package/dist/src/resources/auth/credentials.ts +12 -0
- package/dist/src/resources/auth/index.ts +7 -0
- package/dist/src/resources/auth/space-policies.ts +55 -0
- package/dist/src/resources/auth/space-role-users.ts +42 -0
- package/dist/src/resources/auth/space-roles.ts +95 -0
- package/dist/src/resources/auth/spaces.ts +118 -0
- package/dist/src/resources/auth/users.ts +36 -0
- package/dist/src/resources/console/index.ts +1 -0
- package/dist/src/resources/console/oauth2.ts +83 -0
- package/dist/src/resources/dashboard/dashboards.ts +171 -0
- package/dist/src/resources/dashboard/device-states.ts +142 -0
- package/dist/src/resources/dashboard/index.ts +2 -0
- package/dist/src/resources/index.ts +6 -0
- package/dist/src/shims/node.ts +50 -0
- package/dist/src/shims/web.ts +50 -0
- package/dist/src/types/api.ts +31 -0
- package/dist/src/types/jwt.ts +12 -0
- package/dist/src/version.ts +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/{version.js → dist/version.js} +1 -1
- package/dist/version.js.map +1 -0
- package/dist/version.mjs +2 -0
- package/{version.mjs.map → dist/version.mjs.map} +1 -1
- package/eslint.config.mjs +33 -0
- package/examples/auth/login.ts +14 -0
- package/examples/auth/register.ts +15 -0
- package/examples/console/oauth2.ts +15 -0
- package/package.json +52 -36
- package/scripts/build +56 -0
- package/scripts/utils/check-version.cjs +20 -0
- package/scripts/utils/fix-index-exports.cjs +8 -0
- package/scripts/utils/make-dist-package-json.cjs +21 -0
- package/scripts/utils/postprocess-files.cjs +153 -0
- package/src/_shims/auto/runtime-deno.ts +4 -0
- package/src/_shims/auto/types-deno.ts +4 -0
- package/src/_shims/auto/types.d.ts +18 -18
- package/src/_shims/index-deno.ts +105 -0
- package/src/_shims/index.d.ts +1 -1
- package/src/_shims/index.mjs +1 -1
- package/src/index.ts +1 -0
- package/src/resources/auth/index.ts +1 -0
- package/src/resources/auth/users.ts +36 -0
- package/src/version.ts +1 -1
- package/tsc-multi.json +7 -0
- package/tsconfig.build.json +18 -0
- package/tsconfig.deno.json +20 -0
- package/tsconfig.dist-src.json +11 -0
- package/tsconfig.json +38 -0
- package/index.js.map +0 -1
- package/index.mjs.map +0 -1
- package/src/resources/.DS_Store +0 -0
- package/version.d.ts +0 -2
- package/version.d.ts.map +0 -1
- package/version.js.map +0 -1
- package/version.mjs +0 -2
- package/yarn.lock +0 -268
- /package/{_shims → dist/_shims}/MultipartBody.d.ts +0 -0
- /package/{_shims → dist/_shims}/MultipartBody.d.ts.map +0 -0
- /package/{_shims → dist/_shims}/MultipartBody.js +0 -0
- /package/{_shims → dist/_shims}/MultipartBody.js.map +0 -0
- /package/{_shims → dist/_shims}/MultipartBody.mjs +0 -0
- /package/{_shims → dist/_shims}/MultipartBody.mjs.map +0 -0
- /package/{_shims → dist/_shims}/README.md +0 -0
- /package/{_shims → dist/_shims}/auto/runtime-bun.d.ts +0 -0
- /package/{_shims → dist/_shims}/auto/runtime-bun.d.ts.map +0 -0
- /package/{_shims → dist/_shims}/auto/runtime-bun.js +0 -0
- /package/{_shims → dist/_shims}/auto/runtime-bun.js.map +0 -0
- /package/{_shims → dist/_shims}/auto/runtime-bun.mjs +0 -0
- /package/{_shims → dist/_shims}/auto/runtime-bun.mjs.map +0 -0
- /package/{_shims → dist/_shims}/auto/runtime-node.d.ts +0 -0
- /package/{_shims → dist/_shims}/auto/runtime-node.d.ts.map +0 -0
- /package/{_shims → dist/_shims}/auto/runtime-node.js +0 -0
- /package/{_shims → dist/_shims}/auto/runtime-node.js.map +0 -0
- /package/{_shims → dist/_shims}/auto/runtime-node.mjs +0 -0
- /package/{_shims → dist/_shims}/auto/runtime-node.mjs.map +0 -0
- /package/{_shims → dist/_shims}/auto/runtime.d.ts +0 -0
- /package/{_shims → dist/_shims}/auto/runtime.d.ts.map +0 -0
- /package/{_shims → dist/_shims}/auto/runtime.js +0 -0
- /package/{_shims → dist/_shims}/auto/runtime.js.map +0 -0
- /package/{_shims → dist/_shims}/auto/runtime.mjs +0 -0
- /package/{_shims → dist/_shims}/auto/runtime.mjs.map +0 -0
- /package/{_shims → dist/_shims}/auto/types-node.d.ts +0 -0
- /package/{_shims → dist/_shims}/auto/types-node.d.ts.map +0 -0
- /package/{_shims → dist/_shims}/auto/types-node.js +0 -0
- /package/{_shims → dist/_shims}/auto/types-node.js.map +0 -0
- /package/{_shims → dist/_shims}/auto/types-node.mjs +0 -0
- /package/{_shims → dist/_shims}/auto/types-node.mjs.map +0 -0
- /package/{_shims → dist/_shims}/auto/types.d.ts +0 -0
- /package/{_shims → dist/_shims}/auto/types.js +0 -0
- /package/{_shims → dist/_shims}/auto/types.mjs +0 -0
- /package/{_shims → dist/_shims}/bun-runtime.d.ts +0 -0
- /package/{_shims → dist/_shims}/bun-runtime.d.ts.map +0 -0
- /package/{_shims → dist/_shims}/bun-runtime.js +0 -0
- /package/{_shims → dist/_shims}/bun-runtime.js.map +0 -0
- /package/{_shims → dist/_shims}/bun-runtime.mjs +0 -0
- /package/{_shims → dist/_shims}/bun-runtime.mjs.map +0 -0
- /package/{_shims → dist/_shims}/index.d.ts +0 -0
- /package/{_shims → dist/_shims}/index.js +0 -0
- /package/{_shims → dist/_shims}/index.mjs +0 -0
- /package/{_shims → dist/_shims}/manual-types.d.ts +0 -0
- /package/{_shims → dist/_shims}/manual-types.js +0 -0
- /package/{_shims → dist/_shims}/manual-types.mjs +0 -0
- /package/{_shims → dist/_shims}/node-runtime.d.ts +0 -0
- /package/{_shims → dist/_shims}/node-runtime.d.ts.map +0 -0
- /package/{_shims → dist/_shims}/node-runtime.js +0 -0
- /package/{_shims → dist/_shims}/node-runtime.js.map +0 -0
- /package/{_shims → dist/_shims}/node-runtime.mjs +0 -0
- /package/{_shims → dist/_shims}/node-runtime.mjs.map +0 -0
- /package/{_shims → dist/_shims}/node-types.d.ts +0 -0
- /package/{_shims → dist/_shims}/node-types.js +0 -0
- /package/{_shims → dist/_shims}/node-types.mjs +0 -0
- /package/{_shims → dist/_shims}/registry.d.ts +0 -0
- /package/{_shims → dist/_shims}/registry.d.ts.map +0 -0
- /package/{_shims → dist/_shims}/registry.js +0 -0
- /package/{_shims → dist/_shims}/registry.js.map +0 -0
- /package/{_shims → dist/_shims}/registry.mjs +0 -0
- /package/{_shims → dist/_shims}/registry.mjs.map +0 -0
- /package/{_shims → dist/_shims}/web-runtime.d.ts +0 -0
- /package/{_shims → dist/_shims}/web-runtime.d.ts.map +0 -0
- /package/{_shims → dist/_shims}/web-runtime.js +0 -0
- /package/{_shims → dist/_shims}/web-runtime.js.map +0 -0
- /package/{_shims → dist/_shims}/web-runtime.mjs +0 -0
- /package/{_shims → dist/_shims}/web-runtime.mjs.map +0 -0
- /package/{_shims → dist/_shims}/web-types.d.ts +0 -0
- /package/{_shims → dist/_shims}/web-types.js +0 -0
- /package/{_shims → dist/_shims}/web-types.mjs +0 -0
- /package/{core.d.ts → dist/core.d.ts} +0 -0
- /package/{core.d.ts.map → dist/core.d.ts.map} +0 -0
- /package/{core.js → dist/core.js} +0 -0
- /package/{core.js.map → dist/core.js.map} +0 -0
- /package/{core.mjs → dist/core.mjs} +0 -0
- /package/{core.mjs.map → dist/core.mjs.map} +0 -0
- /package/{error.d.ts → dist/error.d.ts} +0 -0
- /package/{error.d.ts.map → dist/error.d.ts.map} +0 -0
- /package/{error.js → dist/error.js} +0 -0
- /package/{error.js.map → dist/error.js.map} +0 -0
- /package/{error.mjs → dist/error.mjs} +0 -0
- /package/{error.mjs.map → dist/error.mjs.map} +0 -0
- /package/{libs → dist/libs}/utils.d.ts +0 -0
- /package/{libs → dist/libs}/utils.d.ts.map +0 -0
- /package/{libs → dist/libs}/utils.js +0 -0
- /package/{libs → dist/libs}/utils.js.map +0 -0
- /package/{libs → dist/libs}/utils.mjs +0 -0
- /package/{libs → dist/libs}/utils.mjs.map +0 -0
- /package/{resource.d.ts → dist/resource.d.ts} +0 -0
- /package/{resource.d.ts.map → dist/resource.d.ts.map} +0 -0
- /package/{resource.js → dist/resource.js} +0 -0
- /package/{resource.js.map → dist/resource.js.map} +0 -0
- /package/{resource.mjs → dist/resource.mjs} +0 -0
- /package/{resource.mjs.map → dist/resource.mjs.map} +0 -0
- /package/{resources → dist/resources}/auth/auth.d.ts +0 -0
- /package/{resources → dist/resources}/auth/auth.d.ts.map +0 -0
- /package/{resources → dist/resources}/auth/auth.js +0 -0
- /package/{resources → dist/resources}/auth/auth.js.map +0 -0
- /package/{resources → dist/resources}/auth/auth.mjs +0 -0
- /package/{resources → dist/resources}/auth/auth.mjs.map +0 -0
- /package/{resources → dist/resources}/auth/credentials.d.ts +0 -0
- /package/{resources → dist/resources}/auth/credentials.d.ts.map +0 -0
- /package/{resources → dist/resources}/auth/credentials.js +0 -0
- /package/{resources → dist/resources}/auth/credentials.js.map +0 -0
- /package/{resources → dist/resources}/auth/credentials.mjs +0 -0
- /package/{resources → dist/resources}/auth/credentials.mjs.map +0 -0
- /package/{resources → dist/resources}/auth/index.mjs.map +0 -0
- /package/{resources → dist/resources}/auth/space-policies.d.ts +0 -0
- /package/{resources → dist/resources}/auth/space-policies.d.ts.map +0 -0
- /package/{resources → dist/resources}/auth/space-policies.js +0 -0
- /package/{resources → dist/resources}/auth/space-policies.js.map +0 -0
- /package/{resources → dist/resources}/auth/space-policies.mjs +0 -0
- /package/{resources → dist/resources}/auth/space-policies.mjs.map +0 -0
- /package/{resources → dist/resources}/auth/space-role-users.d.ts +0 -0
- /package/{resources → dist/resources}/auth/space-role-users.d.ts.map +0 -0
- /package/{resources → dist/resources}/auth/space-role-users.js +0 -0
- /package/{resources → dist/resources}/auth/space-role-users.js.map +0 -0
- /package/{resources → dist/resources}/auth/space-role-users.mjs +0 -0
- /package/{resources → dist/resources}/auth/space-role-users.mjs.map +0 -0
- /package/{resources → dist/resources}/auth/space-roles.d.ts +0 -0
- /package/{resources → dist/resources}/auth/space-roles.d.ts.map +0 -0
- /package/{resources → dist/resources}/auth/space-roles.js +0 -0
- /package/{resources → dist/resources}/auth/space-roles.js.map +0 -0
- /package/{resources → dist/resources}/auth/space-roles.mjs +0 -0
- /package/{resources → dist/resources}/auth/space-roles.mjs.map +0 -0
- /package/{resources → dist/resources}/auth/spaces.d.ts +0 -0
- /package/{resources → dist/resources}/auth/spaces.d.ts.map +0 -0
- /package/{resources → dist/resources}/auth/spaces.js +0 -0
- /package/{resources → dist/resources}/auth/spaces.js.map +0 -0
- /package/{resources → dist/resources}/auth/spaces.mjs +0 -0
- /package/{resources → dist/resources}/auth/spaces.mjs.map +0 -0
- /package/{resources → dist/resources}/console/index.d.ts +0 -0
- /package/{resources → dist/resources}/console/index.d.ts.map +0 -0
- /package/{resources → dist/resources}/console/index.js +0 -0
- /package/{resources → dist/resources}/console/index.js.map +0 -0
- /package/{resources → dist/resources}/console/index.mjs +0 -0
- /package/{resources → dist/resources}/console/index.mjs.map +0 -0
- /package/{resources → dist/resources}/console/oauth2.d.ts +0 -0
- /package/{resources → dist/resources}/console/oauth2.d.ts.map +0 -0
- /package/{resources → dist/resources}/console/oauth2.js +0 -0
- /package/{resources → dist/resources}/console/oauth2.js.map +0 -0
- /package/{resources → dist/resources}/console/oauth2.mjs +0 -0
- /package/{resources → dist/resources}/console/oauth2.mjs.map +0 -0
- /package/{resources → dist/resources}/dashboard/dashboards.d.ts +0 -0
- /package/{resources → dist/resources}/dashboard/dashboards.d.ts.map +0 -0
- /package/{resources → dist/resources}/dashboard/dashboards.js +0 -0
- /package/{resources → dist/resources}/dashboard/dashboards.js.map +0 -0
- /package/{resources → dist/resources}/dashboard/dashboards.mjs +0 -0
- /package/{resources → dist/resources}/dashboard/dashboards.mjs.map +0 -0
- /package/{resources → dist/resources}/dashboard/device-states.d.ts +0 -0
- /package/{resources → dist/resources}/dashboard/device-states.d.ts.map +0 -0
- /package/{resources → dist/resources}/dashboard/device-states.js +0 -0
- /package/{resources → dist/resources}/dashboard/device-states.js.map +0 -0
- /package/{resources → dist/resources}/dashboard/device-states.mjs +0 -0
- /package/{resources → dist/resources}/dashboard/device-states.mjs.map +0 -0
- /package/{resources → dist/resources}/dashboard/index.d.ts +0 -0
- /package/{resources → dist/resources}/dashboard/index.d.ts.map +0 -0
- /package/{resources → dist/resources}/dashboard/index.js +0 -0
- /package/{resources → dist/resources}/dashboard/index.js.map +0 -0
- /package/{resources → dist/resources}/dashboard/index.mjs +0 -0
- /package/{resources → dist/resources}/dashboard/index.mjs.map +0 -0
- /package/{resources → dist/resources}/index.d.ts +0 -0
- /package/{resources → dist/resources}/index.d.ts.map +0 -0
- /package/{resources → dist/resources}/index.js +0 -0
- /package/{resources → dist/resources}/index.js.map +0 -0
- /package/{resources → dist/resources}/index.mjs +0 -0
- /package/{resources → dist/resources}/index.mjs.map +0 -0
- /package/{shims → dist/shims}/node.d.ts +0 -0
- /package/{shims → dist/shims}/node.d.ts.map +0 -0
- /package/{shims → dist/shims}/node.js +0 -0
- /package/{shims → dist/shims}/node.js.map +0 -0
- /package/{shims → dist/shims}/node.mjs +0 -0
- /package/{shims → dist/shims}/node.mjs.map +0 -0
- /package/{shims → dist/shims}/web.d.ts +0 -0
- /package/{shims → dist/shims}/web.d.ts.map +0 -0
- /package/{shims → dist/shims}/web.js +0 -0
- /package/{shims → dist/shims}/web.js.map +0 -0
- /package/{shims → dist/shims}/web.mjs +0 -0
- /package/{shims → dist/shims}/web.mjs.map +0 -0
- /package/{src → dist/src}/tsconfig.json +0 -0
- /package/{types → dist/types}/api.d.ts +0 -0
- /package/{types → dist/types}/api.d.ts.map +0 -0
- /package/{types → dist/types}/api.js +0 -0
- /package/{types → dist/types}/api.js.map +0 -0
- /package/{types → dist/types}/api.mjs +0 -0
- /package/{types → dist/types}/api.mjs.map +0 -0
- /package/{types → dist/types}/jwt.d.ts +0 -0
- /package/{types → dist/types}/jwt.d.ts.map +0 -0
- /package/{types → dist/types}/jwt.js +0 -0
- /package/{types → dist/types}/jwt.js.map +0 -0
- /package/{types → dist/types}/jwt.mjs +0 -0
- /package/{types → dist/types}/jwt.mjs.map +0 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// @ts-ignore
|
|
2
|
+
import * as types from '../_shims/web-types';
|
|
3
|
+
import { setShims } from '../_shims/registry';
|
|
4
|
+
import { getRuntime } from '../_shims/web-runtime';
|
|
5
|
+
setShims(getRuntime({ manuallyImported: true }));
|
|
6
|
+
|
|
7
|
+
declare module '../_shims/manual-types' {
|
|
8
|
+
export namespace manual {
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
export type Agent = types.Agent;
|
|
11
|
+
// @ts-ignore
|
|
12
|
+
export import fetch = types.fetch;
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
export type Request = types.Request;
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
export type RequestInfo = types.RequestInfo;
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
export type RequestInit = types.RequestInit;
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
export type Response = types.Response;
|
|
21
|
+
// @ts-ignore
|
|
22
|
+
export type ResponseInit = types.ResponseInit;
|
|
23
|
+
// @ts-ignore
|
|
24
|
+
export type ResponseType = types.ResponseType;
|
|
25
|
+
// @ts-ignore
|
|
26
|
+
export type BodyInit = types.BodyInit;
|
|
27
|
+
// @ts-ignore
|
|
28
|
+
export type Headers = types.Headers;
|
|
29
|
+
// @ts-ignore
|
|
30
|
+
export type HeadersInit = types.HeadersInit;
|
|
31
|
+
// @ts-ignore
|
|
32
|
+
export type BlobPropertyBag = types.BlobPropertyBag;
|
|
33
|
+
// @ts-ignore
|
|
34
|
+
export type FilePropertyBag = types.FilePropertyBag;
|
|
35
|
+
// @ts-ignore
|
|
36
|
+
export type FileFromPathOptions = types.FileFromPathOptions;
|
|
37
|
+
// @ts-ignore
|
|
38
|
+
export import FormData = types.FormData;
|
|
39
|
+
// @ts-ignore
|
|
40
|
+
export import File = types.File;
|
|
41
|
+
// @ts-ignore
|
|
42
|
+
export import Blob = types.Blob;
|
|
43
|
+
// @ts-ignore
|
|
44
|
+
export type Readable = types.Readable;
|
|
45
|
+
// @ts-ignore
|
|
46
|
+
export type FsReadStream = types.FsReadStream;
|
|
47
|
+
// @ts-ignore
|
|
48
|
+
export import ReadableStream = types.ReadableStream;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface ListResponse<T> {
|
|
2
|
+
count: number;
|
|
3
|
+
|
|
4
|
+
results: Array<T>;
|
|
5
|
+
|
|
6
|
+
next?: string | null;
|
|
7
|
+
|
|
8
|
+
previous?: string | null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface ListParamsResponse {
|
|
12
|
+
/**
|
|
13
|
+
* Number of results to return per page.
|
|
14
|
+
*/
|
|
15
|
+
limit?: number;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The initial index from which to return the results.
|
|
19
|
+
*/
|
|
20
|
+
offset?: number;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Which field to use when ordering the results.
|
|
24
|
+
*/
|
|
25
|
+
ordering?: string;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* A search term.
|
|
29
|
+
*/
|
|
30
|
+
search?: string;
|
|
31
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const VERSION = '0.0.1-dev.4';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["src/version.ts"],"names":[],"mappings":";;;AAAa,QAAA,OAAO,GAAG,aAAa,CAAC"}
|
package/dist/version.mjs
ADDED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.mjs","sourceRoot":"","sources":["src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"version.mjs","sourceRoot":"","sources":["src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,aAAa,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import globals from 'globals';
|
|
2
|
+
import pluginJs from '@eslint/js';
|
|
3
|
+
import tsEslint from 'typescript-eslint';
|
|
4
|
+
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
|
|
5
|
+
|
|
6
|
+
const globalsConfig = {
|
|
7
|
+
...globals.node,
|
|
8
|
+
...globals.jest,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const rules = {
|
|
12
|
+
'no-empty': 'off',
|
|
13
|
+
'@typescript-eslint/no-explicit-any': 'off',
|
|
14
|
+
'@typescript-eslint/ban-ts-comment': 'off',
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const local = {
|
|
18
|
+
files: ['src/_shims/**/*.ts', 'src/shims/*.ts', 'src/*.ts'],
|
|
19
|
+
rules: {
|
|
20
|
+
'@typescript-eslint/no-unused-vars': 'off',
|
|
21
|
+
'@typescript-eslint/no-namespace': 'off',
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
export default [
|
|
25
|
+
{ languageOptions: { globals: globalsConfig } },
|
|
26
|
+
pluginJs.configs.recommended,
|
|
27
|
+
...tsEslint.configs.recommended,
|
|
28
|
+
eslintPluginPrettierRecommended,
|
|
29
|
+
{ rules },
|
|
30
|
+
{
|
|
31
|
+
...local,
|
|
32
|
+
},
|
|
33
|
+
];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import SpaceDFSDK from '@space-df/sdk';
|
|
2
|
+
|
|
3
|
+
const client = new SpaceDFSDK({ organization: 'abc' });
|
|
4
|
+
|
|
5
|
+
async function main() {
|
|
6
|
+
const login = await client.auth.login({
|
|
7
|
+
email: 'test@digitalfortress.dev',
|
|
8
|
+
password: '123123',
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
console.log('LOGIN response', login);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
main();
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import SpaceDFSDK from 'spacedf-sdk';
|
|
2
|
+
|
|
3
|
+
const client = new SpaceDFSDK();
|
|
4
|
+
|
|
5
|
+
async function main() {
|
|
6
|
+
const register = await client.auth.register({
|
|
7
|
+
email: 'abc@digitalfortress.dev',
|
|
8
|
+
password: '123123',
|
|
9
|
+
first_name: 'abc',
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
console.log('Register response', register);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
main();
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import SpaceDFSDK from 'spacedf-sdk';
|
|
2
|
+
|
|
3
|
+
const client = new SpaceDFSDK({ organization: 'abc' });
|
|
4
|
+
|
|
5
|
+
async function main() {
|
|
6
|
+
const oauth2 = await client.oauth2.authorize({
|
|
7
|
+
client_id: 'abc',
|
|
8
|
+
redirect_uri: 'http://localhost:3000',
|
|
9
|
+
scopes: ['organization'],
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
console.log('oauth2 response', oauth2);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
main();
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@space-df/sdk",
|
|
3
|
-
"version": "0.0.1-dev.
|
|
3
|
+
"version": "0.0.1-dev.4",
|
|
4
4
|
"description": "The official TypeScript library for the Spacedf SDK API",
|
|
5
5
|
"author": "Spacedf SDK <support@digitalfortress.dev>",
|
|
6
|
-
"types": "
|
|
7
|
-
"main": "
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
8
|
"type": "commonjs",
|
|
9
9
|
"repository": "git@github.com:Space-DF/spacedf-sdk-node.git",
|
|
10
10
|
"license": "Apache-2.0",
|
|
@@ -20,7 +20,6 @@
|
|
|
20
20
|
"lint": "eslint \"{src,test}/**/*.ts\""
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@space-df/sdk": "^0.0.1-dev.3.2",
|
|
24
23
|
"@types/node": "^18.11.18",
|
|
25
24
|
"@types/node-fetch": "^2.6.4",
|
|
26
25
|
"abort-controller": "^3.0.0",
|
|
@@ -29,6 +28,23 @@
|
|
|
29
28
|
"formdata-node": "^4.3.2",
|
|
30
29
|
"node-fetch": "^2.6.7"
|
|
31
30
|
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@eslint/js": "^9.12.0",
|
|
33
|
+
"@typescript-eslint/eslint-plugin": "^6.7.0",
|
|
34
|
+
"@typescript-eslint/parser": "^6.7.0",
|
|
35
|
+
"eslint": "^8.57.1",
|
|
36
|
+
"eslint-config-prettier": "^9.1.0",
|
|
37
|
+
"eslint-plugin-prettier": "^5.2.1",
|
|
38
|
+
"eslint-plugin-unused-imports": "^3.0.0",
|
|
39
|
+
"globals": "^15.11.0",
|
|
40
|
+
"prettier": "^3.0.0",
|
|
41
|
+
"ts-morph": "^19.0.0",
|
|
42
|
+
"ts-node": "^10.5.0",
|
|
43
|
+
"tsc-multi": "^1.1.0",
|
|
44
|
+
"tsconfig-paths": "^4.0.0",
|
|
45
|
+
"typescript": "^4.8.2",
|
|
46
|
+
"typescript-eslint": "^8.8.1"
|
|
47
|
+
},
|
|
32
48
|
"sideEffects": [
|
|
33
49
|
"./_shims/index.js",
|
|
34
50
|
"./_shims/index.mjs",
|
|
@@ -44,59 +60,59 @@
|
|
|
44
60
|
"exports": {
|
|
45
61
|
"./_shims/auto/*": {
|
|
46
62
|
"deno": {
|
|
47
|
-
"types": "./_shims/auto/*.d.ts",
|
|
48
|
-
"require": "./_shims/auto/*.js",
|
|
49
|
-
"default": "./_shims/auto/*.mjs"
|
|
63
|
+
"types": "./dist/_shims/auto/*.d.ts",
|
|
64
|
+
"require": "./dist/_shims/auto/*.js",
|
|
65
|
+
"default": "./dist/_shims/auto/*.mjs"
|
|
50
66
|
},
|
|
51
67
|
"bun": {
|
|
52
|
-
"types": "./_shims/auto/*.d.ts",
|
|
53
|
-
"require": "./_shims/auto/*-bun.js",
|
|
54
|
-
"default": "./_shims/auto/*-bun.mjs"
|
|
68
|
+
"types": "./dist/_shims/auto/*.d.ts",
|
|
69
|
+
"require": "./dist/_shims/auto/*-bun.js",
|
|
70
|
+
"default": "./dist/_shims/auto/*-bun.mjs"
|
|
55
71
|
},
|
|
56
72
|
"browser": {
|
|
57
|
-
"types": "./_shims/auto/*.d.ts",
|
|
58
|
-
"require": "./_shims/auto/*.js",
|
|
59
|
-
"default": "./_shims/auto/*.mjs"
|
|
73
|
+
"types": "./dist/_shims/auto/*.d.ts",
|
|
74
|
+
"require": "./dist/_shims/auto/*.js",
|
|
75
|
+
"default": "./dist/_shims/auto/*.mjs"
|
|
60
76
|
},
|
|
61
77
|
"worker": {
|
|
62
|
-
"types": "./_shims/auto/*.d.ts",
|
|
63
|
-
"require": "./_shims/auto/*.js",
|
|
64
|
-
"default": "./_shims/auto/*.mjs"
|
|
78
|
+
"types": "./dist/_shims/auto/*.d.ts",
|
|
79
|
+
"require": "./dist/_shims/auto/*.js",
|
|
80
|
+
"default": "./dist/_shims/auto/*.mjs"
|
|
65
81
|
},
|
|
66
82
|
"workerd": {
|
|
67
|
-
"types": "./_shims/auto/*.d.ts",
|
|
68
|
-
"require": "./_shims/auto/*.js",
|
|
69
|
-
"default": "./_shims/auto/*.mjs"
|
|
83
|
+
"types": "./dist/_shims/auto/*.d.ts",
|
|
84
|
+
"require": "./dist/_shims/auto/*.js",
|
|
85
|
+
"default": "./dist/_shims/auto/*.mjs"
|
|
70
86
|
},
|
|
71
87
|
"node": {
|
|
72
|
-
"types": "./_shims/auto/*-node.d.ts",
|
|
73
|
-
"require": "./_shims/auto/*-node.js",
|
|
74
|
-
"default": "./_shims/auto/*-node.mjs"
|
|
88
|
+
"types": "./dist/_shims/auto/*-node.d.ts",
|
|
89
|
+
"require": "./dist/_shims/auto/*-node.js",
|
|
90
|
+
"default": "./dist/_shims/auto/*-node.mjs"
|
|
75
91
|
},
|
|
76
|
-
"types": "./_shims/auto/*.d.ts",
|
|
77
|
-
"require": "./_shims/auto/*.js",
|
|
78
|
-
"default": "./_shims/auto/*.mjs"
|
|
92
|
+
"types": "./dist/_shims/auto/*.d.ts",
|
|
93
|
+
"require": "./dist/_shims/auto/*.js",
|
|
94
|
+
"default": "./dist/_shims/auto/*.mjs"
|
|
79
95
|
},
|
|
80
96
|
".": {
|
|
81
97
|
"require": {
|
|
82
|
-
"types": "./index.d.ts",
|
|
83
|
-
"default": "./index.js"
|
|
98
|
+
"types": "./dist/index.d.ts",
|
|
99
|
+
"default": "./dist/index.js"
|
|
84
100
|
},
|
|
85
|
-
"types": "./index.d.mts",
|
|
86
|
-
"default": "./index.mjs"
|
|
101
|
+
"types": "./dist/index.d.mts",
|
|
102
|
+
"default": "./dist/index.mjs"
|
|
87
103
|
},
|
|
88
104
|
"./*.mjs": {
|
|
89
|
-
"types": "
|
|
90
|
-
"default": "
|
|
105
|
+
"types": "./dist/*.d.ts",
|
|
106
|
+
"default": "./dist/*.mjs"
|
|
91
107
|
},
|
|
92
108
|
"./*.js": {
|
|
93
|
-
"types": "
|
|
94
|
-
"default": "
|
|
109
|
+
"types": "./dist/*.d.ts",
|
|
110
|
+
"default": "./dist/*.js"
|
|
95
111
|
},
|
|
96
112
|
"./*": {
|
|
97
|
-
"types": "
|
|
98
|
-
"require": "
|
|
99
|
-
"default": "
|
|
113
|
+
"types": "./dist/*.d.ts",
|
|
114
|
+
"require": "./dist/*.js",
|
|
115
|
+
"default": "./dist/*.mjs"
|
|
100
116
|
}
|
|
101
117
|
}
|
|
102
118
|
}
|
package/scripts/build
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
set -exuo pipefail
|
|
4
|
+
|
|
5
|
+
cd "$(dirname "$0")/.."
|
|
6
|
+
|
|
7
|
+
node scripts/utils/check-version.cjs
|
|
8
|
+
|
|
9
|
+
# Build into dist and will publish the package from there,
|
|
10
|
+
# so that src/resources/foo.ts becomes <package root>/resources/foo.js
|
|
11
|
+
# This way importing from `"@space-df/sdk/resources/foo"` works
|
|
12
|
+
# even with `"moduleResolution": "node"`
|
|
13
|
+
|
|
14
|
+
rm -rf dist; mkdir dist
|
|
15
|
+
# Copy src to dist/src and build from dist/src into dist, so that
|
|
16
|
+
# the source map for index.js.map will refer to ./src/index.ts etc
|
|
17
|
+
cp -rp src README.md dist
|
|
18
|
+
rm dist/src/_shims/*-deno.ts dist/src/_shims/auto/*-deno.ts
|
|
19
|
+
for file in LICENSE CHANGELOG.md; do
|
|
20
|
+
if [ -e "${file}" ]; then cp "${file}" dist; fi
|
|
21
|
+
done
|
|
22
|
+
if [ -e "bin/cli" ]; then
|
|
23
|
+
mkdir dist/bin
|
|
24
|
+
cp -p "bin/cli" dist/bin/;
|
|
25
|
+
fi
|
|
26
|
+
# this converts the export map paths for the dist directory
|
|
27
|
+
# and does a few other minor things
|
|
28
|
+
node scripts/utils/make-dist-package-json.cjs > dist/package.json
|
|
29
|
+
|
|
30
|
+
# build to .js/.mjs/.d.ts files
|
|
31
|
+
npm exec tsc-multi
|
|
32
|
+
# copy over handwritten .js/.mjs/.d.ts files
|
|
33
|
+
cp src/_shims/*.{d.ts,js,mjs,md} dist/_shims
|
|
34
|
+
cp src/_shims/auto/*.{d.ts,js,mjs} dist/_shims/auto
|
|
35
|
+
# we need to add exports = module.exports = Spacedf SDK Node to index.js;
|
|
36
|
+
# No way to get that from index.ts because it would cause compile errors
|
|
37
|
+
# when building .mjs
|
|
38
|
+
node scripts/utils/fix-index-exports.cjs
|
|
39
|
+
# with "moduleResolution": "nodenext", if ESM resolves to index.d.ts,
|
|
40
|
+
# it'll have TS errors on the default import. But if it resolves to
|
|
41
|
+
# index.d.mts the default import will work (even though both files have
|
|
42
|
+
# the same export default statement)
|
|
43
|
+
cp dist/index.d.ts dist/index.d.mts
|
|
44
|
+
cp tsconfig.dist-src.json dist/src/tsconfig.json
|
|
45
|
+
|
|
46
|
+
node scripts/utils/postprocess-files.cjs
|
|
47
|
+
|
|
48
|
+
# make sure that nothing crashes when we require the output CJS or
|
|
49
|
+
# import the output ESM
|
|
50
|
+
(cd dist && node -e 'require("@space-df/sdk")')
|
|
51
|
+
(cd dist && node -e 'import("@space-df/sdk")' --input-type=module)
|
|
52
|
+
|
|
53
|
+
if command -v deno &> /dev/null && [ -e ./scripts/build-deno ]
|
|
54
|
+
then
|
|
55
|
+
./scripts/build-deno
|
|
56
|
+
fi
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
const main = () => {
|
|
5
|
+
const pkg = require('../../package.json');
|
|
6
|
+
const version = pkg['version'];
|
|
7
|
+
if (!version) throw 'The version property is not set in the package.json file';
|
|
8
|
+
if (typeof version !== 'string') {
|
|
9
|
+
throw `Unexpected type for the package.json version field; got ${typeof version}, expected string`;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const versionFile = path.resolve(__dirname, '..', '..', 'src', 'version.ts');
|
|
13
|
+
const contents = fs.readFileSync(versionFile, 'utf8');
|
|
14
|
+
const output = contents.replace(/(export const VERSION = ')(.*)(')/g, `$1${version}$3`);
|
|
15
|
+
fs.writeFileSync(versionFile, output);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
if (require.main === module) {
|
|
19
|
+
main();
|
|
20
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
const indexJs = process.env['DIST_PATH'] ? path.resolve(process.env['DIST_PATH'], 'index.js') : path.resolve(__dirname, '..', '..', 'dist', 'index.js');
|
|
5
|
+
|
|
6
|
+
let before = fs.readFileSync(indexJs, 'utf8');
|
|
7
|
+
let after = before.replace(/^\s*exports\.default\s*=\s*(\w+)/m, 'exports = module.exports = $1;\nexports.default = $1');
|
|
8
|
+
fs.writeFileSync(indexJs, after, 'utf8');
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const pkgJson = require(process.env['PKG_JSON_PATH'] || '../../package.json');
|
|
2
|
+
|
|
3
|
+
function processExportMap(m) {
|
|
4
|
+
for (const key in m) {
|
|
5
|
+
const value = m[key];
|
|
6
|
+
if (typeof value === 'string') m[key] = value.replace(/^\.\/dist\//, './');
|
|
7
|
+
else processExportMap(value);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
processExportMap(pkgJson.exports);
|
|
11
|
+
|
|
12
|
+
for (const key of ['types', 'main', 'module']) {
|
|
13
|
+
if (typeof pkgJson[key] === 'string') pkgJson[key] = pkgJson[key].replace(/^(\.\/)?dist\//, './');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
delete pkgJson.devDependencies;
|
|
17
|
+
delete pkgJson.scripts.prepack;
|
|
18
|
+
delete pkgJson.scripts.prepublishOnly;
|
|
19
|
+
delete pkgJson.scripts.prepare;
|
|
20
|
+
|
|
21
|
+
console.log(JSON.stringify(pkgJson, null, 2));
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const { parse } = require('@typescript-eslint/parser');
|
|
4
|
+
|
|
5
|
+
const pkgImportPath = process.env['PKG_IMPORT_PATH'] ?? '@space-df/sdk/';
|
|
6
|
+
|
|
7
|
+
const distDir = process.env['DIST_PATH'] ? path.resolve(process.env['DIST_PATH']) : path.resolve(__dirname, '..', '..', 'dist');
|
|
8
|
+
const distSrcDir = path.join(distDir, 'src');
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Quick and dirty AST traversal
|
|
12
|
+
*/
|
|
13
|
+
function traverse(node, visitor) {
|
|
14
|
+
if (!node || typeof node.type !== 'string') return;
|
|
15
|
+
visitor.node?.(node);
|
|
16
|
+
visitor[node.type]?.(node);
|
|
17
|
+
for (const key in node) {
|
|
18
|
+
const value = node[key];
|
|
19
|
+
if (Array.isArray(value)) {
|
|
20
|
+
for (const elem of value) traverse(elem, visitor);
|
|
21
|
+
} else if (value instanceof Object) {
|
|
22
|
+
traverse(value, visitor);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Helper method for replacing arbitrary ranges of text in input code.
|
|
29
|
+
*
|
|
30
|
+
* The `replacer` is a function that will be called with a mini-api. For example:
|
|
31
|
+
*
|
|
32
|
+
* replaceRanges('foobar', ({ replace }) => replace([0, 3], 'baz')) // 'bazbar'
|
|
33
|
+
*
|
|
34
|
+
* The replaced ranges must not be overlapping.
|
|
35
|
+
*/
|
|
36
|
+
function replaceRanges(code, replacer) {
|
|
37
|
+
const replacements = [];
|
|
38
|
+
replacer({ replace: (range, replacement) => replacements.push({ range, replacement }) });
|
|
39
|
+
|
|
40
|
+
if (!replacements.length) return code;
|
|
41
|
+
replacements.sort((a, b) => a.range[0] - b.range[0]);
|
|
42
|
+
const overlapIndex = replacements.findIndex((r, index) => index > 0 && replacements[index - 1].range[1] > r.range[0]);
|
|
43
|
+
if (overlapIndex >= 0) {
|
|
44
|
+
throw new Error(`replacements overlap: ${JSON.stringify(replacements[overlapIndex - 1])} and ${JSON.stringify(replacements[overlapIndex])}`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const parts = [];
|
|
48
|
+
let end = 0;
|
|
49
|
+
for (const {
|
|
50
|
+
range: [from, to],
|
|
51
|
+
replacement,
|
|
52
|
+
} of replacements) {
|
|
53
|
+
if (from > end) parts.push(code.substring(end, from));
|
|
54
|
+
parts.push(replacement);
|
|
55
|
+
end = to;
|
|
56
|
+
}
|
|
57
|
+
if (end < code.length) parts.push(code.substring(end));
|
|
58
|
+
return parts.join('');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Like calling .map(), where the iteratee is called on the path in every import or export from statement.
|
|
63
|
+
* @returns the transformed code
|
|
64
|
+
*/
|
|
65
|
+
function mapModulePaths(code, iteratee) {
|
|
66
|
+
const ast = parse(code, { range: true });
|
|
67
|
+
return replaceRanges(code, ({ replace }) =>
|
|
68
|
+
traverse(ast, {
|
|
69
|
+
node(node) {
|
|
70
|
+
switch (node.type) {
|
|
71
|
+
case 'ImportDeclaration':
|
|
72
|
+
case 'ExportNamedDeclaration':
|
|
73
|
+
case 'ExportAllDeclaration':
|
|
74
|
+
case 'ImportExpression':
|
|
75
|
+
if (node.source) {
|
|
76
|
+
const { range, value } = node.source;
|
|
77
|
+
const transformed = iteratee(value);
|
|
78
|
+
if (transformed !== value) {
|
|
79
|
+
replace(range, JSON.stringify(transformed));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
}),
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async function* walk(dir) {
|
|
89
|
+
for await (const d of await fs.promises.opendir(dir)) {
|
|
90
|
+
const entry = path.join(dir, d.name);
|
|
91
|
+
if (d.isDirectory()) yield* walk(entry);
|
|
92
|
+
else if (d.isFile()) yield entry;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async function postprocess() {
|
|
97
|
+
for await (const file of walk(path.resolve(__dirname, '..', '..', 'dist'))) {
|
|
98
|
+
if (!/\.([cm]?js|(\.d)?[cm]?ts)$/.test(file)) continue;
|
|
99
|
+
|
|
100
|
+
const code = await fs.promises.readFile(file, 'utf8');
|
|
101
|
+
|
|
102
|
+
let transformed = mapModulePaths(code, (importPath) => {
|
|
103
|
+
if (file.startsWith(distSrcDir)) {
|
|
104
|
+
if (importPath.startsWith(pkgImportPath)) {
|
|
105
|
+
// convert self-references in dist/src to relative paths
|
|
106
|
+
let relativePath = path.relative(path.dirname(file), path.join(distSrcDir, importPath.substring(pkgImportPath.length)));
|
|
107
|
+
if (!relativePath.startsWith('.')) relativePath = `./${relativePath}`;
|
|
108
|
+
return relativePath;
|
|
109
|
+
}
|
|
110
|
+
return importPath;
|
|
111
|
+
}
|
|
112
|
+
if (importPath.startsWith('.')) {
|
|
113
|
+
// add explicit file extensions to relative imports
|
|
114
|
+
const { dir, name } = path.parse(importPath);
|
|
115
|
+
const ext = /\.mjs$/.test(file) ? '.mjs' : '.js';
|
|
116
|
+
return `${dir}/${name}${ext}`;
|
|
117
|
+
}
|
|
118
|
+
return importPath;
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
if (file.startsWith(distSrcDir) && !file.endsWith('_shims/index.d.ts')) {
|
|
122
|
+
// strip out `unknown extends Foo ? never :` shim guards in dist/src
|
|
123
|
+
// to prevent errors from appearing in Go To Source
|
|
124
|
+
transformed = transformed.replace(
|
|
125
|
+
new RegExp('unknown extends (typeof )?\\S+ \\? \\S+ :\\s*'.replace(/\s+/, '\\s+'), 'gm'),
|
|
126
|
+
// replace with same number of characters to avoid breaking source maps
|
|
127
|
+
(match) => ' '.repeat(match.length),
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (file.endsWith('.d.ts')) {
|
|
132
|
+
// work around bad tsc behavior
|
|
133
|
+
// if we have `import { type Readable } from 'spacedf-sdk/_shims/index'`,
|
|
134
|
+
// tsc sometimes replaces `Readable` with `import("stream").Readable` inline
|
|
135
|
+
// in the output .d.ts
|
|
136
|
+
transformed = transformed.replace(/import\("stream"\).Readable/g, 'Readable');
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// strip out lib="dom" and types="node" references; these are needed at build time,
|
|
140
|
+
// but would pollute the user's TS environment
|
|
141
|
+
transformed = transformed.replace(
|
|
142
|
+
/^ *\/\/\/ *<reference +(lib="dom"|types="node").*?\n/gm,
|
|
143
|
+
// replace with same number of characters to avoid breaking source maps
|
|
144
|
+
(match) => ' '.repeat(match.length - 1) + '\n',
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
if (transformed !== code) {
|
|
148
|
+
await fs.promises.writeFile(file, transformed, 'utf8');
|
|
149
|
+
console.error(`wrote ${path.relative(process.cwd(), file)}`);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
postprocess();
|