@aeriajs/entrypoint 0.0.163 → 0.0.165

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/dist/index.js CHANGED
@@ -1,9 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAvailableRoles = exports.getConfig = exports.getRouter = exports.getCollection = exports.getCollections = exports.getEntrypoint = exports.getEntrypointPath = void 0;
4
- const path = require("node:path");
5
- const fs = require("node:fs/promises");
6
- const common_1 = require("@aeriajs/common");
1
+ import * as path from 'node:path';
2
+ import * as fs from 'node:fs/promises';
7
3
  let collectionsMemo;
8
4
  let availableRolesMemo;
9
5
  const collectionMemo = {};
@@ -12,7 +8,7 @@ const DEFAULT_CONFIG = {
12
8
  mutableUserProperties: [],
13
9
  },
14
10
  };
15
- const getEntrypointPath = async () => {
11
+ export const getEntrypointPath = async () => {
16
12
  if (process.env.AERIA_MAIN) {
17
13
  return path.join(process.cwd(), process.env.AERIA_MAIN);
18
14
  }
@@ -21,34 +17,28 @@ const getEntrypointPath = async () => {
21
17
  }));
22
18
  return path.join(process.cwd(), aeriaMain || main);
23
19
  };
24
- exports.getEntrypointPath = getEntrypointPath;
25
- const getEntrypoint = async () => {
26
- const entrypoint = await (0, common_1.dynamicImport)(await (0, exports.getEntrypointPath)());
27
- return entrypoint.default.default
28
- ? entrypoint.default
29
- : entrypoint;
20
+ export const getEntrypoint = async () => {
21
+ return import(await getEntrypointPath());
30
22
  };
31
- exports.getEntrypoint = getEntrypoint;
32
23
  const internalGetCollections = async () => {
33
- const entrypoint = await (0, exports.getEntrypoint)();
24
+ const entrypoint = await getEntrypoint();
34
25
  const collections = entrypoint.collections
35
26
  ? entrypoint.collections
36
27
  : entrypoint.default.options.collections;
37
28
  return Object.assign({}, collections);
38
29
  };
39
- const getCollections = async () => {
30
+ export const getCollections = async () => {
40
31
  if (collectionsMemo) {
41
32
  return collectionsMemo;
42
33
  }
43
34
  collectionsMemo = await internalGetCollections();
44
35
  return Object.freeze(collectionsMemo);
45
36
  };
46
- exports.getCollections = getCollections;
47
- const getCollection = async (collectionName) => {
37
+ export const getCollection = async (collectionName) => {
48
38
  if (collectionMemo[collectionName]) {
49
39
  return collectionMemo[collectionName];
50
40
  }
51
- const collections = await (0, exports.getCollections)();
41
+ const collections = await getCollections();
52
42
  const candidate = collectionName in collections
53
43
  ? collections[collectionName]
54
44
  : undefined;
@@ -60,9 +50,8 @@ const getCollection = async (collectionName) => {
60
50
  }
61
51
  return Object.assign({}, collection);
62
52
  };
63
- exports.getCollection = getCollection;
64
- const getRouter = async () => {
65
- const entrypoint = await (0, exports.getEntrypoint)();
53
+ export const getRouter = async () => {
54
+ const entrypoint = await getEntrypoint();
66
55
  if (entrypoint.router) {
67
56
  return entrypoint.router;
68
57
  }
@@ -70,19 +59,17 @@ const getRouter = async () => {
70
59
  ? entrypoint.default.options.router
71
60
  : null;
72
61
  };
73
- exports.getRouter = getRouter;
74
- const getConfig = async () => {
75
- const entrypoint = await (0, exports.getEntrypoint)();
62
+ export const getConfig = async () => {
63
+ const entrypoint = await getEntrypoint();
76
64
  return entrypoint.default
77
65
  ? entrypoint.default.options.config
78
66
  : DEFAULT_CONFIG;
79
67
  };
80
- exports.getConfig = getConfig;
81
- const getAvailableRoles = async () => {
68
+ export const getAvailableRoles = async () => {
82
69
  if (availableRolesMemo) {
83
70
  return availableRolesMemo;
84
71
  }
85
- const collections = await (0, exports.getCollections)();
72
+ const collections = await getCollections();
86
73
  const availableRoles = [];
87
74
  if ('user' in collections) {
88
75
  const collection = typeof collections.user === 'function'
@@ -114,4 +101,3 @@ const getAvailableRoles = async () => {
114
101
  availableRolesMemo = Array.from(rolesSet);
115
102
  return availableRolesMemo;
116
103
  };
117
- exports.getAvailableRoles = getAvailableRoles;
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@aeriajs/entrypoint",
3
- "version": "0.0.163",
3
+ "type": "module",
4
+ "version": "0.0.165",
4
5
  "description": "",
5
6
  "main": "dist/index.js",
6
- "module": "dist/index.mjs",
7
7
  "types": "dist/index.d.ts",
8
8
  "publishConfig": {
9
9
  "access": "public"
@@ -14,8 +14,7 @@
14
14
  "exports": {
15
15
  ".": {
16
16
  "types": "./dist/index.d.ts",
17
- "import": "./dist/index.mjs",
18
- "require": "./dist/index.js"
17
+ "default": "./dist/index.js"
19
18
  }
20
19
  },
21
20
  "files": [
@@ -26,17 +25,14 @@
26
25
  "@aeriajs/types": "link:../types"
27
26
  },
28
27
  "peerDependencies": {
29
- "@aeriajs/common": "^0.0.157",
30
- "@aeriajs/types": "^0.0.135"
28
+ "@aeriajs/common": "^0.0.158",
29
+ "@aeriajs/types": "^0.0.136"
31
30
  },
32
31
  "scripts": {
33
32
  "test": "vitest run",
34
33
  "test:typecheck": "tsc -p tsconfig.test.json",
35
34
  "lint": "eslint .",
36
35
  "lint:fix": "eslint . --fix",
37
- "build": "pnpm build:cjs && pnpm build:esm",
38
- "build:cjs": "tsc",
39
- "build:esm": "esbuild './src/**/*.ts' --outdir=dist --out-extension:.js=.mjs && pnpm build:esm-transform",
40
- "build:esm-transform": "pnpm -w esm-transform $PWD/dist"
36
+ "build": "tsc"
41
37
  }
42
38
  }
package/dist/index.mjs DELETED
@@ -1,90 +0,0 @@
1
- "use strict";
2
- import * as path from "node:path";
3
- import * as fs from "node:fs/promises";
4
- import { dynamicImport } from "@aeriajs/common";
5
- let collectionsMemo;
6
- let availableRolesMemo;
7
- const collectionMemo = {};
8
- const DEFAULT_CONFIG = {
9
- security: {
10
- mutableUserProperties: []
11
- }
12
- };
13
- export const getEntrypointPath = async () => {
14
- if (process.env.AERIA_MAIN) {
15
- return path.join(process.cwd(), process.env.AERIA_MAIN);
16
- }
17
- const { main, aeriaMain } = JSON.parse(await fs.readFile(path.join(process.cwd(), "package.json"), {
18
- encoding: "utf8"
19
- }));
20
- return path.join(process.cwd(), aeriaMain || main);
21
- };
22
- export const getEntrypoint = async () => {
23
- const entrypoint = await dynamicImport(await getEntrypointPath());
24
- return entrypoint.default.default ? entrypoint.default : entrypoint;
25
- };
26
- const internalGetCollections = async () => {
27
- const entrypoint = await getEntrypoint();
28
- const collections = entrypoint.collections ? entrypoint.collections : entrypoint.default.options.collections;
29
- return Object.assign({}, collections);
30
- };
31
- export const getCollections = async () => {
32
- if (collectionsMemo) {
33
- return collectionsMemo;
34
- }
35
- collectionsMemo = await internalGetCollections();
36
- return Object.freeze(collectionsMemo);
37
- };
38
- export const getCollection = async (collectionName) => {
39
- if (collectionMemo[collectionName]) {
40
- return collectionMemo[collectionName];
41
- }
42
- const collections = await getCollections();
43
- const candidate = collectionName in collections ? collections[collectionName] : void 0;
44
- const collection = typeof candidate === "function" ? candidate() : candidate;
45
- if (collection) {
46
- collectionMemo[collectionName] = collection;
47
- }
48
- return Object.assign({}, collection);
49
- };
50
- export const getRouter = async () => {
51
- const entrypoint = await getEntrypoint();
52
- if (entrypoint.router) {
53
- return entrypoint.router;
54
- }
55
- return entrypoint.default ? entrypoint.default.options.router : null;
56
- };
57
- export const getConfig = async () => {
58
- const entrypoint = await getEntrypoint();
59
- return entrypoint.default ? entrypoint.default.options.config : DEFAULT_CONFIG;
60
- };
61
- export const getAvailableRoles = async () => {
62
- if (availableRolesMemo) {
63
- return availableRolesMemo;
64
- }
65
- const collections = await getCollections();
66
- const availableRoles = [];
67
- if ("user" in collections) {
68
- const collection = typeof collections.user === "function" ? collections.user() : collections.user;
69
- if ("roles" in collection.description.properties && "items" in collection.description.properties.roles && "enum" in collection.description.properties.roles.items) {
70
- availableRoles.push(...collection.description.properties.roles.items.enum);
71
- }
72
- }
73
- for (const collectionName in collections) {
74
- const candidate = collections[collectionName];
75
- const collection = typeof candidate === "function" ? candidate() : candidate;
76
- if (!collection.exposedFunctions) {
77
- continue;
78
- }
79
- for (const fnName in collection.exposedFunctions) {
80
- const exposed = collection.exposedFunctions[fnName];
81
- if (Array.isArray(exposed)) {
82
- availableRoles.push(...exposed);
83
- }
84
- }
85
- }
86
- const rolesSet = new Set(availableRoles);
87
- rolesSet.delete("unauthenticated");
88
- availableRolesMemo = Array.from(rolesSet);
89
- return availableRolesMemo;
90
- };